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 is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries?
Constraints
* 3 \leq N \leq 2\times 10^5
* 0 \leq Q \leq \min(2N-4,2\times 10^5)
* 2 \leq x \leq N-1
* Queries are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q
Output
Print how many black stones there are on the grid after processing all Q queries.
Examples
Input
5 5
1 3
2 3
1 4
2 2
1 2
Output
1
Input
200000 0
Output
39999200004
Input
176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
Output
31159505795
Submitted Solution:
```
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
from collections import deque
from collections import Counter
import bisect
from collections import defaultdict
import itertools
def main():
N, Q = MI()
#i行の一番右をline_right[i], j列目の一番下をcolumn_under[j]とする。
line_right = [N] * N
column_under = [N] * N
bla = pow(N - 2, 2)
x_min = N
y_min = N
for i in range(Q):
query = LI()
if query[0] == 1:
w = query[1]
x = column_under[w]
bla -= x - 2
if w < x_min:
for j in range(x):
line_right[j] = w
x_min = w
else:
y = query[1]
z = line_right[y]
bla -= z - 2
if y < y_min:
for j in range(z):
column_under[j] = y
y_min = y
print(bla)
if __name__ == "__main__":
main()
```
No
| 104,200 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries?
Constraints
* 3 \leq N \leq 2\times 10^5
* 0 \leq Q \leq \min(2N-4,2\times 10^5)
* 2 \leq x \leq N-1
* Queries are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q
Output
Print how many black stones there are on the grid after processing all Q queries.
Examples
Input
5 5
1 3
2 3
1 4
2 2
1 2
Output
1
Input
200000 0
Output
39999200004
Input
176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
Output
31159505795
Submitted Solution:
```
n, q = map(int, input().split())
q = [list(map(int, input().split())) for _i in range(q)]
x_list = [n for _i in range(n+1)]
y_list = [n for _i in range(n+1)]
res = (n-2)**2
from bisect import bisect_right
for i, j in q:
if i==1:
position = x_list[j]
res -= position-2
for s in range(1, position):
y_list[s] = min(y_list[s], j)
else:
position = y_list[j]
res -= position-2
for s in range(1, position):
x_list[s] = min(x_list[s], j)
print(res)
```
No
| 104,201 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries?
Constraints
* 3 \leq N \leq 2\times 10^5
* 0 \leq Q \leq \min(2N-4,2\times 10^5)
* 2 \leq x \leq N-1
* Queries are pairwise distinct.
Input
Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q
Output
Print how many black stones there are on the grid after processing all Q queries.
Examples
Input
5 5
1 3
2 3
1 4
2 2
1 2
Output
1
Input
200000 0
Output
39999200004
Input
176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
Output
31159505795
Submitted Solution:
```
class segtree():
def segfunc(x,y):
return min(x,y)
#####単位元######
ide_ele = -1
n=1
init_val=[0]*n
#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num
def __init__(self,INIT_VAL,SEGFUNC,IDE_ELE):
self.ide_ele=IDE_ELE
self.init_val=[i for i in INIT_VAL]
self.segfunc=SEGFUNC
self.n=len(self.init_val)
self.num =2**(self.n-1).bit_length()
self.seg=[self.ide_ele]*2*self.num
#set_val
for i in range(self.n):
self.seg[i+self.num-1]=self.init_val[i]
#built
for i in range(self.num-2,-1,-1) :
self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2])
def update(self,k,x):
k += self.num-1
self.seg[k] = x
while k+1:
k = (k-1)//2
self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
def query(self,p,q):
if q<=p:
return self.ide_ele
p += self.num-1
q += self.num-2
res=self.ide_ele
while q-p>1:
if p&1 == 0:
res = self.segfunc(res,self.seg[p])
if q&1 == 1:
res = self.segfunc(res,self.seg[q])
q -= 1
p = p//2
q = (q-1)//2
if p == q:
res = self.segfunc(res,self.seg[p])
else:
res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
return res
N,Q=map(int,input().split())
X=segtree([0 for i in range(N)],(lambda x,y:x+y),0)
Y=segtree([0 for i in range(N)],(lambda x,y:x+y),0)
ans=(N-2)*(N-2)
for i in range(Q):
k,x=map(int,input().split())
#print(i,ans)
#print([X.query(0,i) for i in range(1,N)],[Y.query(0,i) for i in range(1,N)])
dp=[[-1 for i in range(N)] for i in range(N)]
for i in range(1,N):
dp[-i-1][-1]=Y.query(0,i)
dp[-1][-1-i]=X.query(0,i)
x=N-x+1
#for line in dp:
# print(line)
if k==1:
a=X.query(0,x)
ans-=N-2-a
if Y.query(a,a+1)<x-1:
Y.update(a,x-1)
else:
b=Y.query(0,x)
ans-=N-2-b
if X.query(b,b+1)<x-1:
X.update(b,x-1)
print(ans)
```
No
| 104,202 |
Provide a correct Python 3 solution for this coding contest problem.
We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.
We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?
Constraints
* All values in input are integers.
* 0 \leq A, B, C
* 1 \leq K \leq A + B + C \leq 2 \times 10^9
Input
Input is given from Standard Input in the following format:
A B C K
Output
Print the maximum possible sum of the numbers written on the cards chosen.
Examples
Input
2 1 1 3
Output
2
Input
1 2 3 4
Output
0
Input
2000000000 0 0 2000000000
Output
2000000000
"Correct Solution:
```
a,b,c,k = map(int,input().split())
ans = min(a,k)
if(k>a+b):
ans-=(k-(a+b))
print(ans)
```
| 104,203 |
Provide a correct Python 3 solution for this coding contest problem.
We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.
We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?
Constraints
* All values in input are integers.
* 0 \leq A, B, C
* 1 \leq K \leq A + B + C \leq 2 \times 10^9
Input
Input is given from Standard Input in the following format:
A B C K
Output
Print the maximum possible sum of the numbers written on the cards chosen.
Examples
Input
2 1 1 3
Output
2
Input
1 2 3 4
Output
0
Input
2000000000 0 0 2000000000
Output
2000000000
"Correct Solution:
```
a,b,c,k = map(int,input().split())
ans=min(k,a)-max(min(k-a-b,c),0)
print(ans)
```
| 104,204 |
Provide a correct Python 3 solution for this coding contest problem.
We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.
We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?
Constraints
* All values in input are integers.
* 0 \leq A, B, C
* 1 \leq K \leq A + B + C \leq 2 \times 10^9
Input
Input is given from Standard Input in the following format:
A B C K
Output
Print the maximum possible sum of the numbers written on the cards chosen.
Examples
Input
2 1 1 3
Output
2
Input
1 2 3 4
Output
0
Input
2000000000 0 0 2000000000
Output
2000000000
"Correct Solution:
```
a,b,c,k=map(int,input().split())
if k<=a+b:
print(min(a,k))
else:
print(a-(k-a-b))
```
| 104,205 |
Provide a correct Python 3 solution for this coding contest problem.
We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.
We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?
Constraints
* All values in input are integers.
* 0 \leq A, B, C
* 1 \leq K \leq A + B + C \leq 2 \times 10^9
Input
Input is given from Standard Input in the following format:
A B C K
Output
Print the maximum possible sum of the numbers written on the cards chosen.
Examples
Input
2 1 1 3
Output
2
Input
1 2 3 4
Output
0
Input
2000000000 0 0 2000000000
Output
2000000000
"Correct Solution:
```
A, B, C, K = map(int, input().split())
print(min(A, K) - max(0, (K - A - B)))
```
| 104,206 |
Provide a correct Python 3 solution for this coding contest problem.
We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.
We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?
Constraints
* All values in input are integers.
* 0 \leq A, B, C
* 1 \leq K \leq A + B + C \leq 2 \times 10^9
Input
Input is given from Standard Input in the following format:
A B C K
Output
Print the maximum possible sum of the numbers written on the cards chosen.
Examples
Input
2 1 1 3
Output
2
Input
1 2 3 4
Output
0
Input
2000000000 0 0 2000000000
Output
2000000000
"Correct Solution:
```
one, zero, neg_one, k = map(int, input().split())
print(min(one, k) - max(0, k-one-zero))
```
| 104,207 |
Provide a correct Python 3 solution for this coding contest problem.
We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.
We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?
Constraints
* All values in input are integers.
* 0 \leq A, B, C
* 1 \leq K \leq A + B + C \leq 2 \times 10^9
Input
Input is given from Standard Input in the following format:
A B C K
Output
Print the maximum possible sum of the numbers written on the cards chosen.
Examples
Input
2 1 1 3
Output
2
Input
1 2 3 4
Output
0
Input
2000000000 0 0 2000000000
Output
2000000000
"Correct Solution:
```
a,b,c,k = map(int,input().split())
ax=min(a,k)
k=k-ax
bx=min(b,k)
k=k-bx
cx=k
print(ax-cx)
```
| 104,208 |
Provide a correct Python 3 solution for this coding contest problem.
We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.
We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?
Constraints
* All values in input are integers.
* 0 \leq A, B, C
* 1 \leq K \leq A + B + C \leq 2 \times 10^9
Input
Input is given from Standard Input in the following format:
A B C K
Output
Print the maximum possible sum of the numbers written on the cards chosen.
Examples
Input
2 1 1 3
Output
2
Input
1 2 3 4
Output
0
Input
2000000000 0 0 2000000000
Output
2000000000
"Correct Solution:
```
A,B,C,K=map(int,input().split())
print(min(A,K)-max(0,K-A-B))
```
| 104,209 |
Provide a correct Python 3 solution for this coding contest problem.
We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.
We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?
Constraints
* All values in input are integers.
* 0 \leq A, B, C
* 1 \leq K \leq A + B + C \leq 2 \times 10^9
Input
Input is given from Standard Input in the following format:
A B C K
Output
Print the maximum possible sum of the numbers written on the cards chosen.
Examples
Input
2 1 1 3
Output
2
Input
1 2 3 4
Output
0
Input
2000000000 0 0 2000000000
Output
2000000000
"Correct Solution:
```
A, B, C, K = [int(i) for i in input().split(' ')]
print(min(A, K) - max(K - B - A, 0))
```
| 104,210 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.
We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?
Constraints
* All values in input are integers.
* 0 \leq A, B, C
* 1 \leq K \leq A + B + C \leq 2 \times 10^9
Input
Input is given from Standard Input in the following format:
A B C K
Output
Print the maximum possible sum of the numbers written on the cards chosen.
Examples
Input
2 1 1 3
Output
2
Input
1 2 3 4
Output
0
Input
2000000000 0 0 2000000000
Output
2000000000
Submitted Solution:
```
A, B, C, K = [int(_) for _ in input().split()]
print(min(K, A) - max(0, (K - A - B)))
```
Yes
| 104,211 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.
We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?
Constraints
* All values in input are integers.
* 0 \leq A, B, C
* 1 \leq K \leq A + B + C \leq 2 \times 10^9
Input
Input is given from Standard Input in the following format:
A B C K
Output
Print the maximum possible sum of the numbers written on the cards chosen.
Examples
Input
2 1 1 3
Output
2
Input
1 2 3 4
Output
0
Input
2000000000 0 0 2000000000
Output
2000000000
Submitted Solution:
```
A, B, C, K = map(int, input().split())
ans = min(A, K) - max(0, K - (A + B))
print(ans)
```
Yes
| 104,212 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.
We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?
Constraints
* All values in input are integers.
* 0 \leq A, B, C
* 1 \leq K \leq A + B + C \leq 2 \times 10^9
Input
Input is given from Standard Input in the following format:
A B C K
Output
Print the maximum possible sum of the numbers written on the cards chosen.
Examples
Input
2 1 1 3
Output
2
Input
1 2 3 4
Output
0
Input
2000000000 0 0 2000000000
Output
2000000000
Submitted Solution:
```
a, b, c, k = map(int, input().split())
if k<a+b:
print(k)
exit()
else:
print(2*a+b-k)
```
Yes
| 104,213 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.
We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?
Constraints
* All values in input are integers.
* 0 \leq A, B, C
* 1 \leq K \leq A + B + C \leq 2 \times 10^9
Input
Input is given from Standard Input in the following format:
A B C K
Output
Print the maximum possible sum of the numbers written on the cards chosen.
Examples
Input
2 1 1 3
Output
2
Input
1 2 3 4
Output
0
Input
2000000000 0 0 2000000000
Output
2000000000
Submitted Solution:
```
a, b, c, k = map(int,input().split())
ans = min(k, a) - max(0, k - a - b)
print(ans)
```
Yes
| 104,214 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.
We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?
Constraints
* All values in input are integers.
* 0 \leq A, B, C
* 1 \leq K \leq A + B + C \leq 2 \times 10^9
Input
Input is given from Standard Input in the following format:
A B C K
Output
Print the maximum possible sum of the numbers written on the cards chosen.
Examples
Input
2 1 1 3
Output
2
Input
1 2 3 4
Output
0
Input
2000000000 0 0 2000000000
Output
2000000000
Submitted Solution:
```
line1 = input().split()
a = int(line1[0])
b = int(line1[1])
c = int(line1[2])
k = int(line1[3])
if a >= k:
print(a)
elif a + b >= k:
print(a)
else:
print(a - (k - (a + b)))
```
No
| 104,215 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.
We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?
Constraints
* All values in input are integers.
* 0 \leq A, B, C
* 1 \leq K \leq A + B + C \leq 2 \times 10^9
Input
Input is given from Standard Input in the following format:
A B C K
Output
Print the maximum possible sum of the numbers written on the cards chosen.
Examples
Input
2 1 1 3
Output
2
Input
1 2 3 4
Output
0
Input
2000000000 0 0 2000000000
Output
2000000000
Submitted Solution:
```
a,b,c,k=map(int,input().split())
max=a
if max<k:
if k>a+b:
max-=k-a-b
print(max)
```
No
| 104,216 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.
We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?
Constraints
* All values in input are integers.
* 0 \leq A, B, C
* 1 \leq K \leq A + B + C \leq 2 \times 10^9
Input
Input is given from Standard Input in the following format:
A B C K
Output
Print the maximum possible sum of the numbers written on the cards chosen.
Examples
Input
2 1 1 3
Output
2
Input
1 2 3 4
Output
0
Input
2000000000 0 0 2000000000
Output
2000000000
Submitted Solution:
```
card = list(map(int, input().split()))
count = card[3] - card[0] - card[1]
answer = card[0]
if count > 0:
if count < card[2]:
answer = answer + (count * -1)
print(answer)
else:
count = count - card[2]
answer = answer + (count * -1)
print(answer)
else:
print(answer)
```
No
| 104,217 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.
We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?
Constraints
* All values in input are integers.
* 0 \leq A, B, C
* 1 \leq K \leq A + B + C \leq 2 \times 10^9
Input
Input is given from Standard Input in the following format:
A B C K
Output
Print the maximum possible sum of the numbers written on the cards chosen.
Examples
Input
2 1 1 3
Output
2
Input
1 2 3 4
Output
0
Input
2000000000 0 0 2000000000
Output
2000000000
Submitted Solution:
```
a, b, c, counts = map(int, input().split())
x = a - counts
if x < 0:
y = b + x
if y < 0:
z = c + y
print(1 * a + -1 * (-(b + x)))
```
No
| 104,218 |
Provide a correct Python 3 solution for this coding contest problem.
Niwango bought a piece of land that can be represented as a half-open interval [0, X).
Niwango will lay out N vinyl sheets on this land. The sheets are numbered 1,2, \ldots, N, and they are distinguishable. For Sheet i, he can choose an integer j such that 0 \leq j \leq X - L_i and cover [j, j + L_i) with this sheet.
Find the number of ways to cover the land with the sheets such that no point in [0, X) remains uncovered, modulo (10^9+7). We consider two ways to cover the land different if and only if there is an integer i (1 \leq i \leq N) such that the region covered by Sheet i is different.
Constraints
* 1 \leq N \leq 100
* 1 \leq L_i \leq X \leq 500
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
L_1 L_2 \ldots L_N
Output
Print the answer.
Examples
Input
3 3
1 1 2
Output
10
Input
18 477
324 31 27 227 9 21 41 29 50 34 2 362 92 11 13 17 183 119
Output
134796357
"Correct Solution:
```
N,X=map(int,input().split())
L=sorted(map(int,input().split()),reverse=True)
mod=10**9+7
D=[[0]*(X+1) for i in range(N//2+2)]
D[1][L[0]]=1
for l in L[1:]:
ND=[[0]*(X+1) for i in range(N//2+1)]
for c in range(1,N//2+1):
for s in range(X+1):
if D[c][s]==0:
continue
k=D[c][s]
if s+l+c<=X and c+1<=N//2:
ND[c+1][s+l]=(ND[c+1][s+l]+k*(c+1))%mod
ND[c][s]=(ND[c][s]+k*(s-c*(l-1)))%mod
for i in range(1,min(X-s-c+2,l+1)):
ND[c][s+i]=(ND[c][s+i]+k*2*c)%mod
if c==1:
continue
for i in range(1,min(X-s-c+3,l+1)):
ND[c-1][s+i]=(ND[c-1][s+i]+k*(c-1)*(l-i+1))%mod
D=ND
print(D[1][X])
```
| 104,219 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Niwango bought a piece of land that can be represented as a half-open interval [0, X).
Niwango will lay out N vinyl sheets on this land. The sheets are numbered 1,2, \ldots, N, and they are distinguishable. For Sheet i, he can choose an integer j such that 0 \leq j \leq X - L_i and cover [j, j + L_i) with this sheet.
Find the number of ways to cover the land with the sheets such that no point in [0, X) remains uncovered, modulo (10^9+7). We consider two ways to cover the land different if and only if there is an integer i (1 \leq i \leq N) such that the region covered by Sheet i is different.
Constraints
* 1 \leq N \leq 100
* 1 \leq L_i \leq X \leq 500
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
L_1 L_2 \ldots L_N
Output
Print the answer.
Examples
Input
3 3
1 1 2
Output
10
Input
18 477
324 31 27 227 9 21 41 29 50 34 2 362 92 11 13 17 183 119
Output
134796357
Submitted Solution:
```
N,X=map(int,input().split())
L=sorted(map(int,input().split()),reverse=True)
mod=10**9+7
D=[[0]*(X+1) for i in range(N//2+1)]
D[1][L[0]]=1
for l in L[1:]:
ND=[[0]*(X+1) for i in range(N//2+1)]
for c in range(1,N//2+1):
for s in range(X+1):
if D[c][s]==0:
continue
k=D[c][s]
if s+l+c<=X and c+1<=N//2:
ND[c+1][s+l]=(ND[c+1][s+l]+k*(c+1))%mod
ND[c][s]=(ND[c][s]+k*(s-c*(l-1)))%mod
for i in range(1,min(X-s-c+2,l+1)):
ND[c][s+i]=(ND[c][s+i]+k*2*c)%mod
if c==1:
continue
for i in range(1,min(X-s-c+3,l+1)):
ND[c-1][s+i]=(ND[c-1][s+i]+k*(c-1)*(l-i+1))%mod
D=ND
print(D[1][X])
```
No
| 104,220 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Niwango bought a piece of land that can be represented as a half-open interval [0, X).
Niwango will lay out N vinyl sheets on this land. The sheets are numbered 1,2, \ldots, N, and they are distinguishable. For Sheet i, he can choose an integer j such that 0 \leq j \leq X - L_i and cover [j, j + L_i) with this sheet.
Find the number of ways to cover the land with the sheets such that no point in [0, X) remains uncovered, modulo (10^9+7). We consider two ways to cover the land different if and only if there is an integer i (1 \leq i \leq N) such that the region covered by Sheet i is different.
Constraints
* 1 \leq N \leq 100
* 1 \leq L_i \leq X \leq 500
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
L_1 L_2 \ldots L_N
Output
Print the answer.
Examples
Input
3 3
1 1 2
Output
10
Input
18 477
324 31 27 227 9 21 41 29 50 34 2 362 92 11 13 17 183 119
Output
134796357
Submitted Solution:
```
N,X=map(int,input().split())
L=sorted(map(int,input().split()),reverse=True)
mod=10**9+7
from collections import defaultdict
D=defaultdict(int)
D[1,L[0]]=1
for l in L[1:]:
ND=defaultdict(int)
for c,s in D:
k=D[c,s]
if s+l+c-1<=X:
ND[c+1,s+l]=(ND[c+1,s+l]+k*(c+1))%mod
ND[c,s]=(ND[c,s]+k*(s-c*(l-1)))%mod
for i in range(1,min(X-s-c+2,l+1)):
ND[c,s+i]=(ND[c,s+i]+k*2*c)%mod
for i in range(1,min(X-s-c+3,l+1)):
ND[c-1,s+i]=(ND[c-1,s+i]+k*(c-1)*(l-i+1))%mod
D=ND
print(D[1,X])
```
No
| 104,221 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Niwango bought a piece of land that can be represented as a half-open interval [0, X).
Niwango will lay out N vinyl sheets on this land. The sheets are numbered 1,2, \ldots, N, and they are distinguishable. For Sheet i, he can choose an integer j such that 0 \leq j \leq X - L_i and cover [j, j + L_i) with this sheet.
Find the number of ways to cover the land with the sheets such that no point in [0, X) remains uncovered, modulo (10^9+7). We consider two ways to cover the land different if and only if there is an integer i (1 \leq i \leq N) such that the region covered by Sheet i is different.
Constraints
* 1 \leq N \leq 100
* 1 \leq L_i \leq X \leq 500
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
L_1 L_2 \ldots L_N
Output
Print the answer.
Examples
Input
3 3
1 1 2
Output
10
Input
18 477
324 31 27 227 9 21 41 29 50 34 2 362 92 11 13 17 183 119
Output
134796357
Submitted Solution:
```
N,X=map(int,input().split())
L=sorted(map(int,input().split()),reverse=True)
mod=10**9+7
from collections import defaultdict
D=dict()
D[1,L[0]]=1
for l in L[1:]:
ND=defaultdict(int)
for c,s in D:
k=D[c,s]
if s+l<=X:
ND[c+1,s+l]=(ND[c+1,s+l]+k*(c+1))%mod
ND[c,s]=(ND[c,s]+k*(s-c*(l-1)))%mod
for i in range(1,min(X-s+1,l+1)):
ND[c,s+i]=(ND[c,s+i]+k*2*c)%mod
for i in range(1,min(X-s+1,l+1)):
ND[c-1,s+i]=(ND[c-1,s+i]+k*(c-1)*(l-i+1))%mod
D=ND
print(D[1,X])
```
No
| 104,222 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Niwango bought a piece of land that can be represented as a half-open interval [0, X).
Niwango will lay out N vinyl sheets on this land. The sheets are numbered 1,2, \ldots, N, and they are distinguishable. For Sheet i, he can choose an integer j such that 0 \leq j \leq X - L_i and cover [j, j + L_i) with this sheet.
Find the number of ways to cover the land with the sheets such that no point in [0, X) remains uncovered, modulo (10^9+7). We consider two ways to cover the land different if and only if there is an integer i (1 \leq i \leq N) such that the region covered by Sheet i is different.
Constraints
* 1 \leq N \leq 100
* 1 \leq L_i \leq X \leq 500
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
L_1 L_2 \ldots L_N
Output
Print the answer.
Examples
Input
3 3
1 1 2
Output
10
Input
18 477
324 31 27 227 9 21 41 29 50 34 2 362 92 11 13 17 183 119
Output
134796357
Submitted Solution:
```
N,X=map(int,input().split())
L=sorted(map(int,input().split()),reverse=True)
mod=10**9+7
D=[[0]*(X+1) for i in range(N//2+2)]
D[1][L[0]]=1
for l in L[1:]:
ND=[[0]*(X+1) for i in range(N//2+1)]
for c in range(1,N//2+1):
for s in range(X+1):
if D[c][s]==0:
continue
k=D[c][s]
if s+l+c<=X and c+1<=N//2:
ND[c+1][s+l]=(ND[c+1][s+l]+k*(c+1))%mod
ND[c][s]=(ND[c][s]+k*(s-c*(l-1)))%mod
for i in range(1,min(X-s-c+2,l+1)):
ND[c][s+i]=(ND[c][s+i]+k*2*c)%mod
if c==1:
continue
for i in range(1,min(X-s-c+3,l+1)):
ND[c-1][s+i]=(ND[c-1][s+i]+k*(c-1)*(l-i+1))%mod
D=ND
print(D[1][X])
```
No
| 104,223 |
Provide a correct Python 3 solution for this coding contest problem.
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Constraints
* 2 \leq N \leq 10^5
* s_i is a string of length 10.
* Each character in s_i is a lowercase English letter.
* s_1, s_2, \ldots, s_N are all distinct.
Input
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
Output
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Examples
Input
3
acornistnt
peanutbomb
constraint
Output
1
Input
2
oneplustwo
ninemodsix
Output
0
Input
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
Output
4
"Correct Solution:
```
from collections import Counter
c = Counter(frozenset(Counter(input()).items()) for _ in range(int(input())))
print(sum(x * (x - 1) // 2 for x in c.values()))
```
| 104,224 |
Provide a correct Python 3 solution for this coding contest problem.
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Constraints
* 2 \leq N \leq 10^5
* s_i is a string of length 10.
* Each character in s_i is a lowercase English letter.
* s_1, s_2, \ldots, s_N are all distinct.
Input
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
Output
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Examples
Input
3
acornistnt
peanutbomb
constraint
Output
1
Input
2
oneplustwo
ninemodsix
Output
0
Input
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
Output
4
"Correct Solution:
```
n=int(input())
d={}
ans=0
for _ in range(n):
s=''.join(sorted(input()))
if s in d.keys():d[s]+=1;ans+=d[s]
else:d.setdefault(s,0)
print(ans)
```
| 104,225 |
Provide a correct Python 3 solution for this coding contest problem.
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Constraints
* 2 \leq N \leq 10^5
* s_i is a string of length 10.
* Each character in s_i is a lowercase English letter.
* s_1, s_2, \ldots, s_N are all distinct.
Input
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
Output
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Examples
Input
3
acornistnt
peanutbomb
constraint
Output
1
Input
2
oneplustwo
ninemodsix
Output
0
Input
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
Output
4
"Correct Solution:
```
N=int(input())
dict={}
cnt=0
for a in range(N):
s="".join(sorted(input()))
if s in dict:
dict[s]+=1
cnt+=dict[s]
else:
dict[s]=0
print(cnt)
```
| 104,226 |
Provide a correct Python 3 solution for this coding contest problem.
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Constraints
* 2 \leq N \leq 10^5
* s_i is a string of length 10.
* Each character in s_i is a lowercase English letter.
* s_1, s_2, \ldots, s_N are all distinct.
Input
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
Output
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Examples
Input
3
acornistnt
peanutbomb
constraint
Output
1
Input
2
oneplustwo
ninemodsix
Output
0
Input
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
Output
4
"Correct Solution:
```
n=int(input())
c=[''.join(sorted(input())) for _ in range(n)]
an=0
d={}
for i in c:
if i in d:
an += d[i]
d[i]+=1
else:
d[i]=1
print(an)
```
| 104,227 |
Provide a correct Python 3 solution for this coding contest problem.
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Constraints
* 2 \leq N \leq 10^5
* s_i is a string of length 10.
* Each character in s_i is a lowercase English letter.
* s_1, s_2, \ldots, s_N are all distinct.
Input
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
Output
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Examples
Input
3
acornistnt
peanutbomb
constraint
Output
1
Input
2
oneplustwo
ninemodsix
Output
0
Input
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
Output
4
"Correct Solution:
```
n=int(input())
s=[''.join(sorted(input())) for _ in range(n)]
dic={}
ans=0
for i in s:
t=dic.get(i,0)
ans+=t
dic[i]=t+1
print(ans)
```
| 104,228 |
Provide a correct Python 3 solution for this coding contest problem.
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Constraints
* 2 \leq N \leq 10^5
* s_i is a string of length 10.
* Each character in s_i is a lowercase English letter.
* s_1, s_2, \ldots, s_N are all distinct.
Input
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
Output
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Examples
Input
3
acornistnt
peanutbomb
constraint
Output
1
Input
2
oneplustwo
ninemodsix
Output
0
Input
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
Output
4
"Correct Solution:
```
import collections
N=int(input())
s=[str(sorted(input())) for i in range(N)]
c=collections.Counter(s)
print(sum((v*(v-1))//2 for v in c.values()))
```
| 104,229 |
Provide a correct Python 3 solution for this coding contest problem.
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Constraints
* 2 \leq N \leq 10^5
* s_i is a string of length 10.
* Each character in s_i is a lowercase English letter.
* s_1, s_2, \ldots, s_N are all distinct.
Input
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
Output
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Examples
Input
3
acornistnt
peanutbomb
constraint
Output
1
Input
2
oneplustwo
ninemodsix
Output
0
Input
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
Output
4
"Correct Solution:
```
n=int(input())
d={}
count=0
for i in range(n):
s=tuple(sorted(input()))
if s not in d:
d[s]=0
count+=d[s]
d[s]+=1
print(count)
```
| 104,230 |
Provide a correct Python 3 solution for this coding contest problem.
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Constraints
* 2 \leq N \leq 10^5
* s_i is a string of length 10.
* Each character in s_i is a lowercase English letter.
* s_1, s_2, \ldots, s_N are all distinct.
Input
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
Output
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Examples
Input
3
acornistnt
peanutbomb
constraint
Output
1
Input
2
oneplustwo
ninemodsix
Output
0
Input
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
Output
4
"Correct Solution:
```
from collections import Counter
n = int(input())
cnt_s = Counter([''.join(sorted(input())) for i in range(n)])
print(sum(v*(v - 1)//2 for v in cnt_s.values()))
```
| 104,231 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Constraints
* 2 \leq N \leq 10^5
* s_i is a string of length 10.
* Each character in s_i is a lowercase English letter.
* s_1, s_2, \ldots, s_N are all distinct.
Input
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
Output
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Examples
Input
3
acornistnt
peanutbomb
constraint
Output
1
Input
2
oneplustwo
ninemodsix
Output
0
Input
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
Output
4
Submitted Solution:
```
from collections import Counter
N = int(input())
S = ["".join(sorted(input())) for i in range(N)]
ans = 0
for i in Counter(S).values():
ans += i*(i-1)//2
print(ans)
```
Yes
| 104,232 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Constraints
* 2 \leq N \leq 10^5
* s_i is a string of length 10.
* Each character in s_i is a lowercase English letter.
* s_1, s_2, \ldots, s_N are all distinct.
Input
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
Output
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Examples
Input
3
acornistnt
peanutbomb
constraint
Output
1
Input
2
oneplustwo
ninemodsix
Output
0
Input
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
Output
4
Submitted Solution:
```
from collections import Counter as C
n,*s=open(0)
print(sum(x*(x-1)//2 for x in C(tuple(sorted(i.strip()))for i in s).values()))
```
Yes
| 104,233 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Constraints
* 2 \leq N \leq 10^5
* s_i is a string of length 10.
* Each character in s_i is a lowercase English letter.
* s_1, s_2, \ldots, s_N are all distinct.
Input
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
Output
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Examples
Input
3
acornistnt
peanutbomb
constraint
Output
1
Input
2
oneplustwo
ninemodsix
Output
0
Input
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
Output
4
Submitted Solution:
```
from collections import Counter
N = int(input())
S = []
for _ in range(N):
S.append("".join(sorted(input())))
c = Counter(S)
print(sum([k*(k-1)//2 for k in c.values()]))
```
Yes
| 104,234 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Constraints
* 2 \leq N \leq 10^5
* s_i is a string of length 10.
* Each character in s_i is a lowercase English letter.
* s_1, s_2, \ldots, s_N are all distinct.
Input
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
Output
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Examples
Input
3
acornistnt
peanutbomb
constraint
Output
1
Input
2
oneplustwo
ninemodsix
Output
0
Input
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
Output
4
Submitted Solution:
```
import collections
n=int(input())
s=["".join(sorted(input())) for i in range(n)]
c=list(collections.Counter(s).values())
r=0
for x in c:
if x!=1:r+=(x*(x-1)//2)
print(r)
```
Yes
| 104,235 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Constraints
* 2 \leq N \leq 10^5
* s_i is a string of length 10.
* Each character in s_i is a lowercase English letter.
* s_1, s_2, \ldots, s_N are all distinct.
Input
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
Output
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Examples
Input
3
acornistnt
peanutbomb
constraint
Output
1
Input
2
oneplustwo
ninemodsix
Output
0
Input
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
Output
4
Submitted Solution:
```
import numpy as np
n = int(input())
# alp = ["a","b","c","d","e",
# "f","g","h","i","j",
# "k","l","m","n","o",
# "p","q","r","s","t",
# "u","v","w","x","y","z"]
#
ans = 0
# array1 = np.zeros().reshape( n,10)
# list1 = []
list_s = []
for i in range(n):
s = input()
list_s.append(s)
list_s = list(map(sorted, list_s))
for i in range(n):
ans = ans + sum(map(lambda x: x==list_s[i],list_s)) -1
print(int(ans/2))
```
No
| 104,236 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Constraints
* 2 \leq N \leq 10^5
* s_i is a string of length 10.
* Each character in s_i is a lowercase English letter.
* s_1, s_2, \ldots, s_N are all distinct.
Input
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
Output
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Examples
Input
3
acornistnt
peanutbomb
constraint
Output
1
Input
2
oneplustwo
ninemodsix
Output
0
Input
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
Output
4
Submitted Solution:
```
n =int(input())
A=[]
for I in range(n):
moji=input()
A.append(moji)
N=0
for i in range(n):
a=list(A[i])
a.sort()
for s in range(i+1,n,1):
b=list(A[s])
b.sort()
if a==b:
N+=1
print(N)
```
No
| 104,237 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Constraints
* 2 \leq N \leq 10^5
* s_i is a string of length 10.
* Each character in s_i is a lowercase English letter.
* s_1, s_2, \ldots, s_N are all distinct.
Input
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
Output
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Examples
Input
3
acornistnt
peanutbomb
constraint
Output
1
Input
2
oneplustwo
ninemodsix
Output
0
Input
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
Output
4
Submitted Solution:
```
import itertools
n = int(input())
sin = [''.join(sorted(input())) for _ in range(n)]
ans = []
for i in set(sin):
if sin.count(i) > 1:
combi = list(itertools.combinations(range(sin.count(i)), 2))
ans.append(len(combi))
print(sum(ans))
```
No
| 104,238 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the same character occurs multiple times, that character must be used that number of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Constraints
* 2 \leq N \leq 10^5
* s_i is a string of length 10.
* Each character in s_i is a lowercase English letter.
* s_1, s_2, \ldots, s_N are all distinct.
Input
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
Output
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.
Examples
Input
3
acornistnt
peanutbomb
constraint
Output
1
Input
2
oneplustwo
ninemodsix
Output
0
Input
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
Output
4
Submitted Solution:
```
import collections
import math
n = int(input())
inputlist = []
for i in range(n):
inputlist.append("".join(sorted(list(input()))))
counter = collections.Counter(inputlist)
counter = dict(counter)
valuelist = list(map(int, counter.values()))
ans = 0
for i in valuelist:
if i == 1:
continue
if i == 2:
ans += 1
continue
ans += math.factorial(i) / 2 / math.factorial(i-2)
print(int(ans))
```
No
| 104,239 |
Provide a correct Python 3 solution for this coding contest problem.
Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack.
He will repeat the following procedure until there is no piece left:
* Choose black or white with equal probability, and eat a piece of that color if it exists.
For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
Constraints
* All values in input are integers.
* 1 \leq B,W \leq 10^{5}
Input
Input is given from Standard Input in the following format:
B W
Output
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7.
Examples
Input
2 1
Output
500000004
750000006
750000006
Input
3 2
Output
500000004
500000004
625000005
187500002
187500002
Input
6 9
Output
500000004
500000004
500000004
500000004
500000004
500000004
929687507
218750002
224609377
303710940
633300786
694091802
172485353
411682132
411682132
"Correct Solution:
```
U = 2*10**5
MOD = 10**9+7
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
for i in range(1,U+1):
fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U], MOD-2, MOD)
for i in range(U,0,-1):
fact_inv[i-1] = (fact_inv[i]*i)%MOD
def comb(n, k):
if k < 0 or k > n:
return 0
z = fact[n]
z *= fact_inv[k]
z %= MOD
z *= fact_inv[n-k]
z %= MOD
return z
B, W = map(int, input().split())
p = 0
q = 0
for i in range(1, B+W+1):
ans = 1 - p + q
ans %= MOD
ans *= pow(2, MOD-2, MOD)
ans %= MOD
print(ans)
p += comb(i-1, B-1) * pow(pow(2, i, MOD), MOD-2, MOD) % MOD
p %= MOD
q += comb(i-1, W-1) * pow(pow(2, i, MOD), MOD-2, MOD) % MOD
q %= MOD
```
| 104,240 |
Provide a correct Python 3 solution for this coding contest problem.
Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack.
He will repeat the following procedure until there is no piece left:
* Choose black or white with equal probability, and eat a piece of that color if it exists.
For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
Constraints
* All values in input are integers.
* 1 \leq B,W \leq 10^{5}
Input
Input is given from Standard Input in the following format:
B W
Output
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7.
Examples
Input
2 1
Output
500000004
750000006
750000006
Input
3 2
Output
500000004
500000004
625000005
187500002
187500002
Input
6 9
Output
500000004
500000004
500000004
500000004
500000004
500000004
929687507
218750002
224609377
303710940
633300786
694091802
172485353
411682132
411682132
"Correct Solution:
```
MOD = 10**9+7
MAX = 2*(10**5)+1
fac = [1 for i in range(MAX)]
finv = [1 for i in range(MAX)]
inv = [1 for i in range(MAX)]
b,w = map(int,input().split())
if (b >= w):
flag = 0
else:
flag = 1
b,w = w,b
for i in range(2,MAX):
fac[i] = fac[i-1]*i%MOD
inv[i] = MOD - inv[MOD%i]*(MOD // i)%MOD
finv[i]=finv[i-1]*inv[i]%MOD
def com(n,k):
if(n < k): return 0
return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
def pow(n,k,m):#n^k mod m
ans = 1
while k>0:
if(k & 1):ans = (ans*n) % m
n = (n*n)%m
k >>= 1
return ans
for i in range(w):
print(inv[2])
p1 = 1
p2 = 0
for i in range(1,w+1):
p2 = (p2+ com(w,i)) % MOD
deno = pow(inv[2],w,MOD)
denodeno = pow(2,w,MOD)
for i in range(b-w):
p1 = (p1*2)%MOD
deno = (deno* inv[2]) % MOD
denodeno = (denodeno*2) % MOD
if(flag == 0):print(((p1+p2)*deno)%MOD)
else : print(((denodeno-p1-p2)*deno)%MOD)
p2 = (p2*2-com(w+i,i+1)) % MOD
p1 = (p1+com(w+i,i+1)) % MOD
p2 -= 1
for i in range(b+1,b+w+1):
p1 *= 2
deno = (deno* inv[2]) % MOD
denodeno = (denodeno*2) % MOD
if(flag == 0):print(((p1+p2)*deno)%MOD)
else : print(((denodeno-p1-p2)*deno)%MOD)
p1 = (p1+com(i-1,w-1)) % MOD
p2 = (p2*2-com(i-1,w-1)-com(i-1,i-b)) % MOD
```
| 104,241 |
Provide a correct Python 3 solution for this coding contest problem.
Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack.
He will repeat the following procedure until there is no piece left:
* Choose black or white with equal probability, and eat a piece of that color if it exists.
For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
Constraints
* All values in input are integers.
* 1 \leq B,W \leq 10^{5}
Input
Input is given from Standard Input in the following format:
B W
Output
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7.
Examples
Input
2 1
Output
500000004
750000006
750000006
Input
3 2
Output
500000004
500000004
625000005
187500002
187500002
Input
6 9
Output
500000004
500000004
500000004
500000004
500000004
500000004
929687507
218750002
224609377
303710940
633300786
694091802
172485353
411682132
411682132
"Correct Solution:
```
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
mod=10**9+7
b,w=map(int,input().split())
n=b+w
def power(x,n):
if n==0:
return 1
elif n%2:
return power(x,n//2)**2*x%mod
else:
return power(x,n//2)**2%mod
def modinv(n):
return power(n,mod-2)
factorial=[1]
for i in range(1,n+1):
factorial.append(factorial[i-1]*i%mod)
inverse=[0]*(n+1)
inverse[-1]=modinv(factorial[-1])
for i in range(n)[::-1]:
inverse[i]=inverse[i+1]*(i+1)%mod
def comb(n,r):
if n<r or r<0:
return 0
return factorial[n]*inverse[r]*inverse[n-r]%mod
Pb,Pw=[0]*n,[0]*n
inv2=modinv(2)
P=[1]*(n+1)
for i in range(1,n+1):
P[i]=P[i-1]*inv2%mod
for i in range(1,n):
Pb[i]=(Pb[i-1]+comb(i-1,b-1)*P[i])%mod
Pw[i]=(Pw[i-1]+comb(i-1,w-1)*P[i])%mod
for i in range(n):
print((1-Pb[i]+Pw[i])*inv2%mod)
```
| 104,242 |
Provide a correct Python 3 solution for this coding contest problem.
Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack.
He will repeat the following procedure until there is no piece left:
* Choose black or white with equal probability, and eat a piece of that color if it exists.
For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
Constraints
* All values in input are integers.
* 1 \leq B,W \leq 10^{5}
Input
Input is given from Standard Input in the following format:
B W
Output
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7.
Examples
Input
2 1
Output
500000004
750000006
750000006
Input
3 2
Output
500000004
500000004
625000005
187500002
187500002
Input
6 9
Output
500000004
500000004
500000004
500000004
500000004
500000004
929687507
218750002
224609377
303710940
633300786
694091802
172485353
411682132
411682132
"Correct Solution:
```
from collections import defaultdict
B,W = map(int,input().split())
mod = 10**9+7
fact = [0]*(10**6+1)
fact[0] = 1
for i in range(10**6):
fact[i+1] = fact[i]*(i+1)%mod
def comb_(n,k):
return fact[n]*pow(fact[k],mod-2,mod)*pow(fact[n-k],mod-2,mod)*pow(2,(n+1)*(mod-2),mod)%mod
f_B = defaultdict(lambda:pow(2,mod-2,mod))
f_W = defaultdict(lambda:pow(2,mod-2,mod))
g = defaultdict(lambda:pow(2,W*(mod-2),mod))
for i in range(B,B+W):
f_B[i+1] = f_B[i]-comb_(i-1,B-1)*pow(2,mod-2,mod)
f_B[i+1] %= mod
for i in range(W,B+W):
f_W[i+1] = f_W[i]-comb_(i-1,W-1)*pow(2,mod-2,mod)
f_W[i+1] %= mod
for i in range(W+1,B+W):
g[i+1] = g[i] + comb_(i-1,W-1)
g[i+1] %= mod
for i in range(1,B+W+1):
if i < W+1:
print(f_B[i])
else:
print((f_B[i]+f_W[i]+g[i]-pow(2,mod-2,mod))%mod)
```
| 104,243 |
Provide a correct Python 3 solution for this coding contest problem.
Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack.
He will repeat the following procedure until there is no piece left:
* Choose black or white with equal probability, and eat a piece of that color if it exists.
For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
Constraints
* All values in input are integers.
* 1 \leq B,W \leq 10^{5}
Input
Input is given from Standard Input in the following format:
B W
Output
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7.
Examples
Input
2 1
Output
500000004
750000006
750000006
Input
3 2
Output
500000004
500000004
625000005
187500002
187500002
Input
6 9
Output
500000004
500000004
500000004
500000004
500000004
500000004
929687507
218750002
224609377
303710940
633300786
694091802
172485353
411682132
411682132
"Correct Solution:
```
B,W=map(int,input().split())
N=B+W+2
mod=10**9+7
table=[1]*(N+3)
t=1
for i in range(1,N+3):
t*=i
t%=mod
table[i]=t
rtable=[1]*(N+3)
t=1
for i in range(1,N+3):
t*=pow(i,mod-2,mod)
t%=mod
rtable[i]=t
p=[0]*(B+W+1)
q=[0]*(B+W+1)
t=pow(2,mod-2,mod)
for i in range(W,B+W+1):
if i==W:
p[i]=pow(t,i,mod)
else:
p[i]=(p[i-1]+table[i-1]*rtable[W-1]*rtable[i-W]*pow(t,i,mod))%mod
#(table[i]*rtable[W]*table[i-W]*pow(t,i,mod))%mod
for i in range(B,B+W+1):
if i==B:
q[i]=pow(t,i,mod)
else:
q[i]=(q[i-1]+table[i-1]*rtable[B-1]*rtable[i-B]*pow(t,i,mod))%mod
#print(p,q)
for i in range(B+W):
ans=((1+p[i]-q[i])*pow(2,mod-2,mod))%mod
print(ans)
```
| 104,244 |
Provide a correct Python 3 solution for this coding contest problem.
Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack.
He will repeat the following procedure until there is no piece left:
* Choose black or white with equal probability, and eat a piece of that color if it exists.
For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
Constraints
* All values in input are integers.
* 1 \leq B,W \leq 10^{5}
Input
Input is given from Standard Input in the following format:
B W
Output
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7.
Examples
Input
2 1
Output
500000004
750000006
750000006
Input
3 2
Output
500000004
500000004
625000005
187500002
187500002
Input
6 9
Output
500000004
500000004
500000004
500000004
500000004
500000004
929687507
218750002
224609377
303710940
633300786
694091802
172485353
411682132
411682132
"Correct Solution:
```
b,w=map(int,input().split())
dp=[0]*(b+w)
dp[0]=1/2
mod=pow(10,9)+7
def cmb(n,r,mod):
if (r<0 or r>n):
return 0
r=min(r,n-r)
return g1[n]*g2[r]*g2[n-r]%mod
g1=[1,1] # g1[i]=i! % mod :階乗
g2=[1,1] # g2[i]=(i!)^(-1) % mod :階乗の逆元
inverse=[0,1]
for i in range(2,b+w+1):
g1.append((g1[-1]*i)%mod)
inverse.append((-inverse[mod%i]*(mod//i))%mod)
g2.append((g2[-1]*inverse[-1])%mod)
t1,t2=0,0
for i in range(1,1+b+w):
t=pow(2,mod-2,mod)
if i-b>0:
t1*=2
t1%=mod
t1+=cmb(i-2,b-1,mod)
t1%=mod
tmp=t1*pow(2,mod-1-i,mod)
tmp%=mod
t-=tmp
t%=mod
if i-w>0:
t2*=2
t2%=mod
t2+=cmb(i-2,w-1,mod)
t2%=mod
tmp=t2*pow(2,mod-1-i,mod)
tmp%=mod
t+=tmp
t%=mod
print(t)
```
| 104,245 |
Provide a correct Python 3 solution for this coding contest problem.
Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack.
He will repeat the following procedure until there is no piece left:
* Choose black or white with equal probability, and eat a piece of that color if it exists.
For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
Constraints
* All values in input are integers.
* 1 \leq B,W \leq 10^{5}
Input
Input is given from Standard Input in the following format:
B W
Output
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7.
Examples
Input
2 1
Output
500000004
750000006
750000006
Input
3 2
Output
500000004
500000004
625000005
187500002
187500002
Input
6 9
Output
500000004
500000004
500000004
500000004
500000004
500000004
929687507
218750002
224609377
303710940
633300786
694091802
172485353
411682132
411682132
"Correct Solution:
```
b,w = map(int,input().split())
flg = 0
if b>w:
flg = 1
b,w = w,b
elif b == w:
for _ in range(b+w):
print(500000004)
exit()
mod = 10**9+7
rng = 200100
fctr = [1]
finv = [1]
for i in range(1,rng):
fctr.append(fctr[-1]*i%mod)
def inv(a):
return pow(a,mod-2,mod)
def cmb(n,k):
if n<0 or k<0:
return 0
else:
return fctr[n]*inv(fctr[n-k])*inv(fctr[k])%mod
ans = [500000004]*b
nume = pow(2,b-1,mod)
domi = pow(2,b,mod)
for i in range(b+1,b+w+1):
domi = domi*2%mod
nume = nume*2-cmb(i-2,i-b-1)
if i >= w:
nume += cmb(i-2,i-w-1)
nume %= mod
x = nume*inv(domi)%mod
if flg:
ans.append(mod+1-x)
else:
ans.append(x)
print(*ans,sep="\n")
```
| 104,246 |
Provide a correct Python 3 solution for this coding contest problem.
Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack.
He will repeat the following procedure until there is no piece left:
* Choose black or white with equal probability, and eat a piece of that color if it exists.
For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
Constraints
* All values in input are integers.
* 1 \leq B,W \leq 10^{5}
Input
Input is given from Standard Input in the following format:
B W
Output
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7.
Examples
Input
2 1
Output
500000004
750000006
750000006
Input
3 2
Output
500000004
500000004
625000005
187500002
187500002
Input
6 9
Output
500000004
500000004
500000004
500000004
500000004
500000004
929687507
218750002
224609377
303710940
633300786
694091802
172485353
411682132
411682132
"Correct Solution:
```
# D より思い付きやすい気がする
class Combination:
def __init__(self, n_max, mod=10**9+7):
# O(n_max + log(mod))
self.mod = mod
f = 1
self.fac = fac = [f]
for i in range(1, n_max+1):
f = f * i % mod
fac.append(f)
f = pow(f, mod-2, mod)
self.facinv = facinv = [f]
for i in range(n_max, 0, -1):
f = f * i % mod
facinv.append(f)
facinv.reverse()
# "n 要素" は区別できる n 要素
# "k グループ" はちょうど k グループ
def __call__(self, n, r): # self.C と同じ
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def C(self, n, r):
if not 0 <= r <= n: return 0
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def P(self, n, r):
if not 0 <= r <= n: return 0
return self.fac[n] * self.facinv[n-r] % self.mod
def H(self, n, r):
if (n == 0 and r > 0) or r < 0: return 0
return self.fac[n+r-1] * self.facinv[r] % self.mod * self.facinv[n-1] % self.mod
def rising_factorial(self, n, r): # 上昇階乗冪 n * (n+1) * ... * (n+r-1)
return self.fac[n+r-1] * self.facinv[n-1] % self.mod
def stirling_first(self, n, k): # 第 1 種スターリング数 lru_cache を使うと O(nk) # n 要素を k 個の巡回列に分割する場合の数
if n == k: return 1
if k == 0: return 0
return (self.stirling_first(n-1, k-1) + (n-1)*self.stirling_first(n-1, k)) % self.mod
def stirling_second(self, n, k): # 第 2 種スターリング数 O(k + log(n)) # n 要素を区別のない k グループに分割する場合の数
if n == k: return 1 # n==k==0 のときのため
return self.facinv[k] * sum((-1)**(k-m) * self.C(k, m) * pow(m, n, self.mod) for m in range(1, k+1)) % self.mod
def balls_and_boxes_3(self, n, k): # n 要素を区別のある k グループに分割する場合の数 O(k + log(n))
return sum((-1)**(k-m) * self.C(k, m) * pow(m, n, self.mod) for m in range(1, k+1)) % self.mod
def bernoulli(self, n): # ベルヌーイ数 lru_cache を使うと O(n**2 * log(mod))
if n == 0: return 1
if n % 2 and n >= 3: return 0 # 高速化
return (- pow(n+1, self.mod-2, self.mod) * sum(self.C(n+1, k) * self.bernoulli(k) % self.mod for k in range(n))) % self.mod
def faulhaber(self, k, n): # べき乗和 0^k + 1^k + ... + (n-1)^k
# bernoulli に lru_cache を使うと O(k**2 * log(mod)) bernoulli が計算済みなら O(k * log(mod))
return pow(k+1, self.mod-2, self.mod) * sum(self.C(k+1, j) * self.bernoulli(j) % self.mod * pow(n, k-j+1, self.mod) % self.mod for j in range(k+1)) % self.mod
def lah(self, n, k): # n 要素を k 個の空でない順序付き集合に分割する場合の数 O(1)
return self.C(n-1, k-1) * self.fac[n] % self.mod * self.facinv[k] % self.mod
def bell(self, n, k): # n 要素を k グループ以下に分割する場合の数 O(k**2 + k*log(mod))
return sum(self.stirling_second(n, j) for j in range(1, k+1)) % self.mod
def main():
comb = Combination(2*10**5)
mod = 10**9+7
B, W = map(int, input().split())
L = [0] * (B+W+1)
for i in range(B, B+W):
L[i+1] = -comb(i, B)
for i in range(W, W+B):
L[i+1] = (L[i+1] + comb(i, W)) % mod
L_cum = [0] + L[:-1]
for i in range(1, B+W+1):
L_cum[i] = (L_cum[i] + 2 * L_cum[i-1]) % mod
Ans = []
p = 1
half = pow(2, mod-2, mod)
denom_inv = half
for l, l_cum in zip(L[1:], L_cum[1:]):
Ans.append((p+l+l_cum) * denom_inv % mod)
p = p * 2 % mod
denom_inv = denom_inv * half % mod
print("\n".join(map(str, Ans)))
main()
```
| 104,247 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack.
He will repeat the following procedure until there is no piece left:
* Choose black or white with equal probability, and eat a piece of that color if it exists.
For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
Constraints
* All values in input are integers.
* 1 \leq B,W \leq 10^{5}
Input
Input is given from Standard Input in the following format:
B W
Output
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7.
Examples
Input
2 1
Output
500000004
750000006
750000006
Input
3 2
Output
500000004
500000004
625000005
187500002
187500002
Input
6 9
Output
500000004
500000004
500000004
500000004
500000004
500000004
929687507
218750002
224609377
303710940
633300786
694091802
172485353
411682132
411682132
Submitted Solution:
```
INF = 1000000007
def ex_gcd(a, b):
x1, x2 = 0, 1
y1, y2 = 1, 0
q = 0
while b:
x1, x2 = x2, x1 - q * x2
y1, y2 = y2, y1 - q * y2
q = a // b
a, b = b, a % b
return a, x2, y2
def invert(x, mod=INF):
return ex_gcd(x, mod)[1] % mod
B, W = map(int, input().split())
p = 0
q = 0
c1, c2 = 0, 1
d1, d2 = 0, 1
s = 1
for k in range(1, B + W + 1):
if B + 1 < k:
c1 = c2
c2 *= invert((k - 1) - B) * (k - 1) % INF
c2 %= INF
if W + 1 < k:
d1 = d2
d2 *= invert((k - 1) - W) * (k - 1) % INF
d2 %= INF
if B < k:
p += (c2 - c1) * s % INF
p %= INF
if W < k:
q += (d2 - d1) * s % INF
q %= INF
print((q + invert(2) * (1 - p - q)) % INF)
s *= invert(2)
s %= INF
```
Yes
| 104,248 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack.
He will repeat the following procedure until there is no piece left:
* Choose black or white with equal probability, and eat a piece of that color if it exists.
For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
Constraints
* All values in input are integers.
* 1 \leq B,W \leq 10^{5}
Input
Input is given from Standard Input in the following format:
B W
Output
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7.
Examples
Input
2 1
Output
500000004
750000006
750000006
Input
3 2
Output
500000004
500000004
625000005
187500002
187500002
Input
6 9
Output
500000004
500000004
500000004
500000004
500000004
500000004
929687507
218750002
224609377
303710940
633300786
694091802
172485353
411682132
411682132
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 30 22:26:37 2019
@author: Owner
"""
MOD = 1000000007
def inv(x):
return pow(x, MOD - 2, MOD)
B, W = map(int, input().split())
fct = [1] * (B + W + 1)
for i in range(B + W):
fct[i + 1] = (fct[i] * (i + 1)) % MOD
def c(n, k):
return (fct[n] * inv(fct[k]) * inv(fct[n - k])) % MOD
#p[i]: 黒B回白i回の確率
#q[i]: 黒i回白W回の確率
p = [0] * W
p[0] = inv(pow(2, B, MOD))
for i in range(W - 1):
p[i + 1] = (p[i] + c(B + i, i + 1) * inv(pow(2, B + i, MOD)) * inv(2)) % MOD
q = [0] * B
q[0] = inv(pow(2, W, MOD))
for i in range(B - 1):
q[i + 1] = (q[i] + c(W + i, i + 1) * inv(pow(2, W + i, MOD)) * inv(2)) % MOD
for i in range(B + W):
if i < min(B, W):
print(inv(2))
continue
if i >= max(B, W):
print((q[i - W] + (1 - p[i - B] - q[i - W] + MOD) * inv(2)) % MOD)
continue
if B < W:
print(((1 - p[i - B] + MOD) * inv(2)) % MOD)
else:
print((q[i - W] + (1 - q[i - W] + MOD) * inv(2)) % MOD)
```
Yes
| 104,249 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack.
He will repeat the following procedure until there is no piece left:
* Choose black or white with equal probability, and eat a piece of that color if it exists.
For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
Constraints
* All values in input are integers.
* 1 \leq B,W \leq 10^{5}
Input
Input is given from Standard Input in the following format:
B W
Output
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7.
Examples
Input
2 1
Output
500000004
750000006
750000006
Input
3 2
Output
500000004
500000004
625000005
187500002
187500002
Input
6 9
Output
500000004
500000004
500000004
500000004
500000004
500000004
929687507
218750002
224609377
303710940
633300786
694091802
172485353
411682132
411682132
Submitted Solution:
```
Q = 10**9+7
def getInv(N):#Qはmod
inv = [0] * (N + 1)
inv[0] = 1
inv[1] = 1
for i in range(2, N + 1):
inv[i] = (-(Q // i) * inv[Q%i]) % Q
return inv
B, W = map( int, input().split())
Z = getInv(B+W)
I = [1]*(B+W+1)
for i in range(1,B+W+1):
I[i] = (I[i-1]*Z[i])%Q
F = [1]*(B+W+1)
for i in range(1,B+W+1):
F[i] = F[i-1]*i%Q
w = 0
b = 0
for i in range(1,B+W+1):
if i - 1 < B and i - 1 < W:
print(I[2])
# elif i - 1 == W and i - 1< B:
# w = pow(I[2],i-1,Q)
# print(((1 - w)%Q*I[2]%Q + w)%Q)
elif i - 1 >= W and i - 1< B: #i > B
w += F[i-2]*I[i-1-W]%Q*I[W-1]%Q*pow(I[2],i-1,Q)%Q
w %= Q
print(((1 - w)%Q*I[2]%Q + w)%Q)
# elif i - 1 == B and i - 1 < W:
# b = pow(I[2],i-1,Q)
# print((1-b)%Q*I[2]%Q)
elif i - 1 >= B and i - 1 < W: #i > W
b += F[i-2]*I[i-1-B]%Q*I[B-1]%Q*pow(I[2],i-1,Q)%Q
b %= Q
print((1-b)%Q*I[2]%Q)
# elif i - 1 == B and i - 1 == W:
# w = pow(I[2],i-1,Q)
# b = pow(I[2],i-1,Q)
# print(((1 - w - b)%Q*I[2]%Q + w)%Q)
else:
w += F[i-2]*I[i-1-W]%Q*I[W-1]%Q*pow(I[2],i-1,Q)%Q
w %= Q
b += F[i-2]*I[i-1-B]%Q*I[B-1]%Q*pow(I[2],i-1,Q)%Q
b %= Q
print(((1 - w - b)%Q*I[2]%Q + w)%Q)
```
Yes
| 104,250 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack.
He will repeat the following procedure until there is no piece left:
* Choose black or white with equal probability, and eat a piece of that color if it exists.
For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
Constraints
* All values in input are integers.
* 1 \leq B,W \leq 10^{5}
Input
Input is given from Standard Input in the following format:
B W
Output
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7.
Examples
Input
2 1
Output
500000004
750000006
750000006
Input
3 2
Output
500000004
500000004
625000005
187500002
187500002
Input
6 9
Output
500000004
500000004
500000004
500000004
500000004
500000004
929687507
218750002
224609377
303710940
633300786
694091802
172485353
411682132
411682132
Submitted Solution:
```
def cmb(n, r):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
b,w=map(int,input().split())
x=0
y=0
for i in range(1,b+w+1):
x=(x*2+cmb(i-2,b-1))%mod
y=(y*2+cmb(i-2,w-1))%mod
print((mod+pow(2,i-1,mod)-x+y)*pow(pow(2,i,mod),mod-2,mod)%mod)
```
Yes
| 104,251 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack.
He will repeat the following procedure until there is no piece left:
* Choose black or white with equal probability, and eat a piece of that color if it exists.
For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
Constraints
* All values in input are integers.
* 1 \leq B,W \leq 10^{5}
Input
Input is given from Standard Input in the following format:
B W
Output
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7.
Examples
Input
2 1
Output
500000004
750000006
750000006
Input
3 2
Output
500000004
500000004
625000005
187500002
187500002
Input
6 9
Output
500000004
500000004
500000004
500000004
500000004
500000004
929687507
218750002
224609377
303710940
633300786
694091802
172485353
411682132
411682132
Submitted Solution:
```
B, W = list(map(int, input().split()))
MOD = 10**9+7
def MakeCombList(n,r, MOD): #iCrをi=0...nまで
ret = []
for i in range(n):
if i < r:
ret = ret+[0]
elif i == r:
ret = ret+[1]
else:
ret = ret+[ int(ret[-1]*(i)/(i-r)) % MOD]
return ret
combB1 = MakeCombList(B+W, B-1, MOD)
combW1 = MakeCombList(B+W, W-1, MOD)
pow2list = [1]
y_pi = 0 #i回目までにBを食べ尽くした確率piの分子
y_qi = 0 #i回目までにWを食べ尽くした確率qiの分子
for i in range(B+W):
pow2list += [pow2list[-1]*2 %MOD]
y_pi = 0 if i < B else 2*y_pi + combB1[i-1]
y_qi = 0 if i < W else 2*y_qi + combW1[i-1]
xi = pow2list[i+1]
yi = (pow2list[i]-y_pi+y_qi) % MOD
z = yi*pow(xi, MOD-2, MOD) % MOD
#print("{}/{}: {}".format(yi,xi,z))
print(z)
```
No
| 104,252 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack.
He will repeat the following procedure until there is no piece left:
* Choose black or white with equal probability, and eat a piece of that color if it exists.
For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
Constraints
* All values in input are integers.
* 1 \leq B,W \leq 10^{5}
Input
Input is given from Standard Input in the following format:
B W
Output
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7.
Examples
Input
2 1
Output
500000004
750000006
750000006
Input
3 2
Output
500000004
500000004
625000005
187500002
187500002
Input
6 9
Output
500000004
500000004
500000004
500000004
500000004
500000004
929687507
218750002
224609377
303710940
633300786
694091802
172485353
411682132
411682132
Submitted Solution:
```
B,W = map(int, input().split())
N = B+W
factorial = [1]
for i in range(N+1):
factorial.append( factorial[-1] * (i+1))
# print(factorial)
mod = 10**9+7
de_factorial = [0] * (N+1)
de_factorial[N] = pow( factorial[N] , mod-2, mod )
for i in range( N, 0, -1):
de_factorial[i-1] = de_factorial[i] * i % mod
def comb(n,r):
if n < r: return 0
if n == r: return 1
return (factorial[n] * de_factorial[r] * de_factorial[n-r]) % mod
p = [0] * (N+1) # Bを食べきった確率
q = [0] * (N+1) # Wを食べきった確率
de2 = de_factorial[2]
for i in range(1, N+1):
p[i] = p[i-1] + comb(i-1 ,B-1) * de2 % mod
q[i] = q[i-1] + comb(i-1 ,W-1) * de2 % mod
de2 = de2 * de_factorial[2] % mod
tmp = ( q[i-1] + 1-p[i-1] ) * de_factorial[2] % mod
print(tmp)
```
No
| 104,253 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack.
He will repeat the following procedure until there is no piece left:
* Choose black or white with equal probability, and eat a piece of that color if it exists.
For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
Constraints
* All values in input are integers.
* 1 \leq B,W \leq 10^{5}
Input
Input is given from Standard Input in the following format:
B W
Output
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7.
Examples
Input
2 1
Output
500000004
750000006
750000006
Input
3 2
Output
500000004
500000004
625000005
187500002
187500002
Input
6 9
Output
500000004
500000004
500000004
500000004
500000004
500000004
929687507
218750002
224609377
303710940
633300786
694091802
172485353
411682132
411682132
Submitted Solution:
```
from functools import lru_cache
import sys
sys.setrecursionlimit(2*10**5)
# 入力
B, W = map(int, input().split())
# ModInt定義
MOD = 10**9 + 7
def mod_operator(ope):
def operate(self, other):
return (
ModInt(ope(self.x, other.x)) if isinstance(other, ModInt) else
ModInt(ope(self.x, other))
)
return operate
class ModInt:
def __init__(self, x):
self.x = x % MOD
def __str__(self):
return str(self.x)
def __repr__(self):
return str(self.x)
__add__ = mod_operator(lambda x, y: x + y)
__radd__ = __add__
__sub__ = mod_operator(lambda x, y: x - y)
__rsub__ = __sub__
__mul__ = mod_operator(lambda x, y: x * y)
__rmul__ = __mul__
__truediv__ = mod_operator(lambda x, y: x * pow(y, MOD - 2, MOD))
__rtruediv__ = __truediv__
__pow__ = mod_operator(lambda x, y: pow(x, y, MOD))
__rpow__ = __pow__
# 最初にm個あったチョコレートについて、i番目までにすべて食べきる確率と確率の計算に必要な二項係数を返す
@lru_cache(maxsize=None)
def p(i, m):
if i < m:
return ModInt(0), ModInt(0)
elif i == m:
return ModInt(1) / ModInt(2**i), ModInt(1)
else:
x, y = p(i - 1, m)
c = y * (i - 1) / (i - m)
return x + c / 2**i, c
# i番目の解は i-1番目までに白チョコレートが枯渇している確率 +
# i-1番目までにどちらのチョコレートも枯渇しない確率 / 2
ans = '\n'.join(
str((1 + p(i - 1, W)[0] - p(i - 1, B)[0]) / 2)
for i in range(1, B + W + 1)
)
# 出力
print(ans)
```
No
| 104,254 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack.
He will repeat the following procedure until there is no piece left:
* Choose black or white with equal probability, and eat a piece of that color if it exists.
For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
Constraints
* All values in input are integers.
* 1 \leq B,W \leq 10^{5}
Input
Input is given from Standard Input in the following format:
B W
Output
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7.
Examples
Input
2 1
Output
500000004
750000006
750000006
Input
3 2
Output
500000004
500000004
625000005
187500002
187500002
Input
6 9
Output
500000004
500000004
500000004
500000004
500000004
500000004
929687507
218750002
224609377
303710940
633300786
694091802
172485353
411682132
411682132
Submitted Solution:
```
B, W = list(map(int, input().split()))
mod = 1000000007
def mul(a, b):
return ((a % mod) * (b % mod)) % mod
def power(x, y):
#print(x,y)
if y == 0 : return 1
elif y == 1 : return x % mod
elif y % 2 == 0 : return power(x, y/2)**2 % mod
else : return power(x, y//2)**2 * x % mod
def div(a, b):
return mul(a, power(b, mod-2))
#from fractions import gcd
#B-1列目
B_1 = [0]*(B) + [1]*(W+1)
for i in range(B, W+B):
#print(i)
B_1[i+1]=(B_1[i]*(i))//(i-B+1)
#print(B_1)
#print(B_1)
#B列目
B_0 = [0]*(B) + [1]*(W+1)
for i in range(B, W+B):
B_0[i+1]=B_0[i]*2 + B_1[i+1]
#print(B_0)
#W-1列目
W_1 = [0]*(W) + [1]*(B+1)
for i in range(W, W+B):
W_1[i+1]=W_1[i]*(i)//(i-W+1)
#print(W_1)
#W列目
W_0 = [0]*(W) + [1]*(B+1)
for i in range(W, W+B):
W_0[i+1]=W_0[i]*2 + W_1[i+1]
#print(W_0)
#分母
log2M = [i for i in range(W+B)]
#print(log2M)
for i in range(B+W):
b = B_0[i]
w = W_0[i]
log2m = log2M[i]
#print(b,w,log2m)
while not b%2 and not w%2 and log2m:
b=b//2
w=w//2
log2m-=1
#print(b,w,log2m)
#print(2**log2m - b + w)
#print(2**(log2m+1))
# (2**(log2m+1) -b + w) /2**(log2m+1) = y/x
# answer = y / x (mod)
p = power(2, (mod-2)*(log2m+1))
a = (mul(power(2,log2m),p) - mul(b,p) + mul(w,p))%mod
print(a)
```
No
| 104,255 |
Provide a correct Python 3 solution for this coding contest problem.
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi:
* If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.
Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
Constraints
* 1 \leq A,B \leq 10^9
* 1 \leq K \leq 100
* A,B and K are integers.
Input
Input is given from Standard Input in the following format:
A B K
Output
Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing K operations in total.
Examples
Input
5 4 2
Output
5 3
Input
3 3 3
Output
1 3
Input
314159265 358979323 84
Output
448759046 224379523
"Correct Solution:
```
A,B,K=map(int,input().split())
for i in range(K):
A//=2
B+=A
A,B=B,A
if(K%2):
A,B=B,A
print(A,B)
```
| 104,256 |
Provide a correct Python 3 solution for this coding contest problem.
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi:
* If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.
Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
Constraints
* 1 \leq A,B \leq 10^9
* 1 \leq K \leq 100
* A,B and K are integers.
Input
Input is given from Standard Input in the following format:
A B K
Output
Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing K operations in total.
Examples
Input
5 4 2
Output
5 3
Input
3 3 3
Output
1 3
Input
314159265 358979323 84
Output
448759046 224379523
"Correct Solution:
```
a,b,k = map(int,input().split())
tmp=1
for i in range(k):
if tmp==1:
b+=a//2
a=a//2
tmp=2
else:
a+=b//2
b=b//2
tmp=1
print(a,b)
```
| 104,257 |
Provide a correct Python 3 solution for this coding contest problem.
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi:
* If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.
Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
Constraints
* 1 \leq A,B \leq 10^9
* 1 \leq K \leq 100
* A,B and K are integers.
Input
Input is given from Standard Input in the following format:
A B K
Output
Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing K operations in total.
Examples
Input
5 4 2
Output
5 3
Input
3 3 3
Output
1 3
Input
314159265 358979323 84
Output
448759046 224379523
"Correct Solution:
```
A, B, K = map(int,input().split())
for i in range(K):
if i % 2 == 0:
A = A // 2
B += A
else:
B = B // 2
A += B
print(int(A), int(B))
```
| 104,258 |
Provide a correct Python 3 solution for this coding contest problem.
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi:
* If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.
Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
Constraints
* 1 \leq A,B \leq 10^9
* 1 \leq K \leq 100
* A,B and K are integers.
Input
Input is given from Standard Input in the following format:
A B K
Output
Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing K operations in total.
Examples
Input
5 4 2
Output
5 3
Input
3 3 3
Output
1 3
Input
314159265 358979323 84
Output
448759046 224379523
"Correct Solution:
```
A, B, K = map(int, input().split())
for i in range(K):
if i % 2 == 0:
A, B = A//2, A//2+B
else:
A, B = A+B//2, B//2
print(A,B)
```
| 104,259 |
Provide a correct Python 3 solution for this coding contest problem.
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi:
* If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.
Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
Constraints
* 1 \leq A,B \leq 10^9
* 1 \leq K \leq 100
* A,B and K are integers.
Input
Input is given from Standard Input in the following format:
A B K
Output
Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing K operations in total.
Examples
Input
5 4 2
Output
5 3
Input
3 3 3
Output
1 3
Input
314159265 358979323 84
Output
448759046 224379523
"Correct Solution:
```
A, B, K = [int(s) for s in input().split(' ')]
for i in range(K):
if i % 2:
B //= 2
A += B
else:
A //= 2
B += A
print ('%d %d' % (A, B))
```
| 104,260 |
Provide a correct Python 3 solution for this coding contest problem.
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi:
* If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.
Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
Constraints
* 1 \leq A,B \leq 10^9
* 1 \leq K \leq 100
* A,B and K are integers.
Input
Input is given from Standard Input in the following format:
A B K
Output
Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing K operations in total.
Examples
Input
5 4 2
Output
5 3
Input
3 3 3
Output
1 3
Input
314159265 358979323 84
Output
448759046 224379523
"Correct Solution:
```
a,b,k = [int(x) for x in input().split()]
for i in range(k):
if i%2:
a += b//2
b = b//2
else:
b += a//2
a = a//2
print(a,b)
```
| 104,261 |
Provide a correct Python 3 solution for this coding contest problem.
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi:
* If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.
Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
Constraints
* 1 \leq A,B \leq 10^9
* 1 \leq K \leq 100
* A,B and K are integers.
Input
Input is given from Standard Input in the following format:
A B K
Output
Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing K operations in total.
Examples
Input
5 4 2
Output
5 3
Input
3 3 3
Output
1 3
Input
314159265 358979323 84
Output
448759046 224379523
"Correct Solution:
```
a,b,k = map(int,input().split())
for i in range(k):
if i%2 == 0:
if a%2 != 0 :
a -=1
a /= 2
b += a
else :
if b%2 != 0:
b -= 1
b /= 2
a += b
print(int(a),int(b))
```
| 104,262 |
Provide a correct Python 3 solution for this coding contest problem.
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi:
* If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.
Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
Constraints
* 1 \leq A,B \leq 10^9
* 1 \leq K \leq 100
* A,B and K are integers.
Input
Input is given from Standard Input in the following format:
A B K
Output
Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing K operations in total.
Examples
Input
5 4 2
Output
5 3
Input
3 3 3
Output
1 3
Input
314159265 358979323 84
Output
448759046 224379523
"Correct Solution:
```
A,B,K=map(int,input().split())
for i in range(K):
if i%2==0:
B+=A//2
A=A//2
else:
A+=B//2
B=B//2
print(A,B)
```
| 104,263 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi:
* If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.
Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
Constraints
* 1 \leq A,B \leq 10^9
* 1 \leq K \leq 100
* A,B and K are integers.
Input
Input is given from Standard Input in the following format:
A B K
Output
Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing K operations in total.
Examples
Input
5 4 2
Output
5 3
Input
3 3 3
Output
1 3
Input
314159265 358979323 84
Output
448759046 224379523
Submitted Solution:
```
a,b,k = list(map(int, input().split()))
for i in range(k):
if i%2 == 0:
if a%2==1: a-=1
b += a//2
a //= 2
else:
if b%2==1: b-=1
a += b//2
b //= 2
print(a, b)
```
Yes
| 104,264 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi:
* If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.
Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
Constraints
* 1 \leq A,B \leq 10^9
* 1 \leq K \leq 100
* A,B and K are integers.
Input
Input is given from Standard Input in the following format:
A B K
Output
Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing K operations in total.
Examples
Input
5 4 2
Output
5 3
Input
3 3 3
Output
1 3
Input
314159265 358979323 84
Output
448759046 224379523
Submitted Solution:
```
a,b,k = [int(x) for x in input().split()]
def func(x,y):
x = x//2
y += x
return x,y
for i in range(k):
if i%2 == 0:
a,b = func(a,b)
else:
b,a = func(b,a)
print(a, b)
```
Yes
| 104,265 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi:
* If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.
Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
Constraints
* 1 \leq A,B \leq 10^9
* 1 \leq K \leq 100
* A,B and K are integers.
Input
Input is given from Standard Input in the following format:
A B K
Output
Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing K operations in total.
Examples
Input
5 4 2
Output
5 3
Input
3 3 3
Output
1 3
Input
314159265 358979323 84
Output
448759046 224379523
Submitted Solution:
```
A, B, K = tuple(map(int, input().split(" ")))
for k in range(K):
if k % 2 == 0:
A = A // 2
B += A
else:
B = B // 2
A += B
print(A, B)
```
Yes
| 104,266 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi:
* If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.
Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
Constraints
* 1 \leq A,B \leq 10^9
* 1 \leq K \leq 100
* A,B and K are integers.
Input
Input is given from Standard Input in the following format:
A B K
Output
Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing K operations in total.
Examples
Input
5 4 2
Output
5 3
Input
3 3 3
Output
1 3
Input
314159265 358979323 84
Output
448759046 224379523
Submitted Solution:
```
a,b,k=[int(x) for x in input().split()]
for i in range(k):
if i%2:
b//=2
a+=b
else:
a//=2
b+=a
print(a,b)
```
Yes
| 104,267 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi:
* If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.
Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
Constraints
* 1 \leq A,B \leq 10^9
* 1 \leq K \leq 100
* A,B and K are integers.
Input
Input is given from Standard Input in the following format:
A B K
Output
Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing K operations in total.
Examples
Input
5 4 2
Output
5 3
Input
3 3 3
Output
1 3
Input
314159265 358979323 84
Output
448759046 224379523
Submitted Solution:
```
A, B, K = map(int,input().rstrip().split())
for i in range(K):
if i % 2 == 0:
B = B + A/2
A = A/2
else:
A = A + B/2
B = B/2
print ('{} {}'.format(A,B))
```
No
| 104,268 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi:
* If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.
Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
Constraints
* 1 \leq A,B \leq 10^9
* 1 \leq K \leq 100
* A,B and K are integers.
Input
Input is given from Standard Input in the following format:
A B K
Output
Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing K operations in total.
Examples
Input
5 4 2
Output
5 3
Input
3 3 3
Output
1 3
Input
314159265 358979323 84
Output
448759046 224379523
Submitted Solution:
```
A, B, K = map(int, input().split())
for i in range(K):
if i % 2 == 0:
B = B + A/2
A = A/2
else:
A = A + B/2
B = B/2
print ('{} {}'.format(A,B))
```
No
| 104,269 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi:
* If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.
Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
Constraints
* 1 \leq A,B \leq 10^9
* 1 \leq K \leq 100
* A,B and K are integers.
Input
Input is given from Standard Input in the following format:
A B K
Output
Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing K operations in total.
Examples
Input
5 4 2
Output
5 3
Input
3 3 3
Output
1 3
Input
314159265 358979323 84
Output
448759046 224379523
Submitted Solution:
```
a, b, k = map(int, input().split(' '))
for i in range(0, k):
if i % 2 == 0:
if a % 2 != 0:
a -= 1
b += a // 2
a -= a/2
else:
if b % 2 != 0:
b -= 1
a += b // 2
b -= b/2
print(f'{max(0,a)} {max(0,b)}')
```
No
| 104,270 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi:
* If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.
Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
Constraints
* 1 \leq A,B \leq 10^9
* 1 \leq K \leq 100
* A,B and K are integers.
Input
Input is given from Standard Input in the following format:
A B K
Output
Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing K operations in total.
Examples
Input
5 4 2
Output
5 3
Input
3 3 3
Output
1 3
Input
314159265 358979323 84
Output
448759046 224379523
Submitted Solution:
```
a,b,c=map(int,input().split())
if c%2==0:
for _ in range(int(c/2)):
if a %2 == 0:
d=0
else:
a=(a-1)
a=a/2
b=a + b
if b%2== 0:
d=0
else:
b=(b-1)
b=b/2
a+=b
print(int(a),int(b))
else:
if c%2==1:
for _ in range(int(c/2)):
if a %2 == 0:
d=0
else:
a=(a-1)
a=a/2
b=a + b
if b%2== 0:
d=0
else:
b=(b-1)
b=b/2
a+=b
if a %2 == 0:
d=0
else:
a=(a-1)
a=a/2
b=a + b
print(int(a),int(b))
```
No
| 104,271 |
Provide a correct Python 3 solution for this coding contest problem.
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts.
The recipes of these doughnuts are developed by repeated modifications from the recipe of Doughnut 1. Specifically, the recipe of Doughnut i (2 ≤ i ≤ N) is a direct modification of the recipe of Doughnut p_i (1 ≤ p_i < i).
Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:
* Let c_i be the number of Doughnut i (1 ≤ i ≤ N) that she makes. For each integer i such that 2 ≤ i ≤ N, c_{p_i} ≤ c_i ≤ c_{p_i} + D must hold. Here, D is a predetermined value.
At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto.
Constraints
* 2 ≤ N ≤ 50
* 1 ≤ X ≤ 10^9
* 0 ≤ D ≤ 10^9
* 1 ≤ m_i ≤ 10^9 (1 ≤ i ≤ N)
* 1 ≤ p_i < i (2 ≤ i ≤ N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X D
m_1
m_2 p_2
:
m_N p_N
Output
Print the maximum number of doughnuts that can be made under the condition.
Examples
Input
3 100 1
15
10 1
20 1
Output
7
Input
3 100 10
15
10 1
20 1
Output
10
Input
5 1000000000 1000000
123
159 1
111 1
135 3
147 3
Output
7496296
"Correct Solution:
```
N, X, D = map(int, input().split())
M = [0]*N
M[0] = int(input())
P = [0]*N
for i in range(N-1):
M[i+1], P[i+1] = map(int, input().split())
C = [1]*N
for i in range(N-1, 0, -1):
p = P[i]-1
C[p] += C[i]
M[p] += M[i]
L = [D]*N
L[0] = X
from collections import deque
def solve(N, W, ws, vs, ms):
V0 = max(vs)
V = sum(v * min(V0, m) for v, m in zip(vs, ms))
dp = [W+1]*(V + 1)
dp[0] = 0
for i in range(N):
v = vs[i]; w = ws[i]; m = ms[i]
c = min(V0, m)
ms[i] -= c
for k in range(v):
que = deque()
push = que.append
popf = que.popleft; popb = que.pop
for j in range((V-k)//v+1):
a = dp[k + j*v] - j * w
while que and a <= que[-1][1]:
popb()
push((j, a))
p, b = que[0]
dp[k + j*v] = b + j * w
if que and p <= j-c:
popf()
*I, = range(N)
I.sort(key=lambda x: ws[x]/vs[x])
*S, = [(vs[i], ws[i], ms[i]) for i in I]
def greedy():
yield 0
for i in range(V + 1):
if dp[i] > W:
continue
rest = W - dp[i]
r = i
for v, w, m in S:
m = min(m, rest // w)
r += m * v
rest -= m * w
yield r
return max(greedy())
print(solve(N, X, M, C, L))
```
| 104,272 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts.
The recipes of these doughnuts are developed by repeated modifications from the recipe of Doughnut 1. Specifically, the recipe of Doughnut i (2 ≤ i ≤ N) is a direct modification of the recipe of Doughnut p_i (1 ≤ p_i < i).
Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:
* Let c_i be the number of Doughnut i (1 ≤ i ≤ N) that she makes. For each integer i such that 2 ≤ i ≤ N, c_{p_i} ≤ c_i ≤ c_{p_i} + D must hold. Here, D is a predetermined value.
At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto.
Constraints
* 2 ≤ N ≤ 50
* 1 ≤ X ≤ 10^9
* 0 ≤ D ≤ 10^9
* 1 ≤ m_i ≤ 10^9 (1 ≤ i ≤ N)
* 1 ≤ p_i < i (2 ≤ i ≤ N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X D
m_1
m_2 p_2
:
m_N p_N
Output
Print the maximum number of doughnuts that can be made under the condition.
Examples
Input
3 100 1
15
10 1
20 1
Output
7
Input
3 100 10
15
10 1
20 1
Output
10
Input
5 1000000000 1000000
123
159 1
111 1
135 3
147 3
Output
7496296
Submitted Solution:
```
#!/usr/bin/env python3
INF = 2 * 10 ** 9
def solve(n, x, d, ma, pa):
v = [1] * n
w = [0] * n
for i in range(n - 1, -1, -1):
w[i] += ma[i]
if 0 <= pa[i]:
v[pa[i]] += v[i]
w[pa[i]] += w[i]
if d == 0:
return (x // w[0]) * n
c_0 = max(0, x - sum(w[1:]) * d + w[0] - 1) // w[0]
ans = n * c_0
y = w[0] * c_0
mean_w = [None] * n
for i in range(n):
mean_w[i] = (w[i] / v[i], i)
mean_w.sort()
t = [0] * n
llj = lj = -1
for i in range(n):
_, j = mean_w[i]
if j == 0:
t[0] = (x - y) // w[0]
y += w[0] * t[0]
lj = 0
break
if x <= y + w[j] * d:
t[j] = (x - y) // w[j]
y += w[j] * t[j]
lj = j
break
y += w[j] * d
t[j] = d
llj = j
c_max = min(n, d)
if c_max <= t[lj]:
y -= w[lj] * c_max
t[lj] -= c_max
else:
y -= w[lj] * t[lj]
t[lj] = 0
if llj != -1:
y -= w[llj] * c_max
t[llj] -= c_max
ans += sum([v[j] * t[j] for j in range(n)])
j_max = c_max * n * n
v_max = 0
rx = x - y
dp = [[0] + [INF] * j_max for _ in range(n)]
for j in range(1, j_max // n + 1):
dp[0][n * j] = ndp = w[0] * j
if ndp <= rx:
v_max = n * j
for i in range(1, n):
vi = v[i]
wi = w[i]
for j in range(1, j_max + 1):
ndp = dp[i - 1][j]
nj = j
w_sum = 0
for k in range(1, min(c_max, d - t[i])):
nj -= vi
w_sum += wi
if nj < 0:
break
ndp = min(ndp, dp[i - 1][nj] + w_sum)
dp[i][j] = ndp
if ndp <= rx:
if v_max < j:
v_max = j
ans += v_max
return ans
def main():
n, x, d = input().split()
n = int(n)
x = int(x)
d = int(d)
ma = []
pa = []
m = input()
m = int(m)
ma.append(m)
pa.append(-1)
for _ in range(n - 1):
m, p = input().split()
m = int(m)
ma.append(m)
p = int(p) - 1
pa.append(p)
print(solve(n, x, d, ma, pa))
if __name__ == '__main__':
main()
```
No
| 104,273 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts.
The recipes of these doughnuts are developed by repeated modifications from the recipe of Doughnut 1. Specifically, the recipe of Doughnut i (2 ≤ i ≤ N) is a direct modification of the recipe of Doughnut p_i (1 ≤ p_i < i).
Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:
* Let c_i be the number of Doughnut i (1 ≤ i ≤ N) that she makes. For each integer i such that 2 ≤ i ≤ N, c_{p_i} ≤ c_i ≤ c_{p_i} + D must hold. Here, D is a predetermined value.
At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto.
Constraints
* 2 ≤ N ≤ 50
* 1 ≤ X ≤ 10^9
* 0 ≤ D ≤ 10^9
* 1 ≤ m_i ≤ 10^9 (1 ≤ i ≤ N)
* 1 ≤ p_i < i (2 ≤ i ≤ N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X D
m_1
m_2 p_2
:
m_N p_N
Output
Print the maximum number of doughnuts that can be made under the condition.
Examples
Input
3 100 1
15
10 1
20 1
Output
7
Input
3 100 10
15
10 1
20 1
Output
10
Input
5 1000000000 1000000
123
159 1
111 1
135 3
147 3
Output
7496296
Submitted Solution:
```
#!/usr/bin/env python3
import math
def dfs_vw(g, m, u, value, weight):
v = 1
w = m[u]
for c in g[u]:
dfs_vw(g, m, c, value, weight)
v += value[c]
w += weight[c]
value[u] = v
weight[u] = w
def dfs(n, x, d, s, j, sum_v, best):
_, v, i, w = s[j]
r_best = sum_v + math.floor(v * x / w)
if r_best < best:
return best, False
max_y = x // w
if 0 < i:
max_y = min(max_y, d)
best = max(best, sum_v + max_y * v)
if j < n - 1:
nj = j + 1
for y in range(max_y, max(max_y - n, 0) - 1, -1):
best, f = dfs(n, x - y * w, d, s, nj, sum_v + y * v, best)
if not f:
break
return best, True
def solve(n, x, d, m, g):
value = [1] * n
weight = [0] * n
dfs_vw(g, m, 0, value, weight)
s = [(weight[i] / value[i], value[i], i, weight[i]) for i in range(n)]
s.sort()
ans, _ = dfs(n, x, d, s, 0, 0, 0)
return ans
def main():
n, x, d = input().split()
n = int(n)
x = int(x)
d = int(d)
m = []
g = [[] for _ in range(n)]
mi = input()
mi = int(mi)
m.append(mi)
for i in range(1, n):
mi, pi = input().split()
mi = int(mi)
pi = int(pi) - 1
m.append(mi)
g[pi].append(i)
print(solve(n, x, d, m, g))
if __name__ == '__main__':
main()
```
No
| 104,274 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts.
The recipes of these doughnuts are developed by repeated modifications from the recipe of Doughnut 1. Specifically, the recipe of Doughnut i (2 ≤ i ≤ N) is a direct modification of the recipe of Doughnut p_i (1 ≤ p_i < i).
Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:
* Let c_i be the number of Doughnut i (1 ≤ i ≤ N) that she makes. For each integer i such that 2 ≤ i ≤ N, c_{p_i} ≤ c_i ≤ c_{p_i} + D must hold. Here, D is a predetermined value.
At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto.
Constraints
* 2 ≤ N ≤ 50
* 1 ≤ X ≤ 10^9
* 0 ≤ D ≤ 10^9
* 1 ≤ m_i ≤ 10^9 (1 ≤ i ≤ N)
* 1 ≤ p_i < i (2 ≤ i ≤ N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X D
m_1
m_2 p_2
:
m_N p_N
Output
Print the maximum number of doughnuts that can be made under the condition.
Examples
Input
3 100 1
15
10 1
20 1
Output
7
Input
3 100 10
15
10 1
20 1
Output
10
Input
5 1000000000 1000000
123
159 1
111 1
135 3
147 3
Output
7496296
Submitted Solution:
```
#!/usr/bin/env python3
import math
def dfs_vw(g, m, u, value, weight):
v = 1
w = m[u]
for c in g[u]:
dfs_vw(g, m, c, value, weight)
v += value[c]
w += weight[c]
value[u] = v
weight[u] = w
def dfs(n, x, d, s, j, sum_v, best):
_, v, i, w = s[j]
r_best = sum_v + math.floor(v * x / w)
if r_best <= best:
return best, False
max_y = x // w
if 0 < i:
max_y = min(max_y, d)
best = max(best, sum_v + max_y * v)
if j < n - 1:
nj = j + 1
for y in range(max_y, max(max_y - n, 0) - 1, -1):
best, f = dfs(n, x - y * w, d, s, nj, sum_v + y * v, best)
if not f:
break
return best, True
def solve(n, x, d, m, g):
value = [1] * n
weight = [0] * n
dfs_vw(g, m, 0, value, weight)
s = [(weight[i] / value[i], value[i], i, weight[i]) for i in range(n)]
s.sort()
ans, _ = dfs(n, x, d, s, 0, 0, 0)
return ans
def main():
n, x, d = input().split()
n = int(n)
x = int(x)
d = int(d)
m = []
g = [[] for _ in range(n)]
mi = input()
mi = int(mi)
m.append(mi)
for i in range(1, n):
mi, pi = input().split()
mi = int(mi)
pi = int(pi) - 1
m.append(mi)
g[pi].append(i)
print(solve(n, x, d, m, g))
if __name__ == '__main__':
main()
```
No
| 104,275 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts.
The recipes of these doughnuts are developed by repeated modifications from the recipe of Doughnut 1. Specifically, the recipe of Doughnut i (2 ≤ i ≤ N) is a direct modification of the recipe of Doughnut p_i (1 ≤ p_i < i).
Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:
* Let c_i be the number of Doughnut i (1 ≤ i ≤ N) that she makes. For each integer i such that 2 ≤ i ≤ N, c_{p_i} ≤ c_i ≤ c_{p_i} + D must hold. Here, D is a predetermined value.
At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto.
Constraints
* 2 ≤ N ≤ 50
* 1 ≤ X ≤ 10^9
* 0 ≤ D ≤ 10^9
* 1 ≤ m_i ≤ 10^9 (1 ≤ i ≤ N)
* 1 ≤ p_i < i (2 ≤ i ≤ N)
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X D
m_1
m_2 p_2
:
m_N p_N
Output
Print the maximum number of doughnuts that can be made under the condition.
Examples
Input
3 100 1
15
10 1
20 1
Output
7
Input
3 100 10
15
10 1
20 1
Output
10
Input
5 1000000000 1000000
123
159 1
111 1
135 3
147 3
Output
7496296
Submitted Solution:
```
N, X, D = map(int, input().split())
M = [0]*N
M[0] = int(input())
P = [0]*N
for i in range(N-1):
M[i+1], P[i+1] = map(int, input().split())
C = [1]*N
for i in range(N-1, 0, -1):
p = P[i]-1
C[p] += C[i]
M[p] += M[i]
L = [D]*N
L[0] = X
from collections import deque
def solve(N, W, ws, vs, ms):
V0 = max(vs)
V = sum(v * min(V0, m) for v, m in zip(vs, ms))
dp = [W+1]*(V + 1)
dp[0] = 0
for i in range(N):
v = vs[i]; w = ws[i]; m = ms[i]
c = min(V0, m)
ms[i] -= c
for k in range(v):
que = deque()
push = que.append
popf = que.popleft; popb = que.pop
for j in range((V-k)//v+1):
a = dp[k + j*v] - j * w
while que and a <= que[-1][1]:
popb()
push((j, a))
p, b = que[0]
dp[k + j*v] = b + j * w
if que and p <= j-c:
popf()
*I, = range(N)
I.sort(key=lambda x: ws[x]/vs[x])
*S, = [(vs[i], ws[i], ms[i]) for i in I]
def greedy():
yield 0
for i in range(V + 1):
if dp[i] > W:
continue
rest = W - dp[i]
r = i
for v, w, m in S:
m = min(m, rest // w)
r += m * v
rest -= m * w
yield r
return max(greedy())
print(solve(N, X, M, C, L))
```
No
| 104,276 |
Provide a correct Python 3 solution for this coding contest problem.
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?
Constraints
* 1000 ≤ N ≤ 9999
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
If N is good, print `Yes`; otherwise, print `No`.
Examples
Input
1118
Output
Yes
Input
7777
Output
Yes
Input
1234
Output
No
"Correct Solution:
```
N = input()
print("Yes" if len(set(N[0:3])) == 1 or len(set(N[1:4]))==1 else "No")
```
| 104,277 |
Provide a correct Python 3 solution for this coding contest problem.
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?
Constraints
* 1000 ≤ N ≤ 9999
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
If N is good, print `Yes`; otherwise, print `No`.
Examples
Input
1118
Output
Yes
Input
7777
Output
Yes
Input
1234
Output
No
"Correct Solution:
```
N = input()
print("Yes" if N[0] == N[1] == N[2] or N[1] == N[2] == N[3] else "No")
```
| 104,278 |
Provide a correct Python 3 solution for this coding contest problem.
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?
Constraints
* 1000 ≤ N ≤ 9999
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
If N is good, print `Yes`; otherwise, print `No`.
Examples
Input
1118
Output
Yes
Input
7777
Output
Yes
Input
1234
Output
No
"Correct Solution:
```
a,b,c,d=input()
if (a==b==c)or (b==c==d):
print('Yes')
else:
print('No')
```
| 104,279 |
Provide a correct Python 3 solution for this coding contest problem.
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?
Constraints
* 1000 ≤ N ≤ 9999
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
If N is good, print `Yes`; otherwise, print `No`.
Examples
Input
1118
Output
Yes
Input
7777
Output
Yes
Input
1234
Output
No
"Correct Solution:
```
S = input()
print('Yes' if len(set(S[:3])) == 1 or len(set(S[1:])) == 1 else 'No')
```
| 104,280 |
Provide a correct Python 3 solution for this coding contest problem.
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?
Constraints
* 1000 ≤ N ≤ 9999
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
If N is good, print `Yes`; otherwise, print `No`.
Examples
Input
1118
Output
Yes
Input
7777
Output
Yes
Input
1234
Output
No
"Correct Solution:
```
n = str(input())
print("Yes" if n[0]==n[1]==n[2] or n[1]==n[2]==n[3] else "No")
```
| 104,281 |
Provide a correct Python 3 solution for this coding contest problem.
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?
Constraints
* 1000 ≤ N ≤ 9999
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
If N is good, print `Yes`; otherwise, print `No`.
Examples
Input
1118
Output
Yes
Input
7777
Output
Yes
Input
1234
Output
No
"Correct Solution:
```
a=int(input())
print("YNeos"[(a//10)%111*(a%1000)%111>0::2])
```
| 104,282 |
Provide a correct Python 3 solution for this coding contest problem.
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?
Constraints
* 1000 ≤ N ≤ 9999
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
If N is good, print `Yes`; otherwise, print `No`.
Examples
Input
1118
Output
Yes
Input
7777
Output
Yes
Input
1234
Output
No
"Correct Solution:
```
a,b,c,d = input()
print('Yes' if (a==b==c) or (b==c==d) or(a==b==c==d) else 'No')
```
| 104,283 |
Provide a correct Python 3 solution for this coding contest problem.
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?
Constraints
* 1000 ≤ N ≤ 9999
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
If N is good, print `Yes`; otherwise, print `No`.
Examples
Input
1118
Output
Yes
Input
7777
Output
Yes
Input
1234
Output
No
"Correct Solution:
```
s=input();print("Yes" if len(set(s[:-1]))== 1 or len(set(s[1:]))==1 else "No")
```
| 104,284 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?
Constraints
* 1000 ≤ N ≤ 9999
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
If N is good, print `Yes`; otherwise, print `No`.
Examples
Input
1118
Output
Yes
Input
7777
Output
Yes
Input
1234
Output
No
Submitted Solution:
```
n = input()
ans = "Yes" if n[0]==n[1]==n[2] or n[1]==n[2]==n[3] else "No"
print(ans)
```
Yes
| 104,285 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?
Constraints
* 1000 ≤ N ≤ 9999
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
If N is good, print `Yes`; otherwise, print `No`.
Examples
Input
1118
Output
Yes
Input
7777
Output
Yes
Input
1234
Output
No
Submitted Solution:
```
n=int(input())
print("Yes" if (n//10)%111==0 or (n%1000)%111==0 else "No")
```
Yes
| 104,286 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?
Constraints
* 1000 ≤ N ≤ 9999
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
If N is good, print `Yes`; otherwise, print `No`.
Examples
Input
1118
Output
Yes
Input
7777
Output
Yes
Input
1234
Output
No
Submitted Solution:
```
x=input()
if len(set(x[:3]))==1 or len(set(x[1:]))==1:
print("Yes")
else:
print("No")
```
Yes
| 104,287 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?
Constraints
* 1000 ≤ N ≤ 9999
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
If N is good, print `Yes`; otherwise, print `No`.
Examples
Input
1118
Output
Yes
Input
7777
Output
Yes
Input
1234
Output
No
Submitted Solution:
```
n=input()
print('Yes' if len(set(n[0:3]))==1 or len(set(n[1:4]))==1 else 'No')
```
Yes
| 104,288 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?
Constraints
* 1000 ≤ N ≤ 9999
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
If N is good, print `Yes`; otherwise, print `No`.
Examples
Input
1118
Output
Yes
Input
7777
Output
Yes
Input
1234
Output
No
Submitted Solution:
```
n = input()
if len(set(n))<= 2:
print('Yes')
else:
print('No')
```
No
| 104,289 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?
Constraints
* 1000 ≤ N ≤ 9999
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
If N is good, print `Yes`; otherwise, print `No`.
Examples
Input
1118
Output
Yes
Input
7777
Output
Yes
Input
1234
Output
No
Submitted Solution:
```
n=list(input())
print("YES" if n[0]==n[1]==n[2] or n[1]==n[2]==n[3] else "NO")
```
No
| 104,290 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?
Constraints
* 1000 ≤ N ≤ 9999
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
If N is good, print `Yes`; otherwise, print `No`.
Examples
Input
1118
Output
Yes
Input
7777
Output
Yes
Input
1234
Output
No
Submitted Solution:
```
n = input()
if n[0] == n[1] == n[2] or n[0] == n[1] == n[3] or n[3] == n[1] == n[2] or n[0] == n[3] == n[2]:
print("Yes")
else:
print("No")
```
No
| 104,291 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?
Constraints
* 1000 ≤ N ≤ 9999
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
If N is good, print `Yes`; otherwise, print `No`.
Examples
Input
1118
Output
Yes
Input
7777
Output
Yes
Input
1234
Output
No
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Sun Nov 4 21:46:51 2018
@author: sk
"""
a = str(input())
char_list = list(a)
if a(0)==a(1):
if a(1)==a(2):
print("Yes")
else :
print("No")
elif a(1)==a(2):
if a(2)==a(3):
print("Yes")
else :
print("No")
```
No
| 104,292 |
Provide a correct Python 3 solution for this coding contest problem.
You are given two integers A and B as the input. Output the value of A + B.
However, if A + B is 10 or greater, output `error` instead.
Constraints
* A and B are integers.
* 1 ≤ A, B ≤ 9
Input
Input is given from Standard Input in the following format:
A B
Output
If A + B is 10 or greater, print the string `error` (case-sensitive); otherwise, print the value of A + B.
Examples
Input
6 3
Output
9
Input
6 4
Output
error
"Correct Solution:
```
S = sum([int(s) for s in input().split()])
print(S if S < 10 else 'error')
```
| 104,293 |
Provide a correct Python 3 solution for this coding contest problem.
You are given two integers A and B as the input. Output the value of A + B.
However, if A + B is 10 or greater, output `error` instead.
Constraints
* A and B are integers.
* 1 ≤ A, B ≤ 9
Input
Input is given from Standard Input in the following format:
A B
Output
If A + B is 10 or greater, print the string `error` (case-sensitive); otherwise, print the value of A + B.
Examples
Input
6 3
Output
9
Input
6 4
Output
error
"Correct Solution:
```
a,b=map(int, input().split())
[print(a+b) if a+b <10 else print('error')]
```
| 104,294 |
Provide a correct Python 3 solution for this coding contest problem.
You are given two integers A and B as the input. Output the value of A + B.
However, if A + B is 10 or greater, output `error` instead.
Constraints
* A and B are integers.
* 1 ≤ A, B ≤ 9
Input
Input is given from Standard Input in the following format:
A B
Output
If A + B is 10 or greater, print the string `error` (case-sensitive); otherwise, print the value of A + B.
Examples
Input
6 3
Output
9
Input
6 4
Output
error
"Correct Solution:
```
A, B = map(int,input().split())
if (A+B)<=9:print(A+B)
else:print('error')
```
| 104,295 |
Provide a correct Python 3 solution for this coding contest problem.
You are given two integers A and B as the input. Output the value of A + B.
However, if A + B is 10 or greater, output `error` instead.
Constraints
* A and B are integers.
* 1 ≤ A, B ≤ 9
Input
Input is given from Standard Input in the following format:
A B
Output
If A + B is 10 or greater, print the string `error` (case-sensitive); otherwise, print the value of A + B.
Examples
Input
6 3
Output
9
Input
6 4
Output
error
"Correct Solution:
```
x,y=map(int,input().split())
print(x+y if (x+y)<10 else 'error')
```
| 104,296 |
Provide a correct Python 3 solution for this coding contest problem.
You are given two integers A and B as the input. Output the value of A + B.
However, if A + B is 10 or greater, output `error` instead.
Constraints
* A and B are integers.
* 1 ≤ A, B ≤ 9
Input
Input is given from Standard Input in the following format:
A B
Output
If A + B is 10 or greater, print the string `error` (case-sensitive); otherwise, print the value of A + B.
Examples
Input
6 3
Output
9
Input
6 4
Output
error
"Correct Solution:
```
x, y = map(int, input().split())
print("error" if x+y>9 else x+y)
```
| 104,297 |
Provide a correct Python 3 solution for this coding contest problem.
You are given two integers A and B as the input. Output the value of A + B.
However, if A + B is 10 or greater, output `error` instead.
Constraints
* A and B are integers.
* 1 ≤ A, B ≤ 9
Input
Input is given from Standard Input in the following format:
A B
Output
If A + B is 10 or greater, print the string `error` (case-sensitive); otherwise, print the value of A + B.
Examples
Input
6 3
Output
9
Input
6 4
Output
error
"Correct Solution:
```
A, B = map(int, input().split())
print ("error") if A+B >= 10 else print(A+B)
```
| 104,298 |
Provide a correct Python 3 solution for this coding contest problem.
You are given two integers A and B as the input. Output the value of A + B.
However, if A + B is 10 or greater, output `error` instead.
Constraints
* A and B are integers.
* 1 ≤ A, B ≤ 9
Input
Input is given from Standard Input in the following format:
A B
Output
If A + B is 10 or greater, print the string `error` (case-sensitive); otherwise, print the value of A + B.
Examples
Input
6 3
Output
9
Input
6 4
Output
error
"Correct Solution:
```
a,b=map(int,input().split());print('error' if a+b>9 else a+b)
```
| 104,299 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.