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.
Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.
Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.
Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
Output
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
Examples
Input
4
4 1 2 10
Output
12 5
Input
7
1 2 3 4 5 6 7
Output
16 12
Note
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
Submitted Solution:
```
n = int(input())
lol= [int (n) for n in input().split()]
left = 0
right = len(lol) - 1
s = 0
d = 0
for i in range(1,n+1):
if(i%2!=0):
if(lol[left]>=lol[right]):
s += lol[left]
left +=1
elif(lol[right]>=lol[left]):
s += lol[right]
right -= 1
if(i%2==0):
if(lol[left]>=lol[right]):
d += lol[left]
left +=1
elif(lol[right]>=lol[left]):
d += lol[right]
right -= 1
print(s,d)
``` | instruction | 0 | 62,661 | 19 | 125,322 |
Yes | output | 1 | 62,661 | 19 | 125,323 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.
Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.
Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
Output
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
Examples
Input
4
4 1 2 10
Output
12 5
Input
7
1 2 3 4 5 6 7
Output
16 12
Note
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
Submitted Solution:
```
n = int(input())
arr = list(map(int, input().split()))
s = [0, 0]
for i in range(n):
if arr[0] > arr[-1]:
s[i%2] += arr[0]
t = arr.pop(0)
else:
s[i%2] += arr[-1]
t = arr.pop(-1)
print(*s)
``` | instruction | 0 | 62,662 | 19 | 125,324 |
Yes | output | 1 | 62,662 | 19 | 125,325 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.
Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.
Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
Output
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
Examples
Input
4
4 1 2 10
Output
12 5
Input
7
1 2 3 4 5 6 7
Output
16 12
Note
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
Submitted Solution:
```
n = int(input())
tab = list(map(int , input().split()))
ser = 0
dim = 0
for i in range(n):
if sum(tab):
ser += max(tab[0] , tab[-1])
tab.remove(max(tab[0] , tab[-1]))
if sum(tab):
dim += max(tab[0] , tab[-1])
tab.remove(max(tab[0], tab[-1]))
print(ser , dim)
``` | instruction | 0 | 62,663 | 19 | 125,326 |
Yes | output | 1 | 62,663 | 19 | 125,327 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.
Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.
Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
Output
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
Examples
Input
4
4 1 2 10
Output
12 5
Input
7
1 2 3 4 5 6 7
Output
16 12
Note
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
Submitted Solution:
```
def cards (n):
inp=list(map(int,input().strip().split()))
s=0
d=0
while len(inp)!=0:
if inp[0] > inp[-1]:
s+=inp[0]
inp.remove(inp[0])
else :
s+=inp[-1]
inp.remove(inp[-1])
if len(inp)==0:
break
if inp[0]>inp[-1]:
d+=inp[0]
inp.remove(inp[0])
else :
d+=inp[-1]
inp.remove(inp[-1])
return str(s)+' '+str(d)
n=int( input())
print(cards(n))
``` | instruction | 0 | 62,664 | 19 | 125,328 |
Yes | output | 1 | 62,664 | 19 | 125,329 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.
Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.
Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
Output
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
Examples
Input
4
4 1 2 10
Output
12 5
Input
7
1 2 3 4 5 6 7
Output
16 12
Note
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
Submitted Solution:
```
n=int(input())
cards=list(map(int,input().split()))
flag=0
sereja=0
dima=0
for i in range(n):
if flag==0:
if cards[0]>=cards[-1]:
sereja+=cards[0]
cards.pop(0)
flag=1
else:
sereja+=cards[-1]
cards.pop(-1)
flag=1
else:
if cards[0]>=cards[-1]:
dima+=cards[0]
cards.pop(0)
flag=0
else:
dima+=cards[-1]
cards.pop(-1)
flag=1
print(sereja,dima)
``` | instruction | 0 | 62,665 | 19 | 125,330 |
No | output | 1 | 62,665 | 19 | 125,331 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.
Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.
Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
Output
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
Examples
Input
4
4 1 2 10
Output
12 5
Input
7
1 2 3 4 5 6 7
Output
16 12
Note
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
Submitted Solution:
```
'''
Amirhossein Alimirzaei
Telegram : @HajLorenzo
Instagram : amirhossein_alimirzaei
University of Bojnourd
'''
N=int(input())
TMP=sorted(list(map(int,input().split())))
print(sum(TMP[i] for i in range(N-1,-1,-2)),sum(TMP[i] for i in range(N-2,-1,-2)))
``` | instruction | 0 | 62,666 | 19 | 125,332 |
No | output | 1 | 62,666 | 19 | 125,333 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.
Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.
Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
Output
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
Examples
Input
4
4 1 2 10
Output
12 5
Input
7
1 2 3 4 5 6 7
Output
16 12
Note
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
getcontext().prec = 25
MOD = pow(10, 9) + 7
BUFSIZE = 8192
from collections import defaultdict
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 = int(input())
arr = list(map(int, input().split(" ")))
a = sum(arr)
arr.sort()
b = 0
for i in range(0, n, 2):
b += arr[i]
print(*sorted([b, a - b], reverse=True))
``` | instruction | 0 | 62,667 | 19 | 125,334 |
No | output | 1 | 62,667 | 19 | 125,335 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.
Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.
Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
Input
The first line contains integer n (1 β€ n β€ 1000) β the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
Output
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
Examples
Input
4
4 1 2 10
Output
12 5
Input
7
1 2 3 4 5 6 7
Output
16 12
Note
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
Submitted Solution:
```
S=0
D=0
n=int(input())
numbers=list(map(int,input().split()))
listt=[]
for i in range(n):
if numbers[0]>numbers[-1]:
listt.append(numbers[0])
numbers.remove(numbers[0])
else:
listt.append(numbers[-1])
numbers.remove(numbers[-1])
#for i in listt:
# if len(listt)==0:
# break
# else:
# D=D+listt.pop()
# if len(listt)==0:
# break
# S=S+listt.pop()
for i in range(len(listt)):
if len(listt)==0:
break
S=S+listt.pop()
if len(listt)==0:
break
D=D+listt.pop()
print(D)
print(S)
``` | instruction | 0 | 62,668 | 19 | 125,336 |
No | output | 1 | 62,668 | 19 | 125,337 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It turns out that you are a great fan of rock band AC/PE. Peter learned that and started the following game: he plays the first song of the list of n songs of the group, and you have to find out the name of the song. After you tell the song name, Peter immediately plays the following song in order, and so on.
The i-th song of AC/PE has its recognizability pi. This means that if the song has not yet been recognized by you, you listen to it for exactly one more second and with probability of pi percent you recognize it and tell it's name. Otherwise you continue listening it. Note that you can only try to guess it only when it is integer number of seconds after the moment the song starts playing.
In all AC/PE songs the first words of chorus are the same as the title, so when you've heard the first ti seconds of i-th song and its chorus starts, you immediately guess its name for sure.
For example, in the song Highway To Red the chorus sounds pretty late, but the song has high recognizability. In the song Back In Blue, on the other hand, the words from the title sound close to the beginning of the song, but it's hard to name it before hearing those words. You can name both of these songs during a few more first seconds.
Determine the expected number songs of you will recognize if the game lasts for exactly T seconds (i. e. you can make the last guess on the second T, after that the game stops).
If all songs are recognized faster than in T seconds, the game stops after the last song is recognized.
Input
The first line of the input contains numbers n and T (1 β€ n β€ 5000, 1 β€ T β€ 5000), separated by a space. Next n lines contain pairs of numbers pi and ti (0 β€ pi β€ 100, 1 β€ ti β€ T). The songs are given in the same order as in Petya's list.
Output
Output a single number β the expected number of the number of songs you will recognize in T seconds. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Examples
Input
2 2
50 2
10 1
Output
1.500000000
Input
2 2
0 2
100 2
Output
1.000000000
Input
3 3
50 3
50 2
25 2
Output
1.687500000
Input
2 2
0 2
0 2
Output
1.000000000
Submitted Solution:
```
def main():
n, time = map(int, input().split())
pp, qq, tt, qqtt = [], [], [], []
for i in range(n):
a, b = input().split()
p = float(a) / 100.
pp.append(p)
q = 1. - p
qq.append(q)
t = int(b) - 1
tt.append(t)
qqtt.append(q ** t)
t_cur, u_cur, t_prev, u_prev = ([0.] * (time + 1) for _ in '1234')
q_1, t_1, qt_1 = qq[-1], tt[-1], qqtt[-1]
for k in range(n - 1, 0, -1):
p, t, qt = q_1, t_1, qt_1
q_1, t_1, qt_1 = qq[k - 1], tt[k - 1], qqtt[k - 1]
q = w = qq[k]
for i in range(time):
t_cur[i + 1] = x=((p * u_prev[i] + 1. - w) if i < t else
(p * u_prev[i] + qt * t_prev[i - t] + 1.))
u_cur[i + 1] = ((q_1 * u_cur[i] + t_cur[i + 1]) if i + 1 < t_1 else
(q_1 * u_cur[i] + t_cur[i + 1] - qt_1 * t_cur[i - t_1 + 1]))
w *= q
t_cur, u_cur, t_prev, u_prev = t_prev, u_prev, t_cur, u_cur
# t_cur[0] = u_cur[0] = 0.
t_cur, u_cur = ([0.] * (time + 1) for _ in '12')
p, t, qt = pp[0], tt[0], qqtt[0]
q = w = qq[0]
for i in range(t):
t_cur[i + 1] = p * u_prev[i] + 1. - w
w *= q
for i in range(t, time):
t_cur[i + 1] = p * u_prev[i] + qt * t_prev[i - t] + 1.
print('{:.12f}'.format(t_cur[-1]))
if __name__ == '__main__':
main()
``` | instruction | 0 | 62,720 | 19 | 125,440 |
No | output | 1 | 62,720 | 19 | 125,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It turns out that you are a great fan of rock band AC/PE. Peter learned that and started the following game: he plays the first song of the list of n songs of the group, and you have to find out the name of the song. After you tell the song name, Peter immediately plays the following song in order, and so on.
The i-th song of AC/PE has its recognizability pi. This means that if the song has not yet been recognized by you, you listen to it for exactly one more second and with probability of pi percent you recognize it and tell it's name. Otherwise you continue listening it. Note that you can only try to guess it only when it is integer number of seconds after the moment the song starts playing.
In all AC/PE songs the first words of chorus are the same as the title, so when you've heard the first ti seconds of i-th song and its chorus starts, you immediately guess its name for sure.
For example, in the song Highway To Red the chorus sounds pretty late, but the song has high recognizability. In the song Back In Blue, on the other hand, the words from the title sound close to the beginning of the song, but it's hard to name it before hearing those words. You can name both of these songs during a few more first seconds.
Determine the expected number songs of you will recognize if the game lasts for exactly T seconds (i. e. you can make the last guess on the second T, after that the game stops).
If all songs are recognized faster than in T seconds, the game stops after the last song is recognized.
Input
The first line of the input contains numbers n and T (1 β€ n β€ 5000, 1 β€ T β€ 5000), separated by a space. Next n lines contain pairs of numbers pi and ti (0 β€ pi β€ 100, 1 β€ ti β€ T). The songs are given in the same order as in Petya's list.
Output
Output a single number β the expected number of the number of songs you will recognize in T seconds. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Examples
Input
2 2
50 2
10 1
Output
1.500000000
Input
2 2
0 2
100 2
Output
1.000000000
Input
3 3
50 3
50 2
25 2
Output
1.687500000
Input
2 2
0 2
0 2
Output
1.000000000
Submitted Solution:
```
def main():
n, time = map(int, input().split())
pp, qq, tt, qqtt = [], [], [], []
for i in range(n):
a, b = input().split()
p = float(a) / 100.
pp.append(p)
q = 1. - p
qq.append(q)
t = int(b) - 1
tt.append(t)
qqtt.append(q ** t)
t_cur, u_cur, t_prev, u_prev = ([0.] * (time + 1) for _ in '1234')
q_1, t_1, qt_1 = qq[-1], tt[-1], qqtt[-1]
for k in range(n - 1, 0, -1):
p, t, qt = q_1, t_1, qt_1
q_1, t_1, qt_1 = qq[k - 1], tt[k - 1], qqtt[k - 1]
q = w = qq[k]
for i in range(time):
t_cur[i + 1] = ((p * u_prev[i] + 1. - w) if i < t else
(p * u_prev[i] + qt * t_prev[i - t] + 1.))
u_cur[i + 1] = ((q_1 * u_cur[i] + t_cur[i + 1]) if i + 1 < t_1 else
(q_1 * u_cur[i] + t_cur[i + 1] - qt_1 * t_cur[i - t_1 + 1]))
w *= q
t_cur, u_cur, t_prev, u_prev = t_prev, u_prev, t_cur, u_cur
t_cur[0] = u_cur[0] = 0.
p, t, qt = pp[0], tt[0], qqtt[0]
q = w = qq[0]
for i in range(t):
t_cur[i + 1] = p * u_prev[i] + 1. - w
w *= q
for i in range(t, time):
t_cur[i + 1] = p * u_prev[i] + qt * t_prev[i - t] + 1.
print('{:.12f}'.format(t_cur[-1]))
if __name__ == '__main__':
main()
``` | instruction | 0 | 62,721 | 19 | 125,442 |
No | output | 1 | 62,721 | 19 | 125,443 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It turns out that you are a great fan of rock band AC/PE. Peter learned that and started the following game: he plays the first song of the list of n songs of the group, and you have to find out the name of the song. After you tell the song name, Peter immediately plays the following song in order, and so on.
The i-th song of AC/PE has its recognizability pi. This means that if the song has not yet been recognized by you, you listen to it for exactly one more second and with probability of pi percent you recognize it and tell it's name. Otherwise you continue listening it. Note that you can only try to guess it only when it is integer number of seconds after the moment the song starts playing.
In all AC/PE songs the first words of chorus are the same as the title, so when you've heard the first ti seconds of i-th song and its chorus starts, you immediately guess its name for sure.
For example, in the song Highway To Red the chorus sounds pretty late, but the song has high recognizability. In the song Back In Blue, on the other hand, the words from the title sound close to the beginning of the song, but it's hard to name it before hearing those words. You can name both of these songs during a few more first seconds.
Determine the expected number songs of you will recognize if the game lasts for exactly T seconds (i. e. you can make the last guess on the second T, after that the game stops).
If all songs are recognized faster than in T seconds, the game stops after the last song is recognized.
Input
The first line of the input contains numbers n and T (1 β€ n β€ 5000, 1 β€ T β€ 5000), separated by a space. Next n lines contain pairs of numbers pi and ti (0 β€ pi β€ 100, 1 β€ ti β€ T). The songs are given in the same order as in Petya's list.
Output
Output a single number β the expected number of the number of songs you will recognize in T seconds. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Examples
Input
2 2
50 2
10 1
Output
1.500000000
Input
2 2
0 2
100 2
Output
1.000000000
Input
3 3
50 3
50 2
25 2
Output
1.687500000
Input
2 2
0 2
0 2
Output
1.000000000
Submitted Solution:
```
inp = input().split(' ')
curr = [[]]*int(inp[0])
rem = [0]*int(inp[0])
for x in range(int(inp[0])):
a = input().split()
rem[x] = float(a[0])/100
curr[x] = [0]*int(a[1])
curr.append([0])
curr[0][0] = 1
for time in range(int(inp[1])):
newcurr = []
for n in curr:
newcurr.append([0]*len(n))
newcurr[-1][0] = curr[-1][0]
for x in range(int(inp[0])-1,-1,-1):
for y in range(len(curr[x])-1):
newcurr[x][y+1] += curr[x][y] * (1-rem[x])
newcurr[x+1][0] += curr[x][y] * rem[x]
newcurr[x+1][0] += curr[x][-1]
if sum(newcurr[x]) == 0:
newcurr[x] = [0]
curr = []
for n in curr:
newcurr.append([0]*len(n))
for n in newcurr:
curr.append(n[:])
out = 0
for x in range(len(curr)):
out += x*sum(curr[x])
print(out)
``` | instruction | 0 | 62,722 | 19 | 125,444 |
No | output | 1 | 62,722 | 19 | 125,445 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It turns out that you are a great fan of rock band AC/PE. Peter learned that and started the following game: he plays the first song of the list of n songs of the group, and you have to find out the name of the song. After you tell the song name, Peter immediately plays the following song in order, and so on.
The i-th song of AC/PE has its recognizability pi. This means that if the song has not yet been recognized by you, you listen to it for exactly one more second and with probability of pi percent you recognize it and tell it's name. Otherwise you continue listening it. Note that you can only try to guess it only when it is integer number of seconds after the moment the song starts playing.
In all AC/PE songs the first words of chorus are the same as the title, so when you've heard the first ti seconds of i-th song and its chorus starts, you immediately guess its name for sure.
For example, in the song Highway To Red the chorus sounds pretty late, but the song has high recognizability. In the song Back In Blue, on the other hand, the words from the title sound close to the beginning of the song, but it's hard to name it before hearing those words. You can name both of these songs during a few more first seconds.
Determine the expected number songs of you will recognize if the game lasts for exactly T seconds (i. e. you can make the last guess on the second T, after that the game stops).
If all songs are recognized faster than in T seconds, the game stops after the last song is recognized.
Input
The first line of the input contains numbers n and T (1 β€ n β€ 5000, 1 β€ T β€ 5000), separated by a space. Next n lines contain pairs of numbers pi and ti (0 β€ pi β€ 100, 1 β€ ti β€ T). The songs are given in the same order as in Petya's list.
Output
Output a single number β the expected number of the number of songs you will recognize in T seconds. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Examples
Input
2 2
50 2
10 1
Output
1.500000000
Input
2 2
0 2
100 2
Output
1.000000000
Input
3 3
50 3
50 2
25 2
Output
1.687500000
Input
2 2
0 2
0 2
Output
1.000000000
Submitted Solution:
```
def main():
n, time = map(int, input().split())
pp, qq, tt, qqtt = [], [], [], []
for i in range(n):
a, b = input().split()
p = float(a) / 100.
pp.append(p)
q = 1. - p
qq.append(q)
t = int(b) - 1
tt.append(t)
qqtt.append(q ** t)
t_prev, u_prev = [0.] * time, [0.] * time
for k in range(n - 1, 0, -1):
q_1, t_1, qt_1, u_cur = qq[k - 1], tt[k - 1], qqtt[k - 1], [0.]
p, t, qt, t_cur = pp[k], tt[k], qqtt[k], [0.]
for i in range(time):
if i < t:
t_cur.append((u_prev[i] + 1.) * p)
else:
t_cur.append(p * u_prev[i] + qt * t_prev[i - t] + 1.)
if i + 1 < t_1:
u_cur.append(q_1 * u_cur[i] + t_cur[i + 1])
else:
u_cur.append(q_1 * u_cur[i] + t_cur[i + 1] - qt_1 * t_cur[i - t_1 + 1])
t_prev, u_prev = t_cur, u_cur
p, t, qt, t_cur = pp[0], tt[0], qqtt[0], [0.]
for i in range(t):
t_cur.append((u_prev[i] + 1.) * p)
for i in range(t, time):
t_cur.append(p * u_prev[i] + qt * t_prev[i - t] + 1.)
print('{:.12f}'.format(t_cur[time]))
if __name__ == '__main__':
main()
``` | instruction | 0 | 62,723 | 19 | 125,446 |
No | output | 1 | 62,723 | 19 | 125,447 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Memory and his friend Lexa are competing to get higher score in one popular computer game. Memory starts with score a and Lexa starts with score b. In a single turn, both Memory and Lexa get some integer in the range [ - k;k] (i.e. one integer among - k, - k + 1, - k + 2, ..., - 2, - 1, 0, 1, 2, ..., k - 1, k) and add them to their current scores. The game has exactly t turns. Memory and Lexa, however, are not good at this game, so they both always get a random integer at their turn.
Memory wonders how many possible games exist such that he ends with a strictly higher score than Lexa. Two games are considered to be different if in at least one turn at least one player gets different score. There are (2k + 1)2t games in total. Since the answer can be very large, you should print it modulo 109 + 7. Please solve this problem for Memory.
Input
The first and only line of input contains the four integers a, b, k, and t (1 β€ a, b β€ 100, 1 β€ k β€ 1000, 1 β€ t β€ 100) β the amount Memory and Lexa start with, the number k, and the number of turns respectively.
Output
Print the number of possible games satisfying the conditions modulo 1 000 000 007 (109 + 7) in one line.
Examples
Input
1 2 2 1
Output
6
Input
1 1 1 2
Output
31
Input
2 12 3 1
Output
0
Note
In the first sample test, Memory starts with 1 and Lexa starts with 2. If Lexa picks - 2, Memory can pick 0, 1, or 2 to win. If Lexa picks - 1, Memory can pick 1 or 2 to win. If Lexa picks 0, Memory can pick 2 to win. If Lexa picks 1 or 2, Memory cannot win. Thus, there are 3 + 2 + 1 = 6 possible games in which Memory wins. | instruction | 0 | 62,777 | 19 | 125,554 |
Tags: combinatorics, dp, math
Correct Solution:
```
mod=10**9+7
f=[0]*500000
def POW(a,b):
if(b==0):
return 1
if(b&1):
return POW(a,b//2)**2*a%mod
else:
return POW(a,b//2)**2
def C(n,m):
if(m>n):
return 0
t=f[n]*POW(f[m],mod-2)%mod*POW(f[n-m],mod-2)%mod
return t
f[0]=1
for i in range(1,500000):
f[i]=f[i-1]*i%mod
a,b,k,t=map(int,input().split(' '))
ans=0
for i in range(0,2*t+1):
t1=POW(-1,i)*C(2*t,i)%mod
t2=(C(210000+2*k*t-a+b+2*t-1-(2*k+1)*i+1,2*t)-C(1+2*k*t-a+b+2*t-1-(2*k+1)*i,2*t))%mod
ans=(ans+t1*t2)%mod
print(ans)
``` | output | 1 | 62,777 | 19 | 125,555 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Memory and his friend Lexa are competing to get higher score in one popular computer game. Memory starts with score a and Lexa starts with score b. In a single turn, both Memory and Lexa get some integer in the range [ - k;k] (i.e. one integer among - k, - k + 1, - k + 2, ..., - 2, - 1, 0, 1, 2, ..., k - 1, k) and add them to their current scores. The game has exactly t turns. Memory and Lexa, however, are not good at this game, so they both always get a random integer at their turn.
Memory wonders how many possible games exist such that he ends with a strictly higher score than Lexa. Two games are considered to be different if in at least one turn at least one player gets different score. There are (2k + 1)2t games in total. Since the answer can be very large, you should print it modulo 109 + 7. Please solve this problem for Memory.
Input
The first and only line of input contains the four integers a, b, k, and t (1 β€ a, b β€ 100, 1 β€ k β€ 1000, 1 β€ t β€ 100) β the amount Memory and Lexa start with, the number k, and the number of turns respectively.
Output
Print the number of possible games satisfying the conditions modulo 1 000 000 007 (109 + 7) in one line.
Examples
Input
1 2 2 1
Output
6
Input
1 1 1 2
Output
31
Input
2 12 3 1
Output
0
Note
In the first sample test, Memory starts with 1 and Lexa starts with 2. If Lexa picks - 2, Memory can pick 0, 1, or 2 to win. If Lexa picks - 1, Memory can pick 1 or 2 to win. If Lexa picks 0, Memory can pick 2 to win. If Lexa picks 1 or 2, Memory cannot win. Thus, there are 3 + 2 + 1 = 6 possible games in which Memory wins. | instruction | 0 | 62,778 | 19 | 125,556 |
Tags: combinatorics, dp, math
Correct Solution:
```
def c(n, k):
if k > n:
return 0
a = b = 1
for i in range(n - k + 1, n + 1):
a *= i
for i in range(1, k + 1):
b *= i
return a // b
a, b, k, t = map(int, input().split())
n, m, s = 2 * k + 1, 2 * t, 2 * k * t + b - a
ans, mod = 0, 1000000007
for i in range(m + 1):
ans = (ans + [1, -1][i & 1] * c(m, i) * c(m + s - n * i, m)) % mod
print((pow(n, m, mod) - ans) % mod)
``` | output | 1 | 62,778 | 19 | 125,557 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Memory and his friend Lexa are competing to get higher score in one popular computer game. Memory starts with score a and Lexa starts with score b. In a single turn, both Memory and Lexa get some integer in the range [ - k;k] (i.e. one integer among - k, - k + 1, - k + 2, ..., - 2, - 1, 0, 1, 2, ..., k - 1, k) and add them to their current scores. The game has exactly t turns. Memory and Lexa, however, are not good at this game, so they both always get a random integer at their turn.
Memory wonders how many possible games exist such that he ends with a strictly higher score than Lexa. Two games are considered to be different if in at least one turn at least one player gets different score. There are (2k + 1)2t games in total. Since the answer can be very large, you should print it modulo 109 + 7. Please solve this problem for Memory.
Input
The first and only line of input contains the four integers a, b, k, and t (1 β€ a, b β€ 100, 1 β€ k β€ 1000, 1 β€ t β€ 100) β the amount Memory and Lexa start with, the number k, and the number of turns respectively.
Output
Print the number of possible games satisfying the conditions modulo 1 000 000 007 (109 + 7) in one line.
Examples
Input
1 2 2 1
Output
6
Input
1 1 1 2
Output
31
Input
2 12 3 1
Output
0
Note
In the first sample test, Memory starts with 1 and Lexa starts with 2. If Lexa picks - 2, Memory can pick 0, 1, or 2 to win. If Lexa picks - 1, Memory can pick 1 or 2 to win. If Lexa picks 0, Memory can pick 2 to win. If Lexa picks 1 or 2, Memory cannot win. Thus, there are 3 + 2 + 1 = 6 possible games in which Memory wins.
Submitted Solution:
```
def convolve(u, v):
m = len(u)
n = len(v)
a = [0] * (m + n - 1)
for i in range(0, m):
for j in range(0, n):
a[i + j] += u[i] * v[j]
return a
def expmod(a, b, p):
ans = 0
if b == 0:
ans = 1
elif b == 1:
ans = a % p
else:
b1 = b // 2
temp = expmod(a, b1, p)
ans = (temp * temp) % p
if b % 2 == 1:
ans = (ans * a) % p
return ans
s = input()
a = int(s.split()[0])
b = int(s.split()[1])
k = int(s.split()[2])
t = int(s.split()[3])
p = 10 ** 9 + 7
diff = abs(b - a)
ans = 0
arr = [[], [1] * (2 * k + 1)]
for i in range(2, t + 1):
arr.append(convolve(arr[i - 1], arr[1]))
arr0 = arr[t]
len0 = 2 * k * t + 1
win = [0] * (diff + 1)
tie = 0
for i in range(0, diff + 1):
for j in range(0, len0 - i):
win[i] += arr0[j] * arr0[j + i]
if i == 0:
tie += win[i]
else:
tie += 2 * win[i]
ans = expmod(2 * k + 1, 2 * t, p)
if a > b:
ans = (ans + tie) % p
else:
ans = (ans - tie) % p
if ans % 2 == 0:
ans = ans // 2
else:
ans = (ans + p) // 2
#print(arr0)
#print("tie =", tie)
print(ans)
``` | instruction | 0 | 62,779 | 19 | 125,558 |
No | output | 1 | 62,779 | 19 | 125,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Memory and his friend Lexa are competing to get higher score in one popular computer game. Memory starts with score a and Lexa starts with score b. In a single turn, both Memory and Lexa get some integer in the range [ - k;k] (i.e. one integer among - k, - k + 1, - k + 2, ..., - 2, - 1, 0, 1, 2, ..., k - 1, k) and add them to their current scores. The game has exactly t turns. Memory and Lexa, however, are not good at this game, so they both always get a random integer at their turn.
Memory wonders how many possible games exist such that he ends with a strictly higher score than Lexa. Two games are considered to be different if in at least one turn at least one player gets different score. There are (2k + 1)2t games in total. Since the answer can be very large, you should print it modulo 109 + 7. Please solve this problem for Memory.
Input
The first and only line of input contains the four integers a, b, k, and t (1 β€ a, b β€ 100, 1 β€ k β€ 1000, 1 β€ t β€ 100) β the amount Memory and Lexa start with, the number k, and the number of turns respectively.
Output
Print the number of possible games satisfying the conditions modulo 1 000 000 007 (109 + 7) in one line.
Examples
Input
1 2 2 1
Output
6
Input
1 1 1 2
Output
31
Input
2 12 3 1
Output
0
Note
In the first sample test, Memory starts with 1 and Lexa starts with 2. If Lexa picks - 2, Memory can pick 0, 1, or 2 to win. If Lexa picks - 1, Memory can pick 1 or 2 to win. If Lexa picks 0, Memory can pick 2 to win. If Lexa picks 1 or 2, Memory cannot win. Thus, there are 3 + 2 + 1 = 6 possible games in which Memory wins.
Submitted Solution:
```
x,y,m,n=map(int,input().split(' '))
f=[0]*(2*n*m+2)
h=[0]*(2*n*m+2)
mod=10**9+7
s=0
f[n*m+1]=1
for i in range(1,n+1):
for j in range(1,2*n*m+1+1):
h[j]=(h[j-1]+f[j])%mod;
for j in range(1,2*n*m+1+1):
f[j]=(h[min(j+m,2*n*m+1)]-h[max(j-m-1,0)]+mod)%mod
for i in range(1,2*n*m+1+1,1):
h[i]=(h[i-1]+f[i])%mod
for i in range(1,2*n*m+1+1,1):
s+=f[i]*h[min(max(i+x-y-1,0),2*n*m+1)]
print(s)
``` | instruction | 0 | 62,780 | 19 | 125,560 |
No | output | 1 | 62,780 | 19 | 125,561 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In this task Anna and Maria play the following game. Initially they have a checkered piece of paper with a painted n Γ m rectangle (only the border, no filling). Anna and Maria move in turns and Anna starts. During each move one should paint inside the last-painted rectangle a new lesser rectangle (along the grid lines). The new rectangle should have no common points with the previous one. Note that when we paint a rectangle, we always paint only the border, the rectangles aren't filled.
Nobody wins the game β Anna and Maria simply play until they have done k moves in total. Count the number of different ways to play this game.
Input
The first and only line contains three integers: n, m, k (1 β€ n, m, k β€ 1000).
Output
Print the single number β the number of the ways to play the game. As this number can be very big, print the value modulo 1000000007 (109 + 7).
Examples
Input
3 3 1
Output
1
Input
4 4 1
Output
9
Input
6 7 2
Output
75
Note
Two ways to play the game are considered different if the final pictures are different. In other words, if one way contains a rectangle that is not contained in the other way.
In the first sample Anna, who performs her first and only move, has only one possible action plan β insert a 1 Γ 1 square inside the given 3 Γ 3 square.
In the second sample Anna has as much as 9 variants: 4 ways to paint a 1 Γ 1 square, 2 ways to insert a 1 Γ 2 rectangle vertically, 2 more ways to insert it horizontally and one more way is to insert a 2 Γ 2 square.
Submitted Solution:
```
MOD = 10 ** 9 + 7
def egcd(a, b):
if a == 0:
return (b, 0, 1)
else:
g, y, x = egcd(b % a, a)
return (g, x - (b // a) * y, y)
def modinv(a, m):
g, x, y = egcd(a, m)
if g != 1:
raise Exception('modular inverse does not exist')
else:
return x % m
def combination(n,k,MOD):
ans = 1
for i in range(n - k + 1, n + 1):
ans *= i
ans %= MOD
for i in range(1,k+1):
ans *= modinv(i,MOD)
ans %= MOD
return ans
n,m,k = map(int,input().split())
print(combination(n-1,n-2 * k-1,MOD) * combination(n-1,n - 2 * k - 1,MOD) % MOD)
``` | instruction | 0 | 63,264 | 19 | 126,528 |
No | output | 1 | 63,264 | 19 | 126,529 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In this task Anna and Maria play the following game. Initially they have a checkered piece of paper with a painted n Γ m rectangle (only the border, no filling). Anna and Maria move in turns and Anna starts. During each move one should paint inside the last-painted rectangle a new lesser rectangle (along the grid lines). The new rectangle should have no common points with the previous one. Note that when we paint a rectangle, we always paint only the border, the rectangles aren't filled.
Nobody wins the game β Anna and Maria simply play until they have done k moves in total. Count the number of different ways to play this game.
Input
The first and only line contains three integers: n, m, k (1 β€ n, m, k β€ 1000).
Output
Print the single number β the number of the ways to play the game. As this number can be very big, print the value modulo 1000000007 (109 + 7).
Examples
Input
3 3 1
Output
1
Input
4 4 1
Output
9
Input
6 7 2
Output
75
Note
Two ways to play the game are considered different if the final pictures are different. In other words, if one way contains a rectangle that is not contained in the other way.
In the first sample Anna, who performs her first and only move, has only one possible action plan β insert a 1 Γ 1 square inside the given 3 Γ 3 square.
In the second sample Anna has as much as 9 variants: 4 ways to paint a 1 Γ 1 square, 2 ways to insert a 1 Γ 2 rectangle vertically, 2 more ways to insert it horizontally and one more way is to insert a 2 Γ 2 square.
Submitted Solution:
```
def inv(a):
return pow(a, mod - 2, mod)
n, m, k = map(int, input().split())
fact = [1]
mod = 1000000007
for i in range(1, 1001):
fact.append(fact[-1] * i % mod)
print(fact[n - 1] * inv(fact[2 * k]) * inv(fact[n - 2 * k - 1]) * fact[m - 1] * inv(fact[2 * k]) * inv(fact[m - 2 * k - 1]) % mod)
``` | instruction | 0 | 63,265 | 19 | 126,530 |
No | output | 1 | 63,265 | 19 | 126,531 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In this task Anna and Maria play the following game. Initially they have a checkered piece of paper with a painted n Γ m rectangle (only the border, no filling). Anna and Maria move in turns and Anna starts. During each move one should paint inside the last-painted rectangle a new lesser rectangle (along the grid lines). The new rectangle should have no common points with the previous one. Note that when we paint a rectangle, we always paint only the border, the rectangles aren't filled.
Nobody wins the game β Anna and Maria simply play until they have done k moves in total. Count the number of different ways to play this game.
Input
The first and only line contains three integers: n, m, k (1 β€ n, m, k β€ 1000).
Output
Print the single number β the number of the ways to play the game. As this number can be very big, print the value modulo 1000000007 (109 + 7).
Examples
Input
3 3 1
Output
1
Input
4 4 1
Output
9
Input
6 7 2
Output
75
Note
Two ways to play the game are considered different if the final pictures are different. In other words, if one way contains a rectangle that is not contained in the other way.
In the first sample Anna, who performs her first and only move, has only one possible action plan β insert a 1 Γ 1 square inside the given 3 Γ 3 square.
In the second sample Anna has as much as 9 variants: 4 ways to paint a 1 Γ 1 square, 2 ways to insert a 1 Γ 2 rectangle vertically, 2 more ways to insert it horizontally and one more way is to insert a 2 Γ 2 square.
Submitted Solution:
```
MOD = 10 ** 9 + 7
def egcd(a, b):
if a == 0:
return (b, 0, 1)
else:
g, y, x = egcd(b % a, a)
return (g, x - (b // a) * y, y)
def modinv(a, m):
g, x, y = egcd(a, m)
if g != 1:
raise Exception('modular inverse does not exist')
else:
return x % m
def combination(n,k,MOD):
ans = 1
for i in range(n - k + 1, n + 1):
ans *= i
ans %= MOD
for i in range(1,k+1):
ans *= modinv(i,MOD)
ans %= MOD
return ans
n,m,k = map(int,input().split())
print(combination(n-1,n-2 * k-1,MOD) * combination(m-1,m - 2 * k - 1,MOD) % MOD)
``` | instruction | 0 | 63,266 | 19 | 126,532 |
No | output | 1 | 63,266 | 19 | 126,533 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In this task Anna and Maria play the following game. Initially they have a checkered piece of paper with a painted n Γ m rectangle (only the border, no filling). Anna and Maria move in turns and Anna starts. During each move one should paint inside the last-painted rectangle a new lesser rectangle (along the grid lines). The new rectangle should have no common points with the previous one. Note that when we paint a rectangle, we always paint only the border, the rectangles aren't filled.
Nobody wins the game β Anna and Maria simply play until they have done k moves in total. Count the number of different ways to play this game.
Input
The first and only line contains three integers: n, m, k (1 β€ n, m, k β€ 1000).
Output
Print the single number β the number of the ways to play the game. As this number can be very big, print the value modulo 1000000007 (109 + 7).
Examples
Input
3 3 1
Output
1
Input
4 4 1
Output
9
Input
6 7 2
Output
75
Note
Two ways to play the game are considered different if the final pictures are different. In other words, if one way contains a rectangle that is not contained in the other way.
In the first sample Anna, who performs her first and only move, has only one possible action plan β insert a 1 Γ 1 square inside the given 3 Γ 3 square.
In the second sample Anna has as much as 9 variants: 4 ways to paint a 1 Γ 1 square, 2 ways to insert a 1 Γ 2 rectangle vertically, 2 more ways to insert it horizontally and one more way is to insert a 2 Γ 2 square.
Submitted Solution:
```
def inv(a):
return pow(a, mod - 2, mod)
n, m, k = map(int, input().split())
fact = [1]
mod = 1000000007
for i in range(1, 1001):
fact.append(fact[-1] * i % mod)
print(fact[n - 1] * inv(2 * k) * inv(n - 2 * k - 1) * fact[m - 1] * inv(2 * k) * inv(m - 2 * k - 1) % mod)
``` | instruction | 0 | 63,267 | 19 | 126,534 |
No | output | 1 | 63,267 | 19 | 126,535 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bob is playing a game named "Walk on Matrix".
In this game, player is given an n Γ m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}.
To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix.
However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to.
Bob can't wait to find out the maximum score he can get using the tool he recently learnt β dynamic programming. Here is his algorithm for this problem.
<image>
However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n Γ m matrix A=(a_{i,j}) such that
* 1 β€ n,m β€ 500 (as Bob hates large matrix);
* 0 β€ a_{i,j} β€ 3 β
10^5 for all 1 β€ iβ€ n,1 β€ jβ€ m (as Bob hates large numbers);
* the difference between the maximum score he can get and the output of his algorithm is exactly k.
It can be shown that for any given integer k such that 0 β€ k β€ 10^5, there exists a matrix satisfying the above constraints.
Please help him with it!
Input
The only line of the input contains one single integer k (0 β€ k β€ 10^5).
Output
Output two integers n, m (1 β€ n,m β€ 500) in the first line, representing the size of the matrix.
Then output n lines with m integers in each line, a_{i,j} in the (i+1)-th row, j-th column.
Examples
Input
0
Output
1 1
300000
Input
1
Output
3 4
7 3 3 1
4 8 3 6
7 7 7 3
Note
In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000.
In the second example, the maximum score Bob can achieve is 7\&3\&3\&3\&7\&3=3, while the output of his algorithm is 2. | instruction | 0 | 63,268 | 19 | 126,536 |
Tags: bitmasks, constructive algorithms, math
Correct Solution:
```
# https://codeforces.com/contest/1332/problem/D
k=int(input())
y=1
while y<=k:
y<<=1
X=k+y
m=[[X,y,y],
[k,y,y],
[k,X,k]]
print(3, 3)
for arr in m:
print(' '.join([str(x) for x in arr]))
``` | output | 1 | 63,268 | 19 | 126,537 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bob is playing a game named "Walk on Matrix".
In this game, player is given an n Γ m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}.
To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix.
However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to.
Bob can't wait to find out the maximum score he can get using the tool he recently learnt β dynamic programming. Here is his algorithm for this problem.
<image>
However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n Γ m matrix A=(a_{i,j}) such that
* 1 β€ n,m β€ 500 (as Bob hates large matrix);
* 0 β€ a_{i,j} β€ 3 β
10^5 for all 1 β€ iβ€ n,1 β€ jβ€ m (as Bob hates large numbers);
* the difference between the maximum score he can get and the output of his algorithm is exactly k.
It can be shown that for any given integer k such that 0 β€ k β€ 10^5, there exists a matrix satisfying the above constraints.
Please help him with it!
Input
The only line of the input contains one single integer k (0 β€ k β€ 10^5).
Output
Output two integers n, m (1 β€ n,m β€ 500) in the first line, representing the size of the matrix.
Then output n lines with m integers in each line, a_{i,j} in the (i+1)-th row, j-th column.
Examples
Input
0
Output
1 1
300000
Input
1
Output
3 4
7 3 3 1
4 8 3 6
7 7 7 3
Note
In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000.
In the second example, the maximum score Bob can achieve is 7\&3\&3\&3\&7\&3=3, while the output of his algorithm is 2. | instruction | 0 | 63,269 | 19 | 126,538 |
Tags: bitmasks, constructive algorithms, math
Correct Solution:
```
k = int(input())
print(3,4)
print(262143, k, k, 0)
print(131072, 0, k, 0)
print(131072, 131072, 262143, 131071)
``` | output | 1 | 63,269 | 19 | 126,539 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bob is playing a game named "Walk on Matrix".
In this game, player is given an n Γ m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}.
To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix.
However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to.
Bob can't wait to find out the maximum score he can get using the tool he recently learnt β dynamic programming. Here is his algorithm for this problem.
<image>
However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n Γ m matrix A=(a_{i,j}) such that
* 1 β€ n,m β€ 500 (as Bob hates large matrix);
* 0 β€ a_{i,j} β€ 3 β
10^5 for all 1 β€ iβ€ n,1 β€ jβ€ m (as Bob hates large numbers);
* the difference between the maximum score he can get and the output of his algorithm is exactly k.
It can be shown that for any given integer k such that 0 β€ k β€ 10^5, there exists a matrix satisfying the above constraints.
Please help him with it!
Input
The only line of the input contains one single integer k (0 β€ k β€ 10^5).
Output
Output two integers n, m (1 β€ n,m β€ 500) in the first line, representing the size of the matrix.
Then output n lines with m integers in each line, a_{i,j} in the (i+1)-th row, j-th column.
Examples
Input
0
Output
1 1
300000
Input
1
Output
3 4
7 3 3 1
4 8 3 6
7 7 7 3
Note
In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000.
In the second example, the maximum score Bob can achieve is 7\&3\&3\&3\&7\&3=3, while the output of his algorithm is 2. | instruction | 0 | 63,270 | 19 | 126,540 |
Tags: bitmasks, constructive algorithms, math
Correct Solution:
```
k=int(input())
if(k==0):
print(1,1)
print(1)
exit(0)
q=bin(100000)
t=pow(2,len(q)-1)-1
rem=bin(k)
rem=rem[2::]
rem='0'*(len(bin(t))-2-len(rem))+(rem)
alpha=0
for i in range(len(rem)):
if(rem[i]=='0'):
alpha+=pow(2,len(rem)-i-1)
ans=[t,k,0]
gns=[alpha,t,0]
tns=[0,k,k]
print(3,3)
print(*ans)
print(*gns)
print(*tns)
``` | output | 1 | 63,270 | 19 | 126,541 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bob is playing a game named "Walk on Matrix".
In this game, player is given an n Γ m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}.
To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix.
However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to.
Bob can't wait to find out the maximum score he can get using the tool he recently learnt β dynamic programming. Here is his algorithm for this problem.
<image>
However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n Γ m matrix A=(a_{i,j}) such that
* 1 β€ n,m β€ 500 (as Bob hates large matrix);
* 0 β€ a_{i,j} β€ 3 β
10^5 for all 1 β€ iβ€ n,1 β€ jβ€ m (as Bob hates large numbers);
* the difference between the maximum score he can get and the output of his algorithm is exactly k.
It can be shown that for any given integer k such that 0 β€ k β€ 10^5, there exists a matrix satisfying the above constraints.
Please help him with it!
Input
The only line of the input contains one single integer k (0 β€ k β€ 10^5).
Output
Output two integers n, m (1 β€ n,m β€ 500) in the first line, representing the size of the matrix.
Then output n lines with m integers in each line, a_{i,j} in the (i+1)-th row, j-th column.
Examples
Input
0
Output
1 1
300000
Input
1
Output
3 4
7 3 3 1
4 8 3 6
7 7 7 3
Note
In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000.
In the second example, the maximum score Bob can achieve is 7\&3\&3\&3\&7\&3=3, while the output of his algorithm is 2. | instruction | 0 | 63,271 | 19 | 126,542 |
Tags: bitmasks, constructive algorithms, math
Correct Solution:
```
k = int(input())
b = k.bit_length()
all_1 = (1<<(b+1)) - 1
first_1 = 1<<b
other_1 = first_1 - 1
a = [
[all_1, first_1, 0],
[other_1, all_1, k],
]
print(2, 3)
for row in a: print(*row)
``` | output | 1 | 63,271 | 19 | 126,543 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bob is playing a game named "Walk on Matrix".
In this game, player is given an n Γ m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}.
To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix.
However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to.
Bob can't wait to find out the maximum score he can get using the tool he recently learnt β dynamic programming. Here is his algorithm for this problem.
<image>
However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n Γ m matrix A=(a_{i,j}) such that
* 1 β€ n,m β€ 500 (as Bob hates large matrix);
* 0 β€ a_{i,j} β€ 3 β
10^5 for all 1 β€ iβ€ n,1 β€ jβ€ m (as Bob hates large numbers);
* the difference between the maximum score he can get and the output of his algorithm is exactly k.
It can be shown that for any given integer k such that 0 β€ k β€ 10^5, there exists a matrix satisfying the above constraints.
Please help him with it!
Input
The only line of the input contains one single integer k (0 β€ k β€ 10^5).
Output
Output two integers n, m (1 β€ n,m β€ 500) in the first line, representing the size of the matrix.
Then output n lines with m integers in each line, a_{i,j} in the (i+1)-th row, j-th column.
Examples
Input
0
Output
1 1
300000
Input
1
Output
3 4
7 3 3 1
4 8 3 6
7 7 7 3
Note
In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000.
In the second example, the maximum score Bob can achieve is 7\&3\&3\&3\&7\&3=3, while the output of his algorithm is 2. | instruction | 0 | 63,272 | 19 | 126,544 |
Tags: bitmasks, constructive algorithms, math
Correct Solution:
```
k = int(input())
x = 1
while x <= k:
x *= 2
x1 = x * 2 - 1
print(3, 3)
print(x1, x, 0)
print(k, x1, x - 1)
print(0, x - 1, x1)
``` | output | 1 | 63,272 | 19 | 126,545 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bob is playing a game named "Walk on Matrix".
In this game, player is given an n Γ m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}.
To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix.
However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to.
Bob can't wait to find out the maximum score he can get using the tool he recently learnt β dynamic programming. Here is his algorithm for this problem.
<image>
However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n Γ m matrix A=(a_{i,j}) such that
* 1 β€ n,m β€ 500 (as Bob hates large matrix);
* 0 β€ a_{i,j} β€ 3 β
10^5 for all 1 β€ iβ€ n,1 β€ jβ€ m (as Bob hates large numbers);
* the difference between the maximum score he can get and the output of his algorithm is exactly k.
It can be shown that for any given integer k such that 0 β€ k β€ 10^5, there exists a matrix satisfying the above constraints.
Please help him with it!
Input
The only line of the input contains one single integer k (0 β€ k β€ 10^5).
Output
Output two integers n, m (1 β€ n,m β€ 500) in the first line, representing the size of the matrix.
Then output n lines with m integers in each line, a_{i,j} in the (i+1)-th row, j-th column.
Examples
Input
0
Output
1 1
300000
Input
1
Output
3 4
7 3 3 1
4 8 3 6
7 7 7 3
Note
In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000.
In the second example, the maximum score Bob can achieve is 7\&3\&3\&3\&7\&3=3, while the output of his algorithm is 2. | instruction | 0 | 63,273 | 19 | 126,546 |
Tags: bitmasks, constructive algorithms, math
Correct Solution:
```
k = int(input())
pow2 = 0
pow2x = 1
while pow2x <= k * 2:
pow2 += 1
pow2x *= 2
one = pow2x - 1
zer = pow2x // 2
kek = k
ans = \
[
[one, one, one, one, zer],
[one, 0, one, kek, zer],
[one, one, 0, kek, one],
[one, kek, kek, 0, kek],
[zer, zer, one, kek, kek]
]
print(5, 5)
for line in ans:
print(*line)
``` | output | 1 | 63,273 | 19 | 126,547 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bob is playing a game named "Walk on Matrix".
In this game, player is given an n Γ m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}.
To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix.
However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to.
Bob can't wait to find out the maximum score he can get using the tool he recently learnt β dynamic programming. Here is his algorithm for this problem.
<image>
However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n Γ m matrix A=(a_{i,j}) such that
* 1 β€ n,m β€ 500 (as Bob hates large matrix);
* 0 β€ a_{i,j} β€ 3 β
10^5 for all 1 β€ iβ€ n,1 β€ jβ€ m (as Bob hates large numbers);
* the difference between the maximum score he can get and the output of his algorithm is exactly k.
It can be shown that for any given integer k such that 0 β€ k β€ 10^5, there exists a matrix satisfying the above constraints.
Please help him with it!
Input
The only line of the input contains one single integer k (0 β€ k β€ 10^5).
Output
Output two integers n, m (1 β€ n,m β€ 500) in the first line, representing the size of the matrix.
Then output n lines with m integers in each line, a_{i,j} in the (i+1)-th row, j-th column.
Examples
Input
0
Output
1 1
300000
Input
1
Output
3 4
7 3 3 1
4 8 3 6
7 7 7 3
Note
In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000.
In the second example, the maximum score Bob can achieve is 7\&3\&3\&3\&7\&3=3, while the output of his algorithm is 2. | instruction | 0 | 63,274 | 19 | 126,548 |
Tags: bitmasks, constructive algorithms, math
Correct Solution:
```
k = int(input())
print(2, 3)
print(pow(2, 18) - 1, k, 0)
print(pow(2, 17), pow(2, 18) - 1, k)
``` | output | 1 | 63,274 | 19 | 126,549 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bob is playing a game named "Walk on Matrix".
In this game, player is given an n Γ m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}.
To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix.
However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to.
Bob can't wait to find out the maximum score he can get using the tool he recently learnt β dynamic programming. Here is his algorithm for this problem.
<image>
However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n Γ m matrix A=(a_{i,j}) such that
* 1 β€ n,m β€ 500 (as Bob hates large matrix);
* 0 β€ a_{i,j} β€ 3 β
10^5 for all 1 β€ iβ€ n,1 β€ jβ€ m (as Bob hates large numbers);
* the difference between the maximum score he can get and the output of his algorithm is exactly k.
It can be shown that for any given integer k such that 0 β€ k β€ 10^5, there exists a matrix satisfying the above constraints.
Please help him with it!
Input
The only line of the input contains one single integer k (0 β€ k β€ 10^5).
Output
Output two integers n, m (1 β€ n,m β€ 500) in the first line, representing the size of the matrix.
Then output n lines with m integers in each line, a_{i,j} in the (i+1)-th row, j-th column.
Examples
Input
0
Output
1 1
300000
Input
1
Output
3 4
7 3 3 1
4 8 3 6
7 7 7 3
Note
In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000.
In the second example, the maximum score Bob can achieve is 7\&3\&3\&3\&7\&3=3, while the output of his algorithm is 2. | instruction | 0 | 63,275 | 19 | 126,550 |
Tags: bitmasks, constructive algorithms, math
Correct Solution:
```
from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
#from math import *
from collections import defaultdict as dd, deque
def data(): return sys.stdin.readline().strip()
def mdata(): return map(int, data().split())
# sys.setrecursionlimit(100000)
k=int(data())
x=len(bin(k)[2:])
t=pow(2,x)
m=[[k+t,k+t,k+t,t],[k+t,k,k,k+t],[t,k+t,k+t,k]]
print(3,4)
for i in range(3):
print(*m[i])
``` | output | 1 | 63,275 | 19 | 126,551 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bob is playing a game named "Walk on Matrix".
In this game, player is given an n Γ m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}.
To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix.
However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to.
Bob can't wait to find out the maximum score he can get using the tool he recently learnt β dynamic programming. Here is his algorithm for this problem.
<image>
However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n Γ m matrix A=(a_{i,j}) such that
* 1 β€ n,m β€ 500 (as Bob hates large matrix);
* 0 β€ a_{i,j} β€ 3 β
10^5 for all 1 β€ iβ€ n,1 β€ jβ€ m (as Bob hates large numbers);
* the difference between the maximum score he can get and the output of his algorithm is exactly k.
It can be shown that for any given integer k such that 0 β€ k β€ 10^5, there exists a matrix satisfying the above constraints.
Please help him with it!
Input
The only line of the input contains one single integer k (0 β€ k β€ 10^5).
Output
Output two integers n, m (1 β€ n,m β€ 500) in the first line, representing the size of the matrix.
Then output n lines with m integers in each line, a_{i,j} in the (i+1)-th row, j-th column.
Examples
Input
0
Output
1 1
300000
Input
1
Output
3 4
7 3 3 1
4 8 3 6
7 7 7 3
Note
In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000.
In the second example, the maximum score Bob can achieve is 7\&3\&3\&3\&7\&3=3, while the output of his algorithm is 2.
Submitted Solution:
```
import sys
input = sys.stdin.readline
from sys import stdin, stdout
import math
def max_bit(k):
n=int(math.log(k,2))+1
return 2**n
def main():
#n,m=map(int,input().split())
k=int(input())
if k!=0:
x1=max_bit(k)
else:
x1,y1=0,0
y1=k+x1
print(3,4)
arr=[[0 for i in range(4)] for j in range(3)]
arr[0][0]=y1
arr[2][2]=y1
arr[0][1]=k
arr[0][2]=k
arr[1][2]=k
arr[2][3]=k
arr[1][0]=x1
arr[2][0]=x1
arr[2][1]=x1
for i in range(3):
for j in range(4):
print(arr[i][j],end=" ")
print()
if __name__ == "__main__":
main()
``` | instruction | 0 | 63,276 | 19 | 126,552 |
Yes | output | 1 | 63,276 | 19 | 126,553 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bob is playing a game named "Walk on Matrix".
In this game, player is given an n Γ m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}.
To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix.
However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to.
Bob can't wait to find out the maximum score he can get using the tool he recently learnt β dynamic programming. Here is his algorithm for this problem.
<image>
However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n Γ m matrix A=(a_{i,j}) such that
* 1 β€ n,m β€ 500 (as Bob hates large matrix);
* 0 β€ a_{i,j} β€ 3 β
10^5 for all 1 β€ iβ€ n,1 β€ jβ€ m (as Bob hates large numbers);
* the difference between the maximum score he can get and the output of his algorithm is exactly k.
It can be shown that for any given integer k such that 0 β€ k β€ 10^5, there exists a matrix satisfying the above constraints.
Please help him with it!
Input
The only line of the input contains one single integer k (0 β€ k β€ 10^5).
Output
Output two integers n, m (1 β€ n,m β€ 500) in the first line, representing the size of the matrix.
Then output n lines with m integers in each line, a_{i,j} in the (i+1)-th row, j-th column.
Examples
Input
0
Output
1 1
300000
Input
1
Output
3 4
7 3 3 1
4 8 3 6
7 7 7 3
Note
In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000.
In the second example, the maximum score Bob can achieve is 7\&3\&3\&3\&7\&3=3, while the output of his algorithm is 2.
Submitted Solution:
```
k = int(input())
if k == 0:
print(1, 1)
print(0)
else:
print(3, 3)
print(2 ** 18 - 1, k, k)
print(2**17, 2**17, 2**18-1)
print(0, 0, k)
``` | instruction | 0 | 63,277 | 19 | 126,554 |
Yes | output | 1 | 63,277 | 19 | 126,555 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bob is playing a game named "Walk on Matrix".
In this game, player is given an n Γ m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}.
To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix.
However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to.
Bob can't wait to find out the maximum score he can get using the tool he recently learnt β dynamic programming. Here is his algorithm for this problem.
<image>
However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n Γ m matrix A=(a_{i,j}) such that
* 1 β€ n,m β€ 500 (as Bob hates large matrix);
* 0 β€ a_{i,j} β€ 3 β
10^5 for all 1 β€ iβ€ n,1 β€ jβ€ m (as Bob hates large numbers);
* the difference between the maximum score he can get and the output of his algorithm is exactly k.
It can be shown that for any given integer k such that 0 β€ k β€ 10^5, there exists a matrix satisfying the above constraints.
Please help him with it!
Input
The only line of the input contains one single integer k (0 β€ k β€ 10^5).
Output
Output two integers n, m (1 β€ n,m β€ 500) in the first line, representing the size of the matrix.
Then output n lines with m integers in each line, a_{i,j} in the (i+1)-th row, j-th column.
Examples
Input
0
Output
1 1
300000
Input
1
Output
3 4
7 3 3 1
4 8 3 6
7 7 7 3
Note
In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000.
In the second example, the maximum score Bob can achieve is 7\&3\&3\&3\&7\&3=3, while the output of his algorithm is 2.
Submitted Solution:
```
k = int(input())
print(2, 3)
print(2**17 + k, k, 0)
print(2**17, 2**17 + k, k)
``` | instruction | 0 | 63,278 | 19 | 126,556 |
Yes | output | 1 | 63,278 | 19 | 126,557 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bob is playing a game named "Walk on Matrix".
In this game, player is given an n Γ m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}.
To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix.
However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to.
Bob can't wait to find out the maximum score he can get using the tool he recently learnt β dynamic programming. Here is his algorithm for this problem.
<image>
However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n Γ m matrix A=(a_{i,j}) such that
* 1 β€ n,m β€ 500 (as Bob hates large matrix);
* 0 β€ a_{i,j} β€ 3 β
10^5 for all 1 β€ iβ€ n,1 β€ jβ€ m (as Bob hates large numbers);
* the difference between the maximum score he can get and the output of his algorithm is exactly k.
It can be shown that for any given integer k such that 0 β€ k β€ 10^5, there exists a matrix satisfying the above constraints.
Please help him with it!
Input
The only line of the input contains one single integer k (0 β€ k β€ 10^5).
Output
Output two integers n, m (1 β€ n,m β€ 500) in the first line, representing the size of the matrix.
Then output n lines with m integers in each line, a_{i,j} in the (i+1)-th row, j-th column.
Examples
Input
0
Output
1 1
300000
Input
1
Output
3 4
7 3 3 1
4 8 3 6
7 7 7 3
Note
In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000.
In the second example, the maximum score Bob can achieve is 7\&3\&3\&3\&7\&3=3, while the output of his algorithm is 2.
Submitted Solution:
```
i = 0
ts = [1]
while ts[-1] <= 10**5:
i+=1
ts.append(2**i)
def slv(k):
if k == 0:
print(1,1)
print(1)
return
t = 0
for i in ts:
if i > k:
t=i
break
t=t*2-1
print(3,3)
print(t, k, t)
print(t-k, t-k, t)
print(t, t, k)
k=int(input())
slv(k)
``` | instruction | 0 | 63,279 | 19 | 126,558 |
Yes | output | 1 | 63,279 | 19 | 126,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bob is playing a game named "Walk on Matrix".
In this game, player is given an n Γ m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}.
To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix.
However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to.
Bob can't wait to find out the maximum score he can get using the tool he recently learnt β dynamic programming. Here is his algorithm for this problem.
<image>
However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n Γ m matrix A=(a_{i,j}) such that
* 1 β€ n,m β€ 500 (as Bob hates large matrix);
* 0 β€ a_{i,j} β€ 3 β
10^5 for all 1 β€ iβ€ n,1 β€ jβ€ m (as Bob hates large numbers);
* the difference between the maximum score he can get and the output of his algorithm is exactly k.
It can be shown that for any given integer k such that 0 β€ k β€ 10^5, there exists a matrix satisfying the above constraints.
Please help him with it!
Input
The only line of the input contains one single integer k (0 β€ k β€ 10^5).
Output
Output two integers n, m (1 β€ n,m β€ 500) in the first line, representing the size of the matrix.
Then output n lines with m integers in each line, a_{i,j} in the (i+1)-th row, j-th column.
Examples
Input
0
Output
1 1
300000
Input
1
Output
3 4
7 3 3 1
4 8 3 6
7 7 7 3
Note
In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000.
In the second example, the maximum score Bob can achieve is 7\&3\&3\&3\&7\&3=3, while the output of his algorithm is 2.
Submitted Solution:
```
k = int(input())
print(2,4)
m = [[1,0,1,1,1],
[1,1,1,0,1]]
for l in m:
print(*[k*x for x in l])
``` | instruction | 0 | 63,280 | 19 | 126,560 |
No | output | 1 | 63,280 | 19 | 126,561 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bob is playing a game named "Walk on Matrix".
In this game, player is given an n Γ m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}.
To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix.
However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to.
Bob can't wait to find out the maximum score he can get using the tool he recently learnt β dynamic programming. Here is his algorithm for this problem.
<image>
However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n Γ m matrix A=(a_{i,j}) such that
* 1 β€ n,m β€ 500 (as Bob hates large matrix);
* 0 β€ a_{i,j} β€ 3 β
10^5 for all 1 β€ iβ€ n,1 β€ jβ€ m (as Bob hates large numbers);
* the difference between the maximum score he can get and the output of his algorithm is exactly k.
It can be shown that for any given integer k such that 0 β€ k β€ 10^5, there exists a matrix satisfying the above constraints.
Please help him with it!
Input
The only line of the input contains one single integer k (0 β€ k β€ 10^5).
Output
Output two integers n, m (1 β€ n,m β€ 500) in the first line, representing the size of the matrix.
Then output n lines with m integers in each line, a_{i,j} in the (i+1)-th row, j-th column.
Examples
Input
0
Output
1 1
300000
Input
1
Output
3 4
7 3 3 1
4 8 3 6
7 7 7 3
Note
In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000.
In the second example, the maximum score Bob can achieve is 7\&3\&3\&3\&7\&3=3, while the output of his algorithm is 2.
Submitted Solution:
```
k = int(input())
p = 262143
print(3,2)
print(p,k)
print(p,k)
print(0,k)
``` | instruction | 0 | 63,281 | 19 | 126,562 |
No | output | 1 | 63,281 | 19 | 126,563 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bob is playing a game named "Walk on Matrix".
In this game, player is given an n Γ m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}.
To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix.
However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to.
Bob can't wait to find out the maximum score he can get using the tool he recently learnt β dynamic programming. Here is his algorithm for this problem.
<image>
However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n Γ m matrix A=(a_{i,j}) such that
* 1 β€ n,m β€ 500 (as Bob hates large matrix);
* 0 β€ a_{i,j} β€ 3 β
10^5 for all 1 β€ iβ€ n,1 β€ jβ€ m (as Bob hates large numbers);
* the difference between the maximum score he can get and the output of his algorithm is exactly k.
It can be shown that for any given integer k such that 0 β€ k β€ 10^5, there exists a matrix satisfying the above constraints.
Please help him with it!
Input
The only line of the input contains one single integer k (0 β€ k β€ 10^5).
Output
Output two integers n, m (1 β€ n,m β€ 500) in the first line, representing the size of the matrix.
Then output n lines with m integers in each line, a_{i,j} in the (i+1)-th row, j-th column.
Examples
Input
0
Output
1 1
300000
Input
1
Output
3 4
7 3 3 1
4 8 3 6
7 7 7 3
Note
In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000.
In the second example, the maximum score Bob can achieve is 7\&3\&3\&3\&7\&3=3, while the output of his algorithm is 2.
Submitted Solution:
```
k=int(input())
print(3*k,3*k,2*k)
print(3*k,k,2*k)
print(2*k,2*k,k)
``` | instruction | 0 | 63,282 | 19 | 126,564 |
No | output | 1 | 63,282 | 19 | 126,565 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bob is playing a game named "Walk on Matrix".
In this game, player is given an n Γ m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}.
To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix.
However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to.
Bob can't wait to find out the maximum score he can get using the tool he recently learnt β dynamic programming. Here is his algorithm for this problem.
<image>
However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n Γ m matrix A=(a_{i,j}) such that
* 1 β€ n,m β€ 500 (as Bob hates large matrix);
* 0 β€ a_{i,j} β€ 3 β
10^5 for all 1 β€ iβ€ n,1 β€ jβ€ m (as Bob hates large numbers);
* the difference between the maximum score he can get and the output of his algorithm is exactly k.
It can be shown that for any given integer k such that 0 β€ k β€ 10^5, there exists a matrix satisfying the above constraints.
Please help him with it!
Input
The only line of the input contains one single integer k (0 β€ k β€ 10^5).
Output
Output two integers n, m (1 β€ n,m β€ 500) in the first line, representing the size of the matrix.
Then output n lines with m integers in each line, a_{i,j} in the (i+1)-th row, j-th column.
Examples
Input
0
Output
1 1
300000
Input
1
Output
3 4
7 3 3 1
4 8 3 6
7 7 7 3
Note
In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000.
In the second example, the maximum score Bob can achieve is 7\&3\&3\&3\&7\&3=3, while the output of his algorithm is 2.
Submitted Solution:
```
import sys
# 26
input = lambda: sys.stdin.readline().strip()
ipnut = input
k = int(ipnut())
t = 1
if k==1:
print('''3 4
7 3 3 1
4 8 3 6
7 7 7 3''')
exit(0)
while t<=k:
t*=2
t1 = 2*t-1
print(t1,k,k)
print(t,t1,k)
``` | instruction | 0 | 63,283 | 19 | 126,566 |
No | output | 1 | 63,283 | 19 | 126,567 |
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bob is playing a game named "Walk on Matrix".
In this game, player is given an n Γ m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}.
To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix.
However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to.
Bob can't wait to find out the maximum score he can get using the tool he recently learnt β dynamic programming. Here is his algorithm for this problem.
<image>
However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n Γ m matrix A=(a_{i,j}) such that
* 1 β€ n,m β€ 500 (as Bob hates large matrix);
* 0 β€ a_{i,j} β€ 3 β
10^5 for all 1 β€ iβ€ n,1 β€ jβ€ m (as Bob hates large numbers);
* the difference between the maximum score he can get and the output of his algorithm is exactly k.
It can be shown that for any given integer k such that 0 β€ k β€ 10^5, there exists a matrix satisfying the above constraints.
Please help him with it!
Input
The only line of the input contains one single integer k (0 β€ k β€ 10^5).
Output
Output two integers n, m (1 β€ n,m β€ 500) in the first line, representing the size of the matrix.
Then output n lines with m integers in each line, a_{i,j} in the (i+1)-th row, j-th column.
Examples
Input
0
Output
1 1
300000
Input
1
Output
3 4
7 3 3 1
4 8 3 6
7 7 7 3
Note
In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000.
In the second example, the maximum score Bob can achieve is 7\&3\&3\&3\&7\&3=3, while the output of his algorithm is 2.
Submitted Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
from fractions import gcd
raw_input = stdin.readline
pr = stdout.write
def in_arr():
return map(int,raw_input().split())
def pr_num(n):
stdout.write(str(n)+'\n')
def pr_arr(arr):
for i in arr:
stdout.write(str(i)+' ')
stdout.write('\n')
range = xrange # not for python 3.0+
k=input()
n,m=3,3
mx=(2**18)-1
arr=[[mx for i in range(3)] for j in range(3)]
arr[1][1]=k
arr[-1][-1]=k
arr[1][2]=0
arr[2][0]-=k
arr[2][1]=2**17+1
print n,m
for i in range(n):
for j in range(m):
print (arr[i][j]),
print
``` | instruction | 0 | 63,284 | 19 | 126,568 |
No | output | 1 | 63,284 | 19 | 126,569 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a card deck of n cards, numbered from top to bottom, i. e. the top card has index 1 and bottom card β index n. Each card has its color: the i-th card has color a_i.
You should process q queries. The j-th query is described by integer t_j. For each query you should:
* find the highest card in the deck with color t_j, i. e. the card with minimum index;
* print the position of the card you found;
* take the card and place it on top of the deck.
Input
The first line contains two integers n and q (2 β€ n β€ 3 β
10^5; 1 β€ q β€ 3 β
10^5) β the number of cards in the deck and the number of queries.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 50) β the colors of cards.
The third line contains q integers t_1, t_2, ..., t_q (1 β€ t_j β€ 50) β the query colors. It's guaranteed that queries ask only colors that are present in the deck.
Output
Print q integers β the answers for each query.
Example
Input
7 5
2 1 1 4 3 3 1
3 2 1 1 4
Output
5 2 3 1 5
Note
Description of the sample:
1. the deck is [2, 1, 1, 4, \underline{3}, 3, 1] and the first card with color t_1 = 3 has position 5;
2. the deck is [3, \underline{2}, 1, 1, 4, 3, 1] and the first card with color t_2 = 2 has position 2;
3. the deck is [2, 3, \underline{1}, 1, 4, 3, 1] and the first card with color t_3 = 1 has position 3;
4. the deck is [\underline{1}, 2, 3, 1, 4, 3, 1] and the first card with color t_4 = 1 has position 1;
5. the deck is [1, 2, 3, 1, \underline{4}, 3, 1] and the first card with color t_5 = 4 has position 5.
Submitted Solution:
```
import sys,os,io
import math,bisect,operator
inf,mod = float('inf'),10**9+7
# sys.setrecursionlimit(10 ** 6)
from itertools import groupby,accumulate
from heapq import heapify,heappop,heappush
from collections import deque,Counter,defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
Neo = lambda : list(map(int,input().split()))
# test, = Neo()
n,q = Neo()
A = Neo()
Q = Neo()
s = set()
B = []
for i in range(n):
if A[i] not in s:
B.append([A[i],i+1])
s.add(A[i])
Ans = []
# print(B)
for i in Q:
for j in range(len(B)):
if B[j][0] == i:
Ans.append(B[j][1])
t = B[j]
B.remove(t)
B = [t]+B
B[0][1] = 1
break
else:
B[j][1] += 1
if B[j][1] > n:
B[j][1] %= n
# print(B)
print(*Ans)
``` | instruction | 0 | 63,378 | 19 | 126,756 |
Yes | output | 1 | 63,378 | 19 | 126,757 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a card deck of n cards, numbered from top to bottom, i. e. the top card has index 1 and bottom card β index n. Each card has its color: the i-th card has color a_i.
You should process q queries. The j-th query is described by integer t_j. For each query you should:
* find the highest card in the deck with color t_j, i. e. the card with minimum index;
* print the position of the card you found;
* take the card and place it on top of the deck.
Input
The first line contains two integers n and q (2 β€ n β€ 3 β
10^5; 1 β€ q β€ 3 β
10^5) β the number of cards in the deck and the number of queries.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 50) β the colors of cards.
The third line contains q integers t_1, t_2, ..., t_q (1 β€ t_j β€ 50) β the query colors. It's guaranteed that queries ask only colors that are present in the deck.
Output
Print q integers β the answers for each query.
Example
Input
7 5
2 1 1 4 3 3 1
3 2 1 1 4
Output
5 2 3 1 5
Note
Description of the sample:
1. the deck is [2, 1, 1, 4, \underline{3}, 3, 1] and the first card with color t_1 = 3 has position 5;
2. the deck is [3, \underline{2}, 1, 1, 4, 3, 1] and the first card with color t_2 = 2 has position 2;
3. the deck is [2, 3, \underline{1}, 1, 4, 3, 1] and the first card with color t_3 = 1 has position 3;
4. the deck is [\underline{1}, 2, 3, 1, 4, 3, 1] and the first card with color t_4 = 1 has position 1;
5. the deck is [1, 2, 3, 1, \underline{4}, 3, 1] and the first card with color t_5 = 4 has position 5.
Submitted Solution:
```
from sys import stdin, stdout
get_string = lambda: stdin.readline().strip('\n')
get_intmap = lambda: map( int, get_string().split(' ') )
def testcase():
n, q = get_intmap()
a = list(get_intmap())
ans = []
for t_color in get_intmap():
index = a.index(t_color)
ans.append(index + 1)#zero to one based indexing
for ind in range(index,0,-1):
a[ind], a[ind-1] = a[ind-1], a[ind]
print(" ".join([str(i) for i in ans]))
testcase();quit()
for t in range(int(input())):
testcase()
``` | instruction | 0 | 63,379 | 19 | 126,758 |
Yes | output | 1 | 63,379 | 19 | 126,759 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a card deck of n cards, numbered from top to bottom, i. e. the top card has index 1 and bottom card β index n. Each card has its color: the i-th card has color a_i.
You should process q queries. The j-th query is described by integer t_j. For each query you should:
* find the highest card in the deck with color t_j, i. e. the card with minimum index;
* print the position of the card you found;
* take the card and place it on top of the deck.
Input
The first line contains two integers n and q (2 β€ n β€ 3 β
10^5; 1 β€ q β€ 3 β
10^5) β the number of cards in the deck and the number of queries.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 50) β the colors of cards.
The third line contains q integers t_1, t_2, ..., t_q (1 β€ t_j β€ 50) β the query colors. It's guaranteed that queries ask only colors that are present in the deck.
Output
Print q integers β the answers for each query.
Example
Input
7 5
2 1 1 4 3 3 1
3 2 1 1 4
Output
5 2 3 1 5
Note
Description of the sample:
1. the deck is [2, 1, 1, 4, \underline{3}, 3, 1] and the first card with color t_1 = 3 has position 5;
2. the deck is [3, \underline{2}, 1, 1, 4, 3, 1] and the first card with color t_2 = 2 has position 2;
3. the deck is [2, 3, \underline{1}, 1, 4, 3, 1] and the first card with color t_3 = 1 has position 3;
4. the deck is [\underline{1}, 2, 3, 1, 4, 3, 1] and the first card with color t_4 = 1 has position 1;
5. the deck is [1, 2, 3, 1, \underline{4}, 3, 1] and the first card with color t_5 = 4 has position 5.
Submitted Solution:
```
import sys,os.path
import os
import sys
from io import BytesIO, IOBase
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")
if __name__ == '__main__':
n,q = map(int,input().split())
a = list(map(int,input().split()))
t = list(map(int,input().split()))
c = [[]for i in range(51)]
visited = [False for i in range(51)]
best = []
for i in range(n):
if not visited[a[i]]:
best.append([a[i],i+1])
visited[a[i]] = True
ans = []
diff = sum(visited)
for i in range(q):
k = 0
for j in range(len(best)):
if best[j][0]==t[i]:
ans.append(best[j][1])
k = best[j][1]
best[j][1] = 0
for j in range(len(best)):
if best[j][1]<k:
best[j][1]+=1
print(*ans)
``` | instruction | 0 | 63,380 | 19 | 126,760 |
Yes | output | 1 | 63,380 | 19 | 126,761 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a card deck of n cards, numbered from top to bottom, i. e. the top card has index 1 and bottom card β index n. Each card has its color: the i-th card has color a_i.
You should process q queries. The j-th query is described by integer t_j. For each query you should:
* find the highest card in the deck with color t_j, i. e. the card with minimum index;
* print the position of the card you found;
* take the card and place it on top of the deck.
Input
The first line contains two integers n and q (2 β€ n β€ 3 β
10^5; 1 β€ q β€ 3 β
10^5) β the number of cards in the deck and the number of queries.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 50) β the colors of cards.
The third line contains q integers t_1, t_2, ..., t_q (1 β€ t_j β€ 50) β the query colors. It's guaranteed that queries ask only colors that are present in the deck.
Output
Print q integers β the answers for each query.
Example
Input
7 5
2 1 1 4 3 3 1
3 2 1 1 4
Output
5 2 3 1 5
Note
Description of the sample:
1. the deck is [2, 1, 1, 4, \underline{3}, 3, 1] and the first card with color t_1 = 3 has position 5;
2. the deck is [3, \underline{2}, 1, 1, 4, 3, 1] and the first card with color t_2 = 2 has position 2;
3. the deck is [2, 3, \underline{1}, 1, 4, 3, 1] and the first card with color t_3 = 1 has position 3;
4. the deck is [\underline{1}, 2, 3, 1, 4, 3, 1] and the first card with color t_4 = 1 has position 1;
5. the deck is [1, 2, 3, 1, \underline{4}, 3, 1] and the first card with color t_5 = 4 has position 5.
Submitted Solution:
```
N, Q = map(int, input().split())
A = list(map(int, input().split()))
T = list(map(int, input().split()))
inds = [0]*51
for i in range(N):
if inds[A[i]]==0:
inds[A[i]] = i+1
ans = []
for i in range(Q):
ans.append(inds[T[i]])
for c in range(1,51):
if inds[c]<inds[T[i]]:
inds[c] += 1
inds[T[i]] = 1
print(*ans)
``` | instruction | 0 | 63,381 | 19 | 126,762 |
Yes | output | 1 | 63,381 | 19 | 126,763 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a card deck of n cards, numbered from top to bottom, i. e. the top card has index 1 and bottom card β index n. Each card has its color: the i-th card has color a_i.
You should process q queries. The j-th query is described by integer t_j. For each query you should:
* find the highest card in the deck with color t_j, i. e. the card with minimum index;
* print the position of the card you found;
* take the card and place it on top of the deck.
Input
The first line contains two integers n and q (2 β€ n β€ 3 β
10^5; 1 β€ q β€ 3 β
10^5) β the number of cards in the deck and the number of queries.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 50) β the colors of cards.
The third line contains q integers t_1, t_2, ..., t_q (1 β€ t_j β€ 50) β the query colors. It's guaranteed that queries ask only colors that are present in the deck.
Output
Print q integers β the answers for each query.
Example
Input
7 5
2 1 1 4 3 3 1
3 2 1 1 4
Output
5 2 3 1 5
Note
Description of the sample:
1. the deck is [2, 1, 1, 4, \underline{3}, 3, 1] and the first card with color t_1 = 3 has position 5;
2. the deck is [3, \underline{2}, 1, 1, 4, 3, 1] and the first card with color t_2 = 2 has position 2;
3. the deck is [2, 3, \underline{1}, 1, 4, 3, 1] and the first card with color t_3 = 1 has position 3;
4. the deck is [\underline{1}, 2, 3, 1, 4, 3, 1] and the first card with color t_4 = 1 has position 1;
5. the deck is [1, 2, 3, 1, \underline{4}, 3, 1] and the first card with color t_5 = 4 has position 5.
Submitted Solution:
```
n,q = [int(i) for i in input().split()]
deq = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
colors = [0 for i in range(50)]
for i in range(1,51):
if i in deq:
colors[i-1] = deq.index(i)+1
j = 0
answ = ""
for i in b:
print(colors[i-1], end=' ')
for j in range(1,51):
if colors[j-1] <=colors[i-1]:
colors[j-1]+=1
colors[i-1] = 1
``` | instruction | 0 | 63,382 | 19 | 126,764 |
No | output | 1 | 63,382 | 19 | 126,765 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a card deck of n cards, numbered from top to bottom, i. e. the top card has index 1 and bottom card β index n. Each card has its color: the i-th card has color a_i.
You should process q queries. The j-th query is described by integer t_j. For each query you should:
* find the highest card in the deck with color t_j, i. e. the card with minimum index;
* print the position of the card you found;
* take the card and place it on top of the deck.
Input
The first line contains two integers n and q (2 β€ n β€ 3 β
10^5; 1 β€ q β€ 3 β
10^5) β the number of cards in the deck and the number of queries.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 50) β the colors of cards.
The third line contains q integers t_1, t_2, ..., t_q (1 β€ t_j β€ 50) β the query colors. It's guaranteed that queries ask only colors that are present in the deck.
Output
Print q integers β the answers for each query.
Example
Input
7 5
2 1 1 4 3 3 1
3 2 1 1 4
Output
5 2 3 1 5
Note
Description of the sample:
1. the deck is [2, 1, 1, 4, \underline{3}, 3, 1] and the first card with color t_1 = 3 has position 5;
2. the deck is [3, \underline{2}, 1, 1, 4, 3, 1] and the first card with color t_2 = 2 has position 2;
3. the deck is [2, 3, \underline{1}, 1, 4, 3, 1] and the first card with color t_3 = 1 has position 3;
4. the deck is [\underline{1}, 2, 3, 1, 4, 3, 1] and the first card with color t_4 = 1 has position 1;
5. the deck is [1, 2, 3, 1, \underline{4}, 3, 1] and the first card with color t_5 = 4 has position 5.
Submitted Solution:
```
a,b=map(int,input().split())
l=list(map(int,input().split()))
lst=list(map(int,input().split()))
x=0
l1=[]
for i in lst:
l1.append(l.index(i)+1)
x=l.pop(l1[-1])
l.insert(0,x)
print(*l1)
``` | instruction | 0 | 63,383 | 19 | 126,766 |
No | output | 1 | 63,383 | 19 | 126,767 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a card deck of n cards, numbered from top to bottom, i. e. the top card has index 1 and bottom card β index n. Each card has its color: the i-th card has color a_i.
You should process q queries. The j-th query is described by integer t_j. For each query you should:
* find the highest card in the deck with color t_j, i. e. the card with minimum index;
* print the position of the card you found;
* take the card and place it on top of the deck.
Input
The first line contains two integers n and q (2 β€ n β€ 3 β
10^5; 1 β€ q β€ 3 β
10^5) β the number of cards in the deck and the number of queries.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 50) β the colors of cards.
The third line contains q integers t_1, t_2, ..., t_q (1 β€ t_j β€ 50) β the query colors. It's guaranteed that queries ask only colors that are present in the deck.
Output
Print q integers β the answers for each query.
Example
Input
7 5
2 1 1 4 3 3 1
3 2 1 1 4
Output
5 2 3 1 5
Note
Description of the sample:
1. the deck is [2, 1, 1, 4, \underline{3}, 3, 1] and the first card with color t_1 = 3 has position 5;
2. the deck is [3, \underline{2}, 1, 1, 4, 3, 1] and the first card with color t_2 = 2 has position 2;
3. the deck is [2, 3, \underline{1}, 1, 4, 3, 1] and the first card with color t_3 = 1 has position 3;
4. the deck is [\underline{1}, 2, 3, 1, 4, 3, 1] and the first card with color t_4 = 1 has position 1;
5. the deck is [1, 2, 3, 1, \underline{4}, 3, 1] and the first card with color t_5 = 4 has position 5.
Submitted Solution:
```
import sys
l=[int(i) for i in input().split()]
n=l[0]
q=l[1]
col=[int(i) for i in input().split()]
q1=[int(i) for i in input().split()]
check=[0]*n
res=[]
res.append(col.index(q1[0])+1)
check[q1[0]]=1
for i in range(2,q+1):
if(check[q1[i-1]]!=0):
res.append(i-check[q1[i-1]])
check[q1[i-1]]=i
else:
res.append(col.index(q1[i-1])+2)
check[q1[i-1]]=i
print(*res)
``` | instruction | 0 | 63,384 | 19 | 126,768 |
No | output | 1 | 63,384 | 19 | 126,769 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a card deck of n cards, numbered from top to bottom, i. e. the top card has index 1 and bottom card β index n. Each card has its color: the i-th card has color a_i.
You should process q queries. The j-th query is described by integer t_j. For each query you should:
* find the highest card in the deck with color t_j, i. e. the card with minimum index;
* print the position of the card you found;
* take the card and place it on top of the deck.
Input
The first line contains two integers n and q (2 β€ n β€ 3 β
10^5; 1 β€ q β€ 3 β
10^5) β the number of cards in the deck and the number of queries.
The second line contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 50) β the colors of cards.
The third line contains q integers t_1, t_2, ..., t_q (1 β€ t_j β€ 50) β the query colors. It's guaranteed that queries ask only colors that are present in the deck.
Output
Print q integers β the answers for each query.
Example
Input
7 5
2 1 1 4 3 3 1
3 2 1 1 4
Output
5 2 3 1 5
Note
Description of the sample:
1. the deck is [2, 1, 1, 4, \underline{3}, 3, 1] and the first card with color t_1 = 3 has position 5;
2. the deck is [3, \underline{2}, 1, 1, 4, 3, 1] and the first card with color t_2 = 2 has position 2;
3. the deck is [2, 3, \underline{1}, 1, 4, 3, 1] and the first card with color t_3 = 1 has position 3;
4. the deck is [\underline{1}, 2, 3, 1, 4, 3, 1] and the first card with color t_4 = 1 has position 1;
5. the deck is [1, 2, 3, 1, \underline{4}, 3, 1] and the first card with color t_5 = 4 has position 5.
Submitted Solution:
```
n,q=[int(i) for i in input().split()]
col=list(map(int,input().split()))
quer=list(map(int,input().split()))
d={}
for i in range(len(col)):
if col[i] not in d:
d[col[i]]=i+1
ans=[]
for q in quer:
ans.append(d[q])
for key,val in d.items():
if val<d[q]:
d[key]=val+1
elif val==d[q]:
d[key]=1
print(ans)
``` | instruction | 0 | 63,385 | 19 | 126,770 |
No | output | 1 | 63,385 | 19 | 126,771 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nauuo is a girl who loves playing cards.
One day she was playing cards but found that the cards were mixed with some empty ones.
There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom.
In one operation she can choose a card in her hands and play it β put it at the bottom of the pile, then draw the top card from the pile.
Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations?
Input
The first line contains a single integer n (1β€ nβ€ 2β
10^5) β the number of numbered cards.
The second line contains n integers a_1,a_2,β¦,a_n (0β€ a_iβ€ n) β the initial cards in Nauuo's hands. 0 represents an empty card.
The third line contains n integers b_1,b_2,β¦,b_n (0β€ b_iβ€ n) β the initial cards in the pile, given in order from top to bottom. 0 represents an empty card.
It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}.
Output
The output contains a single integer β the minimum number of operations to make the n numbered cards piled up in increasing order.
Examples
Input
3
0 2 0
3 0 1
Output
2
Input
3
0 2 0
1 0 3
Output
4
Input
11
0 0 0 5 0 0 0 4 0 0 11
9 2 6 0 8 1 7 0 3 0 10
Output
18
Note
Example 1
We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom.
Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order.
Example 2
Play an empty card and draw the card 1, then play 1, 2, 3 in order. | instruction | 0 | 64,048 | 19 | 128,096 |
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
*hand, = map(int, input().split())
*pile, = map(int, input().split())
dist = [0]*(n+1)
# Should return 2
# n = 3
# hand = [0, 2, 0]
# pile = [3, 0, 1]
# dist = [0]*(n+1)
# Should return 6
# n = 3
# hand = [0, 0, 0]
# pile = [2, 3, 1]
# dist = [0]*(n+1)
# Should return 5
# n = 3
# hand = [0, 3, 0]
# pile = [2, 1, 0]
# dist = [0]*(n+1)
# Should return 3
# n = 3
# hand = [1, 3, 0]
# pile = [2, 0, 0]
# dist = [0]*(n+1)
for index, card in enumerate(pile):
if card != 0:
dist[card] = index + 1
def is_valid():
# print('dist', dist)
if dist[1] == 0:
numbers_placed = 0
else:
base = dist[1]
for i in range(2, n-dist[1]+2):
if dist[i] != dist[1]+i-1:
numbers_placed = 0
break
else:
numbers_placed = n-dist[1]+1
if numbers_placed != 0:
for i in range(numbers_placed+1, n+1):
if dist[i] >= i -numbers_placed:
ans = dist[1] + n
break
else:
ans = n - numbers_placed
return ans
else:
delay = 0
for i in range(1, n+1):
# print('ans', i, dist[i], delay)
delay += max(dist[i]-(i-1+delay), 0)
return delay + n
print(is_valid())
# print(is_valid([0, 1, 2, 3], [1, 2, 3]))
# print(is_valid([0, 0, 2, 3], [0, 2, 3]))
# print(is_valid([0, 1, 2, 0], [1, 2, 0]))
``` | output | 1 | 64,048 | 19 | 128,097 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nauuo is a girl who loves playing cards.
One day she was playing cards but found that the cards were mixed with some empty ones.
There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom.
In one operation she can choose a card in her hands and play it β put it at the bottom of the pile, then draw the top card from the pile.
Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations?
Input
The first line contains a single integer n (1β€ nβ€ 2β
10^5) β the number of numbered cards.
The second line contains n integers a_1,a_2,β¦,a_n (0β€ a_iβ€ n) β the initial cards in Nauuo's hands. 0 represents an empty card.
The third line contains n integers b_1,b_2,β¦,b_n (0β€ b_iβ€ n) β the initial cards in the pile, given in order from top to bottom. 0 represents an empty card.
It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}.
Output
The output contains a single integer β the minimum number of operations to make the n numbered cards piled up in increasing order.
Examples
Input
3
0 2 0
3 0 1
Output
2
Input
3
0 2 0
1 0 3
Output
4
Input
11
0 0 0 5 0 0 0 4 0 0 11
9 2 6 0 8 1 7 0 3 0 10
Output
18
Note
Example 1
We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom.
Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order.
Example 2
Play an empty card and draw the card 1, then play 1, 2, 3 in order. | instruction | 0 | 64,049 | 19 | 128,098 |
Tags: greedy, implementation
Correct Solution:
```
from copy import deepcopy
import heapq
def main():
buf = input()
n = int(buf)
buf = input()
buflist = buf.split()
a = set(map(int, buflist))
buf = input()
buflist = buf.split()
b = list(map(int, buflist))
if 0 in a:
a.remove(0)
a = list(a)
heapq.heapify(a)
# speedrun
next_card = b[-1]
if next_card != 0:
expected_card = next_card - 1
next_card += 1
pointer = -2
while expected_card > 0:
if b[pointer] != expected_card:
break
pointer -= 1
expected_card -= 1
if expected_card == 0:
a_sp = deepcopy(a)
pointer = 0
while next_card <= n:
if not a_sp:
break
if a_sp[0] != next_card:
break
heapq.heappop(a_sp)
if b[pointer] > 0:
heapq.heappush(a_sp, b[pointer])
pointer += 1
next_card += 1
if next_card > n:
print(n - b[-1])
return
# normal
b_pointer = 0
drawn = 0
next_card = 1
while next_card <= n:
if a:
if a[0] == next_card:
heapq.heappop(a)
next_card += 1
if b_pointer < n:
if b[b_pointer] > 0:
heapq.heappush(a, b[b_pointer])
b_pointer += 1
drawn += 1
print(drawn)
if __name__ == '__main__':
main()
``` | output | 1 | 64,049 | 19 | 128,099 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nauuo is a girl who loves playing cards.
One day she was playing cards but found that the cards were mixed with some empty ones.
There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom.
In one operation she can choose a card in her hands and play it β put it at the bottom of the pile, then draw the top card from the pile.
Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations?
Input
The first line contains a single integer n (1β€ nβ€ 2β
10^5) β the number of numbered cards.
The second line contains n integers a_1,a_2,β¦,a_n (0β€ a_iβ€ n) β the initial cards in Nauuo's hands. 0 represents an empty card.
The third line contains n integers b_1,b_2,β¦,b_n (0β€ b_iβ€ n) β the initial cards in the pile, given in order from top to bottom. 0 represents an empty card.
It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}.
Output
The output contains a single integer β the minimum number of operations to make the n numbered cards piled up in increasing order.
Examples
Input
3
0 2 0
3 0 1
Output
2
Input
3
0 2 0
1 0 3
Output
4
Input
11
0 0 0 5 0 0 0 4 0 0 11
9 2 6 0 8 1 7 0 3 0 10
Output
18
Note
Example 1
We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom.
Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order.
Example 2
Play an empty card and draw the card 1, then play 1, 2, 3 in order. | instruction | 0 | 64,050 | 19 | 128,100 |
Tags: greedy, implementation
Correct Solution:
```
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
table = [0] * (N + 1)
for i in range(N):
if b[i]: table[b[i]] = i + 1
#print(table)
last = N - table[1] + 1
islast = 1
if table[1] == 0:
last = 0
islast = 0
for i in range(1, last + 1):
if table[i] != N - last + i:
islast = 0
break
#print(last, islast)
if islast:
for i in range(N - last):
x = last + i + 1
if table[x] > i:
islast = 0
break
#print(x)
if islast:
print(N - last)
exit(0)
x = 0
for i in range(1, N + 1):
x = max(table[i], x) + 1
print(x)
``` | output | 1 | 64,050 | 19 | 128,101 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nauuo is a girl who loves playing cards.
One day she was playing cards but found that the cards were mixed with some empty ones.
There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom.
In one operation she can choose a card in her hands and play it β put it at the bottom of the pile, then draw the top card from the pile.
Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations?
Input
The first line contains a single integer n (1β€ nβ€ 2β
10^5) β the number of numbered cards.
The second line contains n integers a_1,a_2,β¦,a_n (0β€ a_iβ€ n) β the initial cards in Nauuo's hands. 0 represents an empty card.
The third line contains n integers b_1,b_2,β¦,b_n (0β€ b_iβ€ n) β the initial cards in the pile, given in order from top to bottom. 0 represents an empty card.
It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}.
Output
The output contains a single integer β the minimum number of operations to make the n numbered cards piled up in increasing order.
Examples
Input
3
0 2 0
3 0 1
Output
2
Input
3
0 2 0
1 0 3
Output
4
Input
11
0 0 0 5 0 0 0 4 0 0 11
9 2 6 0 8 1 7 0 3 0 10
Output
18
Note
Example 1
We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom.
Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order.
Example 2
Play an empty card and draw the card 1, then play 1, 2, 3 in order. | instruction | 0 | 64,051 | 19 | 128,102 |
Tags: greedy, implementation
Correct Solution:
```
n=int(input())
a=[int(v) for v in input().split()]
b=[int(v) for v in input().split()]
c=0
d={}
f=0
for j in range(n):
d[a[j]]=1
j=n-1
while j>0:
if b[j]==b[j-1]+1 and b[j]!=1:
j=j-1
#print(j)
else:
break
#print(j)
if b[j]==1 and j>0:
p=b[-1]+1
f=1
elif b[j]==1 and j==0:
f=2
else:
p=1
if f==0:
w=0
for j in range(n):
if p not in d:
w=w+1
else:
p=p+1
d[b[j]]=1
ans=w+n
print(ans)
elif f==2:
print(0)
else:
w=0
m=j-1
j=0
#print(p)
while j<=m:
if p in d and f==1:
w=w+1
p=p+1
elif f==0 and p not in d:
w=w+1
elif f==0 and p in d:
p=p+1
else:
f=0
w=w+1
p=1
m=n-1
d[b[j]]=1
j=j+1
if f==1:
print(w)
else:
print(w+n)
#print(f)
``` | output | 1 | 64,051 | 19 | 128,103 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Nauuo is a girl who loves playing cards.
One day she was playing cards but found that the cards were mixed with some empty ones.
There are n cards numbered from 1 to n, and they were mixed with another n empty cards. She piled up the 2n cards and drew n of them. The n cards in Nauuo's hands are given. The remaining n cards in the pile are also given in the order from top to bottom.
In one operation she can choose a card in her hands and play it β put it at the bottom of the pile, then draw the top card from the pile.
Nauuo wants to make the n numbered cards piled up in increasing order (the i-th card in the pile from top to bottom is the card i) as quickly as possible. Can you tell her the minimum number of operations?
Input
The first line contains a single integer n (1β€ nβ€ 2β
10^5) β the number of numbered cards.
The second line contains n integers a_1,a_2,β¦,a_n (0β€ a_iβ€ n) β the initial cards in Nauuo's hands. 0 represents an empty card.
The third line contains n integers b_1,b_2,β¦,b_n (0β€ b_iβ€ n) β the initial cards in the pile, given in order from top to bottom. 0 represents an empty card.
It is guaranteed that each number from 1 to n appears exactly once, either in a_{1..n} or b_{1..n}.
Output
The output contains a single integer β the minimum number of operations to make the n numbered cards piled up in increasing order.
Examples
Input
3
0 2 0
3 0 1
Output
2
Input
3
0 2 0
1 0 3
Output
4
Input
11
0 0 0 5 0 0 0 4 0 0 11
9 2 6 0 8 1 7 0 3 0 10
Output
18
Note
Example 1
We can play the card 2 and draw the card 3 in the first operation. After that, we have [0,3,0] in hands and the cards in the pile are [0,1,2] from top to bottom.
Then, we play the card 3 in the second operation. The cards in the pile are [1,2,3], in which the cards are piled up in increasing order.
Example 2
Play an empty card and draw the card 1, then play 1, 2, 3 in order. | instruction | 0 | 64,052 | 19 | 128,104 |
Tags: greedy, implementation
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
f = True
if 1 in b:
j = b.index(1)
for i in range(n - j):
d = i + 1 - b[j + i]
if d != 0:
break
else:
s = -2
for k in range(j):
if b[k] != 0 and b[k] - k <= n - (j - 1):
break
else:
print(j)
f = False
if f:
s = -2
for k in range(n):
if b[k] != 0:
s = max(s, k - b[k])
print(s + n + 2)
``` | output | 1 | 64,052 | 19 | 128,105 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.