peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N = int(input())
if N%2:
    print(0)
    exit()

ans = 0
i = 5
while i < N:
    ans += N//(2*i)
    i *= 5
print(ans)
# Judge status: Wrong Answer
N = int(input())
s = input()
t = input()
p = N
def dfs(i, j):
    if i == N or j == N:
        return p
    if s[i] == t[j]:
        return min(dfs(i, -~j) - 1, dfs(-~i, -~j) - 1)
    else:
        return min(dfs(i, -~j), dfs(-~i, -~j))

print(N + dfs(0, 0))
# Judge status: Accepted
x, y = map(int, input().split())
print(x * (x - 1) //2 + y*(y-1)//2)
# Judge status: Wrong Answer
N=int(input())
T,A=map(int,input().split())
H=list(map(int,input().split()))
m=100100100100
for i in range(N):
  if abs(A-H[i])<m:
    m=abs(A-H[i])
    ans=i
print(ans)
# Judge status: Accepted
import itertools
import math 
def C(n,r):
    if n-r < 0:
        return 0 
    return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
    d[i] = d.get(i, 0)+1

c = 0
cc = {}
for key, val in d.items():
    temp = C(val,2)
    c += temp
    if cc.get(key) is None:
        cc[key] = temp - C(val-1,2)
for i in a:
    print(c - cc[i])
# Judge status: Wrong Answer
import numpy as np
a,b = map(int,input().split())
def cf(x1,x2):
    cf = []
    for i in range(1,int(np.sqrt(max(x1,x2))+1)):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

def prime(num):
  for p in range(2, int(np.sqrt(num)+1)):
    if num % p == 0:
      return False
  return True

lis = cf(a,b)
for k,l in enumerate(lis):
  if prime(l) == False:
    lis[k] = -1
s = set(lis) - set([-1])
print(len(s))
# Judge status: Accepted
X = int(input())
sho = X//500
glad = 0

glad = 1000 * sho
X -= sho*500

sho = X//5
glad += 5*sho

print(glad)
# Judge status: Wrong Answer
from functools import reduce
from fractions import gcd
N = int(input())
T = []
for i in range(N):
    T.append(int(input()))
x = reduce(gcd,T)
sum=1
for i in T:
    sum*=(x*i)
print(sum)
# Judge status: Accepted
A = input()
arr1 = [i for i in A.split(' ')]
if(arr1[0]==arr1[1]==arr1[2]):
	print('No')
elif((arr1[0]!=arr1[1]) and (arr1[0]!=arr1[2]) and (arr1[1]!=arr1[2])):
	print('No')
else:
	print('Yes')
# Judge status: Wrong Answer
import sys
#DEBUG = True
DEBUG = False
if DEBUG:
    f=open("202007_1st/A_input.txt")
else:
    f=sys.stdin
N=int(f.readline().strip())
A=N%1000
print(A)
f.close()
# Judge status: Accepted
from math import pi
print(2*pi*int(input()))
# Judge status: Accepted
a,b,c = map(int, input().split())

if a == b and b == c:
    print('No')
elif a != b and b != c and a != c:
    print('No')
else:
    print('Yes')
# Judge status: Wrong Answer
import bisect
import itertools

N = int(input())
up = sorted(list(map(int, input().split())))
middle = sorted(list(map(int, input().split())))
bottom = sorted(list(map(int, input().split())))
up_arr = []
middle_arr =[]

for list in middle:
    middle_arr.append(N-bisect.bisect_right(bottom,list))

for list in up:
    up_arr.append(N-bisect.bisect_right(middle,list))

rui_middle = []
count = 0
for i in middle_arr[::-1]:
    count += i
    rui_middle.append(count)

ans =0
for i in up_arr:
    ans += rui_middle[i-1]

print(ans)
# Judge status: Accepted
from math import ceil
n=int(input())
val=ceil(n/1000)
print(1000*val-n)
# Judge status: Wrong Answer
import math

A,B,N = map(int, input().split())
k=1000000

max=0
x_max=-1


for x in range(B-k,B+k):
	if x>=0 and x<=N:
		tmp = math.floor(A*x/B)-A*math.floor(x/B)
		if max<=tmp:
			max=tmp
			x_max=x


for x in range(N-k,N+1):
	if x>=0:
		tmp = math.floor(A*x/B)-A*math.floor(x/B)
		if max<=tmp:
			max=tmp
			x_max=x
	
print(max)
# Judge status: Accepted
n = int(input())
l = []
l.append(1)
for i in range(2,40):
  b = i**2
  while b <= 1000:
    l.append(b)
    b*= i
l.sort()

for i in range(len(l)):
  if n < l[i]:
    print(l[i-1])
    exit()
print(1000)
# Judge status: Wrong Answer
a=int(input())
f=3
b=[]
if f<=a-1:
    b.append(1)
for i in range(a):
    if f>=a-1:
        break
    if a-f<3:
        continue
    else:
        b.append(f)
        f+=1
print(len(b)%((10**9)+7))
# Judge status: Accepted
A, B = map(int, input().split())
import math
N = math.ceil((B-1)/(A-1))
print(N)
# Judge status: Wrong Answer

if __name__ == '__main__':
    N=int(input())
    ans=[]
    while N:
        ans.append(str(N%2))
        N=-(N//2)
    ans.reverse()
    print("".join(ans))
# Judge status: Accepted
N = int(input())
if N%1000==0:
  print(0)
else:
  print(1000-(N%1000))
# Judge status: Accepted
K, N = map(int, input().split())
A = list(map(int, input().split()))
distance = [A[i+1] - A[i] for i in range(N-1)]+[A[0]-(A[-1]-K)]
result = K - max(distance)
print(result)
# Judge status: Wrong Answer
#B - Guidebook (別解)
N = int(input())

iSP = []
for i in range(N):
    s,p = input().split()
    iSP.append([i+1,s,p])


ans = sorted(iSP, key = lambda x:x[2], reverse = True)

ans = sorted(ans, key = lambda x:x[1])

for j,k,l in ans:
    print(j)
# Judge status: Accepted
sx,sy,tx,ty = map(int, input().split())

ans = ""
# 1周目
ans += (ty-sy)*"U" + (tx-sx)*"R" + (ty-sy)*"D" + (tx-sx)*"L"
# 2周目
ans += "L" + (ty-sy+1)*"U" + (tx-sx+1)*"R" + "DR" + (ty-sy+1)*"D" + (tx-sx+1)*"L" + "U"
print(ans)
# Judge status: Accepted
import sys
input = lambda: sys.stdin.readline().rstrip()
 
q,h,s,d=map(int,input().split())
n=int(input())

a=min(d,s*2,h*4,q*8) #2L
b=min(s,h*2,q*4) #1L
ans=0
ans+=(n//2)*a
n-=2*(n//2)
ans+=n*b
print(ans)
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))

minus_cnt = 0
for i in range(n):
  if a[i] < 0:
    minus_cnt += 1
    a[i] *= -1
  
s = sum(a)
a.sort()
if(minus_cnt % 2 == 1):
  s -= a[0] * 2

print(s)
# Judge status: Accepted
n = int(input())
a = [0]
a += list(map(int,input().split()))
b = [0]*n
for i in range(n-1,0,-1):
    b[a[i]-1] += 1
for i in b:
    print(i)
# Judge status: Accepted
n = int(input())
a = [[int(m),i] for i, m in enumerate(input().split())]
a.sort(key=lambda x: x[0])
ans = [i[1]+1 for i in a]
print(*ans)
# Judge status: Accepted
n_str = input()
n_len = len(n_str)
sur = 0

for i in range(n_len):
    c = n_str[i]
    c_int = int(c)
    sur += c_int
    sur %= 9

if sur:
    print('No')
else:
    print('Yes')
# Judge status: Accepted
K,X=map(int,input().split())

if 500*K<X:
  print("No")
else:
  print("Yes")
# Judge status: Accepted
import math
x = int(input())
if x==1:
  print(1)
  exit()

used = {}
for b in range(2,int(math.sqrt(x))+1):
  p=2
  while(b**p<=x):
    used[b**p]=True
    p+=1

ans=0
for key in used.keys():
  ans = max(ans,key)

print(ans)
# Judge status: Accepted
import itertools
import math

n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]

root = {}
for i in range(n-1):
    ix, iy = xy[i][0], xy[i][1]
    for j in range(i+1, n):
        jx, jy = xy[j][0], xy[j][1]
        root[(i, j)] = ((ix-jx)**2+(iy-jy)**2)**(1/2)

long = 0
for i in itertools.permutations([i for i in range(n)]):
    for j in range(1, len(i)):
        long += root[tuple(sorted([i[j-1], i[j]]))]
print(long/math.factorial(n))
# Judge status: Wrong Answer
N = int(input())
dic = dict()
for i in range(N):
    S = input()
    if S in dic:
        dic[S] += 1
    else:
        dic[S] = 1
    Start  = S[0]
    if i != 0:
        if Start != End or dic[S] > 1:
            print("No")
            exit
    End = S[len(S)-1]
print("Yes")
# Judge status: Accepted
Q, H, S, D = map(int, input().split())
N = int(input())
Q *= 4
H *= 2
if(N == 1): print(min(Q, H, S))
elif(N == 2): print(min(Q * 2, H * 2, S * 2, D))
else:
    ans = 0
    if(N % 2):
        N = N - 1
        ans += min(N * Q, N * H, N * S, (N // 2) * D)
        ans += min(Q, H, S)
    else:
        ans += min(N * Q, N * H, N * S, (N // 2) * D)
    print(ans)
# Judge status: Wrong Answer
n = int(input())
s = [0] * n
for i in range(n):
    s[i] = input()
print('AC　x　' + str(s.count('AC')))
print('WA　x　' + str(s.count('WA')))
print('TLE　x　' + str(s.count('TLE')))
print('RE　x　' + str(s.count('RE')))
# Judge status: Accepted
from collections import Counter
S = input()
work = sorted(list(Counter(S).values()), reverse=True)
a = work[0]
b = work[1] if len(work)>1 else 0
c = work[2] if len(work)>2 else 0
result = "YES"
if (a > b + 1 or a > c + 1):
    result = "NO"
print(result)
# Judge status: Accepted
n,m = map(int,input().split())
h = list(map(int,input().split()))
ans = [1 for _ in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    if h[a-1] > h[b-1]:
        ans[b-1] = 0
    elif h[a-1] < h[b-1]:
        ans[a-1] = 0
    else:
       ans[a-1] = 0
       ans[b-1] = 0
cnt = 0
for i in range(n):
    if ans[i] == 0:
        cnt += 1
print(n-cnt)
# Judge status: Accepted
s = int(input())
if s == 10**18:
    x = 0
    y = s//(10**9)
else:
    x = 10**9-s%(10**9)
    y = s//(10**9) +1
print(0,0,10**9,1,x,y)
# Judge status: Accepted
# https://drken1215.hatenablog.com/entry/2020/05/16/005300

def main():
    from itertools import tee

    N, K = map(int, input().split())
    S = input()

    s1, s2 = tee(S, 2)
    next(s2)

    cnt = 0
    for c1, c2 in zip(s1, s2):
        if c1 != c2:
            cnt += 1

    ans = N - 1 - max(cnt - K * 2, 0)

    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
N,M=map(int,input().split())
tmax=(M-2*N)//4
print(tmax+N)
# Judge status: Accepted
import numpy as np
n,m=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
A=list(set(A))
AA=np.array(A)
cnt=0
 
from fractions import gcd
 
def lcm(a,b):
  return a*b//gcd(a,b)
 
while sum(AA%2)==0:
    cnt+=1
    AA//=2
if np.sum(AA%2)!=len(AA):
    ans=0
else:
  A=np.array(A)//2
  maxbai=A[-1]
  for i in range(len(A)):
    maxbai=lcm(A[-i-1],maxbai)
  x=m//maxbai
  ans=x//2+(x%2)
print(ans)
# Judge status: Accepted
N = int(input())
p = list(map(int, input().split()))

count = 0
i = 0
while i < N:
    if (i+1) == p[i]:
        count += 1
        i += 2
    else:
        i += 1
print(count)
# Judge status: Accepted
import sys

lines = sys.stdin.readlines()

s, t = lines[0].split()

print(t + s)
# Judge status: Accepted
x, a, b = map(int, input().split())
print('A' if abs(x-a) < abs(x-b) else 'B')
# Judge status: Accepted
W, a, b = map(int, input().split())

if a > b + W:
    print(a - (b + W))
elif b > a + W:
    print(b - (a + W))
else:
    print(0)
# Judge status: Wrong Answer
c1 = list(input())
c2 = list(input())

if c1[0] == c2[2] and c1[1] == c2[1] and c1[2] == c2[0]:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
A, B = map(int, input().split())

sum = 0

for n in range(A, B+1):
    rev = 0
    m = n
    while n != 0:
        dig = n % 10
        rev = rev*10+dig
        n = n//10
    if(m == rev):
        sum += 1
print(sum)
# Judge status: Accepted
def solve():
    X, Y = map(int, input().split())

    for n_cranes in range(X+1):
        n_turtles = X - n_cranes

        if n_cranes * 4 + n_turtles * 2 == Y:
            return 'Yes'

    return 'No'


def main():
    print(solve())


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
n = int(input())
cnts = [k*(n//k)*((n//k)+1)//2 for k in range(1,n//2)]
print(sum(cnts)+ ((n//2)+n)*(n-(n//2)+1)//2)
# Judge status: Accepted
N = int(input())
ans = 'No'
for i in range(30):
    for j in range(30):
        if 4*i + 7*j == N:
            ans = 'Yes'
print(ans)
# Judge status: Accepted
ls =[]
for i in range(5):
    ls.append(int(input()))
rm = 10
time = 0
for i in ls:
    if i % 10 == 0:
        time += i
    else:
        time += (i//10+1)*10
        rm = min(rm,i%10)
time += rm - 10
print(time)
# Judge status: Wrong Answer
s = input()
q = int(input())
status = 1
for i in range(q):
    query = [i for i in input().split()]
    if query[0] == "1":
        status *= -1
    else:
        if (query[1] == "1" and status == 1) or (query[1] == "2" and status == -1):
            s = query[2] + s
        else:
            s = s + query[2]

print(s if status else reversed(s))
# Judge status: Wrong Answer
A = {}

for _ in range(3):
  for n in input().split():
    A[n] = False
  
N = int(input())
B = []
for _ in range(N):
  B.append(input())

for b in B:
  A[b] = True


A = list(A.values())


def check_row(A):
  return any(all(A[i:i+2]) for i in [0, 3, 6])
  
def check_col(A):
  return any(all(v for v in A[i::3]) for i in [0, 1, 2])

def check_diagonal(A):
  a = A[0] and A[4] and A[8]
  b = A[2] and A[4] and A[6]
  return a or b

cond = check_row(A) or check_col(A) or check_diagonal(A)
print("Yes" if cond else "No")
# Judge status: Accepted
n = int(input())
a = [int(input()) for _ in range(n)] 

p = 0
cnt = 1
for _ in range(n):
    if a[p] == 2:
        print(cnt)
        exit()

    p = a[p] - 1 
    cnt += 1

print(-1)
# Judge status: Accepted
N = int(input())
nums = input().split()
nums = set(nums)
if len(nums) == N:
  print("YES")
else:
  print("NO")
# Judge status: Accepted
s = input()
l = s[:2]
r = s[2:]

if(int(l) >= 1 and int(l) <=12 and int(r) <= 12 and int(r) >= 1):
    print('AMBIGUOUS')
else :
    if(int(l) <= 12 and int(l) >= 1):
        print('MMYY')
    else:
        if(int(r) <= 12 and int(r) >= 1):
            print('YYMM')
        else:
            print('NA')
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

cnt1 = 0
cnt4 = 0
cnt2 = 0
for i in a:
    if i % 2 != 0:
        cnt1 += 1
    elif i % 4 == 0:
        cnt4 += 1
    elif i % 2 == 0:
        cnt2 += 1

if n % 2 == 0:
    if cnt1 <= cnt4:
        print("Yes")
    else:
        print("No")
else:
    if cnt1 - 1 <= cnt4:
        print("Yes")
    else:
        print("No")
# Judge status: Accepted
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    x,y=map(int, input().split())
    if x%y==0:
        print(-1)
    else:
        print(x)
resolve()
# Judge status: Accepted
n=int(input())
a=0
for i in range(1,n+1):
    a+=len(str(i))%2
print(a)
# Judge status: Accepted
import math

N, A, B = map(int, input().split())
if A > B: print(0)
elif N == 1:
    if A == B: print(1)
    else: print(0)
else: print((B-A)*(N-2)+1)
# Judge status: Accepted
import math

n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

x = min([a,b,c,d,e])

print(math.ceil(n/x)+4)
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
def find_min_fuka_idx(lst, e1, e2):
  left = 0
  right = len(lst)
  while right-left>1:
    mid = (left+right)//2
    e3 = lst[mid]
    if e1+e2 > e3 and e2+e3>e1 and e3+e1>e2:
      left = mid
    else:
      right = mid
  return right
c = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    c += find_min_fuka_idx(a[j+1:], i, j)
print(c)
# Judge status: Accepted
N = int(input())
p = list(map(int, input().split()))

sorted_p = sorted(p)

count = 0
for i in range(N):
    if p[i] != sorted_p[i]:
        count += 1

if count == 2 or count == 0:
    print('YES')
else:
    print('NO')
# Judge status: Wrong Answer
K,X = map(int,input().split())

[print(i,end=' ')for i in range(K-X+1,K+X)]
# Judge status: Accepted
r,g,b= map(int,input().split())

num=100*r+10*g+b
if num%4==0:
  print("YES")
else:
  print("NO")
# Judge status: Accepted
a,b,c,d,e,k = [int(input()) for i in range(6)]
print('Yay!' if e-a <=k else ':(')
# Judge status: Accepted
N, K, Q = map(int, input().split())
correct_count = [0 for _ in range(N)]

for _ in range(Q):
    ai = int(input())
    correct_count[ai - 1] += 1

for c in correct_count:
    if K - Q + c < 1:
        print("No")
    else:
        print("Yes")
# Judge status: Accepted
if __name__ == "__main__":
    s = input()

    print('2018'+s[4:])
# Judge status: Accepted
N, H = map(int, input().split())
a = [0] * N
b = [0] * N
for i in range(N):
    a[i], b[i] = map(int, input().split())
b.sort(reverse=True)
max_a = max(a)
count = 0
while H > 0:
    if count >= N or b[count] <= max_a:
        if H % max_a == 0:
            count += H // max_a
        else:
            count += (H // max_a)+1
        break
    H -= b[count]
    count += 1
print(count)
# Judge status: Accepted
import collections
N = int(input())
S = [input() for _ in range(N)]

c = collections.Counter(S)
print(len(c))
# Judge status: Wrong Answer
N= int(input())
A = list(map(int,input().split()))
B = []
C = []

for i in range(1,N+1):
    n = A.count(i)
    B.append(n*(n-1)//2)
    C.append((n-1)*(n-2)//2 if n >1 else 0)

B_sum = sum(B)
print(B)
print(C)

for i in range(N):
    a = A[i]-1
    print(B_sum-B[a]+C[a])
# Judge status: Accepted
N,X,T=map(int,input().split())
if N//X!=N/X:
    print((N//X+1)*T)
else:
    print((N//X)*T)
# Judge status: Wrong Answer
from sys import stdin

def main():
    n = stdin.readline()
    ans = 0
    count = 1

    for i in range(len(n)):
        if ans == n[i]:
            count += 1
        ans = n[i]
    
    if count >= 3:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()
# Judge status: Accepted
# -*- coding: utf-8 -*-
"""
Created on Wed May 13 16:16:15 2020

@author: shinba
"""
import sys

s = list(input())

if s[0] != "A":
    print("WA")
    sys.exit()
else:
    s = s[1:]

t = s[1:len(s)-1]

if t.count("C") != 1:
    print("WA")
    sys.exit()
else:
    t.remove("C")

t.append(s[-1])
t.insert(0,s[0])

if "".join(t) == "".join(t).lower():
    print("AC")
else:
    print("WA")
# Judge status: Accepted
A,B,C,D=map(int,input().split())
print(max(0,min(B,D)-max(A,C)))
# Judge status: Wrong Answer
li = list(input())
li.sort

if li[0] != 'a' or li[1] != 'b' or li[2] != 'c':
    print('Yes')
else:
    print('Yes')
# Judge status: Wrong Answer
A,B,C,X,Y=map(int,input().split())
ans=5000*(10**5)+1

for i in range(max(X,Y)+1):
  total=0
  total=2*C*i+A*max(X-i,0)+B*max(Y-i,0)
  if ans>=total:
    ans=total
print(ans)
# Judge status: Wrong Answer
import scipy.misc
N,P=map(int,input().split(' '))
A=list(map(int,input().split(' ')))
odd = 0
even = 0
for i in A:
    if i%2 !=0:
        odd += 1
    else:
        even += 1

ans = 0
if P ==1:
    for i in range(1,odd+1,2):
        ans += scipy.misc.comb(odd,i)
else:
    for i in range(0,odd+1,2):
        ans += scipy.misc.comb(odd,i)
ans = ans*(2**even)
print(ans)
# Judge status: Wrong Answer
#Weather Prediction 141
#一日ごとにSunny、Cloudy、Rainy
#Sは Sunny, Cloudy, Rainy のいずれかである

S = input('')
print()

if S =="Sunny":
    print('Cloudy')
elif S =="Cloudy":
    print('Rainy')
elif S =="Rainy":
    print('sunny')
# Judge status: Wrong Answer
n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

am = 0
bm = 0
for i in range(n):
    am += a[i]
    bm = max(bm, b[i])
    
if am <= bm:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
S = set(input())
if len(S)==26:
    print('None')
else:
    A = 'abcdefghijklmnopqrstuvwxyz'
    for i in range(26):
        if A[i] not in S:
            print(A[i])
            break
# Judge status: Wrong Answer
import math

a,b,h,m = map(float,input().split())
if 6*m>30*h+m*0.5:
  angle = 6*m - 30*h+m*0.5
else:
  angle = 30*h+m*0.5 - 6*m
  
if angle>180:
  angle = 360-angle
  
c = math.sqrt((a**2) + (b**2) - (2*a*b*math.cos(math.radians(angle))))
  
print(c)
# Judge status: Accepted
import sys

n,k=map(int,input().split())
d=list(map(int,input().split()))
count=0

for i in range(n,1000000000):
  for j in range(len(str(i))):
    if str(i)[j] in str(d):
      break
      
    else:
      count+=1
      
  if count==len(str(i)):
    print(i)
    sys.exit()
  count=0
# Judge status: Accepted
n = int(input())
arr = list(map(int, input().split()))
su = sum(arr)
lst = [0]*100001
q = int(input())
for i in arr:
    lst[i] += 1
for _ in range(q):
    b, c = map(int, input().split())
    su += (c - b) * lst[b]
    print(su)
    lst[c] += lst[b]
    lst[b] = 0
# Judge status: Accepted
n=int(input())

ans=[]
for i in range(n+1):
  if i%3==0 and i%5==0:
    ans.append(0)
  if i%3==0 or i%5==0:
    ans.append(0)
  else:
    ans.append(i)
print(sum(ans))
# Judge status: Accepted
n=int(input())
a=int(n/1.08)
z=lambda x:int(x*1.08)
if z(a)==n:
  print(a)
elif z(a+1)==n:
  print(a+1)
else:
  print(":(")
# Judge status: Wrong Answer
import sys
X, K, D = map(int, input().split())

num = X - K*D
if 0<num:
  print(num)
  sys.exit(0)

k2 = X//D
if (K-k2)%2==0:
  print(X - k2*D)
elif K<k2+1:
  print((k2-1)*D - X)
else:
  print((k2+1)*D - X)
# Judge status: Accepted
n,k,*a=map(int,open(0).read().split())
now=1
if k<=n:
  for i in range(k):
    now=a[now-1]
  print(now)
  exit()
# 絶対ループする
visited=[False]*n
visited[now-1]=-1
for i in range(4*10**5):
  now=a[now-1]
  if visited[now-1]==False:
    visited[now-1]=i
  else:
    c,d=visited[now-1],i
    break

k=(k-c)%(d-c)+c
while k<n:
  k+=(d-c)
now=1
for i in range(k):
  now=a[now-1]
print(now)
# Judge status: Accepted
N=int(input())
ans=0
for i in range(1,N+1):
    for j in range(i,N+1,i):
        ans+=j
print(ans)
# Judge status: Accepted
D = input()
D = int(D)
X = int(25 - D)
Y = "Christmas" + " Eve"*X
print(Y)
# Judge status: Wrong Answer
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

for _ in range(M):
    b,c = [int(x) for x in input().split()]
    A.extend([c] * b)
    if len(A) >= 2*N:
        break


A.sort(reverse=True)

ans = sum(A[:N])
print(ans)
# Judge status: Wrong Answer
K, A, B = map(int, input().split())
if B - A <= 2 :
  print(K + 1)
elif K < A + 1:
  print(K + 1)
elif K == A + 1:
  print(B)
else:
  count = K - (A + 1)
  if count % 2 == 1:
    ans = count // 2 * (B - A) + B
  else:
    ans = count//2 * (B - A) + B + 1
  print(ans)
# Judge status: Accepted
X = int(input())

# import math
# print(math.log10(X)/math.log10(2))
a = 100
for i in range(1000000):
    a = int(a * 1.01)
    if a >= X:
        print(i+1)
        exit()
# Judge status: Accepted
S = input()

from collections import defaultdict
mod = 2019
N = len(S)
D = defaultdict(int)
S = S[::-1]
ans = 0
T = 0
D[0]+=1
for i in range(N):
    s = int(S[i])*pow(10,i,mod)
    T = (T+s)%mod
    ans += D[T]
    D[T]+=1
print(ans)
# Judge status: Wrong Answer
n = int(input())
s = list(input())
white = 0
black = 0
rightmost = -1
temp = 0
for i in range(n):
    if s[i] == '#':
        black+=1
    else:
        white+=1
        rightmost = i
        temp = black
print(min(n-white, n-black, temp))
# Judge status: Accepted
S=list(map(int,input().split('/')))
if S[1] < 5: print('Heisei')
else: print('TBD')
# Judge status: Accepted
k,x = map(int,input().split())
if 500 * k < x:
    print('No')
else:
    print('Yes')
# Judge status: Wrong Answer
import fractions as fr
import numpy as np
def main():
    N=int(input())
    A=np.array([int(i) for i in input().split()])
    MOD=1000000007
    lcm = 1
    gcd=fr.gcd
    for i in range(N):
        lcm = A[i] * lcm //fr.gcd(A[i], lcm)

    sumval = np.sum(lcm/A)

    print(sumval%MOD)


main()
# Judge status: Wrong Answer
N, K = map(int, input().split())
S = input()

happy = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        happy += 1

m = 0
for i in range(N-1):
    if S[i] == 'R' and S[i+1] == 'L':
        m += 1

if K <= m:
    happy += 2*K
else:
    if m > 1:
        happy += 2*m
    elif S[0] != S[N-1]:
        happy += 1
print(happy)
# Judge status: Accepted
def solve():
    A = list(map(int, input().split()))
    a,b,c,d = A
    s = a * b / 2
    b = 1 if a == c*2 and b == d*2 else 0
    ans = [s, b]
    print(*ans)
solve()
# Judge status: Wrong Answer
n = int(input())

i = 1
while i * i <= n:
  i += 1

print(i - 1)
# Judge status: Accepted

N = int(input())
K = int(input())
X = int(input())
Y = int(input())

if N > K:
    print(X*K+(N-K)*Y)
else:
    print(X*N)
# Judge status: Wrong Answer
def main():
    x = int(input())

    t = 0
    now = 0
    for i in range(1, x):
        if x - now == i:
            t = i
            break
        if x - now == (i + 1):
            t = i + 1
            break
        else:
            now += i

    print(t)


if __name__ == '__main__':
    main()
# Judge status: Accepted
from itertools import accumulate

n,k=map(int,input().split())
p=list(map(int,input().split()))

exp={}
cum=[]

ans=0
cnt=0
for i in range(1,1001):
    sum=0
    for j in range(1,i+1):
        sum+=j
    exp[i]=sum/i

for i in p:
    cum.append(exp[i])

cumsum=list(accumulate(cum))
cumsum.insert(0,0)

for i in range(n-k+1):
    tmp = cumsum[i+k] - cumsum[i]
    if ans <= tmp:
        ans = tmp

print(ans)