Harryxun/stf_run huggingface dataset:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	N, K = map(int, input().split(" "))
	A = input().split(" ")
	A = [int(s) for s in A]
	
	DP = [100000000000000000000000000000000 for _ in range(N)]
	DP[0] = 0
	
	for i, val in enumerate(A):
		if i == 0:
			continue
		tmp = 100000000000000000000000000000000
		
		for j in range(K):
			index = j+1
			if i >= index:
				tmp1 = DP[i-index] + abs(A[i-index] - val)
				tmp = min(tmp, tmp1)
			else:
				break
		DP[i] = min(DP[i], tmp)
		
	#print(DP)
	print(DP[N-1])
	
	
if __name__ == "__main__":
	main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys

def main():
	N, K = map(int, input().split(" "))
	H = input().split(" ")
	H = [int(s) for s in H]
	
	DP = [-1 for _ in range(N)]
	DP[0] = 0
	
	for i in range(1, len(H)):
		paths = [DP[j] + abs(H[j] - H[i]) for j in range(max(0, i-K), i)]
		DP[i] = min(paths)
		
	print(DP[N-1])
		
if __name__ == "__main__":
	main()
n=int(input())
a=list(map(int,input().split()))
b=0
for i in range(n):
    if a[i]>=max(a[0:i]):
        b+=1
print(b)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=1
for i in range(n-1):
    if a[i+1]>=max(a[0:i+1]):
        b+=1
print(b)
times=int(input())
answers=[]
for i in range(times):
    hen=input().split()
    for j in range(times):
        hen[j]=int(hen[j])
    for j in range(times-1):
        for k in range(times-1):
            if hen[j]>hen[j+1]:
                num=hen[j]
                hen[j]=hen[j+1]
                hen[j+1]=num
    if hen[0]*hen[0]+hen[1]*hen[1]==hen[2]*hen[2]:
        answers.append('Yes')
    else:
        answers.append('No')

for i in range(len(answers)):
    print(answers[i])

### FIXED CODE ###

[print("YES" if x[0] + x[1] == x[2] else "NO") for x in [sorted([x * x for x in [int(i) for i in input().split(" ")]]) for _ in range(int(input()))]]
hoge_a=input()
hoge_b=input()
hoge_c=input()
tugi="A"
while 1:
  if(tugi=="A"):
    if(hoge_a[0]=="a"):
      tugi="A"
    if(hoge_a[0]=="b"):
      tugi="B"
    if(hoge_a[0]=="c"):
      tugi="C"
    hoge_a=hoge_a[1:]
      
  if(tugi=="B"):
    if(hoge_b[0]=="a"):
      tugi="A"
    if(hoge_b[0]=="b"):
      tugi="B"
    if(hoge_b[0]=="c"):
      tugi="C"
    hoge_b=hoge_b[1:]
      
  if(tugi=="C"):
    if(hoge_c[0]=="a"):
      tugi="A"
    if(hoge_c[0]=="b"):
      tugi="B"
    if(hoge_c[0]=="c"):
      tugi="C"
    hoge_c=hoge_c[1:]
    
  if(len(hoge_a)==0 and tugi=="A"):
    print(tugi)
    break
    
  if(len(hoge_b)==0 and tugi=="B"):
    print(tugi)
    break
    
  if(len(hoge_c)==0 and tugi=="C"):
    print(tugi)
    break

### FIXED CODE ###

hoa=list(input())
hob=list(input())
hoc=list(input())
f="A"

while 1:
  if(f=="A" and len(hoa)==0):
    print(f)
    break
  elif(f=="B" and len(hob)==0):
    print(f)
    break
  elif(f=="C" and len(hoc)==0):
    print(f)
    break
  elif(f=="A"):
    if(hoa[0]=="a"):
      f="A"
      hoa=hoa[1:]
    elif(hoa[0]=="b"):
      f="B"
      hoa=hoa[1:]
    elif(hoa[0]=="c"):
      f="C"
      hoa=hoa[1:]
  elif(f=="B"):
    if(hob[0]=="a"):
      f="A"
      hob=hob[1:]
    elif(hob[0]=="b"):
      f="B"
      hob=hob[1:]
    elif(hob[0]=="c"):
      f="C"
      hob=hob[1:]
  elif(f=="C"):
    if(hoc[0]=="a"):
      f="A"
      hoc=hoc[1:]
    elif(hoc[0]=="b"):
      f="B"
      hoc=hoc[1:]
    elif(hoc[0]=="c"):
      f="C"
      hoc=hoc[1:]
n, m, x = map(int, input().split())

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

import bisect

l = bisect.bisect_left(a, x)

print(min(l, m-l))


### FIXED CODE ###

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

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

import bisect

l = bisect.bisect_left(a, x)

print(min(l, m-l))
A,B,T = input().split()
A = int(A)
B = int(B)
T = int(T)
for X in range(1,20):
  if A*X <= T + 0.5:
    s = B*X
  if A*X >=T + 0.5:
    break
print(s)



### FIXED CODE ###

A,B,T = input().split()
A = int(A)
B = int(B)
T = int(T)
s = 0
for X in range(1,21):
  if A*X <= T + 0.5:
    s = B*X
  if A*X >=T + 0.5:
    break
print(s)
n = int(input())
a = list(map(int,input().split()))
dp = [[0 for i in range(3)] for j in range(n+1)]
for i in range(1,n+1):
  ai = a[i-1]
  dp[i] = dp[i-1][:]
  if i%2:
    dp[i][0] += +ai
    dp[i][1] = max(dp[i-1][0],dp[i-1][1])
  if i%2 == 0:
    dp[i][1] += ai
    dp[i][2] = max(dp[i-1][1],dp[i-1][2])
  if i >= 3 and i%2:
    dp[i][2] += ai
if n%2 == 0:
  print(max(dp[-1][0],dp[-1][1]))
else:
  print(max(dp[-1][1],dp[-1][2]))

### FIXED CODE ###

if input().count("7"):
  print("Yes")
else:
  print("No")
lines = input().split()
K, N = map(int, lines[0].strip().split())
As = map(int, lines[1].strip().split())
dists = []
for base, switch in zip(As[:-1], As[1:]):
    dists.append(switch - base)
dists.append(As[0]+(K-As[-1]))
print(K - max(dists))


### FIXED CODE ###

K, N = list(map(int, input().split()))
As = list(map(int, input().split()))
dists = []
for base, switch in zip(As[:-1], As[1:]):
    dists.append(switch - base)
dists.append(As[0]+(K-As[-1]))
print(K - max(dists))
from decimal import Decimal
a,b = input().split()
c = (int(a)*(decimal(b)*1000000))/1000000
print(int(c//1)

### FIXED CODE ###

from decimal import Decimal
a,b = input().split()
c = int(a)*Decimal(b)
print(int(c))
if a+b<c:
  if (4*a*b)<(pow(c-a-b,2)):
    print("Yes")
  else:
    print("No")
else:
  print("No")

### FIXED CODE ###

a,b,c=list(map(int, input().split()))
if a+b<c:
  if (4*a*b)<(pow(c-a-b,2)):
    print("Yes")
  else:
    print("No")
else:
  print("No")
import  math
lis = []

N,M = [int(i) for i in input().split()]
M_ = M
i = 2
for i in range(1,int(math.sqrt(M))):
    if M % i == 0:
        lis.append(i)
        lis.append(M//i)

lis.sort()
ret = 0
for i in lis:
    if i > N:
        break
    ret = i

print(M_//ret )


### FIXED CODE ###

import  math
lis = []

N,M = [int(i) for i in input().split()]

for i in range(1,int(math.sqrt(M))):
    if M % i == 0:
        lis.append(i)
        lis.append(M//i)


lis.sort()
i =1
for i in lis:
    if i >= N:
        break

print(M//i )
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

H, W, K = IR(3)
c = SRL(H)

ans=0
 
for i in range(2**H):
    seen=[]
    for n in range(H):
        if ((i>>n) & 1):
            seen.append(c[n])
    for j in range(2**W):
        count=0
        for m in range(W):
            if ((j>>m) & 1):
                for l in range(len(seen)):
                    if seen[l][m]=="#":
                        count+=1
]
        if count==K:
            ans+=1
print(ans)

### FIXED CODE ###

import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

H, W, K = LI()
c = SRL(H)

ans=0
 
for i in range(2**H):
    seen=[]
    for n in range(H):
        if ((i>>n) & 1):
            seen.append(c[n])
    for j in range(2**W):
        count=0
        for m in range(W):
            if ((j>>m) & 1):
                for l in range(len(seen)):
                    if seen[l][m]=="#":
                        count+=1

        if count==K:
            ans+=1
print(ans)
_ = int(input())
A = list(map(int, input().split()))


def solve(i, s, k, sign):
    if i >= len(A):
        return k

    if sign * (s + A[i]) > 0:
        return solve(i + 1, s + A[i], k, sign * -1)
    else:
        return solve(i + 1, sign, k + abs(s + A[i]) + 1, sign * -1)


print(min(solve(0, 0, 0, 1), solve(0, 0, 0, -1)))


### FIXED CODE ###

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

ret = float('inf')

sign = 1
s = 0
k = 0
for a in A:
    if sign * (s + a) > 0:
        s += a
    else:
        k += abs(s + a) + 1
        s = sign
    sign *= -1
ret = min(ret, k)

sign = -1
s = 0
k = 0
for a in A:
    if sign * (s + a) > 0:
        s += a
    else:
        k += abs(s + a) + 1
        s = sign
    sign *= -1

ret = min(ret, k)


print(ret)
n,k=map(int,input().split())
l=list(map(int,input().split()))
sl=sorted(l)
ten=0
for i in range(n):
    for j in range(n):
        if l[i]>l[j]and i<j:ten+=1
pre=sl[0]
jiten=0
c=0
for i,x in enumerate(sl):
    if x==pre:jiten+=c
    else:
        jiten+=i
        c=i
        pre=x

print(ten*k+jiten*(k*(k-1))//2)n,k=map(int,input().split())
l=list(map(int,input().split()))
sl=sorted(l)
ten=0
for i in range(n):
    for j in range(n):
        if l[i]>l[j]and i<j:ten+=1
pre=sl[0]
jiten=0
c=0
for i,x in enumerate(sl):
    if x==pre:jiten+=c
    else:
        jiten+=i
        c=i
        pre=x

print(ten*k+jiten*(k*(k-1))//2)

### FIXED CODE ###

n,k=map(int,input().split())
l=list(map(int,input().split()))
sl=sorted(l)
ten=0
for i in range(n):
    for j in range(n):
        if l[i]>l[j]and i<j:ten+=1
pre=sl[0]
jiten=0
c=0
for i,x in enumerate(sl):
    if x==pre:jiten+=c
    else:
        jiten+=i
        c=i
        pre=x

print((ten*k+jiten*(k*(k-1))//2)%(10**9+7))
if S == 'Sunny':
    print('Cloudy')
elif S == 'Cloudy':
    print('Rainy')
else:
    print('Sunny')

### FIXED CODE ###

S = input()

if S == 'Sunny':
    print('Cloudy')
elif S == 'Cloudy':
    print('Rainy')
else:
    print('Sunny')
import math
N = int(input())

ans = 0
for m in range(1, int(math.sqrt(N)) + 2):
    if (N - m) % m == 0:
        t = (N - m) // m
        a = N // t
        b = N % t
        if a == b:
            ans += t
print(ans)


### FIXED CODE ###

import math
N = int(input())

ans = 0
for m in range(1, int(math.sqrt(N))+2):
    if N % m == 0:
        t = N//m - 1
        if t <= 0:
            continue
        a = N//t
        b = N % t
        if a == b:
            ans += t
print(ans)
import numpy as np
N=int(input())
A=np.zeros(N+1)
a=list(map(int,input().split()))
for i in range(N+1):
  A[i]=a[i]
v=0
j=0
k=0
B=np.zeros(N+1)
for i in range(N+1):
  B[i]=N-i
for i in reversed(range(0, N+1)):
  j+=A[i]/(2**i)
  if i==N:
    k=A[i]
  else:
    k=min(k+A[i],2**i-np.sum(A[0:i]*(2**(B[0:i]-(N-i)))))
  v+=k

if j>1:
  print(-1)
else:
  print(int(v))

### FIXED CODE ###

import numpy as np
N,M,X=map(int,input().split())
C=np.zeros(N,dtype=int)
A=np.zeros([N,M],dtype=int)
for i in range(N):
    T=list(map(int,input().split()))
    C[i]=T[0]
    for j in range(M):
        A[i,j]=T[j+1]
a=np.zeros(N,dtype=int)
ans=-1
while a.all()!=1:
  if ((a@A)>=X).all():
    if ans==-1:
        ans=a@(C.T)
    elif a@(C.T)<ans:
        ans=a@(C.T)
  for i in range(N):
    if a[N-i-1]==0:
      a[N-i-1]=1
      break
    else:
      a[N-i-1]=0

if ((a@A)>=X).all():
  if ans==-1:
      ans=a@(C.T)
  elif a@(C.T)<ans:
      ans=a@(C.T)

print(ans)
import sys

sys.setrecursionlimit(100000)
N = int(raw_input())
act = [map(int, raw_input().split()) for _ in range(N)]
memo = [[-1]*3 for _ in range(N)]

def happy(n, i):
  if memo[n][i] >= 0:
    return memo[n][i]
  if n == 0:
    h = act[n][i]
  else:
    h = -1
    for j in range(3):
      if j == i:
        continue
      c = happy(n-1,j)+act[n][i]
      h = h if h > c else c
  memo[n][i] = h
  return h
print max(happy(N-1,0),happy(N-1,1),happy(N-1,2))



### FIXED CODE ###


import sys

sys.setrecursionlimit(100000)
N = int(raw_input())
act = [map(int, raw_input().split()) for _ in range(N)]
memo = [[-1]*3 for _ in range(N)]

def happy(n, i):
  if memo[n][i] >= 0:
    return memo[n][i]
  if n == 0:
    h = act[n][i]
  else:
    h = -1
    for j in range(3):
      if j == i:
        continue
      c = happy(n-1,j)+act[n][i]
      h = h if h > c else c
  memo[n][i] = h
  return h
print max(happy(N-1,0),happy(N-1,1),happy(N-1,2))
w = input()

for i in w:
    if w.count(i)%2! = 0:
        print("No")
        	break
    else:
        print("Yes")



### FIXED CODE ###

w = input()

ans = "No"
for i in w:
    if w.count(i)%2!= 0:
        break
else:
    ans = "Yes"
print(ans)
import sys
input = sys.stdin.readline

H, W = [int(x) for x in input().split()]
a = []
for _ in range(H):
    a.append([int(x) for x in input().split()])

place = [0, 0]
ans = []
flag = 1

for i in range(H * W - 1):
    x, y = place
    if flag:
        new_x, new_y = x, y + 1
        if new_y >= W:
            new_x, new_y = x + 1, y
            flag = 0
    else:
        new_x, new_y = x, y - 1
        if new_x < 0:
            new_x, new_y = x + 1, y
            flag = 1
    if a[x][y] % 2 == 1:
        ans.append([x + 1, y + 1, new_x + 1, new_y + 1])
        a[new_x][new_y] += 1
    place = [new_x, new_y]

for j in ans:
    print(*j)

### FIXED CODE ###

import sys
input = sys.stdin.readline

H, W = [int(x) for x in input().split()]
a = []
for _ in range(H):
    a.append([int(x) for x in input().split()])

place = [0, 0]
ans = []
flag = 1

for i in range(H * W - 1):
    x, y = place
    if flag:
        new_x, new_y = x, y + 1
        if new_y >= W:
            new_x, new_y = x + 1, y
            flag = 0
    else:
        new_x, new_y = x, y - 1
        if new_y < 0:
            new_x, new_y = x + 1, y
            flag = 1
    if a[x][y] % 2 == 1:
        ans.append([x + 1, y + 1, new_x + 1, new_y + 1])
        a[new_x][new_y] += 1
    place = [new_x, new_y]

print(len(ans))
for j in ans:
    print(*j)
import collections
import random
n=int(input())
a=list(map(int,input().split()))
if len(set(a))==1 and a[0]==0:
  print('Yes')
elif n%3!=0:
  print('No')
elif len(set(a))!=3:
  x=random.randint(1,2)
  if x%2==0:
    print('No')
  elif n%3!=0
    print('No')
  else:
    print('Yes')
else:
  a=list(set(a))
  for i in range(len(a)):
    a[i]=format(a[i],'020b')
  l=[0 for i in range(20)]
  for i in range(len(a)):
    for j in range(20):
      if a[i][j]=='1':
        l[j]+=1
  ct=0
  for j in range(20):
    if l[j]==2 or l[j]==0:ct+=1
  if ct==20:
    print('Yes')
  else:
    print('No')

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
for i in range(n):
  a[i]=format(a[i],'030b')
l=[0 for i in range(30)]
for i in range(n):
  for j in range(30):
    if a[i][j]=='1':
      l[j]+=1
for j in range(30):
  l[j]=l[j]%2
 
if 1 in l:
  print('No')
else:
  print('Yes')
n1 = input()
n2 = input()

if n1%500<n2:
  print(Yes)
else:
  print(No)

### FIXED CODE ###

n1 = int(input())
n2 = int(input())
 
if n1%500<=n2:
  print("Yes")
else:
  print("No")
# 実行時の引数の入力：https://qiita.com/orange_u/items/3f0fb6044fd5ee2c3a37

import sys

args = sys.argv

num_len = int(args[1])
a = []
b = []
N = 100
# b = [1,2,1]
for i in range(2, 2+num_len):
    b.append(int(args[i]))
print(b)



# for i in range(len(b)):
for i in range(num_len):
    # try:
    #     # print(i)
    #     a.insert(b[i], b[i])
    #     print(a)
    # except:
    #     print(-1)

    if a == b:
        # print(i)
        a.insert(b[i], b[i])
        print(a)
    else:
        print(-1)




### FIXED CODE ###

# 実行時の引数の入力：https://qiita.com/orange_u/items/3f0fb6044fd5ee2c3a37

# ***.py a b c形式の引数使用時
# import sys
#
# args = sys.argv
#
# num_len = int(args[1])
# a = []
# b = []
# N = 100
# # b = [1,2,1]
# for i in range(2, 2+num_len):
#     b.append(int(args[i]))
# print(b)

a = []
# print('input:')
num_len = int(input())
b = list(map(int, input().split()))
# print('--'*len(b))
# print('output:')
# print(b)
N = 100



# for i in range(len(b)):
for i in range(num_len):
    # try:
    #     # print(i)
    #     a.insert(b[i], b[i])
    #     print(a)
    # except:
    #     print(-1)

    if b[i]-1 <= len(a):
        # print(i)
        a.insert(b[i]-1, b[i])
        # print(a)
        flag = True
    else:
        flag = False
        break


if flag:
    for i in a:
        print(i)
else:
    print(-1)
S = list(input())
K = int(input())
length = []
tl = 1
x = 0
ans = 0
J = True
same = 1
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    same += 1
if same == len(S):
  J = False
S.append('end')
if S[0] != S[len(S)-2] and J:
  for i in range(len(S)):
    if S[i] == S[i+1]:
      tl += 1
    else:
      length.append(tl)
      tl = 1
  for i in range(len(length)):
    x += length[i]//2
  ans += x*K
  print(ans)
elif not J:
  ans = (len(S)-1)*K//2
  print(ans)
else:
  for i in range(len(S)):
    if S[i] == S[i+1]:
      tl += 1
    else:
      length.append(tl)
      tl = 1
  ans += ((length[0]+length[len(length)])*(K-1)//2) + length[0]//2 + length[length]//2
  length[0] = 0
  length[len(length)] = 0
  for i in range(len(length)):
    x += length[i]//2
  ans += x*K
  print(ans)
  


### FIXED CODE ###

S = list(input())
R = int(input())
lengths = []
same = False
All = False
odd = False
sl = 1
Sum = 0
if S[0] == S[len(S)-1]:
  same = True
S.append('0')
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    sl += 1
  else:
    lengths.append(sl)
    sl = 1
if len(lengths) == 1:
  All = True
if lengths[0]%2 == 1 and lengths[len(lengths)-1]%2 == 1:
  odd = True
if same:
  if All:
    Sum += (lengths[0]*R)//2
  else:
    temp = lengths[0]
    lengths[0] = 0
    lengths[len(lengths)-1] += temp
    if odd:
      for l in range(len(lengths)):
        Sum += (lengths[l]//2)*R
      Sum -= 1
    else:
      for g in range(len(lengths)):
        Sum += (lengths[g]//2)*R
else:
  for j in range(len(lengths)):
    Sum += (lengths[j]//2)*R
print(Sum)
n,k=map(int,input().split())
p_lis = []
import math
for x in range(1,n+1):
    power = -((-math.log2(k//x))//1)
    p_lis.append(((1/2)**power)*(1/n))
print(sum(p_lis))


### FIXED CODE ###

n,k=map(int,input().split())
p_lis = []
for x in range(1,n+1):
    if k>x:
        i=1
        while x*2<k:
            x*=2
            i+=1
        p_lis.append(((1/2)**i)*(1/n))
    else:
        p_lis.append(1/n)
print(sum(p_lis))
import numpy as np
N , K ,Q = map(int, input().split())
s = []
for i in range(Q):
    s.append(int(input())-1)
initializer_list = np.full(N,K)
for i in range(len(s)):
    for j in range(len(initializer_list)):
        if j == s[i]:
            pass
        else:
            initializer_list[j] -= 1
for i in range(len(initializer_list)):
    if initializer_list[i] > 0:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

import numpy as np
N , K ,Q = map(int, input().split())
initializer_list = [0] * N
for _ in range(Q):
    i = int(input())-1
    initializer_list[i] += 1
    

[print('Yes') if (Q - initializer_list[i] < K) else print('No')  for i in range(N)]
str_list = list(input())
import string
dif_list = sorted(list(set(string.ascii_lowercase) - set(sorted(str_list))))
print(dif_list[0])

### FIXED CODE ###

str_list = list(input())
import string
if set(str_list) == set(string.ascii_lowercase):
    print("None")
else:
    dif_list = sorted(list(set(string.ascii_lowercase) - set(str_list)))
    print(dif_list[0])
x,y=map(int,input().split())
for i in range(x+1):
    if 2*i+4*(x-i)==y:
        print("Yes")
        break
else:
    print("No")

### FIXED CODE ###

n = list(map(int, input().split()))
result = 0
for i in range(len(n)):
  if n[i] == 0:
    print(i+1)
a,b,k=map(int, input().split())
l=list(range(a,b+1))
c=a+k
d=b-k
for i in l:
	if i<(c) or i>(d):
		print(i)

### FIXED CODE ###

a,b,k = map(int, input().split())
for i in range(a,min(b+1,a+k)):
    print(i)
for i in range(max(b-k+1,(a+k)),b+1):
    print(i)
a = input()
q = int(input())
b = list(input().split() for i in range(q))

for i in range(q):
    j = b[i][0]
    k = b[i][1]
    a = a.replace(j,k)
    l = a.split(' ')
    l = [int(i) for i in l]
    print(sum(l))

### FIXED CODE ###

import collections
n = int(input())
a = list(map(int,input().split()))
q = int(input())
l = [list(map(int,input().split())) for i in range(q)]
b,c = [list(i) for i in zip(*l)]
x = collections.Counter(a)
y = sum(a)
for i in range(q):
    if b[i] in x:
        y -= x[b[i]] * b[i]
        y += x[b[i]] * c[i]
        x[c[i]] += x[b[i]]
        x[b[i]] = 0
    print(y)
NM = input().split(" ")
N = int(NM[0])
M = int(NM[1])

Xin= input().split(" ")


Xls = []
tousa = []
for i in range(0,M):
    Xls.append(int(Xin[i]))

Xls.sort()

if M != 1:
    for i in range(0,M-1):
        tousa.append(abs(Xls[i+1] - Xls[i]))

if M == 1:
    print(0)
    exit()

tousa.sort()
if N != 1:
    for i in range(0,N-1):
        tousa.pop()

ret = 0

for i in tousa:
    ret = i + ret

print(ret)


### FIXED CODE ###

NM = input().split(" ")
N = int(NM[0])
M = int(NM[1])

Xin= input().split(" ")


Xls = []
tousa = []
for i in range(0,M):
    Xls.append(int(Xin[i]))

Xls.sort()

if M != 1:
    for i in range(0,M-1):
        tousa.append(abs(Xls[i+1] - Xls[i]))




tousa.sort()


if N<M:
    for i in range(0,N-1):
        tousa.pop()
else:
    print(0)
    exit()
ret = 0

for i in tousa:
    ret = i + ret

print(ret)
from sys import stdin

def main():
    n = int(stdin.readline().rstrip())
    xs = [int(stdin.readline().rstrip()) for _ in range(n)]

    for i in range(n):
        print(max(xs[0:i]+xs[i+1:])

if __name__ == '__main__':
    main()


### FIXED CODE ###

from sys import stdin

def main():
    n = int(stdin.readline().rstrip())
    xs = [int(stdin.readline().rstrip()) for _ in range(n)]

    max_1, max_2 = sorted(xs)[-1], sorted(xs)[-2]

    for i in range(n):
        if xs[i] == max_1:
            print(max_2)
        else:
            print(max_1)
            
if __name__ == '__main__':
    main()
n = int(input())
s = input()

if n % 2 == 1:
  print('No')
else:
  for i in range(n/2):
    if s[i] != s[i+n/2]:
      print('No')
      break
      
  print('Yes')

### FIXED CODE ###

n = int(input())
s = input()

if n % 2 == 1:
  print('No')
else:
  m = int(n/2)
  s1 = s[: m]
  s2 = s[m: ]
  
  if s1 == s2:
    print('Yes')
  else:
    print('No')
import sys
input = sys.stdin.readline
import numpy as np

h, w = map(int, input().split())
A = np.array([input().split() for _ in range(h)], dtype=np.int64)
B = np.array([input().split() for _ in range(h)], dtype=np.int64)
D = abs(A-B)
M = D.max()*(h+w-1) + 1
dp = np.zeros((h, w, 2*M), dtype=bool)
dp[0, 0, M-D[0, 0]] = True
dp[0, 0, M+D[0, 0]] = True
for i in range(h):
  for j in range(w):
    if i:
      dp[i, j, D[i, j]:] |= dp[i-1, j, :-D[i, j]]
      dp[i, j, :-D[i, j]] |= dp[i-1, j, D[i, j]:]
    if j:
      dp[i, j, D[i, j]:] |= dp[i, j-1, :-D[i, j]] 
      dp[i, j, :-D[i, j]] |= dp[i, j-1, D[i, j]:]
idx = np.where(dp[-1, -1, M:])
ans = idx[0][0]
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
  h, w = map(int, input().split())
  A = [list(map(int, input().split())) for _ in range(h)]
  B = [list(map(int, input().split())) for _ in range(h)]
  M = 80*(h+w)
  dp = [[0]*w for i in range(h)]
  d = abs(A[0][0] - B[0][0])
  mask = (1 << (2*M)) - 1
  dp[0][0] |= 1 << (M-d)
  dp[0][0] |= 1 << (M+d)
  for i in range(h):
    for j in range(w):
      d = abs(A[i][j] - B[i][j])
      if i:
        dp[i][j] |= (dp[i-1][j] << d) & mask
        dp[i][j] |= dp[i-1][j] >> d
      if j:
        dp[i][j] |= (dp[i][j-1] << d) & mask
        dp[i][j] |= dp[i][j-1] >> d
  t = dp[-1][-1] >> M
  ans = (t & (-t)).bit_length() - 1
  print(ans)
  
if __name__ == "__main__":
  main()
S = input()
l = len(S)
diff = 999

for i in range(0,S-2):
    n = int(S[i:i+3])
    if diff > abs(753-n):
        diff = abs(753-n)
    
print(diff)

### FIXED CODE ###

S = input()
l = len(S)
diff = 999

for i in range(0,l-2):
    n = int(S[i:i+3])
    if diff > abs(753-n):
        diff = abs(753-n)
    
print(diff)