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.
A string of length 6 consisting of lowercase English letters is said to be coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th and 6-th characters are also equal.
Given a string S, determine whether it is coffee-like.
Constraints
* S is a string of length 6 consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
S
Output
If S is coffee-like, print `Yes`; otherwise, print `No`.
Examples
Input
sippuu
Output
Yes
Input
iphone
Output
No
Input
coffee
Output
Yes
Submitted Solution:
```
letters = eval(input("Enter your words: "))
for i in letters:
if (i[2]==i[3]) and (i[4]==i[5]:
print("Yes")
else:
print("No")
```
No
| 106,800 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts with the same length.
Constraints
* 2 \leq N \leq 200000
* 1 \leq A_i \leq 2020202020
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N
Output
Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.
Examples
Input
3
2 4 3
Output
3
Input
12
100 104 102 105 103 103 101 105 104 102 104 101
Output
0
"Correct Solution:
```
from itertools import accumulate
n = int(input())
a = map(int, input().split())
acc = tuple(accumulate(a))
ret = min(abs(acc[-1] - x * 2) for x in acc)
print(ret)
```
| 106,801 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts with the same length.
Constraints
* 2 \leq N \leq 200000
* 1 \leq A_i \leq 2020202020
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N
Output
Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.
Examples
Input
3
2 4 3
Output
3
Input
12
100 104 102 105 103 103 101 105 104 102 104 101
Output
0
"Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
harf=sum(a)/2
l,r,i=0,a[0],0
while r<harf:
i+=1
l=r
r+=a[i]
print(int(min(harf-l,r-harf)*2))
```
| 106,802 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts with the same length.
Constraints
* 2 \leq N \leq 200000
* 1 \leq A_i \leq 2020202020
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N
Output
Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.
Examples
Input
3
2 4 3
Output
3
Input
12
100 104 102 105 103 103 101 105 104 102 104 101
Output
0
"Correct Solution:
```
N=int(input())
A=list(map(int, input().split()))
S=sum(A)
x=0
ans=S
for a in A:
x+=a
y=abs(S-2*x)
ans=min(ans,y)
print(ans)
```
| 106,803 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts with the same length.
Constraints
* 2 \leq N \leq 200000
* 1 \leq A_i \leq 2020202020
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N
Output
Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.
Examples
Input
3
2 4 3
Output
3
Input
12
100 104 102 105 103 103 101 105 104 102 104 101
Output
0
"Correct Solution:
```
n,*a=map(int,open(0).read().split())
s=sum(a)
c=0
m=[]
for b in a:c+=b;m+=abs(c+c-s),
print(min(m))
```
| 106,804 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts with the same length.
Constraints
* 2 \leq N \leq 200000
* 1 \leq A_i \leq 2020202020
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N
Output
Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.
Examples
Input
3
2 4 3
Output
3
Input
12
100 104 102 105 103 103 101 105 104 102 104 101
Output
0
"Correct Solution:
```
import sys
n = int(input())
a = list(map(int, input().split()))
tmp=sys.maxsize
s = sum(a)
t = 0
for i in range(n):
t += a[i]
tmp = min(tmp,abs(s-t*2))
print(tmp)
```
| 106,805 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts with the same length.
Constraints
* 2 \leq N \leq 200000
* 1 \leq A_i \leq 2020202020
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N
Output
Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.
Examples
Input
3
2 4 3
Output
3
Input
12
100 104 102 105 103 103 101 105 104 102 104 101
Output
0
"Correct Solution:
```
n = int(input())
*a, = map(int, input().split())
s = sum(a)
ans = s
tmp = 0
for i in a[:-1]:
tmp += i
ans = min(ans, abs(tmp*2 - s))
print(ans)
```
| 106,806 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts with the same length.
Constraints
* 2 \leq N \leq 200000
* 1 \leq A_i \leq 2020202020
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N
Output
Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.
Examples
Input
3
2 4 3
Output
3
Input
12
100 104 102 105 103 103 101 105 104 102 104 101
Output
0
"Correct Solution:
```
n=int(input())
l=list(map(int,input().split()))
s=sum(l)
m=0
i=-1
while m<s//2:
i+=1
m+=l[i]
print(min(2*m-s,s-2*(m-l[i])))
```
| 106,807 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts with the same length.
Constraints
* 2 \leq N \leq 200000
* 1 \leq A_i \leq 2020202020
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N
Output
Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.
Examples
Input
3
2 4 3
Output
3
Input
12
100 104 102 105 103 103 101 105 104 102 104 101
Output
0
"Correct Solution:
```
N = int(input())
b = [int(x) for x in input().split()]
d = sum(b)
ans = d
for i in range(N):
if d < 0:
break
d -= b[i] * 2
ans = min(ans, abs(d))
print(ans)
```
| 106,808 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts with the same length.
Constraints
* 2 \leq N \leq 200000
* 1 \leq A_i \leq 2020202020
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N
Output
Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.
Examples
Input
3
2 4 3
Output
3
Input
12
100 104 102 105 103 103 101 105 104 102 104 101
Output
0
Submitted Solution:
```
n = int(input())
a = list(map(int,input().split()))
iron_len = sum(a)
res = iron_len
st = 0
for i in range(n-1):
st += a[i]
res = min(res,abs(iron_len-st*2))
print(res)
```
Yes
| 106,809 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts with the same length.
Constraints
* 2 \leq N \leq 200000
* 1 \leq A_i \leq 2020202020
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N
Output
Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.
Examples
Input
3
2 4 3
Output
3
Input
12
100 104 102 105 103 103 101 105 104 102 104 101
Output
0
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
half = sum(a)/2
l, r, i = 0, a[0], 0
while r < half:
i += 1
l = r
r += a[i]
print(int(min(half - l, r - half)*2 ))
```
Yes
| 106,810 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts with the same length.
Constraints
* 2 \leq N \leq 200000
* 1 \leq A_i \leq 2020202020
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N
Output
Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.
Examples
Input
3
2 4 3
Output
3
Input
12
100 104 102 105 103 103 101 105 104 102 104 101
Output
0
Submitted Solution:
```
n = int(input())
A = list(map(int, input().split()))
x = sum(A)-A[0]
y = A[0]
ans = abs(x-y)
for a in A[1:]:
y += a
x -= a
ans = min(ans, abs(x-y))
print(ans)
```
Yes
| 106,811 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts with the same length.
Constraints
* 2 \leq N \leq 200000
* 1 \leq A_i \leq 2020202020
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N
Output
Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.
Examples
Input
3
2 4 3
Output
3
Input
12
100 104 102 105 103 103 101 105 104 102 104 101
Output
0
Submitted Solution:
```
n = int(input())
a = list(map(int,input().split()))
for i in range(1,n):
a[i] += a[i-1]
c = a[-1]
for i in range(n):
p = abs(a[-1]-a[i]*2)
if c > p:
c = p
print(c)
```
Yes
| 106,812 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts with the same length.
Constraints
* 2 \leq N \leq 200000
* 1 \leq A_i \leq 2020202020
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N
Output
Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.
Examples
Input
3
2 4 3
Output
3
Input
12
100 104 102 105 103 103 101 105 104 102 104 101
Output
0
Submitted Solution:
```
# import math
import bisect
import numpy as np
mod = 10**9 + 7
# http://cav-inet.hateblo.jp/entry/2017/02/18/165141
def binary_search(list,target):
result = -1
left = 0
right = len(list) - 1
while left <= right:
center = (left + right)//2
if list[center] == target:
result = center
break
elif list[center] < target:
left = center + 1
elif list[center] > target:
right = center - 1
if result == -1:
return False
else:
return True
n = int(input())
a = list(map(int,input().split()))
c = np.cumsum(a)
if binary_search(c, c[n-1]/2):
print(0)
exit()
i = bisect.bisect_left(c, c[n-1]/2)
ans = c[i+1] - c[i]
print(ans)
```
No
| 106,813 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts with the same length.
Constraints
* 2 \leq N \leq 200000
* 1 \leq A_i \leq 2020202020
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N
Output
Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.
Examples
Input
3
2 4 3
Output
3
Input
12
100 104 102 105 103 103 101 105 104 102 104 101
Output
0
Submitted Solution:
```
N = int(input())
n = [int(i) for i in input().split()]
l = sum(n)
s=0
e=0
for i in range(N):
s+=n[i]
if s>=l/2:
e=l-s
break
e+=n[N-i-1]
if e>=l/2:
s=l-e
break
print(abs(s-e))
```
No
| 106,814 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts with the same length.
Constraints
* 2 \leq N \leq 200000
* 1 \leq A_i \leq 2020202020
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N
Output
Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.
Examples
Input
3
2 4 3
Output
3
Input
12
100 104 102 105 103 103 101 105 104 102 104 101
Output
0
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
m = s/2
x = 0
p = 0
for i in range(n):
if x < m:
x += a[i]
else:
y = i-1
break
y = s - x
ans = x - y
print(ans)
```
No
| 106,815 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:
* Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
* Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
Find the minimum amount of money needed before cutting the bar into two parts with the same length.
Constraints
* 2 \leq N \leq 200000
* 1 \leq A_i \leq 2020202020
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_N
Output
Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.
Examples
Input
3
2 4 3
Output
3
Input
12
100 104 102 105 103 103 101 105 104 102 104 101
Output
0
Submitted Solution:
```
N = int(input())
P = list(map(int, input().split()))
cnt = 1 # P[0] is counted forcely
min_num = P[0]
for p in P:
if p < min_num:
min_num = p
cnt += 1
print(cnt)
```
No
| 106,816 |
Provide a correct Python 3 solution for this coding contest problem.
There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.
First, Snuke will arrange the N balls in a row from left to right.
Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.
How many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \leq i \leq K.
Constraints
* 1 \leq K \leq N \leq 2000
Input
Input is given from Standard Input in the following format:
N K
Output
Print K lines. The i-th line (1 \leq i \leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.
Examples
Input
5 3
Output
3
6
1
Input
2000 3
Output
1998
3990006
327341989
"Correct Solution:
```
n,k = map(int, input().split())
mod = 10**9+7
dp = [[1] + [0 for i in range(k)] for j in range(n+1)]
for i in range(1,n+1):
for j in range(1,k+1):
dp[i][j] = dp[i-1][j] + dp[i-1][j-1]
for i in range(k):
print(dp[n-k+1][i+1]*dp[k-1][i]%mod)
```
| 106,817 |
Provide a correct Python 3 solution for this coding contest problem.
There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.
First, Snuke will arrange the N balls in a row from left to right.
Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.
How many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \leq i \leq K.
Constraints
* 1 \leq K \leq N \leq 2000
Input
Input is given from Standard Input in the following format:
N K
Output
Print K lines. The i-th line (1 \leq i \leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.
Examples
Input
5 3
Output
3
6
1
Input
2000 3
Output
1998
3990006
327341989
"Correct Solution:
```
from math import factorial as f
N, K = map(int,input().split())
WARU = 10**9+7
def nCr(n, r):
return f(n)//(f(r)*f(n-r))
for i in range(K):
if i <= N-K:
print((nCr(K-1, i) * nCr(N-K+1, i+1)) % WARU)
else:
print(0)
```
| 106,818 |
Provide a correct Python 3 solution for this coding contest problem.
There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.
First, Snuke will arrange the N balls in a row from left to right.
Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.
How many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \leq i \leq K.
Constraints
* 1 \leq K \leq N \leq 2000
Input
Input is given from Standard Input in the following format:
N K
Output
Print K lines. The i-th line (1 \leq i \leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.
Examples
Input
5 3
Output
3
6
1
Input
2000 3
Output
1998
3990006
327341989
"Correct Solution:
```
n,k=map(int,input().split())
mod=10**9+7
fac=[1]*n
for i in range(n-1):
fac[i+1]=((i+2)*fac[i])
def comb(a,b):
if a==0:
return 1
if b==0 or b==a:
return 1
return (fac[a-1]//(fac[a-b-1]*fac[b-1]))%mod
for i in range(k):
print((comb(n-k+1,i+1)*comb(k-1,i))%mod)
```
| 106,819 |
Provide a correct Python 3 solution for this coding contest problem.
There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.
First, Snuke will arrange the N balls in a row from left to right.
Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.
How many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \leq i \leq K.
Constraints
* 1 \leq K \leq N \leq 2000
Input
Input is given from Standard Input in the following format:
N K
Output
Print K lines. The i-th line (1 \leq i \leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.
Examples
Input
5 3
Output
3
6
1
Input
2000 3
Output
1998
3990006
327341989
"Correct Solution:
```
from math import factorial
N, K = map(int, input().split())
mod = 10**9 + 7
def cmb(n, r):
if n >= r:
return int(factorial(n) // (factorial(r) * factorial(n-r)))
else:
return 0
for i in range(1, K+1):
print(cmb(N-K+1, i) * cmb(K-1, i-1) % mod)
```
| 106,820 |
Provide a correct Python 3 solution for this coding contest problem.
There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.
First, Snuke will arrange the N balls in a row from left to right.
Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.
How many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \leq i \leq K.
Constraints
* 1 \leq K \leq N \leq 2000
Input
Input is given from Standard Input in the following format:
N K
Output
Print K lines. The i-th line (1 \leq i \leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.
Examples
Input
5 3
Output
3
6
1
Input
2000 3
Output
1998
3990006
327341989
"Correct Solution:
```
def ncr(n,r,mod):
X = 1
Y = 1
for i in range(r):
X = (X*(n-i))%mod
Y = (Y*(i+1))%mod
return (X*pow(Y,mod-2,mod))%mod
N,K = map(int,input().split())
mod = pow(10,9)+7
for i in range(1,K+1):
ans = (ncr(K-1,i-1,mod)*ncr(N-K+1,i,mod))%mod
print(ans)
```
| 106,821 |
Provide a correct Python 3 solution for this coding contest problem.
There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.
First, Snuke will arrange the N balls in a row from left to right.
Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.
How many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \leq i \leq K.
Constraints
* 1 \leq K \leq N \leq 2000
Input
Input is given from Standard Input in the following format:
N K
Output
Print K lines. The i-th line (1 \leq i \leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.
Examples
Input
5 3
Output
3
6
1
Input
2000 3
Output
1998
3990006
327341989
"Correct Solution:
```
import math
N,K=map(int,input().split())
def c(n,r):
return math.factorial(n)//(math.factorial(abs(n-r))*math.factorial(r))
for i in range(K):
if N-K<i:
print(0)
else:
red = c(N-K+1,i+1)
blue=c(K-1,i)
ans=(red*blue)%(10**9+7)
print(ans)
```
| 106,822 |
Provide a correct Python 3 solution for this coding contest problem.
There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.
First, Snuke will arrange the N balls in a row from left to right.
Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.
How many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \leq i \leq K.
Constraints
* 1 \leq K \leq N \leq 2000
Input
Input is given from Standard Input in the following format:
N K
Output
Print K lines. The i-th line (1 \leq i \leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.
Examples
Input
5 3
Output
3
6
1
Input
2000 3
Output
1998
3990006
327341989
"Correct Solution:
```
M=10**9+7;N,K=map(int,input().split())
def c(n,k):
if k>n:return 0
m=d=1
for i in range(k):m*=n-i;d*=i+1
return m%M*pow(d%M,M-2,M)%M
for i in range(K):print(c(K-1,i)*c(N-K+1,i+1)%M)
```
| 106,823 |
Provide a correct Python 3 solution for this coding contest problem.
There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.
First, Snuke will arrange the N balls in a row from left to right.
Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.
How many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \leq i \leq K.
Constraints
* 1 \leq K \leq N \leq 2000
Input
Input is given from Standard Input in the following format:
N K
Output
Print K lines. The i-th line (1 \leq i \leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.
Examples
Input
5 3
Output
3
6
1
Input
2000 3
Output
1998
3990006
327341989
"Correct Solution:
```
#!/usr/bin/env python3
from math import factorial as f
n, k = map(int, input().split())
mod = 10**9+7
for i in range(k):
try:
print(f(n - k + 1) * f(k - 1) // f(i + 1) // f(n - k - i) // f(i) // f(k - i - 1) % mod)
except ValueError:
print(0)
```
| 106,824 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.
First, Snuke will arrange the N balls in a row from left to right.
Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.
How many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \leq i \leq K.
Constraints
* 1 \leq K \leq N \leq 2000
Input
Input is given from Standard Input in the following format:
N K
Output
Print K lines. The i-th line (1 \leq i \leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.
Examples
Input
5 3
Output
3
6
1
Input
2000 3
Output
1998
3990006
327341989
Submitted Solution:
```
n, k = map(int, input().split())
a = n-k+1
for i in range(k):
print(a%(10**9+7))
a = a*((n-k-i)*(k-i-1))//(i+1)//(i+2)
```
Yes
| 106,825 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.
First, Snuke will arrange the N balls in a row from left to right.
Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.
How many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \leq i \leq K.
Constraints
* 1 \leq K \leq N \leq 2000
Input
Input is given from Standard Input in the following format:
N K
Output
Print K lines. The i-th line (1 \leq i \leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.
Examples
Input
5 3
Output
3
6
1
Input
2000 3
Output
1998
3990006
327341989
Submitted Solution:
```
mod=10**9+7
n,k=map(int,input().split())
mt=[1]
invt=[1]
for i in range(1,n+1):
mt.append((mt[-1]*i)%mod)
invt.append(pow(mt[-1], mod-2, mod))
for i in range(1,k+1):
a=mt[n-k+1]*invt[i]*invt[n-k-i+1]
b=mt[k-1]*invt[i-1]*invt[k-i]
print((a*b)%mod if n-k+1>=i else 0)
```
Yes
| 106,826 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.
First, Snuke will arrange the N balls in a row from left to right.
Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.
How many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \leq i \leq K.
Constraints
* 1 \leq K \leq N \leq 2000
Input
Input is given from Standard Input in the following format:
N K
Output
Print K lines. The i-th line (1 \leq i \leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.
Examples
Input
5 3
Output
3
6
1
Input
2000 3
Output
1998
3990006
327341989
Submitted Solution:
```
from math import factorial
n,k = map(int,input().split())
for i in range(k):
if i <= n-k:
blue = factorial(k-1)//(factorial(k-i-1)*factorial(i))
red = factorial(n-k+1)//(factorial(n-k-i)*factorial(i+1))
print((blue*red)%1000000007)
else:
print(0)
```
Yes
| 106,827 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.
First, Snuke will arrange the N balls in a row from left to right.
Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.
How many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \leq i \leq K.
Constraints
* 1 \leq K \leq N \leq 2000
Input
Input is given from Standard Input in the following format:
N K
Output
Print K lines. The i-th line (1 \leq i \leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.
Examples
Input
5 3
Output
3
6
1
Input
2000 3
Output
1998
3990006
327341989
Submitted Solution:
```
MOD=10**9+7
def com(n,k,mod):
res=1
tmp=1
for i in range(1,k+1):
res=res*(n-i+1)%mod
tmp=tmp*i%mod
a=pow(tmp,mod-2,mod)
return res*a%mod
N,K=map(int,input().split())
X=N-K
for i in range(1,K+1):
print(com(X+1,i,MOD)*com(K-1,i-1,MOD)%MOD)
```
Yes
| 106,828 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.
First, Snuke will arrange the N balls in a row from left to right.
Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.
How many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \leq i \leq K.
Constraints
* 1 \leq K \leq N \leq 2000
Input
Input is given from Standard Input in the following format:
N K
Output
Print K lines. The i-th line (1 \leq i \leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.
Examples
Input
5 3
Output
3
6
1
Input
2000 3
Output
1998
3990006
327341989
Submitted Solution:
```
def cmb(n, r):
if n - r < r: r = n - r
if r == 0: return 1
if r == 1: return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2,r+1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p-1,r,p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
N, K =map(int, input().split())
blue = K
red = N - K
over = 10**9 + 7
for i in range(K):
if i == 0:
print(red+1)
elif i <= red:
print((cmb(red+1, i+1) % over) * (cmb(blue-1, i) % over))
else:
print(0)
```
No
| 106,829 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.
First, Snuke will arrange the N balls in a row from left to right.
Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.
How many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \leq i \leq K.
Constraints
* 1 \leq K \leq N \leq 2000
Input
Input is given from Standard Input in the following format:
N K
Output
Print K lines. The i-th line (1 \leq i \leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.
Examples
Input
5 3
Output
3
6
1
Input
2000 3
Output
1998
3990006
327341989
Submitted Solution:
```
N,K = map(int,input().split())
B = 1
R = N-K+1
i = 0
while B*R%(10**9+7) != 0:
print(B*R%(10**9+7))
B = B * (K-i-1) // (i+1)
R = R * (N-K-i) // (i+2)
i += 1
```
No
| 106,830 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.
First, Snuke will arrange the N balls in a row from left to right.
Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.
How many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \leq i \leq K.
Constraints
* 1 \leq K \leq N \leq 2000
Input
Input is given from Standard Input in the following format:
N K
Output
Print K lines. The i-th line (1 \leq i \leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.
Examples
Input
5 3
Output
3
6
1
Input
2000 3
Output
1998
3990006
327341989
Submitted Solution:
```
#132_D
n,k=map(int,input().split())
mod=10**9+7
f=[1 for i in range(n-k+2)]
f_inv=[1 for i in range(n-k+2)]
for i in range(1,n-k+2):
f[i]=f[i-1]*i%mod
f_inv[i]=pow(f[i],mod-2,mod)
def comb(n,k):
if k>n:
return 0
return f[n]*f_inv[k]*f_inv[n-k]%mod
for i in range(1,k+1):
print(comb(n-k+1,i)*comb(k-1,i-1)%mod)
```
No
| 106,831 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.
First, Snuke will arrange the N balls in a row from left to right.
Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.
How many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \leq i \leq K.
Constraints
* 1 \leq K \leq N \leq 2000
Input
Input is given from Standard Input in the following format:
N K
Output
Print K lines. The i-th line (1 \leq i \leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.
Examples
Input
5 3
Output
3
6
1
Input
2000 3
Output
1998
3990006
327341989
Submitted Solution:
```
n, k = list(map(int, input().split()))
mod = int(1e9 + 7)
def comb(a, b):
result = 1
for i in range(b):
result *= a-i
result //= i+1
result %= mod
return result
for i in range(1, k+1):
print(comb(n-k+1, i) * comb(k-1, i-1) % mod)
```
No
| 106,832 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes:
* Hit his pocket, which magically increases the number of biscuits by one.
* Exchange A biscuits to 1 yen.
* Exchange 1 yen to B biscuits.
Find the maximum possible number of biscuits in Snuke's pocket after K operations.
Constraints
* 1 \leq K,A,B \leq 10^9
* K,A and B are integers.
Input
Input is given from Standard Input in the following format:
K A B
Output
Print the maximum possible number of biscuits in Snuke's pocket after K operations.
Examples
Input
4 2 6
Output
7
Input
7 3 4
Output
8
Input
314159265 35897932 384626433
Output
48518828981938099
"Correct Solution:
```
N,A,B = list(map(int,input().split()))
another=1+1*N
ans =A
N -= A-1
ans += N//2 * (B-A)
ans += N%2
print(max(ans,another))
```
| 106,833 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes:
* Hit his pocket, which magically increases the number of biscuits by one.
* Exchange A biscuits to 1 yen.
* Exchange 1 yen to B biscuits.
Find the maximum possible number of biscuits in Snuke's pocket after K operations.
Constraints
* 1 \leq K,A,B \leq 10^9
* K,A and B are integers.
Input
Input is given from Standard Input in the following format:
K A B
Output
Print the maximum possible number of biscuits in Snuke's pocket after K operations.
Examples
Input
4 2 6
Output
7
Input
7 3 4
Output
8
Input
314159265 35897932 384626433
Output
48518828981938099
"Correct Solution:
```
k, a, b = map(int, input().split())
if b-a < 3 or k < a+1:
print(k+1)
else:
print(a + (k-a+1)//2*(b-a) + (k-a+1)%2)
```
| 106,834 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes:
* Hit his pocket, which magically increases the number of biscuits by one.
* Exchange A biscuits to 1 yen.
* Exchange 1 yen to B biscuits.
Find the maximum possible number of biscuits in Snuke's pocket after K operations.
Constraints
* 1 \leq K,A,B \leq 10^9
* K,A and B are integers.
Input
Input is given from Standard Input in the following format:
K A B
Output
Print the maximum possible number of biscuits in Snuke's pocket after K operations.
Examples
Input
4 2 6
Output
7
Input
7 3 4
Output
8
Input
314159265 35897932 384626433
Output
48518828981938099
"Correct Solution:
```
K, A, B = map(int, input().split())
K += 1
if B - A <= 2 or K < A + 2:
print(K)
else:
K -= A + 2
print(B + K // 2 * (B - A) + K % 2)
```
| 106,835 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes:
* Hit his pocket, which magically increases the number of biscuits by one.
* Exchange A biscuits to 1 yen.
* Exchange 1 yen to B biscuits.
Find the maximum possible number of biscuits in Snuke's pocket after K operations.
Constraints
* 1 \leq K,A,B \leq 10^9
* K,A and B are integers.
Input
Input is given from Standard Input in the following format:
K A B
Output
Print the maximum possible number of biscuits in Snuke's pocket after K operations.
Examples
Input
4 2 6
Output
7
Input
7 3 4
Output
8
Input
314159265 35897932 384626433
Output
48518828981938099
"Correct Solution:
```
K,A,B = map(int, input().split())
S=K+1
diff=B-A
t=((K-A+1)//2)
T=diff*t
odd=((K-A+1)%2)
print(max(T+odd+A,S))
```
| 106,836 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes:
* Hit his pocket, which magically increases the number of biscuits by one.
* Exchange A biscuits to 1 yen.
* Exchange 1 yen to B biscuits.
Find the maximum possible number of biscuits in Snuke's pocket after K operations.
Constraints
* 1 \leq K,A,B \leq 10^9
* K,A and B are integers.
Input
Input is given from Standard Input in the following format:
K A B
Output
Print the maximum possible number of biscuits in Snuke's pocket after K operations.
Examples
Input
4 2 6
Output
7
Input
7 3 4
Output
8
Input
314159265 35897932 384626433
Output
48518828981938099
"Correct Solution:
```
k,a,b = map(int,input().split())
if a+2 >= b or a >= k:
print(k+1)
else:
k -= a-1
print(a+ (b-a)*(k//2) + k%2)
```
| 106,837 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes:
* Hit his pocket, which magically increases the number of biscuits by one.
* Exchange A biscuits to 1 yen.
* Exchange 1 yen to B biscuits.
Find the maximum possible number of biscuits in Snuke's pocket after K operations.
Constraints
* 1 \leq K,A,B \leq 10^9
* K,A and B are integers.
Input
Input is given from Standard Input in the following format:
K A B
Output
Print the maximum possible number of biscuits in Snuke's pocket after K operations.
Examples
Input
4 2 6
Output
7
Input
7 3 4
Output
8
Input
314159265 35897932 384626433
Output
48518828981938099
"Correct Solution:
```
k,a,b = map(int,input().split())
bis = 1
bis = a
k -= (a-1)
print(max((b-a) * (k//2)+ 1 * (k % 2) + bis,k + bis))
#copy code
```
| 106,838 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes:
* Hit his pocket, which magically increases the number of biscuits by one.
* Exchange A biscuits to 1 yen.
* Exchange 1 yen to B biscuits.
Find the maximum possible number of biscuits in Snuke's pocket after K operations.
Constraints
* 1 \leq K,A,B \leq 10^9
* K,A and B are integers.
Input
Input is given from Standard Input in the following format:
K A B
Output
Print the maximum possible number of biscuits in Snuke's pocket after K operations.
Examples
Input
4 2 6
Output
7
Input
7 3 4
Output
8
Input
314159265 35897932 384626433
Output
48518828981938099
"Correct Solution:
```
k,a,b=map(int,input().split())
ans=1
yen=0
if b<=a+2 or k<=a:
ans+=k
else:
n=(k-a+1)//2
ans+=n*(b-a)+(k-2*n)
print(ans)
```
| 106,839 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes:
* Hit his pocket, which magically increases the number of biscuits by one.
* Exchange A biscuits to 1 yen.
* Exchange 1 yen to B biscuits.
Find the maximum possible number of biscuits in Snuke's pocket after K operations.
Constraints
* 1 \leq K,A,B \leq 10^9
* K,A and B are integers.
Input
Input is given from Standard Input in the following format:
K A B
Output
Print the maximum possible number of biscuits in Snuke's pocket after K operations.
Examples
Input
4 2 6
Output
7
Input
7 3 4
Output
8
Input
314159265 35897932 384626433
Output
48518828981938099
"Correct Solution:
```
k,a,b=map(int,input().split())
gain=b-a
if gain>=2:
k-=a-1
print(a+k//2*gain+k%2)
else:
print(k+1)
```
| 106,840 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes:
* Hit his pocket, which magically increases the number of biscuits by one.
* Exchange A biscuits to 1 yen.
* Exchange 1 yen to B biscuits.
Find the maximum possible number of biscuits in Snuke's pocket after K operations.
Constraints
* 1 \leq K,A,B \leq 10^9
* K,A and B are integers.
Input
Input is given from Standard Input in the following format:
K A B
Output
Print the maximum possible number of biscuits in Snuke's pocket after K operations.
Examples
Input
4 2 6
Output
7
Input
7 3 4
Output
8
Input
314159265 35897932 384626433
Output
48518828981938099
Submitted Solution:
```
k,a,b=map(int,input().split())
if b-a<=2 or a>=k:
print(1+k)
exit()
bis=a
k-=a-1
bis+=k//2*(b-a)
if k%2==1:
bis+=1
print(bis)
```
Yes
| 106,841 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes:
* Hit his pocket, which magically increases the number of biscuits by one.
* Exchange A biscuits to 1 yen.
* Exchange 1 yen to B biscuits.
Find the maximum possible number of biscuits in Snuke's pocket after K operations.
Constraints
* 1 \leq K,A,B \leq 10^9
* K,A and B are integers.
Input
Input is given from Standard Input in the following format:
K A B
Output
Print the maximum possible number of biscuits in Snuke's pocket after K operations.
Examples
Input
4 2 6
Output
7
Input
7 3 4
Output
8
Input
314159265 35897932 384626433
Output
48518828981938099
Submitted Solution:
```
k, a, b = map(int, input().split())
if b - a <= 2:
print(k + 1)
exit()
k -= a - 1
bis = a
print(a + ((b - a) * (k // 2)) + k % 2)
```
Yes
| 106,842 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes:
* Hit his pocket, which magically increases the number of biscuits by one.
* Exchange A biscuits to 1 yen.
* Exchange 1 yen to B biscuits.
Find the maximum possible number of biscuits in Snuke's pocket after K operations.
Constraints
* 1 \leq K,A,B \leq 10^9
* K,A and B are integers.
Input
Input is given from Standard Input in the following format:
K A B
Output
Print the maximum possible number of biscuits in Snuke's pocket after K operations.
Examples
Input
4 2 6
Output
7
Input
7 3 4
Output
8
Input
314159265 35897932 384626433
Output
48518828981938099
Submitted Solution:
```
K,A,B=map(int,input().split());print(K+1if(B-A)<2or K+1<A else A+(B-A)*((K-A+1)//2)+(K+A+1)%2)
```
Yes
| 106,843 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes:
* Hit his pocket, which magically increases the number of biscuits by one.
* Exchange A biscuits to 1 yen.
* Exchange 1 yen to B biscuits.
Find the maximum possible number of biscuits in Snuke's pocket after K operations.
Constraints
* 1 \leq K,A,B \leq 10^9
* K,A and B are integers.
Input
Input is given from Standard Input in the following format:
K A B
Output
Print the maximum possible number of biscuits in Snuke's pocket after K operations.
Examples
Input
4 2 6
Output
7
Input
7 3 4
Output
8
Input
314159265 35897932 384626433
Output
48518828981938099
Submitted Solution:
```
K,A,B=map(int,input().split())
K1=K-(A+1)
n=K1//2
print(max(K+1,((n+1)*B-n*A+K1%2)))
```
Yes
| 106,844 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes:
* Hit his pocket, which magically increases the number of biscuits by one.
* Exchange A biscuits to 1 yen.
* Exchange 1 yen to B biscuits.
Find the maximum possible number of biscuits in Snuke's pocket after K operations.
Constraints
* 1 \leq K,A,B \leq 10^9
* K,A and B are integers.
Input
Input is given from Standard Input in the following format:
K A B
Output
Print the maximum possible number of biscuits in Snuke's pocket after K operations.
Examples
Input
4 2 6
Output
7
Input
7 3 4
Output
8
Input
314159265 35897932 384626433
Output
48518828981938099
Submitted Solution:
```
K , A , B = map(int, input().split())
if A >= B:
print(K+1)
elif A < B:
print(max((K//(A+2))*B +(K%(A+2))+1,K+1))
```
No
| 106,845 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes:
* Hit his pocket, which magically increases the number of biscuits by one.
* Exchange A biscuits to 1 yen.
* Exchange 1 yen to B biscuits.
Find the maximum possible number of biscuits in Snuke's pocket after K operations.
Constraints
* 1 \leq K,A,B \leq 10^9
* K,A and B are integers.
Input
Input is given from Standard Input in the following format:
K A B
Output
Print the maximum possible number of biscuits in Snuke's pocket after K operations.
Examples
Input
4 2 6
Output
7
Input
7 3 4
Output
8
Input
314159265 35897932 384626433
Output
48518828981938099
Submitted Solution:
```
k, a, b = map(int, input().split())
if a < b - 2:
# k が a+2より大きい場合
if k > (a + 2):
# まずa+2回叩いて b 枚を得る
k2 = k - (a + 2)
res = b
# 残りの k2回を a枚を1円に,1円をB枚に交換の2回の操作をできるだけ繰り返す
# 2回の操作で (b-a)円増える
# この操作は k2//2 + 1 回行える
res += (k2//2 + 1) * (b - a)
# kがa+2より小さい場合は全部叩くしかない
else:
res = k + 1
else:
# a枚をb枚に交換しても増えなければ全部叩いた方が良い
res = k + 1
print(res)
```
No
| 106,846 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes:
* Hit his pocket, which magically increases the number of biscuits by one.
* Exchange A biscuits to 1 yen.
* Exchange 1 yen to B biscuits.
Find the maximum possible number of biscuits in Snuke's pocket after K operations.
Constraints
* 1 \leq K,A,B \leq 10^9
* K,A and B are integers.
Input
Input is given from Standard Input in the following format:
K A B
Output
Print the maximum possible number of biscuits in Snuke's pocket after K operations.
Examples
Input
4 2 6
Output
7
Input
7 3 4
Output
8
Input
314159265 35897932 384626433
Output
48518828981938099
Submitted Solution:
```
arr = input().split()
K = int(arr[0])
A = int(arr[1])
B = int(arr[2])
n = 1 + K
x = B
K -= A+1
temp = int(K / 2)
x += temp * (B-A)
K -= temp * 2
while K > 0:
K -= 1
x += 1
print(max(x, n))
```
No
| 106,847 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes:
* Hit his pocket, which magically increases the number of biscuits by one.
* Exchange A biscuits to 1 yen.
* Exchange 1 yen to B biscuits.
Find the maximum possible number of biscuits in Snuke's pocket after K operations.
Constraints
* 1 \leq K,A,B \leq 10^9
* K,A and B are integers.
Input
Input is given from Standard Input in the following format:
K A B
Output
Print the maximum possible number of biscuits in Snuke's pocket after K operations.
Examples
Input
4 2 6
Output
7
Input
7 3 4
Output
8
Input
314159265 35897932 384626433
Output
48518828981938099
Submitted Solution:
```
k,a,b = list(map(int,input().split()))
mon = 0
bis = 1
if(a <= b-1):
for i in range(k):
bis = bis + 1
else:
for i in range(k):
if(mon == 1):
mon = 0
bis = bis + b
elif(bis >= a and i < k-1):
mon = 1
bis = bis - a
else:
bis = bis + 1
print(bis)
```
No
| 106,848 |
Provide a correct Python 3 solution for this coding contest problem.
There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning. Snuke decides to light K of the N candles.
Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.
Find the minimum time required to light K candles.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq K \leq N
* x_i is an integer.
* |x_i| \leq 10^8
* x_1 < x_2 < ... < x_N
Input
Input is given from Standard Input in the following format:
N K
x_1 x_2 ... x_N
Output
Print the minimum time required to light K candles.
Examples
Input
5 3
-30 -10 10 20 50
Output
40
Input
3 2
10 20 30
Output
20
Input
1 1
0
Output
0
Input
8 5
-9 -7 -4 -3 1 2 3 4
Output
10
"Correct Solution:
```
n,k=map(int,input().split())
x=list(map(int,input().split()))
ans=3*10**8
for i in range(n-k+1):
ans=min(ans,min(abs(x[i]),abs(x[k+i-1]))+x[k+i-1]-x[i])
print(ans)
```
| 106,849 |
Provide a correct Python 3 solution for this coding contest problem.
There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning. Snuke decides to light K of the N candles.
Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.
Find the minimum time required to light K candles.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq K \leq N
* x_i is an integer.
* |x_i| \leq 10^8
* x_1 < x_2 < ... < x_N
Input
Input is given from Standard Input in the following format:
N K
x_1 x_2 ... x_N
Output
Print the minimum time required to light K candles.
Examples
Input
5 3
-30 -10 10 20 50
Output
40
Input
3 2
10 20 30
Output
20
Input
1 1
0
Output
0
Input
8 5
-9 -7 -4 -3 1 2 3 4
Output
10
"Correct Solution:
```
n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = float("inf")
for i in range(n-k+1):
res = x[i+k-1] - x[i] + min(abs(x[i+k-1]), abs(x[i]))
ans = min(ans, res)
print(ans)
```
| 106,850 |
Provide a correct Python 3 solution for this coding contest problem.
There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning. Snuke decides to light K of the N candles.
Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.
Find the minimum time required to light K candles.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq K \leq N
* x_i is an integer.
* |x_i| \leq 10^8
* x_1 < x_2 < ... < x_N
Input
Input is given from Standard Input in the following format:
N K
x_1 x_2 ... x_N
Output
Print the minimum time required to light K candles.
Examples
Input
5 3
-30 -10 10 20 50
Output
40
Input
3 2
10 20 30
Output
20
Input
1 1
0
Output
0
Input
8 5
-9 -7 -4 -3 1 2 3 4
Output
10
"Correct Solution:
```
N,K=map(int,input().split())
x=[int(i) for i in input().split()]
cost=10**13
for i in range(N-K+1):
c=x[i+K-1]-x[i]+min(abs(x[i]),abs(x[i+K-1]))
cost=min(cost,c)
print(cost)
```
| 106,851 |
Provide a correct Python 3 solution for this coding contest problem.
There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning. Snuke decides to light K of the N candles.
Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.
Find the minimum time required to light K candles.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq K \leq N
* x_i is an integer.
* |x_i| \leq 10^8
* x_1 < x_2 < ... < x_N
Input
Input is given from Standard Input in the following format:
N K
x_1 x_2 ... x_N
Output
Print the minimum time required to light K candles.
Examples
Input
5 3
-30 -10 10 20 50
Output
40
Input
3 2
10 20 30
Output
20
Input
1 1
0
Output
0
Input
8 5
-9 -7 -4 -3 1 2 3 4
Output
10
"Correct Solution:
```
N, K = map(int, input().split())
x = list(map(int, input().split()))
ans = []
for i in range(N-K+1):
l = x[i]
r = x[i+K-1]
ans.append(min(abs(l)+abs(l-r), abs(r)+abs(l-r)))
print(min(ans))
```
| 106,852 |
Provide a correct Python 3 solution for this coding contest problem.
There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning. Snuke decides to light K of the N candles.
Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.
Find the minimum time required to light K candles.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq K \leq N
* x_i is an integer.
* |x_i| \leq 10^8
* x_1 < x_2 < ... < x_N
Input
Input is given from Standard Input in the following format:
N K
x_1 x_2 ... x_N
Output
Print the minimum time required to light K candles.
Examples
Input
5 3
-30 -10 10 20 50
Output
40
Input
3 2
10 20 30
Output
20
Input
1 1
0
Output
0
Input
8 5
-9 -7 -4 -3 1 2 3 4
Output
10
"Correct Solution:
```
f = lambda:map(int,input().split())
n,k = f()
x = list(f())
d = 10**9
for i in range(n-k+1):
l,r = x[i],x[i+k-1]
d = [min(d,max(-l,r)),min(d,(r-l)+min(-l,r))][l<0<r]
print(d)
```
| 106,853 |
Provide a correct Python 3 solution for this coding contest problem.
There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning. Snuke decides to light K of the N candles.
Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.
Find the minimum time required to light K candles.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq K \leq N
* x_i is an integer.
* |x_i| \leq 10^8
* x_1 < x_2 < ... < x_N
Input
Input is given from Standard Input in the following format:
N K
x_1 x_2 ... x_N
Output
Print the minimum time required to light K candles.
Examples
Input
5 3
-30 -10 10 20 50
Output
40
Input
3 2
10 20 30
Output
20
Input
1 1
0
Output
0
Input
8 5
-9 -7 -4 -3 1 2 3 4
Output
10
"Correct Solution:
```
N, K = map(int, input().split())
x = list(map(int, input().split()))
m = float("INF")
for i in range(N - K + 1):
m = min(m, x[i + K - 1] - x[i] + min(abs(x[i + K - 1]), abs(x[i])))
print(m)
```
| 106,854 |
Provide a correct Python 3 solution for this coding contest problem.
There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning. Snuke decides to light K of the N candles.
Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.
Find the minimum time required to light K candles.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq K \leq N
* x_i is an integer.
* |x_i| \leq 10^8
* x_1 < x_2 < ... < x_N
Input
Input is given from Standard Input in the following format:
N K
x_1 x_2 ... x_N
Output
Print the minimum time required to light K candles.
Examples
Input
5 3
-30 -10 10 20 50
Output
40
Input
3 2
10 20 30
Output
20
Input
1 1
0
Output
0
Input
8 5
-9 -7 -4 -3 1 2 3 4
Output
10
"Correct Solution:
```
n, k = map(int, input().split())
X = list(map(int, input().split()))
ans = 10**9
for i in range(n-k+1):
l = X[i]
r = X[i+k-1]
tmp = min(abs(l)+abs(l-r), abs(r)+abs(l-r))
ans = min(tmp, ans)
print(ans)
```
| 106,855 |
Provide a correct Python 3 solution for this coding contest problem.
There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning. Snuke decides to light K of the N candles.
Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.
Find the minimum time required to light K candles.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq K \leq N
* x_i is an integer.
* |x_i| \leq 10^8
* x_1 < x_2 < ... < x_N
Input
Input is given from Standard Input in the following format:
N K
x_1 x_2 ... x_N
Output
Print the minimum time required to light K candles.
Examples
Input
5 3
-30 -10 10 20 50
Output
40
Input
3 2
10 20 30
Output
20
Input
1 1
0
Output
0
Input
8 5
-9 -7 -4 -3 1 2 3 4
Output
10
"Correct Solution:
```
N, K = map(int, input().split())
x = list(map(int, input().split()))
Min = 1e10
for i in range(N-K+1):
Min = min(Min, x[K+i-1]-x[i]+min(abs(x[i]),abs(x[K+i-1])))
print(Min)
```
| 106,856 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning. Snuke decides to light K of the N candles.
Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.
Find the minimum time required to light K candles.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq K \leq N
* x_i is an integer.
* |x_i| \leq 10^8
* x_1 < x_2 < ... < x_N
Input
Input is given from Standard Input in the following format:
N K
x_1 x_2 ... x_N
Output
Print the minimum time required to light K candles.
Examples
Input
5 3
-30 -10 10 20 50
Output
40
Input
3 2
10 20 30
Output
20
Input
1 1
0
Output
0
Input
8 5
-9 -7 -4 -3 1 2 3 4
Output
10
Submitted Solution:
```
N, K = map(int, input().split())
X = list(map(int, input().split()))
ans_ar = []
for i in range(N-K+1):
ans_ar.append(min(abs(X[i]), abs(X[i+K-1])) + (X[i+K-1] - X[i]))
print(min(ans_ar))
```
Yes
| 106,857 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning. Snuke decides to light K of the N candles.
Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.
Find the minimum time required to light K candles.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq K \leq N
* x_i is an integer.
* |x_i| \leq 10^8
* x_1 < x_2 < ... < x_N
Input
Input is given from Standard Input in the following format:
N K
x_1 x_2 ... x_N
Output
Print the minimum time required to light K candles.
Examples
Input
5 3
-30 -10 10 20 50
Output
40
Input
3 2
10 20 30
Output
20
Input
1 1
0
Output
0
Input
8 5
-9 -7 -4 -3 1 2 3 4
Output
10
Submitted Solution:
```
N,K=map(int,input().split())
L=list(map(int,input().split()))
ans=1000000010
for i in range(N-K+1):
ans=min(ans,(min(abs(L[i]),abs(L[i+K-1]))+L[i+K-1]-L[i]))
print(ans)
```
Yes
| 106,858 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning. Snuke decides to light K of the N candles.
Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.
Find the minimum time required to light K candles.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq K \leq N
* x_i is an integer.
* |x_i| \leq 10^8
* x_1 < x_2 < ... < x_N
Input
Input is given from Standard Input in the following format:
N K
x_1 x_2 ... x_N
Output
Print the minimum time required to light K candles.
Examples
Input
5 3
-30 -10 10 20 50
Output
40
Input
3 2
10 20 30
Output
20
Input
1 1
0
Output
0
Input
8 5
-9 -7 -4 -3 1 2 3 4
Output
10
Submitted Solution:
```
n,k,*a=map(int,open(0).read().split())
print(min(r-l+min(abs(r),abs(l))for l,r in zip(a,a[k-1:])))
```
Yes
| 106,859 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning. Snuke decides to light K of the N candles.
Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.
Find the minimum time required to light K candles.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq K \leq N
* x_i is an integer.
* |x_i| \leq 10^8
* x_1 < x_2 < ... < x_N
Input
Input is given from Standard Input in the following format:
N K
x_1 x_2 ... x_N
Output
Print the minimum time required to light K candles.
Examples
Input
5 3
-30 -10 10 20 50
Output
40
Input
3 2
10 20 30
Output
20
Input
1 1
0
Output
0
Input
8 5
-9 -7 -4 -3 1 2 3 4
Output
10
Submitted Solution:
```
n, k, *a = map(int, open(0).read().split())
m = INF = float("inf")
for i in range(n - k + 1):
l, r = a[i], a[i + k - 1]
c = abs(r-l)
m = min(m, min(abs(l) + c, abs(r) + c))
print(m)
```
Yes
| 106,860 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning. Snuke decides to light K of the N candles.
Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.
Find the minimum time required to light K candles.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq K \leq N
* x_i is an integer.
* |x_i| \leq 10^8
* x_1 < x_2 < ... < x_N
Input
Input is given from Standard Input in the following format:
N K
x_1 x_2 ... x_N
Output
Print the minimum time required to light K candles.
Examples
Input
5 3
-30 -10 10 20 50
Output
40
Input
3 2
10 20 30
Output
20
Input
1 1
0
Output
0
Input
8 5
-9 -7 -4 -3 1 2 3 4
Output
10
Submitted Solution:
```
import numpy as np
n, k = map(int, input().split())
lst = list(map(int, input().split()))
#array = np.array(lst)
#po_array = array[array>=0]
#ne_array = abs(array[array<0])
#ne_array.sort()
po_array = sorted([x for x in lst if x >= 0])
ne_array = sorted([abs(x) for x in lst if x < 0])
if len(po_array) >= len(ne_array):
long_array = po_array
short_array = ne_array
else:
long_array = ne_array
short_array = po_array
if len(short_array) > k:
min_len = k
else:
min_len = len(short_array)
if min_len == 0:
print(long_array[k-1])
else:
min_dist = 10**10
for i in range(min_len):
if i == k-1:
dist = short_array[i]
else:
dist = min(short_array[i]*2 + long_array[k-i-2], short_array[i] + long_array[k-i-2]*2)
if min_dist > dist:
min_dist = dist
if len(long_array) >= k:
if min_dist > long_array[k-1]:
min_dist = long_array[k-1]
print(min_dist)
```
No
| 106,861 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning. Snuke decides to light K of the N candles.
Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.
Find the minimum time required to light K candles.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq K \leq N
* x_i is an integer.
* |x_i| \leq 10^8
* x_1 < x_2 < ... < x_N
Input
Input is given from Standard Input in the following format:
N K
x_1 x_2 ... x_N
Output
Print the minimum time required to light K candles.
Examples
Input
5 3
-30 -10 10 20 50
Output
40
Input
3 2
10 20 30
Output
20
Input
1 1
0
Output
0
Input
8 5
-9 -7 -4 -3 1 2 3 4
Output
10
Submitted Solution:
```
import numpy as np
n,k = list(map(int,input().split()))
x = list(map(int,input().split()))
n = len(x)
if 0 in x:
x.remove(0)
k = k - 1
if len(x) == 0:
print(0)
else:
scores = []
xx = np.array(x)
a = xx >= 0
pos = sum(a)
neg = n - pos
pos_ind = a
try:
b = np.where(a)[0][0]
except:
b = 0
if pos >= k:
scores.append(np.sum(xx[pos_ind][k-1]))
# print(scores)
for i in range(min([pos,k])):
if b + i - k + 1 < 0:
break
score = xx[b + i] * 2 - xx[b + i - k + 1]
scores.append(score)
# print(scores)
xx = np.array(x)
xx = - xx
xx = xx[::-1]
a = xx >= 0
pos = sum(a)
neg = n - pos
pos_ind = a
try:
b = np.where(a)[0][0]
except:
b = 0
if pos >= k:
scores.append(np.sum(xx[pos_ind][k-1]))
# print(scores)
for i in range(min([pos,k])):
if b + i - k + 1 < 0:
break
score = xx[b + i] * 2 - xx[b + i - k + 1]
scores.append(score)
# print(scores)
print(np.min(scores))
```
No
| 106,862 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning. Snuke decides to light K of the N candles.
Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.
Find the minimum time required to light K candles.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq K \leq N
* x_i is an integer.
* |x_i| \leq 10^8
* x_1 < x_2 < ... < x_N
Input
Input is given from Standard Input in the following format:
N K
x_1 x_2 ... x_N
Output
Print the minimum time required to light K candles.
Examples
Input
5 3
-30 -10 10 20 50
Output
40
Input
3 2
10 20 30
Output
20
Input
1 1
0
Output
0
Input
8 5
-9 -7 -4 -3 1 2 3 4
Output
10
Submitted Solution:
```
N, K = map(int, input().split())
x = list(map(int, input().split()))
dist = []
for i in range(N-K+1):
a = 0
tmp = x[i:i+K]
mini, maxi = tmp[0], tmp[-1]
if (mini >= 0 and maxi >= 0):
a = maxi
elif (mini < 0 and maxi < 0):
a = abs(mixi)
if mini < 0 and maxi >= 0:
a = abs(mixi) + maxi + min(abs(mixi), maxi)
dist.append(a)
print(min(dist))
```
No
| 106,863 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning. Snuke decides to light K of the N candles.
Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.
Find the minimum time required to light K candles.
Constraints
* 1 \leq N \leq 10^5
* 1 \leq K \leq N
* x_i is an integer.
* |x_i| \leq 10^8
* x_1 < x_2 < ... < x_N
Input
Input is given from Standard Input in the following format:
N K
x_1 x_2 ... x_N
Output
Print the minimum time required to light K candles.
Examples
Input
5 3
-30 -10 10 20 50
Output
40
Input
3 2
10 20 30
Output
20
Input
1 1
0
Output
0
Input
8 5
-9 -7 -4 -3 1 2 3 4
Output
10
Submitted Solution:
```
#coding:utf-8
# n, k = 5, 3
# ls = [-30,-10,10,20,50]
# n,k = 3,2
# ls=[10,20,30]
# n,k = 1,1
# ls = [0]
#n,k=8,5
#ls=[-9,-7,-4,-3,1,2,3,4]
first = -1
for i,point in enumerate(ls):
if point >= 0:
first = i
break
size=k+1
ans = []
for i in range(size):
if first-size+i+1>=0 and first+i-1< len(ls):
temp = [0,ls[first-size+i+1],ls[first+i-1]]
temp = [abs(min(temp)),abs(max(temp))]
ans.append((2*min(temp)+max(temp)))
print (min(ans))
```
No
| 106,864 |
Provide a correct Python 3 solution for this coding contest problem.
In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage.
A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules:
* A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten.
* A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten.
Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process K times:
* Grab either a red ball or a blue ball.
* Throw that ball into the cage. Then, one of the chameleons eats it.
After Ringo threw in K balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in K balls. How many such ways are there? Find the count modulo 998244353. Here, two ways to throw in balls are considered different when there exists i such that the color of the ball that are thrown in the i-th throw is different.
Constraints
* 1 \leq N,K \leq 5 \times 10^5
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the possible ways Ringo could have thrown in K balls, modulo 998244353.
Examples
Input
2 4
Output
7
Input
3 7
Output
57
Input
8 3
Output
0
Input
8 10
Output
46
Input
123456 234567
Output
857617983
"Correct Solution:
```
n,k=map(int,input().split());p=998244353
r=range
f=[1]
for i in r(k):f+=[-~i*f[i]%p]
print(sum(f[-2]*pow(f[i]*f[-2-i],-1,p)for i in r(n-1,k))%p)
```
| 106,865 |
Provide a correct Python 3 solution for this coding contest problem.
In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage.
A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules:
* A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten.
* A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten.
Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process K times:
* Grab either a red ball or a blue ball.
* Throw that ball into the cage. Then, one of the chameleons eats it.
After Ringo threw in K balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in K balls. How many such ways are there? Find the count modulo 998244353. Here, two ways to throw in balls are considered different when there exists i such that the color of the ball that are thrown in the i-th throw is different.
Constraints
* 1 \leq N,K \leq 5 \times 10^5
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the possible ways Ringo could have thrown in K balls, modulo 998244353.
Examples
Input
2 4
Output
7
Input
3 7
Output
57
Input
8 3
Output
0
Input
8 10
Output
46
Input
123456 234567
Output
857617983
"Correct Solution:
```
n,k=map(int,input().split());p=998244353;r=range;f=[1]
for i in r(k):f+=[-~i*f[i]%p]
print(sum(f[-2]*pow(f[i]*f[-2-i],-1,p)for i in r(n-1,k))%p)
```
| 106,866 |
Provide a correct Python 3 solution for this coding contest problem.
In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage.
A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules:
* A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten.
* A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten.
Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process K times:
* Grab either a red ball or a blue ball.
* Throw that ball into the cage. Then, one of the chameleons eats it.
After Ringo threw in K balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in K balls. How many such ways are there? Find the count modulo 998244353. Here, two ways to throw in balls are considered different when there exists i such that the color of the ball that are thrown in the i-th throw is different.
Constraints
* 1 \leq N,K \leq 5 \times 10^5
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the possible ways Ringo could have thrown in K balls, modulo 998244353.
Examples
Input
2 4
Output
7
Input
3 7
Output
57
Input
8 3
Output
0
Input
8 10
Output
46
Input
123456 234567
Output
857617983
"Correct Solution:
```
n,k=map(int,input().split())
p=998244353
r=range
f=[1]
for i in r(k):f+=[-~i*f[i]%p]
print(sum(f[-2]*pow(f[i]*f[-2-i],-1,p)for i in r(n-1,k))%p)
```
| 106,867 |
Provide a correct Python 3 solution for this coding contest problem.
In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage.
A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules:
* A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten.
* A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten.
Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process K times:
* Grab either a red ball or a blue ball.
* Throw that ball into the cage. Then, one of the chameleons eats it.
After Ringo threw in K balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in K balls. How many such ways are there? Find the count modulo 998244353. Here, two ways to throw in balls are considered different when there exists i such that the color of the ball that are thrown in the i-th throw is different.
Constraints
* 1 \leq N,K \leq 5 \times 10^5
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the possible ways Ringo could have thrown in K balls, modulo 998244353.
Examples
Input
2 4
Output
7
Input
3 7
Output
57
Input
8 3
Output
0
Input
8 10
Output
46
Input
123456 234567
Output
857617983
"Correct Solution:
```
n,k=map(int,input().split())
p=998244353
r=range
f=[1]
for i in r(k):f+=[-~i*f[i]%p]
print(sum(f[k-1]*pow(f[i]*f[k-1-i],-1,p)for i in r(n-1,k))%p)
```
| 106,868 |
Provide a correct Python 3 solution for this coding contest problem.
In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage.
A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules:
* A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten.
* A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten.
Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process K times:
* Grab either a red ball or a blue ball.
* Throw that ball into the cage. Then, one of the chameleons eats it.
After Ringo threw in K balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in K balls. How many such ways are there? Find the count modulo 998244353. Here, two ways to throw in balls are considered different when there exists i such that the color of the ball that are thrown in the i-th throw is different.
Constraints
* 1 \leq N,K \leq 5 \times 10^5
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the possible ways Ringo could have thrown in K balls, modulo 998244353.
Examples
Input
2 4
Output
7
Input
3 7
Output
57
Input
8 3
Output
0
Input
8 10
Output
46
Input
123456 234567
Output
857617983
"Correct Solution:
```
def solve(n, k):
MOD = 998244353
if n > k:
return 0
if n == 1:
return pow(2, k - 1, MOD)
pf, kf = 1, 1
for m in range(2, k + 1):
pf = kf
kf *= m
kf %= MOD
inv = pow(kf, MOD - 2, MOD)
invs = [1] * (k + 1)
invs[k] = inv
for m in range(k, 1, -1):
inv *= m
inv %= MOD
invs[m - 1] = inv
ans = 0
if k & 1 == 0:
r = k >> 1
s = k - n + 1
ans = pf * (invs[r] * invs[r - 1] - invs[s] * invs[k - s - 1]) % MOD
for r in range(k // 2 + 1, k + 1):
if r * 2 >= n + k:
ans += kf * invs[r] * invs[k - r]
else:
s = r * 2 - n + 1
ans += kf * (invs[r] * invs[k - r] - invs[s] * invs[k - s])
ans %= MOD
return ans
print(solve(*map(int, input().split())))
```
| 106,869 |
Provide a correct Python 3 solution for this coding contest problem.
In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage.
A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules:
* A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten.
* A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten.
Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process K times:
* Grab either a red ball or a blue ball.
* Throw that ball into the cage. Then, one of the chameleons eats it.
After Ringo threw in K balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in K balls. How many such ways are there? Find the count modulo 998244353. Here, two ways to throw in balls are considered different when there exists i such that the color of the ball that are thrown in the i-th throw is different.
Constraints
* 1 \leq N,K \leq 5 \times 10^5
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the possible ways Ringo could have thrown in K balls, modulo 998244353.
Examples
Input
2 4
Output
7
Input
3 7
Output
57
Input
8 3
Output
0
Input
8 10
Output
46
Input
123456 234567
Output
857617983
"Correct Solution:
```
n,k=map(int,input().split())
p=998244353
r=range
f=[1]
for i in r(k):f+=[-~i*f[i]%p]
a=0
for i in r(n-1,k):a+=f[k-1]*pow(f[i]*f[k-1-i],-1,p)
print(a%p)
```
| 106,870 |
Provide a correct Python 3 solution for this coding contest problem.
In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage.
A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules:
* A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten.
* A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten.
Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process K times:
* Grab either a red ball or a blue ball.
* Throw that ball into the cage. Then, one of the chameleons eats it.
After Ringo threw in K balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in K balls. How many such ways are there? Find the count modulo 998244353. Here, two ways to throw in balls are considered different when there exists i such that the color of the ball that are thrown in the i-th throw is different.
Constraints
* 1 \leq N,K \leq 5 \times 10^5
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the possible ways Ringo could have thrown in K balls, modulo 998244353.
Examples
Input
2 4
Output
7
Input
3 7
Output
57
Input
8 3
Output
0
Input
8 10
Output
46
Input
123456 234567
Output
857617983
"Correct Solution:
```
n,k=map(int,input().split())
p=998244353
f=[1]
for i in range(k):f+=[-~i*f[i]%p]
print(sum(f[-2]*pow(f[i]*f[-2-i],-1,p)for i in range(n-1,k))%p)
```
| 106,871 |
Provide a correct Python 3 solution for this coding contest problem.
In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage.
A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules:
* A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten.
* A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten.
Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process K times:
* Grab either a red ball or a blue ball.
* Throw that ball into the cage. Then, one of the chameleons eats it.
After Ringo threw in K balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in K balls. How many such ways are there? Find the count modulo 998244353. Here, two ways to throw in balls are considered different when there exists i such that the color of the ball that are thrown in the i-th throw is different.
Constraints
* 1 \leq N,K \leq 5 \times 10^5
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the possible ways Ringo could have thrown in K balls, modulo 998244353.
Examples
Input
2 4
Output
7
Input
3 7
Output
57
Input
8 3
Output
0
Input
8 10
Output
46
Input
123456 234567
Output
857617983
"Correct Solution:
```
def combs_mod(n,k,mod):
#nC0からnCkまで
inv = [1]*(k+1)
for i in range(1,k+1):
inv[i] = pow(i,mod-2,mod)
ans = [1]*(k+1)
for i in range(1,k+1):
ans[i] = ans[i-1]*(n+1-i)*inv[i]%mod
return ans
def solve():
mod = 998244353
N, K = map(int, input().split())
ans = 0
if K<N:
return ans
com = combs_mod(K,K,mod)
com2 = combs_mod(K-1,K-1,mod)
for r in range(K+1):
b = K-r
dif = r-b
if dif<0 or r<N:
continue
elif dif==0:
ans += com2[r]
if N>=2:
ans -= com2[N-2]
elif dif<N:
ans += com[r] - com[N-1-dif]
else:
ans += com[r]
ans %= mod
return ans
print(solve())
```
| 106,872 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage.
A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules:
* A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten.
* A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten.
Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process K times:
* Grab either a red ball or a blue ball.
* Throw that ball into the cage. Then, one of the chameleons eats it.
After Ringo threw in K balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in K balls. How many such ways are there? Find the count modulo 998244353. Here, two ways to throw in balls are considered different when there exists i such that the color of the ball that are thrown in the i-th throw is different.
Constraints
* 1 \leq N,K \leq 5 \times 10^5
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the possible ways Ringo could have thrown in K balls, modulo 998244353.
Examples
Input
2 4
Output
7
Input
3 7
Output
57
Input
8 3
Output
0
Input
8 10
Output
46
Input
123456 234567
Output
857617983
Submitted Solution:
```
#メモ代わりの写経
n,k=map(int,input().split())
p=998244353
f=[1]
#階乗のリストを先に作っておく
for i in range(k):
#f+=[-~i*f[i]%p]
f+=[(i+1)*f[i]%p]
#combinationsの総和
print(sum(f[-2]*pow(f[i]*f[-2-i],-1,p)for i in range(n-1,k))%p)
```
Yes
| 106,873 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage.
A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules:
* A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten.
* A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten.
Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process K times:
* Grab either a red ball or a blue ball.
* Throw that ball into the cage. Then, one of the chameleons eats it.
After Ringo threw in K balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in K balls. How many such ways are there? Find the count modulo 998244353. Here, two ways to throw in balls are considered different when there exists i such that the color of the ball that are thrown in the i-th throw is different.
Constraints
* 1 \leq N,K \leq 5 \times 10^5
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the possible ways Ringo could have thrown in K balls, modulo 998244353.
Examples
Input
2 4
Output
7
Input
3 7
Output
57
Input
8 3
Output
0
Input
8 10
Output
46
Input
123456 234567
Output
857617983
Submitted Solution:
```
def combs_mod(n,k,mod):
#nC0からnCkまで
inv = [1]*(k+1)
for i in range(1,k+1):
inv[i] = pow(i,mod-2,mod)
ans = [1]*(k+1)
for i in range(1,k+1):
ans[i] = ans[i-1]*(n+1-i)*inv[i]%mod
return ans
def solve():
mod = 998244353
N, K = map(int, input().split())
ans = 0
if K<N:
return ans
com = combs_mod(K,K,mod)
for r in range(K+1):
b = K-r
dif = r-b
if dif<0 or r<N:
continue
elif dif==0:
com2 = combs_mod(K-1,K-1,mod)
ans += com2[r]
if N>=2:
ans -= com2[N-2]
elif dif<N:
ans += com[r] - com[N-1-dif]
else:
ans += com[r]
ans %= mod
return ans
print(solve())
```
Yes
| 106,874 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage.
A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules:
* A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten.
* A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten.
Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process K times:
* Grab either a red ball or a blue ball.
* Throw that ball into the cage. Then, one of the chameleons eats it.
After Ringo threw in K balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in K balls. How many such ways are there? Find the count modulo 998244353. Here, two ways to throw in balls are considered different when there exists i such that the color of the ball that are thrown in the i-th throw is different.
Constraints
* 1 \leq N,K \leq 5 \times 10^5
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the possible ways Ringo could have thrown in K balls, modulo 998244353.
Examples
Input
2 4
Output
7
Input
3 7
Output
57
Input
8 3
Output
0
Input
8 10
Output
46
Input
123456 234567
Output
857617983
Submitted Solution:
```
mod = 998244353
def comb(n, r):
if n < r:return 0
if n < 0 or r < 0:return 0
return fa[n] * fi[r] % mod * fi[n - r] % mod
n, k = map(int, input().split())
fa = [1] * (k + 1)
fi = [1] * (k + 1)
for i in range(1, k + 1):
fa[i] = fa[i - 1] * i % mod
fi[i] = pow(fa[i], mod - 2, mod)
ans = 0
for i in range(k - n + 1):
ans += comb(k - 1, n + i - 1)
ans %= mod
print(ans)
```
Yes
| 106,875 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage.
A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules:
* A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten.
* A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten.
Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process K times:
* Grab either a red ball or a blue ball.
* Throw that ball into the cage. Then, one of the chameleons eats it.
After Ringo threw in K balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in K balls. How many such ways are there? Find the count modulo 998244353. Here, two ways to throw in balls are considered different when there exists i such that the color of the ball that are thrown in the i-th throw is different.
Constraints
* 1 \leq N,K \leq 5 \times 10^5
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the possible ways Ringo could have thrown in K balls, modulo 998244353.
Examples
Input
2 4
Output
7
Input
3 7
Output
57
Input
8 3
Output
0
Input
8 10
Output
46
Input
123456 234567
Output
857617983
Submitted Solution:
```
def solve(n, k):
MOD = 998244353
if n > k:
return 0
if n == 1:
return pow(2, k - 1, MOD)
invs = [1] * (k + 1)
pf, kf = 1, 1
for m in range(2, k + 1):
pf = kf
kf *= m
kf %= MOD
invs[m] = pow(kf, MOD - 2, MOD)
ans = 0
if k & 1 == 0:
r = k >> 1
s = k - n + 1
ans = pf * (invs[r] * invs[r - 1] - invs[s] * invs[k - s - 1]) % MOD
for r in range(k // 2 + 1, k + 1):
if r * 2 >= n + k:
ans += kf * invs[r] * invs[k - r]
else:
s = r * 2 - n + 1
ans += kf * (invs[r] * invs[k - r] - invs[s] * invs[k - s])
ans %= MOD
return ans
print(solve(*map(int, input().split())))
```
Yes
| 106,876 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage.
A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules:
* A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten.
* A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten.
Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process K times:
* Grab either a red ball or a blue ball.
* Throw that ball into the cage. Then, one of the chameleons eats it.
After Ringo threw in K balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in K balls. How many such ways are there? Find the count modulo 998244353. Here, two ways to throw in balls are considered different when there exists i such that the color of the ball that are thrown in the i-th throw is different.
Constraints
* 1 \leq N,K \leq 5 \times 10^5
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the possible ways Ringo could have thrown in K balls, modulo 998244353.
Examples
Input
2 4
Output
7
Input
3 7
Output
57
Input
8 3
Output
0
Input
8 10
Output
46
Input
123456 234567
Output
857617983
Submitted Solution:
```
def combs_mod(n,k,mod):
#nC0からnCkまで
inv = [1]*(k+1)
for i in range(1,k+1):
inv[i] = pow(i,mod-2,mod)
ans = [1]*(k+1)
for i in range(1,k+1):
ans[i] = ans[i-1]*(n+1-i)*inv[i]%mod
return ans
def solve():
mod = 998244353
N, K = map(int, input().split())
ans = 0
if K<N:
return ans
com = combs_mod(K,K,mod)
com2 = combs_mod(K-1,K-1,mod)
for r in range(K+1):
b = K-r
dif = r-b
if dif<0 or r<N:
continue
elif dif==0:
ans += com2[r]
if N>=2:
ans -= com2[N-2]
elif dif<N:
ans += com[r] - com[N-1-dif]
else:
ans += com[r]
ans %= mod
return ans
print(solve())
```
No
| 106,877 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage.
A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules:
* A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten.
* A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten.
Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process K times:
* Grab either a red ball or a blue ball.
* Throw that ball into the cage. Then, one of the chameleons eats it.
After Ringo threw in K balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in K balls. How many such ways are there? Find the count modulo 998244353. Here, two ways to throw in balls are considered different when there exists i such that the color of the ball that are thrown in the i-th throw is different.
Constraints
* 1 \leq N,K \leq 5 \times 10^5
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the possible ways Ringo could have thrown in K balls, modulo 998244353.
Examples
Input
2 4
Output
7
Input
3 7
Output
57
Input
8 3
Output
0
Input
8 10
Output
46
Input
123456 234567
Output
857617983
Submitted Solution:
```
def solve(n, k):
MOD = 998244353
if n > k:
return 0
invs = [1] * (k + 1)
pf, kf = 1, 1
for m in range(2, k + 1):
pf = kf
kf *= m
kf %= MOD
invs[m] = pow(kf, MOD - 2, MOD)
ans = 0
if k & 1 == 0:
if n == 1:
ans = 1
else:
r = k >> 1
t = r - n + 1
ans = pf * (invs[r] * invs[r - 1] - invs[r + t] * invs[k - r - t - 1]) % MOD
for r in range(k // 2 + 1, k + 1):
if r * 2 >= n + k:
ans += kf * invs[r] * invs[k - r]
else:
t = r - n + 1
ans += kf * (invs[r] * invs[k - r] - invs[r + t] * invs[k - r - t])
ans %= MOD
return ans
print(solve(*map(int, input().split())))
```
No
| 106,878 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage.
A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules:
* A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten.
* A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten.
Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process K times:
* Grab either a red ball or a blue ball.
* Throw that ball into the cage. Then, one of the chameleons eats it.
After Ringo threw in K balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in K balls. How many such ways are there? Find the count modulo 998244353. Here, two ways to throw in balls are considered different when there exists i such that the color of the ball that are thrown in the i-th throw is different.
Constraints
* 1 \leq N,K \leq 5 \times 10^5
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the possible ways Ringo could have thrown in K balls, modulo 998244353.
Examples
Input
2 4
Output
7
Input
3 7
Output
57
Input
8 3
Output
0
Input
8 10
Output
46
Input
123456 234567
Output
857617983
Submitted Solution:
```
n,k=map(int,input().split())
p=998244353
r=range
f=[1]
for i in r(k):f+=[-~i*f[i]%p]
print(sum(f[-2]*pow(f[i]*f[-2-i],-1,p)for i in r(n-1,k))%p)
```
No
| 106,879 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage.
A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules:
* A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten.
* A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten.
Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process K times:
* Grab either a red ball or a blue ball.
* Throw that ball into the cage. Then, one of the chameleons eats it.
After Ringo threw in K balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in K balls. How many such ways are there? Find the count modulo 998244353. Here, two ways to throw in balls are considered different when there exists i such that the color of the ball that are thrown in the i-th throw is different.
Constraints
* 1 \leq N,K \leq 5 \times 10^5
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the possible ways Ringo could have thrown in K balls, modulo 998244353.
Examples
Input
2 4
Output
7
Input
3 7
Output
57
Input
8 3
Output
0
Input
8 10
Output
46
Input
123456 234567
Output
857617983
Submitted Solution:
```
def combs_mod(n,k,mod):
#nC0からnCkまで
inv = [1]*(k+1)
for i in range(1,k+1):
inv[i] = pow(i,mod-2,mod)
ans = [1]*(k+1)
for i in range(1,k+1):
ans[i] = ans[i-1]*(n+1-i)*inv[i]%mod
return ans
def solve():
mod = 998244353
N, K = map(int, input().split())
ans = 0
if K<N:
return ans
com = combs_mod(K,K,mod)
for r in range(K+1):
b = K-r
if r<b or r<N:
continue
ans += com[r]
if r-b<N:
ans -= com[max(b,N)-1+b-r]
ans %= mod
return ans
print(solve())
```
No
| 106,880 |
Provide a correct Python 3 solution for this coding contest problem.
Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities.
Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.
Find the maximum possible sum of utilities of purchased integers.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq K < 2^{30}
* 0 \leq A_i < 2^{30}(1\leq i\leq N)
* 1 \leq B_i \leq 10^9(1\leq i\leq N)
* All input values are integers.
Inputs
Input is given from Standard Input in the following format:
N K
A_1 B_1
:
A_N B_N
Outputs
Print the maximum possible sum of utilities of purchased integers.
Examples
Input
3 5
3 3
4 4
2 5
Output
8
Input
3 6
3 3
4 4
2 5
Output
9
Input
7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
Output
32
"Correct Solution:
```
n, k = [int(x) for x in input().strip().split()]
ls = []
for _ in range(n):
ls.append(tuple(int(x) for x in input().strip().split()))
bk = bin(k)[2:]
cands = [k]
for i in range(len(bk)):
if bk[i] == '1':
cands.append(int(bk[:i] + '0' + '1'*(len(bk)-i-1), base=2))
m_ = len(cands)
max_ = [0] * m_
for a, b in ls:
for i in range(m_):
if a | cands[i] == cands[i]:
max_[i] += b
print(max(max_))
```
| 106,881 |
Provide a correct Python 3 solution for this coding contest problem.
Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities.
Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.
Find the maximum possible sum of utilities of purchased integers.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq K < 2^{30}
* 0 \leq A_i < 2^{30}(1\leq i\leq N)
* 1 \leq B_i \leq 10^9(1\leq i\leq N)
* All input values are integers.
Inputs
Input is given from Standard Input in the following format:
N K
A_1 B_1
:
A_N B_N
Outputs
Print the maximum possible sum of utilities of purchased integers.
Examples
Input
3 5
3 3
4 4
2 5
Output
8
Input
3 6
3 3
4 4
2 5
Output
9
Input
7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
Output
32
"Correct Solution:
```
n, k = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
l = []
kb = bin(k)
ll = [k]
for i in range(len(kb) - 2):
if kb[i + 2] == '1':
ll.append(int(kb[:i + 2] + '0' + '1' * (len(kb) - (i + 3)), 2))
for i in ll:
ans = 0
for j in range(n):
if i == ab[j][0] | i:
ans += ab[j][1]
l.append(ans)
print(max(l))
```
| 106,882 |
Provide a correct Python 3 solution for this coding contest problem.
Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities.
Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.
Find the maximum possible sum of utilities of purchased integers.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq K < 2^{30}
* 0 \leq A_i < 2^{30}(1\leq i\leq N)
* 1 \leq B_i \leq 10^9(1\leq i\leq N)
* All input values are integers.
Inputs
Input is given from Standard Input in the following format:
N K
A_1 B_1
:
A_N B_N
Outputs
Print the maximum possible sum of utilities of purchased integers.
Examples
Input
3 5
3 3
4 4
2 5
Output
8
Input
3 6
3 3
4 4
2 5
Output
9
Input
7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
Output
32
"Correct Solution:
```
N,K=map(int,input().split())
ad=dict()
al=ad.keys()
for i in range(N):
a,b=map(int,input().split())
if not a in ad:
ad[a]=b
else:
ad[a]+=b
bk=bin(K)
lbk=len(bk)-2
k1=2**(lbk-1)-1
kl=[]
for i in range(lbk):
ki=str(bk)[i+2]
if ki=='1':
kk=2**(lbk-1-int(i))
kl.append((K-kk)|(kk-1))
kl.append(K)
kll=[0for i in range(len(kl))]
for i in range(len(kl)):
for n in al:
if n | kl[i]==kl[i]:
kll[i]+=ad[n]
print(max(kll))
```
| 106,883 |
Provide a correct Python 3 solution for this coding contest problem.
Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities.
Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.
Find the maximum possible sum of utilities of purchased integers.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq K < 2^{30}
* 0 \leq A_i < 2^{30}(1\leq i\leq N)
* 1 \leq B_i \leq 10^9(1\leq i\leq N)
* All input values are integers.
Inputs
Input is given from Standard Input in the following format:
N K
A_1 B_1
:
A_N B_N
Outputs
Print the maximum possible sum of utilities of purchased integers.
Examples
Input
3 5
3 3
4 4
2 5
Output
8
Input
3 6
3 3
4 4
2 5
Output
9
Input
7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
Output
32
"Correct Solution:
```
import sys
import math
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]
def main():
N, K = NMI()
integars = [NLI() for _ in range(N)]
Kr = [K]
now_k = 0
for i in range(32, -1, -1):
now_bit = (K >> i) & 1
if now_bit == 0:
continue
now_k += pow(2, i)
Kr.append(now_k - 1)
ans = 0
for kr in Kr:
tmp = 0
for a, b in integars:
if (kr | a) == kr:
tmp += b
ans = max(ans, tmp)
print(ans)
if __name__ == "__main__":
main()
```
| 106,884 |
Provide a correct Python 3 solution for this coding contest problem.
Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities.
Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.
Find the maximum possible sum of utilities of purchased integers.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq K < 2^{30}
* 0 \leq A_i < 2^{30}(1\leq i\leq N)
* 1 \leq B_i \leq 10^9(1\leq i\leq N)
* All input values are integers.
Inputs
Input is given from Standard Input in the following format:
N K
A_1 B_1
:
A_N B_N
Outputs
Print the maximum possible sum of utilities of purchased integers.
Examples
Input
3 5
3 3
4 4
2 5
Output
8
Input
3 6
3 3
4 4
2 5
Output
9
Input
7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
Output
32
"Correct Solution:
```
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
N,K = inpl()
L = K.bit_length()
koho = [K]
tmp = 0
for b in reversed(range(L)):
if (K>>b) & 1:
tmp += (1<<b)
koho.append(tmp-1)
nums = [0]*len(koho)
for _ in range(N):
A,B = inpl()
for i,k in enumerate(koho):
if k|A == k:
nums[i] += B
print(max(nums))
```
| 106,885 |
Provide a correct Python 3 solution for this coding contest problem.
Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities.
Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.
Find the maximum possible sum of utilities of purchased integers.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq K < 2^{30}
* 0 \leq A_i < 2^{30}(1\leq i\leq N)
* 1 \leq B_i \leq 10^9(1\leq i\leq N)
* All input values are integers.
Inputs
Input is given from Standard Input in the following format:
N K
A_1 B_1
:
A_N B_N
Outputs
Print the maximum possible sum of utilities of purchased integers.
Examples
Input
3 5
3 3
4 4
2 5
Output
8
Input
3 6
3 3
4 4
2 5
Output
9
Input
7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
Output
32
"Correct Solution:
```
import sys
N, K = map(int, input().split())
AB = []
for _ in range(N):
AB.append([int(s) for s in input().split()])
ans = 0
kbin = bin(K)[2:]
for a, b in AB:
if K | a == K:
ans += b
for i in range(1, len(kbin)):
if kbin[i - 1] == "0":
continue
kl = list(kbin)
kl[i - 1] = "0"
for j in range(i, len(kbin)):
kl[j] = "1"
km = int("".join(kl), 2)
anscand = 0
for a, b in AB:
if km | a == km:
anscand += b
if ans < anscand:
ans = anscand
print(ans)
```
| 106,886 |
Provide a correct Python 3 solution for this coding contest problem.
Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities.
Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.
Find the maximum possible sum of utilities of purchased integers.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq K < 2^{30}
* 0 \leq A_i < 2^{30}(1\leq i\leq N)
* 1 \leq B_i \leq 10^9(1\leq i\leq N)
* All input values are integers.
Inputs
Input is given from Standard Input in the following format:
N K
A_1 B_1
:
A_N B_N
Outputs
Print the maximum possible sum of utilities of purchased integers.
Examples
Input
3 5
3 3
4 4
2 5
Output
8
Input
3 6
3 3
4 4
2 5
Output
9
Input
7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
Output
32
"Correct Solution:
```
import sys
readline=sys.stdin.readline
read=sys.stdin.read
def main():
n,k=map(int,readline().split())
ab=[list(map(int,l.split())) for l in read().splitlines()]
ek=0
while k>>ek:
ek+=1
cand=[]
for i in range(ek):
if k>>i&1:
m=(k>>(i+1))<<(i+1)|((1<<i)-1)
cand.append(sum([e[1] for e in ab if e[0]|m==m]))
cand.append(sum([e[1] for e in ab if e[0]|k==k]))
print(max(cand))
if __name__=='__main__':
main()
```
| 106,887 |
Provide a correct Python 3 solution for this coding contest problem.
Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities.
Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.
Find the maximum possible sum of utilities of purchased integers.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq K < 2^{30}
* 0 \leq A_i < 2^{30}(1\leq i\leq N)
* 1 \leq B_i \leq 10^9(1\leq i\leq N)
* All input values are integers.
Inputs
Input is given from Standard Input in the following format:
N K
A_1 B_1
:
A_N B_N
Outputs
Print the maximum possible sum of utilities of purchased integers.
Examples
Input
3 5
3 3
4 4
2 5
Output
8
Input
3 6
3 3
4 4
2 5
Output
9
Input
7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
Output
32
"Correct Solution:
```
def solve(K, ABs):
if not ABs: return 0
ansK = sum(b for a, b in ABs if (K | a) == K)
pool = []
for i in range(30, -1, -1):
if (K & (1<<i)):
pool.append(i)
for p in pool:
v = 1 << p
KK = (K >> p) << p
KKK = (K >> p)
t = sum(b for a, b in ABs if (not(a & v) and ((a | KK) >> p) == KKK))
if t > ansK:
ansK = t
return ansK
N, K = map(int, input().split())
ABs = []
for i in range(N):
a, b = map(int, input().split())
if a > K: continue
ABs.append([a, b])
print(solve(K, ABs))
```
| 106,888 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities.
Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.
Find the maximum possible sum of utilities of purchased integers.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq K < 2^{30}
* 0 \leq A_i < 2^{30}(1\leq i\leq N)
* 1 \leq B_i \leq 10^9(1\leq i\leq N)
* All input values are integers.
Inputs
Input is given from Standard Input in the following format:
N K
A_1 B_1
:
A_N B_N
Outputs
Print the maximum possible sum of utilities of purchased integers.
Examples
Input
3 5
3 3
4 4
2 5
Output
8
Input
3 6
3 3
4 4
2 5
Output
9
Input
7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
Output
32
Submitted Solution:
```
N,K=map(int,input().split())
AB=[]
for i in range(N):
a,b=map(int,input().split())
AB.append([a,b])
ans=sum([b for a,b in AB if K|a==K])
for i in range(int.bit_length(K)-1,0,-1):
if not K &(1<<i):
continue
m=K & ~(1<<i)|(1<<i)-1
s=sum([b for a,b in AB if m | a ==m])
ans=max(s,ans)
print(ans)
```
Yes
| 106,889 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities.
Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.
Find the maximum possible sum of utilities of purchased integers.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq K < 2^{30}
* 0 \leq A_i < 2^{30}(1\leq i\leq N)
* 1 \leq B_i \leq 10^9(1\leq i\leq N)
* All input values are integers.
Inputs
Input is given from Standard Input in the following format:
N K
A_1 B_1
:
A_N B_N
Outputs
Print the maximum possible sum of utilities of purchased integers.
Examples
Input
3 5
3 3
4 4
2 5
Output
8
Input
3 6
3 3
4 4
2 5
Output
9
Input
7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
Output
32
Submitted Solution:
```
n, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
k_subset = [k]
for i in range(len(bin(k)) - 2):
if (k >> i) & 1:
x = k & ~(1 << i) # remove i-th bit
x = x | ((1 << i) - 1) # add 1 to j-th bit (j<i)
k_subset.append(x)
ans = max(sum(b for a, b in ab if a | x == x) for x in k_subset)
print(ans)
```
Yes
| 106,890 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities.
Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.
Find the maximum possible sum of utilities of purchased integers.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq K < 2^{30}
* 0 \leq A_i < 2^{30}(1\leq i\leq N)
* 1 \leq B_i \leq 10^9(1\leq i\leq N)
* All input values are integers.
Inputs
Input is given from Standard Input in the following format:
N K
A_1 B_1
:
A_N B_N
Outputs
Print the maximum possible sum of utilities of purchased integers.
Examples
Input
3 5
3 3
4 4
2 5
Output
8
Input
3 6
3 3
4 4
2 5
Output
9
Input
7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
Output
32
Submitted Solution:
```
import sys
readline=sys.stdin.readline
read=sys.stdin.read
def main():
n,k=map(int,readline().split())
ab=[list(map(int,l.split())) for l in read().splitlines()]
ek=0
while k>>ek:
ek+=1
ans=0
for i in range(ek):
if k>>i&1:
m=(k>>(i+1))<<(i+1)|((1<<i)-1)
ans=max(ans,sum([e[1] for e in ab if e[0]|m==m]))
ans=max(ans,sum([e[1] for e in ab if e[0]|k==k]))
print(ans)
if __name__=='__main__':
main()
```
Yes
| 106,891 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities.
Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.
Find the maximum possible sum of utilities of purchased integers.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq K < 2^{30}
* 0 \leq A_i < 2^{30}(1\leq i\leq N)
* 1 \leq B_i \leq 10^9(1\leq i\leq N)
* All input values are integers.
Inputs
Input is given from Standard Input in the following format:
N K
A_1 B_1
:
A_N B_N
Outputs
Print the maximum possible sum of utilities of purchased integers.
Examples
Input
3 5
3 3
4 4
2 5
Output
8
Input
3 6
3 3
4 4
2 5
Output
9
Input
7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
Output
32
Submitted Solution:
```
n, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ans = sum(b for a, b in ab if a | k == k)
k_bin = bin(k)
# print(k_bin)
for i in range(len(k_bin) - 2):
if (k >> i) & 1:
x = k_bin[:-(i + 1)] + '0' + '1' * i
x = int(x, 0)
cand = 0
for a, b in ab:
if a | x == x:
cand += b
# print(i, bin(x), cand)
ans = max(ans, cand)
print(ans)
```
Yes
| 106,892 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities.
Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.
Find the maximum possible sum of utilities of purchased integers.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq K < 2^{30}
* 0 \leq A_i < 2^{30}(1\leq i\leq N)
* 1 \leq B_i \leq 10^9(1\leq i\leq N)
* All input values are integers.
Inputs
Input is given from Standard Input in the following format:
N K
A_1 B_1
:
A_N B_N
Outputs
Print the maximum possible sum of utilities of purchased integers.
Examples
Input
3 5
3 3
4 4
2 5
Output
8
Input
3 6
3 3
4 4
2 5
Output
9
Input
7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
Output
32
Submitted Solution:
```
import itertools
n,k = map(int,input().split())
arr = [list(map(int,input().split())) for i in range(n)]
nums = []
dic = {}
for i in arr:
dic[i[0]] = i[1]
ans = 0
tmp = 0
for i in arr:
nums.append(i[0])
for i in range(n):
for c in itertools.permutations(nums,i):
if sum(c) <= k:
for j in range(len(c)):
tmp += dic[c[j]]
if tmp > ans:
ans = tmp
tmp = 0
print(ans)
```
No
| 106,893 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities.
Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.
Find the maximum possible sum of utilities of purchased integers.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq K < 2^{30}
* 0 \leq A_i < 2^{30}(1\leq i\leq N)
* 1 \leq B_i \leq 10^9(1\leq i\leq N)
* All input values are integers.
Inputs
Input is given from Standard Input in the following format:
N K
A_1 B_1
:
A_N B_N
Outputs
Print the maximum possible sum of utilities of purchased integers.
Examples
Input
3 5
3 3
4 4
2 5
Output
8
Input
3 6
3 3
4 4
2 5
Output
9
Input
7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
Output
32
Submitted Solution:
```
n,k=list(map(int,input().split(' ')))
a=[0 for i in range(n)]
b=[0 for i in range(n)]
m=0
for i in range(n):
a[i],b[i]=list(map(int,input().split(' ')))
i=0
j=0
while i <len(a):
j=i+1
while j<len(a):
if a[i]+a[j]<=k and m<b[i]+b[j] :
m=b[i]+b[j]
j+=1
i+=1
print(m)
```
No
| 106,894 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities.
Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.
Find the maximum possible sum of utilities of purchased integers.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq K < 2^{30}
* 0 \leq A_i < 2^{30}(1\leq i\leq N)
* 1 \leq B_i \leq 10^9(1\leq i\leq N)
* All input values are integers.
Inputs
Input is given from Standard Input in the following format:
N K
A_1 B_1
:
A_N B_N
Outputs
Print the maximum possible sum of utilities of purchased integers.
Examples
Input
3 5
3 3
4 4
2 5
Output
8
Input
3 6
3 3
4 4
2 5
Output
9
Input
7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
Output
32
Submitted Solution:
```
from math import sqrt
from math import ceil
from itertools import permutations
from heapq import *
from collections import defaultdict
from copy import deepcopy
from math import log
N,K=map(int,input().split())
AB=[0]*N
dic=defaultdict(int)
n=int(ceil(log(K,2)))+1
for i in range(N):
a,b=map(int,input().split())
if a in dic.keys():
AB[dic[a]]=[a,AB[dic[a]][1]+b]
else:
dic[a]=i
AB[i]=[a,b]
n=max(n,int(ceil(log(a,2)))+1)
AB_=[]
for i in AB:
if i==0:
continue
k=bin(i[0])[2:].zfill(n)
AB_.append([k,i[1]])
AB=AB_
k=bin(K)[2:].zfill(n)
l=len(AB)
dp=[[0]*(n+1) for i in range(l)]
for i in range(l):
for j in range(n):
#print(i,j,dp[i][j]<<1,"j:",k[j],"k:",AB[i][0][j])
dp[i][j+1]=(dp[i][j]<<1)+int(k[j])|int(AB[i][0][j])
#print((dp[i][j]<<1)+int(k[j])|int(AB[i][0][j]))
ans=0
for i in range(n):
if k[i]=="1":
sum=0
for j in range(l):
if AB[j][0][i]=="0" and dp[j][i]<=int(k[:i],2):
sum+=AB[j][1]
ans=max(ans,sum)
sum=0
t=k
for j in range(l):
if int(t)|int(AB[j][0])<=int(t):
sum+=AB[j][1]
ans=max(ans,sum)
print(ans)
```
No
| 106,895 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities.
Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.
Find the maximum possible sum of utilities of purchased integers.
Constraints
* 1 \leq N \leq 10^5
* 0 \leq K < 2^{30}
* 0 \leq A_i < 2^{30}(1\leq i\leq N)
* 1 \leq B_i \leq 10^9(1\leq i\leq N)
* All input values are integers.
Inputs
Input is given from Standard Input in the following format:
N K
A_1 B_1
:
A_N B_N
Outputs
Print the maximum possible sum of utilities of purchased integers.
Examples
Input
3 5
3 3
4 4
2 5
Output
8
Input
3 6
3 3
4 4
2 5
Output
9
Input
7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
Output
32
Submitted Solution:
```
import copy
n,k = map(int, input().split())
data = []
bit_k = format(k, 'b')
len_k = len(bit_k)
for i in range(n):
a, b = map(int, input().split())
if a <= k:
data.append([a,b])
def check_value(bit):
res = 0
for i in range(len(data)):
tmp = format(data[i][0], 'b')
tmp = tmp.zfill(len_k)
flag = True
for j in range(len_k):
if bit[j] == '0' and tmp[j] == '1':
flag = False
break
if flag:
#print("tmp:{} bit{}".format(tmp, bit))
res += data[i][1]
return res
ans = 0
for i in range(len_k):
p = list(copy.deepcopy(bit_k))
if p[i] == '1':
p = p[:i] + ['0'] + ['1']*(len_k-1-i)
p = "".join(p)
else:
p = "".join(p)
ans = max(ans, check_value(p))
print(ans)
```
No
| 106,896 |
Provide a correct Python 3 solution for this coding contest problem.
There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i.
The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds.
Constraints
* All input values are integers.
* 1 \leq N \leq 10^5
* 1 \leq L \leq 10^9
* 1 \leq T \leq 10^9
* 0 \leq X_1 < X_2 < ... < X_N \leq L - 1
* 1 \leq W_i \leq 2
Input
The input is given from Standard Input in the following format:
N L T
X_1 W_1
X_2 W_2
:
X_N W_N
Output
Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive.
Examples
Input
3 8 3
0 1
3 2
6 1
Output
1
3
0
Input
4 20 9
7 2
9 1
12 1
18 1
Output
7
18
18
1
"Correct Solution:
```
import math
temp=input().split()
N=int(temp[0])
L=int(temp[1])
T=int(temp[2])
XW=[[int(j) for j in input().split()] for i in range(N)]
count=0
for i in range(N):
if XW[i][1]==1:
XW[i][0]+=T
else:
XW[i][0]-=T
count+=math.floor(XW[i][0]/L)
#
# if XW[0][1]==1:
# for i in range(1,N):
# if XW[i][0]<XW[0][0]:
# count+=int((XW[0][0]-XW[i][0])/L)+1
# else:
# for i in range(1,N):
# if XW[i][0]>XW[0][0]:
# count+=int((XW[i][0]-XW[0][0])/L)+1
#print(count)
#print(len())
newX=[]
for i in range(N):
newX.append(XW[i][0]%L)
newX.sort()
#print(newX)
for i in range(N):
print(newX[(i+count)%N]%L)
```
| 106,897 |
Provide a correct Python 3 solution for this coding contest problem.
There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i.
The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds.
Constraints
* All input values are integers.
* 1 \leq N \leq 10^5
* 1 \leq L \leq 10^9
* 1 \leq T \leq 10^9
* 0 \leq X_1 < X_2 < ... < X_N \leq L - 1
* 1 \leq W_i \leq 2
Input
The input is given from Standard Input in the following format:
N L T
X_1 W_1
X_2 W_2
:
X_N W_N
Output
Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive.
Examples
Input
3 8 3
0 1
3 2
6 1
Output
1
3
0
Input
4 20 9
7 2
9 1
12 1
18 1
Output
7
18
18
1
"Correct Solution:
```
import math
temp=input().split()
N=int(temp[0])
L=int(temp[1])
T=int(temp[2])
XW=[[int(j) for j in input().split()] for i in range(N)]
count=0
for i in range(N):
if XW[i][1]==1:
XW[i][0]+=T
else:
XW[i][0]-=T
count+=math.floor(XW[i][0]/L)
newX=[]
for i in range(N):
newX.append(XW[i][0]%L)
newX.sort()
#print(newX)
for i in range(N):
print(newX[(i+count)%N]%L)
```
| 106,898 |
Provide a correct Python 3 solution for this coding contest problem.
There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i.
The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction.
For each ant, find its position after T seconds.
Constraints
* All input values are integers.
* 1 \leq N \leq 10^5
* 1 \leq L \leq 10^9
* 1 \leq T \leq 10^9
* 0 \leq X_1 < X_2 < ... < X_N \leq L - 1
* 1 \leq W_i \leq 2
Input
The input is given from Standard Input in the following format:
N L T
X_1 W_1
X_2 W_2
:
X_N W_N
Output
Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive.
Examples
Input
3 8 3
0 1
3 2
6 1
Output
1
3
0
Input
4 20 9
7 2
9 1
12 1
18 1
Output
7
18
18
1
"Correct Solution:
```
# C
N, L, T = map(int, input().split())
X = list()
W = list()
positions = list()
for _ in range(N):
x, w = map(int, input().split())
X.append(x)
W.append(w)
if w == 1:
positions.append((x + T) % L)
else:
positions.append((x - T) % L)
# find which is the position
cnt_conf = 0
if W[0] == 1:
for i in range(N):
if W[i] != W[0]:
cnt_conf += (2*T - (X[i] - X[0])) // L + 1
n0 = cnt_conf % N
p0 = (X[0] + T) % L
else:
for i in range(N):
if W[i] != W[0]:
cnt_conf += (2*T - (X[0] + L - X[i])) // L + 1
n0 = -cnt_conf % N
p0 = (X[0] - T) % L
positions.sort()
# find index
if W[0] == 1:
num = max([n for n in range(N) if positions[n]==p0])
else:
num = min([n for n in range(N) if positions[n]==p0])
for i in range(N):
print(positions[(num - n0 + i) % N])
```
| 106,899 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.