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

n=int(input())
a=list(map(int,input().split()))
b=len(a)
result=1
i=0
j=0
while True:
    if a[i]!=result:
        del a[i]
    else:
        result+=1
        i+=1
    j+=1
    if j>=b:
        break
if a==[]:
    print(-1)
else:
    print(b-len(a))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=len(a)
result=1
i=0
j=0
while True:
    if a[i]==result:
        result+=1
    i+=1
    if i>=b:
        break
if result==1:
    print(-1)
else:
    print(b-result+1)
### BUGGY CODE ###

N = int(input())
lst = list([int(input()) for i in range(N)])

for i in range(N):
  copy_lst = lst.copy()
  copy_lst.remove(copy_lst[i])
  print(max(copy_lst))

### FIXED CODE ###

N = int(input())
lst = list([int(input()) for i in range(N)])
a = sorted(lst,reverse=True)
for i in range(N):
  if lst[i] != a[0]:
    print(a[0])
  else:
    print(a[1])
### BUGGY CODE ###

import heapq
def SME():
    A = []
    ANS = [None] * N
    C = set([i for i in range(N)])
    D = set([])
    E = [None] * N
    parameter = 0.9997
    count = 0
    for i,x in enumerate(Whole) :
        heapq.heappush(A,[x,i])
    for j in range(N) :
        a = heapq.heappop(A)
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    D.add(idx)
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in C.difference(D):
        if i < L : ANS[i] = min(Whole[:i+1])
        else : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
ANS = SME()
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
### BUGGY CODE ###

N = int(input())
li = []
for _ in range(N):
    li.append(int(input()))

max_indexs =  [i for i, x in enumerate(li) if x == max(li)]
li.sort()
max_val = li[-1]

if len(max_indexs) == 1:
    for i in range(N):
        if i == max_indexs[0]:
            print(li[-2])
        else:
            print(max_val)
else:
    for i in range(N):
        print(max_val)

### FIXED CODE ###

N = int(input())
li = []
for _ in range(N):
    li.append(int(input()))

li2 = sorted(li)
max1 = li2[-1]
max2 = li2[-2]
max_index = li.index(max1)

if max1 != max2:
    for i in range(N):
        if i == max_index:
            print(max2)
        else:
            print(max1)
else:
    for i in range(N):
        print(max1)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Grand Contest 023
Author     : Kitaura Hiromi
LastUpdate : 20180502
Since      : 20180428
"""
N = int(input())
A = list(map(int, input().split(" ")))

"""
# O(N^2)
cnt = 0
for i in range(N):
    for j in range(i+1, N+1):
        if sum(A[i:j]) == 0:
            cnt += 1
print(cnt)
"""

# O(NlogN)
S = []
for i in range(N+1):
    S.append(sum(A[:i]))
S = sorted(S)
cnt = 1
ret = 0
tmp = S[0]
for i in range(1, len(S)):
    if tmp == S[i]:
        cnt += 1
    else:
        ret += cnt * (cnt - 1) // 2
        cnt = 1
        tmp = S[i]
ret += cnt * (cnt - 1) // 2
print(ret)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Grand Contest 023
Author     : Kitaura Hiromi
LastUpdate : 20180502
Since      : 20180428
"""
N = int(input())
A = list(map(int, input().split(" ")))

# O(NlogN)
S = []
tmp = 0
for i in range(N):
    S.append(tmp)
    tmp += A[i]
S.append(tmp)
S = sorted(S)
cnt = 1
ret = 0
tmp = S[0]
for i in range(1, len(S)):
    if tmp == S[i]:
        cnt += 1
    else:
        ret += cnt * (cnt - 1) // 2
        cnt = 1
        tmp = S[i]
ret += cnt * (cnt - 1) // 2
print(ret)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
B = sorted([(a,i) for i,a in enumerate(A)])

dp = [[0]*(N+1) for _ in range(N+1)]
for i in range(N):
    a,j = B.pop()
    for k in range(i+1):
        dp[k][i-k+1] = max(dp[k][i-k+1], dp[k][i-k] + a * abs(j-(N-1-(i-k))))
        dp[k+1][i-k] = max(dp[k+1][i-k], dp[k][i-k] + a * abs(j-k))

print(max(dp[i][N-i] for i in range(N+1)))

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
B = sorted([(a,i) for i,a in enumerate(A)])

dp = [[0]*(N+1) for _ in range(N+1)]
for i in range(N):
    a,j = B.pop()
    for k in range(i+1):
        dp[k][i-k+1] = max(dp[k][i-k+1], dp[k][i-k] + a * abs(j-(N-1-(i-k))))
        dp[k+1][i-k] = max(dp[k+1][i-k], dp[k][i-k] + a * abs(j-k))

print(max(dp[i][N-i] for i in range(N+1)))
### BUGGY CODE ###

n, m = [int(i) for i in input().split(" ")]
s = [int(input()) for _ in range(m)]

divider = 10**9 + 7
ans = [0]*(n + 1)
ans[0] = 1
ans[1] = 1

if 1 in s:
    ans[1] = 0
        
for i in range(2, n+1):
    
    ans[i] = ans[i-1] + ans[i-2]
    if i in s:
        ans[i] = 0
   
print(ans[n] % divider)

### FIXED CODE ###

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

l = list(range(1, n+1))
divider = 10**9 + 7
ans = [0]*(n + 1)
broken = [False]*(n+1)
ans[0] = 1
ans[1] = 1

for i in range(m):
    a = int(input())
    broken[a] = True
    if a == 1:
        ans[1] = 0
    
for i in range(2,n+1):
    if broken[i] == False:
        ans[i] = ans[i-1] + ans[i-2]
    
   
print(ans[n] % divider)
### BUGGY CODE ###

def solve():
    rem = N * (N - 1) // 2
    for day in range(N * (N - 1) // 2):
        did_play = [0] * N
        for i in range(N):
            if did_play[i] or A[i] == []:
                continue
            opponent = A[i][-1]
            if A[opponent][-1] == i and not did_play[opponent]:
                A[i].pop()
                A[opponent].pop()
                rem -= 1
                did_play[i] = 1
                did_play[opponent] = 1
        if sum(did_play) == 0:
            break
        if rem == 0:
            return day + 1
    return -1


N = int(input())
A = [list(map(lambda x: int(x) - 1, input().split()))[::-1] for _ in range(N)]
print(solve())


### FIXED CODE ###

from sys import setrecursionlimit


def encode(i, j):
    if i < j:
        i, j = j, i
    return i * (i - 1) // 2 + j + 1


def dfs(v):
    if visited[v] == 2:
        return dp[v]
    visited[v] = 1
    for nv in g[v]:
        if visited[nv] == 1:
            print(-1)
            exit()
        dp[v] = max(dp[v], dfs(nv) + 1)
    visited[v] = 2
    return dp[v]


setrecursionlimit(10 ** 6)
N = int(input())
GAMES_CNT = N * (N - 1) // 2
g = [[] for _ in range(GAMES_CNT + 1)]
for i in range(N):
    orig = 0
    for j in map(lambda x: int(x) - 1, input().split()):
        dest = encode(i, j)
        g[orig].append(dest)
        orig = dest
dp = [0] * (GAMES_CNT + 1)
visited = [0] * (GAMES_CNT + 1)
print(dfs(0))
### BUGGY CODE ###

import sys
 
INF         = 10000
VISITED     = 1
NOT_VISITED = 0

N, M = map(int, input().split())
route = [[INF for _ in range(N)] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    route[a-1][b-1] = 1
    route[b-1][a-1] = 1

size = len(route)
cost = [INF for _ in range(size)]
visit = [NOT_VISITED for _ in range(size)]
before = [None for _ in range(size)]
cost[0] = 0
while True:
    min = INF
    for i in range(size):
        if visit[i] == NOT_VISITED and cost[i] < min:
            x = i
            min = cost[x]
    if min == INF:
        break
    visit[x] = VISITED
 
    for i in range(size):
        if cost[i] > route[x][i] + cost[x]:
            cost[i] = route[x][i] + cost[x]
            before[i] = x

ans = [-1 for _ in range(size)]
for i in range(1, size):
    point = i
    to = before[point]
    while True:
        if to == 0:
            ans[point] = 0
            break
        elif ans[point] != -1 and to != ans[point]:
            print("No")
            sys.exit()
        ans[point] = to
        point = to
        to = before[point]

print("Yes")
for a in ans[1:]:
    print(a+1)


### FIXED CODE ###

from collections import deque
 
N,M=map(int,input().split())
 
graph=[[]for _ in range(N+1)]
 
for _ in range(M):
    A,B=map(int,input().split())
    graph[A].append(B)
    graph[B].append(A)
 
dist=[-1]*(N+1)
dist[0]=0
dist[1]=0
 
D=deque()
D.append(1)
 
while D:
    V=D.popleft()
    for i in graph[V]:
        if dist[i]!=-1:
            continue
        dist[i]=V
        D.append(i)
 
print('Yes')
for j in dist[2:]:
    print(j)
### BUGGY CODE ###

n = int(input())
a = []
for i in range(n):
    c = input()
    if(c in a):
        a.remove(c)
    else:
        a.append(c)
print(len(a))

### FIXED CODE ###

n = int(input())
dict = {}
ans = 0
for i in range(n):
    c = input()
    if(c in dict):
        dict[c] += 1
    else:
        dict[c] = 1
for i in dict:
    ans += dict[i] % 2
print(ans)
### BUGGY CODE ###

if __name__ == '__main__':
    n, a, b = tuple([int(s) for s in input().split()])
    res = 0

    while n > 0:
        res += min([a, n])
        n -= a
        n -= b

    print(res)


### FIXED CODE ###

if __name__ == '__main__':
    n, a, b = tuple([int(s) for s in input().split()])
    div = n // (a + b)
    mod = n % (a + b)

    print(a * div + min([a, mod]))
### BUGGY CODE ###

word = input()
start = 0
end = len(word)
while(True):
	i = word.find('?', start, end)
	if (i == -1):
		break
	elif ((i == (end-1)) or (word[i-1] == 'P')):
		word = word[:i] + 'D' + word[i+1:]
	elif ((word[i+1] == "?") or (word[i+1] == "D")):
		word = word[:i] + 'P' + word[i+1:]
	start = i + 1
print(word)

### FIXED CODE ###

word = input()
start = 0
end = len(word)
while(True):
	i = word.find('?', start, end)
	if (i == -1):
		break
	elif (i == (end-1)):
		word = word.replace('?', "D", 1)   
	elif (word[i-1] == 'P'):
		word = word.replace('?', "D", 1)
	elif ((word[i+1] == "?") or (word[i+1] == "D")):
		word = word.replace('?', "P", 1)
	else:
		word = word.replace('?', "D", 1)
	start = i + 1
print(word)
### BUGGY CODE ###

import os
from collections import Counter

import math
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353


def get_factors(n):
    """
    素因数分解
    :param int n:
    :rtype: list of int
    """
    if n <= 1:
        return []

    ret = []
    while n > 2 and n % 2 == 0:
        ret.append(2)
        n //= 2
    i = 3
    while i <= math.sqrt(n):
        if n % i == 0:
            ret.append(i)
            n //= i
        else:
            i += 2
    ret.append(n)
    return ret


def get_divisors(n):
    """
    n の約数をリストで返す
    :param int n:
    :rtype: list of int
    """
    ret = []
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            ret.append(i)
            if n // i != i:
                ret.append(n // i)
    return ret


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

S = set(A)
counts = Counter(A)
ans=0
for a in A:
    if counts[a] >= 2:
        continue
    ok = True
    for d in get_divisors(a):
        if d == a:
            continue
        ok &= d not in S
    ans +=ok
print(ans)

exit()
factors = []
for a in A:
    fs = get_factors(a)
    factors.append(fs)
    for f in fs:
        counts[f] += 1

ans = 0
for i, a in enumerate(A):
    fs = factors[i]
    ok = True
    for k, v in Counter(fs).items():
        ok &= counts[k] == v
    ans += ok
    print(i, a, ok)
print(ans)

# TODO: 1


### FIXED CODE ###

import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

counter = Counter(A)
A.sort()

dp = [True] * (max(A) + 10)
ans = 0
for a in A:
    if not dp[a]:
        continue
    if counter[a] == 1:
        ans += dp[a]
    j = a
    while j < len(dp):
        dp[j] = False
        j += a
print(ans)
### BUGGY CODE ###

h,n=map(int,input().split())
A=[]; dp=[10**9]*(h+10)
for i in range(n):
  x,y=map(int,input().split())
  A.append((x,y))
dp[0]=0
for a,b in A:
  for i in range(h):
    if dp[i]==10**9: continue
    index=min(h,i+a)
    dp[index]=min(dp[index],dp[i]+b)
print(dp[h])

### FIXED CODE ###

def IN(): return map(int,input().split())
ans = pow(2,31); mod = pow(10,9)+7
h,n=IN()
A=[]; dp=[pow(2,31)]*111111
for i in range(n):
  x,y=IN()
  A.append((x,y))
dp[0]=0
for a,b in A:
  for i in range(h+1111):
    dp[i+a]=min(dp[i+a],dp[i]+b)
for i in range(h,11111):
  ans=min(ans,dp[i])
print(ans)
### BUGGY CODE ###

s = input()
q = int(input())

roll = False

for i in range(q) :
    inp = input()
    if inp[:1] == '1' :
        roll = not roll
        #print(roll)
    else :
        t, f, c = inp.split()
        #print(t, f, c)
        if (f == '1' and (not roll)) or (f == '2' and roll) :
            s = c + s
        else :
            s += c

if roll :
    s = s[::-1]

print(s)


### FIXED CODE ###

from collections import deque

s = input()
q = int(input())

roll = False
ans = deque([s])
preNum = 0

for i in range(q) :
    inp = input()
    if inp[:1] == '1' :
        roll = not roll
        #print(roll)
    else :
        t, f, c = inp.split()
        #print(ans)
        #print(t, f, c)
        if (f == '1' and (not roll)) or (f == '2' and roll) :
            ans.appendleft(c)
            preNum += 1
        else :
            ans.append(c)
#print(ans)
ans = list(ans)
if roll :
    ans[preNum] = ans[preNum][::-1]
    ans = ans[::-1]

#print(ans)
#print("".join(ans))
for s in ans :
    print(s, end='')
### BUGGY CODE ###

import copy

data = input().split()
N = int(data[0])
K = int(data[1])

TL = input()
TL = list(TL)
TLlist = []
now = TL[0]
nowlist = now

for lop in range(1,len(TL)):
    if not (now == TL[lop]):
        TLlist.append(nowlist)
        nowlist = TL[lop]
        now = TL[lop]
    else:
        nowlist += now
TLlist.append(nowlist)

maxS = 0
cnt = 0
fg = 0
tfg = 0
fg2 = False
loplist = copy.deepcopy(TLlist)

for lop3 in range(len(loplist)):
    for lop2 in range(len(loplist)):
        if loplist[lop2][:1] == "0":
            if fg <= tfg:
                num = len(loplist[lop2])
                loplist[lop2] = ""
                for lop3 in range( num ):
                    loplist[lop2] += "1"
                cnt += 1
                if cnt == K:
                    fg2 = True
                    break
            else:
                tfg += 1
    loplist = "".join(loplist).split("0")
    for lop2 in loplist:
        if maxS < len(lop2):
            maxS = len(lop2)

    loplist = copy.deepcopy(TLlist)
    fg += 1
    cnt = 0
    tfg = 0
    if fg2 == False:
        break
    else:
        fg2 = False

print(maxS)


### FIXED CODE ###

data = input().split()
N = int(data[0])
K = int(data[1])
 
TL = list(input())
TLlist = []
TLLlist = []
now = TL[0]
nowlist = now
anslist = []
 
for lop in range(1,len(TL)):
    if not (now == TL[lop]):
        TLlist.append(nowlist)
        TLLlist.append(len(nowlist))
        nowlist = TL[lop]
        now = TL[lop]
    else:
        nowlist += now
TLlist.append(nowlist)
TLLlist.append(len(nowlist))
 
 
if TLlist[0][:1] == "0" :
    anslist.append( sum(TLLlist[:2*K]) )
    anslist.append( sum(TLLlist[1:2*K + 2]) )
    for lop in range(3,len(TLlist),2):
        if 2*K +  lop > len(TLlist):
            break
        anslist.append( anslist[len(anslist)-1] - sum(TLLlist[lop-2:lop]) + sum(TLLlist[lop + 2*K - 1 : lop + 2*K + 1])  )
elif TLlist[0][:1] == "1" :
    anslist.append( sum(TLLlist[:2*K + 1 ]) )
    for lop in range(2,len(TLlist),2):
        if 2*K +  lop > len(TLlist):
            break
        anslist.append( anslist[len(anslist)-1] - sum(TLLlist[lop-2:lop]) + sum(TLLlist[lop + 2*K - 1 : lop + 2*K + 1])  )
 
print(max(anslist))
### BUGGY CODE ###

import heapq

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

def heapsort(iterable):
    h = []
    for value in iterable:
        heapq.heappush(h, value)
    return [heapq.heappop(h) for i in range(len(h))]

for i in range(m):
    m -= 0
    a = heapsort(a)
    a[-1] = a[-1] // 2

print(sum(a))

"""
for i in range(m):
    a.sort()
    a.reverse()
    m -= 1
    a[0] = a[0] // 2

print(sum(a))
"""


### FIXED CODE ###

import heapq

n,m = map(int, input().split())
#a = list(map(int, input().split()))
a = [-int(n) for n in input().split()]

heapq.heapify(a)

for i in range(m):
    tmp = heapq.heappop(a)
    tmp = int(tmp/2)
    heapq.heappush(a,tmp)

print(-sum(a))

"""
for i in range(m):
    a.sort()
    a.reverse()
    m -= 1
    a[0] = a[0] // 2

print(sum(a))
"""
"""
def heapsort(iterable):
    h = []
    for value in iterable:
        heapq.heappush(h, value)
    return [heapq.heappop(h) for i in range(len(h))]
"""
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
ans=1
for i in A:
    ans*=i
if ans>pow(10,18):
    print(-1)
else:
    print(ans)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
A.sort()
if A[0]!=0:
    ans=1
    for i in range(N):
        ans=ans*A[i]
        if ans>pow(10,18):
            ans='-1'
            break
else:
    ans=0
print(ans)
### BUGGY CODE ###

k, s = map(int, input().split())
count = 0
for kx in range(0, k+1):
    for ky in range(0, k+1):
        kz = s - kx -ky
        if kx + ky + kz == s and 0 <= kz <= k:
            count += 1
print(count)

### FIXED CODE ###

k, s = map(int, input().split())
count = 0
for kx in range(0, k+1):
    for ky in range(0, k+1):
        kz = s - kx -ky
        if 0 <= kz <= k and kx + ky + kz == s:
            count += 1
print(count)
### BUGGY CODE ###


from collections import deque
def resolve():
    drc4 = [(-1, 0), (0, 1), (1, 0), (0, -1)]

    def bfs(start, goal):
        sy, sx = start
        gy, gx = goal
        q = deque()
        q.append(start)
        ans[sy][sx] = 0

        while q:
            sy, sx = q.popleft()
            # if sy == gy and sx == gx:
            #     return print(ans[gy][gx])
            for dy, dx in drc4:
                ny, nx = dy + sy, dx + sx
                # if G[ny][nx] == "@" or ans[ny][nx] != INF:
                #     if G[ny][nx] != "#":
                #         continue
                if G[ny][nx] == "." and ans[ny][nx] > ans[sy][sx]:
                    ans[ny][nx] = ans[sy][sx]
                    q.append((ny, nx))

            for dy8 in range(-2, 3):
                for dx8 in range(-2, 3):
                    ny8, nx8 = dy8 + sy, dx8 + sx
                    if 1 <= ny8 <= H + 1 and 1 <= nx8 <= W + 1:
                        # if G[ny8][nx8] == "#":
                        #     continue
                        # if G[ny8][nx8] == "@" or ans[ny8][nx8] != INF:
                        #     continue
                        if G[ny8][nx8] == "." and ans[ny8][nx8] > ans[sy][sx] + 1:
                            ans[ny8][nx8] = ans[sy][sx] + 1
                            q.append((ny8, nx8))
        # return print(-1)

    H, W = map(int, input().split())
    sy, sx = map(int, input().split())
    gy, gx = map(int, input().split())
    G = []
    G.append(["@"] * (W + 2))
    G += [["@"] + list(input()) + ["@"] for _ in range(H)]
    G.append(["@"] * (W + 2))

    # visited = [[False] * (W + 2) for _ in range(H+2)]
    INF = 10 ** 7
    ans = [[INF] * (W + 2) for _ in range(H + 2)]

    bfs((sy, sx), (gy, gx))

    print(ans[gy][gx] if ans[gy][gx] < INF else '-1')


if __name__ == "__main__":
    resolve()

### FIXED CODE ###


from collections import deque
def resolve():
    H, W = map(int, input().split())
    Ch, Cw = map(lambda x: int(x) - 1, input().split())
    Dh, Dw = map(lambda x: int(x) - 1, input().split())
    maze = [input() for _ in range(H)]

    INF = 10 ** 12
    path = [[INF] * W for _ in range(H)]

    q = deque()
    path[Ch][Cw] = 0
    q.append((Ch, Cw, 0))

    walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
    warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]

    while q:
        x, y, s = q.popleft()
        for dx, dy in walk:
            nx = x + dx
            ny = y + dy
            if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s:
                path[nx][ny] = s
                q.appendleft((nx, ny, s))
        for dx, dy in warp:
            nx = x + dx
            ny = y + dy
            if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s + 1:
                path[nx][ny] = s + 1
                q.append((nx, ny, s + 1))

    ans = path[Dh][Dw] if path[Dh][Dw] < INF else -1
    print(ans)


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

def walking():
    x, k, d = map(int, input().split())
    for i in range(k):
        if x > 0:
            x = x - d
            k = k - 1
        else:
            x = x + d
            k = k -1
    return x
loc = walking()
print(abs(loc))

### FIXED CODE ###


def walking():
    x, k, d = map(int, input().split())
    x = abs(x)
    r = 0
    if x > k * d:
        return x - k * d
    else:
        r = x//d
        if (k - r)%2 == 0:
            return x - r * d
        else:
            return abs(x - (r + 1 ) * d)
    
loc = walking()
print(loc)