text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th character in S is `2`.
Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure 2N times, modulo 998244353:
* Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.
* Takahashi receives the ball and put it to the end of his sequence.
Constraints
* 1 \leq |S| \leq 2000
* S consists of `0`,`1` and `2`.
Note that the integer N is not directly given in input; it is given indirectly as the length of the string S.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of the possible sequences Takahashi may have after repeating the procedure 2N times, modulo 998244353.
Examples
Input
02
Output
3
Input
1210
Output
55
Input
12001021211100201020
Output
543589959
Submitted Solution:
```
import sys
input = sys.stdin.readline
S = input()[:-1]
N = len(S)
dp = [[0]*(2*N+1) for _ in range(2*N+1)]
dp[0][0] = 1
MOD = 998244353
r, b = 0, 0
for i in range(2*N):
if i<N:
if S[i]=='0':
r += 2
elif S[i]=='1':
r += 1
b += 1
else:
b += 2
for j in range(2*N+1):
rc = r-j
bc = b-(i-j)
if rc>0:
dp[i+1][j+1] += dp[i][j]
dp[i+1][j+1] %= MOD
if bc>0:
dp[i+1][j] += dp[i][j]
dp[i+1][j] %= MOD
print(sum(dp[2*N]))
```
Yes
| 8,900 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th character in S is `2`.
Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure 2N times, modulo 998244353:
* Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.
* Takahashi receives the ball and put it to the end of his sequence.
Constraints
* 1 \leq |S| \leq 2000
* S consists of `0`,`1` and `2`.
Note that the integer N is not directly given in input; it is given indirectly as the length of the string S.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of the possible sequences Takahashi may have after repeating the procedure 2N times, modulo 998244353.
Examples
Input
02
Output
3
Input
1210
Output
55
Input
12001021211100201020
Output
543589959
Submitted Solution:
```
S=input()
N=len(S)
d=[[0]*4001 for _ in range(4001)]
d[0][0]=1
x=0
y=0
for i in range(2*N):
if i<N:
x+=int(S[i])
y=2*i+2-x
for j in range(i+1):
for k in range(2):
if j+1-k<=x and i-j+k<=y:
d[j+1-k][i-j+k]+=d[j][i-j]
d[j+1-k][i-j+k]%=998244353
print(d[x][y])
```
Yes
| 8,901 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th character in S is `2`.
Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure 2N times, modulo 998244353:
* Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.
* Takahashi receives the ball and put it to the end of his sequence.
Constraints
* 1 \leq |S| \leq 2000
* S consists of `0`,`1` and `2`.
Note that the integer N is not directly given in input; it is given indirectly as the length of the string S.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of the possible sequences Takahashi may have after repeating the procedure 2N times, modulo 998244353.
Examples
Input
02
Output
3
Input
1210
Output
55
Input
12001021211100201020
Output
543589959
Submitted Solution:
```
M=998244353
S=input()
N=len(S)
d=[[0]*4001 for _ in range(4001)]
d[0][0]=1
x=0
for i in range(2*N):
if i<N:
x+=int(S[i])
y=2*i+2-x
for j in range(i+1):
for k in range(2):
if i-y<=j-k<x:d[j+1-k][i-j+k]+=d[j][i-j]%M
print(d[x][y]%M)
```
Yes
| 8,902 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th character in S is `2`.
Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure 2N times, modulo 998244353:
* Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.
* Takahashi receives the ball and put it to the end of his sequence.
Constraints
* 1 \leq |S| \leq 2000
* S consists of `0`,`1` and `2`.
Note that the integer N is not directly given in input; it is given indirectly as the length of the string S.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of the possible sequences Takahashi may have after repeating the procedure 2N times, modulo 998244353.
Examples
Input
02
Output
3
Input
1210
Output
55
Input
12001021211100201020
Output
543589959
Submitted Solution:
```
from collections import defaultdict
def inpl(): return list(map(int, input().split()))
MOD = 998244353
S = input()
N = len(S)
B = [0]*(2*N+1)
R = [0]*(2*N+1)
for i in range(N):
b = int(S[i])
B[i] = b
R[i] = 2 - b
DP = defaultdict(int)
DP[(B[0], R[0])] = 1
for i in range(1, 2*N+1):
DP2 = defaultdict(int)
b1, r1 = B[i], R[i]
for (b0, r0), v in DP.items():
b2, r2 = b0+b1, r0+r1
if b0:
DP2[(b2-1, r2)] = (DP2[(b2-1, r2)] + v)%MOD
if r0:
DP2[(b2, r2-1)] = (DP2[(b2, r2-1)] + v)%MOD
DP = DP2
print(sum(DP.values()))
```
Yes
| 8,903 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th character in S is `2`.
Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure 2N times, modulo 998244353:
* Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.
* Takahashi receives the ball and put it to the end of his sequence.
Constraints
* 1 \leq |S| \leq 2000
* S consists of `0`,`1` and `2`.
Note that the integer N is not directly given in input; it is given indirectly as the length of the string S.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of the possible sequences Takahashi may have after repeating the procedure 2N times, modulo 998244353.
Examples
Input
02
Output
3
Input
1210
Output
55
Input
12001021211100201020
Output
543589959
Submitted Solution:
```
s = input()
n = len(s)
mod = 998244353
R = [0] * n
B = [0] * n
for i in range(n):
if s[i] == '0':
R[i] = 2
elif s[i] == '1':
R[i] = 1
B[i] = 1
else:
B[i] = 2
for i in range(n-1):
R[i+1] += R[i]
B[i+1] += B[i]
dp = [[0] * (2*n+10) for _ in range(2*n+10)]
if R[0] > 0:
dp[0][1] = 1
if B[0] > 0:
dp[0][0] = 1
for i in range(n-1):
for r in range(2*n+1):
if R[i+1] >= r+1:
dp[i+1][r+1] += dp[i][r]
dp[i+1][r+1] %= mod
if i+2-r < 0:
break
if B[i+1] >= i+2-r:
dp[i+1][r] += dp[i][r]
dp[i+1][r] %= mod
for i in range(n-1, 2*n-1):
for r in range(2*n+1):
if R[n-1] >= r+1:
dp[i + 1][r + 1] += dp[i][r]
dp[i + 1][r + 1] %= mod
if i+2-r < 0:
break
if B[n-1] >= i+2-r:
dp[i+1][r] += dp[i][r]
dp[i+1][r] %= mod
ans = 0
for r in range(2*n+1):
ans += dp[2*n-1][r]
ans %= mod
print(ans)
```
No
| 8,904 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th character in S is `2`.
Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure 2N times, modulo 998244353:
* Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.
* Takahashi receives the ball and put it to the end of his sequence.
Constraints
* 1 \leq |S| \leq 2000
* S consists of `0`,`1` and `2`.
Note that the integer N is not directly given in input; it is given indirectly as the length of the string S.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of the possible sequences Takahashi may have after repeating the procedure 2N times, modulo 998244353.
Examples
Input
02
Output
3
Input
1210
Output
55
Input
12001021211100201020
Output
543589959
Submitted Solution:
```
from collections import defaultdict
def tqdm(iterable): return iterable
def inpl(): return list(map(int, input().split()))
MOD = 998244353
S = input()
N = len(S)
B = [0]*N
R = [0]*N
for i in range(N):
b = int(S[i])
B[i] = b
R[i] = 2 - b
DP = defaultdict(int)
DP[(B[0], R[0])] = 1
for i in tqdm(range(1, N)):
DP2 = defaultdict(int)
b1, r1 = B[i], R[i]
for (b0, r0), v in DP.items():
b2, r2 = b0+b1, r0+r1
if b0:
DP2[(b2-1, r2)] = (DP2[(b2-1, r2)] + v)%MOD
if r0:
DP2[(b2, r2-1)] = (DP2[(b2, r2-1)] + v)%MOD
DP = DP2
for _ in tqdm(range(N+1)):
DP2 = defaultdict(int)
for (b, r), v in DP.items():
if b:
DP2[(b-1, r)] = (DP2[(b-1, r)] + v)%MOD
if r:
DP2[(b, r-1)] = (DP2[(b, r-1)] + v)%MOD
DP = DP2
print(sum(DP.values()))
```
No
| 8,905 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th character in S is `2`.
Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure 2N times, modulo 998244353:
* Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.
* Takahashi receives the ball and put it to the end of his sequence.
Constraints
* 1 \leq |S| \leq 2000
* S consists of `0`,`1` and `2`.
Note that the integer N is not directly given in input; it is given indirectly as the length of the string S.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of the possible sequences Takahashi may have after repeating the procedure 2N times, modulo 998244353.
Examples
Input
02
Output
3
Input
1210
Output
55
Input
12001021211100201020
Output
543589959
Submitted Solution:
```
mod = 998244353
s = list(map(int, list(input())))
n = len(s)
dp = [[0]*(sum(s)+1) for _ in range(2*n+1)]
dp[0][0] = 1
curr = curb = 0
for i in range(2*n):
if i < n:
curb += s[i]
curr += 2 - s[i]
for j in range(min(i, curb)+1):
if dp[i][j]:
dp[i][j] %= mod
if i - j < curr:
dp[i+1][j] += dp[i][j]
if j < curb:
dp[i+1][j+1] += dp[i][j]
print(dp[2*n][curb])
```
No
| 8,906 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N Snukes lining up in a row. You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is `0`; one red ball and one blue ball if the i-th character in S is `1`; two blue balls if the i-th character in S is `2`.
Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure 2N times, modulo 998244353:
* Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.
* Takahashi receives the ball and put it to the end of his sequence.
Constraints
* 1 \leq |S| \leq 2000
* S consists of `0`,`1` and `2`.
Note that the integer N is not directly given in input; it is given indirectly as the length of the string S.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of the possible sequences Takahashi may have after repeating the procedure 2N times, modulo 998244353.
Examples
Input
02
Output
3
Input
1210
Output
55
Input
12001021211100201020
Output
543589959
Submitted Solution:
```
mod = 998244353
import sys
sys.setrecursionlimit(10**9)
S = input()
N = len(S)
Sum = [0]*(N+1)
for i in range(1, N+1):
Sum[i] = Sum[i-1]+int(S[i-1])
from functools import lru_cache
@lru_cache(maxsize=10**8)
def dp(i, j):
n = min(i+j+1, N)
if i+j == N*2:
return 1
res = 0
s = Sum[n]
if i<s:
res+=dp(i+1, j)
if j<2*n-s:
res+=dp(i, j+1)
return res%mod
print(dp(0, 0))
```
No
| 8,907 |
Provide a correct Python 3 solution for this coding contest problem.
There are N robots and M exits on a number line. The N + M coordinates of these are all integers and all distinct. For each i (1 \leq i \leq N), the coordinate of the i-th robot from the left is x_i. Also, for each j (1 \leq j \leq M), the coordinate of the j-th exit from the left is y_j.
Snuke can repeatedly perform the following two kinds of operations in any order to move all the robots simultaneously:
* Increment the coordinates of all the robots on the number line by 1.
* Decrement the coordinates of all the robots on the number line by 1.
Each robot will disappear from the number line when its position coincides with that of an exit, going through that exit. Snuke will continue performing operations until all the robots disappear.
When all the robots disappear, how many combinations of exits can be used by the robots? Find the count modulo 10^9 + 7. Here, two combinations of exits are considered different when there is a robot that used different exits in those two combinations.
Constraints
* 1 \leq N, M \leq 10^5
* 1 \leq x_1 < x_2 < ... < x_N \leq 10^9
* 1 \leq y_1 < y_2 < ... < y_M \leq 10^9
* All given coordinates are integers.
* All given coordinates are distinct.
Input
Input is given from Standard Input in the following format:
N M
x_1 x_2 ... x_N
y_1 y_2 ... y_M
Output
Print the number of the combinations of exits that can be used by the robots when all the robots disappear, modulo 10^9 + 7.
Examples
Input
2 2
2 3
1 4
Output
3
Input
3 4
2 5 10
1 3 7 13
Output
8
Input
4 1
1 2 4 5
3
Output
1
Input
4 5
2 5 7 11
1 3 6 9 13
Output
6
Input
10 10
4 13 15 18 19 20 21 22 25 27
1 5 11 12 14 16 23 26 29 30
Output
22
"Correct Solution:
```
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from bisect import bisect_left
MOD = 10**9 + 7
N,M = map(int,readline().split())
X = list(map(int,readline().split()))
Y = list(map(int,readline().split()))
L = []; R = []
for x in X:
i = bisect_left(Y,x) # 右出口
if i in [0,M]:
continue
y0,y1 = Y[i-1:i+1]
L.append(y0-x); R.append(y1-x)
# 座圧
Rtoi = {x:i for i,x in enumerate(sorted(set(R)),1)}
R = [Rtoi[r] for r in R]
if len(R) == 0:
print(1)
exit()
"""
・計算方法
・これをやるために実際にはBITを使う
dp = [0] * (max(R)+1)
for _,r in sorted(set(zip(L,R)),reverse=True):
dp[r] += 1 + sum(dp[1:r]) #これをやるために BIT で dp を持つ
answer=1+sum(dp)
print(answer)
"""
class BIT():
def __init__(self, max_n):
self.size = max_n + 1
self.tree = [0] * self.size
def get_sum(self,i):
s = 0
while i:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i < self.size:
self.tree[i] += x
i += i & -i
dp = BIT(max_n=max(R))
for _,r in sorted(set(zip(L,R)),reverse=True):
x = dp.get_sum(r-1) + 1; x %= MOD
dp.add(r,x)
answer=1+dp.get_sum(max(R))
answer %= MOD
print(answer)
```
| 8,908 |
Provide a correct Python 3 solution for this coding contest problem.
There are N robots and M exits on a number line. The N + M coordinates of these are all integers and all distinct. For each i (1 \leq i \leq N), the coordinate of the i-th robot from the left is x_i. Also, for each j (1 \leq j \leq M), the coordinate of the j-th exit from the left is y_j.
Snuke can repeatedly perform the following two kinds of operations in any order to move all the robots simultaneously:
* Increment the coordinates of all the robots on the number line by 1.
* Decrement the coordinates of all the robots on the number line by 1.
Each robot will disappear from the number line when its position coincides with that of an exit, going through that exit. Snuke will continue performing operations until all the robots disappear.
When all the robots disappear, how many combinations of exits can be used by the robots? Find the count modulo 10^9 + 7. Here, two combinations of exits are considered different when there is a robot that used different exits in those two combinations.
Constraints
* 1 \leq N, M \leq 10^5
* 1 \leq x_1 < x_2 < ... < x_N \leq 10^9
* 1 \leq y_1 < y_2 < ... < y_M \leq 10^9
* All given coordinates are integers.
* All given coordinates are distinct.
Input
Input is given from Standard Input in the following format:
N M
x_1 x_2 ... x_N
y_1 y_2 ... y_M
Output
Print the number of the combinations of exits that can be used by the robots when all the robots disappear, modulo 10^9 + 7.
Examples
Input
2 2
2 3
1 4
Output
3
Input
3 4
2 5 10
1 3 7 13
Output
8
Input
4 1
1 2 4 5
3
Output
1
Input
4 5
2 5 7 11
1 3 6 9 13
Output
6
Input
10 10
4 13 15 18 19 20 21 22 25 27
1 5 11 12 14 16 23 26 29 30
Output
22
"Correct Solution:
```
from bisect import bisect
from collections import defaultdict
class Bit:
def __init__(self, n, MOD):
self.size = n
self.tree = [0] * (n + 1)
self.depth = n.bit_length()
self.mod = MOD
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s % self.mod
def add(self, i, x):
while i <= self.size:
self.tree[i] = (self.tree[i] + x) % self.mod
i += i & -i
def debug_print(self):
for i in range(1, self.size + 1):
j = (i & -i).bit_length()
print(' ' * j, self.tree[i])
def lower_bound(self, x):
sum_ = 0
pos = 0
for i in range(self.depth, -1, -1):
k = pos + (1 << i)
if k <= self.size and sum_ + self.tree[k] < x:
sum_ += self.tree[k]
pos += 1 << i
return pos + 1, sum_
n, m = map(int, input().split())
xxx = list(map(int, input().split()))
yyy = list(map(int, input().split()))
ab = defaultdict(set)
coordinates = set()
for x in xxx:
if x < yyy[0] or yyy[-1] < x:
continue
i = bisect(yyy, x)
a = x - yyy[i - 1]
b = yyy[i] - x
ab[a].add(b)
coordinates.add(b)
# Bitのindexは1から始まるように作っているが、"0"を取れるようにするため、全体を1ずらす
cor_dict = {b: i for i, b in enumerate(sorted(coordinates), start=2)}
cdg = cor_dict.get
MOD = 10 ** 9 + 7
bit = Bit(len(coordinates) + 1, MOD)
bit.add(1, 1)
for a in sorted(ab):
bbb = sorted(map(cdg, ab[a]), reverse=True)
for b in bbb:
bit.add(b, bit.sum(b - 1))
print(bit.sum(bit.size))
```
| 8,909 |
Provide a correct Python 3 solution for this coding contest problem.
There are N robots and M exits on a number line. The N + M coordinates of these are all integers and all distinct. For each i (1 \leq i \leq N), the coordinate of the i-th robot from the left is x_i. Also, for each j (1 \leq j \leq M), the coordinate of the j-th exit from the left is y_j.
Snuke can repeatedly perform the following two kinds of operations in any order to move all the robots simultaneously:
* Increment the coordinates of all the robots on the number line by 1.
* Decrement the coordinates of all the robots on the number line by 1.
Each robot will disappear from the number line when its position coincides with that of an exit, going through that exit. Snuke will continue performing operations until all the robots disappear.
When all the robots disappear, how many combinations of exits can be used by the robots? Find the count modulo 10^9 + 7. Here, two combinations of exits are considered different when there is a robot that used different exits in those two combinations.
Constraints
* 1 \leq N, M \leq 10^5
* 1 \leq x_1 < x_2 < ... < x_N \leq 10^9
* 1 \leq y_1 < y_2 < ... < y_M \leq 10^9
* All given coordinates are integers.
* All given coordinates are distinct.
Input
Input is given from Standard Input in the following format:
N M
x_1 x_2 ... x_N
y_1 y_2 ... y_M
Output
Print the number of the combinations of exits that can be used by the robots when all the robots disappear, modulo 10^9 + 7.
Examples
Input
2 2
2 3
1 4
Output
3
Input
3 4
2 5 10
1 3 7 13
Output
8
Input
4 1
1 2 4 5
3
Output
1
Input
4 5
2 5 7 11
1 3 6 9 13
Output
6
Input
10 10
4 13 15 18 19 20 21 22 25 27
1 5 11 12 14 16 23 26 29 30
Output
22
"Correct Solution:
```
from bisect import bisect
from collections import defaultdict
class Bit:
def __init__(self, n, MOD):
self.size = n
self.tree = [0] * (n + 1)
self.depth = n.bit_length()
self.mod = MOD
def sum(self, i):
s = 0
while i > 0:
s = (s + self.tree[i]) % self.mod
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] = (self.tree[i] + x) % self.mod
i += i & -i
def debug_print(self):
for i in range(1, self.size + 1):
j = (i & -i).bit_length()
print(' ' * j, self.tree[i])
def lower_bound(self, x):
sum_ = 0
pos = 0
for i in range(self.depth, -1, -1):
k = pos + (1 << i)
if k <= self.size and sum_ + self.tree[k] < x:
sum_ += self.tree[k]
pos += 1 << i
return pos + 1, sum_
n, m = map(int, input().split())
xxx = list(map(int, input().split()))
yyy = list(map(int, input().split()))
ab = defaultdict(set)
coordinates = set()
for x in xxx:
if x < yyy[0] or yyy[-1] < x:
continue
i = bisect(yyy, x)
a = x - yyy[i - 1]
b = yyy[i] - x
ab[a].add(b)
coordinates.add(b)
# Bitのindexは1から始まるように作っているが、"0"を取れるようにするため、全体を1ずらす
cor_dict = {b: i for i, b in enumerate(sorted(coordinates), start=2)}
cdg = cor_dict.get
MOD = 10 ** 9 + 7
bit = Bit(len(coordinates) + 1, MOD)
bit.add(1, 1)
for a in sorted(ab):
bbb = sorted(map(cdg, ab[a]), reverse=True)
for b in bbb:
bit.add(b, bit.sum(b - 1))
print(bit.sum(bit.size))
```
| 8,910 |
Provide a correct Python 3 solution for this coding contest problem.
There are N robots and M exits on a number line. The N + M coordinates of these are all integers and all distinct. For each i (1 \leq i \leq N), the coordinate of the i-th robot from the left is x_i. Also, for each j (1 \leq j \leq M), the coordinate of the j-th exit from the left is y_j.
Snuke can repeatedly perform the following two kinds of operations in any order to move all the robots simultaneously:
* Increment the coordinates of all the robots on the number line by 1.
* Decrement the coordinates of all the robots on the number line by 1.
Each robot will disappear from the number line when its position coincides with that of an exit, going through that exit. Snuke will continue performing operations until all the robots disappear.
When all the robots disappear, how many combinations of exits can be used by the robots? Find the count modulo 10^9 + 7. Here, two combinations of exits are considered different when there is a robot that used different exits in those two combinations.
Constraints
* 1 \leq N, M \leq 10^5
* 1 \leq x_1 < x_2 < ... < x_N \leq 10^9
* 1 \leq y_1 < y_2 < ... < y_M \leq 10^9
* All given coordinates are integers.
* All given coordinates are distinct.
Input
Input is given from Standard Input in the following format:
N M
x_1 x_2 ... x_N
y_1 y_2 ... y_M
Output
Print the number of the combinations of exits that can be used by the robots when all the robots disappear, modulo 10^9 + 7.
Examples
Input
2 2
2 3
1 4
Output
3
Input
3 4
2 5 10
1 3 7 13
Output
8
Input
4 1
1 2 4 5
3
Output
1
Input
4 5
2 5 7 11
1 3 6 9 13
Output
6
Input
10 10
4 13 15 18 19 20 21 22 25 27
1 5 11 12 14 16 23 26 29 30
Output
22
"Correct Solution:
```
from bisect import bisect
from collections import defaultdict
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
self.depth = n.bit_length()
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
def debug_print(self):
for i in range(1, self.size + 1):
j = (i & -i).bit_length()
print(' ' * j, self.tree[i])
def lower_bound(self, x):
sum_ = 0
pos = 0
for i in range(self.depth, -1, -1):
k = pos + (1 << i)
if k <= self.size and sum_ + self.tree[k] < x:
sum_ += self.tree[k]
pos += 1 << i
return pos + 1, sum_
n, m = map(int, input().split())
xxx = list(map(int, input().split()))
yyy = list(map(int, input().split()))
ab = defaultdict(set)
coordinates = set()
for x in xxx:
if x < yyy[0] or yyy[-1] < x:
continue
i = bisect(yyy, x)
a = x - yyy[i - 1]
b = yyy[i] - x
ab[a].add(b)
coordinates.add(b)
# Bitのindexは1から始まるように作っているが、"0"を取れるようにするため、全体を1ずらす
cor_dict = {b: i for i, b in enumerate(sorted(coordinates), start=2)}
cdg = cor_dict.get
bit = Bit(len(coordinates) + 1)
bit.add(1, 1)
for a in sorted(ab):
bbb = sorted(map(cdg, ab[a]), reverse=True)
for b in bbb:
bit.add(b, bit.sum(b - 1))
print(bit.sum(bit.size) % (10 ** 9 + 7))
```
| 8,911 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N robots and M exits on a number line. The N + M coordinates of these are all integers and all distinct. For each i (1 \leq i \leq N), the coordinate of the i-th robot from the left is x_i. Also, for each j (1 \leq j \leq M), the coordinate of the j-th exit from the left is y_j.
Snuke can repeatedly perform the following two kinds of operations in any order to move all the robots simultaneously:
* Increment the coordinates of all the robots on the number line by 1.
* Decrement the coordinates of all the robots on the number line by 1.
Each robot will disappear from the number line when its position coincides with that of an exit, going through that exit. Snuke will continue performing operations until all the robots disappear.
When all the robots disappear, how many combinations of exits can be used by the robots? Find the count modulo 10^9 + 7. Here, two combinations of exits are considered different when there is a robot that used different exits in those two combinations.
Constraints
* 1 \leq N, M \leq 10^5
* 1 \leq x_1 < x_2 < ... < x_N \leq 10^9
* 1 \leq y_1 < y_2 < ... < y_M \leq 10^9
* All given coordinates are integers.
* All given coordinates are distinct.
Input
Input is given from Standard Input in the following format:
N M
x_1 x_2 ... x_N
y_1 y_2 ... y_M
Output
Print the number of the combinations of exits that can be used by the robots when all the robots disappear, modulo 10^9 + 7.
Examples
Input
2 2
2 3
1 4
Output
3
Input
3 4
2 5 10
1 3 7 13
Output
8
Input
4 1
1 2 4 5
3
Output
1
Input
4 5
2 5 7 11
1 3 6 9 13
Output
6
Input
10 10
4 13 15 18 19 20 21 22 25 27
1 5 11 12 14 16 23 26 29 30
Output
22
Submitted Solution:
```
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from bisect import bisect_left
MOD = 10**9 + 7
N,M = map(int,readline().split())
X = list(map(int,readline().split()))
Y = list(map(int,readline().split()))
L = []; R = []
for x in X:
i = bisect_left(Y,x) # 右出口
if i in [0,M]:
continue
y0,y1 = Y[i-1:i+1]
L.append(y0-x); R.append(y1-x)
# 座圧
Rtoi = {x:i for i,x in enumerate(sorted(set(R)),1)}
R = [Rtoi[r] for r in R]
if len(R) == 0:
print(1)
exit()
"""
・計算方法
・これをやるために実際にはBITを使う
dp = [0] * (max(R)+1)
for _,r in sorted(set(zip(L,R)),reverse=True):
dp[r] += 1 + sum(dp[1:r]) #これをやるために BIT で dp を持つ
answer=1+sum(dp)
print(answer)
"""
class BIT():
def __init__(self, max_n):
self.size = max_n + 1
self.tree = [0] * self.size
def get_sum(self,i):
s = 0
while i:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i < self.size:
self.tree[i] += x
i += i & -i
dp = BIT(max_n=max(R))
for _,r in sorted(set(zip(L,R)),reverse=True):
x = dp.get_sum(r-1) + 1; x %= MOD
dp.add(r,x)
answer=1+dp.get_sum(max(R))
print(answer)
```
No
| 8,912 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N robots and M exits on a number line. The N + M coordinates of these are all integers and all distinct. For each i (1 \leq i \leq N), the coordinate of the i-th robot from the left is x_i. Also, for each j (1 \leq j \leq M), the coordinate of the j-th exit from the left is y_j.
Snuke can repeatedly perform the following two kinds of operations in any order to move all the robots simultaneously:
* Increment the coordinates of all the robots on the number line by 1.
* Decrement the coordinates of all the robots on the number line by 1.
Each robot will disappear from the number line when its position coincides with that of an exit, going through that exit. Snuke will continue performing operations until all the robots disappear.
When all the robots disappear, how many combinations of exits can be used by the robots? Find the count modulo 10^9 + 7. Here, two combinations of exits are considered different when there is a robot that used different exits in those two combinations.
Constraints
* 1 \leq N, M \leq 10^5
* 1 \leq x_1 < x_2 < ... < x_N \leq 10^9
* 1 \leq y_1 < y_2 < ... < y_M \leq 10^9
* All given coordinates are integers.
* All given coordinates are distinct.
Input
Input is given from Standard Input in the following format:
N M
x_1 x_2 ... x_N
y_1 y_2 ... y_M
Output
Print the number of the combinations of exits that can be used by the robots when all the robots disappear, modulo 10^9 + 7.
Examples
Input
2 2
2 3
1 4
Output
3
Input
3 4
2 5 10
1 3 7 13
Output
8
Input
4 1
1 2 4 5
3
Output
1
Input
4 5
2 5 7 11
1 3 6 9 13
Output
6
Input
10 10
4 13 15 18 19 20 21 22 25 27
1 5 11 12 14 16 23 26 29 30
Output
22
Submitted Solution:
```
from bisect import bisect
from collections import defaultdict
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
self.depth = n.bit_length()
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
def debug_print(self):
for i in range(1, self.size + 1):
j = (i & -i).bit_length()
print(' ' * j, self.tree[i])
def lower_bound(self, x):
sum_ = 0
pos = 0
for i in range(self.depth, -1, -1):
k = pos + (1 << i)
if k <= self.size and sum_ + self.tree[k] < x:
sum_ += self.tree[k]
pos += 1 << i
return pos + 1, sum_
n, m = map(int, input().split())
xxx = list(map(int, input().split()))
yyy = list(map(int, input().split()))
ab = defaultdict(set)
coordinates = set()
for x in xxx:
if x < yyy[0] or yyy[-1] < x:
continue
i = bisect(yyy, x)
a = x - yyy[i - 1]
b = yyy[i] - x
ab[a].add(b)
coordinates.add(b)
# Bitのindexは1から始まるように作っているが、"0"を取れるようにするため、全体を1ずらす
cor_dict = {b: i for i, b in enumerate(sorted(coordinates), start=2)}
cdg = cor_dict.get
bit = Bit(len(coordinates) + 1)
bit.add(1, 1)
for a in sorted(ab):
bbb = sorted(map(cdg, ab[a]), reverse=True)
for b in bbb:
bit.add(b, bit.sum(b - 1))
print(bit.sum(bit.size))
```
No
| 8,913 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N robots and M exits on a number line. The N + M coordinates of these are all integers and all distinct. For each i (1 \leq i \leq N), the coordinate of the i-th robot from the left is x_i. Also, for each j (1 \leq j \leq M), the coordinate of the j-th exit from the left is y_j.
Snuke can repeatedly perform the following two kinds of operations in any order to move all the robots simultaneously:
* Increment the coordinates of all the robots on the number line by 1.
* Decrement the coordinates of all the robots on the number line by 1.
Each robot will disappear from the number line when its position coincides with that of an exit, going through that exit. Snuke will continue performing operations until all the robots disappear.
When all the robots disappear, how many combinations of exits can be used by the robots? Find the count modulo 10^9 + 7. Here, two combinations of exits are considered different when there is a robot that used different exits in those two combinations.
Constraints
* 1 \leq N, M \leq 10^5
* 1 \leq x_1 < x_2 < ... < x_N \leq 10^9
* 1 \leq y_1 < y_2 < ... < y_M \leq 10^9
* All given coordinates are integers.
* All given coordinates are distinct.
Input
Input is given from Standard Input in the following format:
N M
x_1 x_2 ... x_N
y_1 y_2 ... y_M
Output
Print the number of the combinations of exits that can be used by the robots when all the robots disappear, modulo 10^9 + 7.
Examples
Input
2 2
2 3
1 4
Output
3
Input
3 4
2 5 10
1 3 7 13
Output
8
Input
4 1
1 2 4 5
3
Output
1
Input
4 5
2 5 7 11
1 3 6 9 13
Output
6
Input
10 10
4 13 15 18 19 20 21 22 25 27
1 5 11 12 14 16 23 26 29 30
Output
22
Submitted Solution:
```
import bisect
r_n, e_n = map(int,input().split())
robot = list(map(int,input().split()))
exit = list(map(int,input().split()))
dict = []
for r in robot:
i = bisect.bisect(exit,r)
if i == 0 or i == e_n:
continue
left = exit[i - 1]
right = exit[i]
dict.append([r - left, right - r])
dict.sort()
def check(dict):
if len(dict) <= 1:
if len(dict) == 0:
return 1
else:
return 2
result = 0
left = dict[0][0]
count = 1
while True:
if count == len(dict) or dict[count][0] > left:
break
else:
count += 1
result += check(dict[count:])
right = dict[0][1]
new_dict = []
for d in dict:
if d[1] > right:
new_dict.append(d)
result += check(new_dict)
return result
print(check(dict))
```
No
| 8,914 |
Provide a correct Python 3 solution for this coding contest problem.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
"Correct Solution:
```
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
print(sum(A[::2])-sum(A[1::2]))
```
| 8,915 |
Provide a correct Python 3 solution for this coding contest problem.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
"Correct Solution:
```
n = int(input())
a = [int(n) for n in input().split(" ")]
a.sort()
print(sum(a[::-2]) - sum(a[-2::-2]))
```
| 8,916 |
Provide a correct Python 3 solution for this coding contest problem.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
"Correct Solution:
```
N = int(input())
a = list(map(int, input().split()))
a.sort()
print(abs(sum(a[0::2]) - sum(a[1::2])))
```
| 8,917 |
Provide a correct Python 3 solution for this coding contest problem.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
"Correct Solution:
```
N=input()
A=sorted(map(int,input().split()),reverse=True)
print(sum(A[::2])-sum(A[1::2]))
```
| 8,918 |
Provide a correct Python 3 solution for this coding contest problem.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
"Correct Solution:
```
_ = input()
l = list(map(int,input().split()))
l.sort()
l.reverse()
print(sum(l[::2])-sum(l[1::2]))
```
| 8,919 |
Provide a correct Python 3 solution for this coding contest problem.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
"Correct Solution:
```
n = int(input())
a = sorted(list(map(int, input().split())))
print(abs(sum(a[0::2]) - sum(a[1::2])))
```
| 8,920 |
Provide a correct Python 3 solution for this coding contest problem.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
"Correct Solution:
```
N=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
print(sum(a[::2])-sum(a[1::2]))
```
| 8,921 |
Provide a correct Python 3 solution for this coding contest problem.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
"Correct Solution:
```
N = input()
ai = sorted(map(int, input().split()))[::-1]
print(sum(ai[::2]) - sum(ai[1::2]))
```
| 8,922 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
Submitted Solution:
```
n=int(input())
a=sorted(map(int,input().split()))
print(abs(sum(a[1::2])-sum(a[::2])))
```
Yes
| 8,923 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
Submitted Solution:
```
n = int(input())
a = sorted(list(map(int, input().split())))
print(sum(a[::-2])-sum(a[-2::-2]))
```
Yes
| 8,924 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
Submitted Solution:
```
N = int(input())
c = sorted((map(int,input().split())),reverse = True)
print(sum(c[0::2])-sum(c[1::2]))
```
Yes
| 8,925 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
Submitted Solution:
```
N = int(input())
A = sorted(map(int, input().split()),reverse=True)
print( sum(A[0::2]) - sum(A[1::2]))
```
Yes
| 8,926 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
Submitted Solution:
```
import numpy as np
n = int(input())
a_list = list(map(int, input().split()))
n_alice = 0
n_bob = 0
for i in range(1, n+1):
if i % 2:
n_alice += max(a_list)
del a_list[np.argmax(a_list)]
else:
n_bob += min(a_list)
del a_list[np.argmin(a_list)]
print(n_alice - n_bob)
```
No
| 8,927 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
Submitted Solution:
```
n=int(input())
a=sorted(list(map(int,input().split())))
al=[a[2*i] for i in range(n//2)]
bo=[a[2*i+1] for i in range(n//2)]
print(sum(al)-sum(bo))
```
No
| 8,928 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
Submitted Solution:
```
N = map(int, input())
cards = list(map(int, input().split()))
cards.sort(reverse=True)
sum_A = 0
sum_B = 0
for i in range(N):
if i % 2 == 0:
sum_A += cards[i]
else:
sum_B += cards[i]
print(sum_A - sum_B)
```
No
| 8,929 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have N cards. A number a_i is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
Constraints
* N is an integer between 1 and 100 (inclusive).
* a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N
a_1 a_2 a_3 ... a_N
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Examples
Input
2
3 1
Output
2
Input
3
2 7 4
Output
5
Input
4
20 18 2 18
Output
18
Submitted Solution:
```
n=int(input())
s=list(map(int,input().split()))
s.sort(reverse=True)
print(s)
tokuten=0
for i in range(n):
if i%2==0:
tokuten+=s[i]
else:
tokuten-=s[i]
print(tokuten)
```
No
| 8,930 |
Provide a correct Python 3 solution for this coding contest problem.
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition.
Constraints
* 1 ≤ H, W ≤ 100
* a_{ij} is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}
Output
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise, print `No`.
Examples
Input
3 4
aabb
aabb
aacc
Output
Yes
Input
2 2
aa
bb
Output
No
Input
5 1
t
w
e
e
t
Output
Yes
Input
2 5
abxba
abyba
Output
No
Input
1 1
z
Output
Yes
"Correct Solution:
```
import sys
from collections import Counter
stdin = sys.stdin
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to only numbers
rs = lambda: stdin.readline().rstrip() # ignores trailing space
H, W = rl()
l = []
for _ in range(H):
l.extend(list(rs()))
c = Counter(l)
count = W//2 * H
pair = 0
four = 0
for x in c.values():
four += x // 4
pair += x // 2
f = H // 2 * (W // 2)
if f > four:
print('No')
exit()
pair -= f * 2 #残りのペア
p = W // 2 if H&1 else 0
p += H // 2 if W&1 else 0
if p > pair:
print('No')
exit()
print('Yes')
# 16
```
| 8,931 |
Provide a correct Python 3 solution for this coding contest problem.
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition.
Constraints
* 1 ≤ H, W ≤ 100
* a_{ij} is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}
Output
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise, print `No`.
Examples
Input
3 4
aabb
aabb
aacc
Output
Yes
Input
2 2
aa
bb
Output
No
Input
5 1
t
w
e
e
t
Output
Yes
Input
2 5
abxba
abyba
Output
No
Input
1 1
z
Output
Yes
"Correct Solution:
```
H,W = map(int,input().split())
A = [input() for i in range(H)]
from collections import Counter
ctr = Counter()
for row in A:
ctr.update(row)
if H%2==0 and W%2==0:
print('Yes' if all(v%4==0 for v in ctr.values()) else 'No')
elif H%2 and W%2:
odd = 0
for k,v in ctr.items():
if v%2:
odd += 1
ctr[k] -= 1
if odd != 1:
print('No')
exit()
four = 0
for v in ctr.values():
four += (v//4)*4
want = (H-H%2)*(W-W%2)
print('Yes' if four >= want else 'No')
else:
if any(v%2 for v in ctr.values()):
print('No')
exit()
four = 0
for v in ctr.values():
four += (v//4)*4
want = (H-H%2)*(W-W%2)
print('Yes' if four >= want else 'No')
```
| 8,932 |
Provide a correct Python 3 solution for this coding contest problem.
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition.
Constraints
* 1 ≤ H, W ≤ 100
* a_{ij} is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}
Output
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise, print `No`.
Examples
Input
3 4
aabb
aabb
aacc
Output
Yes
Input
2 2
aa
bb
Output
No
Input
5 1
t
w
e
e
t
Output
Yes
Input
2 5
abxba
abyba
Output
No
Input
1 1
z
Output
Yes
"Correct Solution:
```
import string
string.ascii_lowercase
H,W = map(int,input().split())
A = ''
for i in range(H):
A += input()
#print(A)
S = {}
for s in string.ascii_lowercase:
if A.count(s) > 0:
S[s] = A.count(s)
#print(S)
h1 = H//2
w1 = W//2
h2 = H - h1*2
w2 = W - w1*2
for i in range(h1*w1):
flag = True
for s in S.keys():
if S[s] >= 4:
S[s] -= 4
flag = False
break
if flag:
print('No')
exit()
for i in range(h1*w2+w1*h2):
flag = True
for s in S.keys():
if S[s] >= 2:
S[s] -= 2
flag = False
break
if flag:
print('No')
exit()
print('Yes')
```
| 8,933 |
Provide a correct Python 3 solution for this coding contest problem.
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition.
Constraints
* 1 ≤ H, W ≤ 100
* a_{ij} is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}
Output
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise, print `No`.
Examples
Input
3 4
aabb
aabb
aacc
Output
Yes
Input
2 2
aa
bb
Output
No
Input
5 1
t
w
e
e
t
Output
Yes
Input
2 5
abxba
abyba
Output
No
Input
1 1
z
Output
Yes
"Correct Solution:
```
t,_,s=open(0).read().partition('\n')
h,w=map(int,t.split())
a=b=c=0
if h%2and w%2:
a=h//2*(w//2)
c=1
b=(h*w-a*4-c)//2
elif h%2or w%2:
a=h//2*(w//2)
b=(h*w-a*4)//2
else:
a=h*w//4
l=[]
for i in set(s.replace('\n','')):
l.append(s.count(i))
for i in l:
if i>3:
while i>3and a:
i-=4
a-=1
if i>1:
while i>1and b:
i-=2
b-=1
if i and c:
i-=1
c-=1
if all(not t for t in(a,b,c)):
print('Yes')
else:
print('No')
```
| 8,934 |
Provide a correct Python 3 solution for this coding contest problem.
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition.
Constraints
* 1 ≤ H, W ≤ 100
* a_{ij} is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}
Output
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise, print `No`.
Examples
Input
3 4
aabb
aabb
aacc
Output
Yes
Input
2 2
aa
bb
Output
No
Input
5 1
t
w
e
e
t
Output
Yes
Input
2 5
abxba
abyba
Output
No
Input
1 1
z
Output
Yes
"Correct Solution:
```
h, w = map(int, input().split())
a = {}
for i in range(h):
s = input()
for i in s:
a.setdefault(i, 0)
a[i] += 1
a2 = 0
a1 = 0
for i in a.values():
if i % 2 == 1:
a1 += 1
elif i % 4 == 2:
a2 += 2
if h % 2 == 1:
if w % 2 == 1:
b1 = 1
b2 = h + w - 2
else:
b1 = 0
b2 = w
else:
if w % 2 == 1:
b1 = 0
b2 = h
else:
b1 = 0
b2 = 0
if a1 > b1 or a2 > b2:
print("No")
else:
print("Yes")
```
| 8,935 |
Provide a correct Python 3 solution for this coding contest problem.
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition.
Constraints
* 1 ≤ H, W ≤ 100
* a_{ij} is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}
Output
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise, print `No`.
Examples
Input
3 4
aabb
aabb
aacc
Output
Yes
Input
2 2
aa
bb
Output
No
Input
5 1
t
w
e
e
t
Output
Yes
Input
2 5
abxba
abyba
Output
No
Input
1 1
z
Output
Yes
"Correct Solution:
```
#!/usr/bin/env python3
from collections import Counter
def check():
h, w = map(int, input().split())
c = Counter()
for i in range(h):
c.update(input())
cc = {}
cc[4] = (h >> 1) * (w >> 1)
cc[2] = (h & 1) * (w >> 1) + (w & 1) * (h >> 1)
cc[1] = (h & 1) * (w & 1)
tt = list(c.values())
for v in [4, 2, 1]:
for i in range(len(tt)):
k = min(cc[v], tt[i] // v)
tt[i] -= k * v
cc[v] -= k
return sum(tt) == 0
print(["No", "Yes"][check()])
```
| 8,936 |
Provide a correct Python 3 solution for this coding contest problem.
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition.
Constraints
* 1 ≤ H, W ≤ 100
* a_{ij} is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}
Output
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise, print `No`.
Examples
Input
3 4
aabb
aabb
aacc
Output
Yes
Input
2 2
aa
bb
Output
No
Input
5 1
t
w
e
e
t
Output
Yes
Input
2 5
abxba
abyba
Output
No
Input
1 1
z
Output
Yes
"Correct Solution:
```
h,w = map(int, input().split())
a = [input() for i in range(h)]
cnt = [0] * 26
for i in a:
for j in i:
cnt[ord(j)-ord("a")] += 1
two,no = 0,0
for i in cnt:
if i % 2:
no += 1
elif i % 4:
two += 1
if (h % 2) and (w % 2):
if no <= 1 and two <= h//2 + w//2:
print("Yes")
else:
print("No")
elif (h % 2):
if no == 0 and two <= w//2:
print("Yes")
else:
print("No")
elif (w % 2):
if no == 0 and two <= h//2:
print("Yes")
else:
print("No")
else:
if no == 0 and two == 0:
print("Yes")
else:
print("No")
```
| 8,937 |
Provide a correct Python 3 solution for this coding contest problem.
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition.
Constraints
* 1 ≤ H, W ≤ 100
* a_{ij} is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}
Output
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise, print `No`.
Examples
Input
3 4
aabb
aabb
aacc
Output
Yes
Input
2 2
aa
bb
Output
No
Input
5 1
t
w
e
e
t
Output
Yes
Input
2 5
abxba
abyba
Output
No
Input
1 1
z
Output
Yes
"Correct Solution:
```
import heapq
from collections import defaultdict
def main():
h, w = map(int, input().split())
d = defaultdict(int)
for _ in range(h):
for i in input():
d[i] -= 1
char = list(d.values())
heapq.heapify(char)
hd, hm = divmod(h, 2)
wd, wm = divmod(w, 2)
pair = [-2] * hd + [-1] * hm
pair = [i * 2 for i in pair]*wd + pair*wm
heapq.heapify(pair)
while char:
tmp = heapq.heappop(char) - heapq.heappop(pair)
if tmp > 0:
return "No"
if tmp == 0:
continue
heapq.heappush(char, tmp)
return "Yes"
if __name__ == "__main__":
ans = main()
print(ans)
```
| 8,938 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition.
Constraints
* 1 ≤ H, W ≤ 100
* a_{ij} is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}
Output
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise, print `No`.
Examples
Input
3 4
aabb
aabb
aacc
Output
Yes
Input
2 2
aa
bb
Output
No
Input
5 1
t
w
e
e
t
Output
Yes
Input
2 5
abxba
abyba
Output
No
Input
1 1
z
Output
Yes
Submitted Solution:
```
h,w = map(int, input().split())
b = [0]*26
for i in range(h):
a=input()
for j in range(w):
b[ord(a[j])-97]+=1
c = [0]*4
for i in range(len(b)):
c[b[i] % 4] += 1
d = 1
if h%2==1 and w%2==1:
if c[1]+c[3]!=1:
d = 0
elif c[2]+c[3]>h//2+w//2:
d = 0
elif h%2==1:
if c[1]+c[3]>0:
d = 0
elif c[2]>w//2:
d = 0
elif w%2==1:
if c[1]+c[3]>0:
d = 0
elif c[2]>h//2:
d = 0
else:
if c[1]+c[2]+c[3]>0:
d = 0
print('Yes' if d else 'No')
```
Yes
| 8,939 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition.
Constraints
* 1 ≤ H, W ≤ 100
* a_{ij} is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}
Output
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise, print `No`.
Examples
Input
3 4
aabb
aabb
aacc
Output
Yes
Input
2 2
aa
bb
Output
No
Input
5 1
t
w
e
e
t
Output
Yes
Input
2 5
abxba
abyba
Output
No
Input
1 1
z
Output
Yes
Submitted Solution:
```
from collections import Counter
h, w, *s = open(0).read().split()
h = int(h)
w = int(w)
s = Counter(''.join(s))
odd = 0
two = 0
four = 0
for k, v in s.items():
four += v // 4
v %= 4
if v % 2 == 0:
two += v // 2
else:
odd += 1
if h % 2 == 1 and w % 2 == 1:
if odd == 1 and two <= h // 2 + w // 2:
print('Yes')
else:
print('No')
elif h % 2 == 1:
if odd == 0 and two <= w // 2:
print('Yes')
else:
print('No')
elif w % 2 == 1:
if odd == 0 and two <= h // 2:
print('Yes')
else:
print('No')
else:
if odd == 0 and two == 0:
print('Yes')
else:
print('No')
```
Yes
| 8,940 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition.
Constraints
* 1 ≤ H, W ≤ 100
* a_{ij} is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}
Output
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise, print `No`.
Examples
Input
3 4
aabb
aabb
aacc
Output
Yes
Input
2 2
aa
bb
Output
No
Input
5 1
t
w
e
e
t
Output
Yes
Input
2 5
abxba
abyba
Output
No
Input
1 1
z
Output
Yes
Submitted Solution:
```
H,W=list(map(int,input().split()))
l=[]
for i in range(H):
l.append(list(input()))
from collections import Counter
l=sum(l,[])
l=Counter(l)
one=(H%2)*(W%2)
two=(H%2)*(W//2)+(W%2)*(H//2)
four=(H//2)*(W//2)
for i in l.values():
j=i//4
i=i%4
four-=j
if i==1:
one-=1
elif i==2:
two-=1
elif i==3:
one-=1;two-=1
if set([0]) == set([one,two,four]):
print("Yes")
else:
if four<0:
two+=four*2
four=0
if set([0]) == set([one,two,four]):
print("Yes")
else:
print("No")
```
Yes
| 8,941 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition.
Constraints
* 1 ≤ H, W ≤ 100
* a_{ij} is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}
Output
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise, print `No`.
Examples
Input
3 4
aabb
aabb
aacc
Output
Yes
Input
2 2
aa
bb
Output
No
Input
5 1
t
w
e
e
t
Output
Yes
Input
2 5
abxba
abyba
Output
No
Input
1 1
z
Output
Yes
Submitted Solution:
```
# coding: utf-8
import collections
def main():
H, W = map(int, input().split())
cnt = collections.Counter()
for i in range(H):
for c in input().strip():
cnt[c] += 1
cnts = list(cnt.values())
l = len(cnts)
if H % 2 and W % 2:
for i in range(l):
if cnts[i] % 2 != 0:
cnts[i] -= 1
break
d = 0
if H % 2:
d += (W // 2) * 2
if W % 2:
d += (H // 2) * 2
i = 0
while d > 0 and i < l:
if cnts[i] % 4 != 0:
cnts[i] -= 2
d -= 2
i += 1
for k in cnts:
if k % 4 != 0:
return "No"
return "Yes"
print(main())
```
Yes
| 8,942 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition.
Constraints
* 1 ≤ H, W ≤ 100
* a_{ij} is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}
Output
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise, print `No`.
Examples
Input
3 4
aabb
aabb
aacc
Output
Yes
Input
2 2
aa
bb
Output
No
Input
5 1
t
w
e
e
t
Output
Yes
Input
2 5
abxba
abyba
Output
No
Input
1 1
z
Output
Yes
Submitted Solution:
```
H, W = map(int,input().split())
S = []
for _ in range(H):
S.append(input())
# check palindrome
def main():
oddnum = (H*W) % 2
d = {}
for i in range(H):
for j in range(W):
ch = S[i][j]
if ch in d:
d[ch] += 1
else:
d[ch] = 1
check = sum([val % 2 for key,val in d.items()])
if check != oddnum:
return False
return True
ans = main()
if ans:
print("Yes")
else:
print("No")
```
No
| 8,943 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition.
Constraints
* 1 ≤ H, W ≤ 100
* a_{ij} is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}
Output
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise, print `No`.
Examples
Input
3 4
aabb
aabb
aacc
Output
Yes
Input
2 2
aa
bb
Output
No
Input
5 1
t
w
e
e
t
Output
Yes
Input
2 5
abxba
abyba
Output
No
Input
1 1
z
Output
Yes
Submitted Solution:
```
# import bisect
from collections import Counter, deque # https://note.nkmk.me/python-scipy-connected-components/
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np # Pythonのみ!
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components # Pythonのみ!
# ↑cf. https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
def main():
gg = Counter([])
H, W = map(int, input().split())
grid = [[_ for _ in input()] for _ in range(H)]
for g in grid:
gg.update(Counter(g))
if H % 2 == 0 and W % 2 == 0:
for i in gg.values():
if i % 4 != 0:
return 'No'
return 'Yes'
elif H % 2 == 0 and W % 2 == 1:
cnt = 0
for i in gg.values():
if i % 4 == 2:
cnt += 2
elif i % 4 == 1 or i % 4 == 3:
return 'No'
if cnt <= H and cnt % 2 == 0:
return 'Yes'
else:
return 'No'
elif H % 2 == 1 and W % 2 == 0:
cnt = 0
for i in gg.values():
if i % 4 == 2:
cnt += 2
elif i % 4 == 1 or i % 4 == 3:
return 'No'
if cnt <= W and cnt % 2 == 0:
return 'Yes'
else:
return 'No'
else:
cnt0 = 0
cnt1 = 0
cnt2 = 0
for i in gg.values():
if i % 4 == 1:
cnt1 += 1
elif i % 4 == 2:
cnt2 += 2
elif i % 4 == 3:
cnt2 += 2
cnt1 += 1
else:
cnt0 += 1
if cnt1 == 1 and (cnt2 <= (H + W - 2) and cnt2 % 2 == 0 and cnt0 % 4 == 0):
return 'Yes'
else:
return 'No'
print(main())
resolve()
```
No
| 8,944 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition.
Constraints
* 1 ≤ H, W ≤ 100
* a_{ij} is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}
Output
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise, print `No`.
Examples
Input
3 4
aabb
aabb
aacc
Output
Yes
Input
2 2
aa
bb
Output
No
Input
5 1
t
w
e
e
t
Output
Yes
Input
2 5
abxba
abyba
Output
No
Input
1 1
z
Output
Yes
Submitted Solution:
```
from collections import Counter
h,w=map(int,input().split())
s=""
for i in range(h):
s+=input()
sc=Counter(s)
d=[0,0,0]
for v in sc.values():
d[0]+=(v//4)*4
d[1]+=2 if v%4>=2 else 0
d[2]+=v%2
if w%2==0 and h%2==0:
print("Yes" if d[0]==h*w else "No")
elif (w%2)*(h%2)==1:
print("Yes" if d[1]<=(w-1)+(h-1) and d[2]==1 else "No")
elif w%2==0:
print("Yes" if d[1]<=w and d[2]==0 else "No")
elif h%2==0:
print("Yes" if d[1]<=h and d[2]==0 else "No")
from collections import Counter
h,w=map(int,input().split())
s=""
for i in range(h):
s+=input()
sc=Counter(s)
d=[0,0,0]
for v in sc.values():
d[0]+=(v//4)*4
d[1]+=2 if v%4>=2 else 0
d[2]+=v%2
if w%2==0 and h%2==0:
print("Yes" if d[0]==h*w else "No")
elif (w%2)*(h%2)==1:
print("Yes" if d[1]<=(w-1)+(h-1) and d[2]==1 else "No")
elif w%2==0:
print("Yes" if d[1]<=w and d[2]==0 else "No")
elif h%2==0:
print("Yes" if d[1]<=h and d[2]==0 else "No")
```
No
| 8,945 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition.
Constraints
* 1 ≤ H, W ≤ 100
* a_{ij} is a lowercase English letter.
Input
Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}
Output
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise, print `No`.
Examples
Input
3 4
aabb
aabb
aacc
Output
Yes
Input
2 2
aa
bb
Output
No
Input
5 1
t
w
e
e
t
Output
Yes
Input
2 5
abxba
abyba
Output
No
Input
1 1
z
Output
Yes
Submitted Solution:
```
from collections import Counter
def solve(h, w, a):
c = Counter(list("".join(a)))
d = Counter(list(map(lambda num: num % 4, c.values())))
if (h % 2 == 0) and (w % 2 == 0):
return "Yes" if list(d.keys()) == [4] else "No"
if 3 in d:
return "No"
if (h % 2 == 1) and (w % 2 == 1):
if (1 in d) and (d[1] != 1):
return "No"
if (2 in d) and d[2] > sum(x // 2 for x in [h,w]):
return "No"
else:
if 1 in d:
return "No"
if (2 in d) and d[2] > sum((x % 2 == 0) * (x // 2) for x in [h,w]):
return "No"
return "Yes"
h, w = map(int, input().split())
a = [input() for r in range(h)]
print(solve(h, w, a))
```
No
| 8,946 |
Provide a correct Python 3 solution for this coding contest problem.
There are N towns in Takahashi Kingdom. They are conveniently numbered 1 through N.
Takahashi the king is planning to go on a tour of inspection for M days. He will determine a sequence of towns c, and visit town c_i on the i-th day. That is, on the i-th day, he will travel from his current location to town c_i. If he is already at town c_i, he will stay at that town. His location just before the beginning of the tour is town 1, the capital. The tour ends at town c_M, without getting back to the capital.
The problem is that there is no paved road in this kingdom. He decided to resolve this issue by paving the road himself while traveling. When he travels from town a to town b, there will be a newly paved one-way road from town a to town b.
Since he cares for his people, he wants the following condition to be satisfied after his tour is over: "it is possible to travel from any town to any other town by traversing roads paved by him". How many sequences of towns c satisfy this condition?
Constraints
* 2≦N≦300
* 1≦M≦300
Input
The input is given from Standard Input in the following format:
N M
Output
Print the number of sequences of towns satisfying the condition, modulo 1000000007 (=10^9+7).
Examples
Input
3 3
Output
2
Input
150 300
Output
734286322
Input
300 150
Output
0
"Correct Solution:
```
mod=10**9+7
N,M=map(int,input().split())
dp=[[0 for i in range(N+1)] for j in range(N+1)]
dp[N][N]=1
for i in range(M-1,-1,-1):
for k in range(1,N+1):
for j in range(k,N+1):
if j==k:
if j<N:
dp[j][k]=(j*dp[j][k]+(N-j)*dp[j+1][k])%mod
else:
dp[j][k]=(N*dp[j][k])%mod
else:
if j<N:
dp[j][k]=(k*dp[j][j]+(N-j)*dp[j+1][k]+(j-k)*dp[j][k])%mod
else:
dp[j][k]=(k*dp[j][j]+(N-k)*dp[j][k])%mod
print(dp[1][1])
```
| 8,947 |
Provide a correct Python 3 solution for this coding contest problem.
There are N towns in Takahashi Kingdom. They are conveniently numbered 1 through N.
Takahashi the king is planning to go on a tour of inspection for M days. He will determine a sequence of towns c, and visit town c_i on the i-th day. That is, on the i-th day, he will travel from his current location to town c_i. If he is already at town c_i, he will stay at that town. His location just before the beginning of the tour is town 1, the capital. The tour ends at town c_M, without getting back to the capital.
The problem is that there is no paved road in this kingdom. He decided to resolve this issue by paving the road himself while traveling. When he travels from town a to town b, there will be a newly paved one-way road from town a to town b.
Since he cares for his people, he wants the following condition to be satisfied after his tour is over: "it is possible to travel from any town to any other town by traversing roads paved by him". How many sequences of towns c satisfy this condition?
Constraints
* 2≦N≦300
* 1≦M≦300
Input
The input is given from Standard Input in the following format:
N M
Output
Print the number of sequences of towns satisfying the condition, modulo 1000000007 (=10^9+7).
Examples
Input
3 3
Output
2
Input
150 300
Output
734286322
Input
300 150
Output
0
"Correct Solution:
```
mod = 1000000007
eps = 10**-9
def main():
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
dp = [[0] * N for _ in range(N+1)]
dp[1][0] = 1
for i in range(M):
dp_new = [[0] * N for _ in range(N+1)]
for j in range(N+1):
for k in range(N):
dp_new[j][k] = (dp_new[j][k] + dp[j][k] * k)%mod
if k+1 < N:
dp_new[j][k+1] = (dp_new[j][k+1] + dp[j][k] * (N - j - k))%mod
if j+k <= N:
dp_new[j+k][0] = (dp_new[j+k][0] + dp[j][k] * j)%mod
dp = dp_new
print(dp[N][0])
if __name__ == '__main__':
main()
```
| 8,948 |
Provide a correct Python 3 solution for this coding contest problem.
There are N towns in Takahashi Kingdom. They are conveniently numbered 1 through N.
Takahashi the king is planning to go on a tour of inspection for M days. He will determine a sequence of towns c, and visit town c_i on the i-th day. That is, on the i-th day, he will travel from his current location to town c_i. If he is already at town c_i, he will stay at that town. His location just before the beginning of the tour is town 1, the capital. The tour ends at town c_M, without getting back to the capital.
The problem is that there is no paved road in this kingdom. He decided to resolve this issue by paving the road himself while traveling. When he travels from town a to town b, there will be a newly paved one-way road from town a to town b.
Since he cares for his people, he wants the following condition to be satisfied after his tour is over: "it is possible to travel from any town to any other town by traversing roads paved by him". How many sequences of towns c satisfy this condition?
Constraints
* 2≦N≦300
* 1≦M≦300
Input
The input is given from Standard Input in the following format:
N M
Output
Print the number of sequences of towns satisfying the condition, modulo 1000000007 (=10^9+7).
Examples
Input
3 3
Output
2
Input
150 300
Output
734286322
Input
300 150
Output
0
"Correct Solution:
```
n,m = map(int,input().split())
mod = 10**9+7
dp = [[[0 for i in range(j+1)] for j in range(n+1)] for k in range(m+1)]
dp[0][1][1] = 1
for i in range(m):
for j in range(n+1):
for k in range(j+1):
x = dp[i][j][k]
if j < n:
dp[i+1][j+1][k] += x*(n-j)
dp[i+1][j+1][k] %= mod
dp[i+1][j][j] = (dp[i+1][j][j]+x*k)%mod
dp[i+1][j][k] = (dp[i+1][j][k]+x*(j-k))%mod
print(dp[m][n][n])
```
| 8,949 |
Provide a correct Python 3 solution for this coding contest problem.
There are N towns in Takahashi Kingdom. They are conveniently numbered 1 through N.
Takahashi the king is planning to go on a tour of inspection for M days. He will determine a sequence of towns c, and visit town c_i on the i-th day. That is, on the i-th day, he will travel from his current location to town c_i. If he is already at town c_i, he will stay at that town. His location just before the beginning of the tour is town 1, the capital. The tour ends at town c_M, without getting back to the capital.
The problem is that there is no paved road in this kingdom. He decided to resolve this issue by paving the road himself while traveling. When he travels from town a to town b, there will be a newly paved one-way road from town a to town b.
Since he cares for his people, he wants the following condition to be satisfied after his tour is over: "it is possible to travel from any town to any other town by traversing roads paved by him". How many sequences of towns c satisfy this condition?
Constraints
* 2≦N≦300
* 1≦M≦300
Input
The input is given from Standard Input in the following format:
N M
Output
Print the number of sequences of towns satisfying the condition, modulo 1000000007 (=10^9+7).
Examples
Input
3 3
Output
2
Input
150 300
Output
734286322
Input
300 150
Output
0
"Correct Solution:
```
import sys
readline = sys.stdin.readline
N, M = map(int, readline().split())
MOD = 10**9+7
dpscc = [[0]*(N+1) for _ in range(N+1)]
dpus = [[0]*(N+1) for _ in range(N+1)]
dpscc[1][0] = 1
for m in range(M):
dpscc2 = [[0]*(N+1) for _ in range(N+1)]
dpus2 = [[0]*(N+1) for _ in range(N+1)]
for i in range(1, N+1):
for j in range(N+1-i):
kscc = dpscc[i][j]
kus = dpus[i][j]
dpscc2[i][j] = (dpscc2[i][j] + i*kscc) % MOD
dpus2[i][j] = (dpus2[i][j] + j*(kus+kscc)) % MOD
dpscc2[i+j][0] = (dpscc2[i+j][0] + i*kus) % MOD
if N-i-j:
dpus2[i][j+1] = (dpus2[i][j+1] + (N-i-j)*(kus+kscc)) % MOD
dpscc = [d[:] for d in dpscc2]
dpus = [d[:] for d in dpus2]
print(dpscc[N][0])
```
| 8,950 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N towns in Takahashi Kingdom. They are conveniently numbered 1 through N.
Takahashi the king is planning to go on a tour of inspection for M days. He will determine a sequence of towns c, and visit town c_i on the i-th day. That is, on the i-th day, he will travel from his current location to town c_i. If he is already at town c_i, he will stay at that town. His location just before the beginning of the tour is town 1, the capital. The tour ends at town c_M, without getting back to the capital.
The problem is that there is no paved road in this kingdom. He decided to resolve this issue by paving the road himself while traveling. When he travels from town a to town b, there will be a newly paved one-way road from town a to town b.
Since he cares for his people, he wants the following condition to be satisfied after his tour is over: "it is possible to travel from any town to any other town by traversing roads paved by him". How many sequences of towns c satisfy this condition?
Constraints
* 2≦N≦300
* 1≦M≦300
Input
The input is given from Standard Input in the following format:
N M
Output
Print the number of sequences of towns satisfying the condition, modulo 1000000007 (=10^9+7).
Examples
Input
3 3
Output
2
Input
150 300
Output
734286322
Input
300 150
Output
0
Submitted Solution:
```
mod=10**9+7
N,M=map(int,input().split())
dp=[[[0 for i in range(N+1)] for j in range(N+1)] for k in range(M+1)]
dp[M][N][N]=1
for i in range(M-1,-1,-1):
for k in range(1,N+1):
for j in range(k,N+1):
if j==k:
if j<N:
dp[i][j][k]=(j*dp[i+1][j][k]+(N-j)*dp[i+1][j+1][k])%mod
else:
dp[i][j][k]=(N*dp[i+1][j][k])%mod
else:
if j<N:
dp[i][j][k]=(k*dp[i+1][j][j]+(N-j)*dp[i+1][j+1][k]+(j-k)*dp[i+1][j][k])%mod
else:
dp[i][j][k]=(k*dp[i+1][j][j]+(N-k)*dp[i+1][j][k])%mod
print(dp[0][1][1])
```
No
| 8,951 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N towns in Takahashi Kingdom. They are conveniently numbered 1 through N.
Takahashi the king is planning to go on a tour of inspection for M days. He will determine a sequence of towns c, and visit town c_i on the i-th day. That is, on the i-th day, he will travel from his current location to town c_i. If he is already at town c_i, he will stay at that town. His location just before the beginning of the tour is town 1, the capital. The tour ends at town c_M, without getting back to the capital.
The problem is that there is no paved road in this kingdom. He decided to resolve this issue by paving the road himself while traveling. When he travels from town a to town b, there will be a newly paved one-way road from town a to town b.
Since he cares for his people, he wants the following condition to be satisfied after his tour is over: "it is possible to travel from any town to any other town by traversing roads paved by him". How many sequences of towns c satisfy this condition?
Constraints
* 2≦N≦300
* 1≦M≦300
Input
The input is given from Standard Input in the following format:
N M
Output
Print the number of sequences of towns satisfying the condition, modulo 1000000007 (=10^9+7).
Examples
Input
3 3
Output
2
Input
150 300
Output
734286322
Input
300 150
Output
0
Submitted Solution:
```
mod = 1000000007
eps = 10**-9
def main():
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
dp = [[[0] * N for _ in range(N+1)] for _ in range(M+1)]
dp[0][1][0] = 1
for i in range(M):
for j in range(N+1):
for k in range(N):
dp[i+1][j][k] = (dp[i+1][j][k] + dp[i][j][k] * k)%mod
if k+1 < N:
dp[i+1][j][k+1] = (dp[i+1][j][k+1] + dp[i][j][k] * (N - j - k))%mod
if j+k <= N:
dp[i+1][j+k][0] = (dp[i+1][j+k][0] + dp[i][j][k] * j)%mod
print(dp[-1][N][0])
if __name__ == '__main__':
main()
```
No
| 8,952 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N towns in Takahashi Kingdom. They are conveniently numbered 1 through N.
Takahashi the king is planning to go on a tour of inspection for M days. He will determine a sequence of towns c, and visit town c_i on the i-th day. That is, on the i-th day, he will travel from his current location to town c_i. If he is already at town c_i, he will stay at that town. His location just before the beginning of the tour is town 1, the capital. The tour ends at town c_M, without getting back to the capital.
The problem is that there is no paved road in this kingdom. He decided to resolve this issue by paving the road himself while traveling. When he travels from town a to town b, there will be a newly paved one-way road from town a to town b.
Since he cares for his people, he wants the following condition to be satisfied after his tour is over: "it is possible to travel from any town to any other town by traversing roads paved by him". How many sequences of towns c satisfy this condition?
Constraints
* 2≦N≦300
* 1≦M≦300
Input
The input is given from Standard Input in the following format:
N M
Output
Print the number of sequences of towns satisfying the condition, modulo 1000000007 (=10^9+7).
Examples
Input
3 3
Output
2
Input
150 300
Output
734286322
Input
300 150
Output
0
Submitted Solution:
```
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 10**9+7
N,M = map(int,read().split())
"""
・既に強連結成分として確定している町の個数
・訪問済だけれど強連結成分には入っていない町の個数
に対する場合の数を持ってdp
"""
dp = np.zeros((N+1,N+1),np.int64)
dp[1,0] = 1
rng = np.arange(N+1,dtype=np.int64)
for _ in range(M):
prev = dp
dp = np.zeros_like(prev)
# 強連結成分から出発する場合。
dp[:,0] += prev[:,0] * rng
dp[:,1] += prev[:,0] * rng[::-1]
# 未確定部分から
for m in range(1,N):
# 強連結成分に戻る
dp[m:,0] += prev[:-m,m] * rng[:-m]
# 未確定部分のまま
dp[:,m] += prev[:,m] * m
# 未確定部分を広げる
dp[:,m+1] += prev[:,m] * (N-m-rng)
dp %= MOD
answer = dp[N,0]
print(answer)
```
No
| 8,953 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N towns in Takahashi Kingdom. They are conveniently numbered 1 through N.
Takahashi the king is planning to go on a tour of inspection for M days. He will determine a sequence of towns c, and visit town c_i on the i-th day. That is, on the i-th day, he will travel from his current location to town c_i. If he is already at town c_i, he will stay at that town. His location just before the beginning of the tour is town 1, the capital. The tour ends at town c_M, without getting back to the capital.
The problem is that there is no paved road in this kingdom. He decided to resolve this issue by paving the road himself while traveling. When he travels from town a to town b, there will be a newly paved one-way road from town a to town b.
Since he cares for his people, he wants the following condition to be satisfied after his tour is over: "it is possible to travel from any town to any other town by traversing roads paved by him". How many sequences of towns c satisfy this condition?
Constraints
* 2≦N≦300
* 1≦M≦300
Input
The input is given from Standard Input in the following format:
N M
Output
Print the number of sequences of towns satisfying the condition, modulo 1000000007 (=10^9+7).
Examples
Input
3 3
Output
2
Input
150 300
Output
734286322
Input
300 150
Output
0
Submitted Solution:
```
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 10**9+7
N,M = map(int,read().split())
"""
・既に強連結成分として確定している町の個数
・訪問済だけれど強連結成分には入っていない町の個数
に対する場合の数を持ってdp
"""
dp = np.zeros((N+1,N+1),np.int64)
dp[1,0] = 1
rng = np.arange(N+1,dtype=np.int64)
for _ in range(M):
prev = dp
dp = np.zeros_like(prev)
# 強連結成分から出発する場合。
dp[:,0] += prev[:,0] * rng
dp[:,1] += prev[:,0] * rng[::-1]
# 未確定部分から
for m in range(1,N):
# 強連結成分に戻る
dp[m:,0] += prev[:-m,m] * rng[:-m]
# 未確定部分のまま
dp[:,m] += prev[:,m] * m
# 未確定部分を広げる
dp[:N-m,m+1] += prev[:N-m,m] * (N-m-rng[:N-m])
dp %= MOD
answer = dp[N,0]
print(answer)
```
No
| 8,954 |
Provide a correct Python 3 solution for this coding contest problem.
When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer".
His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper.
For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town.
You can assume that d ≤ 100 and -180 ≤ t ≤ 180.
Input
A sequence of pairs of integers d and t which end with "0,0".
Output
Print the integer portion of x and y in a line respectively.
Example
Input
56,65
97,54
64,-4
55,76
42,-27
43,80
87,-86
55,-6
89,34
95,5
0,0
Output
171
-302
"Correct Solution:
```
import math
Tre = []
num = 0
while True:
li = list(map(int,input().split(",")))
if li == [0,0]:
break
Tre.append(li)
num += 1
x,y = 0,0
deg = 90
for i in range(num):
x,y = x + Tre[i][0]*math.cos(math.pi*deg/180),y + Tre[i][0]*math.sin(math.pi*deg/180)
deg = deg - Tre[i][1]
print(int(x))
print(int(y))
```
| 8,955 |
Provide a correct Python 3 solution for this coding contest problem.
When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer".
His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper.
For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town.
You can assume that d ≤ 100 and -180 ≤ t ≤ 180.
Input
A sequence of pairs of integers d and t which end with "0,0".
Output
Print the integer portion of x and y in a line respectively.
Example
Input
56,65
97,54
64,-4
55,76
42,-27
43,80
87,-86
55,-6
89,34
95,5
0,0
Output
171
-302
"Correct Solution:
```
# -*- coding: utf-8 -*-
import sys
import os
from math import sin, cos
import math
def rotate_vector(v, rad):
x = v[0]
y = v[1]
new_x = cos(rad) * x - sin(rad) * y
new_y = sin(rad) * x + cos(rad) * y
return (new_x, new_y)
pos = [0, 0]
dir = [0, 1]
for s in sys.stdin:
length, degree = map(int, s.split(','))
# move
pos[0] += dir[0] * length
pos[1] += dir[1] * length
# rotate
rad = math.radians(degree)
rad *= -1
# rotated dir
dir = rotate_vector(dir, rad)
print(int(pos[0]))
print(int(pos[1]))
```
| 8,956 |
Provide a correct Python 3 solution for this coding contest problem.
When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer".
His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper.
For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town.
You can assume that d ≤ 100 and -180 ≤ t ≤ 180.
Input
A sequence of pairs of integers d and t which end with "0,0".
Output
Print the integer portion of x and y in a line respectively.
Example
Input
56,65
97,54
64,-4
55,76
42,-27
43,80
87,-86
55,-6
89,34
95,5
0,0
Output
171
-302
"Correct Solution:
```
import sys
import math
def sign(x):
if x>=0:
return 1.0
else:
return -1.0
pi = math.pi
deg = 0.0
pos_x = 0.0
pos_y = 0.0
lines = sys.stdin.readlines()
for line in lines:
line = line.split(",")
inp = []
for i in line:
inp.append(int(i))
if inp[0]>0:
dist = inp[0]
pos_x += dist*math.sin(deg/180*pi)
pos_y += dist*math.cos(deg/180*pi)
deg += inp[1]
else:
print ("%d" % (sign(pos_x)*math.floor(math.fabs(pos_x))))
print ("%d" % (sign(pos_y)*math.floor(math.fabs(pos_y))))
```
| 8,957 |
Provide a correct Python 3 solution for this coding contest problem.
When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer".
His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper.
For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town.
You can assume that d ≤ 100 and -180 ≤ t ≤ 180.
Input
A sequence of pairs of integers d and t which end with "0,0".
Output
Print the integer portion of x and y in a line respectively.
Example
Input
56,65
97,54
64,-4
55,76
42,-27
43,80
87,-86
55,-6
89,34
95,5
0,0
Output
171
-302
"Correct Solution:
```
from math import sin,cos,pi
x = 0
y = 0
ca = 90
while True:
d, a = list(map(int, input().split(",")))
if d or a:
x += d*cos(ca*pi/180)
y += d*sin(ca*pi/180)
ca -= a
else:
break
print(int(x))
print(int(y))
```
| 8,958 |
Provide a correct Python 3 solution for this coding contest problem.
When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer".
His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper.
For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town.
You can assume that d ≤ 100 and -180 ≤ t ≤ 180.
Input
A sequence of pairs of integers d and t which end with "0,0".
Output
Print the integer portion of x and y in a line respectively.
Example
Input
56,65
97,54
64,-4
55,76
42,-27
43,80
87,-86
55,-6
89,34
95,5
0,0
Output
171
-302
"Correct Solution:
```
import math
import cmath
coordinates = 0
ang = 90
while True:
line = list(map(float, input().split(",")))
if line[0] == 0 and line[1] == 0:
break
coordinates += cmath.rect(line[0], math.radians(ang))
ang -= line[1]
print(int(coordinates.real))
print(int(coordinates.imag))
```
| 8,959 |
Provide a correct Python 3 solution for this coding contest problem.
When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer".
His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper.
For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town.
You can assume that d ≤ 100 and -180 ≤ t ≤ 180.
Input
A sequence of pairs of integers d and t which end with "0,0".
Output
Print the integer portion of x and y in a line respectively.
Example
Input
56,65
97,54
64,-4
55,76
42,-27
43,80
87,-86
55,-6
89,34
95,5
0,0
Output
171
-302
"Correct Solution:
```
import cmath
import math
z = 0 + 0j
theta = 90
while True:
r, phi = map(int, input().split(","))
if r == phi == 0:
break
z += cmath.rect(r, math.radians(theta))
theta = (theta - phi) % 360
print(math.trunc(z.real))
print(math.trunc(z.imag))
```
| 8,960 |
Provide a correct Python 3 solution for this coding contest problem.
When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer".
His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper.
For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town.
You can assume that d ≤ 100 and -180 ≤ t ≤ 180.
Input
A sequence of pairs of integers d and t which end with "0,0".
Output
Print the integer portion of x and y in a line respectively.
Example
Input
56,65
97,54
64,-4
55,76
42,-27
43,80
87,-86
55,-6
89,34
95,5
0,0
Output
171
-302
"Correct Solution:
```
# AOJ 0016 Treasure Hunt
# Python3 2018.6.15 bal4u
import math
PI = 3.1415926535897932384626433832795
M = 0.01745329251994329576923690768489
EPS = 1e-8
r, q, f = 0, 90*M, 0
while True:
d, a = list(map(int, input().split(',')))
if d == 0 and a == 0: break
r2 = math.sqrt(r*r + d*d - 2*r*d*math.cos(PI - math.fabs(f)))
if math.fabs(r) < EPS or math.fabs(r2) < EPS:
q2 = q - f
f = a * M
else:
t = math.acos((r*r + r2*r2 - d*d) / (2 * r*r2));
if f >= 0:
q2 = q - t
f += a*M - t
else:
q2 = q + t
f += a*M + t
r = r2
q = q2
print(int(r * math.cos(q)), int(r * math.sin(q)), sep='\n')
```
| 8,961 |
Provide a correct Python 3 solution for this coding contest problem.
When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer".
His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper.
For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town.
You can assume that d ≤ 100 and -180 ≤ t ≤ 180.
Input
A sequence of pairs of integers d and t which end with "0,0".
Output
Print the integer portion of x and y in a line respectively.
Example
Input
56,65
97,54
64,-4
55,76
42,-27
43,80
87,-86
55,-6
89,34
95,5
0,0
Output
171
-302
"Correct Solution:
```
from math import cos, sin, pi
treasure_x, treasure_y = 0, 0
angle = pi / 2
while True:
d, a = map(int, input().split(','))
if d == 0 and a == 0:
break
treasure_x += d * cos(angle)
treasure_y += d * sin(angle)
angle -= a * pi / 180
print(int(treasure_x))
print(int(treasure_y))
```
| 8,962 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer".
His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper.
For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town.
You can assume that d ≤ 100 and -180 ≤ t ≤ 180.
Input
A sequence of pairs of integers d and t which end with "0,0".
Output
Print the integer portion of x and y in a line respectively.
Example
Input
56,65
97,54
64,-4
55,76
42,-27
43,80
87,-86
55,-6
89,34
95,5
0,0
Output
171
-302
Submitted Solution:
```
import sys
import math
x,y,t = 0,0,0
for s in sys.stdin:
a,b = map(int,s.split(','))
if a==0 and b==0:
break
x += a*math.sin(math.radians(t))
y += a*math.cos(math.radians(t))
t += b
print(int(x))
print(int(y))
```
Yes
| 8,963 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer".
His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper.
For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town.
You can assume that d ≤ 100 and -180 ≤ t ≤ 180.
Input
A sequence of pairs of integers d and t which end with "0,0".
Output
Print the integer portion of x and y in a line respectively.
Example
Input
56,65
97,54
64,-4
55,76
42,-27
43,80
87,-86
55,-6
89,34
95,5
0,0
Output
171
-302
Submitted Solution:
```
# Treasure Hunt
import math
x,y,pd = 0,0,-90
r,d = map(int, input().split(','))
while not (r == 0 and d == 0):
x += r * math.cos(math.radians(-pd))
y += r * math.sin(math.radians(-pd))
pd += d
r,d = map(int, input().split(','))
print(int(x))
print(int(y))
```
Yes
| 8,964 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer".
His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper.
For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town.
You can assume that d ≤ 100 and -180 ≤ t ≤ 180.
Input
A sequence of pairs of integers d and t which end with "0,0".
Output
Print the integer portion of x and y in a line respectively.
Example
Input
56,65
97,54
64,-4
55,76
42,-27
43,80
87,-86
55,-6
89,34
95,5
0,0
Output
171
-302
Submitted Solution:
```
from math import radians, cos, sin, ceil, floor
g = 90
x = y = 0
while 1:
d, a = map(int, input().split(","))
if d == 0:
break
t = radians(g)
x += cos(t) * d
y += sin(t) * d
g -= a
x = floor(x) if x > 0 else ceil(x)
y = floor(y) if y > 0 else ceil(y)
print("%d" % x)
print("%d" % y)
```
Yes
| 8,965 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer".
His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper.
For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town.
You can assume that d ≤ 100 and -180 ≤ t ≤ 180.
Input
A sequence of pairs of integers d and t which end with "0,0".
Output
Print the integer portion of x and y in a line respectively.
Example
Input
56,65
97,54
64,-4
55,76
42,-27
43,80
87,-86
55,-6
89,34
95,5
0,0
Output
171
-302
Submitted Solution:
```
import math
def main():
p = [0, 0]
x = math.radians(90)
while True:
d, angle = map(int, input().split(","))
if d == 0 and angle == 0:
break
p[0] += math.cos(x) * d
p[1] += math.sin(x) * d
x -= math.radians(angle)
for i in (0,1):
p[i] = int(p[i])
print(*p, sep="\n")
if __name__ == "__main__":
main()
```
Yes
| 8,966 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer".
His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper.
For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town.
You can assume that d ≤ 100 and -180 ≤ t ≤ 180.
Input
A sequence of pairs of integers d and t which end with "0,0".
Output
Print the integer portion of x and y in a line respectively.
Example
Input
56,65
97,54
64,-4
55,76
42,-27
43,80
87,-86
55,-6
89,34
95,5
0,0
Output
171
-302
Submitted Solution:
```
from math import *
x = 0
y = 0
D = []
A = []
sum_a = -90
while True:
d, a = map(int, input().split(","))
if a == 0 and d == 0:
break
else:
D.append(d)
A.append(a)
for i in range(len(A)):
x += D[i] * cos(-sum_a * pi / 180)
y += D[i] * sin(-sum_a * pi / 180)
sum_a += A[i]
print(floor(x))
print(floor(y))
```
No
| 8,967 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer".
His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper.
For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town.
You can assume that d ≤ 100 and -180 ≤ t ≤ 180.
Input
A sequence of pairs of integers d and t which end with "0,0".
Output
Print the integer portion of x and y in a line respectively.
Example
Input
56,65
97,54
64,-4
55,76
42,-27
43,80
87,-86
55,-6
89,34
95,5
0,0
Output
171
-302
Submitted Solution:
```
from math import radians
from cmath import rect
z = 0
deg = 90
while True:
r, d = map(int, input().split(','))
if r == d == 0: break
z += rect(r, radians(deg))
deg -= d
print(int(z.real), int(z.imag))
```
No
| 8,968 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer".
His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper.
For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town.
You can assume that d ≤ 100 and -180 ≤ t ≤ 180.
Input
A sequence of pairs of integers d and t which end with "0,0".
Output
Print the integer portion of x and y in a line respectively.
Example
Input
56,65
97,54
64,-4
55,76
42,-27
43,80
87,-86
55,-6
89,34
95,5
0,0
Output
171
-302
Submitted Solution:
```
import math
x = y = 0
h = math.radians(90)
while True:
d, t = map(int, input().split(","))
if d == 0 and t == 0:
break
x += d * math.cos(h)
y += d * math.sin(h)
h -= math.radians(t)
print("{} {}".format(int(math.modf(x)[1]), int(math.modf(y)[1])))
```
No
| 8,969 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
When a boy was cleaning up after his grand father passing, he found an old paper:
<image>
In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer".
His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper.
For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town.
You can assume that d ≤ 100 and -180 ≤ t ≤ 180.
Input
A sequence of pairs of integers d and t which end with "0,0".
Output
Print the integer portion of x and y in a line respectively.
Example
Input
56,65
97,54
64,-4
55,76
42,-27
43,80
87,-86
55,-6
89,34
95,5
0,0
Output
171
-302
Submitted Solution:
```
import math
x, y, r = 0, 0, 90
while True:
d, t = map(int, input().split(","))
if d == t == 0:
break
x += r * math.cos(math.radians(r))
y += r * math.sin(math.radians(r))
r -= t
print(int(x))
print(int(y))
```
No
| 8,970 |
Provide a correct Python 3 solution for this coding contest problem.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01
"Correct Solution:
```
while 1:
try:
n = int(input())
except:
break
if n % 39 == 0:
ans = 39
else:
ans = n % 39
print("3C" + str(ans).zfill(2))
```
| 8,971 |
Provide a correct Python 3 solution for this coding contest problem.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01
"Correct Solution:
```
try:
while True:
ame = int(input())
num1 = ame % 39
if num1 == 0:
num1 = 39
if num1 < 10:
print("3C0" + str(num1))
else:
print("3C" + str(num1))
except EOFError as e:
num = 0
```
| 8,972 |
Provide a correct Python 3 solution for this coding contest problem.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01
"Correct Solution:
```
while True:
try:
a = int(input())
except:break
if a%39 == 0:
print("3C39")
else:
b = a // 39
c = a - 39 * b
if c < 10:
print("3C0",c,sep='')
else:
print("3C",c,sep='')
```
| 8,973 |
Provide a correct Python 3 solution for this coding contest problem.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01
"Correct Solution:
```
while True:
try:
a = int(input())
except:
break
a = str(a%39)
if a == "0":
a = "39"
elif len(a) == 1:
a = "0"+a
print("3C"+a)
```
| 8,974 |
Provide a correct Python 3 solution for this coding contest problem.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01
"Correct Solution:
```
while True:
try:
n = int(input())
except:
break
if n % 39 == 0:
ans = 39
else:
ans = n % 39
print("3C" + str(ans).zfill(2))
```
| 8,975 |
Provide a correct Python 3 solution for this coding contest problem.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01
"Correct Solution:
```
while True:
try:
n = int(input().strip())
m = n % 39
if m==0:
s = "39"
else:
s = "%02d" % m
print("3C" + s)
except EOFError:
break
```
| 8,976 |
Provide a correct Python 3 solution for this coding contest problem.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01
"Correct Solution:
```
while True:
try:
n = int(input())
except:
break
ans = n % 39
if ans == 0:
ans = "39"
else:
ans = "{0:02d}".format(ans)
print("3C"+ans)
```
| 8,977 |
Provide a correct Python 3 solution for this coding contest problem.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01
"Correct Solution:
```
# AOJ 0148 Candy and Class Flag
# Python3 2018.6.18 bal4u
while True:
try: a = (int(input())-1) % 39 + 1
except: break
print("3C", format(a, "02d"), sep='')
```
| 8,978 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0148
"""
import sys
from sys import stdin
input = stdin.readline
def main(args):
for line in sys.stdin:
candy = int(line)
hit = candy % 39
if hit == 0:
hit = 39
print('3C{:02d}'.format(hit))
if __name__ == '__main__':
main(sys.argv[1:])
```
Yes
| 8,979 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01
Submitted Solution:
```
import sys
for i in sys.stdin:
p = int(i) % 39
if p == 0:
print("3C39")
elif p < 10:
print("3C0%d" %(p))
else:
print("3C%d" %(p))
```
Yes
| 8,980 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01
Submitted Solution:
```
while True:
try:
n = int(input())
num = n % 39
if num == 0:
num = 39
if num < 10:
num = "0" + str(num)
print("3" + "C" + str(num))
except EOFError:
break
```
Yes
| 8,981 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01
Submitted Solution:
```
def get_input():
while True:
try:
yield ''.join(input())
except EOFError:
break
N = list(get_input())
for l in range(len(N)):
n = int(N[l])
print("3C", end="")
ans = n % 39
if ans == 0:
print(39)
elif ans < 10:
print("0", end="")
print(ans)
else:
print(ans)
```
Yes
| 8,982 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day.
* Each student will take one candy in the order of student number.
* If candy remains after one round, continue to take candy in order from the person with the first student number.
* The person who picks up the last candy will be the student who keeps the "class flag".
There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag".
Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag".
Input
Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≤ a ≤ 10000) representing the number of candies is given on one line. Process until the end of input (EOF).
The number of datasets does not exceed 20.
Output
For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line.
Example
Input
50
5576
5577
5578
Output
3C11
3C38
3C39
3C01
Submitted Solution:
```
while True:
try:
a = int(input())
except:
break
tmp = a - (a // 39) * 39
print("3C{:02d}".format(39 if tmp == 39 else tmp))
```
No
| 8,983 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today is the open campus of Z University. Every year during the lunch break on this day, many high school students line up for the school cafeteria. Therefore, the secretariat of Z University decided to predict the maximum distance of the procession. As a result of the preliminary survey, we know the following.
* The matrix is lined with N people, each numbered from 1 to N.
* For each pair of C high school students (ai, bi), there are two types of restrictions:
* The first constraint is on the order and is one of the following:
ai must be ahead of bi or in the same position
ai must line up after or in the same position as bi
ai can be before, in the same position, or after bi
* The second constraint is on distance and is one of the following:
ai and bi must be at least di meters apart
ai and bi must line up within di meters
We also know that multiple people can be lined up at the same distance from the beginning, and that the number 1 person is always at the beginning of the procession.
Create a program to find the distance when the matrix that satisfies all the given C constraints is arranged so that the distance from the beginning to the end is the maximum. However, output inf if it can be separated indefinitely, and -1 if it is not possible to arrange in a way that satisfies the constraint.
input
The input is given in the following format.
N C
constraint1
constraint2
::
constraintC
The number of high school students in the queue on the first line N (2 ≤ N ≤ 100) and the number of constraints C (0 ≤ C ≤ 200) are given. Each constraint constrainti is given in the following C line in the following format.
aioibisidi
The constraint does not include spaces. The meanings of ai, oi, bi, si and di are shown below.
* ai and bi (1 ≤ ai, bi ≤ N and ai ≠ bi) are high school student numbers, and di is an integer representing the distance (0 ≤ d ≤ 10000).
* oi is a string of <=,> =, * that specifies the order constraint, and if <=, "ai must precede bi or be in the same position",> = In the case of, "ai must be after bi or in the same position", and in the case of *, it means that "ai can be before, in the same position, or after bi". However, no more than 7 constraints with oi as * can be given.
* si is the + or-character that specifies the distance constraint, for + "ai and bi must be at least di meters apart", for-"ai and bi must be within di meters" It means that.
However, it is assumed that multiple constraints are not given to a pair.
output
The distance from the beginning to the end is output on one line.
Example
Input
3 2
1
Output
3
Submitted Solution:
```
import sys
import re
import math
import itertools
def create_edge(fr,to,weight,si):
edges = []
if si == '-':
edges.append((fr,to,weight))
edges.append((to,fr,0))
else:
edges.append((to,fr,-weight))
return edges
#????????????????????´???-1?????????
def bellmanford(edges, length):
start_vertex = 0
distance = [float('inf')] * length
distance[start_vertex] = 0
for i in range(length):
for fr, to, weight in edges:
if distance[to] > distance[fr] + weight:
distance[to] = distance[fr] + weight
for fr, to, weight in edges:
if distance[to] > distance[fr] + weight:
return -1
return max(distance)
f = sys.stdin
n,c = map(int, f.readline().split())
p = re.compile('(\d+)(\D+)(\d+)(\D+)(\d+)')
constraints = [p.match(line).groups() for line in f]
fixed_edges = []
floating_edges = []
for ai, oi, bi, si, di in constraints:
fr,to,weight = int(ai) - 1,int(bi) - 1,int(di)
if oi == '*':
floating_edges.append((create_edge(fr,to,weight,si),create_edge(to,fr,weight,si)))
else:
if oi == '>=':
fr, to = to, fr
fixed_edges.extend(create_edge(fr,to,weight,si))
distance = []
for edges in itertools.product(*floating_edges):
distance.append(bellmanford(fixed_edges + [y for x in edges for y in x], n))
print(max(distance))
```
No
| 8,984 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today is the open campus of Z University. Every year during the lunch break on this day, many high school students line up for the school cafeteria. Therefore, the secretariat of Z University decided to predict the maximum distance of the procession. As a result of the preliminary survey, we know the following.
* The matrix is lined with N people, each numbered from 1 to N.
* For each pair of C high school students (ai, bi), there are two types of restrictions:
* The first constraint is on the order and is one of the following:
ai must be ahead of bi or in the same position
ai must line up after or in the same position as bi
ai can be before, in the same position, or after bi
* The second constraint is on distance and is one of the following:
ai and bi must be at least di meters apart
ai and bi must line up within di meters
We also know that multiple people can be lined up at the same distance from the beginning, and that the number 1 person is always at the beginning of the procession.
Create a program to find the distance when the matrix that satisfies all the given C constraints is arranged so that the distance from the beginning to the end is the maximum. However, output inf if it can be separated indefinitely, and -1 if it is not possible to arrange in a way that satisfies the constraint.
input
The input is given in the following format.
N C
constraint1
constraint2
::
constraintC
The number of high school students in the queue on the first line N (2 ≤ N ≤ 100) and the number of constraints C (0 ≤ C ≤ 200) are given. Each constraint constrainti is given in the following C line in the following format.
aioibisidi
The constraint does not include spaces. The meanings of ai, oi, bi, si and di are shown below.
* ai and bi (1 ≤ ai, bi ≤ N and ai ≠ bi) are high school student numbers, and di is an integer representing the distance (0 ≤ d ≤ 10000).
* oi is a string of <=,> =, * that specifies the order constraint, and if <=, "ai must precede bi or be in the same position",> = In the case of, "ai must be after bi or in the same position", and in the case of *, it means that "ai can be before, in the same position, or after bi". However, no more than 7 constraints with oi as * can be given.
* si is the + or-character that specifies the distance constraint, for + "ai and bi must be at least di meters apart", for-"ai and bi must be within di meters" It means that.
However, it is assumed that multiple constraints are not given to a pair.
output
The distance from the beginning to the end is output on one line.
Example
Input
3 2
1
Output
3
Submitted Solution:
```
import sys
import re
import math
import itertools
f = sys.stdin
n,c = map(int, f.readline().split())
p = re.compile('(\d+)(\D+)(\d+)(\D+)(\d+)')
constraints = [p.match(line).groups() for line in f]
print(3)
```
No
| 8,985 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today is the open campus of Z University. Every year during the lunch break on this day, many high school students line up for the school cafeteria. Therefore, the secretariat of Z University decided to predict the maximum distance of the procession. As a result of the preliminary survey, we know the following.
* The matrix is lined with N people, each numbered from 1 to N.
* For each pair of C high school students (ai, bi), there are two types of restrictions:
* The first constraint is on the order and is one of the following:
ai must be ahead of bi or in the same position
ai must line up after or in the same position as bi
ai can be before, in the same position, or after bi
* The second constraint is on distance and is one of the following:
ai and bi must be at least di meters apart
ai and bi must line up within di meters
We also know that multiple people can be lined up at the same distance from the beginning, and that the number 1 person is always at the beginning of the procession.
Create a program to find the distance when the matrix that satisfies all the given C constraints is arranged so that the distance from the beginning to the end is the maximum. However, output inf if it can be separated indefinitely, and -1 if it is not possible to arrange in a way that satisfies the constraint.
input
The input is given in the following format.
N C
constraint1
constraint2
::
constraintC
The number of high school students in the queue on the first line N (2 ≤ N ≤ 100) and the number of constraints C (0 ≤ C ≤ 200) are given. Each constraint constrainti is given in the following C line in the following format.
aioibisidi
The constraint does not include spaces. The meanings of ai, oi, bi, si and di are shown below.
* ai and bi (1 ≤ ai, bi ≤ N and ai ≠ bi) are high school student numbers, and di is an integer representing the distance (0 ≤ d ≤ 10000).
* oi is a string of <=,> =, * that specifies the order constraint, and if <=, "ai must precede bi or be in the same position",> = In the case of, "ai must be after bi or in the same position", and in the case of *, it means that "ai can be before, in the same position, or after bi". However, no more than 7 constraints with oi as * can be given.
* si is the + or-character that specifies the distance constraint, for + "ai and bi must be at least di meters apart", for-"ai and bi must be within di meters" It means that.
However, it is assumed that multiple constraints are not given to a pair.
output
The distance from the beginning to the end is output on one line.
Example
Input
3 2
1
Output
3
Submitted Solution:
```
def create_edge(fr,to,weight,si):
edges = []
if si == '-':
edges.append((fr,to,weight))
edges.append((to,fr,0))
else:
edges.append((to,fr,-weight))
return edges
#????????????????????´???-1?????????
def bellmanford(edges, length):
start_vertex = 0
distance = [float('inf')] * length
distance[start_vertex] = 0
for i in range(length):
for fr, to, weight in edges:
if distance[to] > distance[fr] + weight:
distance[to] = distance[fr] + weight
for fr, to, weight in edges:
if distance[to] > distance[fr] + weight:
return -1
return max(distance)
import sys
import re
import math
import itertools
n,c = map(int, f.readline().split())
p = re.compile('(\d+)(\D+)(\d+)(\D+)(\d+)')
constraints = [p.match(line).groups() for line in f]
fixed_edges = []
floating_edges = []
for ai, oi, bi, si, di in constraints:
fr,to,weight = int(ai) - 1,int(bi) - 1,int(di)
if oi == '*':
floating_edges.append((create_edge(fr,to,weight,si),create_edge(to,fr,weight,si)))
else:
if oi == '>=':
fr, to = to, fr
fixed_edges.extend(create_edge(fr,to,weight,si))
distance = []
for edges in itertools.product(*floating_edges):
distance.append(bellmanford(fixed_edges + [y for x in edges for y in x], n))
print(max(distance))
```
No
| 8,986 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today is the open campus of Z University. Every year during the lunch break on this day, many high school students line up for the school cafeteria. Therefore, the secretariat of Z University decided to predict the maximum distance of the procession. As a result of the preliminary survey, we know the following.
* The matrix is lined with N people, each numbered from 1 to N.
* For each pair of C high school students (ai, bi), there are two types of restrictions:
* The first constraint is on the order and is one of the following:
ai must be ahead of bi or in the same position
ai must line up after or in the same position as bi
ai can be before, in the same position, or after bi
* The second constraint is on distance and is one of the following:
ai and bi must be at least di meters apart
ai and bi must line up within di meters
We also know that multiple people can be lined up at the same distance from the beginning, and that the number 1 person is always at the beginning of the procession.
Create a program to find the distance when the matrix that satisfies all the given C constraints is arranged so that the distance from the beginning to the end is the maximum. However, output inf if it can be separated indefinitely, and -1 if it is not possible to arrange in a way that satisfies the constraint.
input
The input is given in the following format.
N C
constraint1
constraint2
::
constraintC
The number of high school students in the queue on the first line N (2 ≤ N ≤ 100) and the number of constraints C (0 ≤ C ≤ 200) are given. Each constraint constrainti is given in the following C line in the following format.
aioibisidi
The constraint does not include spaces. The meanings of ai, oi, bi, si and di are shown below.
* ai and bi (1 ≤ ai, bi ≤ N and ai ≠ bi) are high school student numbers, and di is an integer representing the distance (0 ≤ d ≤ 10000).
* oi is a string of <=,> =, * that specifies the order constraint, and if <=, "ai must precede bi or be in the same position",> = In the case of, "ai must be after bi or in the same position", and in the case of *, it means that "ai can be before, in the same position, or after bi". However, no more than 7 constraints with oi as * can be given.
* si is the + or-character that specifies the distance constraint, for + "ai and bi must be at least di meters apart", for-"ai and bi must be within di meters" It means that.
However, it is assumed that multiple constraints are not given to a pair.
output
The distance from the beginning to the end is output on one line.
Example
Input
3 2
1
Output
3
Submitted Solution:
```
def create_edge(fr,to,weight,si):
edges = []
if si == '-':
edges.append((fr,to,weight))
edges.append((to,fr,0))
else:
edges.append((to,fr,-weight))
return edges
#????????????????????´???-1?????????
def bellmanford(edges, length):
start_vertex = 0
distance = [float('inf')] * length
distance[start_vertex] = 0
for i in range(length):
for fr, to, weight in edges:
if distance[to] > distance[fr] + weight:
distance[to] = distance[fr] + weight
for fr, to, weight in edges:
if distance[to] > distance[fr] + weight:
return -1
return max(distance)
import sys
import re
import math
n,c = map(int, f.readline().split())
p = re.compile('(\d+)(\D+)(\d+)(\D+)(\d+)')
constraints = [p.match(line).groups() for line in f]
fixed_edges = []
floating_edges = []
for ai, oi, bi, si, di in constraints:
fr,to,weight = int(ai) - 1,int(bi) - 1,int(di)
if oi == '*':
floating_edges.append((create_edge(fr,to,weight,si),create_edge(to,fr,weight,si)))
else:
if oi == '>=':
fr, to = to, fr
fixed_edges.extend(create_edge(fr,to,weight,si))
distance = []
for edges in itertools.product(*floating_edges):
distance.append(bellmanford(fixed_edges + [y for x in edges for y in x], n))
print(max(distance))
```
No
| 8,987 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None
"Correct Solution:
```
import itertools
ans = []
while True:
n = int(input())
k = int(input())
if n == 0 and k == 0:
break
cards = []
ans_set = []
for i in range(n):
cards.append(input())
for i in itertools.permutations(cards, k):
ans_set.append(int("".join(i)))
ans.append(len(set(ans_set)))
for i in ans:
print(i)
```
| 8,988 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None
"Correct Solution:
```
import itertools
while(1):
n = int(input())
k = int(input())
if((n == 0)and(k == 0)): break
num = []
for i in range(n): num.append(input())
#print('num :::',num)
A = []
for i in range(n): A.append(i)
#print('A :::',A)
num_list = []
Comb = list(itertools.permutations(A,k))
#print('Comb :::',len(Comb))
for i in range(len(Comb)):
tmp = list(Comb[i])
tmp_num = ''
for j in range(len(tmp)):
tmp_num += num[tmp[j]]
tmp_num = int(tmp_num)
num_list.append(tmp_num)
ans = len(list(set(num_list)))
print(ans)
#print('aaaa')
```
| 8,989 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None
"Correct Solution:
```
from itertools import permutations as P
for e in iter(input,'0'):
n,k=int(e),int(input())
C=[input()for _ in[0]*n]
print(len(set(''.join(s)for s in P(C,k))))
```
| 8,990 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None
"Correct Solution:
```
import sys
import itertools
if sys.platform =='win32':
sys.stdin=open('input.txt')
def MAP(): return [int(x) for x in input().split()]
while True:
N = int(input())
K = int(input())
if N==0 and K==0: break
a = [int(input()) for _ in range(N)]
perm = itertools.permutations(a, K)
nums = []
for p in perm:
num = ''
for s in p:
num += str(s)
nums.append(int(num))
print(len(set(nums)))
```
| 8,991 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None
"Correct Solution:
```
def s():
from itertools import permutations as P
for e in iter(input,'0'):
n,k=int(e),int(input())
C=[input()for _ in[0]*n]
print(len(set(''.join(s)for s in P(C,k))))
if'__main__'==__name__:s()
```
| 8,992 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Lining up the cards
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0546
"""
import sys
from itertools import permutations
def solve(cards, k):
return len(set([''.join(c) for c in permutations(cards, k)]))
def main(args):
while True:
n = int(input())
k = int(input())
if n == 0 and k == 0:
break
cards = [input() for _ in range(n)]
ans = solve(cards, k)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
```
| 8,993 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None
"Correct Solution:
```
import itertools
while 1:
n = int(input())
k = int(input())
if n == k == 0:
break
a = []
for i in range(n):
a.append(input())
b = []
p = list(itertools.permutations(a, k))
for i in p:
b.append(''.join(i))
c = list(set(b))
print(len(c))
```
| 8,994 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None
"Correct Solution:
```
from itertools import permutations as P
while True:
n, k = int(input()), int(input())
if k == 0:
break
card = [input() for _ in range(n)]
print(len(set([''.join(s) for s in P(card, k)])))
```
| 8,995 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None
Submitted Solution:
```
while True:
n = int(input())
k = int(input())
if not n:
break
lst = [input() for i in range(n)]
dic = dict()
def func(num,selected):
if num == 0:
dic["".join([lst[i] for i in selected])] = 1
return
for i in range(n):
if not i in selected:
selected.append(i)
func(num - 1, selected)
selected.pop()
func(k,[])
print(len(dic))
```
Yes
| 8,996 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None
Submitted Solution:
```
n = k = 0
cards = []
mini_ans = {}
def dfs(s: list) -> None:
global n, k, cards, mini_ans
if len(s) == k:
string = ""
for i in s:
string += cards[i]
mini_ans.add(string)
return
for i in range(n):
if i not in s:
dfs(s + [i])
def main() -> None:
ans = []
global n, k, cards, mini_ans
while True:
n, k = [int(input()) for _ in range(2)]
if n + k == 0:
break
cards = [input() for _ in range(n)]
mini_ans = set()
dfs([])
ans += [len(mini_ans)]
print("\n".join(map(str, ans)))
if __name__ == "__main__":
main()
```
Yes
| 8,997 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None
Submitted Solution:
```
from itertools import permutations
while 1:
N = int(input())
S = int(input())
if N == 0:
break
l = [int(input()) for _ in range(N)]
dic = {}
for i in permutations(l,S):
i = map(str,i)
dic[("".join(i))] = 1
print(len(dic))
```
Yes
| 8,998 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?
For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.
Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.
input
The input consists of multiple datasets. Each dataset is given in the following format.
Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.
When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each data set, the number of integers that Hanako can create is output on one line.
Examples
Input
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
Output
7
68
Input
None
Output
None
Submitted Solution:
```
from itertools import permutations as P
while True:
n, k = int(input()), int(input())
if k == 0:
break
card = [int(input()) for _ in range(n)]
print(len(set([''.join(map(str, s)) for s in set(P(card, k))])))
```
Yes
| 8,999 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.