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.
Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple:
* The game starts with n piles of stones indexed from 1 to n. The i-th pile contains si stones.
* The players make their moves alternatively. A move is considered as removal of some number of stones from a pile. Removal of 0 stones does not count as a move.
* The player who is unable to make a move loses.
Now Jon believes that he is ready for battle, but Sam does not think so. To prove his argument, Sam suggested that they play a modified version of the game.
In this modified version, no move can be made more than once on a pile. For example, if 4 stones are removed from a pile, 4 stones cannot be removed from that pile again.
Sam sets up the game and makes the first move. Jon believes that Sam is just trying to prevent him from going to battle. Jon wants to know if he can win if both play optimally.
Input
First line consists of a single integer n (1 ≤ n ≤ 106) — the number of piles.
Each of next n lines contains an integer si (1 ≤ si ≤ 60) — the number of stones in i-th pile.
Output
Print a single line containing "YES" (without quotes) if Jon wins, otherwise print "NO" (without quotes)
Examples
Input
1
5
Output
NO
Input
2
1
2
Output
YES
Note
In the first case, Sam removes all the stones and Jon loses.
In second case, the following moves are possible by Sam: <image>
In each of these cases, last move can be made by Jon to win the game as follows: <image>
Submitted Solution:
```
memo = {}
def get_reachable_states(k, max_allowed):
states = []
for i in range(1, max_allowed+1):
new_k = k - i
states.append((new_k,i-1))
return states
def Grundy(k, max_allowed):
if (k, max_allowed) in memo:
return memo[(k, max_allowed)]
reachable_states = get_reachable_states(k, max_allowed)
if len(reachable_states) == 0:
memo[(k, max_allowed)] = 0
return 0
s = set()
for state in reachable_states:
s.add(Grundy(*state))
i = 0
while i in s:
i += 1
memo[(k, max_allowed)] = i
return memo[(k, max_allowed)]
n = int(input())
GrundyTotal = 0
for i in range(n):
k = int(input())
GrundyTotal ^= Grundy(k, k+1)
print("YES" if GrundyTotal == 0 else "NO")
``` | instruction | 0 | 52,719 | 19 | 105,438 |
No | output | 1 | 52,719 | 19 | 105,439 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple:
* The game starts with n piles of stones indexed from 1 to n. The i-th pile contains si stones.
* The players make their moves alternatively. A move is considered as removal of some number of stones from a pile. Removal of 0 stones does not count as a move.
* The player who is unable to make a move loses.
Now Jon believes that he is ready for battle, but Sam does not think so. To prove his argument, Sam suggested that they play a modified version of the game.
In this modified version, no move can be made more than once on a pile. For example, if 4 stones are removed from a pile, 4 stones cannot be removed from that pile again.
Sam sets up the game and makes the first move. Jon believes that Sam is just trying to prevent him from going to battle. Jon wants to know if he can win if both play optimally.
Input
First line consists of a single integer n (1 ≤ n ≤ 106) — the number of piles.
Each of next n lines contains an integer si (1 ≤ si ≤ 60) — the number of stones in i-th pile.
Output
Print a single line containing "YES" (without quotes) if Jon wins, otherwise print "NO" (without quotes)
Examples
Input
1
5
Output
NO
Input
2
1
2
Output
YES
Note
In the first case, Sam removes all the stones and Jon loses.
In second case, the following moves are possible by Sam: <image>
In each of these cases, last move can be made by Jon to win the game as follows: <image>
Submitted Solution:
```
n = int(input())
s=[]
a=[]
for i in range(n):
s.append(int(input()))
t = 'j'
while(s.count(0)!=n):
for i in range(n):
if s.count(0)==n-1 or n==1:
if n == 1:
a.append(s[i])
s[i] = s[i] - s[i]
if t == 'j':
t = 's'
else: t = 'j'
elif s.count(0)==n-1 and a.count(s[i])==0:
a.append(s[i])
s[i] = s[i] - s[i]
if t == 'j':
t = 's'
else: t = 'j'
elif a.count(s[i])==0:
a.append(s[i])
s[i] = s[i] - s[i]
if t == 'j':
t = 's'
else: t = 'j'
elif a.count(s[i])!=0:
a.append(s[i])
s[i] = s[i] - (s[i] - 1)
if t == 'j':
t = 's'
else: t = 'j'
if t == 'j':
print('YES')
else: print('NO')
``` | instruction | 0 | 52,720 | 19 | 105,440 |
No | output | 1 | 52,720 | 19 | 105,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple:
* The game starts with n piles of stones indexed from 1 to n. The i-th pile contains si stones.
* The players make their moves alternatively. A move is considered as removal of some number of stones from a pile. Removal of 0 stones does not count as a move.
* The player who is unable to make a move loses.
Now Jon believes that he is ready for battle, but Sam does not think so. To prove his argument, Sam suggested that they play a modified version of the game.
In this modified version, no move can be made more than once on a pile. For example, if 4 stones are removed from a pile, 4 stones cannot be removed from that pile again.
Sam sets up the game and makes the first move. Jon believes that Sam is just trying to prevent him from going to battle. Jon wants to know if he can win if both play optimally.
Input
First line consists of a single integer n (1 ≤ n ≤ 106) — the number of piles.
Each of next n lines contains an integer si (1 ≤ si ≤ 60) — the number of stones in i-th pile.
Output
Print a single line containing "YES" (without quotes) if Jon wins, otherwise print "NO" (without quotes)
Examples
Input
1
5
Output
NO
Input
2
1
2
Output
YES
Note
In the first case, Sam removes all the stones and Jon loses.
In second case, the following moves are possible by Sam: <image>
In each of these cases, last move can be made by Jon to win the game as follows: <image>
Submitted Solution:
```
memo = {}
def get_reachable_states(k, max_allowed):
states = []
for i in range(1, max_allowed + 1):
new_k = k - i
states.append((new_k, i - 1))
return states
def Grundy(k, max_allowed):
if k == 0:
return 0
if (k, max_allowed) in memo:
return memo[(k, max_allowed)]
reachable_states = get_reachable_states(k, max_allowed)
if len(reachable_states) == 0:
memo[(k, max_allowed)] = 0
return 0
s = set()
for state in reachable_states:
s.add(Grundy(*state))
i = 0
while i in s:
i += 1
memo[(k, max_allowed)] = i
return memo[(k, max_allowed)]
n = int(input())
GrundyTotal = 0
for i in range(n):
k = int(input())
GrundyTotal ^= Grundy(k, k)
print("YES" if GrundyTotal == 0 else "NO")
``` | instruction | 0 | 52,721 | 19 | 105,442 |
No | output | 1 | 52,721 | 19 | 105,443 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple:
* The game starts with n piles of stones indexed from 1 to n. The i-th pile contains si stones.
* The players make their moves alternatively. A move is considered as removal of some number of stones from a pile. Removal of 0 stones does not count as a move.
* The player who is unable to make a move loses.
Now Jon believes that he is ready for battle, but Sam does not think so. To prove his argument, Sam suggested that they play a modified version of the game.
In this modified version, no move can be made more than once on a pile. For example, if 4 stones are removed from a pile, 4 stones cannot be removed from that pile again.
Sam sets up the game and makes the first move. Jon believes that Sam is just trying to prevent him from going to battle. Jon wants to know if he can win if both play optimally.
Input
First line consists of a single integer n (1 ≤ n ≤ 106) — the number of piles.
Each of next n lines contains an integer si (1 ≤ si ≤ 60) — the number of stones in i-th pile.
Output
Print a single line containing "YES" (without quotes) if Jon wins, otherwise print "NO" (without quotes)
Examples
Input
1
5
Output
NO
Input
2
1
2
Output
YES
Note
In the first case, Sam removes all the stones and Jon loses.
In second case, the following moves are possible by Sam: <image>
In each of these cases, last move can be made by Jon to win the game as follows: <image>
Submitted Solution:
```
n = int(input())
if n % 2:
print('NO')
else:
print('YES')
``` | instruction | 0 | 52,722 | 19 | 105,444 |
No | output | 1 | 52,722 | 19 | 105,445 |
Provide a correct Python 3 solution for this coding contest problem.
You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.) N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows:
* For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.
* Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.
You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
Constraints
* 1 \leq M
* M \times 2 +1 \leq N \leq 200000
Input
Input is given from Standard Input in the following format:
N M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Examples
Input
4 1
Output
2 3
Input
7 3
Output
1 6
2 5
3 4 | instruction | 0 | 52,838 | 19 | 105,676 |
"Correct Solution:
```
n,m=map(int,input().split())
oddflag=True
for i in range(1,m+1):
mid=(1+n)//2
if oddflag:
oddflag = False
print(i//2 + 1 , n - i//2)
else:
oddflag = True
print(mid + i//2, mid - i//2)
``` | output | 1 | 52,838 | 19 | 105,677 |
Provide a correct Python 3 solution for this coding contest problem.
You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.) N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows:
* For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.
* Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.
You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
Constraints
* 1 \leq M
* M \times 2 +1 \leq N \leq 200000
Input
Input is given from Standard Input in the following format:
N M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Examples
Input
4 1
Output
2 3
Input
7 3
Output
1 6
2 5
3 4 | instruction | 0 | 52,839 | 19 | 105,678 |
"Correct Solution:
```
inf = 10**15
mod = 10**9+7
n,m = map(int, input().split())
tmp = n//2
for i in range(m):
if i % 2 == 0:
print('{} {}'.format(tmp-i//2, tmp+1+i//2))
else:
print('{} {}'.format(1+i//2, n-i//2-1))
``` | output | 1 | 52,839 | 19 | 105,679 |
Provide a correct Python 3 solution for this coding contest problem.
You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.) N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows:
* For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.
* Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.
You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
Constraints
* 1 \leq M
* M \times 2 +1 \leq N \leq 200000
Input
Input is given from Standard Input in the following format:
N M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Examples
Input
4 1
Output
2 3
Input
7 3
Output
1 6
2 5
3 4 | instruction | 0 | 52,840 | 19 | 105,680 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N, M = map(int, input().split())
res = []
def solve(l, r):
global res
if r <= l: return
res.append((l, r))
solve(l + 1, r - 1)
solve(1, M + 1)
solve(M + 2, M * 2 + 1)
for r in res: print(*r)
``` | output | 1 | 52,840 | 19 | 105,681 |
Provide a correct Python 3 solution for this coding contest problem.
You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.) N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows:
* For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.
* Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.
You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
Constraints
* 1 \leq M
* M \times 2 +1 \leq N \leq 200000
Input
Input is given from Standard Input in the following format:
N M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Examples
Input
4 1
Output
2 3
Input
7 3
Output
1 6
2 5
3 4 | instruction | 0 | 52,841 | 19 | 105,682 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
N,M = map(int, input().split())
if N%2==1:
for i in range(M):
print(M-i,M+1+i)
else:
for i in range(M):
if 4*(i+1)>N:
print(M-i,M+2+i)
else:
print(M-i,M+1+i)
``` | output | 1 | 52,841 | 19 | 105,683 |
Provide a correct Python 3 solution for this coding contest problem.
You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.) N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows:
* For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.
* Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.
You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
Constraints
* 1 \leq M
* M \times 2 +1 \leq N \leq 200000
Input
Input is given from Standard Input in the following format:
N M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Examples
Input
4 1
Output
2 3
Input
7 3
Output
1 6
2 5
3 4 | instruction | 0 | 52,842 | 19 | 105,684 |
"Correct Solution:
```
n, m = map(int, input().split())
if n % 2 == 1:
for i in range(m):
print(i + 1, n - i)
else:
for i in range(m):
if 2 * (i + 1) <= m + 1:
print(i + 1, n - i)
else:
print(i + 1, n - i - 1)
``` | output | 1 | 52,842 | 19 | 105,685 |
Provide a correct Python 3 solution for this coding contest problem.
You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.) N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows:
* For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.
* Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.
You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
Constraints
* 1 \leq M
* M \times 2 +1 \leq N \leq 200000
Input
Input is given from Standard Input in the following format:
N M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Examples
Input
4 1
Output
2 3
Input
7 3
Output
1 6
2 5
3 4 | instruction | 0 | 52,843 | 19 | 105,686 |
"Correct Solution:
```
# E - Rotation Matching
N, M = map(int, input().split())
if N%2:
for i in range(M):
print(i+1, N-(i))
else:
for i in range(M):
if (i+1)+(N-(N-(i+1))) < N-(i+1)-(i+1):
print(i+1, N-(i+1))
else:
print(i+2, N-(i+1))
``` | output | 1 | 52,843 | 19 | 105,687 |
Provide a correct Python 3 solution for this coding contest problem.
You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.) N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows:
* For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.
* Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.
You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
Constraints
* 1 \leq M
* M \times 2 +1 \leq N \leq 200000
Input
Input is given from Standard Input in the following format:
N M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Examples
Input
4 1
Output
2 3
Input
7 3
Output
1 6
2 5
3 4 | instruction | 0 | 52,844 | 19 | 105,688 |
"Correct Solution:
```
n,m=map(int,input().split())
l1,r2=1,2*m+1
if m%2:
r1=m
else:
r1=m+1
l2=r1+1
for i in range(m//2):
print(l1,r1)
print(l2,r2)
l1+=1
l2+=1
r1-=1
r2-=1
if m%2:
print(l2,r2)
``` | output | 1 | 52,844 | 19 | 105,689 |
Provide a correct Python 3 solution for this coding contest problem.
You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.) N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows:
* For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.
* Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.
You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
Constraints
* 1 \leq M
* M \times 2 +1 \leq N \leq 200000
Input
Input is given from Standard Input in the following format:
N M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Examples
Input
4 1
Output
2 3
Input
7 3
Output
1 6
2 5
3 4 | instruction | 0 | 52,845 | 19 | 105,690 |
"Correct Solution:
```
N, M = map(int, input().split())
for i in range(1, M+1):
if N % 2 == 1:
print(i, N+1-i)
else:
if i <= N//4:
print(i, N+1-i)
else:
print(i, N-i)
``` | output | 1 | 52,845 | 19 | 105,691 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.) N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows:
* For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.
* Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.
You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
Constraints
* 1 \leq M
* M \times 2 +1 \leq N \leq 200000
Input
Input is given from Standard Input in the following format:
N M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Examples
Input
4 1
Output
2 3
Input
7 3
Output
1 6
2 5
3 4
Submitted Solution:
```
n,m = map(int,input().split())
a = int(n/2)
b = a+1
offset = False
if n%2 == 0:
offset = True
for i in range(m):
if offset and b-a >= n/2:
b += 1
offset = False
print(a,b)
a -= 1
b += 1
``` | instruction | 0 | 52,846 | 19 | 105,692 |
Yes | output | 1 | 52,846 | 19 | 105,693 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.) N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows:
* For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.
* Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.
You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
Constraints
* 1 \leq M
* M \times 2 +1 \leq N \leq 200000
Input
Input is given from Standard Input in the following format:
N M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Examples
Input
4 1
Output
2 3
Input
7 3
Output
1 6
2 5
3 4
Submitted Solution:
```
n, m = map(int, input().split())
if n % 2 or m < n//4:
for i in range(m):
print(i+1, n-i)
else:
for i in range(n//4):
print(i+1, n-i)
for i in range(n//4, m):
print(i+1, n-i-1)
``` | instruction | 0 | 52,847 | 19 | 105,694 |
Yes | output | 1 | 52,847 | 19 | 105,695 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.) N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows:
* For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.
* Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.
You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
Constraints
* 1 \leq M
* M \times 2 +1 \leq N \leq 200000
Input
Input is given from Standard Input in the following format:
N M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Examples
Input
4 1
Output
2 3
Input
7 3
Output
1 6
2 5
3 4
Submitted Solution:
```
n,m=map(int,input().split())
ans=[1]*n
for i in range(1,n):
if ans[i]==1:ans[n-i]=0
c=0
x=[]
for i in range(1,n):
if ans[i]==1:
if len(x)%2==0:x.append(n-i)
else:x.append(i)
x.sort(reverse=1)
for i in range(m):print(i+1,i+1+x[i])
``` | instruction | 0 | 52,848 | 19 | 105,696 |
Yes | output | 1 | 52,848 | 19 | 105,697 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.) N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows:
* For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.
* Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.
You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
Constraints
* 1 \leq M
* M \times 2 +1 \leq N \leq 200000
Input
Input is given from Standard Input in the following format:
N M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Examples
Input
4 1
Output
2 3
Input
7 3
Output
1 6
2 5
3 4
Submitted Solution:
```
import sys
N, M = [int(x) for x in input().split()]
s = 1
e = 2 * -(-M // 2)
for _ in range(M):
if s >= e:
s = N - 2 * (M // 2)
e = N
print(s, e)
s += 1
e -= 1
``` | instruction | 0 | 52,849 | 19 | 105,698 |
Yes | output | 1 | 52,849 | 19 | 105,699 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.) N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows:
* For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.
* Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.
You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
Constraints
* 1 \leq M
* M \times 2 +1 \leq N \leq 200000
Input
Input is given from Standard Input in the following format:
N M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Examples
Input
4 1
Output
2 3
Input
7 3
Output
1 6
2 5
3 4
Submitted Solution:
```
n, m = map(int, input().split())
for i in range(m):
print(i+1, n-1-i)
``` | instruction | 0 | 52,850 | 19 | 105,700 |
No | output | 1 | 52,850 | 19 | 105,701 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.) N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows:
* For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.
* Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.
You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
Constraints
* 1 \leq M
* M \times 2 +1 \leq N \leq 200000
Input
Input is given from Standard Input in the following format:
N M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Examples
Input
4 1
Output
2 3
Input
7 3
Output
1 6
2 5
3 4
Submitted Solution:
```
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
# 割り当てを一つ求める
# N回Mラウンドを行う 1ラウンドあたりの最大対戦者数はN以下になる
# 対戦者A, B, C, D...にそれぞれ1、2、3、4...を割り当てる
# 試合後、A, B, C, D...の数字は2、3、4、5...になる N + 1になったら1になる
# N, M = 4, 1の時 M1に[1, 2]を割り当てると
# A B C D
# 1 1 2 3 4 A vs B
# 2 2 3 4 1 D vs A
# 3 3 4 1 2 C vs D
# 4 4 1 2 3 B vs C なのでok
# Nラウンドでちょうど一周するので、M = 1の時は何を入れてもok
# N, M = 5, 2の時
# A B C D E
# 1 1 2 3 4 5
# 2 2 3 4 5 1
# 3 3 4 5 1 2
# 4 4 5 1 2 3
# 5 5 1 2 3 4
# M1には何を指定してもいい?
# 少なくともM1とM2が同じパターン(i, i+1等)はダメ
# 全てのMについて違うパターンで数字を割り当てられるか
# = 任意のMi(ai, bi), Mj(aj, bj)について abs(bi - ai) != abs(bj - aj)
N, M = getNM()
A = []
B = []
for i in range(N):
A.append(i + 1)
B.append(N - i)
for i in range(M):
print(A[i], B[i])
``` | instruction | 0 | 52,851 | 19 | 105,702 |
No | output | 1 | 52,851 | 19 | 105,703 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.) N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows:
* For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.
* Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.
You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
Constraints
* 1 \leq M
* M \times 2 +1 \leq N \leq 200000
Input
Input is given from Standard Input in the following format:
N M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Examples
Input
4 1
Output
2 3
Input
7 3
Output
1 6
2 5
3 4
Submitted Solution:
```
n,m=map(int,input().split())
a,b=n//2,n//2+1
for i in range(m):
print(a,b)
a-=1
b+=1
``` | instruction | 0 | 52,852 | 19 | 105,704 |
No | output | 1 | 52,852 | 19 | 105,705 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.) N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows:
* For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.
* Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.
You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
Constraints
* 1 \leq M
* M \times 2 +1 \leq N \leq 200000
Input
Input is given from Standard Input in the following format:
N M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Output
Print M lines in the format below. The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.
a_1 b_1
a_2 b_2
:
a_M b_M
Examples
Input
4 1
Output
2 3
Input
7 3
Output
1 6
2 5
3 4
Submitted Solution:
```
#
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A):
for a in A: print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
N,M=MI()
if(N&1):
N+=1
for i in range(M):
print(i+1+1,N-i-2+1)
if __name__ == '__main__':
main()
``` | instruction | 0 | 52,853 | 19 | 105,706 |
No | output | 1 | 52,853 | 19 | 105,707 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are playing a variation of game 2048. Initially you have a multiset s of n integers. Every integer in this multiset is a power of two.
You may perform any number (possibly, zero) operations with this multiset.
During each operation you choose two equal integers from s, remove them from s and insert the number equal to their sum into s.
For example, if s = \{1, 2, 1, 1, 4, 2, 2\} and you choose integers 2 and 2, then the multiset becomes \{1, 1, 1, 4, 4, 2\}.
You win if the number 2048 belongs to your multiset. For example, if s = \{1024, 512, 512, 4\} you can win as follows: choose 512 and 512, your multiset turns into \{1024, 1024, 4\}. Then choose 1024 and 1024, your multiset turns into \{2048, 4\} and you win.
You have to determine if you can win this game.
You have to answer q independent queries.
Input
The first line contains one integer q (1 ≤ q ≤ 100) – the number of queries.
The first line of each query contains one integer n (1 ≤ n ≤ 100) — the number of elements in multiset.
The second line of each query contains n integers s_1, s_2, ..., s_n (1 ≤ s_i ≤ 2^{29}) — the description of the multiset. It is guaranteed that all elements of the multiset are powers of two.
Output
For each query print YES if it is possible to obtain the number 2048 in your multiset, and NO otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
4
1024 512 64 512
1
2048
3
64 512 2
2
4096 4
7
2048 2 2048 2048 2048 2048 2048
2
2048 4096
Output
YES
YES
NO
NO
YES
YES
Note
In the first query you can win as follows: choose 512 and 512, and s turns into \{1024, 64, 1024\}. Then choose 1024 and 1024, and s turns into \{2048, 64\} and you win.
In the second query s contains 2048 initially. | instruction | 0 | 53,155 | 19 | 106,310 |
Tags: brute force, greedy, math
Correct Solution:
```
q = int(input())
out = []
for i in range(q):
n = int(input())
lst = sorted(map(int, input().split()))
lst = [i for i in lst if i <= 2048]
while 2048 not in lst and len(lst) > 1 and len(lst) != len(set(lst)):
if lst[0] == lst[1]:
lst.append(lst[0] * 2)
del lst[0]
del lst[0]
lst = sorted(lst)
else:
del lst[0]
if 2048 not in lst:
out.append('NO')
else:
out.append('YES')
print('\n'.join(out))
``` | output | 1 | 53,155 | 19 | 106,311 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are playing a variation of game 2048. Initially you have a multiset s of n integers. Every integer in this multiset is a power of two.
You may perform any number (possibly, zero) operations with this multiset.
During each operation you choose two equal integers from s, remove them from s and insert the number equal to their sum into s.
For example, if s = \{1, 2, 1, 1, 4, 2, 2\} and you choose integers 2 and 2, then the multiset becomes \{1, 1, 1, 4, 4, 2\}.
You win if the number 2048 belongs to your multiset. For example, if s = \{1024, 512, 512, 4\} you can win as follows: choose 512 and 512, your multiset turns into \{1024, 1024, 4\}. Then choose 1024 and 1024, your multiset turns into \{2048, 4\} and you win.
You have to determine if you can win this game.
You have to answer q independent queries.
Input
The first line contains one integer q (1 ≤ q ≤ 100) – the number of queries.
The first line of each query contains one integer n (1 ≤ n ≤ 100) — the number of elements in multiset.
The second line of each query contains n integers s_1, s_2, ..., s_n (1 ≤ s_i ≤ 2^{29}) — the description of the multiset. It is guaranteed that all elements of the multiset are powers of two.
Output
For each query print YES if it is possible to obtain the number 2048 in your multiset, and NO otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
4
1024 512 64 512
1
2048
3
64 512 2
2
4096 4
7
2048 2 2048 2048 2048 2048 2048
2
2048 4096
Output
YES
YES
NO
NO
YES
YES
Note
In the first query you can win as follows: choose 512 and 512, and s turns into \{1024, 64, 1024\}. Then choose 1024 and 1024, and s turns into \{2048, 64\} and you win.
In the second query s contains 2048 initially. | instruction | 0 | 53,156 | 19 | 106,312 |
Tags: brute force, greedy, math
Correct Solution:
```
t = int(input())
for _ in range(t):
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
for i in range(n):
num = 0
f=0
if a[i]>2048:
continue
else:
for j in range(i,n):
if num+a[j]==2048:
f=1
print("YES")
break
else:
num+=a[j]
if f==1:
break
if f==0:
print("NO")
``` | output | 1 | 53,156 | 19 | 106,313 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are playing a variation of game 2048. Initially you have a multiset s of n integers. Every integer in this multiset is a power of two.
You may perform any number (possibly, zero) operations with this multiset.
During each operation you choose two equal integers from s, remove them from s and insert the number equal to their sum into s.
For example, if s = \{1, 2, 1, 1, 4, 2, 2\} and you choose integers 2 and 2, then the multiset becomes \{1, 1, 1, 4, 4, 2\}.
You win if the number 2048 belongs to your multiset. For example, if s = \{1024, 512, 512, 4\} you can win as follows: choose 512 and 512, your multiset turns into \{1024, 1024, 4\}. Then choose 1024 and 1024, your multiset turns into \{2048, 4\} and you win.
You have to determine if you can win this game.
You have to answer q independent queries.
Input
The first line contains one integer q (1 ≤ q ≤ 100) – the number of queries.
The first line of each query contains one integer n (1 ≤ n ≤ 100) — the number of elements in multiset.
The second line of each query contains n integers s_1, s_2, ..., s_n (1 ≤ s_i ≤ 2^{29}) — the description of the multiset. It is guaranteed that all elements of the multiset are powers of two.
Output
For each query print YES if it is possible to obtain the number 2048 in your multiset, and NO otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
4
1024 512 64 512
1
2048
3
64 512 2
2
4096 4
7
2048 2 2048 2048 2048 2048 2048
2
2048 4096
Output
YES
YES
NO
NO
YES
YES
Note
In the first query you can win as follows: choose 512 and 512, and s turns into \{1024, 64, 1024\}. Then choose 1024 and 1024, and s turns into \{2048, 64\} and you win.
In the second query s contains 2048 initially. | instruction | 0 | 53,157 | 19 | 106,314 |
Tags: brute force, greedy, math
Correct Solution:
```
def solve(n,a):
a.sort()
i = 0
while i+1 < len(a):
if a[i] == a[i + 1]:
a.append(a[i] * 2)
del a[i]
del a[i]
else:
i += 1
if 2048 in a:
return "YES"
a.sort()
return "NO"
def main():
q = int(input())
for i in range(q):
n = int(input())
a = list(map(int,input().split()))
if 2048 in a:
print("YES")
continue
print(solve(n,a))
main()
``` | output | 1 | 53,157 | 19 | 106,315 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are playing a variation of game 2048. Initially you have a multiset s of n integers. Every integer in this multiset is a power of two.
You may perform any number (possibly, zero) operations with this multiset.
During each operation you choose two equal integers from s, remove them from s and insert the number equal to their sum into s.
For example, if s = \{1, 2, 1, 1, 4, 2, 2\} and you choose integers 2 and 2, then the multiset becomes \{1, 1, 1, 4, 4, 2\}.
You win if the number 2048 belongs to your multiset. For example, if s = \{1024, 512, 512, 4\} you can win as follows: choose 512 and 512, your multiset turns into \{1024, 1024, 4\}. Then choose 1024 and 1024, your multiset turns into \{2048, 4\} and you win.
You have to determine if you can win this game.
You have to answer q independent queries.
Input
The first line contains one integer q (1 ≤ q ≤ 100) – the number of queries.
The first line of each query contains one integer n (1 ≤ n ≤ 100) — the number of elements in multiset.
The second line of each query contains n integers s_1, s_2, ..., s_n (1 ≤ s_i ≤ 2^{29}) — the description of the multiset. It is guaranteed that all elements of the multiset are powers of two.
Output
For each query print YES if it is possible to obtain the number 2048 in your multiset, and NO otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
4
1024 512 64 512
1
2048
3
64 512 2
2
4096 4
7
2048 2 2048 2048 2048 2048 2048
2
2048 4096
Output
YES
YES
NO
NO
YES
YES
Note
In the first query you can win as follows: choose 512 and 512, and s turns into \{1024, 64, 1024\}. Then choose 1024 and 1024, and s turns into \{2048, 64\} and you win.
In the second query s contains 2048 initially. | instruction | 0 | 53,158 | 19 | 106,316 |
Tags: brute force, greedy, math
Correct Solution:
```
from collections import Counter
def solve ():
n = int(input())
arr = list(map(int, input().split()))
if 2048 in arr :
return "Yes"
while 1 :
if arr.count(min(arr)) > 1 :
arr.append(2*min(arr))
arr.remove(min(arr))
arr.remove(min(arr))
elif arr.count(min(arr)) == 1 :
arr.remove(min(arr))
if 2048 in arr :
return "Yes"
if len(Counter(arr).keys()) == len(arr) :
break
return "No"
if __name__ == "__main__" :
q = int(input())
for i in range(0,q) :
print(solve())
``` | output | 1 | 53,158 | 19 | 106,317 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are playing a variation of game 2048. Initially you have a multiset s of n integers. Every integer in this multiset is a power of two.
You may perform any number (possibly, zero) operations with this multiset.
During each operation you choose two equal integers from s, remove them from s and insert the number equal to their sum into s.
For example, if s = \{1, 2, 1, 1, 4, 2, 2\} and you choose integers 2 and 2, then the multiset becomes \{1, 1, 1, 4, 4, 2\}.
You win if the number 2048 belongs to your multiset. For example, if s = \{1024, 512, 512, 4\} you can win as follows: choose 512 and 512, your multiset turns into \{1024, 1024, 4\}. Then choose 1024 and 1024, your multiset turns into \{2048, 4\} and you win.
You have to determine if you can win this game.
You have to answer q independent queries.
Input
The first line contains one integer q (1 ≤ q ≤ 100) – the number of queries.
The first line of each query contains one integer n (1 ≤ n ≤ 100) — the number of elements in multiset.
The second line of each query contains n integers s_1, s_2, ..., s_n (1 ≤ s_i ≤ 2^{29}) — the description of the multiset. It is guaranteed that all elements of the multiset are powers of two.
Output
For each query print YES if it is possible to obtain the number 2048 in your multiset, and NO otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
4
1024 512 64 512
1
2048
3
64 512 2
2
4096 4
7
2048 2 2048 2048 2048 2048 2048
2
2048 4096
Output
YES
YES
NO
NO
YES
YES
Note
In the first query you can win as follows: choose 512 and 512, and s turns into \{1024, 64, 1024\}. Then choose 1024 and 1024, and s turns into \{2048, 64\} and you win.
In the second query s contains 2048 initially. | instruction | 0 | 53,159 | 19 | 106,318 |
Tags: brute force, greedy, math
Correct Solution:
```
q=int(input())
for i in range(q):
n=int(input())
lst=list(map(int,input().split()))
lst.sort()
while True:
if 2048 in lst:
break
b=0
s=len(lst)
for j in range(s):
a=0
for p in range(j+1,s):
if lst[j]==lst[p]:
lst.append((lst[j]+lst[p]))
lst.remove(lst[p])
lst.remove(lst[j])
lst.sort()
a+=1
break
if a==1:
break
else:
b+=1
if b==len(lst):
break
if 2048 in lst:
print("YES")
else:
print("NO")
``` | output | 1 | 53,159 | 19 | 106,319 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are playing a variation of game 2048. Initially you have a multiset s of n integers. Every integer in this multiset is a power of two.
You may perform any number (possibly, zero) operations with this multiset.
During each operation you choose two equal integers from s, remove them from s and insert the number equal to their sum into s.
For example, if s = \{1, 2, 1, 1, 4, 2, 2\} and you choose integers 2 and 2, then the multiset becomes \{1, 1, 1, 4, 4, 2\}.
You win if the number 2048 belongs to your multiset. For example, if s = \{1024, 512, 512, 4\} you can win as follows: choose 512 and 512, your multiset turns into \{1024, 1024, 4\}. Then choose 1024 and 1024, your multiset turns into \{2048, 4\} and you win.
You have to determine if you can win this game.
You have to answer q independent queries.
Input
The first line contains one integer q (1 ≤ q ≤ 100) – the number of queries.
The first line of each query contains one integer n (1 ≤ n ≤ 100) — the number of elements in multiset.
The second line of each query contains n integers s_1, s_2, ..., s_n (1 ≤ s_i ≤ 2^{29}) — the description of the multiset. It is guaranteed that all elements of the multiset are powers of two.
Output
For each query print YES if it is possible to obtain the number 2048 in your multiset, and NO otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
4
1024 512 64 512
1
2048
3
64 512 2
2
4096 4
7
2048 2 2048 2048 2048 2048 2048
2
2048 4096
Output
YES
YES
NO
NO
YES
YES
Note
In the first query you can win as follows: choose 512 and 512, and s turns into \{1024, 64, 1024\}. Then choose 1024 and 1024, and s turns into \{2048, 64\} and you win.
In the second query s contains 2048 initially. | instruction | 0 | 53,160 | 19 | 106,320 |
Tags: brute force, greedy, math
Correct Solution:
```
# cook your dish here
t=int(input())
for i in range(t):
sum=0
n=int(input())
l=list(map(int,input().split()))
for j in range(n):
if(l[j]<=2048):
sum+=l[j]
if sum>=2048:
print("YES")
else:
print("NO")
``` | output | 1 | 53,160 | 19 | 106,321 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are playing a variation of game 2048. Initially you have a multiset s of n integers. Every integer in this multiset is a power of two.
You may perform any number (possibly, zero) operations with this multiset.
During each operation you choose two equal integers from s, remove them from s and insert the number equal to their sum into s.
For example, if s = \{1, 2, 1, 1, 4, 2, 2\} and you choose integers 2 and 2, then the multiset becomes \{1, 1, 1, 4, 4, 2\}.
You win if the number 2048 belongs to your multiset. For example, if s = \{1024, 512, 512, 4\} you can win as follows: choose 512 and 512, your multiset turns into \{1024, 1024, 4\}. Then choose 1024 and 1024, your multiset turns into \{2048, 4\} and you win.
You have to determine if you can win this game.
You have to answer q independent queries.
Input
The first line contains one integer q (1 ≤ q ≤ 100) – the number of queries.
The first line of each query contains one integer n (1 ≤ n ≤ 100) — the number of elements in multiset.
The second line of each query contains n integers s_1, s_2, ..., s_n (1 ≤ s_i ≤ 2^{29}) — the description of the multiset. It is guaranteed that all elements of the multiset are powers of two.
Output
For each query print YES if it is possible to obtain the number 2048 in your multiset, and NO otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
4
1024 512 64 512
1
2048
3
64 512 2
2
4096 4
7
2048 2 2048 2048 2048 2048 2048
2
2048 4096
Output
YES
YES
NO
NO
YES
YES
Note
In the first query you can win as follows: choose 512 and 512, and s turns into \{1024, 64, 1024\}. Then choose 1024 and 1024, and s turns into \{2048, 64\} and you win.
In the second query s contains 2048 initially. | instruction | 0 | 53,161 | 19 | 106,322 |
Tags: brute force, greedy, math
Correct Solution:
```
from collections import defaultdict as dd
for _ in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
s = 0
flag = 0
for i in a:
if(i<=2048):
s+=i
if(s>=2048):
flag = 1
print('YES')
break
if(not flag):
print('NO')
``` | output | 1 | 53,161 | 19 | 106,323 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are playing a variation of game 2048. Initially you have a multiset s of n integers. Every integer in this multiset is a power of two.
You may perform any number (possibly, zero) operations with this multiset.
During each operation you choose two equal integers from s, remove them from s and insert the number equal to their sum into s.
For example, if s = \{1, 2, 1, 1, 4, 2, 2\} and you choose integers 2 and 2, then the multiset becomes \{1, 1, 1, 4, 4, 2\}.
You win if the number 2048 belongs to your multiset. For example, if s = \{1024, 512, 512, 4\} you can win as follows: choose 512 and 512, your multiset turns into \{1024, 1024, 4\}. Then choose 1024 and 1024, your multiset turns into \{2048, 4\} and you win.
You have to determine if you can win this game.
You have to answer q independent queries.
Input
The first line contains one integer q (1 ≤ q ≤ 100) – the number of queries.
The first line of each query contains one integer n (1 ≤ n ≤ 100) — the number of elements in multiset.
The second line of each query contains n integers s_1, s_2, ..., s_n (1 ≤ s_i ≤ 2^{29}) — the description of the multiset. It is guaranteed that all elements of the multiset are powers of two.
Output
For each query print YES if it is possible to obtain the number 2048 in your multiset, and NO otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
4
1024 512 64 512
1
2048
3
64 512 2
2
4096 4
7
2048 2 2048 2048 2048 2048 2048
2
2048 4096
Output
YES
YES
NO
NO
YES
YES
Note
In the first query you can win as follows: choose 512 and 512, and s turns into \{1024, 64, 1024\}. Then choose 1024 and 1024, and s turns into \{2048, 64\} and you win.
In the second query s contains 2048 initially. | instruction | 0 | 53,162 | 19 | 106,324 |
Tags: brute force, greedy, math
Correct Solution:
```
n = int(input())
for i in range(n):
ff = {}
r = int(input())
for j in input().split():
ff[int(j)] = ff.get(int(j), 0) + 1
if ff.get(1, 0) > 0:
ff[2] = ff.get(2, 0) + (ff[1]//2)
for j in range(1, 11):
c = 2 ** j
if ff.get(c, 0) >= 2:
ff[2 ** (j+1)] = ff.get(2 ** (j+1), 0) + (ff[c] // 2)
if ff.get(2048) != None:
print("YES")
else:
print("NO")
``` | output | 1 | 53,162 | 19 | 106,325 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bob is playing with 6-sided dice. A net of such standard cube is shown below.
<image>
He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosing the orientation of each dice. Then he counts the number of visible pips on the faces of the dice.
For example, the number of visible pips on the tower below is 29 — the number visible on the top is 1, from the south 5 and 3, from the west 4 and 2, from the north 2 and 4 and from the east 3 and 5.
<image>
The one at the bottom and the two sixes by which the dice are touching are not visible, so they are not counted towards total.
Bob also has t favourite integers x_i, and for every such integer his goal is to build such a tower that the number of visible pips is exactly x_i. For each of Bob's favourite integers determine whether it is possible to build a tower that has exactly that many visible pips.
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of favourite integers of Bob.
The second line contains t space-separated integers x_i (1 ≤ x_i ≤ 10^{18}) — Bob's favourite integers.
Output
For each of Bob's favourite integers, output "YES" if it is possible to build the tower, or "NO" otherwise (quotes for clarity).
Example
Input
4
29 34 19 38
Output
YES
YES
YES
NO
Note
The first example is mentioned in the problem statement.
In the second example, one can build the tower by flipping the top dice from the previous tower.
In the third example, one can use a single die that has 5 on top.
The fourth example is impossible. | instruction | 0 | 53,172 | 19 | 106,344 |
Tags: constructive algorithms, math
Correct Solution:
```
n = int(input())
def getAns(li):
for x in li:
if x > 14:
if x % 14 <= 6 and x % 14 > 0:
print("YES")
else:
print("NO")
else:
print("NO")
getAns([int(x) for x in input().split(' ')])
``` | output | 1 | 53,172 | 19 | 106,345 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bob is playing with 6-sided dice. A net of such standard cube is shown below.
<image>
He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosing the orientation of each dice. Then he counts the number of visible pips on the faces of the dice.
For example, the number of visible pips on the tower below is 29 — the number visible on the top is 1, from the south 5 and 3, from the west 4 and 2, from the north 2 and 4 and from the east 3 and 5.
<image>
The one at the bottom and the two sixes by which the dice are touching are not visible, so they are not counted towards total.
Bob also has t favourite integers x_i, and for every such integer his goal is to build such a tower that the number of visible pips is exactly x_i. For each of Bob's favourite integers determine whether it is possible to build a tower that has exactly that many visible pips.
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of favourite integers of Bob.
The second line contains t space-separated integers x_i (1 ≤ x_i ≤ 10^{18}) — Bob's favourite integers.
Output
For each of Bob's favourite integers, output "YES" if it is possible to build the tower, or "NO" otherwise (quotes for clarity).
Example
Input
4
29 34 19 38
Output
YES
YES
YES
NO
Note
The first example is mentioned in the problem statement.
In the second example, one can build the tower by flipping the top dice from the previous tower.
In the third example, one can use a single die that has 5 on top.
The fourth example is impossible. | instruction | 0 | 53,176 | 19 | 106,352 |
Tags: constructive algorithms, math
Correct Solution:
```
n = int(input())
entrada = input().split(" ")
for k in range(n):
x1 = (int(entrada[k])-15)//14
if(int(entrada[k]) < 15):
print('NO')
elif(int(entrada[k]) >= x1*14+15 and int(entrada[k]) <= x1*14+20):
print('YES')
else:
print('NO')
``` | output | 1 | 53,176 | 19 | 106,353 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bob is playing with 6-sided dice. A net of such standard cube is shown below.
<image>
He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosing the orientation of each dice. Then he counts the number of visible pips on the faces of the dice.
For example, the number of visible pips on the tower below is 29 — the number visible on the top is 1, from the south 5 and 3, from the west 4 and 2, from the north 2 and 4 and from the east 3 and 5.
<image>
The one at the bottom and the two sixes by which the dice are touching are not visible, so they are not counted towards total.
Bob also has t favourite integers x_i, and for every such integer his goal is to build such a tower that the number of visible pips is exactly x_i. For each of Bob's favourite integers determine whether it is possible to build a tower that has exactly that many visible pips.
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of favourite integers of Bob.
The second line contains t space-separated integers x_i (1 ≤ x_i ≤ 10^{18}) — Bob's favourite integers.
Output
For each of Bob's favourite integers, output "YES" if it is possible to build the tower, or "NO" otherwise (quotes for clarity).
Example
Input
4
29 34 19 38
Output
YES
YES
YES
NO
Note
The first example is mentioned in the problem statement.
In the second example, one can build the tower by flipping the top dice from the previous tower.
In the third example, one can use a single die that has 5 on top.
The fourth example is impossible.
Submitted Solution:
```
t = int(input())
ara = list(map(int, input().strip().split()))
for i in ara:
if 1 <= i % 14 <= 6 and i > 14:
print("YES")
else:
print("NO")
``` | instruction | 0 | 53,179 | 19 | 106,358 |
Yes | output | 1 | 53,179 | 19 | 106,359 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bob is playing with 6-sided dice. A net of such standard cube is shown below.
<image>
He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosing the orientation of each dice. Then he counts the number of visible pips on the faces of the dice.
For example, the number of visible pips on the tower below is 29 — the number visible on the top is 1, from the south 5 and 3, from the west 4 and 2, from the north 2 and 4 and from the east 3 and 5.
<image>
The one at the bottom and the two sixes by which the dice are touching are not visible, so they are not counted towards total.
Bob also has t favourite integers x_i, and for every such integer his goal is to build such a tower that the number of visible pips is exactly x_i. For each of Bob's favourite integers determine whether it is possible to build a tower that has exactly that many visible pips.
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of favourite integers of Bob.
The second line contains t space-separated integers x_i (1 ≤ x_i ≤ 10^{18}) — Bob's favourite integers.
Output
For each of Bob's favourite integers, output "YES" if it is possible to build the tower, or "NO" otherwise (quotes for clarity).
Example
Input
4
29 34 19 38
Output
YES
YES
YES
NO
Note
The first example is mentioned in the problem statement.
In the second example, one can build the tower by flipping the top dice from the previous tower.
In the third example, one can use a single die that has 5 on top.
The fourth example is impossible.
Submitted Solution:
```
import re
in1 = int(input())
in2 = [int(x) for x in re.split("\\s", input())]
for x in in2:
if x <= 14:
print("NO")
else:
x = x%14
if x >= 1 and x <= 6:
print("YES")
else:
print("NO")
``` | instruction | 0 | 53,181 | 19 | 106,362 |
Yes | output | 1 | 53,181 | 19 | 106,363 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bob is playing with 6-sided dice. A net of such standard cube is shown below.
<image>
He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosing the orientation of each dice. Then he counts the number of visible pips on the faces of the dice.
For example, the number of visible pips on the tower below is 29 — the number visible on the top is 1, from the south 5 and 3, from the west 4 and 2, from the north 2 and 4 and from the east 3 and 5.
<image>
The one at the bottom and the two sixes by which the dice are touching are not visible, so they are not counted towards total.
Bob also has t favourite integers x_i, and for every such integer his goal is to build such a tower that the number of visible pips is exactly x_i. For each of Bob's favourite integers determine whether it is possible to build a tower that has exactly that many visible pips.
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of favourite integers of Bob.
The second line contains t space-separated integers x_i (1 ≤ x_i ≤ 10^{18}) — Bob's favourite integers.
Output
For each of Bob's favourite integers, output "YES" if it is possible to build the tower, or "NO" otherwise (quotes for clarity).
Example
Input
4
29 34 19 38
Output
YES
YES
YES
NO
Note
The first example is mentioned in the problem statement.
In the second example, one can build the tower by flipping the top dice from the previous tower.
In the third example, one can use a single die that has 5 on top.
The fourth example is impossible.
Submitted Solution:
```
t = int(input())
xs = map(int, input().split())
for x in xs:
if 1 <= x % 14 <= 6 and x > 14:
print("YES")
else:
print("NO")
``` | instruction | 0 | 53,182 | 19 | 106,364 |
Yes | output | 1 | 53,182 | 19 | 106,365 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bob is playing with 6-sided dice. A net of such standard cube is shown below.
<image>
He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosing the orientation of each dice. Then he counts the number of visible pips on the faces of the dice.
For example, the number of visible pips on the tower below is 29 — the number visible on the top is 1, from the south 5 and 3, from the west 4 and 2, from the north 2 and 4 and from the east 3 and 5.
<image>
The one at the bottom and the two sixes by which the dice are touching are not visible, so they are not counted towards total.
Bob also has t favourite integers x_i, and for every such integer his goal is to build such a tower that the number of visible pips is exactly x_i. For each of Bob's favourite integers determine whether it is possible to build a tower that has exactly that many visible pips.
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of favourite integers of Bob.
The second line contains t space-separated integers x_i (1 ≤ x_i ≤ 10^{18}) — Bob's favourite integers.
Output
For each of Bob's favourite integers, output "YES" if it is possible to build the tower, or "NO" otherwise (quotes for clarity).
Example
Input
4
29 34 19 38
Output
YES
YES
YES
NO
Note
The first example is mentioned in the problem statement.
In the second example, one can build the tower by flipping the top dice from the previous tower.
In the third example, one can use a single die that has 5 on top.
The fourth example is impossible.
Submitted Solution:
```
# cook your dish here
t = int(input())
a=[]
a = list(map(int,input().split()))
for i in a:
#print(i//14)
if(i%14 >=1 and i%14 <=6 ):
print("YES")
else:
print("NO")
``` | instruction | 0 | 53,183 | 19 | 106,366 |
No | output | 1 | 53,183 | 19 | 106,367 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bob is playing with 6-sided dice. A net of such standard cube is shown below.
<image>
He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosing the orientation of each dice. Then he counts the number of visible pips on the faces of the dice.
For example, the number of visible pips on the tower below is 29 — the number visible on the top is 1, from the south 5 and 3, from the west 4 and 2, from the north 2 and 4 and from the east 3 and 5.
<image>
The one at the bottom and the two sixes by which the dice are touching are not visible, so they are not counted towards total.
Bob also has t favourite integers x_i, and for every such integer his goal is to build such a tower that the number of visible pips is exactly x_i. For each of Bob's favourite integers determine whether it is possible to build a tower that has exactly that many visible pips.
Input
The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of favourite integers of Bob.
The second line contains t space-separated integers x_i (1 ≤ x_i ≤ 10^{18}) — Bob's favourite integers.
Output
For each of Bob's favourite integers, output "YES" if it is possible to build the tower, or "NO" otherwise (quotes for clarity).
Example
Input
4
29 34 19 38
Output
YES
YES
YES
NO
Note
The first example is mentioned in the problem statement.
In the second example, one can build the tower by flipping the top dice from the previous tower.
In the third example, one can use a single die that has 5 on top.
The fourth example is impossible.
Submitted Solution:
```
n = int(input())
mas = list(map(int, input().split()))
for a in mas:
ost = a % 14
if (ost < 7 and ost != 0):
print('YES')
else:
print("NO")
``` | instruction | 0 | 53,184 | 19 | 106,368 |
No | output | 1 | 53,184 | 19 | 106,369 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are considered different when there exists an integer k such that the number of dice showing k is different in those two.
Constraints
* 1 \leq K \leq 2000
* 2 \leq N \leq 2000
* K and N are integers.
Input
Input is given from Standard Input in the following format:
K N
Output
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer for i=t+1.
Examples
Input
3 3
Output
7
7
4
7
7
Input
4 5
Output
36
36
20
20
20
36
36
Input
6 1000
Output
149393349
149393349
668669001
668669001
4000002
4000002
4000002
668669001
668669001
149393349
149393349 | instruction | 0 | 53,735 | 19 | 107,470 |
"Correct Solution:
```
#!/usr/bin/env python3
M = 998244353
fact = None
factr = None
def comb(n, k):
if n <= 0 or k < 0 or n < k:
return 0
r = fact[n] * factr[k] % M
r *= factr[n - k]
r %= M
return r
def solve(k, n):
global fact, factr
inv = [1] * (k + n + 1)
for i in range(2, k + n + 1):
inv[i] = inv[M % i] * (M - M // i) % M
fact = [1] * (k + n + 1)
factr = [1] * (k + n + 1)
for i in range(2, k + n + 1):
fact[i] = fact[i - 1] * i % M
factr[i] = factr[i - 1] * inv[i] % M
if k == 1:
print(0)
return
if k == 2:
for _ in range(3):
print(2)
return
g0 = (comb(k + n - 2, k - 2) + comb(k + n - 3, k - 2)) % M
g1 = comb(k + n - 1, k - 1)
rs0 = [0] * (min(k // 2, n // 2) + 1)
rs1 = [0] * (min(k // 2, n // 2) + 1)
for t in range(1, min(k // 2, n // 2) + 1):
rs0[t] = (comb(k + n - 2 * t - 2, k - 2) + comb(k + n - 2 * t - 3, k - 2)) % M
rs1[t] = comb(k + n - 2 * t - 1, k - 1)
results = [0] * (k + 2)
for i in range(2, k + 2):
ns = (i - 1) // 2
ans = g0 if i % 2 == 0 else g1
p = -1
for t in range(1, min(ns, n // 2) + 1):
r = rs0[t] if i % 2 == 0 else rs1[t]
r *= comb(ns, t)
r %= M
ans += M + p * r
ans %= M
p = 0 - p
print(ans)
results[i] = ans
for i in range(k + 2, 2 * k + 1):
print(results[2 * k + 2 - i])
def main():
k, n = input().split()
k = int(k)
n = int(n)
solve(k, n)
if __name__ == '__main__':
main()
``` | output | 1 | 53,735 | 19 | 107,471 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are considered different when there exists an integer k such that the number of dice showing k is different in those two.
Constraints
* 1 \leq K \leq 2000
* 2 \leq N \leq 2000
* K and N are integers.
Input
Input is given from Standard Input in the following format:
K N
Output
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer for i=t+1.
Examples
Input
3 3
Output
7
7
4
7
7
Input
4 5
Output
36
36
20
20
20
36
36
Input
6 1000
Output
149393349
149393349
668669001
668669001
4000002
4000002
4000002
668669001
668669001
149393349
149393349 | instruction | 0 | 53,736 | 19 | 107,472 |
"Correct Solution:
```
K, N = map(int, input().split())
mod = 998244353
def inved(a):
x, y, u, v, k, l = 1, 0, 0, 1, a, mod
while l != 0:
x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
k, l = l, k % l
return x % mod
X = [0 for i in range(2*K-1)]
frac = [1]
for i in range(N + K):
frac.append(((i+1)*frac[i])%mod)
invf = []
for i in range(N + K + 1):
invf.append(inved(frac[i]))
for k in range(2, K+2):
S = 0
sign = 1
l = k // 2
for m in range(min(l+1, N//2+1)):
prod = (sign * (frac[l]*frac[N+K-2*m-1])) % mod
prod *= (invf[m]*invf[l-m]) % mod
prod %= mod
prod *= (invf[N-2*m] * invf[K-1]) % mod
prod %= mod
S += prod
S %= mod
sign *= -1
X[k-2], X[2*K-k] = S, S
for i in range(2*K-1):
print(X[i])
``` | output | 1 | 53,736 | 19 | 107,473 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are considered different when there exists an integer k such that the number of dice showing k is different in those two.
Constraints
* 1 \leq K \leq 2000
* 2 \leq N \leq 2000
* K and N are integers.
Input
Input is given from Standard Input in the following format:
K N
Output
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer for i=t+1.
Examples
Input
3 3
Output
7
7
4
7
7
Input
4 5
Output
36
36
20
20
20
36
36
Input
6 1000
Output
149393349
149393349
668669001
668669001
4000002
4000002
4000002
668669001
668669001
149393349
149393349 | instruction | 0 | 53,737 | 19 | 107,474 |
"Correct Solution:
```
K, N = map(int, input().split())
MOD = 998244353
P = N+K
fact = [1]*(P+1)
rfact = [1]*(P+1)
for i in range(P):
fact[i+1] = r = ((i+1) * fact[i]) % MOD
rfact[i+1] = pow(r, MOD-2, MOD)
def comb(n, k):
return fact[n] * rfact[k] * rfact[n-k] % MOD
V = [1]*(P+1)
r = 1
for i in range(P):
r = (r * 2) % MOD
V[i+1] = r * rfact[i+1] % MOD
memo = {}
def calc(A):
if A in memo:
return memo[A]
M = A//2
r = 0
if A % 2:
p = K - 2*M + N - 2
for m in range(max(0, 2*M+2-K), min(M, N-1)+1):
r += V[m] * rfact[M-m] * (fact[p]*rfact[N-m] + fact[p-1]*rfact[N-m-1])*rfact[p-N+m] % MOD
if 2*M+2-K <= N <= M:
r += V[N] * rfact[M-N] % MOD
r *= fact[M]
else:
p = K - 2*M + N - 1
for m in range(max(0, 2*M+1-K), min(N, M)+1):
r += V[m] * rfact[M-m] * rfact[N-m] * rfact[p-N+m] % MOD
r *= fact[M] * fact[p]
r = memo[A] = r % MOD
return r
ans = []
for i in range(2, 2*K+1):
if i <= K:
ans.append(calc(i - 1))
else:
ans.append(calc(2*K - i + 1))
print(*ans, sep='\n')
``` | output | 1 | 53,737 | 19 | 107,475 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are considered different when there exists an integer k such that the number of dice showing k is different in those two.
Constraints
* 1 \leq K \leq 2000
* 2 \leq N \leq 2000
* K and N are integers.
Input
Input is given from Standard Input in the following format:
K N
Output
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer for i=t+1.
Examples
Input
3 3
Output
7
7
4
7
7
Input
4 5
Output
36
36
20
20
20
36
36
Input
6 1000
Output
149393349
149393349
668669001
668669001
4000002
4000002
4000002
668669001
668669001
149393349
149393349 | instruction | 0 | 53,738 | 19 | 107,476 |
"Correct Solution:
```
K, N = map(int, input().split())
mod = 998244353
A = []
p = mod - 2
while p != 0:
A = [p%2] + A[:]
p //= 2
def inved(x):
y = 1
for _ in range(len(A)):
if A[_] == 1:
y *= x
y %= mod
if _ != len(A) - 1:
y *= y
y %= mod
return y
X = [0 for i in range(2*K-1)]
frac = [1]
for i in range(N + K):
frac.append(((i+1)*frac[i])%mod)
invf = []
for i in range(N + K + 1):
invf.append(inved(frac[i]))
for k in range(2, K+2):
S = 0
sign = 1
l = k // 2
for m in range(min(l+1, N//2+1)):
prod = (sign * (frac[l]*frac[N+K-2*m-1])) % mod
prod *= (invf[m]*invf[l-m]) % mod
prod %= mod
prod *= (invf[N-2*m] * invf[K-1]) % mod
prod %= mod
S += prod
S %= mod
sign *= -1
X[k-2], X[2*K-k] = S, S
for i in range(2*K-1):
print(X[i])
``` | output | 1 | 53,738 | 19 | 107,477 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are considered different when there exists an integer k such that the number of dice showing k is different in those two.
Constraints
* 1 \leq K \leq 2000
* 2 \leq N \leq 2000
* K and N are integers.
Input
Input is given from Standard Input in the following format:
K N
Output
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer for i=t+1.
Examples
Input
3 3
Output
7
7
4
7
7
Input
4 5
Output
36
36
20
20
20
36
36
Input
6 1000
Output
149393349
149393349
668669001
668669001
4000002
4000002
4000002
668669001
668669001
149393349
149393349 | instruction | 0 | 53,739 | 19 | 107,478 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
def nCr(com_n, com_r):
if com_n < com_r: return 0
return fac[com_n] * ifac[com_r] % md * ifac[com_n - com_r] % md
def nHr(hn,hr):
return nCr(hn+hr-1,hr)
md = 998244353
n_max = 5000
fac = [1]
for i in range(1, n_max + 1): fac.append(fac[-1] * i % md)
ifac = [1] * (n_max + 1)
ifac[n_max] = pow(fac[n_max], md - 2, md)
for i in range(n_max - 1, 1, -1): ifac[i] = ifac[i + 1] * (i + 1) % md
def solve():
res=0
for p in range(min(t,n)//2+1):
cur=nCr(t//2,p)*nHr(k,n-2*p)
if p&1:res-=cur
else:res+=cur
res%=md
return res
k,n=MI()
ans=[]
for t in range(2,k+2):
a=solve()
ans.append(a)
print(a)
ans.reverse()
for a in ans[1:]:print(a)
``` | output | 1 | 53,739 | 19 | 107,479 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are considered different when there exists an integer k such that the number of dice showing k is different in those two.
Constraints
* 1 \leq K \leq 2000
* 2 \leq N \leq 2000
* K and N are integers.
Input
Input is given from Standard Input in the following format:
K N
Output
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer for i=t+1.
Examples
Input
3 3
Output
7
7
4
7
7
Input
4 5
Output
36
36
20
20
20
36
36
Input
6 1000
Output
149393349
149393349
668669001
668669001
4000002
4000002
4000002
668669001
668669001
149393349
149393349 | instruction | 0 | 53,740 | 19 | 107,480 |
"Correct Solution:
```
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 998244353
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
K,N = inpl()
MAX = K+N+10
fac = [1]*(MAX+1)
for i in range(1,MAX+1):
fac[i] = (fac[i-1]*i)%mod
gyakugen = [1]*(MAX+1)
gyakugen[MAX] = pow(fac[MAX],mod-2,mod)
for i in range(MAX,0,-1):
gyakugen[i-1] = (gyakugen[i]*i)%mod
def Comb(n,k):#nCk
return (fac[n]*gyakugen[k]*gyakugen[n-k])%mod
#K=k,N=n,0pair = 0
def calc(k,n,i):
#i=2に帰着させる
pairs = (i-2)//2
k -= pairs
n -= pairs
#色々と例外処理
if n < 0 or k <= 0:
return 0
elif k == 1 and n >= 2:
return 0
if n == 0: #球が0個なら1通り
ans = 1
else:
ans = 0
#i=2の時の数え上げ
for x in range(2):
ball = n-x #球
box = k-1 #箱
ans += Comb(box-1+ball,ball)%mod
ans *= pow(2,pairs,mod) #0pairの選び方
return ans % mod
ans = []
for i in range(2,K+2):
if i%2 == 0:
pairs = (i-2)//2
tmp = 0
for p0 in range(pairs+1): #p0 = 0pairの数
tmp += calc(K-p0*2 , N , i-p0*2) * Comb(pairs,p0)%mod
tmp %= mod
ans.append(tmp)
print(tmp)
ans = ans[::-1]
for i in range(1,K):
print(ans[i])
``` | output | 1 | 53,740 | 19 | 107,481 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are considered different when there exists an integer k such that the number of dice showing k is different in those two.
Constraints
* 1 \leq K \leq 2000
* 2 \leq N \leq 2000
* K and N are integers.
Input
Input is given from Standard Input in the following format:
K N
Output
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer for i=t+1.
Examples
Input
3 3
Output
7
7
4
7
7
Input
4 5
Output
36
36
20
20
20
36
36
Input
6 1000
Output
149393349
149393349
668669001
668669001
4000002
4000002
4000002
668669001
668669001
149393349
149393349 | instruction | 0 | 53,741 | 19 | 107,482 |
"Correct Solution:
```
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n+1):
fac.append(fac[i-1] * i % self.mod)
facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n+1)
modinv[1] = 1
for i in range(2, n+1):
modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
return modinv
mod = 998244353
K, N = map(int, input().split())
comb = Combination(10000, mod=mod)
def C(n, r):
if n<r or r<0:
return 0
else:
return comb(n, r)
def H(n, r):
return C(n+r-1, r)
L = []
for i in range(2, 2*K+1, 2):
ans = 0
M = i//2
b = 1
for j, a in enumerate(range(M, K)):
if M-j<0:
break
ans += pow(2, M-j, mod) * C(M, j) * H(K-a, N) * b
#print((j, a), C(M, j) , H(N, K-a), b, pow(2, M-j, mod) * C(M, j) * H(K-a, N) * b)
ans %= mod
b = -b
print(ans)
if i == K+1:
break
elif i == K:
print(ans)
print(ans)
break
L.append(ans)
print(ans)
L.append(ans)
print(*L[::-1], sep="\n")
``` | output | 1 | 53,741 | 19 | 107,483 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are considered different when there exists an integer k such that the number of dice showing k is different in those two.
Constraints
* 1 \leq K \leq 2000
* 2 \leq N \leq 2000
* K and N are integers.
Input
Input is given from Standard Input in the following format:
K N
Output
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer for i=t+1.
Examples
Input
3 3
Output
7
7
4
7
7
Input
4 5
Output
36
36
20
20
20
36
36
Input
6 1000
Output
149393349
149393349
668669001
668669001
4000002
4000002
4000002
668669001
668669001
149393349
149393349 | instruction | 0 | 53,742 | 19 | 107,484 |
"Correct Solution:
```
K, N = map(int, input().split())
mod = 998244353
def cmb(n, r, mod):
if (r < 0 or r > n):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
def H(n, k, mod):
return cmb(n+k-1, k, mod)
Nmax = 10**5
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, Nmax+1):
g1.append((g1[-1] * i) % mod)
inv.append((-inv[mod % i] * (mod//i)) % mod)
g2.append((g2[-1] * inv[-1]) % mod)
ans = []
for i in range(2, K+2):
res = 0
if i % 2 == 1:
for j in range(i//2+1):
res += cmb(i//2, j, mod)*2**j*H(K-i//2*2+j, N-j, mod)
res %= mod
else:
for j in range(i//2):
res += cmb(i//2-1, j, mod)*2**j*H(K-i+1+j, N-j, mod)
res += cmb(i//2-1, j, mod)*2**j*H(K-i+1+j, N-1-j, mod)
res %= mod
ans.append(res)
for elem in ans + ans[-2::-1]:
print(elem)
``` | output | 1 | 53,742 | 19 | 107,485 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are considered different when there exists an integer k such that the number of dice showing k is different in those two.
Constraints
* 1 \leq K \leq 2000
* 2 \leq N \leq 2000
* K and N are integers.
Input
Input is given from Standard Input in the following format:
K N
Output
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer for i=t+1.
Examples
Input
3 3
Output
7
7
4
7
7
Input
4 5
Output
36
36
20
20
20
36
36
Input
6 1000
Output
149393349
149393349
668669001
668669001
4000002
4000002
4000002
668669001
668669001
149393349
149393349
Submitted Solution:
```
K,N = (int(i) for i in input().split())
mod,ans,kn = 998244353,[],K+N
fn,fk = [1]*kn,[1]*kn
for i in range(kn-1): fn[i+1] = (fn[i]*(i+2))%mod
def power(n,k):
if k==1: return n
elif k%2==0: return power((n**2)%mod,k//2)
else: return (n*power(n,k-1))%mod
def comb(n,k):
if n==0 or k==0 or n==k: return 1
else: return (((fn[n-1]*fk[n-k-1])%mod)*fk[k-1])%mod
fk[-1] = power(fn[-1],mod-2)
for i in range(2,kn+1): fk[-i] = (fk[-i+1]*(kn+2-i))%mod
x = comb(kn-1,N)
for i in range(2,K+2):
num,c,y,p = N-2,1,0,i//2
while num>-1 and c<=p:
if c%2: y = (y+comb(p,c)*comb(K+num-1,num))%mod
else: y = (y-comb(p,c)*comb(K+num-1,num))%mod
num,c = num-2,c+1
ans.append((x-y)%mod)
for i in range(2,K+2): print(ans[i-2])
for i in range(K,1,-1): print(ans[i-2])
``` | instruction | 0 | 53,743 | 19 | 107,486 |
Yes | output | 1 | 53,743 | 19 | 107,487 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are considered different when there exists an integer k such that the number of dice showing k is different in those two.
Constraints
* 1 \leq K \leq 2000
* 2 \leq N \leq 2000
* K and N are integers.
Input
Input is given from Standard Input in the following format:
K N
Output
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer for i=t+1.
Examples
Input
3 3
Output
7
7
4
7
7
Input
4 5
Output
36
36
20
20
20
36
36
Input
6 1000
Output
149393349
149393349
668669001
668669001
4000002
4000002
4000002
668669001
668669001
149393349
149393349
Submitted Solution:
```
K,N = map(int,input().split())
MOD = 998244353
fact = [1]*4000
t = 1
for i in range(1,4000):
t = (t*i)%MOD
fact[i] = t
factinv = [1]*4000
for i in range(1,4000):
factinv[i] = pow(fact[i], MOD-2, MOD)
def ncr(n,r):
if n < 0 or r < 0 or n-r < 0:
return 0
return (fact[n] * factinv[r] * factinv[n-r]) % MOD
def nhr(n,r):
if n == 0 and r == 0:
return 1
return ncr(n+r-1, r)
for i in range(2,2*K+1):
t1,t2 = 0,0
Ans = 0
# p : 足して i になる整数の組の数
np = i//2 - max(i-1-K,0)
# p組からq組, 片方を使用する場合の数を足し合わせる
# 偶奇で場合分け
if i%2==0:
# 偶数の場合 : 1組だけ同じ数の組があるため特別扱いする
np -= 1
for nq in range(np+1):
# 同じ数の組の数字を全く含まない場合
t1 = ncr(np,nq)*pow(2, nq, MOD)
t1 %= MOD
t2 = nhr(K-np*2+nq-1,N-nq)
t2 %= MOD
Ans = (Ans + t1*t2) % MOD
# 同じ数の組の数字を1つ含む場合
t2 = nhr(K-np*2+nq-1,N-nq-1)
t2 %= MOD
Ans = (Ans + t1*t2) % MOD
else:
# 奇数の場合 : p組全て互いに異なる数
for nq in range(np+1):
t1 = ncr(np,nq)*pow(2, nq, MOD)
t1 %= MOD
t2 = nhr(K-np*2+nq,N-nq)
t2 %= MOD
Ans = (Ans + t1*t2) % MOD
print(Ans%MOD)
``` | instruction | 0 | 53,744 | 19 | 107,488 |
Yes | output | 1 | 53,744 | 19 | 107,489 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are considered different when there exists an integer k such that the number of dice showing k is different in those two.
Constraints
* 1 \leq K \leq 2000
* 2 \leq N \leq 2000
* K and N are integers.
Input
Input is given from Standard Input in the following format:
K N
Output
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer for i=t+1.
Examples
Input
3 3
Output
7
7
4
7
7
Input
4 5
Output
36
36
20
20
20
36
36
Input
6 1000
Output
149393349
149393349
668669001
668669001
4000002
4000002
4000002
668669001
668669001
149393349
149393349
Submitted Solution:
```
def prepare(n, MOD):
f = 1
factorials = [1]
for m in range(1, n + 1):
f *= m
f %= MOD
factorials.append(f)
inv = pow(f, MOD - 2, MOD)
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= MOD
invs[m - 1] = inv
return factorials, invs
def solve_sub(k, n, p, factorials, invs):
"""Number of patterns where any pair(s) of p pairs appear when n dices are rolled"""
ret = 0
fp, ik = factorials[p], invs[k - 1]
for q in range(1, min(p, n // 2) + 1):
# tmp1 = factorials[p + q - 1] * invs[q] * invs[p - 1] % MOD
tmp1 = (fp * invs[q] % MOD) * invs[p - q] % MOD
tmp2 = (factorials[k + n - 2 * q - 1] * invs[n - 2 * q] % MOD) * ik % MOD
if q % 2 == 1:
ret += tmp1 * tmp2
else:
ret -= tmp1 * tmp2
ret %= MOD
return ret
def solve(k, n):
if k == 1:
return [0]
factorials, invs = prepare(k + n, MOD)
all_patterns_odd = factorials[k + n - 1] * invs[n] * invs[k - 1] % MOD
all_patterns_even0 = factorials[k + n - 2] * invs[n] * invs[k - 2] % MOD
all_patterns_even1 = factorials[k + n - 3] * invs[n - 1] * invs[k - 2] % MOD
buf = []
for i in range(2, k + 2):
pairs = i // 2 - max(0, i - k - 1)
if i % 2 == 0:
ans = all_patterns_even0 - solve_sub(k - 1, n, pairs - 1, factorials, invs)
ans += all_patterns_even1 - solve_sub(k - 1, n - 1, pairs - 1, factorials, invs)
ans %= MOD
else:
ans = (all_patterns_odd - solve_sub(k, n, pairs, factorials, invs)) % MOD
buf.append(ans)
return buf
MOD = 998244353
k, n = map(int, input().split())
ans = solve(k, n)
print('\n'.join(map(str, ans)))
print('\n'.join(map(str, ans[-2::-1])))
``` | instruction | 0 | 53,745 | 19 | 107,490 |
Yes | output | 1 | 53,745 | 19 | 107,491 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are considered different when there exists an integer k such that the number of dice showing k is different in those two.
Constraints
* 1 \leq K \leq 2000
* 2 \leq N \leq 2000
* K and N are integers.
Input
Input is given from Standard Input in the following format:
K N
Output
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer for i=t+1.
Examples
Input
3 3
Output
7
7
4
7
7
Input
4 5
Output
36
36
20
20
20
36
36
Input
6 1000
Output
149393349
149393349
668669001
668669001
4000002
4000002
4000002
668669001
668669001
149393349
149393349
Submitted Solution:
```
import sys
input = sys.stdin.readline
# K+1 - x でうつす -> i と 2K+2-i は同じ
MOD = 998244353
U = 10000
fact = [1] * (U+1)
fact_inv = [1] * (U+1)
for n in range(1,U+1):
fact[n] = fact[n-1] * n % MOD
fact_inv[n] = pow(fact[n], MOD-2, MOD)
for n in range(U,0,-1):
fact_inv[n-1] = fact_inv[n] * n % MOD
def comb(n,k):
if not (0 <= k <= n):
return 0
return fact[n] * fact_inv[k] * fact_inv[n-k] % MOD
K,N = map(int,input().split())
def F(x,y,N):
n = min(x, N)
return sum(comb(x,i) * pow(2,i,MOD) * comb(N+y-1,i+y-1) for i in range(n+1)) % MOD
answer = []
for S in range(2,K+2):
if S & 1:
x = F((S-1)//2, K - S + 1, N)
else:
x = F((S-1)//2, K - S + 1, N) + F((S-1)//2, K - S + 1, N - 1)
answer.append(x % MOD)
answer += answer[:-1][::-1]
print('\n'.join(map(str,answer)))
``` | instruction | 0 | 53,746 | 19 | 107,492 |
Yes | output | 1 | 53,746 | 19 | 107,493 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are considered different when there exists an integer k such that the number of dice showing k is different in those two.
Constraints
* 1 \leq K \leq 2000
* 2 \leq N \leq 2000
* K and N are integers.
Input
Input is given from Standard Input in the following format:
K N
Output
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer for i=t+1.
Examples
Input
3 3
Output
7
7
4
7
7
Input
4 5
Output
36
36
20
20
20
36
36
Input
6 1000
Output
149393349
149393349
668669001
668669001
4000002
4000002
4000002
668669001
668669001
149393349
149393349
Submitted Solution:
```
import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
# nの逆元のリスト
def inv_mod(n:int, mod:int) -> list:
inv = [0,1]
for i in range(2,n+1):
inv.append(mod - ((mod//i)*inv[mod%i]) % mod)
return inv
# nの階乗のリスト
def fact(n:int, mod:int) -> list:
fac = [1,1]
res = 1
for i in range(2,n+1):
res = res*i%mod
fac.append(res)
return fac
# nの階乗の逆元のリスト
def fact_inv(n:int, inv:list, mod:int) -> list:
facInv = [1,1]
for i in range(2,n+1):
facInv.append(facInv[i-1]*inv[i] % mod)
return facInv
# 二項係数
def nCr(n:int, r:int, mod:int, fac:list, facInv:list) -> int:
if not (0<=r and r<=n):
return 0
return ((fac[n]*facInv[r]) % mod) * facInv[n-r] % mod
MOD = 998244353
k,n = li()
inv = inv_mod(n+k,MOD)
fac = fact(n+k,MOD)
facInv = fact_inv(n+k,inv,MOD)
answers = []
if k == 1:
print(0)
else:
for t in range(2,k+2):
p = t//2
ans = 0
if t%2 == 0:
temp = 0
for q in range(p):
temp = temp + nCr(p-1,q,MOD,fac,facInv) \
* (2**q) \
* nCr(n+k-2*p,n-q,MOD,fac,facInv)
temp %= MOD
temp = temp + nCr(p-1,q,MOD,fac,facInv) \
* (2**q) \
* nCr(n+k-2*p-1,n-q-1,MOD,fac,facInv)
temp %= MOD
ans = temp%MOD
else:
temp = 0
for q in range(p+1):
temp = temp + nCr(p,q,MOD,fac,facInv) \
* (2**q) \
* nCr(n+k-2*p-1,n-q,MOD,fac,facInv)
temp %= MOD
ans = temp%MOD
answers.append(ans)
print(ans)
for ans in answers[-2::-1]:
print(ans)
``` | instruction | 0 | 53,747 | 19 | 107,494 |
No | output | 1 | 53,747 | 19 | 107,495 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are considered different when there exists an integer k such that the number of dice showing k is different in those two.
Constraints
* 1 \leq K \leq 2000
* 2 \leq N \leq 2000
* K and N are integers.
Input
Input is given from Standard Input in the following format:
K N
Output
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer for i=t+1.
Examples
Input
3 3
Output
7
7
4
7
7
Input
4 5
Output
36
36
20
20
20
36
36
Input
6 1000
Output
149393349
149393349
668669001
668669001
4000002
4000002
4000002
668669001
668669001
149393349
149393349
Submitted Solution:
```
mod = 998244353
rng = 4100
fctr = [1]
finv = [1]
for i in range(1,rng):
fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
if n<0 or k<0:
return 0
else:
return fctr[n]*finv[n-k]*finv[k]%mod
def homo(n,k):
if n<0 or k<=0:
return 0
else:
return cmb(n+k-1,k-1)
k,n = map(int,input().split())
if k%2 == 0:
flg = 0
else:
flg = 1
ans = []
for i in range(3,k+2,2):
ic = (i-1)//2
anstmp = 0
for j in range(ic+1):
t = homo(n-j,(k-ic*2+j))*cmb(ic,j)*pow(2,j,mod)
anstmp = (anstmp+t)%mod
ans.append(anstmp)
ans.append(anstmp)
if flg:
anstmp = 0
for j in range(1,k//2+1):
t = (homo(n-j,j)*homo(n-j-1,j+1))*cmb(k//2,j)*pow(2,j,mod)
anstmp = (anstmp+t)%mod
ans.append(anstmp)
ans2 = ans[:-1]
ans2 = ans2[::-1]
print(*ans,*ans2,sep="\n")
``` | instruction | 0 | 53,748 | 19 | 107,496 |
No | output | 1 | 53,748 | 19 | 107,497 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the following value modulo 998244353:
* The number of combinations of N sides shown by the dice such that the sum of no two different sides is i.
Note that the dice are NOT distinguishable, that is, two combinations are considered different when there exists an integer k such that the number of dice showing k is different in those two.
Constraints
* 1 \leq K \leq 2000
* 2 \leq N \leq 2000
* K and N are integers.
Input
Input is given from Standard Input in the following format:
K N
Output
Print 2K-1 integers. The t-th of them (1\leq t\leq 2K-1) should be the answer for i=t+1.
Examples
Input
3 3
Output
7
7
4
7
7
Input
4 5
Output
36
36
20
20
20
36
36
Input
6 1000
Output
149393349
149393349
668669001
668669001
4000002
4000002
4000002
668669001
668669001
149393349
149393349
Submitted Solution:
```
MOD = 998244353
k, n = map(int, input().split())
list_size = 5000
f_list = [1] * list_size
f_r_list = [1] * list_size
for i in range(list_size - 1):
f_list[i + 1] = int((f_list[i] * (i + 2)) % MOD)
def power(n, x):
if x == 1:
return n
elif x % 2 == 0:
return power(int((n * n) % MOD), int(x / 2))
else:
return int((n * power(n, x - 1)) % MOD)
f_r_list[-1] = power(f_list[-1], MOD - 2)
for i in range(2, list_size + 1):
f_r_list[-i] = int((f_r_list[-i + 1] * (list_size + 2 - i)) % MOD)
def comb(n, r):
if n < r or r < 0:
return 0
elif n == 0 or r == 0 or n == r:
return 1
else:
return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD
ans = []
for i in range(2, k+2):
num = 0
if i%2 == 1:
for j in range(0, i//2+1):
#num += comb(i//2, j) * comb(n-1, j-1) * pow(2, j, MOD) * comb(n+k-i-j, k-i)
num += comb(i//2, j) * pow(2, j, MOD) * comb(n+k-i, k-i+j)
num %= MOD
else:
for j in range(0, i//2):
#num += comb(i//2-1, j) * comb(n-1, j-1) * pow(2, j, MOD) * comb(n+k-i-j, k-i)
num += comb(i//2-1, j) * pow(2, j, MOD) * comb(n+k-i, k-i+j)
#num += comb(i//2-1, j) * comb(n-2, j-1) * pow(2, j, MOD) * comb(n+k-i-j-1, k-i)
num += comb(i//2-1, j) * pow(2, j, MOD) * comb(n+k-i-1, k-i+j)
num %= MOD
ans.append(num)
print(*ans, sep="\n")
ans = reversed(ans[:k-1])
print(*ans, sep="\n")
``` | instruction | 0 | 53,749 | 19 | 107,498 |
No | output | 1 | 53,749 | 19 | 107,499 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.