Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

a,b,c,d = map(int,input().split())
count = 0
for _ in range(a, b+1):
    if _%c != 0 and _%d != 0:
        count += 1

print(count)

### FIXED CODE ###

def lcm(a,b):
    ab = a*b
    while b != 0:
        a, b = b, a%b
    return ab //a

def su(n,c,d):
    return n - n//c - n//d + n//lcm(c,d)
    
def main():
    a,b,c,d = map(int,input().split())
    print(su(b,c,d) - su(a-1,c,d))
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

from collections import deque

n = int(input())

q = deque()
for i in range(n):
    cmd = input().strip().split()
    if cmd[0] == 'insert':
        q.appendleft(cmd[1])
        continue
    if cmd[0] == 'delete':
        try:
            q.remove(cmd[1])
        except:
            pass
        continue
    if cmd[0] == 'deleteFirst':
        q.popleft()
        continue
    if cmd[0] == 'deleteLast':
        q.pop()
        continue

print(' '.join(q))

### FIXED CODE ###

import sys
from collections import deque

n = int(sys.stdin.readline())
q = deque()
for i in range(n):
    cmd = sys.stdin.readline()[:-1]
    if cmd[0] == 'i':
        q.appendleft(cmd[7:])
    elif cmd[6] == ' ':
        try:
            q.remove(cmd[7:])
        except:
            pass
    elif cmd[6] == 'F':
        q.popleft()
    else:
        q.pop()

print(' '.join(q))
### BUGGY CODE ###

n,s = map(int,input().split())
a = list(map(int,input().split()))
dp = [[[0]*2 for _ in range(s)] for _ in range(n)]
mod = 998244353
if a[0] <= s:
    dp[0][a[0]-1][0] = 1
    dp[0][a[0]-1][1] = 1

for i in range(1,n):
    for j in range(s):
        if a[i] < j+1:
            dp[i][j][0] = dp[i-1][j-a[i]][0] + dp[i-1][j][0] 
            dp[i][j][1] = dp[i-1][j-a[i]][0] + dp[i-1][j][0] + dp[i-1][j][1]
        elif a[i] == j+1:
            dp[i][j][0] = dp[i-1][j][0] + i + 1
            dp[i][j][1] = dp[i-1][j][0] + dp[i-1][j][1] + i + 1
        else:
            dp[i][j][0] = dp[i-1][j][0]
            dp[i][j][1] = dp[i-1][j][0] + dp[i-1][j][1]
        dp[i][j][0] %= mod   
        dp[i][j][1] %= mod
        
print(dp[n-1][s-1][1])

### FIXED CODE ###

n,s = map(int,input().split())
a = list(map(int,input().split()))
c = [0]*(s+1)
ans = 0
mod = 998244353
for i in range(n):
    c_=c.copy()
    if a[i] <= s:
        for j in range(a[i],s+1):
            c[j] += c_[j-a[i]]
        c[a[i]] += i+1
    ans += c[s]
    ans %= mod

print(ans)
### BUGGY CODE ###

N = int(input())
L = sorted(list(map(int,input().split())))
lenl = len(L)
count = 0
for i in range(0,lenl-2):
    for j in range(i+1,lenl-1):
        for k in range(j+1,lenl):
            if L[i]+L[j] <= L[k]:
                break
            count += 1
print(count)

### FIXED CODE ###

import bisect
N = int(input())
L = sorted(list(map(int,input().split())))
lenl = len(L)
count = 0
for i in range(0,lenl-2):
    for j in range(i+1,lenl-1):
        count += bisect.bisect_left(L,L[i]+L[j])-j-1
print(count)
### BUGGY CODE ###

from collections import deque
 
def bfs():
  d = [0]*n
  que = deque([])
  que.append(0)
  d[0] = 1 #到達済み
  for i in range(10**10):
    if que == []:
      break
    now = que.popleft() 
    if d == [1]*n: #全て到達したら終わり
      break
    for next in g[now]: #部屋1から行ける場所で回す
      if d[next] == 0:
        que.append(next)
        d[next] = 1
        direction[next] = now 
        
n,m = map(int,input().split())
g = [[] for i in range(n)]
direction = [0]*n
for i in range(m):
  a,b = map(int,input().split())
  g[a-1].append(b-1)
  g[b-1].append(a-1)
  
bfs()
print('Yes')
for i in range(1,n):
  print(direction[i]+1)

### FIXED CODE ###

from collections import deque
 
def bfs():
  que = deque([])
  que.append(0)
  
  while que:
    now = que.popleft()
    for next in g[now]: #部屋1から行ける場所で回す
      if d[next] == 0:
        que.append(next)
        d[next] = now +1
        
n,m = map(int,input().split())
g = [[] for i in range(n)]
d = [0]*n
for i in range(m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  g[a].append(b)
  g[b].append(a)
  
bfs()
print('Yes')
for i in range(1,n):
  print(d[i])
### BUGGY CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from numpy.fft import fft, ifft
from fractions import gcd
import numpy as np

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W = MAP()
S = [input() for _ in range(H)]

L = [[0]*W for _ in range(H)]
R = [[0]*W for _ in range(H)]
D = [[0]*W for _ in range(H)]
U = [[0]*W for _ in range(H)]


for i in range(H):
	for j in range(W):
		if S[i][j] == '#':
			L[i][j] = 0
		elif j == 0:
			L[i][j] = 1
		else:
			L[i][j] = L[i][j-1] + 1

for i in range(H):
	for j in range(W-1, -1, -1):
		if S[i][j] == '#':
			R[i][j] = 0
		elif j == W-1:
			R[i][j] = 1
		else:
			R[i][j] = R[i][j+1] + 1

for i in range(H):
	for j in range(W):
		if S[i][j] == '#':
			U[i][j] = 0
		elif i == 0:
			U[i][j] = 1
		else:
			U[i][j] = U[i-1][j] + 1

for i in range(H-1, -1, -1):
	for j in range(W):
		if S[i][j] == '#':
			D[i][j] = 0
		elif i == H-1:
			D[i][j] = 1
		else:
			D[i][j] = D[i+1][j] + 1

L = np.array(L)
R = np.array(R)
U = np.array(U)
D = np.array(D)

print((L+R+U+D).max()-3)


### FIXED CODE ###

import sys
# from collections import deque, defaultdict, Counter
# from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
# from itertools import permutations, combinations, product
# from operator import itemgetter, mul
# from copy import deepcopy
# from string import ascii_lowercase, ascii_uppercase, digits
# from numpy.fft import fft, ifft
# from fractions import gcd
# import numpy as np

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W = MAP()
S = [input() for _ in range(H)]

L = [[0]*W for _ in range(H)]
R = [[0]*W for _ in range(H)]
D = [[0]*W for _ in range(H)]
U = [[0]*W for _ in range(H)]

for i in range(H):
	for j in range(W):
		if S[i][j] == '#':
			L[i][j] = 0
		elif j == 0:
			L[i][j] = 1
		else:
			L[i][j] = L[i][j-1] + 1

for i in range(H):
	for j in range(W-1, -1, -1):
		if S[i][j] == '#':
			R[i][j] = 0
		elif j == W-1:
			R[i][j] = 1
		else:
			R[i][j] = R[i][j+1] + 1

for i in range(H):
	for j in range(W):
		if S[i][j] == '#':
			U[i][j] = 0
		elif i == 0:
			U[i][j] = 1
		else:
			U[i][j] = U[i-1][j] + 1

for i in range(H-1, -1, -1):
	for j in range(W):
		if S[i][j] == '#':
			D[i][j] = 0
		elif i == H-1:
			D[i][j] = 1
		else:
			D[i][j] = D[i+1][j] + 1

# L = np.array(L)
# R = np.array(R)
# U = np.array(U)
# D = np.array(D)

ans = 0
for i in range(H):
	for j in range(W):
		ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

print(ans)
# print((L+R+U+D).max()-3)
### BUGGY CODE ###

#%%
K = int(input())

def func_gcd(a, b):
    if b > a:
        a, b = b, a
    
    while b > 0:
        r = a % b
        a = b
        b = r

    return a

ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        temp = func_gcd(i, j)
        for l in range(1, K + 1):
            temp2= func_gcd(temp, l)
            ans += temp2

print(ans)

### FIXED CODE ###

from math import gcd
 
k=int(input())
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for m in range(1,k+1):
            ans += gcd(i, gcd(j,m))
print(ans)
### BUGGY CODE ###


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

import sys
sys.setrecursionlimit(10**7)

h,w=map(int,input().split())
s=[input() for _ in range(h)]

u=UnionFind(h*w)

for i in range(h):
    for j in range(w):
        if j !=0:
            if s[i][j-1] != s[i][j]:
                u.union(i*w+j-1,i*w+j)
        if i !=0:
            if s[i-1][j] != s[i][j]:
                u.union((i-1)*w+j,i*w+j)
res = 0
for i in range(h*w):
    for j in range(i,h*w):
        if s[i//w][i%w] != s[j//w][j%w]:
            if u.same(i,j):
                res += 1
print(res)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

h,w=map(int,input().split())
s=[input() for _ in range(h)]
flag = [[0]*w for _ in range(h)]

def dfs(th,tw):
    global flag,h,w,s
    flag[th][tw] = True
    tblack = 0
    twhite = 0
    if s[th][tw] == "#":
        tblack += 1
    else:
        twhite += 1 
    for x,y in ([0,1],[0,-1],[1,0],[-1,0]):
        nth = th + x
        ntw = tw + y
        if nth >= 0 and nth < h and ntw >= 0 and ntw < w:
            if not flag[nth][ntw] and s[th][tw] != s[nth][ntw]:
                ttb,ttw = dfs(nth,ntw)
                tblack += ttb
                twhite += ttw
    return [tblack,twhite]
                
def main():
    global flag,h,w,s
    res = 0
    for i in range(h):
        for j in range(w):
            if not flag[i][j]:
                black,white = dfs(i,j)
                res += black * white 

    return res
print(main())
### BUGGY CODE ###

import sys
import numpy as np
input = sys.stdin.readline

N, Q = map(int, input().split())
children = [[i] for i in range(N)]  # 各頂点の持つ部分木の頂点の集合
edges = [tuple(map(int, input().split())) for _ in range(N-1)]
counts = np.zeros(N, dtype=np.int32)

for i in range(N-2, -1, -1):
    children[edges[i][0]-1] += children[edges[i][1]-1]

for _ in range(Q):
    p, x = map(int, input().split())
    counts[children[p-1]] += x

for count in counts:
    print(count, end=' ')

### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline

def main():
    N, Q = map(int, input().split())
    # edges = [None]*N
    edges = [[] for _ in range(N)]
    # edges[0] = 0
    # edges[0].append = 0
    for _ in range(N-1):
        a, b = map(int, input().split())
        edges[b-1].append(a-1)
        edges[a-1].append(b-1)

    counts = [0]*N
    for _ in range(Q):
        p, x = map(int, input().split())
        counts[p-1] += x

    parent_nodes = deque()
    parent_nodes.append(0)
    visited_nodes = set()
    while parent_nodes:
        parent = parent_nodes.popleft()
        if parent in visited_nodes:
            continue
        visited_nodes.add(parent)
        for child in edges[parent]:
            if child in visited_nodes:
                continue
            counts[child] += counts[parent]
            parent_nodes.append(child)

    print(' '.join(list(map(str, counts))))

if __name__ == "__main__":
    main()
### BUGGY CODE ###

from collections import defaultdict
S = input()
T = input()

S_indices_dict = defaultdict(set)
T_indices_dict = defaultdict(set)

for i, char in enumerate(S):
    S_indices_dict[char].add(i)
for i, char in enumerate(T):
    T_indices_dict[char].add(i)

indices_set = set(range(len(S)))
for char in S:
    indices = S_indices_dict[char]
    char_set = set()
    for i in indices:
        char_set.add(T[i])
        if len(char_set) != 1:
            print("No")
            exit(0)
for char in T:
    indices = T_indices_dict[char]
    char_set = set()
    for i in indices:
        char_set.add(S[i])
    if len(char_set) != 1:
        print("No")
        exit(0)
print("Yes")


### FIXED CODE ###

import sys
fin = sys.stdin.readline


S = fin()[:-1]
T = fin()[:-1]

correspondence = dict()
for char_s, char_t in zip(S, T):
    if char_s not in correspondence:
        correspondence[char_s] = char_t
    else:
        if char_t != correspondence[char_s]:
            print("No")
            exit(0)
if len(set(correspondence.values())) < len(correspondence):
    print("No")
else:
    print("Yes")
### BUGGY CODE ###

n, k = map(int, input().split())
a = [min(i, k) for i in sorted(list(map(int, input().split())))]
#print(a)
fr = 0
ba = n+1
while ba-fr > 1:
    mi = (ba+fr+1) // 2
    #print(mi)
    dp = [False for _ in range(k+1)]
    dp[0] = True
    for i in range(n):
        if i == mi-1:
            continue
        for j in range(k, -1, -1):
            if j >= a[i]:
                dp[j] = dp[j] | dp[j-a[i]]

    #print(dp)
    needed = False
    for j in range(max(0, k - a[mi-1]), k):
        if dp[j] == True:
            needed = True
            break

    if needed:
        ba = mi
    else:
        fr = mi

print(fr)

### FIXED CODE ###

import sys

n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
#print(a)
fr = 0
ba = n+1

def check(mi):
    x = a[mi-1]
    if x >= k:
        return True
    #print(mi)
    dp = [False] * (k+1)
    dp[0] = True
    for i in range(n):
        if i == mi-1:
            continue
        y = a[i]
        for j in range(k, -1, -1):
            if j >= y:
                dp[j] = dp[j] | dp[j-y]

    if sum(dp[k-x:k]):
        return True
    else:
        return False

if check(1):
    print(0)
    sys.exit()

if not check(n):
    print(n)
    sys.exit()

while ba-fr > 1:
    mi = (ba+fr+1) // 2
    if check(mi):
        ba = mi
    else:
        fr = mi

print(fr)
### BUGGY CODE ###

from itertools import combinations

n = int(input())
value = list(map(int, input().split()))
cost = list(map(int, input().split()))

idx = range(n)
result = [0, sum(value)-sum(cost)]
comb = [com for i in range(1, n) for com in combinations(idx, i)]

for com in comb:
  tmp = 0
  for c in com:
    tmp += value[c]-cost[c]
  result.append(tmp)
    
print(max(result))

### FIXED CODE ###

n = int(input())
value = list(map(int, input().split()))
cost = list(map(int, input().split()))
result = 0
for v, c in zip(value, cost):
  if v > c:
    result += v-c
print(result)
### BUGGY CODE ###

import numpy as np

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


def match2int(x, y):
    x, y = min(x, y), max(x, y)
    return (2 * n - 1 - x) * x // 2 + y - x - 1


match_sm = n * (n - 1) // 2

adj = [np.empty(0, dtype=np.int32) for _ in range(match_sm)]
in_deg = np.zeros(match_sm, dtype=np.int16)
for i, li in enumerate(a):
    for j, k in zip(li, li[1:]):
        j -= 1
        k -= 1
        match1 = match2int(i, j)
        match2 = match2int(i, k)
        adj[match1] = np.append(adj[match1], match2)
        in_deg[match2] += 1

cnd = np.array([i for i, e in enumerate(in_deg) if e == 0], dtype=np.int32)
day = 0
while cnd.size:
    in_deg[cnd] -= 1
    for u in cnd:
        in_deg[adj[u]] -= 1

    cnd = np.where(in_deg == 0)[0]
    day += 1

if np.any(in_deg >= 1):
    day = -1

print(day)


### FIXED CODE ###

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


def match2int(x, y):
    x, y = min(x, y), max(x, y)
    return (2 * n - 1 - x) * x // 2 + y - x - 1


match_sm = n * (n - 1) // 2

adj = [[] for _ in range(match_sm)]
in_deg = [0] * match_sm
for i, li in enumerate(a):
    for j, k in zip(li, li[1:]):
        j -= 1
        k -= 1
        match1 = match2int(i, j)
        match2 = match2int(i, k)
        adj[match1].append(match2)
        in_deg[match2] += 1

cnd = [i for i, e in enumerate(in_deg) if e == 0]
day = 0
while cnd:
    nxt_cnd = []
    for u in cnd:
        for v in adj[u]:
            in_deg[v] -= 1
            if in_deg[v] == 0:
                nxt_cnd.append(v)

    cnd = nxt_cnd
    day += 1

if in_deg.count(0) != match_sm:
    day = -1

print(day)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))

def gcd(x,y):#ユークリッドの互除法
  if y > x:
    x, y = y, x
  while y != 0:
    x, y = y, x % y
    if y == 0:
      return x
    
def lcm(x,y):
  return x * y / gcd(x,y)

m = 1
for i in range(N):
  m = lcm(m, A[i])
  
count = 0
for i in range(N):
  count += (m - 1) % A[i]
  
print(int(count))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))

count = 0
for i in range(N):
  count += A[i] - 1
  
print(count)
### BUGGY CODE ###

import math
 
def combination(n, k):
    return math.factorial(n) // math.factorial(k) // math.factorial(n - k)

n, k = map(int, input().split())
a = list(map(int,input().split()))
mod = 10 ** 9 + 7

ans = 0

a.sort()

for i in range(n-k+1):
    ans -= a[i] * combination(n-i-1, k-1) % mod
    ans %= mod

a.sort(reverse=True)

for i in range(n-k+1):
    ans += a[i] * combination(n-i-1, k-1) % mod
    ans %= mod

print(ans%mod)


### FIXED CODE ###

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

A = list(map(int,input().split()))
 
MAX = 10 ** 5 + 1
MOD = 10 ** 9 + 7
 
fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1
for i in range(2, MAX + 1):
    fac[i] = fac[i - 1] * i % MOD
    
finv = [0] * (MAX + 1)
finv[MAX] = pow(fac[MAX], MOD - 2, MOD)
  
for i in range(MAX, 0, -1):
    finv[i - 1] = finv[i] * i % MOD
 
def comb(n, k):
    if n < k or k < 0:
        return 0
    return (fac[n] * finv[k] * finv[n - k]) % MOD

A.sort()
ans = 0
for i in range(N):
    if i >= K - 1:
        ans += comb(i, K - 1) * A[i]
    if i + K - 1 < N:
        ans -= comb(N - i - 1, K - 1) * A[i]
    ans %= MOD
print(ans)
### BUGGY CODE ###

N = int(input())
L = list(map(int, input().split()))

L.sort()

count = 0
for i in range(0, N - 2):
    for p in range(i + 1, N - 1):
        left = p + 1
        right = N - 1
        tmp = (left + right) // 2
        while 'true':
            if L[i] + L[p] > L[tmp]:
                left = tmp
                tmp = (left + right) // 2
            else:
                right = tmp
                tmp = (left + right) // 2
            if abs(right - left) <= 1:
                if L[i] + L[p] > L[right]:
                    count += (right - p)
                    break
                elif L[i] + L[p] > L[left]:
                    count += (left - p)
                    break
                else:
                    break
print(count)

### FIXED CODE ###

import bisect

N = int(input())
L = list(map(int, input().split()))

L.sort()

count = 0
for i in range(0, N - 2):
    for p in range(i + 1, N - 1):
        count += bisect.bisect_left(L, L[i] + L[p]) - p - 1
print(count)
### BUGGY CODE ###

import sys,fractions
sys.setrecursionlimit(10**5)
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
l = list(map(int, input().split()))

u = 10**9+7

from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

G = l[0]
for i in range(N-1,0,-1):
    G = fractions.gcd(G,l[i])
    if G==1:
        break
gcd = G
L = [l[i]//gcd for i in range(N)]
lcm = lcm_list(L)

# print(lcm,gcd,'aaa')
ANS = 0
for i in range(N):
    elm = L[i]
    ANS += (lcm//elm)
    ANS %= u
print(ANS)

### FIXED CODE ###

import sys
from fractions import gcd
sys.setrecursionlimit(10**5)
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
l = list(map(int, input().split()))

u = 10**9+7

lcm = 1
s = 0
for i in range(N):
    k = l[i]
    g = gcd(k,lcm)
    t = k//g
    lcm = lcm*t
    s = s*t + lcm//k
print(s%u)
### BUGGY CODE ###

n, a, b, c, d = map(int, input().split())
s = list(input())
for i in range(b, d - 1):
    if s[i] == '#' and s[i + 1] == '#':
        print('No')
        exit(0)
    for i in range(a, c - 1):
        if s[i] == '#' and s[i + 1] == '#':
            print('No')
            exit(0)
if (a < b and c < d) or (b < a and d < c):
    print('Yes')
else:
    if a < b:
        l, r = a - 1, a
    else:
        l, r = b - 1, b
    while l >= 0 and (s[l] != '#' or s[l + 1] != '#'):
        l -= 1
    l += 2 - int(l == -1)
    while r < n and (s[r - 1] != '#' or s[r] != '#'):
        r += 1
    r -= 2 - int(r == n)
    for i in range(l, r - 1):
        if s[i] == '.' and s[i + 1] == '.' and s[i + 2] == '.':
            print('Yes')
            break
    else:
        print('No')


### FIXED CODE ###

n, a, b, c, d = map(int, input().split())
s = input()
if '##' in s[a-1:c] or '##' in s[b-1:d]:
    print('No')
elif c < d:
    print('Yes')
else:
    if '...' in s[b-2:d+1]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

x,k,d=map(int,input().split())

x=abs(x)

m=[]

for i in range(1,k+1):
    a=x-(d*i)
    m.append(abs(a))

print(min(m))

### FIXED CODE ###

import sys
x,k,d=map(int,input().split())

x=abs(x)

a=x//d

if a>=k:
    ans=x-k*d

elif (k-a)%2==0:
    ans=x-d*a

else:
    ans=x-d*a-d

print(abs(ans))
### BUGGY CODE ###

n = int(input())
nums = [input() for i in range(n)]
m = max(nums)

for i in range(n):
  num = nums[i]
  if nums.count(m) >= 2 or num != m:
    print(m)
  else:
    print(sorted(nums)[-2])

### FIXED CODE ###

n = int(input())
nums = [int(input()) for i in range(n)]
m = max(nums)
m2 = sorted(nums)[-2]
[print(m) if nums[i] != m else print(m2) for i in range(n)]
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**8)

N,W=map(int,input().split())
wv=[list(map(int,input().split())) for i in range(N)]

dp=[[-1]*(W+1) for i in range(N+1)]

def calc(n,w):
    if n<0:
        return 0
    if dp[n][w]>=0:
        return dp[n][w]
    cw,cv=wv[n]
    r1,r2=0,0
    r1=calc(n-1,w)
    if (cw+w)<=W:
        r2=calc(n-1,cw+w)+cv

    dp[n][w]= max([r1,r2])
    return dp[n][w]

print(calc(N-1,0))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)

N,W=map(int,input().split())
wv=[list(map(int,input().split())) for i in range(N)]

dp=[[0]*(W+1) for i in range(N+1)]

for i in range(N):
    for j in range(0,W+1):
        if (j-wv[i][0])>=0:
            dp[i+1][j] = max([dp[i][j],dp[i][j-wv[i][0]] + wv[i][1]])
        else:
            dp[i+1][j] = dp[i][j]

print(dp[N][W])
### BUGGY CODE ###

from functools import lru_cache
import sys 
sys.setrecursionlimit(2147483647)

N = int(input())
A = []
for i in range(0,N):
    A.append(list(map(int,input().split())))


@lru_cache(None)
def dfs(d,pre):
    if d>=N-1: return 0
    ma = 0 
    for idx,a in enumerate(A[d]):
        if idx != pre:
            res = dfs(d + 1,idx) + a 
            ma = max(res,ma)
    return ma
res = dfs(-1,-1)
print(res)

### FIXED CODE ###

N = int(input())
A = []
for i in range(0,N):
    A.append(list(map(int,input().split())))

dp = [[0 for _ in range(3)] for _ in range(N)]
for i in range(N):
    for j in range(3):
        if i == 0:
            dp[i][j]= A[i][j]
        else:
            tmp = [0] 
            for k in range(3):
                if j !=k:
                    tmp.append(dp[i-1][k])
            dp[i][j] = max(tmp) + A[i][j]
print(max(dp[-1]))
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))

answer = 1
for i in range(n):
    answer*=a[i]
    
if answer>int(1e+18):
    print(-1)
else:
    print(answer)

### FIXED CODE ###

import sys
n = int(input())
a = list(map(int, input().split()))

answer = 1
zero_exist = False
up_to_threshold = False
for i in range(n):
    if answer>int(1e+18):
        up_to_threshold = True
    else:
        answer*=a[i]
    if a[i] == 0:
        zero_exist = True
    
if zero_exist == True:
    print(0)
elif up_to_threshold == True or answer > int(1e+18):
    print(-1)
else:
    print(answer)