Harryxun/stf_run huggingface dataset:
import defaultdict from collections

d = defaultdict([])
goal, n = map(int,  input().split())
for _ in range(n):
  from, to = map(int, input().split())
  d[from].append[to]
  d[to].append[from]
for current in d[1]:
  if goal in d[current]:
    print("POSSIBLE")
    break
else:
  print("IMPOSSIBLE")

### FIXED CODE ###

from collections import defaultdict

d = defaultdict(list)
goal, n = map(int, input().split())
for _ in range(n):
  f, t = map(int, input().split())
  d[f].append(t)
  d[t].append(f)
for current in d[1]:
  if goal in d[current]:
    print("POSSIBLE")
    break
else:
  print("IMPOSSIBLE")
s = input()
ans = []
counter = 0
for i in s:
    if i in 'ATGC':
        counter += 1
    else:
        ans.append(counter)
        conter = 0

print(max(ans))

### FIXED CODE ###

s = input()
ans = []
counter = 0
for i in s:
    if i in 'ATGC':
        counter += 1
    else:
        counter = 0
    ans.append(counter)
print(max(ans))
p = []
for i in range(int(input())):
    p.append(int(input()))

p.sort().reverse()
total = int(p[0] * 0.5)
for i in range(1, len(p)):
    total += p[i]
print(total)

### FIXED CODE ###

n = int(input())
p = [int(input()) for _ in range(n)]
p.sort(reverse=True)
sum = int(p[0] / 2)
for i in range(1, len(p)):
	sum += p[i]
print(sum)
N = map(int,input())
x = 0
while x < N :
  x = x + 1000
print(x-N)

### FIXED CODE ###

N = int(input())
x = 0
while x < N :
  x = x + 1000
print(x-N)
def sortex(X):
  b=sorted(X)
  b.append("null")
  a=[]
  for i in range(len(X)):
    if b[i]!=b[i+1]:a.append(b[i])
  return a
n,s=int(input()),input().split();s=sortex(s);print("Four"if len(n)==4else"Three")

### FIXED CODE ###

def sortex(X):
  b=sorted(X)
  b.append("null")
  a=[]
  for i in range(len(X)):
    if b[i]!=b[i+1]:a.append(b[i])
  return a
n,s=int(input()),input().split();s=sortex(s);print("Four"if len(s)==4else"Three")
from bisect import bisect_left
N = input()
t_list = list ( map ( int, input().split() ) )
t_list.sort()

for i in range ( N - 2 ):
  a = t_list[i]
  for j in range ( i + 1, N - 1 ):
    b = t_list[j]
    c = bisect_left ( t_list , a + b)
    ans += c - j - 1
    
print(ans)


### FIXED CODE ###

from bisect import bisect_left
N = int ( input() )
t_list = list ( map ( int, input().split() ) )
t_list.sort()
ans = 0

for i in range ( N - 2 ):
  a = t_list[i]
  for j in range ( i + 1, N - 1 ):
    b = t_list[j]
    c = bisect_left ( t_list , a + b)
    ans += c - j - 1
    
print(ans)
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = sum(B) + sum(C) - C[A[N-1] - 1]
print(ans)

### FIXED CODE ###

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

ans = sum(B)
for i in range(N-1):
  if A[i]+1 == A[i+1]:
    ans += C[A[i]-1]
print(ans)
S=input()
N=len(S)
ans='Yes'
if N==3:
  S[0]!=S[2]:
    ans='No'
else:
    if int((N-1)/2)%2==1:
        for i in range((N-3)//4):
            if S[i] != S[((N-3)//2)-i] or S[((N+1)//2)+i] != S[N-i-1]:
                ans='No'
    else:
        for i in range((N-1)//4):
            if S[i] != S[((N-3)//2)-i] or S[((N+1)//2)+i] != S[N-i-1]:
                ans='No'
 
print(ans)

### FIXED CODE ###

S=input()
N=len(S)
ans='Yes'

for i in range((N-1)//2):
    if S[i] != S[N-i-1]:
        ans='No'

if int((N-1)/2)%2==1:
    for i in range((N-3)//4):
        if S[i] != S[((N-3)//2)-i] or S[((N+1)//2)+i] != S[N-i-1]:
            ans='No'
else:
    for i in range((N-1)//4):
        if S[i] != S[((N-3)//2)-i] or S[((N+1)//2)+i] != S[N-i-1]:
            ans='No'
 
print(ans)
mod=10**9+7
x,y=map(int,input().split())

a=(-x+2*y)//3
b=(2*x-y)//3

f=[1]
for i in range(1,a+b+1):
    f.append(f[-1]*i%mod)

if a+2*b==x and 2*a+b==y and (-x+2*y)%3==0 and (2*x-y)%3==0:
    print(f[a+b]*pow(f[a]*f[b],mod-2,mod)%mod)
else:
    print(0)

### FIXED CODE ###

r=int(input())

print(r**2)
s=input()
t=input()
S=list(s)
T=list(t)
S.sort()
T.sort()
T.reverse()
s=str(S)
t=str(T)



i=0
a=False
for wer in range( len(S) ):
    if S[i]<T[i]:
        a=True
        break
    i+=1
   

if a:print("Yes")
else :print("No")

### FIXED CODE ###

s=input()
t=input()
S=list(s)
T=list(t)
S.sort()
T.sort()
T.reverse()
s=str(S)
t=str(T)

if S<T:print("Yes")
else :print("No")
n, m = map(int, input().split())
l = sorted(list(map(int, input().split())), reverse=True)

if m == 1 and n == 1:
    S =0
else:
    d = sorted([l[i] - l[i+1]  for i in range(m-1)], reverse=True)
    S = max(l) - min(l)

    for i in range(n-1):
        S -= d[i]

print(S)


### FIXED CODE ###

n, m = map(int, input().split())
l = sorted(list(map(int, input().split())), reverse=True)

if n>=m or m == 1:
    S =0
else:
    d = sorted([l[i] - l[i+1]  for i in range(m-1)], reverse=True)
    S = max(l) - min(l)
    for i in range(n-1):
        S -= d[i]

print(S)
s = input()
    if s[0] == s[1] and s[1] == s[2]:
        print("No")
    else:
        print("Yes")


### FIXED CODE ###

s = input()
if s[0] == s[1] and s[1] == s[2]:
    print("No")
else:
    print("Yes")
S=list(input())
ans=10**10
for i in range(8):
    if abs(753-int(''.join(S[i:i+3])))<ans:
        ans=abs(753-int(''.join(S[i:i+3])))
print(ans)

### FIXED CODE ###

S=list(input())
ans=10**10
for i in range(len(S)-2):
    if abs(753-int(''.join(S[i:i+3])))<ans:
        ans=abs(753-int(''.join(S[i:i+3])))
print(ans)
X,Y,A,B,C = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
C_copy = C.copy()
for i in range(30):
    C_copy.append(0)
    C.append(0)
ux_1 = 0
uy_1 = 0
for i in range(X):
    ux_1 += max(max(A),max(C_copy))
    if max(A) >= max(C_copy):
        A.pop(A.index(max(A)))
    else:
        C_copy.pop(C_copy.index(max(C_copy)))
for i in range(Y):
    uy_1 += max(max(B),max(C_copy))
    if max(B) >= max(C_copy):
        B.pop(B.index(max(B)))
    else:
        C_copy.pop(C_copy.index(max(C_copy)))
print(ux_1 + uy_1)

### FIXED CODE ###

S = str(input())
if S[2] == S[3] and S[4] == S[5]:
    print('Yes')
else:
    print('No')
N, M = map(int, raw_input().split())

res = 0
for i in range(1, N + 1):
	if i > M * M:
		break
	iif M % i != 0:
		continue
	j = M / i
	if i * N <= M:
		res = max(res, i)
	if j * N <= M:
		res = max(res, j)
print res


### FIXED CODE ###

import math
N, M = map(int, raw_input().split())

MAX_RES = int(math.sqrt(M))
res = 1
for i in range(1, MAX_RES + 1):
	if i * i > M:
		break
	if M % i != 0:
		continue
	j = M / i
	if i * N <= M:
		res = max(res, i)
	if j * N <= M:
		res = max(res, j)
print res
import math
def equation(a,b,n):
  return math.floor((a*n)/b)-a*math.floor(n/b)
d,e,f = map(int,input().split())
K = min(e-1,f)
print(equation(K))


### FIXED CODE ###

K = int(input())
a,b = map(int,input().split())
flag = 0
for i in range(a,b+1):
    if i%K == 0:
        flag += 1
        print("OK")
        break
if flag == 0:
    print("NG")
import sys
sys.setrecursionlimit(10000)

def dfs(friends, friend, cluster, visited, belongs, index):
    for i in friends[friend]:
        if not visited[i]:
            visited[i] = True
            cluster.add(i)
            belongs[i] = index
            dfs(friends, i, cluster, visited, belongs, index)

def make_clusters(friends, N):
    clusters = []
    visited = [False] * N
    belongs = [0] * N
    index = 0
    for i in range(N):
        if not visited[i]:
            cluster = set()
            visited[i] = True
            belongs[i] = index
            cluster.add(i)
            dfs(friends, i, cluster, visited, belongs, index)
            index += 1
            clusters.append(cluster)
    return (clusters, belongs)
    
    
N, M, K = map(int, input().split())

friends = [[] for _ in range(N)]
blocks = [set() for _ in range(N)]
clusters = []

for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    friends[A].append(B)
    friends[B].append(A)

for _ in range(K):
    C, D = map(int, input().split())
    C -= 1
    D -= 1
    blocks[C].add(D)
    blocks[D].add(C)

clusters, belongs = make_clusters(friends, N)

clusters_len = len(clusters)
cluster_len = [0] * clusters_len
for i in range(clusters_len):
    cluster_len[i] = len(clusters[i])

for i in range(N):
    ans = cluster_len[belongs[i]] - len(friends[i]) - len(clusters[belongs[i]] & blocks[i]) - 1
    print(ans, end=' ')

print()

### FIXED CODE ###

import sys
sys.setrecursionlimit(50000)

def dfs(friends, friend, cluster, visited, belongs, index):
    for i in friends[friend]:
        if not visited[i]:
            visited[i] = True
            cluster.add(i)
            belongs[i] = index
            dfs(friends, i, cluster, visited, belongs, index)

def make_clusters(friends, N):
    clusters = []
    visited = [False] * N
    belongs = [0] * N
    index = 0
    for i in range(N):
        if not visited[i]:
            cluster = set()
            visited[i] = True
            belongs[i] = index
            cluster.add(i)
            dfs(friends, i, cluster, visited, belongs, index)
            index += 1
            clusters.append(cluster)
    return (clusters, belongs)
    
    
N, M, K = map(int, input().split())

friends = [[] for _ in range(N)]
blocks = [set() for _ in range(N)]
clusters = []

for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    friends[A].append(B)
    friends[B].append(A)

for _ in range(K):
    C, D = map(int, input().split())
    C -= 1
    D -= 1
    blocks[C].add(D)
    blocks[D].add(C)

clusters, belongs = make_clusters(friends, N)

clusters_len = len(clusters)
cluster_len = [0] * clusters_len
for i in range(clusters_len):
    cluster_len[i] = len(clusters[i])

for i in range(N):
    ans = cluster_len[belongs[i]] - len(friends[i]) - len(clusters[belongs[i]] & blocks[i]) - 1
    print(ans, end=' ')

print()
# coding: utf-8
# Your code here!

import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

def main():
    l = input().rstrip().split(' ')
    
    x = int(l[0])
    y = int(l[1])
    
    print(lcm(x, y))
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

#最大公約数、最小公倍数
import fractions
a,b=map(int, input().split())
f=fractions.gcd(a,b)
f2=a*b//f
print(f2)
from math import gcd
n, k = map(int, input().split())
arr = list(map(int, input().split()))
g = arr[0]
for e in arr[1:]:
	g = gcd(g, e)
if k <= max(arr) and k//g*g == k:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

### FIXED CODE ###

def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)

n, k = map(int, input().split())
arr = list(map(int, input().split()))
g = arr[0]
for e in arr[1:]:
    g = gcd(g, e)

if k <= max(arr) and k//g*g == k:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
s,t=input().split()
a,b=map(int,input().split())
u=input()
print(a-1 b if u==s else a b-1)


### FIXED CODE ###

s,t=input().split()
a,b=map(int,input().split())
u=input()
print(a-1, b) if u==s else print(a, b-1)
a, b, c = map(int, input().split())

cnt = 0
while c > 0:
    c -= 1
    cnt += 1
    if b > 0:
        b -= 1
        cnt += 1
        continue
    elif a > 0:
        a -= 1
        continue
    else:
        break

print(cnt)



### FIXED CODE ###

def func2(input_list):
    if n >= m:
        return 0

    input_list.sort()

    input_diff = []
    for i in range(m-1):
        diff = input_list[i+1] - input_list[i]
        input_diff.append(abs(diff))

    input_diff.sort(reverse=True)
    ans = input_list[-1] - input_list[0]
    for i in range(0, n-1):
        ans -= input_diff[i]

    return ans

n, m = map(int, input().split())
input_list = [int(i) for i in input().split()]

print(func2(input_list))
a, b, c = map(int, input().split())

if (a!=b && a!=c && b!=c) || (a==b && a==c):
  print("No")
else :
  print("Yes")


### FIXED CODE ###

a, b, c = map(int, input().split())

if (a!=b and a!=c and b!=c) or (a==b and a==c):
  print("No")
else :
  print("Yes")
import sys

a = int(sys.argv[1])
print("{}".format(a**3))

### FIXED CODE ###

x = int(input())
print(x**3)
W, H, x, y = [int(item) for item in input().split()]
S = W * H
m = max(min(x/W, 1-x/W), min(y/H, 1-y/H))
ans_s = S * m
ans_m = 0
if (W/x == 2 and H/y==2):
  ans_m = 1
print (ans_s, ans_m)

### FIXED CODE ###

W, H, x, y = [int(item) for item in input().split()]
S = W * H
ans_m = 0
if (W == 2*x and H==2*y):
  ans_m = 1
print (S/2, ans_m)
import math
n=int(input()
p=list(input().split())
q=list(input().split())
cntp=0
cntq=0
for i in range(n-2):
  cntp+=(p[0]-1)*math.factorial(n-i-1)
  cntq+=(q[0]-1)*math.factorial(n-i-1)
print(abs(cntp-cntq))

### FIXED CODE ###

import itertools
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
l=[]
for a in itertools.permutations(range(1,n+1),n):
  l.append(a)
ip=l.index(tuple(p))
iq=l.index(tuple(q))
print(abs(ip-iq))
n = int(input())
s = list(input())
k = int(input())

moji = s[k-1]

for ss in s:
	if s[ss]!=moji:
		s[ss]='*'

print(str(s))

### FIXED CODE ###

n = int(input())
s = list(input())
k = int(input())

moji = s[k-1]

for i in range(n):
	if s[i]!=moji:
		s[i]='*'

ans = ''.join(s)
print(ans)
a = int(input())
l=list(map(int ,input().split()))
ll=[]
for i in range(a-2):
        k=(l[i]+l[i+1])/2+(l[i+2])
        ll.append(k/2)

print(max(ll))

### FIXED CODE ###

a = int(input())
l=(list(map(int ,input().split())))
l.sort()
ll=[]
j=0
r=(l[0]+l[1])/2
ll.append(r)
for i in range(a-2):
        j=(ll[0]+l[i+2])/2
        ll.append(j)
        ll.remove(ll[0])
print((ll[0]))
import math
def hoge(a):
    return a * a
x1, y1, x2, y2 = map(int, input().split())
print (math.sqrt(hoge(math.fabs(x1-x2)) + hoge(math.fabs(y1-y2))))


### FIXED CODE ###

import math
def hoge(a):
    return a * a
x1, y1, x2, y2 = map(float, input().split())
print (math.sqrt(hoge(math.fabs(x1-x2)) + hoge(math.fabs(y1-y2))))
N,X,D=map(int,input().split())
from collections import defaultdict as d
f,c,r=d(int),d(int),0
for x,y,z in sorted(((N-k)*k*j+~-k*k//2+k*X//D,j,k*X%D)for k in range(N+1) for j in[0,1]):
 r+=(x-f[z]+1)*(c[z]<2)*y
 f[z]=x if(c[z]+y<1)else f[z]
 c[z]-=2*y-1
print(r)

### FIXED CODE ###

N, X, D = map(int, input().split())
if D == 0:
    r = N+1
    if X == 0:
        r = 1
    print(r)
else:
    if D < 0:
        X, D = -X, -D
    d = dict()
    for k in range(N+1):
        M = (k*X) % D
        F = (k*X)//D + ((k-1)*k)//2 #(1..k-1)
        L = (k*X)//D + (2*N-k-1)*k//2# (N-k..N-1)
        if M not in d:
            d[M] = list()
        d[M].append((F, 0))
        d[M].append((L, 1))
    r = 0
    for m in d:
        d[m] = sorted(d[m])
        fc = 0
        f = 0
        for x in d[m]:
            if not x[1]:
                fc += 1
                if fc == 1:
                    f = x[0]
            if x[1]:
                fc -= 1
                if fc == 0:
                    r += x[0] - f + 1
    print(r)
print(!(int)(input()))

### FIXED CODE ###

a = int(input())
print(int(not a))
n = int(input())
t, a = map(int, input().split())
t *= 1000
a *= 1000
lst = list(map(int, input().split()))
tmp = abs(t - 6 * lst[0] - a)
tmpa = 0
for i in range(1, n):
    if temp < tmp:
        tmp = tmp
        tmpa = i
print(tmpa + 1)

### FIXED CODE ###

n = int(input())
t, a = map(int, input().split())
t *= 1000
a *= 1000
lst = list(map(int, input().split()))
tmp = abs(t - 6 * lst[0] - a)
tmpa = 0
for i in range(1, n):
    temp = abs(t - 6 * lst[i] - a)
    if temp < tmp:
        tmp = temp
        tmpa = i
print(tmpa + 1)
S = input()
dp = [-1, -1]*len(S)


def solve(s):
    l = len(s)
    if dp[l-1] != -1:
        return dp[l-1]
    else:

        if l >= 2:
            dp[l-2] = solve(s[:-1])
        else:
            dp[0] = [1, 1]
            return dp[0]
        if s[-1] != s[-2]:
            if dp[l-2][1] == 2 and s[-2] == s[-3]:
                dp[l-1] = [dp[l-2][0] + 1, 2]
            else:
                dp[l-1] = [dp[l-2][0] + 1, 1]
        else:
            if dp[l-2][1] == 2:
                dp[l-1] = [dp[l-2][0] + 1, 1]
            else:
                dp[l-1] = [dp[l-2][0], 2]

        return dp[l-1]


ans = solve(S)
print(ans[0])


### FIXED CODE ###

S = input()
ans = []

prev = ""
now = ""
for i in range(len(S)):
    now = now + S[i]
    if now != prev:
        ans.append(now)
        prev = now
        now = ""


print(len(ans))
def run(x, n, num_array):
    '''
    '''
    if len(num_array) == 0:
        print(x)
        return
    
    i = 0
    while True:
        if x - i not in num_array:
            print(x - i)
            return
        elif x + i not in num_array:
            print(x + i)
            return
        i += 1
        

if __name__ == '__main__':
    x, n = list(map(int, input().split()))
    num_array = list(map(int, input().split()))
    run(x, n, num_array)

### FIXED CODE ###

def run(x):
    '''
    '''
    for i,v in enumerate(x):
        if v == 0:
            print(i+1)


if __name__ == '__main__':
    x = list(map(int, input().split()))
    run(x)
from collections import deque


def transaction(N, r):
    x = r[0]
    n = int(N / x[1])
    if N % x[1] == 0:
        return n * x[2]
    if len(r) == 1:
        return n * x[2] + N - n * x[1]
    r.popleft()
    s = N
    for i in range(n + 1):
        tmp = i * x[2] + transaction(N - i * x[1], r)
        if tmp > s:
            s = tmp
    return s

N = int(input())
A = [int(e) for e in input().split()]
B = [int(e) for e in input().split()]

r = []
for i in range(3):
    (a, b) = (A[i], B[i])
    if b > a:
        r.append((b / a, a, b))

if len(r) > 0:
    r.sort(reverse=True)
    dr = deque(maxlen=3)
    for x in r:
        dr.append(x)
    N = transaction(N, dr)

r = []
for i in range(3):
    (a, b) = (A[i], B[i])
    if a > b:
        r.append((a / b, b, a))

if len(r) > 0:
    r.sort(reverse=True)
    dr = deque(maxlen=3)
    for x in r:
        dr.append(x)
    N = transaction(N, dr)

print(N)

### FIXED CODE ###

import math
import sys

N = int(input())
GA, SA, BA = list(map(int, input().split()))
GB, SB, BB = list(map(int, input().split()))

def knapsack(n, ga, sa, ba, gb, sb, bb):
    values = []
    weights = []
    if gb / ga > 1:
        values.append(gb - ga)
        weights.append(ga)
    if sb / sa > 1:
        values.append(sb - sa)
        weights.append(sa)
    if bb / ba > 1:
        values.append(bb - ba)
        weights.append(ba)
    if len(values) == 3:
        # dp[i]: 重さ i 以下で選ぶのの価値の最大値
        dp = [0] * (n + 1)
        dp[0] = n
        for i in range(1, n + 1):
            x = dp[i - 1]
            for w, v in zip(weights, values):
                if i - w >= 0:
                    x = max(x, dp[i - w] + v)
            dp[i] = x
        return dp[n]
    if len(values) == 2:
        w1, w2 = weights
        v1, v2 = values
        if (v1 + w1) / w1 < (v2 + w2) / w2:
            v1, v2 = v2, v1
            w1, w2 = w2, w1
        c1 = n // w1
        c2 = (n - w1 * c1) // w2
        ret = n + v1 * c1 + v2 * c2
        while c1 >= 0:
            a = n - w1 * c1 - w2 * c2
            c1 -= max(1, math.ceil((w2 - a) / w1))
            c2 = (n - w1 * c1) // w2
            ret = max(ret, n + v1 * c1 + v2 * c2)
            if w1 * c1 + w2 * c2 == n:
                break
        return ret
    if len(values) == 1:
        return n + n // weights[0] * values[0]
    return n

ans = knapsack(N, GA, SA, BA, GB, SB, BB)
ans = knapsack(ans, GB, SB, BB, GA, SA, BA)
print(int(ans))
n = int(input())
d, x = map(int,input().split())
res = x
for i in range(n):
    a = int(input())
    if a == 1:
        res +=d
    else :
        res += (d-1)//a + 1
print(res)

### FIXED CODE ###

a=int(input())
b=int(input())
c=int(input())
d=int(input())
print(min(a,b)+min(c,d))
N = int(input())
s = [input() for i in range(N)]
for v in ['AC', 'WA', 'TLE', 'RE']:
print('{0} x {1}'.format(v, s.count(v)))

### FIXED CODE ###

n = int(input())
c1 = 0
c2 = 0
c3 = 0
c4 = 0
for i in range(n):
  s = str(input()) 
  if s == "AC":
    c1 += 1
  if s== "WA":
    c2 += 1
  if s == "TLE":
    c3 += 1
  if s == "RE":
    c4 += 1

print("AC x " + str(c1))
print("WA x " + str(c2))
print("TLE x " + str(c3))
print("RE x " + str(c4))
def main():
    x, k, d = map(int, input().split())
    x = abs(x)
    count_p = abs(x // d) 
    count_m = abs(x // d) + 1
    if abs(x - (count_p*d)) <= abs((x - count_m*d)):
        small_count = count_p
    else:
        small_count = count_m
    if small_count > k:
        print(abs(x - (k * d)))
    else:
        if x - (small_count*d) != 0:
            if (k % small_count) % 2 == 0:
                print(abs(x - (small_count*d)))
            else:
                print(abs(x - (small_count*(d+1))))
        else:
            if (k % small_count) % 2 == 0:
                print(d)
            else:
                print(0)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    x, k, d = map(int, input().split())
    x = abs(x)
    count = x // d
    if count > k:
        ans = x - (k*d)
    else:
        if k % 2 == count % 2:
            ans = x - (count*d)
        else:
            ans = x - (count+1) * d
    print(abs(ans))
    
if __name__ == '__main__':
    main()
import sys
input = sys.stdin.readline
H,W = map(int,input().rstrip().split())
h,w = map(int,input().rstrip().split())
cells = [[1]*W]*H
cells = cells[h:]
cells = list(zip(*cells))
cells = cells[w:]
cells = list(zip(*cells))
print(int(sum(list(map(sum,[*cells])))))

### FIXED CODE ###

import sys
input = sys.stdin.readline
H,W = map(int,input().rstrip().split())
h,w = map(int,input().rstrip().split())
cells = [[1]*W]*H
cells = cells[h:]
cells = list(zip(*cells))
cells = cells[w:]
print(sum(list(map(sum,list(zip(*cells))))))
import sys
print(int(sys.argv[1]) ** 3)

### FIXED CODE ###

i = int(raw_input())
print(i ** 3)
# https://atcoder.jp/contests/dp/tasks/dp_f?lang=ja


def lcs(s1,s2):
    n1,n2 = len(s1),len(s2)
    dp = [ [0]*(n2+1) for _ in range(n1+1) ]
    for i in range(1,n1+1):
        for j in range(1,n2+1):
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]) 
            if s1[i-1] == s2[j-1]: dp[i][j] = dp[i-1][j-1]+1
    return dp[-1][-1]



for _ in range(int(input())):
    s1 = input()
    s2 = input()
    ans = lcs(s1,s2)
    print(ans,flush=True)

### FIXED CODE ###

# https://atcoder.jp/contests/dp/tasks/dp_f?lang=ja

# get LCS length
def lcs_len(s1,s2):
    n1,n2 = len(s1),len(s2)
    dp = [ [0]*(n2+1) for _ in range(n1+1) ]
    for i in range(1,n1+1):
        for j in range(1,n2+1):
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]) 
            if s1[i-1] == s2[j-1]: dp[i][j] = dp[i-1][j-1]+1
    return dp[-1][-1]

# get LCS string
def lcs_str(s1,s2):
    n1,n2 = len(s1),len(s2)
    dp = [ [0]*(n2+1) for _ in range(n1+1) ]
    for i in range(1,n1+1):
        for j in range(1,n2+1):
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]) 
            if s1[i-1] == s2[j-1]: dp[i][j] = dp[i-1][j-1]+1
    ansr = []
    i,j = n1,n2
    while i > 0 and j > 0:
        if dp[i][j] == dp[i-1][j]: i -= 1
        elif dp[i][j] == dp[i][j-1]: j -= 1
        else: 
            ansr.append(s1[i-1])
            i -= 1
            j -= 1
    ans = ansr[::-1]
    return ''.join(ans)


s1 = input()
s2 = input()
ans = lcs_str(s1,s2)
print(ans,flush=True)
m = list(map(int, input().split()))

hp = list(map(int, input().split()))
result = 0
checkyakusuru = []
checkodd = []
checkeven = []

if (hp.count(hp[0]) == m[0]):
    result = hp[0]

minhp = min(hp)

for p in hp:
    if (p % minhp == 0):
        checkyakusuru.append(1)
    
    if (checkyakusuru.count(1) == m[0]):
        result = p
        break
    else:
        if (p % 2 == 0):
            checkeven.append(1)
        if (checkeven.count(1) == m[0]):
            result = 2
            break
        else:
            result = 1

### FIXED CODE ###

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

def f(a, b):
    if (b % a == 0):
        return a + b 
    else:
        return b - a 
print(f(a[0], a[1]))