Harryxun/stf_run huggingface dataset:
S=list(str(input()))
s=set(S)
K=int(input())
num=0
i=0
lst=[]
def dp(i,lst):
  if i==len(S)-1:
    return lst
  if S[i]!=S[i+1]:
    return dp(i+1,lst)
  j=i+1
  while j<=len(S)-1  and S[i]==S[j]:
    j+=1
  lst.append(list(S[i:j]))
  return dp(j-1,lst)
if len(s)>=2:
  L=dp(i,lst)
  for i in range(len(L)):
    num+=(len(L[i])//2)
  if L[-1][-1]==S[0] and len(L[-1])%2==1:
    print(num+(K-1)*(num+1))
  else:
    print(num*K)
else:
  print((len(S)*K)//2)

### FIXED CODE ###

S=list(str(input()))
s=set(S)
K=int(input())
num=0
i=0
lst=[]
def dp(i,lst):
  if i==len(S)-1:
    return lst
  if S[i]!=S[i+1]:
    return dp(i+1,lst)
  j=i+1
  while j<=len(S)-1  and S[i]==S[j]:
    j+=1
  lst.append(list(S[i:j]))
  return dp(j-1,lst)

if 2<=len(s):
  L=dp(i,lst)
  for i in range(len(L)):
    num+=(len(L[i])//2)
  if num==0:
    if S[0]!=S[-1]:
      print(0)
    else:
      print(K-1)
  elif L[-1][-1]==S[0] and len(L[-1])%2==len(L[0])%2==1:
    print(num+(K-1)*(num+1))
  else:
    print(num*K)
else:
  print((len(S)*K)//2)
bingo = [ input().split() for j in range(3)]
N = int(input())
b = []
for n in range(N):
	b.append(input())
count = 0
total = 0
p = 'No'
for x in range(N):
	for i in range(3):
		for j in range(3):
			count = count + 1
			if bingo[i][j] == b[x]:
				total = total + count
	count = 0
	if total == 6 or total == 12 or total == 15 or total == 18 or total == 24 or total == 33 or total == 36 or total == 27 or total == 30 or total == 39 or total == 31 or total == 25 or total == 32:
		p = 'Yes'
		break
print(p)

### FIXED CODE ###

N = int(input())
print(int(N/2)+N%2)
def bubble_sort(num_list):
    list_b = num_list[:]
    for i in range(len(list_b)-1):
        for j in range(len(list_b)-1,i,-1):
            if list_b[j][1] < list_b[j-1][1]:
                list_b[j],list_b[j-1] = list_b[j-1],list_b[j]
    return list_b


def selection_sort(num_list):
    list_s = num_list[:]
    for i in range(len(list_s)):
        minj = i
        for j in range(i,len(list_s)):
            if list_s[minj][1] > list_s[j][1]:
                minj = j
        list_s[i],list_s[minj] = list_s[minj],list_s[i]
    return list_s


def isStable(list_x, list_y):
    leng = int(len(list_x))
    for i in range(leng-1):
        for j in range(i+1, leng):
            for x in range(leng-1):
                for y in range(x+1, leng):
                    if list_x[i][1]==list_x[j][1] and list_x[i]==list_y[y] and list_x[j] == list_y[x]:
                        return "Not stable"
    return "Stable"


qnt = int(input())
num_list = input().split()

bs = bubble_sort(num_list)
ss = selection_sort(num_list)
print(" ".join(bs))
print(isStable(num_list,bs))
print(" ".join(ss))
print(isStable(num_list,ss)

### FIXED CODE ###

def bubble_sort(num_list):
    list_b = num_list[:]
    for i in range(len(list_b)-1):
        for j in range(len(list_b)-1,i,-1):
            if list_b[j][1] < list_b[j-1][1]:
                list_b[j],list_b[j-1] = list_b[j-1],list_b[j]
    return list_b

def selection_sort(num_list):
    list_s = num_list[:]
    for i in range(len(list_s)):
        minj = i
        for j in range(i,len(list_s)):
            if list_s[minj][1] > list_s[j][1]:
                minj = j
        list_s[i],list_s[minj] = list_s[minj],list_s[i]
    return list_s

def isStable(list_x, list_y):
    leng = int(len(list_x))
    for i in range(leng-1):
        for j in range(i+1, leng):
            for x in range(leng-1):
                for y in range(x+1, leng):
                    if list_x[i][1]==list_x[j][1] and list_x[i]==list_y[y] and list_x[j] == list_y[x]:
                        return "Not stable"
    return "Stable"


qnt = int(input())
num_list = input().split()

bs = bubble_sort(num_list)
ss = selection_sort(num_list)
print(" ".join(bs))
print(isStable(num_list,bs))
print(" ".join(ss))
print(isStable(num_list,ss))
s,k=map(int,input().split())
cnt = 0
for x in range(k+1):
    for y in range(y+1):
        if 0 <= s-(x+y) <= 2500:
            cnt+=1
print(cnt)


### FIXED CODE ###

k, s = map(int, input().split())
c = 0

for i in range(k+1):
    for j in range(k+1):
        z = s - i - j
        if z >= 0 and z <= k:
            c += 1
print(c)
N = int(input())
Inputs = [tuple(map(int, input().split())) for _ in range(N)]

f = 0
for cx in range(101):
    for cy in range(101):
        n = 0
        while(n < N-1):
            x1, y1, h1 = Inputs[n]
            H1 = h1 + abs(x1-cx) + abs(y1-cy)
            x2, y2, h2 = Inputs[n+1]
            H2 = h2 + abs(x2-cx) + abs(y2-cy)
            if H1 != H2:
                f = 0
                break
            else:
                f = 1
                n += 1
        if f:
            Cx = cx
            Cy = cy
            H = H1
            
                
print(Cx, Cy, H)

### FIXED CODE ###

N = int(input())
coordinate = []
ans = -1
for _ in range(N):
    x, y, h = map(int, input().split())
    if h == 0:
        continue
    coordinate.append([x, y, h])
N = len(coordinate)
for cx in range(101):
    for cy in range(101):
        x1, y1, h1 = coordinate[0]
        H1 = h1 + abs(cx-x1) + abs(cy-y1)
        f = 1
        if N == 1:
            f = 2
            Cx = x1
            Cy = y1
            ans = h1
            break
        for n in range(1, N):
            x, y, h = coordinate[n]
            H = h + abs(cx-x) + abs(cy-y)
            if H == H1:
                f *= 1
            else:
                f *= 0
            if f and n == N-1:
                break
        if f == 1:
            Cx = cx
            Cy = cy
            ans = H1
            break
    if f:
        break
        
print(Cx, Cy, ans)
import sys, os, time, math
import numpy as np
import pandas as pd

 
# print("Start")
N = list(map(str, input().split()))
N = N[0]
# N = np.array(list(map(int, input().split())))
# print(N, K)
# print(N)
 
if (N[0] == "7") or (N[1] == "7") or (N[2] == "7"):
    print("Yes")
else:
    print("No")

### FIXED CODE ###

N = input()
# N = N[0]
# N = np.array(list(map(int, input().split())))
# print(N, K)
# print(N)
 
if (N[0] == "7") or (N[1] == "7") or (N[2] == "7"):
    print("Yes")
else:
    print("No")
N, T = map(int,input().split())
ans = float("inf")

for i in range(N):
    c,t = map(int,input(),split())
    if t <= T:
        ans = min(ans,c)

if ans == float("inf"):
    print("TLE")
else:
    print(ans)


### FIXED CODE ###

N, T = map(int,input().split())
ans = float("inf")

for i in range(N):
    c,t = map(int,input().split())
    if t <= T:
        ans = min(ans,c)

if ans == float("inf"):
    print("TLE")
else:
    print(ans)
a,b = [input() for i in range(2)]

length = abs(len(a)-len(b))

for i in range(length+1):
    right_length = length - i
    temp = '?'*i+b+'?'*right_length
    
    #判定
    judge = 0
    for j in range(len(a)):
        if a[j] == temp[j] or temp[j] == '?':
            judge += 1
        elif temp[j] != '?' and a[j] == '?':
            judge += 1
    if judge == len(a):
        S = ''
        for k in range(len(temp)):
            if temp[k] == '?':
                S += a[k]
            else:
                S += temp[k]
        
        print(S.replace('?','a'))
        exit()

    else:
        continue

print('UNRESTORABLE')

### FIXED CODE ###

a = input()
b = input()

length = len(a) - len(b) + 1

ans = []
for i in range(length):
    A = list('?'*i+b+'?'*(length-i-1))
    flag = True
    for j in range(len(a)):
        if a[j] == '?' or a[j] == A[j]:
            pass
        elif a[j] != '?' and A[j] == '?':
            A[j] = a[j]
        else:
            flag = False
    if flag:
        ans.append(''.join(A).replace('?','a'))

if ans:
    ans.sort()
    print(ans[0])
else:
    print('UNRESTORABLE')
N, K = list(map(int,input().split()))
S = input()

n = 1
c = []
if S[0]=='0': c.append(0)
for i in range(1,N):
    if S[i]!=S[i-1]:
    c.append(n)
        n=1
    else:
        n+=1
c.append(n)
if S[-1]=='0': c.append(0)

t = sum(c[:2*K+1])
m = t
for i in range(2*K+1, len(c), 2):
    t += c[i] + c[i+1] - c[i-(2*K+1)] - c[i+1-(2*K+1)]
    m = max(m,t)

print(m)

### FIXED CODE ###

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

n = 1
c = []
if S[0]=='0': c.append(0)
for i in range(1,N):
    if S[i]!=S[i-1]:
        c.append(n)
        n=1
    else:
        n+=1
c.append(n)
if S[-1]=='0': c.append(0)

t = sum(c[:2*K+1])
m = t
for i in range(2*K+1, len(c), 2):
    t += c[i] + c[i+1] - c[i-(2*K+1)] - c[i+1-(2*K+1)]
    m = max(m,t)

print(m)
N = int(input())
A = [int(x) for x in input().split()]
Q = int(input())
B = [[int(i) for i in input().split()] for Q in range(Q)]

p = [0]*100000
for i in range(N):
    p[A[i]] += 1

cnt = 0
for j in range(100000):
    cnt += p[j]*j

for i in range(Q):
    cnt = cnt + (B[i][1]- B[i][0]) * p[B[i][0]]
    
    p[B[i][1]] += p[B[i][0]]
    p[B[i][0]] = 0

    print(cnt)


### FIXED CODE ###

N = int(input())
A = [int(x) for x in input().split()]
Q = int(input())
B = [[int(i) for i in input().split()] for Q in range(Q)]

p = [0]*100001
for i in range(N):
    p[A[i]] += 1

cnt = 0
for j in range(100001):
    cnt += p[j]*j

for i in range(Q):
    cnt = cnt + (B[i][1]- B[i][0]) * p[B[i][0]]

    p[B[i][1]] += p[B[i][0]]
    p[B[i][0]] = 0

    print(cnt)
n,m=map(int,input().split())

if n>=3 and m>=3:
  a=n*m
  b=n*2+m*2-
  ans=a-b
elif n==1 and b==1:
  ans=1
elif n==1 or m==1:
  a=n*m
  b=2
  ans=a-b
elif n==2 or m==2:
  ans=0
  
print(ans)


### FIXED CODE ###

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

if n>=3 and m>=3:
  a=n*m
  b=n*2+m*2-4
  ans=a-b
elif n==1 and m==1:
  ans=1
elif n==1 or m==1:
  a=n*m
  b=2
  ans=a-b
elif n==2 or m==2:
  ans=0
  
print(ans)
from collections import deque

H, W, N = map(int, input().split())
field = [list(input()) for i in range(H)]
us = [str(i) for i in range(N, 0, -1)]
queue = deque([])
dx = [1,0,-1,0]
dy = [0,1,0,-1]

def search():
	global flag
	global us
	global count
	global queue

	while queue:
		x, y, c = queue.popleft()
		
		if (field[y][x] == us[-1]):
			flag = True
			if (us[-1] == str(N)):
				print(c)
				exit()
			us.pop()
			queue.clear()
			queue.append([x, y, c])
			return
	
		for q in range(4):
			nx = x + dx[q]
			ny = y + dy[q]
			if (nx >= 0 and nx <= W-1) and (ny >= 0 and ny <= H-1) and ([nx,ny] not in queue) and (field[ny][nx] != 'X') and (field[ny][nx] != 'S'):
				queue.append([nx, ny, c+1])


bf = False
for i in range(H):
	for j in range(W):
		if field[i][j] == 'S':
			c = 0
			queue.append([j, i, c])
			bf = True
			break
	if (bf):
		break

while 1:
	flag = False
	search()


### FIXED CODE ###

#import time, sys#
from collections import deque

H, W, N = map(int, input().split())
field = [list(input()) for i in range(H)]
'''
20 30 9
.......X..8.XXXX.XX..XX.X.XX..
X.XX....X.XX..X.X.X....XXXX..X
..X.X..XX..X.....XX.X..X.XX...
....X.X.X.XXX.X..X..X.X..XX.X.
..XXX.XX...X.X....X.X..X..X...
..X...........X.X...X.1.XX...X
.X.X....X..XX..XX......9.X...4
..X....X........X......X......
....XXX.X...XX.X.....X.X..X.X.
..S..XXX..X....X.X.......X..X.
.5...XX..X.X..X....X...XXX....
..X...X.X....X....X..X.2X.....
XXXXXXXX.X.XX..XX..XX.......X.
.....X...........3..XX.XXX.X.X
..X.....X..X..XX.XX..X.X...XX.
...X..X.XXX.XX......X...X..XXX
.X.XX.X.........X.X...X...X..X
..X...X..X..XX..XXX..X.XX...X.
X....X.X....X...X.X..XX.XX..X.
...X6X..X........X.X.....7.X..
'''

#input = input().split('\n')#
#H, W, N = map(int, input.pop(0).split())#
#field = [line for line in input]#
node_posi = [0 for i in range(N+1)]

#s1 = time.time()#
nodes = 'S123456789'
for i in range(H):
	for j in range(W):
		if field[i][j] in nodes:
			node_posi[nodes.index(field[i][j])] = [j, i]
#e1 = time.time()#
#print("b:{}".format(e1-s1))#

cost = 0
#count = 1#
for i in range(len(node_posi)-1):
	#s2 = time.time()#
	searched = [[-1]*W for i in range(H)]
	start, goal = node_posi[i], node_posi[i+1]
	Q = deque([start])
	searched[start[1]][start[0]] = 0
	goal_flag = False
	
	while Q and not goal_flag:
		x, y = Q.popleft()
		goal_flag = False

		for q in range(4):
			nx = x + [1,0,-1,0][q]
			ny = y + [0,1,0,-1][q]
			
			if nx >= 0 and nx < W and ny >= 0 and ny < H:
				if searched[ny][nx] == -1 and field[ny][nx] != 'X':
					Q.append([nx, ny])
					searched[ny][nx] = searched[y][x] + 1
					if ([nx, ny] == goal):
						cost += searched[ny][nx]
						goal_flag = True
						break

			#s = "\n".join(["".join(map(lambda x: str(x)[:1], j)) for j in searched])#
			#sys.stdout.write("\r{}".format(s))#
			#sys.stdout.flush()#
	
	#e2 = time.time()#
	#print("{}:{}".format(count, e2-s2))#
	#count += 1#
print(cost)
n, q = map(int , input().split())
queue = []
for _ in range(n):
    line = input().split()
    queue.append([line[0], int(line[1])])

class my_queue:
    def __init__(self, queue):
        self.queue = queue
    def enqueue(self, item):
        self.queue = self.queue + [item]
        self.queue.append(item)
    def dequeue(self):
        if len(self.queue) != 0:
            item = self.queue[0]
            self.queue = self.queue[1:]
        else :
            item = None
        return item


time = 0
finish_task = []

while(True):
    item = queue.pop()
    if item == None:
        break
    elif item[1] <= q:
        time += item[1]
        finish_task.append([item[0], time])
    else :
        time += q
        queue.append([item[0], item[1] - q])

for item in finish_task:
    print(item[0], item[1])

### FIXED CODE ###

n, q = map(int , input().split())
queue = []
for _ in range(n):
    line = input().split()
    queue.append([line[0], int(line[1])])

class my_queue:
    def __init__(self, queue):
        self.queue = queue
    def enqueue(self, item):
        self.queue = self.queue + [item]
        self.queue.append(item)
    def dequeue(self):
        if len(self.queue) != 0:
            item = self.queue[0]
            self.queue = self.queue[1:]
        else :
            item = None
        return item


time = 0
finish_task = []

while(len(queue) != 0):
    item = queue.pop(0)
    if item == None:
        break
    elif item[1] <= q:
        time += item[1]
        finish_task.append([item[0], time])
    else :
        time += q
        queue.append([item[0], item[1] - q])

for item in finish_task:
    print(item[0], item[1])
N = input()
ans = 1
A = list(map(int, input().split()))
A.sort(reverse=True)
if A[N-1] == 0:
  ans = 0
else:
  for a in A:
    ans *= a
    if ans > 10 ** 18:
      ans = -1
      break
print(ans)

### FIXED CODE ###

N = int(input())
ans = 1
A = list(map(int, input().split()))
A.sort(reverse=True)
if A[N-1] == 0:
  ans = 0
else:
  for a in A:
    ans *= a
    if ans > 10 ** 18:
      ans = -1
      break
print(ans)
n = input()
a = list(map(int, input()))
count = 0
while 1:
  b =[int(i/2) for i in a] 
  if a == b:
    count+=1
    a = b
  else:
    print(count)
    break
return 0


### FIXED CODE ###

n = input()
a = list(map(int, input().split()))
count = 0
while 1:
  if [int(i/2) for i in a] == [round(i/2, 1) for i in a]:
    count+=1
    a = [int(i/2) for i in a]
  else:
    print(count)
    break
def main():
    c=[[0]*3001for _ in range(3001)]
    h,w,k=map(int,input().split())
    for i in range(k):
        y,x,v=map(int,input().split())
        c[y][x]=v
    dp=[[0]*(w+1)for _ in range(h+1)]
    for i in range(1,h+1):
        x=y=z=p=0
        for j in range(1,w+1):
            v=c[i][j]
            if v>x:x,y,z=v,x,y
            elif v>y:y,z=v,y
            elif v>z:z=v
            if x+y+z+p<=dp[i-1][j]+v:
                x,y,z=v,0,0
                p=dp[i-1][j]
            dp[i][j]=x+y+z+p
    a=dp[h][w]
    dp=[[[0]*(w+1)for _ in range(h+1)]for _ in range(4)]
    for i in range(1,h+1):
        for j in range(1,w+1):
            x=max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])
            for k in range(4):
                if k:dp[k][i][j]=max(dp[k][i][j-1],dp[k-1][i][j-1]+c[i][j])
                else:dp[k][i][j]=max(dp[k][i][j-1],x)
            dp[1][i][j]=max(dp[1][i][j],x+c[i][j])
    if a<max(dp[0][h][w],dp[1][h][w],dp[2][h][w],dp[3][h][w]):1/0
main()

### FIXED CODE ###

c=[[0]*3001for _ in range(3001)]
dp=[[[0]*3001for _ in range(3001)]for _ in range(4)]
h,w,k=map(int,input().split())
for i in range(k):
    y,x,v=map(int,input().split())
    c[y][x]=v
for i in range(1,h+1):
    for j in range(1,w+1):
        x=max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])
        for k in range(4):
            if k:dp[k][i][j]=max(dp[k][i][j-1],dp[k-1][i][j-1]+c[i][j])
            else:dp[k][i][j]=max(dp[k][i][j-1],x)
        dp[1][i][j]=max(dp[1][i][j],x+c[i][j])
print(max(dp[0][h][w],dp[1][h][w],dp[2][h][w],dp[3][h][w]))
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if a>b:
    x=a-v+t
    y=b-w*t
else:
    x=a+v*t
    y=b+w*t
    if abs(x)>=abs(y) or abs(x)=0:
        print('YES')
    else:
        print('NO')

### FIXED CODE ###


a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if a>b:
    x=a-v*t
    y=b-w*t
    if x<=y:
        print('YES')
    else:
        print('NO')
else:
    x=a+v*t
    y=b+w*t
    if x>=y:
        print('YES')
    else:
        print('NO')
# -*- coding: utf-8 -*-
"""
B - Frog 2
https://atcoder.jp/contests/dp/tasks/dp_b
AC
"""
import sys
from sys import stdin


def solve(ashiba, N, K):
    dp = [float('inf')] * N
    dp[0] = 0
    for i in range(1, len(ashiba)):
        paths = [dp[j]+abs(ashiba[j]-ashiba[i]) for j in range(max(0, i-K), i)]
        dp[i] = min(paths)
    return dp[-1]


def main(args):
    N, K = map(int, input().split())
    ashiba = [int(i) for i in input().split()]
    ans = solve(ashiba, N, K)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
https://atcoder.jp/contests/dp/tasks/dp_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(N, ashiba):
    dp = [0] * N
    for i in range(1, N):
        dp[i] = min(dp[i-1] + abs(ashiba[i] - ashiba[i-1]), dp[i-2] + abs(ashiba[i] - ashiba[max(i-2, 0)]))
    return dp[-1]


def main(args):
    N = int(input())
    ashiba = [int(a) for a in input().split()]
    ans = solve(N, ashiba)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
S = list(input())
K = int(input())

if S[0] == 1:
    if K >= 2:
        print(S[1])
    else:
        print(1)
else:
    print(S[1])

### FIXED CODE ###

S = input()
K = int(input())

for i in range(K):
    if S[i] != "1":
        print(S[i])
        break
else:
    print(1)
import fractions as math

A,B = map(int,input().split())
G = math.gcd(A,B)
count = 0
p = 1
for i in range(1,math.ceil(math.sqrt(G))+1,1):
    if G%i ==0:
        if math.gcd(p,i)==1:
            count +=1
            p = p*i
print(count)

### FIXED CODE ###

import math

A,B = map(int,input().split())
G = math.gcd(A,B)

N = G
#素因数分解
sep = []
for i in range(2,int(math.sqrt(N))+2,1):
    if N % i ==0:
        count = 0
        while N % i == 0:
            N = N//i
            count += 1
        sep.append([i,count])
if N != 1:
    sep.append([N,1])

print(len(sep)+1)
import sys
sys.setrecursionlimit(10 ** 6)

n = int(input())
x = input()
z = '1' * n
o = '0' * n
X = int(x, 2)

if (z == x):
  u = n - 1
  d = n - 1
elif (o == x):
  u = 1
  d = 1
else:
  tmp = len(list(filter(lambda x: x == '1', x)))
  u = tmp + 1
  d = tmp - 1


def popcount(i):
  return i % len(list(filter(lambda x: x == '1', format(i, 'b'))))


def solve(i, count):
  if (i <= 2 * 10**5 and ans[i] != 0):
    return count + ans[i]
  elif (i == 0):
    return count
  else:
    return solve(popcount(i), count + 1)


def solve2(i, div):
  if (i <= 2 * 10**5):
    return ans[i]
  else:
    return ans[i % div] + 1


ans = [0] * (2 * 10 ** 5 + 4)
_u = (2 * 10 ** 5) // u
U = X % u + (u * _u) + u
_d = (2 * 10 ** 5) // d
D = X % d + (d * _d) * 2 + d * 2
Us = [0] * (2 * 10 ** 5)
Ds = [0] * (2 * 10 ** 5)
for i in range(1, 2 * 10 ** 5 + 4):
  ans[i] = solve(i, 0)
  
Us[0] = 1 % u
Ds[0] = 1 % d
for i in range(1, 2 * 10 ** 5):
  Us[i] = (Us[i-1] * 2) % u
  Ds[i] = (Ds[i-1] * 2) % d

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

n = int(input())
x = input()
z = '1' * n
o = '0' * n
X = int(x, 2)

if (n == 1 and x == '1'):
  print(0)
  exit()

if (z == x):
  u = n - 1
  d = n - 1
elif (o == x):
  u = 1
  d = 1
else:
  tmp = len(list(filter(lambda x: x == '1', x)))
  u = tmp + 1
  d = tmp - 1


def popcount(i):
  return i % len(list(filter(lambda x: x == '1', format(i, 'b'))))


def solve(i, count):
  if (i <= 2 * 10**5 and ans[i] != 0):
    return count + ans[i]
  elif (i == 0):
    return count
  else:
    return solve(popcount(i), count + 1)


def solve2(i, div):
  if (i <= 2 * 10**5):
    return ans[i]
  else:
    return ans[i % div] + 1


ans = [0] * (2 * 10 ** 5 + 4)
_u = (2 * 10 ** 5) // u
U = X % u + (u * _u) + u
if(d != 0):
  _d = (2 * 10 ** 5) // d
  D = X % d + (d * _d) * 2 + d * 2
Us = [0] * (2 * 10 ** 5)
Ds = [0] * (2 * 10 ** 5)
for i in range(1, 2 * 10 ** 5 + 4):
  ans[i] = solve(i, 0)
Us[0] = 1 % u
if(d != 0):
  Ds[0] = 1 % d
for i in range(1, 2 * 10 ** 5):
  Us[i] = (Us[i - 1] * 2) % u
  if(d != 0):
    Ds[i] = (Ds[i-1] * 2) % d

for i in range(n):
  if(x[i] == '0'):
    print(solve2(U + Us[n-i-1], u))
  else:
    if (d == 0):
      print(0)
    else:
      print(solve2(D - Ds[n-i-1], d))
import sys
n=int(input())
while(1):
    if(n%4=0):
        print("Yes")
        sys.exit()
    n-=7
    if(n<=3):
        break
print("No")

### FIXED CODE ###

import sys
n=int(input())
if(n%7==0):
  print("Yes")
  sys.exit(0)
while(1):
    if(n%4==0):
        print("Yes")
        sys.exit(0)
    n-=7
    if(n<=3):
        break
print("No")
N = int(input())
S, T = map(str, input().split())
T = str(input())

ST = ''

for i in range(N):
  ST += S[i]
  ST += T[i]

print(ST)

### FIXED CODE ###

N = int(input())
S, T = map(str, input().split())

ST = ''

for i in range(N):
  ST += S[i]
  ST += T[i]

print(ST)
l=list(map(int,input().split()))
ans=min(l[1],l[3])-max(l[0],l[2])
print(ans if ans>0 else 0)

### FIXED CODE ###

i=input()
print("Yes" if i[0]==i[2] else "No")
n,k = map(int, input().split())
s = []
ans = 0
rangecounter = 0
for i in range(k-1):
  d = int(input())
  rangecounter += d
  for j in range(d):
    s.append(input().split())
for i in range(1,rangecounter):
  if s.count(i) == 0:
    ans += 1
print(ans)

### FIXED CODE ###

n , k = map(int,input().split())
ans = [0] * n
for i in range(k):
  d = int(input())
  for j in list(map(int,input().split())):
    ans[j-1] = 1
print(ans.count(0))
n, k = map(int, input().split())
x = list(map(int, input().split()))

for i in range(n-k+1):
    xtmp = x[i:i+k]
    print(i, xtmp)

    if i==0:
        MIN = abs(xtmp[0])+2*abs(xtmp[-1])

    MIN = min(MIN, abs(xtmp[0]-xtmp[-1]) + abs(xtmp[0]))
    MIN = min(MIN, abs(xtmp[0]-xtmp[-1]) + abs(xtmp[-1]))

    i+=1

print(MIN)

### FIXED CODE ###

# -*- coding: utf-8 -*-

n, k = map(int, input().split())
X = list(map(int, input().split()))
ans = 10**10
for i in range(n-k+1):
    left = X[i]
    right = X[i+k-1]
    ans = min(ans, abs(left)+abs(left-right), abs(right)+abs(right-left))
print(ans)
import sys
input = sys.stdin.readline

x, k, d = map(int, input().split())
dp = [None]*(1000000)
dp[0] = x

for i in range(1, k+1):
  x0, x1 = x+d, x-d
  if abs(x0) < abs(x1):
    x = x0
    dp[i] = x0
  else:
    x = x1
    dp[i] = x1
  if x == dp[i-2]:
    if i%2 != k%2:
      x = dp[i-1]
    break

print(abs(x))

### FIXED CODE ###

import sys
input = sys.stdin.readline

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

if k < tmp:
  result = abs(abs(x) - d*k)
elif tmp%2 == k%2:
  result = abs(abs(x) - d*tmp)
else:
  a = result = abs(abs(x) - d*tmp)
  result = abs(abs(a) - d)

print(result)