message stringlengths 2 67k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 463 109k | cluster float64 19 19 | __index_level_0__ int64 926 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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 ai, the attack skill is bi.
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 ai and bi (1 β€ ai, bi β€ 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).
Submitted Solution:
```
a_1, d_1 = map(int, input().split())
a_2, d_2 = map(int, input().split())
a_3, d_3 = map(int, input().split())
a_4, d_4 = map(int, input().split())
fl1 = fl2 = False
if ((a_1 > d_3 and d_2 > a_4) and (a_1 > d_4 and d_2 > a_3)) or ((a_2 > d_4 and d_1 > a_3) and (a_2 > d_3 and d_1 > a_4)):
fl1 = True;
if (a_1 < d_3 and d_2 < a_4) or (a_2 < d_3 and d_1 < a_4) or (a_1 < d_4 and d_2 < a_3) or (a_2 < d_4 and d_1 < a_3):
fl2 = True;
if fl1 == fl2:
print('Draw');
elif fl1:
print('Team 1');
elif fl2:
print('Team 2');
``` | instruction | 0 | 93,863 | 19 | 187,726 |
No | output | 1 | 93,863 | 19 | 187,727 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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 ai, the attack skill is bi.
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 ai and bi (1 β€ ai, bi β€ 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).
Submitted Solution:
```
def1, at1 = map(int, input().split())
def2, at2 = map(int, input().split())
def3, at3 = map(int, input().split())
def4, at4 = map(int, input().split())
first = [def1, at2]
a_1 = 0
if (at3 > first[1] and def4 > first[0]) or (at4 > first[1] and def3 > first[0]):
a_1 = 2
elif (def3 < first[0] and at4 < first[1]) and (def4 < first[0] and at3 < first[1]):
a_1 = 1
else:
a_1 = 0
first = [def2, at1]
a_2 = 0
if (at3 > first[1] and def4 > first[0]) or (at4 > first[1] and def3 > first[0]):
a_2 = 2
elif (def3 < first[0] and at4 < first[1]) and (def4 < first[0] and at3 < first[1]):
a_2 = 1
else:
a_2 = 0
if a_1 == 1 or a_2 == 1:
print("Team 1")
elif a_2 == 2 and a_1 == 2:
print("Team 2")
else:
print("Draw")
``` | instruction | 0 | 93,864 | 19 | 187,728 |
No | output | 1 | 93,864 | 19 | 187,729 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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 ai, the attack skill is bi.
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 ai and bi (1 β€ ai, bi β€ 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).
Submitted Solution:
```
p1 = list(map(int, input().split()))
p2 = list(map(int, input().split()))
p3 = list(map(int, input().split()))
p4 = list(map(int, input().split()))
t1 = [(p1[0],p2[1]), (p2[0],p1[1])]
score = [0,0]
t2 = [(p3[0],p4[1]), (p4[0],p3[1])]
t11 = t1[0]
t12 = t1[1]
t21 = t2[0]
t22 = t2[1]
# if any team of t1 wins both game, then t1 wins
# if any both team loses to any of t2, t2 wins
if t11[0] > t21[1] and t11[0] > t22[1] and t11[1] > t21[0] and t11[1] >t22[0]:
print("Team 1")
elif t12[0] > t21[1] and t12[0] > t22[1] and t12[1] > t21[0] and t12[1] >t22[1]:
print("Team 1")
elif ((t11[0] < t21[1] and t11[1] < t21[0] ) or ( t11[0] < t22[1] and t11[1] < t22[0])) and ((t12[0] < t21[1] and t12[1] < t21[0] ) or ( t12[0] < t22[1] and t12[1] < t22[0])):
print("Team 2")
else:
print("Draw")
``` | instruction | 0 | 93,865 | 19 | 187,730 |
No | output | 1 | 93,865 | 19 | 187,731 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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 ai, the attack skill is bi.
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 ai and bi (1 β€ ai, bi β€ 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).
Submitted Solution:
```
A = [0]*5
B = [0]*5
for i in range(1,5):
A[i],B[i] = map(int, input().split())
def Fight(Team1, Team2):
if Team1[0]>Team2[0] and Team1[1]>Team2[1]:
return 3
elif Team1[0]<Team2[0] and Team1[1]<Team2[1]:
return 1
else:
return 2
Team11 = [A[1],B[2]]
Team12 = [A[2],B[1]]
Team21 = [A[3],B[4]]
Team22 = [A[4],B[3]]
res = 0
ans = max(min(Fight(Team11,Team21),Fight(Team11,Team22)),min(Fight(Team12,Team21),Fight(Team12,Team22)))
if ans==3:
print('Team 1')
elif ans==2:
print('Draw')
else:
print('Team 2')
``` | instruction | 0 | 93,866 | 19 | 187,732 |
No | output | 1 | 93,866 | 19 | 187,733 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is Borya's eleventh birthday, and he has got a great present: n cards with numbers. The i-th card has the number ai written on it. Borya wants to put his cards in a row to get one greater number. For example, if Borya has cards with numbers 1, 31, and 12, and he puts them in a row in this order, he would get a number 13112.
He is only 11, but he already knows that there are n! ways to put his cards in a row. But today is a special day, so he is only interested in such ways that the resulting big number is divisible by eleven. So, the way from the previous paragraph is good, because 13112 = 1192 Γ 11, but if he puts the cards in the following order: 31, 1, 12, he would get a number 31112, it is not divisible by 11, so this way is not good for Borya. Help Borya to find out how many good ways to put the cards are there.
Borya considers all cards different, even if some of them contain the same number. For example, if Borya has two cards with 1 on it, there are two good ways.
Help Borya, find the number of good ways to put the cards. This number can be large, so output it modulo 998244353.
Input
Input data contains multiple test cases. The first line of the input data contains an integer t β the number of test cases (1 β€ t β€ 100). The descriptions of test cases follow.
Each test is described by two lines.
The first line contains an integer n (1 β€ n β€ 2000) β the number of cards in Borya's present.
The second line contains n integers ai (1 β€ ai β€ 109) β numbers written on the cards.
It is guaranteed that the total number of cards in all tests of one input data doesn't exceed 2000.
Output
For each test case output one line: the number of ways to put the cards to the table so that the resulting big number was divisible by 11, print the number modulo 998244353.
Example
Input
4
2
1 1
3
1 31 12
3
12345 67 84
9
1 2 3 4 5 6 7 8 9
Output
2
2
2
31680
Submitted Solution:
```
mod = 998244353
f0 = [ [0 for i in range(11)] for j in range(2010) ]
f1 = [ [0 for i in range(11)] for j in range(2010) ]
fac = [0 for i in range(2010)]
tab = [0 for i in range(11)]
C = [ [0 for i in range(2010)] for j in range(2010) ]
def Init() :
fac[0] = 1
for i in range(2010) :
if i > 0 : fac[i] = fac[i - 1] * i % mod
C[i][0] = 1
for j in range(1, 2010) :
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod
def len(x) :
res = 0
while x > 0 :
res += 1
x = x // 10
return res
def solve() :
n = int(input())
f0[0][0] = f1[0][0] = 1
a = list(map(int, input().split()))
c0, c1 = 0, 0
s0, s1 = 0, 0
for nu in a :
m = nu % 11
if len(nu) & 1 :
c1 += 1
s1 += m
for i in range(11) :
f1[c1][i] = 0
for i in range(c1 - 1, -1, -1) :
for j in range(11) :
if f1[i][j] == 0 : continue
f1[i + 1][(j + m) % 11] += f1[i][j]
f1[i + 1][(j + m) % 11] %= mod
else :
c0 += 1
s0 += m
for i in range(11) :
f0[c0][i] = 0
for i in range(c0 - 1, -1, -1) :
for j in range(11) :
if f0[i][j] == 0 : continue
f0[i + 1][(j + m) % 11] += f0[i][j]
f0[i + 1][(j + m) % 11] %= mod
s1 %= 11
s0 %= 11
part = c1 // 2
for i in range(11) :
tab[i] = 0
for i in range(11) :
tab[(i + i + 11 - s1) % 11] = f1[c1 - part][i]
for i in range(11) :
tab[i] = tab[i] * fac[part] % mod * fac[c1 - part] % mod
ans = 0
if c1 == 0 :
ans = f0[c0][0]
elif c0 == 0 :
ans = tab[0]
else :
for i in range(c0 + 1) :
for j in range(11) :
if f0[i][j] == 0 : continue
# print(f0[i][j], tab[(j + j + 11 - s0) % 11], fac[i] % mod * fac[c0 - i] % mod, C[j + part - 1][part - 1] % mod * C[part + c0 - i - 1][c0 - i - 1] % mod )
ans = ( ans \
+ f0[i][j] * tab[(j + j + 11 - s0) % 11] % mod \
* fac[i] % mod * fac[c0 - i] % mod \
* C[j + part - 1][(c1 - part) - 1] % mod * C[part + c0 - i - 1][c0 - i - 1] ) % mod
print(ans)
Init()
T = int(input())
for ttt in range(T) : solve()
``` | instruction | 0 | 94,094 | 19 | 188,188 |
No | output | 1 | 94,094 | 19 | 188,189 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is Borya's eleventh birthday, and he has got a great present: n cards with numbers. The i-th card has the number ai written on it. Borya wants to put his cards in a row to get one greater number. For example, if Borya has cards with numbers 1, 31, and 12, and he puts them in a row in this order, he would get a number 13112.
He is only 11, but he already knows that there are n! ways to put his cards in a row. But today is a special day, so he is only interested in such ways that the resulting big number is divisible by eleven. So, the way from the previous paragraph is good, because 13112 = 1192 Γ 11, but if he puts the cards in the following order: 31, 1, 12, he would get a number 31112, it is not divisible by 11, so this way is not good for Borya. Help Borya to find out how many good ways to put the cards are there.
Borya considers all cards different, even if some of them contain the same number. For example, if Borya has two cards with 1 on it, there are two good ways.
Help Borya, find the number of good ways to put the cards. This number can be large, so output it modulo 998244353.
Input
Input data contains multiple test cases. The first line of the input data contains an integer t β the number of test cases (1 β€ t β€ 100). The descriptions of test cases follow.
Each test is described by two lines.
The first line contains an integer n (1 β€ n β€ 2000) β the number of cards in Borya's present.
The second line contains n integers ai (1 β€ ai β€ 109) β numbers written on the cards.
It is guaranteed that the total number of cards in all tests of one input data doesn't exceed 2000.
Output
For each test case output one line: the number of ways to put the cards to the table so that the resulting big number was divisible by 11, print the number modulo 998244353.
Example
Input
4
2
1 1
3
1 31 12
3
12345 67 84
9
1 2 3 4 5 6 7 8 9
Output
2
2
2
31680
Submitted Solution:
```
mod = 998244353
f0 = [ [0 for i in range(11)] for j in range(2010) ]
f1 = [ [0 for i in range(11)] for j in range(2010) ]
fac = [0 for i in range(2010)]
tab = [0 for i in range(11)]
C = [ [0 for i in range(2010)] for j in range(2010) ]
def Init() :
fac[0] = 1
for i in range(2010) :
if i > 0 : fac[i] = fac[i - 1] * i % mod
C[i][0] = 1
for j in range(1, 2010) :
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod
def len(x) :
res = 0
while x > 0 :
res += 1
x = x // 10
return res
def solve(ttt) :
n = int(input())
f0[0][0] = f1[0][0] = 1
a = list(map(int, input().split()))
if ttt == 38 :
print(a)
c0, c1 = 0, 0
s0, s1 = 0, 0
for nu in a :
m = nu % 11
if len(nu) & 1 :
c1 += 1
s1 += m
for i in range(11) :
f1[c1][i] = 0
for i in range(c1 - 1, -1, -1) :
for j in range(11) :
if f1[i][j] == 0 : continue
f1[i + 1][(j + m) % 11] += f1[i][j]
f1[i + 1][(j + m) % 11] %= mod
else :
c0 += 1
s0 += m
for i in range(11) :
f0[c0][i] = 0
for i in range(c0 - 1, -1, -1) :
for j in range(11) :
if f0[i][j] == 0 : continue
f0[i + 1][(j + m) % 11] += f0[i][j]
f0[i + 1][(j + m) % 11] %= mod
s1 %= 11
s0 %= 11
part = c1 // 2
for i in range(11) :
tab[i] = 0
for i in range(11) :
tab[(i + i + 11 - s1) % 11] = f1[c1 - part][i]
for i in range(11) :
tab[i] = tab[i] * fac[part] % mod * fac[c1 - part] % mod
ans = 0
if c1 == 0 :
ans = f0[c0][0] * fac[c0]
elif c0 == 0 :
ans = tab[0]
else :
for i in range(c0 + 1) :
for j in range(11) :
if f0[i][j] == 0 : continue
# print(f0[i][j], tab[(j + j + 11 - s0) % 11] \
# , fac[i] % mod * fac[c0 - i] % mod, C[j + (c1 - part) - 1][(c1 - part) - 1] % mod * C[part + c0 - i][part] % mod )
ans = ( ans \
+ fac[i] % mod * fac[c0 - i] % mod \
* f0[i][j] * tab[(j + j + 11 - s0) % 11] % mod \
* C[i + (c1 - part) - 1][(c1 - part) - 1] % mod \
* C[part + c0 - i][part]
) % mod
print(ans)
Init()
T = int(input())
for ttt in range(T) : solve(ttt + 1)
``` | instruction | 0 | 94,095 | 19 | 188,190 |
No | output | 1 | 94,095 | 19 | 188,191 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is Borya's eleventh birthday, and he has got a great present: n cards with numbers. The i-th card has the number ai written on it. Borya wants to put his cards in a row to get one greater number. For example, if Borya has cards with numbers 1, 31, and 12, and he puts them in a row in this order, he would get a number 13112.
He is only 11, but he already knows that there are n! ways to put his cards in a row. But today is a special day, so he is only interested in such ways that the resulting big number is divisible by eleven. So, the way from the previous paragraph is good, because 13112 = 1192 Γ 11, but if he puts the cards in the following order: 31, 1, 12, he would get a number 31112, it is not divisible by 11, so this way is not good for Borya. Help Borya to find out how many good ways to put the cards are there.
Borya considers all cards different, even if some of them contain the same number. For example, if Borya has two cards with 1 on it, there are two good ways.
Help Borya, find the number of good ways to put the cards. This number can be large, so output it modulo 998244353.
Input
Input data contains multiple test cases. The first line of the input data contains an integer t β the number of test cases (1 β€ t β€ 100). The descriptions of test cases follow.
Each test is described by two lines.
The first line contains an integer n (1 β€ n β€ 2000) β the number of cards in Borya's present.
The second line contains n integers ai (1 β€ ai β€ 109) β numbers written on the cards.
It is guaranteed that the total number of cards in all tests of one input data doesn't exceed 2000.
Output
For each test case output one line: the number of ways to put the cards to the table so that the resulting big number was divisible by 11, print the number modulo 998244353.
Example
Input
4
2
1 1
3
1 31 12
3
12345 67 84
9
1 2 3 4 5 6 7 8 9
Output
2
2
2
31680
Submitted Solution:
```
mod = 998244353
f0 = [ [0 for i in range(11)] for j in range(2010) ]
f1 = [ [0 for i in range(11)] for j in range(2010) ]
fac = [0 for i in range(2010)]
tab = [0 for i in range(11)]
C = [ [0 for i in range(2010)] for j in range(2010) ]
def Init() :
fac[0] = 1
for i in range(2010) :
if i > 0 : fac[i] = fac[i - 1] * i % mod
C[i][0] = 1
for j in range(1, 2010) :
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod
def len(x) :
res = 0
while x > 0 :
res += 1
x = x // 10
return res
def solve(ttt) :
n = int(input())
f0[0][0] = f1[0][0] = 1
a = list(map(int, input().split()))
if ttt == 38 :
print(a)
c0, c1 = 0, 0
s0, s1 = 0, 0
for nu in a :
m = nu % 11
if len(nu) & 1 :
c1 += 1
s1 += m
for i in range(11) :
f1[c1][i] = 0
for i in range(c1 - 1, -1, -1) :
for j in range(11) :
if f1[i][j] == 0 : continue
f1[i + 1][(j + m) % 11] += f1[i][j]
f1[i + 1][(j + m) % 11] %= mod
else :
c0 += 1
s0 += m
for i in range(11) :
f0[c0][i] = 0
for i in range(c0 - 1, -1, -1) :
for j in range(11) :
if f0[i][j] == 0 : continue
f0[i + 1][(j + m) % 11] += f0[i][j]
f0[i + 1][(j + m) % 11] %= mod
s1 %= 11
s0 %= 11
part = c1 // 2
for i in range(11) :
tab[i] = 0
for i in range(11) :
tab[(i + i + 11 - s1) % 11] = f1[c1 - part][i]
for i in range(11) :
tab[i] = tab[i] * fac[part] % mod * fac[c1 - part] % mod
ans = 0
if c1 == 0 :
ans = f0[c0][0]
elif c0 == 0 :
ans = tab[0]
else :
for i in range(c0 + 1) :
for j in range(11) :
if f0[i][j] == 0 : continue
# print(f0[i][j], tab[(j + j + 11 - s0) % 11] \
# , fac[i] % mod * fac[c0 - i] % mod, C[j + (c1 - part) - 1][(c1 - part) - 1] % mod * C[part + c0 - i][part] % mod )
ans = ( ans \
+ fac[i] % mod * fac[c0 - i] % mod \
* f0[i][j] * tab[(j + j + 11 - s0) % 11] % mod \
* C[i + (c1 - part) - 1][(c1 - part) - 1] % mod \
* C[part + c0 - i][part]
) % mod
print(ans)
Init()
T = int(input())
for ttt in range(T) : solve(ttt + 1)
``` | instruction | 0 | 94,096 | 19 | 188,192 |
No | output | 1 | 94,096 | 19 | 188,193 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is Borya's eleventh birthday, and he has got a great present: n cards with numbers. The i-th card has the number ai written on it. Borya wants to put his cards in a row to get one greater number. For example, if Borya has cards with numbers 1, 31, and 12, and he puts them in a row in this order, he would get a number 13112.
He is only 11, but he already knows that there are n! ways to put his cards in a row. But today is a special day, so he is only interested in such ways that the resulting big number is divisible by eleven. So, the way from the previous paragraph is good, because 13112 = 1192 Γ 11, but if he puts the cards in the following order: 31, 1, 12, he would get a number 31112, it is not divisible by 11, so this way is not good for Borya. Help Borya to find out how many good ways to put the cards are there.
Borya considers all cards different, even if some of them contain the same number. For example, if Borya has two cards with 1 on it, there are two good ways.
Help Borya, find the number of good ways to put the cards. This number can be large, so output it modulo 998244353.
Input
Input data contains multiple test cases. The first line of the input data contains an integer t β the number of test cases (1 β€ t β€ 100). The descriptions of test cases follow.
Each test is described by two lines.
The first line contains an integer n (1 β€ n β€ 2000) β the number of cards in Borya's present.
The second line contains n integers ai (1 β€ ai β€ 109) β numbers written on the cards.
It is guaranteed that the total number of cards in all tests of one input data doesn't exceed 2000.
Output
For each test case output one line: the number of ways to put the cards to the table so that the resulting big number was divisible by 11, print the number modulo 998244353.
Example
Input
4
2
1 1
3
1 31 12
3
12345 67 84
9
1 2 3 4 5 6 7 8 9
Output
2
2
2
31680
Submitted Solution:
```
mod = 998244353
f0 = [ [0 for i in range(11)] for j in range(2010) ]
f1 = [ [0 for i in range(11)] for j in range(2010) ]
fac = [0 for i in range(2010)]
tab = [0 for i in range(11)]
C = [ [0 for i in range(2010)] for j in range(2010) ]
def Init() :
fac[0] = 1
for i in range(2010) :
if i > 0 : fac[i] = fac[i - 1] * i % mod
C[i][0] = 1
for j in range(1, 2010) :
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod
def len(x) :
res = 0
while x > 0 :
res += 1
x = x // 10
return res
def solve() :
n = int(input())
f0[0][0] = f1[0][0] = 1
a = list(map(int, input().split()))
c0, c1 = 0, 0
s0, s1 = 0, 0
for nu in a :
m = nu % 11
if len(nu) & 1 :
c1 += 1
s1 += m
for i in range(11) :
f1[c1][i] = 0
for i in range(c1 - 1, -1, -1) :
for j in range(11) :
if f1[i][j] == 0 : continue
f1[i + 1][(j + m) % 11] += f1[i][j]
f1[i + 1][(j + m) % 11] %= mod
else :
c0 += 1
s0 += m
for i in range(11) :
f0[c0][i] = 0
for i in range(c0 - 1, -1, -1) :
for j in range(11) :
if f0[i][j] == 0 : continue
f0[i + 1][(j + m) % 11] += f0[i][j]
f0[i + 1][(j + m) % 11] %= mod
s1 %= 11
s0 %= 11
part = c1 // 2
for i in range(11) :
tab[i] = 0
for i in range(11) :
tab[(i + i + 11 - s1) % 11] = f1[c1 - part][i]
for i in range(11) :
tab[i] = tab[i] * fac[part] % mod * fac[c1 - part] % mod
ans = 0
if c1 == 0 :
ans = f0[c0][0]
elif c0 == 0 :
ans = tab[0]
else :
for i in range(c0 + 1) :
for j in range(11) :
if f0[i][j] == 0 : continue
# print(f0[i][j], tab[(j + j + 11 - s0) % 11] \
# , fac[i] % mod * fac[c0 - i] % mod, C[j + (c1 - part) - 1][(c1 - part) - 1] % mod * C[part + c0 - i][part] % mod )
ans = ( ans \
+ fac[i] % mod * fac[c0 - i] % mod \
* f0[i][j] * tab[(j + j + 11 - s0) % 11] % mod \
* C[i + (c1 - part) - 1][(c1 - part) - 1] % mod \
* C[part + c0 - i][part]
) % mod
print(ans)
Init()
T = int(input())
for ttt in range(T) : solve()
``` | instruction | 0 | 94,097 | 19 | 188,194 |
No | output | 1 | 94,097 | 19 | 188,195 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.
Who wins if both participants play optimally?
Alice and Bob would like to play several games, so you should determine the winner in each game.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of games. Next T lines contain one game per line. All games are independent.
Each of the next T lines contains two integers n and k (0 β€ n β€ 109, 3 β€ k β€ 109) β the length of the strip and the constant denoting the third move, respectively.
Output
For each game, print Alice if Alice wins this game and Bob otherwise.
Example
Input
4
0 3
3 3
3 4
4 4
Output
Bob
Alice
Bob
Alice | instruction | 0 | 94,478 | 19 | 188,956 |
Tags: games, math
Correct Solution:
```
def solve():
[n, k] = (int(x) for x in input().split())
if k % 3 != 0:
if n % 3 == 0:
print('Bob')
else:
print('Alice')
else:
tc = k // 3
n = n % (1 + 3 * tc)
if n == 3 * tc:
print('Alice')
else:
if n % 3 == 0:
print('Bob')
else:
print('Alice')
t = int(input())
for _ in range(t):
solve()
``` | output | 1 | 94,478 | 19 | 188,957 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.
Who wins if both participants play optimally?
Alice and Bob would like to play several games, so you should determine the winner in each game.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of games. Next T lines contain one game per line. All games are independent.
Each of the next T lines contains two integers n and k (0 β€ n β€ 109, 3 β€ k β€ 109) β the length of the strip and the constant denoting the third move, respectively.
Output
For each game, print Alice if Alice wins this game and Bob otherwise.
Example
Input
4
0 3
3 3
3 4
4 4
Output
Bob
Alice
Bob
Alice | instruction | 0 | 94,479 | 19 | 188,958 |
Tags: games, math
Correct Solution:
```
T = int(input())
for i in range(T):
n, k = list(map(int, input().split()))
if k % 3 != 0:
if n % 3 == 0:
print("Bob")
else:
print("Alice")
else:
quotient = k + 1
remainder = n % quotient
if remainder % 3 == 0 and remainder != k:
print("Bob")
else:
print("Alice")
``` | output | 1 | 94,479 | 19 | 188,959 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.
Who wins if both participants play optimally?
Alice and Bob would like to play several games, so you should determine the winner in each game.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of games. Next T lines contain one game per line. All games are independent.
Each of the next T lines contains two integers n and k (0 β€ n β€ 109, 3 β€ k β€ 109) β the length of the strip and the constant denoting the third move, respectively.
Output
For each game, print Alice if Alice wins this game and Bob otherwise.
Example
Input
4
0 3
3 3
3 4
4 4
Output
Bob
Alice
Bob
Alice | instruction | 0 | 94,480 | 19 | 188,960 |
Tags: games, math
Correct Solution:
```
def solve(n, k):
sol = [None] * (n+1)
for i in range(n+1):
if i == 0:
sol[i] = 'B'
continue
for offset in (1, 2, k):
if i - offset >= 0 and sol[i - offset] == 'B':
sol[i] = 'A'
break
else:
sol[i] = 'B'
print(''.join(sol))
return sol[-1]
def solve2(n, k):
if k % 3 > 0:
return n % 3 != 0
d = k // 3 - 1
m = d*3 + 4 # BAA * d + BAAA
r = n % m
return r % 3 != 0 or r == m - 1
T = int(input().strip())
for _ in range(T):
n, k = list(map(int, input().strip().split()))
print("Alice" if solve2(n,k) else "Bob")
``` | output | 1 | 94,480 | 19 | 188,961 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.
Who wins if both participants play optimally?
Alice and Bob would like to play several games, so you should determine the winner in each game.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of games. Next T lines contain one game per line. All games are independent.
Each of the next T lines contains two integers n and k (0 β€ n β€ 109, 3 β€ k β€ 109) β the length of the strip and the constant denoting the third move, respectively.
Output
For each game, print Alice if Alice wins this game and Bob otherwise.
Example
Input
4
0 3
3 3
3 4
4 4
Output
Bob
Alice
Bob
Alice | instruction | 0 | 94,481 | 19 | 188,962 |
Tags: games, math
Correct Solution:
```
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
def rl(proc=None):
if proc is not None:
return proc(sys.stdin.readline())
else:
return sys.stdin.readline().rstrip()
def srl(proc=None):
if proc is not None:
return list(map(proc, rl().split()))
else:
return rl().split()
def solve(n, k):
if k % 3:
return n % 3
n = n % (k + 1)
if n == k:
return 1
return n % 3
def main():
T = rl(int)
for t in range(1, T+1):
n, k = srl(int)
print('Alice' if solve(n, k) else 'Bob')
if __name__ == '__main__':
main()
``` | output | 1 | 94,481 | 19 | 188,963 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.
Who wins if both participants play optimally?
Alice and Bob would like to play several games, so you should determine the winner in each game.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of games. Next T lines contain one game per line. All games are independent.
Each of the next T lines contains two integers n and k (0 β€ n β€ 109, 3 β€ k β€ 109) β the length of the strip and the constant denoting the third move, respectively.
Output
For each game, print Alice if Alice wins this game and Bob otherwise.
Example
Input
4
0 3
3 3
3 4
4 4
Output
Bob
Alice
Bob
Alice | instruction | 0 | 94,482 | 19 | 188,964 |
Tags: games, math
Correct Solution:
```
import sys
import math as mt
import bisect
input=sys.stdin.readline
t=int(input())
def issub(str1,str2):
m = len(str1)
n = len(str2)
j = 0
i = 0
while j<m and i<n:
if str1[j] == str2[i]:
j=j+1
i=i+1
return j==m
def ncr_util():
inv[0]=inv[1]=1
fact[0]=fact[1]=1
for i in range(2,300001):
inv[i]=(inv[i%p]*(p-p//i))%p
for i in range(1,300001):
inv[i]=(inv[i-1]*inv[i])%p
fact[i]=(fact[i-1]*i)%p
def solve():
s2='Bob'
s1='Alice'
if k%3!=0:
if n%3==0:
return (s2)
else:
return(s1)
else:
x=n%(k+1)
if x%3==0 and x!=k:
return (s2)
else:
return s1
for _ in range(t):
#n=int(input())
n,k=(map(int,input().split()))
#n1=n
#a=int(input())
#b=int(input())
#a,b,c,r=map(int,input().split())
#x2,y2=map(int,input().split())
#n=int(input())
#s=input()
#s1=input()
#p=input()
#l=list(map(int,input().split()))
#l2=list(map(int,input().split()))
#l=str(n)
#l.sort(reverse=True)
#l2.sort(reverse=True)
#l1.sort(reverse=True)
print(solve())
``` | output | 1 | 94,482 | 19 | 188,965 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.
Who wins if both participants play optimally?
Alice and Bob would like to play several games, so you should determine the winner in each game.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of games. Next T lines contain one game per line. All games are independent.
Each of the next T lines contains two integers n and k (0 β€ n β€ 109, 3 β€ k β€ 109) β the length of the strip and the constant denoting the third move, respectively.
Output
For each game, print Alice if Alice wins this game and Bob otherwise.
Example
Input
4
0 3
3 3
3 4
4 4
Output
Bob
Alice
Bob
Alice | instruction | 0 | 94,483 | 19 | 188,966 |
Tags: games, math
Correct Solution:
```
t = int(input())
for i in range(t):
n,k = map(int,input().split())
if k % 3 != 0 or k > n:
print('Bob' if n % 3 == 0 else 'Alice')
else:
print('Bob' if (n % (k + 1)) % 3 == 0 and (n % (k + 1)) != k else 'Alice')
``` | output | 1 | 94,483 | 19 | 188,967 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.
Who wins if both participants play optimally?
Alice and Bob would like to play several games, so you should determine the winner in each game.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of games. Next T lines contain one game per line. All games are independent.
Each of the next T lines contains two integers n and k (0 β€ n β€ 109, 3 β€ k β€ 109) β the length of the strip and the constant denoting the third move, respectively.
Output
For each game, print Alice if Alice wins this game and Bob otherwise.
Example
Input
4
0 3
3 3
3 4
4 4
Output
Bob
Alice
Bob
Alice | instruction | 0 | 94,484 | 19 | 188,968 |
Tags: games, math
Correct Solution:
```
'''
# Sample code to perform I/O:
name = input() # Reading input from STDIN
print('Hi, %s.' % name) # Writing output to STDOUT
# Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
'''
# Write your code here
''' CODED WITH LOVE BY SATYAM KUMAR '''
from sys import stdin, stdout
import heapq
import cProfile, math
from collections import Counter, defaultdict, deque
from bisect import bisect_left, bisect, bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as op
from functools import reduce
import sys
sys.setrecursionlimit(10 ** 6) # max depth of recursion
threading.stack_size(2 ** 27) # new thread will get stack of such size
fac_warm_up = False
printHeap = str()
memory_constrained = False
P = 10 ** 9 + 7
class MergeFind:
def __init__(self, n):
self.parent = list(range(n))
self.size = [1] * n
self.num_sets = n
self.lista = [[_] for _ in range(n)]
def find(self, a):
to_update = []
while a != self.parent[a]:
to_update.append(a)
a = self.parent[a]
for b in to_update:
self.parent[b] = a
return self.parent[a]
def merge(self, a, b):
a = self.find(a)
b = self.find(b)
if a == b:
return
if self.size[a] < self.size[b]:
a, b = b, a
self.num_sets -= 1
self.parent[b] = a
self.size[a] += self.size[b]
self.lista[a] += self.lista[b]
def set_size(self, a):
return self.size[self.find(a)]
def __len__(self):
return self.num_sets
def display(string_to_print):
stdout.write(str(string_to_print) + "\n")
def prime_factors(n): # n**0.5 complex
factors = dict()
for i in range(2, math.ceil(math.sqrt(n)) + 1):
while n % i == 0:
if i in factors:
factors[i] += 1
else:
factors[i] = 1
n = n // i
if n > 2:
factors[n] = 1
return (factors)
def all_factors(n):
return set(reduce(list.__add__,
([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
def fibonacci_modP(n, MOD):
if n < 2: return 1
return (cached_fn(fibonacci_modP, (n + 1) // 2, MOD) * cached_fn(fibonacci_modP, n // 2, MOD) + cached_fn(
fibonacci_modP, (n - 1) // 2, MOD) * cached_fn(fibonacci_modP, (n - 2) // 2, MOD)) % MOD
def factorial_modP_Wilson(n, p):
if (p <= n):
return 0
res = (p - 1)
for i in range(n + 1, p):
res = (res * cached_fn(InverseEuler, i, p)) % p
return res
def binary(n, digits=20):
b = bin(n)[2:]
b = '0' * (digits - len(b)) + b
return b
def is_prime(n):
"""Returns True if n is prime."""
if n < 4:
return True
if n % 2 == 0:
return False
if n % 3 == 0:
return False
i = 5
w = 2
while i * i <= n:
if n % i == 0:
return False
i += w
w = 6 - w
return True
def generate_primes(n):
prime = [True for i in range(n + 1)]
p = 2
while p * p <= n:
if prime[p]:
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 1
return prime
factorial_modP = []
def warm_up_fac(MOD):
global factorial_modP, fac_warm_up
if fac_warm_up: return
factorial_modP = [1 for _ in range(fac_warm_up_size + 1)]
for i in range(2, fac_warm_up_size):
factorial_modP[i] = (factorial_modP[i - 1] * i) % MOD
fac_warm_up = True
def InverseEuler(n, MOD):
return pow(n, MOD - 2, MOD)
def nCr(n, r, MOD):
global fac_warm_up, factorial_modP
if not fac_warm_up:
warm_up_fac(MOD)
fac_warm_up = True
return (factorial_modP[n] * (
(pow(factorial_modP[r], MOD - 2, MOD) * pow(factorial_modP[n - r], MOD - 2, MOD)) % MOD)) % MOD
def test_print(*args):
if testingMode:
print(args)
def display_list(list1, sep=" "):
stdout.write(sep.join(map(str, list1)) + "\n")
def display_2D_list(li):
for i in li:
print(i)
def prefix_sum(li):
sm = 0
res = []
for i in li:
sm += i
res.append(sm)
return res
def get_int():
return int(stdin.readline().strip())
def get_tuple():
return map(int, stdin.readline().split())
def get_list():
return list(map(int, stdin.readline().split()))
memory = dict()
def clear_cache():
global memory
memory = dict()
def cached_fn(fn, *args):
global memory
if args in memory:
return memory[args]
else:
result = fn(*args)
memory[args] = result
return result
def ncr(n, r):
return math.factorial(n) / (math.factorial(n - r) * math.factorial(r))
def binary_search(i, li):
fn = lambda x: li[x] - x // i
x = -1
b = len(li)
while b >= 1:
while b + x < len(li) and fn(b + x) > 0: # Change this condition 2 to whatever you like
x += b
b = b // 2
return x
# -------------------------------------------------------------- MAIN PROGRAM
TestCases = True
fac_warm_up_size = 10 ** 5 + 100
optimise_for_recursion = False # Can not be used clubbed with TestCases WHen using recursive functions, use Python 3
def main():
n, k = get_tuple()
if k%3!=0:
print("Alice") if n%3!=0 else print("Bob")
else:
mod = n%(k+1)
print("Bob") if mod%3==0 and mod<k else print("Alice")
# --------------------------------------------------------------------- END=
if TestCases:
for i in range(get_int()):
main()
else:
main() if not optimise_for_recursion else threading.Thread(target=main).start()
``` | output | 1 | 94,484 | 19 | 188,969 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.
Who wins if both participants play optimally?
Alice and Bob would like to play several games, so you should determine the winner in each game.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of games. Next T lines contain one game per line. All games are independent.
Each of the next T lines contains two integers n and k (0 β€ n β€ 109, 3 β€ k β€ 109) β the length of the strip and the constant denoting the third move, respectively.
Output
For each game, print Alice if Alice wins this game and Bob otherwise.
Example
Input
4
0 3
3 3
3 4
4 4
Output
Bob
Alice
Bob
Alice | instruction | 0 | 94,485 | 19 | 188,970 |
Tags: games, math
Correct Solution:
```
a = int(input())
for i in range(a):
b, c = map(int,input().split())
if c % 3 == 0:
if b % (c+1) == c:
print("Alice")
elif (b % (c+1)) % 3 == 0:
print("Bob")
else:
print("Alice")
else:
if b % 3 == 0:
print("Bob")
else:
print("Alice")
``` | output | 1 | 94,485 | 19 | 188,971 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.
Who wins if both participants play optimally?
Alice and Bob would like to play several games, so you should determine the winner in each game.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of games. Next T lines contain one game per line. All games are independent.
Each of the next T lines contains two integers n and k (0 β€ n β€ 109, 3 β€ k β€ 109) β the length of the strip and the constant denoting the third move, respectively.
Output
For each game, print Alice if Alice wins this game and Bob otherwise.
Example
Input
4
0 3
3 3
3 4
4 4
Output
Bob
Alice
Bob
Alice
Submitted Solution:
```
t=int(input())
while(t):
n,k=map(int,input().split())
if(k%3==0):
n=n%(k+1)
if(n%3==0 and n!=k):
print("Bob")
else:
print("Alice")
t-=1
``` | instruction | 0 | 94,486 | 19 | 188,972 |
Yes | output | 1 | 94,486 | 19 | 188,973 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.
Who wins if both participants play optimally?
Alice and Bob would like to play several games, so you should determine the winner in each game.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of games. Next T lines contain one game per line. All games are independent.
Each of the next T lines contains two integers n and k (0 β€ n β€ 109, 3 β€ k β€ 109) β the length of the strip and the constant denoting the third move, respectively.
Output
For each game, print Alice if Alice wins this game and Bob otherwise.
Example
Input
4
0 3
3 3
3 4
4 4
Output
Bob
Alice
Bob
Alice
Submitted Solution:
```
for _ in range(int(input())):
n,k = [*map(int, input().split())]
if k % 3 != 0:
loss = ((n%3) == 0)
else:
cycle_length = ((k // 3) - 1) * 3 + 4
n = n % cycle_length
loss = (((n%3) == 0) and (n != cycle_length-1))
print("Bob" if loss else "Alice")
``` | instruction | 0 | 94,487 | 19 | 188,974 |
Yes | output | 1 | 94,487 | 19 | 188,975 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.
Who wins if both participants play optimally?
Alice and Bob would like to play several games, so you should determine the winner in each game.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of games. Next T lines contain one game per line. All games are independent.
Each of the next T lines contains two integers n and k (0 β€ n β€ 109, 3 β€ k β€ 109) β the length of the strip and the constant denoting the third move, respectively.
Output
For each game, print Alice if Alice wins this game and Bob otherwise.
Example
Input
4
0 3
3 3
3 4
4 4
Output
Bob
Alice
Bob
Alice
Submitted Solution:
```
T = int(input())
while T:
T -= 1
str = list(map(int, input().split()))
n = str[0]
k = str[1]
if k % 3 != 0:
print("Bob" if n % 3 == 0 else "Alice")
else:
n = n%(k+1)
if n==k or n%3!=0:
print("Alice")
else:
print("Bob")
``` | instruction | 0 | 94,488 | 19 | 188,976 |
Yes | output | 1 | 94,488 | 19 | 188,977 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.
Who wins if both participants play optimally?
Alice and Bob would like to play several games, so you should determine the winner in each game.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of games. Next T lines contain one game per line. All games are independent.
Each of the next T lines contains two integers n and k (0 β€ n β€ 109, 3 β€ k β€ 109) β the length of the strip and the constant denoting the third move, respectively.
Output
For each game, print Alice if Alice wins this game and Bob otherwise.
Example
Input
4
0 3
3 3
3 4
4 4
Output
Bob
Alice
Bob
Alice
Submitted Solution:
```
for _ in range(int(input())):
n,k = map(int,input().split())
if(k % 3 == 0):
n %= (k+1)
if(n % 3 == 0 and n != k):
print("Bob")
else:
print("Alice")
``` | instruction | 0 | 94,489 | 19 | 188,978 |
Yes | output | 1 | 94,489 | 19 | 188,979 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.
Who wins if both participants play optimally?
Alice and Bob would like to play several games, so you should determine the winner in each game.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of games. Next T lines contain one game per line. All games are independent.
Each of the next T lines contains two integers n and k (0 β€ n β€ 109, 3 β€ k β€ 109) β the length of the strip and the constant denoting the third move, respectively.
Output
For each game, print Alice if Alice wins this game and Bob otherwise.
Example
Input
4
0 3
3 3
3 4
4 4
Output
Bob
Alice
Bob
Alice
Submitted Solution:
```
n = int(input())
for i in range(n):
a, b = map(int, input().split())
if a == 0:
print("Bob")
continue
if a <= 2 or a == b:
print("Alice")
continue
if a%3==0 or a%(b+1)==0 or a%(b+2)==0:
print("Bob")
continue
else:
print("Alice")
``` | instruction | 0 | 94,490 | 19 | 188,980 |
No | output | 1 | 94,490 | 19 | 188,981 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.
Who wins if both participants play optimally?
Alice and Bob would like to play several games, so you should determine the winner in each game.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of games. Next T lines contain one game per line. All games are independent.
Each of the next T lines contains two integers n and k (0 β€ n β€ 109, 3 β€ k β€ 109) β the length of the strip and the constant denoting the third move, respectively.
Output
For each game, print Alice if Alice wins this game and Bob otherwise.
Example
Input
4
0 3
3 3
3 4
4 4
Output
Bob
Alice
Bob
Alice
Submitted Solution:
```
t = int(input())
for i in range(t):
n,k = map(int,input().split())
if k % 3 != 0:
if n % 3 == 0:
print('Bob')
else:
print('Alice')
else:
if n % 4 == 0:
print('Bob')
else:
print('Alice')
``` | instruction | 0 | 94,491 | 19 | 188,982 |
No | output | 1 | 94,491 | 19 | 188,983 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.
Who wins if both participants play optimally?
Alice and Bob would like to play several games, so you should determine the winner in each game.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of games. Next T lines contain one game per line. All games are independent.
Each of the next T lines contains two integers n and k (0 β€ n β€ 109, 3 β€ k β€ 109) β the length of the strip and the constant denoting the third move, respectively.
Output
For each game, print Alice if Alice wins this game and Bob otherwise.
Example
Input
4
0 3
3 3
3 4
4 4
Output
Bob
Alice
Bob
Alice
Submitted Solution:
```
Q=int(input())
for i in range(Q):
n,m=map(int,input().split())
if n<m:
if n%3==0:
print("Bob")
else:
print("Alice")
elif n ==m:
print("Alice")
else:
if m%3==0:
print("Alice")
elif m%3!=0 and n%3==0:
print("Bob")
else:
print("Alice")
``` | instruction | 0 | 94,492 | 19 | 188,984 |
No | output | 1 | 94,492 | 19 | 188,985 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.
Who wins if both participants play optimally?
Alice and Bob would like to play several games, so you should determine the winner in each game.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of games. Next T lines contain one game per line. All games are independent.
Each of the next T lines contains two integers n and k (0 β€ n β€ 109, 3 β€ k β€ 109) β the length of the strip and the constant denoting the third move, respectively.
Output
For each game, print Alice if Alice wins this game and Bob otherwise.
Example
Input
4
0 3
3 3
3 4
4 4
Output
Bob
Alice
Bob
Alice
Submitted Solution:
```
T = int(input())
l = []
for i in range(T):
n, k = map(int, input().split())
if n == 0:
x = 2
else:
x = n % k
l.append(x)
for i in range(T):
if l[i] == 0:
print("Alice")
else:
print("Bob")
``` | instruction | 0 | 94,493 | 19 | 188,986 |
No | output | 1 | 94,493 | 19 | 188,987 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A famous gang of pirates, Sea Dogs, has come back to their hideout from one of their extravagant plunders. They want to split their treasure fairly amongst themselves, that is why You, their trusted financial advisor, devised a game to help them:
All of them take a sit at their round table, some of them with the golden coins they have just stolen. At each iteration of the game if one of them has equal or more than 2 coins, he is eligible to the splitting and he gives one coin to each pirate sitting next to him. If there are more candidates (pirates with equal or more than 2 coins) then You are the one that chooses which one of them will do the splitting in that iteration. The game ends when there are no more candidates eligible to do the splitting.
Pirates can call it a day, only when the game ends. Since they are beings with a finite amount of time at their disposal, they would prefer if the game that they are playing can end after finite iterations, and if so, they call it a good game. On the other hand, if no matter how You do the splitting, the game cannot end in finite iterations, they call it a bad game. Can You help them figure out before they start playing if the game will be good or bad?
Input
The first line of input contains two integer numbers n and k (1 β€ n β€ 10^{9}, 0 β€ k β€ 2β
10^5), where n denotes total number of pirates and k is the number of pirates that have any coins.
The next k lines of input contain integers a_i and b_i (1 β€ a_i β€ n, 1 β€ b_i β€ 10^{9}), where a_i denotes the index of the pirate sitting at the round table (n and 1 are neighbours) and b_i the total number of coins that pirate a_i has at the start of the game.
Output
Print 1 if the game is a good game: There is a way to do the splitting so the game ends after finite number of iterations.
Print -1 if the game is a bad game: No matter how You do the splitting the game does not end in finite number of iterations.
Examples
Input
4 2
1 2
2 2
Output
1
Input
6 2
2 3
4 1
Output
1
Input
3 2
1 1
2 2
Output
-1
Note
In the third example the game has no end, because You always only have only one candidate, after whose splitting you end up in the same position as the starting one. | instruction | 0 | 94,578 | 19 | 189,156 |
Tags: math
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
def main():
pass
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
n, k = map(int, input().split())
coins = 0
pos = 0
for _ in range(k):
a, b = map(int, input().split())
coins += b
pos += a * b
pos %= n
if coins < n or coins == n and (pos - (n*n-n)//2) % n == 0:
print(1)
else:
print(-1)
``` | output | 1 | 94,578 | 19 | 189,157 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A famous gang of pirates, Sea Dogs, has come back to their hideout from one of their extravagant plunders. They want to split their treasure fairly amongst themselves, that is why You, their trusted financial advisor, devised a game to help them:
All of them take a sit at their round table, some of them with the golden coins they have just stolen. At each iteration of the game if one of them has equal or more than 2 coins, he is eligible to the splitting and he gives one coin to each pirate sitting next to him. If there are more candidates (pirates with equal or more than 2 coins) then You are the one that chooses which one of them will do the splitting in that iteration. The game ends when there are no more candidates eligible to do the splitting.
Pirates can call it a day, only when the game ends. Since they are beings with a finite amount of time at their disposal, they would prefer if the game that they are playing can end after finite iterations, and if so, they call it a good game. On the other hand, if no matter how You do the splitting, the game cannot end in finite iterations, they call it a bad game. Can You help them figure out before they start playing if the game will be good or bad?
Input
The first line of input contains two integer numbers n and k (1 β€ n β€ 10^{9}, 0 β€ k β€ 2β
10^5), where n denotes total number of pirates and k is the number of pirates that have any coins.
The next k lines of input contain integers a_i and b_i (1 β€ a_i β€ n, 1 β€ b_i β€ 10^{9}), where a_i denotes the index of the pirate sitting at the round table (n and 1 are neighbours) and b_i the total number of coins that pirate a_i has at the start of the game.
Output
Print 1 if the game is a good game: There is a way to do the splitting so the game ends after finite number of iterations.
Print -1 if the game is a bad game: No matter how You do the splitting the game does not end in finite number of iterations.
Examples
Input
4 2
1 2
2 2
Output
1
Input
6 2
2 3
4 1
Output
1
Input
3 2
1 1
2 2
Output
-1
Note
In the third example the game has no end, because You always only have only one candidate, after whose splitting you end up in the same position as the starting one. | instruction | 0 | 94,579 | 19 | 189,158 |
Tags: math
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def main():
n, k = [int(x) for x in input().split()]
p, s = 0, 0
for _ in range(k):
a, b = [int(x) for x in input().split()]
s += b
p += a * b
p %= n
print(['-1', '1'][s < n or (s == n and p == (n * (n + 1) // 2) % n)])
main()
``` | output | 1 | 94,579 | 19 | 189,159 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A famous gang of pirates, Sea Dogs, has come back to their hideout from one of their extravagant plunders. They want to split their treasure fairly amongst themselves, that is why You, their trusted financial advisor, devised a game to help them:
All of them take a sit at their round table, some of them with the golden coins they have just stolen. At each iteration of the game if one of them has equal or more than 2 coins, he is eligible to the splitting and he gives one coin to each pirate sitting next to him. If there are more candidates (pirates with equal or more than 2 coins) then You are the one that chooses which one of them will do the splitting in that iteration. The game ends when there are no more candidates eligible to do the splitting.
Pirates can call it a day, only when the game ends. Since they are beings with a finite amount of time at their disposal, they would prefer if the game that they are playing can end after finite iterations, and if so, they call it a good game. On the other hand, if no matter how You do the splitting, the game cannot end in finite iterations, they call it a bad game. Can You help them figure out before they start playing if the game will be good or bad?
Input
The first line of input contains two integer numbers n and k (1 β€ n β€ 10^{9}, 0 β€ k β€ 2β
10^5), where n denotes total number of pirates and k is the number of pirates that have any coins.
The next k lines of input contain integers a_i and b_i (1 β€ a_i β€ n, 1 β€ b_i β€ 10^{9}), where a_i denotes the index of the pirate sitting at the round table (n and 1 are neighbours) and b_i the total number of coins that pirate a_i has at the start of the game.
Output
Print 1 if the game is a good game: There is a way to do the splitting so the game ends after finite number of iterations.
Print -1 if the game is a bad game: No matter how You do the splitting the game does not end in finite number of iterations.
Examples
Input
4 2
1 2
2 2
Output
1
Input
6 2
2 3
4 1
Output
1
Input
3 2
1 1
2 2
Output
-1
Note
In the third example the game has no end, because You always only have only one candidate, after whose splitting you end up in the same position as the starting one.
Submitted Solution:
```
n, k = map(int, input().split())
table = {}
for i in range(k):
a, b = map(int, input().split())
table[a] = b
total = 0
for key,value in table.items():
total += value
print(total)
if total % k == 0:
print(1)
else:
print(-1)
``` | instruction | 0 | 94,580 | 19 | 189,160 |
No | output | 1 | 94,580 | 19 | 189,161 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A famous gang of pirates, Sea Dogs, has come back to their hideout from one of their extravagant plunders. They want to split their treasure fairly amongst themselves, that is why You, their trusted financial advisor, devised a game to help them:
All of them take a sit at their round table, some of them with the golden coins they have just stolen. At each iteration of the game if one of them has equal or more than 2 coins, he is eligible to the splitting and he gives one coin to each pirate sitting next to him. If there are more candidates (pirates with equal or more than 2 coins) then You are the one that chooses which one of them will do the splitting in that iteration. The game ends when there are no more candidates eligible to do the splitting.
Pirates can call it a day, only when the game ends. Since they are beings with a finite amount of time at their disposal, they would prefer if the game that they are playing can end after finite iterations, and if so, they call it a good game. On the other hand, if no matter how You do the splitting, the game cannot end in finite iterations, they call it a bad game. Can You help them figure out before they start playing if the game will be good or bad?
Input
The first line of input contains two integer numbers n and k (1 β€ n β€ 10^{9}, 0 β€ k β€ 2β
10^5), where n denotes total number of pirates and k is the number of pirates that have any coins.
The next k lines of input contain integers a_i and b_i (1 β€ a_i β€ n, 1 β€ b_i β€ 10^{9}), where a_i denotes the index of the pirate sitting at the round table (n and 1 are neighbours) and b_i the total number of coins that pirate a_i has at the start of the game.
Output
Print 1 if the game is a good game: There is a way to do the splitting so the game ends after finite number of iterations.
Print -1 if the game is a bad game: No matter how You do the splitting the game does not end in finite number of iterations.
Examples
Input
4 2
1 2
2 2
Output
1
Input
6 2
2 3
4 1
Output
1
Input
3 2
1 1
2 2
Output
-1
Note
In the third example the game has no end, because You always only have only one candidate, after whose splitting you end up in the same position as the starting one.
Submitted Solution:
```
import sys;input=sys.stdin.readline
N, K = map(int, input().split())
s = 0
X = []
zenb1=1
for _ in range(K):
a, b = map(int, input().split())
X.append((a, b))
s += b
if b != 1:
zenb1 = 0
X.sort(key=lambda x:x[0])
f = 0
ff = 0
T = []
ba = None
for i in range(K):
a, b = X[i]
if a-1 == ba:
T[-1].append((a, b))
else:
T.append([(a, b)])
ba = a
cc = []
for t in T:
if len(t) == 1:
if t[0][1] == 3:
continue
elif t[0][0] == 1 or t[-1][0] == N:
cc.append(t)
else:
ff = 1
break
else:
ft = 1
for x in t[1:-1]:
if x[1] != 1:
ft = 0
break
if (t[0][1] == 2 and t[-1][1] == 2) and ft:
continue
elif t[0][0] == 1 or t[-1][0] == N:
cc.append(t)
else:
ff = 1
break
if len(cc) == 1:
ff = 1
elif len(cc) == 2:
t = cc[0]+cc[1]
ft = 1
for x in t[1:-1]:
if x[1] != 1:
ft = 0
break
if (t[0][1] == 2 and t[-1][1] == 2) and ft:
pass
else:
ff = 1
if s < N:
print(1)
elif s == N:
if zenb1:
print(1)
elif ff:
print(-1)
else:
print(1)
else:
print(-1)
``` | instruction | 0 | 94,581 | 19 | 189,162 |
No | output | 1 | 94,581 | 19 | 189,163 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A famous gang of pirates, Sea Dogs, has come back to their hideout from one of their extravagant plunders. They want to split their treasure fairly amongst themselves, that is why You, their trusted financial advisor, devised a game to help them:
All of them take a sit at their round table, some of them with the golden coins they have just stolen. At each iteration of the game if one of them has equal or more than 2 coins, he is eligible to the splitting and he gives one coin to each pirate sitting next to him. If there are more candidates (pirates with equal or more than 2 coins) then You are the one that chooses which one of them will do the splitting in that iteration. The game ends when there are no more candidates eligible to do the splitting.
Pirates can call it a day, only when the game ends. Since they are beings with a finite amount of time at their disposal, they would prefer if the game that they are playing can end after finite iterations, and if so, they call it a good game. On the other hand, if no matter how You do the splitting, the game cannot end in finite iterations, they call it a bad game. Can You help them figure out before they start playing if the game will be good or bad?
Input
The first line of input contains two integer numbers n and k (1 β€ n β€ 10^{9}, 0 β€ k β€ 2β
10^5), where n denotes total number of pirates and k is the number of pirates that have any coins.
The next k lines of input contain integers a_i and b_i (1 β€ a_i β€ n, 1 β€ b_i β€ 10^{9}), where a_i denotes the index of the pirate sitting at the round table (n and 1 are neighbours) and b_i the total number of coins that pirate a_i has at the start of the game.
Output
Print 1 if the game is a good game: There is a way to do the splitting so the game ends after finite number of iterations.
Print -1 if the game is a bad game: No matter how You do the splitting the game does not end in finite number of iterations.
Examples
Input
4 2
1 2
2 2
Output
1
Input
6 2
2 3
4 1
Output
1
Input
3 2
1 1
2 2
Output
-1
Note
In the third example the game has no end, because You always only have only one candidate, after whose splitting you end up in the same position as the starting one.
Submitted Solution:
```
from sys import stdin,stdout
from collections import defaultdict as dd
from copy import deepcopy
from math import ceil
input=stdin.readline
mod=10**9+7
for _ in range(1):
n,k=map(int,input().split())
oc=0
r=0
for i in range(k):
a,b= list(map(int,input().split()))
r+=b
if b==1:
oc+=1
if r<n:
print(1)
elif r==n:
if n%2==1:
if oc==n:
print(1)
else:
print(-1)
else:
print(1)
else:
print(-1)
``` | instruction | 0 | 94,582 | 19 | 189,164 |
No | output | 1 | 94,582 | 19 | 189,165 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A famous gang of pirates, Sea Dogs, has come back to their hideout from one of their extravagant plunders. They want to split their treasure fairly amongst themselves, that is why You, their trusted financial advisor, devised a game to help them:
All of them take a sit at their round table, some of them with the golden coins they have just stolen. At each iteration of the game if one of them has equal or more than 2 coins, he is eligible to the splitting and he gives one coin to each pirate sitting next to him. If there are more candidates (pirates with equal or more than 2 coins) then You are the one that chooses which one of them will do the splitting in that iteration. The game ends when there are no more candidates eligible to do the splitting.
Pirates can call it a day, only when the game ends. Since they are beings with a finite amount of time at their disposal, they would prefer if the game that they are playing can end after finite iterations, and if so, they call it a good game. On the other hand, if no matter how You do the splitting, the game cannot end in finite iterations, they call it a bad game. Can You help them figure out before they start playing if the game will be good or bad?
Input
The first line of input contains two integer numbers n and k (1 β€ n β€ 10^{9}, 0 β€ k β€ 2β
10^5), where n denotes total number of pirates and k is the number of pirates that have any coins.
The next k lines of input contain integers a_i and b_i (1 β€ a_i β€ n, 1 β€ b_i β€ 10^{9}), where a_i denotes the index of the pirate sitting at the round table (n and 1 are neighbours) and b_i the total number of coins that pirate a_i has at the start of the game.
Output
Print 1 if the game is a good game: There is a way to do the splitting so the game ends after finite number of iterations.
Print -1 if the game is a bad game: No matter how You do the splitting the game does not end in finite number of iterations.
Examples
Input
4 2
1 2
2 2
Output
1
Input
6 2
2 3
4 1
Output
1
Input
3 2
1 1
2 2
Output
-1
Note
In the third example the game has no end, because You always only have only one candidate, after whose splitting you end up in the same position as the starting one.
Submitted Solution:
```
a,b = map(int, input().split())
coins = []
count = 0
for i in range(a):
coins.append(0)
for j in range(b):
ind, coin = map(int,input().split())
coins[ind-1] = coin
def solve(count, coins):
print(coins)
if count > 1000:
print(-1)
elif all(x==coins[0] for x in coins):
print(1)
elif all(p < 2 for p in coins):
print(1)
else:
try:
graterIndex = [n for n,i in enumerate(coins) if i>=2 ][0]
if graterIndex == 0:
coins[graterIndex] -=2
coins[len(coins)-1] +=1
coins[1] +=1
count +=1
solve(count, coins)
elif graterIndex == len(coins)-1:
coins[graterIndex] -=2
coins[0] +=1
coins[len(coins)-2] +=1
count +=1
solve(count, coins)
else:
coins[graterIndex] -=2
coins[graterIndex-1] +=1
coins[graterIndex+1] +=1
count +=1
solve(count, coins)
except:
if all(x==coins[0] for x in coins):
print(1)
else:
print(-1)
solve(0, coins)
``` | instruction | 0 | 94,583 | 19 | 189,166 |
No | output | 1 | 94,583 | 19 | 189,167 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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 (109 + 9).
Input
The single line contains three space-separated integers n, m and k (2 β€ k β€ n β€ 109; 0 β€ m β€ n).
Output
Print a single integer β the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109 + 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. | instruction | 0 | 94,711 | 19 | 189,422 |
Tags: binary search, greedy, math, matrices, number theory
Correct Solution:
```
n, m, k = map(int, input().split())
x, c, ic, ans, mod = min(m//(k-1), n-m), m, n-m, 0, 10**9 + 9
c = c - (k-1)*x
p, r = c//k, c%k
ans = ((((pow(2, p+1, mod) - 2 + mod)%mod) * (k%mod))%mod + (k-1)*x + r)%mod
print(ans)
``` | output | 1 | 94,711 | 19 | 189,423 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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 (109 + 9).
Input
The single line contains three space-separated integers n, m and k (2 β€ k β€ n β€ 109; 0 β€ m β€ n).
Output
Print a single integer β the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109 + 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. | instruction | 0 | 94,712 | 19 | 189,424 |
Tags: binary search, greedy, math, matrices, number theory
Correct Solution:
```
z = 10**9+9
n,m,k = map(int,input().split())
i = n-m
x = (n-k+1)//k
if k*i>=n-k+1:
print((n-i)%z)
else:
l = n-k+1
f = l-(i-1)*k-1
t = f//k
f = t*k
v = 2*(pow(2,t,z)-1)*k+(n-f-i)
print(v%z)
``` | output | 1 | 94,712 | 19 | 189,425 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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 (109 + 9).
Input
The single line contains three space-separated integers n, m and k (2 β€ k β€ n β€ 109; 0 β€ m β€ n).
Output
Print a single integer β the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109 + 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. | instruction | 0 | 94,713 | 19 | 189,426 |
Tags: binary search, greedy, math, matrices, number theory
Correct Solution:
```
n, corecte, k = map(int, input().split())
incorecte = n - corecte
mod = 10**9 + 9
corecte_consecutive = max(0, n - incorecte * k)
dublari = corecte_consecutive // k
corecte_ramase = corecte - corecte_consecutive
def power(b, exp):
if exp == 0: return 1
half = power(b, exp//2)
if exp%2 == 0: return (half*half) % mod
return (half*half*b) % mod
score = (power(2, dublari+1) - 2) * k + corecte_ramase + corecte_consecutive % k
print(score % mod)
``` | output | 1 | 94,713 | 19 | 189,427 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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 (109 + 9).
Input
The single line contains three space-separated integers n, m and k (2 β€ k β€ n β€ 109; 0 β€ m β€ n).
Output
Print a single integer β the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109 + 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. | instruction | 0 | 94,714 | 19 | 189,428 |
Tags: binary search, greedy, math, matrices, number theory
Correct Solution:
```
n,m,k = map(int,input().split())
chunks = n//k
freespots = chunks*(k-1) + n%k
if m <= freespots:
print(m)
else:
doubles = m-freespots
dchunks = doubles
chunks -= dchunks
total = (pow(2,dchunks,1000000009)-1)*k*2
total += n%k + chunks*(k-1)
print(total%1000000009)
``` | output | 1 | 94,714 | 19 | 189,429 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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 (109 + 9).
Input
The single line contains three space-separated integers n, m and k (2 β€ k β€ n β€ 109; 0 β€ m β€ n).
Output
Print a single integer β the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109 + 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. | instruction | 0 | 94,715 | 19 | 189,430 |
Tags: binary search, greedy, math, matrices, number theory
Correct Solution:
```
n,m,k=map(int,input().split())
mod=10**9+9
c=m
inc=n-m
rep=n//k
if rep<=inc:
print(c)
else:
rem_c=m-(k-1)*inc
score=(k-1)*inc
rep2=rem_c//k
score+=(pow(2,rep2+1,mod)-2)*k
rem_c-=rep2*k
score+=rem_c
print(score%mod)
``` | output | 1 | 94,715 | 19 | 189,431 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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 (109 + 9).
Input
The single line contains three space-separated integers n, m and k (2 β€ k β€ n β€ 109; 0 β€ m β€ n).
Output
Print a single integer β the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109 + 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. | instruction | 0 | 94,716 | 19 | 189,432 |
Tags: binary search, greedy, math, matrices, number theory
Correct Solution:
```
b = 10**9 + 9
def f(q):
x = q//1000
y = q%1000
num = 2**1000 % b
res = 1
for i in range(x):
res = (res * num) % b
res = (res * 2**y) %b
return res
def F(n,m,k):
r = n%k
if m <= n//k * (k-1) + r :
print(m%b)
else:
q = m - (n//k * (k-1) + r)
print((m + (f(q+1)-q-2)*k)%b)
n,m,k = [int(x) for x in input().split(' ')]
F(n,m,k)
``` | output | 1 | 94,716 | 19 | 189,433 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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 (109 + 9).
Input
The single line contains three space-separated integers n, m and k (2 β€ k β€ n β€ 109; 0 β€ m β€ n).
Output
Print a single integer β the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109 + 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. | instruction | 0 | 94,717 | 19 | 189,434 |
Tags: binary search, greedy, math, matrices, number theory
Correct Solution:
```
global MOD
MOD = int(1e9+9)
def pow(m, n):
ans = 1
while(n):
if n & 1:
ans = (ans*m) % MOD
m = (m*m) % MOD
n >>= 1
return ans
def quiz(n, m, k):
numk = n//k; # Divido mi problema en k pedazos
# Primer Problema
if numk*(k-1) >= m: # Si puedo efectuar al menos x * (k-1) respuestas correctas
return m; # retorno mi m que sera la cantidad de veces a cada k intentos que hago una respuesta correcta
rest_n = n-k*numk; # Analizo mi problema restante que seria n - k*numk(este es la cantidad de problemas q fueron analizados, es decir la cantidad de respuestas correctas que pude responder utilizando intentos a cada k intervalos)
rest_m = m-numk*(k-1); # analizo la cantidad de intentos que me quedan por efectuar, m - numk*(k-1), siendo num*(k-1) la cantidad de intentos realizados en el pedazo que se estaba analizando anteriormente, es decir m pedazos de tamanno k, donde se falla al menos 1 vez en cada caso para no llegar al valor de k
# Segundo Problema
if rest_m <= rest_n: # Si la cantidad de intentos que me queda es menor o igual que la cantidad de preguntas correctos que puedo hacer, entonces hago esta ultima pregunta correcta
return (numk*(k-1)+rest_m)%MOD; # y devuelvo la cantidad de puntos obtenidos en las numk*(k-1) veces q respondi bien y le sumo la cantidad de preguntas que me faltaban, tal que sumando estas preguntas no llego a k
# Tercer Problema
t = rest_m-rest_n; # Buscando diferencia de cantidad de aciertos restantes por efectuar con cantidad de aciertos restantes disponibles
num = rest_n+t*k; # Si a la cantidad de aciertos restantes disponibles restantes le sumamos la cantidad de aciertos que necesitamos que no se han podido efectuar hasta el momento multiplicada por k obtenemos
ans = (numk-t)*(k-1)%MOD; # Sumando a ans valores que no pertenecen a los k grupos(los que pertenecen a los k-1) (al hacer soluciones del final(grupo de tamanno menor q k) + soluciones que pertenecen a los k-1 grupos pero q la cantidad de respuestas correctas no es igual a k + grupos del comienzo los cuales la cantidad de aciertos es igual a k )
numk = num//k;
ans = (ans+num-numk*k)%MOD; # Sumando a ans valores que pertenecen a los k-1 grupos que no contienen k aciertos
return (m - numk*k + ((pow(2, numk+1) - 2) * k))%MOD
#ans = ans + 2*(k*(pow(2 , numk)-1))%MOD; # Sumando a ans valores que pertenecen a los k-1 grupos que contienen k aciertos, estos seran los puntos que se duplicaran
#return ans%MOD;
n, m, k = map(int, input().split())
print(quiz(n, m, k))
# linea 30
# A la cantidad de grupos de tamanno k que pueden formarse le restamos t, que seran la cantidad de grupos con al menos k-1 aciertos que se sumaran a la respuesta con unvalor de cantidad necesaria de estos grupos * k-1
# esto podra hacerse ya que al quedarnos t intentos que tenemos que efectuar correctamente, podemos asumir que los mismos se podran ubicar en los primeros x grupos de k respuestas correctas consecutivas , luego restamos la cantidad de respuestas que se exceden a la cantidad de grupos posibles de k intentos correctos y nos queda la cantidad de grupos que podrian tener k aciertos
# como nos interesan la cantidad de grupos que pueden tener k-1 aciertos multiplicamos esta resta anterior por k-1, obteniendo asi aquellos grupos que lenan exactamente k-1 aciertos correctamente
# este numero se lo sumamos a la cantidad total
``` | output | 1 | 94,717 | 19 | 189,435 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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 (109 + 9).
Input
The single line contains three space-separated integers n, m and k (2 β€ k β€ n β€ 109; 0 β€ m β€ n).
Output
Print a single integer β the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109 + 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. | instruction | 0 | 94,718 | 19 | 189,436 |
Tags: binary search, greedy, math, matrices, number theory
Correct Solution:
```
global MOD
MOD = int(1e9+9)
def pow(m, n):
ans = 1
while(n):
if n & 1:
ans = (ans*m) % MOD
m = (m*m) % MOD
n >>= 1
return ans
def getAns(n, m, k):
numk = n//k; # Divido mi problema en k pedazos
# first judgment
if numk*(k-1) >= m: # Si puedo efectuar al menos x * (k-1) respuestas correctas
return m; # retorno mi m que sera la cantidad de veces a cada k intentos que hago una respuesta correcta
rest_n = n-k*numk; # Analizo mi problema restante que seria n - k*numk(este es la cantidad de problemas q fueron analizados, es decir la cantidad de respuestas correctas que pude responder utilizando intentos a cada k intervalos)
rest_m = m-numk*(k-1); # analizo la cantidad de intentos que me quedan por efectuar, m - numk*(k-1), siendo num*(k-1) la cantidad de intentos realizados en el pedazo que se estaba analizando anteriormente, es decir m pedazos de tamanno k, donde se falla al menos 1 vez en cada caso para no llegar al valor de k
# second judgment
if rest_m <= rest_n: # Si la cantidad de intentos que me queda es menor o igual que la cantidad de preguntas correctos que puedo hacer, entonces hago esta ultima pregunta correcta
return (numk*(k-1)+rest_m)%MOD; # y devuelvo la cantidad de puntos obtenidos en las numk*(k-1) veces q respondi bien y le sumo la cantidad de preguntas que me faltaban, tal que sumando estas preguntas no llego a k
# Third judgment
t = rest_m-rest_n;
num = rest_n+t*k;
ans = (numk-t)*(k-1)%MOD;
numk = num//k;
ans = (ans+num-numk*k)%MOD;
ans = ans + 2*(k*(pow(2 , numk)-1))%MOD;
return ans%MOD;
n, m, k = map(int, input().split())
print(getAns(n, m, k))
``` | output | 1 | 94,718 | 19 | 189,437 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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 (109 + 9).
Input
The single line contains three space-separated integers n, m and k (2 β€ k β€ n β€ 109; 0 β€ m β€ n).
Output
Print a single integer β the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109 + 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.
Submitted Solution:
```
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
def main():
n, m, k = [ int(x) for x in input().split() ]
mod = 1000000009
availablePositions = (k - 1) * (n // k) + n % k
if availablePositions >= m:
points = m
else:
positionsLeft = m - availablePositions
points = (
((pow(2, positionsLeft + 1, mod) - 2) * k) % mod
+ (m - k * positionsLeft) % mod
) % mod
print(points)
BUFFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
input = lambda: sys.stdin.readline().rstrip("\r\n")
def print(*args, **kwargs):
sep = kwargs.pop("sep", " ")
file = kwargs.pop("file", sys.stdout)
atStart = True
for x in args:
if not atStart:
file.write(sep)
file.write(str(x))
atStart = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
main()
``` | instruction | 0 | 94,719 | 19 | 189,438 |
Yes | output | 1 | 94,719 | 19 | 189,439 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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 (109 + 9).
Input
The single line contains three space-separated integers n, m and k (2 β€ k β€ n β€ 109; 0 β€ m β€ n).
Output
Print a single integer β the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109 + 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.
Submitted Solution:
```
###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # # # # ######### #
###### ######### # # # # # # ######### #
# # # # # # # # # # #### # # #
# # # # # # # ## # # # # #
###### # # ####### ####### # # ##### # # # #
# mandatory imports
import os
import sys
from io import BytesIO, IOBase
from math import log2, ceil, sqrt, gcd, log
# optional imports
# from itertools import permutations
# from functools import cmp_to_key # for adding custom comparator
# from fractions import Fraction
from collections import *
from bisect import *
# from __future__ import print_function # for PyPy2
# from heapq import *
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
g = lambda : input().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
rr = lambda x : reversed(range(x))
mod = int(1e9)+7
inf = float("inf")
mod = int(1e9 + 9)
n, m, k = gil()
ans = min(n%k, m)%mod
m -= min(m, n%k)
n -= n%k
if m:
l = n//k
dbl = max(0, m - (l*(k-1)))
if dbl :
delta = (pow(2, dbl+1, mod) + mod - 2)%mod
delta *= k
delta %= mod
ans += delta
ans %= mod
l -= dbl
ans += (m - dbl*k)%mod
print(ans%mod)
``` | instruction | 0 | 94,720 | 19 | 189,440 |
Yes | output | 1 | 94,720 | 19 | 189,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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 (109 + 9).
Input
The single line contains three space-separated integers n, m and k (2 β€ k β€ n β€ 109; 0 β€ m β€ n).
Output
Print a single integer β the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109 + 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.
Submitted Solution:
```
n, m, k = map(int, input().split())
if (n - m) >= n//k:
print (m)
else:
longest_correct_streak = n - k*(n - m)
p = longest_correct_streak//k
print ((k*(pow(2, p+1, 1000000009) - 2) + (longest_correct_streak % k) + (n - m)*(k - 1)) % 1000000009)
``` | instruction | 0 | 94,721 | 19 | 189,442 |
Yes | output | 1 | 94,721 | 19 | 189,443 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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 (109 + 9).
Input
The single line contains three space-separated integers n, m and k (2 β€ k β€ n β€ 109; 0 β€ m β€ n).
Output
Print a single integer β the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109 + 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.
Submitted Solution:
```
import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def add(a,b):
return (a+b)%1000000009
def sub(a,b):
return (a-(b%1000000009)+1000000009)%1000000009
def mul(a,b):
return (a*b)%1000000009
def qpow(a,n):
k = a
r = 1
for i in range(32):
if n & (1<<i):
r = mul(r,k)
k = mul(k,k)
return r
n, m, k = mints()
c = (n+1)//k
z = c*(k-1)
if n-c*k >= 0:
z += n-c*k
d = 0
if z < m:
d = m-z
else:
print(m)
exit(0)
s = mul(k,mul(2, sub(qpow(2, d), 1)))
#print(c,d,z,s)
s = sub(add(s, z),mul(d,(k-1)))
print(s)
``` | instruction | 0 | 94,722 | 19 | 189,444 |
Yes | output | 1 | 94,722 | 19 | 189,445 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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 (109 + 9).
Input
The single line contains three space-separated integers n, m and k (2 β€ k β€ n β€ 109; 0 β€ m β€ n).
Output
Print a single integer β the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109 + 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.
Submitted Solution:
```
n, corecte, k = map(int, input().split())
incorecte = n - corecte
mod = 10**9 + 9
corecte_consecutive = max(0, n - incorecte * k)
dublari = corecte_consecutive // k
corecte_ramase = corecte - corecte_consecutive
#print("dublari = %i" % dublari)
score = 0
#for i in range(0, dublari):
# score += k
# score *= 2
# score %= mod
def power(b, exp):
if exp == 0: return 1
half = power(b, exp//2)
if exp % 2 == 0: return (half*half)
else: return (half*half*b)
score = power(2, dublari) + 1
score = ~score
score *= k
#print("scor chiar dupa dublari = %i" % score)
#print("corecte_consecutive = %i" % corecte_consecutive)
#print("dublari = %i" % dublari)
#print("corecte_ramase = %i" % corecte_ramase)
score += corecte_ramase
score += corecte_consecutive % k
score = -score
print(score % mod)
"""
sirul trebuie structurat asa:
RRRRRRRRRRRR WRRRRR WRRRRR WRRRRR WRRRRR
"""
``` | instruction | 0 | 94,723 | 19 | 189,446 |
No | output | 1 | 94,723 | 19 | 189,447 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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 (109 + 9).
Input
The single line contains three space-separated integers n, m and k (2 β€ k β€ n β€ 109; 0 β€ m β€ n).
Output
Print a single integer β the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109 + 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.
Submitted Solution:
```
def game(n,m,k):
dp=[0]*(n)
for i in range(0,n,2):
dp[i]=1
while dp.count(1)<m:
for i in range(len(dp)):
if dp[i]==0:
dp[i]=1
if dp.count(i)==m:
break
score=0
curr=0
for i in dp:
if i==1:
curr+=1
score+=1
if curr==k:
score*=2
curr=0
if i==0:
curr=0
return score%(10**9+9)
a,b,c=map(int,input().strip().split())
print(game(a,b,c))
``` | instruction | 0 | 94,724 | 19 | 189,448 |
No | output | 1 | 94,724 | 19 | 189,449 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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 (109 + 9).
Input
The single line contains three space-separated integers n, m and k (2 β€ k β€ n β€ 109; 0 β€ m β€ n).
Output
Print a single integer β the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109 + 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.
Submitted Solution:
```
from sys import stdin
mod = 1000000009
def find(k, ak):
return ((((4*pow(2, ak, mod))%mod - (4 + 2*ak)%mod + mod)%mod)*k)%mod
n, m, k = map(int, stdin.readline().split())
w = min(n//k, n-m)
ak = n//k - w
print((find(k, ak) + m - k*ak)%mod)
``` | instruction | 0 | 94,725 | 19 | 189,450 |
No | output | 1 | 94,725 | 19 | 189,451 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
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 (109 + 9).
Input
The single line contains three space-separated integers n, m and k (2 β€ k β€ n β€ 109; 0 β€ m β€ n).
Output
Print a single integer β the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109 + 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.
Submitted Solution:
```
z = 10**9+9
n,m,k = map(int,input().split())
i = n-m
x = (n-k+1)//k
if i>=x:
print((n-i)%z)
else:
l = n-k+1
f = l-(i-1)*k-1
t = f//k
f = t*k
v = 2*(pow(2,t,z)-1)*k+(n-f-i)
print(v%z)
``` | instruction | 0 | 94,726 | 19 | 189,452 |
No | output | 1 | 94,726 | 19 | 189,453 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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 β€ 1018) β 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. | instruction | 0 | 94,882 | 19 | 189,764 |
Tags: combinatorics, constructive algorithms, greedy, math
Correct Solution:
```
n=int(input())
a,b=2,1
cnt=0
while a<=n:
cnt+=1
a,b=a+b,a
print(cnt)
``` | output | 1 | 94,882 | 19 | 189,765 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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 β€ 1018) β 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. | instruction | 0 | 94,883 | 19 | 189,766 |
Tags: combinatorics, constructive algorithms, greedy, math
Correct Solution:
```
n = int(input())
l = [1, 2]
for i in range(100): l.append(l[-1] + l[-2])
for i in range(100):
if l[i] > n:
print(i - 1)
break
``` | output | 1 | 94,883 | 19 | 189,767 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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 β€ 1018) β 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. | instruction | 0 | 94,884 | 19 | 189,768 |
Tags: combinatorics, constructive algorithms, greedy, math
Correct Solution:
```
#python 3.6
fib=[1,2]
for i in range(90):
fib.append(fib[-1]+fib[-2])
n=int(input())
for i in range(len(fib)):
if fib[i]>n:
print(i-1)
break
``` | output | 1 | 94,884 | 19 | 189,769 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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 β€ 1018) β 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. | instruction | 0 | 94,885 | 19 | 189,770 |
Tags: combinatorics, constructive algorithms, greedy, math
Correct Solution:
```
###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # # # # ######### #
###### ######### # # # # # # ######### #
# # # # # # # # # # #### # # #
# # # # # # # ## # # # # #
###### # # ####### ####### # # ##### # # # #
from __future__ import print_function # for PyPy2
# from itertools import permutations
# from functools import cmp_to_key # for adding custom comparator
# from fractions import Fraction
from collections import *
from sys import stdin
from bisect import *
# from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
rr = lambda x : reversed(range(x))
mod = int(1e9)+7
inf = float("inf")
r = range
n, = gil()
a, b = 1, 2
ans = 1
while b+a <= n:
a, b = b, a+b
ans += 1
print(ans)
``` | output | 1 | 94,885 | 19 | 189,771 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.