Harryxun/stf_run huggingface dataset:
n, m = map(int, input().split())
p = list(map(int, input().split()))
xys = [list(map(int, input().split())) for _ in range(m)]
uf = {}

def dfs(cld):
    if cld not in uf:
        return []
    elif uf[cld] < 0:
        return [cld]
    return dfs(uf[cld]) + [cld]

for xy in xys:
    xin = (xy[0] in uf)
    yin = (xy[1] in uf)
    xp = dfs(xy[0])
    yp = dfs(xy[1])
    if xin and yin:
        if uf[xp[0]] == uf[yp[0]]:
            uf[xy[1]] = xp[0]
            uf[xp[0]] -= 1
        elif uf[xp[0]] < uf[yp[0]]:
            uf[xy[1]] = xp[0]
        else:
            uf[xy[0]] = yp[0]
    elif xin:
        uf[xy[1]] = xp[0]
    elif yin:
        uf[xy[0]] = yp[0]
    else:
        uf[xy[0]] = -1
        uf[xy[1]] = xy[0]
count = 0
for i in range(n):
    num = i + 1
    pi = p[i]
    if num == pi or sum(set(dfs(num)) & set(dfs(pi))) > 0:
        count += 1
print(count)

### FIXED CODE ###

n, m = map(int, input().split())
p = list(map(int, input().split()))
xys = [list(map(int, input().split())) for _ in range(m)]
mapp = [[] for _ in range(n + 1)]
for xy in xys:
    mapp[xy[0]].append(xy[1])
    mapp[xy[1]].append(xy[0])

bfs = [0] * (n + 1)
count = 0
for i in range(1, n + 1):
    nexts = mapp[i]
    if not(bfs[i]):
        bfs[i] = i
    for j in nexts:
        if bfs[j]:
            continue
        bfs[j] = i
        nexts += mapp[j]
    if bfs[i] == bfs[p[i - 1]]:
        count += 1
print(count)
L, R = map(int , input().split())

ans = 10 ** 9
for i range(L, R+1):
    for j range(i, R):
        mod = i * j % 2019
        if ans > mod:
            ans = mod
        elif mod == 0:
            ans = 0
            break
    else:
        continue
    break
print(ans)

### FIXED CODE ###

L, R = map(int, input().split())

ans = 10 ** 9
for i in range(L, R):
    for j in range(i+1, R+1):
        tmp = (i*j)%2019
        if ans > tmp:
            ans = tmp
        if ans == 0:
            break
    else:
        continue
    break
print(ans)
nk = input(' ')
n = int(nk.split()[0])
k = int(nk.split()[1])
alist = list(map(int,input('').split()))

loop_start=0
loop_end=0
root = []
next=1
for i in range(k):
    a = next
    next = alist[a-1]
    root.append(a)
#    print("{}: {}->{} [{}]".format(i,a,next,root))
    if next in root:
        loop_start=root.index(next)
        loop_end=len(root)
        break

#print("{} {}->{}".format(root,loop_start,loop_end))

step=(k-loop_start)%(loop_end-loop_start)
#print("step:({}-{})%({} - {})={}".format(k,loop_start,loop_end,loop_start,step))
#print("root[{}+{}]={}".format(loop_start,step,root[loop_start+step]))
if k < loop_start:
    print(root[k])
else:
    print(root[loop_start+step])

### FIXED CODE ###

nk = input(' ')
n = int(nk.split()[0])
k = int(nk.split()[1])
alist = list(map(int,input('').split()))

loop_start=0
loop_end=0
root = [1]
next_val=1
flag=[True]*n
flag[0]=False # 踏んだかどうか判定機
a=1
for i in range(k):
    a = alist[a-1]
    if flag[a-1]: # 踏んでたらそこでブレイク
        root.append(a)
        flag[a-1]=False # 踏んだらFalseに
    else:
        break

#print("{} {}->{}".format(root,loop_start,loop_end))

loop_start=root.index(a)
loop_end=len(root)
step=(k-loop_start)%(len(root)-loop_start)
#print("step:({}-{})%({} - {})={}".format(k,loop_start,loop_end,loop_start,step))
#print("root[{}+{}]={}".format(loop_start,step,root[loop_start+step]))
print(root[loop_start+step])
s = list(input())
for i in range(10**5):
    if i%2==0:
        s[i].replace(s[i],'')
print(s)

### FIXED CODE ###

s = input()
for i in range(0,len(s),2):
    print(s[i],end="")
from bisect import bisect_right
def main():
  s=input()
  t=input()
  n=len(t)
  m=len(s)
  lindex=[[] for _ in range(26)]
  for i in range(m):
    if s[i] in t:
      lindex[ord(s[i])-97].append(i)
  for i in range(n):
    if len(lindex[ord(t[i])-97])==0:
      print(-1)
      exit()
  cnt=0
  for i in range(n-1):
    l=len(lindex[ord(t[i+1])-97])
    if l==bisect_right(lindex[ord(t[i+1])-97],lindex[ord(t[i])-97][0]):
      cnt+=1
    if i==n-2:
      if l>bisect_right(lindex[ord(t[i+1])-97],lindex[ord(t[i])-97][0]):
        k=lindex[ord(t[n-1])-97][0]
      else:
        k=bisect_right(lindex[ord(t[n-1])-97],lindex[ord(t[i])-97][0])
  return print(m*cnt+k+1)
if __name__=='__main__':
  main()

### FIXED CODE ###

from bisect import bisect_right
def main():
  s=input()
  t=input()
  n=len(t)
  m=len(s)
  lindex=[[] for _ in range(26)]
  for i in range(m):
    if s[i] in t:
      lindex[ord(s[i])-97].append(i)
  for i in range(n):
    if len(lindex[ord(t[i])-97])==0:
      print(-1)
      exit()
  cnt=0
  inde=-1
  for i in range(n):
    l=len(lindex[ord(t[i])-97])
    idx=bisect_right(lindex[ord(t[i])-97],inde)
    if l==idx:
      cnt+=1
      inde=lindex[ord(t[i])-97][0]
    else:
      inde=lindex[ord(t[i])-97][idx]
  return print(m*cnt+inde+1)
if __name__=='__main__':
  main()
import sys
input = sys.stdin.readline

def comb(n):
    if n == 1:
        return 0
    else:
        return int(n*(n-1)/2)

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

origin = list(set(AS))
num = []
for i in origin:
    num.append(AS.count(i))
comb_list = [-1]*(max(num)+1)
all_num = 0
for i in num:
    if comb_list[i] == -1:
        all_num += comb(i)
        comb_list[i] = comb(i)
    else:
        all_num += comb_list[i]
    
for i in range(n):
    j = num[origin.index(AS[i])]
    ans = all_num - (j-1)
    print(ans)

### FIXED CODE ###

from math import factorial

n, m = map(int, input().split())
if n > 1 and m > 1:
    print(int(factorial(n)/factorial(2)/factorial(n-2) + factorial(m)/factorial(2)/factorial(m-2)))
elif n > 1:
    print(int(factorial(n)/factorial(2)/factorial(n-2)))
elif m > 1:
    print(int(factorial(m)/factorial(2)/factorial(m-2)))
else:
    print(0)
A, B = map(int,input())
print((A*3+B)//2)

### FIXED CODE ###

A, B = map(int,input().split())
print((A*3+B)//2)
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()

move = 0

if n >= m:
  print(move)
elif n==1:
  move = max(x) - min(x)
  print(move)
else:
  x_diff = [None]*(m-1)
  for i in range(m-1):
    x_diff[i] = [i+1, x[i+1] - x[i]]
  x_diff = sorted(x_diff, key=lambda x:-x[1])
  for j in range(n):
    if j==0:
      move += max(x[0:x_diff[j][0]])-min(x[0:x_diff[j][0]])
    elif j==n-1:
      move += max(x[x_diff[j-1][0]:])-min(x[x_diff[j-1][0]:])
    else:
      move += max(x[x_diff[j-1][0]:x_diff[j][0]])-min(x[x_diff[j-1][0]:x_diff[j][0]])
  print(move)

### FIXED CODE ###

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

move = 0

if n >= m:
  print(move)
elif n==1:
  move = max(x) - min(x)
  print(move)
else:
  x_diff = [None]*(m-1)
  for i in range(m-1):
    x_diff[i] = [i+1, x[i+1] - x[i]]
  x_diff = sorted(x_diff, key=lambda x:-x[1])
  sep = sorted(x_diff[:n-1])
  for j in range(n):
    if j==0:
      move += max(x[0:sep[j][0]])-min(x[0:sep[j][0]])
    elif j==n-1:
      move += max(x[sep[j-1][0]:])-min(x[sep[j-1][0]:])
    else:
      move += max(x[sep[j-1][0]:sep[j][0]])-min(x[sep[j-1][0]:sep[j][0]])
  print(move)
import numpy as np
a=int(input())
b=int(input())
print(max(a+b,a-b,a*b))

### FIXED CODE ###

a,b = map(int,input().split())
print(max(a+b,a-b,a*b))
import numpy as np
n,m = map(int,input().split())
A = np.array([int(i) for i in input().split()])
A_half = A//2
lcm = 1
for i in A_half:
    lcm = np.lcm(lcm,i)
c = m//lcm
print(c//2 + c%2)


### FIXED CODE ###

import numpy as np
import copy
n,m = map(int,input().split())
A = np.array([int(i) for i in input().split()])//2
lcm_ = 1
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a
def lcm(a,b):
    return a*b//gcd(a,b)

for i in A:
    lcm_ = lcm(lcm_,i)
c = 0
lcm_2 = copy.deepcopy(lcm_)
for _ in range(30):
    if lcm_2 % 2 == 0:
        c += 1
        lcm_2 = lcm_2//2
if np.all(A%(2**c) == 0):
    c = m//lcm_
    print(c//2 + c%2)
else:
    print(0)
target = input()
length = len(target)
binary = length - 1
target_list = []
answers = 0
for i in range(length):
    if i:
        target_list.append("")
    target_list.append(target[i])
for bit in range(2 ** binary):
    temp = target_list.copy()
    for i in range(binary):
        if bit & (1 << i):
            temp[1 + 2 * i] = "+"
    # print(temp, bit)
    answers += eval("".join(temp))
print(answers)

### FIXED CODE ###

target = input()
length = len(target)
binary = length - 1
target_list = []
answers = 0
for i in range(length):
    if i:
        target_list.append("")
    target_list.append(target[i])
for bit in range(2 ** binary):
    temp = target_list.copy()
    for i in range(binary):
        if bit & (1 << i):
            temp[1 + 2 * i] = "+"
    # print(temp, bit)
    answers += eval("".join(temp))
print(answers)
a,b=input().split()
a = int(a)
b = int(b.repalce('.',""))

print(int(a*b)//100)

### FIXED CODE ###

a,b=input().split()
a = int(a)
b = int(b.replace('.',""))

print(int(a*b)//100)
a,b = map(int,input().split())
 i ="Even" if a * b % 2 == 0 else "Odd"
 print(i)

### FIXED CODE ###

a,b = map(int,input().split())
if a * b % 2 == 0:
    print("Even")
else:
    print("Odd")
import sys
import math
input = sys.stdin.readline


mod = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split(" ")))

lcm = 1
for a in A:
    lcm = a // math.gcd(a, lcm) * lcm

ans = 0
for a in A:
    ans += lcm // a

print(ans % mod)

### FIXED CODE ###

import sys
import fractions
input = sys.stdin.readline


mod = 10 ** 9 + 7
N = int(input().strip())
A = list(map(int, input().strip().split(" ")))

lcm = 1
for a in A:
    lcm = a // fractions.gcd(a, lcm) * lcm

ans = 0
for a in A:
    ans += lcm // a

print(ans % mod)
n=int(input())
total=0
l = list(range(2,n+1)) + [1]
for i in range(n):
  total+=(i+1)%l[i]
print(total)


### FIXED CODE ###

n=int(input())
#total=0
#l = list(range(2,n+1)) + [1]
#for i in range(n):
#    total+=(i+1)%l[i]
#print(total)
# 1+2+3+...+n-1
print(n*(n-1)//2)
mod = 10**9+7
N, K = map(int, input().split())
if K % 2:
    print(0)
else:
    dp = [[[0]*(2*N**2) for _ in range(N+1)] for _ in range(N+1)]
    dp[0][0][0] = 1
    for i in range(N):
        for k in range(i+2):
            for S in range(-N**2+1, N**2):
                d = dp[i][k][S]
                if not d:
                    continue
                dp[i+1][k][S] = (dp[i+1][k][S]+(2*k+1)*d)%mod
                dp[i+1][k+1][S-2*(i+1)] = (dp[i+1][k+1][S-2*(i+1)]+d)%mod
                dp[i+1][k-1][S+2*(i+1)] = (dp[i+1][k-1][S+2*(i+1)]+k*k*d)%mod
    print(dp[N][0][K])

### FIXED CODE ###

mod = 10**9+7
N, K = map(int, input().split())
if K % 2:
    print(0)
else:
    dp = [[[0]*(2*N**2+2*N) for _ in range(N+1)] for _ in range(N+1)]
    dp[0][0][0] = 1
    for i in range(N):
        for k in range(i+2):
            for S in range(-N**2+1, N**2):
                d = dp[i][k][S]
                if not d:
                    continue
                dp[i+1][k][S] = (dp[i+1][k][S]+(2*k+1)*d)%mod
                dp[i+1][k+1][S-2*(i+1)] = (dp[i+1][k+1][S-2*(i+1)]+d)%mod
                dp[i+1][k-1][S+2*(i+1)] = (dp[i+1][k-1][S+2*(i+1)]+k*k*d)%mod
    print(dp[N][0][K])
W, a, b = map(int, input().split())
return min(abs(a - b), abs(a - b + W), abs(b - a + W))

### FIXED CODE ###

W, a, b = map(int, input().split())
if abs(a-b) > W:
    print(min(abs(a - b), abs(a - b + W), abs(b - a + W)))
else:
    print(0)
taka = input()
remainder = taka%1000
ans = 1000 - remainder

### FIXED CODE ###

taka = int(input())
remainder = taka % 1000
ans = 1000 - remainder
print(ans % 1000)
N, K = map(int, input().split())
items = []
neta = {}
for _ in range(N):
    t, d = tuple(map(int, input().split()))
    items.append((t, d))

    if t not in neta:
        neta[t] = d
    else:
        tmp = neta[t]
        if d > tmp:
            neta[t] = d

neta = sorted(neta.items(), key=lambda x: -x[1])
items = sorted(items, key=lambda x: -x[1])

ans1 = 0
select1 = set()
for i in range(K):
    t, d = items[i]
    select1.add(t)
    ans1 += d
ans1 += len(select1) ** 2

ans2 = 0
select2 = set()
cnt = 0
for k, v in neta:
    cnt += 1
    select2.add(k)
    ans2 += v
    if cnt == K:
        ans2 += cnt ** 2
        print(max(ans1, ans2))
        exit()

remain = K - cnt
i = 1
sel = set()
while remain != 0:
    t, d = items[i]
    if t not in sel:
        ans2 += d
        sel.add(t)
        remain -= 1
    else:
        i += 1
        sel.add(t)
print(max(ans1, ans2))


### FIXED CODE ###

N, K = map(int, input().split())
umai = {}
mazui = []
for _ in range(N):
    t, d = map(int, input().split())
    if t not in umai:
        umai[t] = d
    else:
        tmp = umai[t]
        if tmp < d:
            umai[t] = d
            mazui.append((t, tmp))
        else:
            mazui.append((t, d))

umai = sorted(umai.items(), key=lambda x: -x[1])
mazui = sorted(mazui, key=lambda x: -x[1])


umai_len = len(umai)
mazui_len = len(mazui)

acc_umai = [0 for _ in range(umai_len)]
acc_umai[0] = umai[0][1]
for i in range(umai_len - 1):
    acc_umai[i + 1] = acc_umai[i] + umai[i + 1][1]

acc_mazui = [0 for _ in range(mazui_len)]
if mazui_len > 0:

    acc_mazui[0] = mazui[0][1]
    for i in range(mazui_len - 1):
        acc_mazui[i + 1] = acc_mazui[i] + mazui[i + 1][1]
acc_mazui.insert(0, 0)

ans = []
for i in range(1, K + 1):
    if umai_len < i or mazui_len < K - i:
        continue
    ans.append(acc_umai[i - 1] + acc_mazui[K - i] + i ** 2)
print(max(ans))
N, M = map(int, input().split())
A = list(map(int, input().split()))
b = []
for i in range(M):
    b.append(list(map(int, input().split())))
ans = 0
A.sort()
b.sort(key=lambda x: x[1], reverse=True)
j = 0
for i in range(M):
    if b[i][1] <= A[j] or j == N:
        break
    while j < N and b[i][0] and b[i][1] > A[j]:
        ans += b[i][1]
        b[i][0] -= 1
        j += 1
if j == N:
    print(ans)
else:
    print(ans + sum(A[j:]))

### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
b = []
for i in range(M):
    b.append(list(map(int, input().split())))
ans = 0
A.sort()
b.sort(key=lambda x: x[1], reverse=True)
j = 0
for i in range(M):
    if j >= N or b[i][1] <= A[j]:
        break
    while j < N and b[i][0] and b[i][1] > A[j]:
        ans += b[i][1]
        b[i][0] -= 1
        j += 1
if j >= N:
    print(ans)
else:
    print(ans + sum(A[j:]))
A,B = map(int,input().split())
if abs(a-b)<=1:
  print(a+b)
else:
  if a>b:
    print(a*2-1)
  else:
    print(b*2-1)
    

### FIXED CODE ###

a,b = map(int,input().split())
if abs(a-b)<=1:
  print(a+b)
else:
  if a>b:
    print((a*2)-1)
  else:
    print((b*2)-1)
from scipy import special

def main():
    n, m = map(int, input().split())

    ans = 0
    ans += special.comb(n, 2)
    ans += special.comb(m, 2)

    print(int(ans))

if __name__ == '__main__':
    main()


### FIXED CODE ###

from itertools import combinations

def main():
    n, m = map(int, input().split())

    ans = 0

    n_list = [i+1 for i in range(n)]
    m_list = [i+1 for i in range(m)]

    ans += len(list(combinations(n_list, 2)))
    ans += len(list(combinations(m_list, 2)))

    print(ans)

if __name__ == '__main__':
    main()
n = int(input())
a = [i in int(input())]
for  i in range(n):
    v  = a[i]
    j = i-1
    while a[j]>a[j+1] and j>0:
        a[j+1] = a[j]
        a[j] = v
        j -=1


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
for  i in range(n):
    v  = a[i]
    j = i-1
    while a[j]>v and j>=0:
        a[j+1] = a[j]
        j -=1

    a[j+1] = v
    print(*a)
import math
x1,y1,x2,y2 = map(int, input().split())
print("{:.6f}".format(math.sqrt((x2-x1)**2+(y2-y1)**2)))

### FIXED CODE ###

import math
x1,y1,x2,y2 = map(float, input().split())
dist = math.sqrt((x2-x1)**2+(y2-y1)**2)
print("%.6f" % (dist))
a, b, n = map(int, input().split())

if b-1 > n:
    x = n
else:
    x = (n // (b-1)) * (b-1)
answer = max(0, (a*x)//b - a*(x//b))

print(answer)


### FIXED CODE ###

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

if b > n:
    x = n
else:
    x = n // b * b - 1
answer = max(0, (a*x)//b - a*(x//b))

print(answer)
from bisect import bisect_left
import math
import sys
readlines = sys.stdin.readline

def main():
  n,d,a = map(int,input().split())
  xx = []
  hh = []
  X = []
  H = []
  for _ in range(n):
    tmp = list(map(int,input().split()))
    xx.append(tmp[0])
    hh.append(tmp[1])

  k = zip(xx,hh)
  q = sorted(k)
  for xxx,hhh in q:
    X.append(xxx)
    H.append(hhh)
  X = tuple(X)
  ans = 0
  end = n-1
  while True:
    x = X[end] - d
    start = bisect_left(X,x-d)
    num = math.ceil(H[end] / a)
    ans += num
    H[end] = 0
    e = end
    end = start-1
    for i in range(start,e):
      H[i] -= a * num
      if H[i] > 0:
        end = i
    if end < 0:
      break

  print(ans)
if __name__ == '__main__':
  main()

### FIXED CODE ###

import math

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

print(int(math.ceil(h / a)))
N = int(input())
*A, = map(int,input().split())

if N%3:
    ans = True
    for a in A:
        if a:ans=False;break
else:
    B = set(A)
    l = len(B)
    ans = True
    if l>3 or l==2:
        ans = False
        1/0
    elif l==1:
        for b in B:
            if b:ans=False;break
    else:
        a,b,c = B
        ans = ans and (A.count(a)==A.count(b)==A.count(c)==N//3) and (a^b==c)
        
if ans:print("Yes")
else:print("No")

### FIXED CODE ###

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

if N%3:
    ans = True
    for a in A:
        if a:ans=False;break
else:
    B = set(A)
    l = len(B)
    ans = True
    if l>3:
        ans = False
    elif l==1:
        for b in B:
            if b:ans=False;break
    else:
        if l==3:
            a,b,c = B
            l,m,n = (A.count(x) for x in (a,b,c))
        if l==2:
            a,b = B
            l,m = (A.count(x) for x in (a,b))
            if l>=m:
                c=a
                n=l//2
                l-=n
            else:
                c=b
                n=m//2
                m-=n
        ans = ans and (l==m==n==N//3) and (a^b==c)
        
if ans:print("Yes")
else:print("No")
n = int(input())
v = list(map(int,input().split()))
l1 = []
l2 = []
for i,v_ in enumerate(v):
    if i%2==0:
        l1.append(v_)
    else:
        l2.append(v_)

from collections import Counter
if set(l1)==set(l2):
    print(n//2)
else:
    c1 = Counter(l1).most_common(2)
    c2 = Counter(l2).most_common(2)
    if c1[0][0]==c2[0][0]:
        print(n-max(c1[0][1]+c2[1][1], c1[1][1]+c2[0][1]))
    else:
        print(n-c1[0][1]-c2[0][1])


### FIXED CODE ###

n = input()
for n_ in n:
    if n_=='1':
        print('9',end='')
    else:
        print('1',end='')
print()
mod = 10 ** 9 + 7
x, y = map(int, input().split())
if (x + y) % 3 != 0:
    print(0)
    exit()
a = 0
while y / x != 2 and x / y != 2:
    x -= 2
    y -= 1
    a += 1
b = min(x, y)

n = a + b
r = min(a, b)
x = 1
for i in range(n - r):
    x = x * (n - i) % mod
y = 1
for j in range(1, r):
    y = y * j
ans = x * pow(y, mod - 2, mod) % mod
print(ans)


### FIXED CODE ###

mod = 10 ** 9 + 7
x, y = map(int, input().split())
a = (2 * y - x) // 3
b = (2 * x - y) // 3
if (x + y) % 3 != 0 or a < 0 or b < 0:
    print(0)
    exit()
n = a + b
r = min(a, b)
ans = 1
for i in range(r):
    ans = ans * (n - i) * pow(i + 1, mod - 2, mod) % mod
print(ans)
a,b=map(int, input().split())
if print("Even" if a*b%2==0 else "Odd")


### FIXED CODE ###

a,b=map(int, input().split())
print("Even" if a*b%2==0 else "Odd")
s, t = input().split(" ")
if t.__contains__(s):
    print("Yes")
else:
    print('No')

### FIXED CODE ###

s = input()
t = input()
if s == t[:len(s)]:
    print("Yes")
else:
    print('No')
import sys
input = sys.stdin.readline
import bisect

a,b,q = map(int, input().split())
m = {}
st = []
for _ in range(a):
    num = int(input())
    st.append(num)
    m[num] = "A"
for _ in range(b):
    num = int(input())
    st.append(num)
    m[num] = "B"
st.sort()

def search_left(idx):
    t = {"A": False, "B": False}
    for i in st[:idx][::-1]:
        if m[i] == "A":t["A"]=True
        if m[i] == "B":t["B"]=True
        if t["A"] and t["B"]:return i
    return 0
def search_right(idx):
    t = {"A": False, "B": False}
    for i in st[idx:]:
        if m[i] == "A":t["A"]=True
        if m[i] == "B":t["B"]=True
        if t["A"] and t["B"]:return i
    return 0
def search_left_one(idx, c):
    for i in st[:idx][::-1]:
        if m[i] == c:return i
def search_right_one(idx, c):
    for i in st[idx:]:
        if m[i] == c:return i
for _ in range(q):
    x = int(input())
    idx = bisect.bisect_left(st,x)
    if idx == 0:
        most_right = search_right(0)
        print(abs(x-most_right))
        continue
    elif idx == a+b:
        most_left = search_left(a+b)
        print(abs(x-most_left))
        continue        
    left = st[idx-1]
    right = st[idx]
    c = "A" if m[left]=="B" else "B"
    most_right = search_right_one(idx, c)
    ans = abs(abs(x-left)+most_right-left)
    c = "A" if m[right]=="B" else "B"
    most_left = search_left_one(idx, c)
    ans = min(ans,abs(abs(x-right)+right-most_left))
    most_left = search_left(idx)
    if most_left != 0:ans = min(ans,abs(x-most_left))
    most_right = search_right(idx)
    if most_right != 0:ans = min(ans,abs(x-most_right))
    print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
import bisect

a,b,q = map(int, input().split())
INF = 10**18
s = [-INF] + [int(input()) for _ in range(a)] + [INF]
t = [-INF] + [int(input()) for _ in range(b)] + [INF]
for _ in range(q):
    x = int(input())
    i = bisect.bisect_right(s,x)
    j = bisect.bisect_right(t,x)
    d = INF
    for si in [s[i-1],s[i]]:
        for ti in [t[j-1],t[j]]:
            d1 = abs(x-si)+abs(ti-si)
            d2 = abs(x-ti)+abs(ti-si)
            d = min(d,d1,d2)
    print(d)
K=input()
A=input()
B=input()

for i in range(A,B):
  i %= K
  if i==0:
    print("OK")


### FIXED CODE ###

K=int(input())
A,B=map(int,input().split())

yn=0
for i in range(A,B+1,1):
    if (i % K) == 0:
        print("OK")
        yn=1
        break
if yn==0:
    print("NG")
import sys

def check(a,b,k):
    if a + b == k:
        b = 0
        a = 0
    elif a < k:
        b = b - (k-a)
        a = 0
    elif a > k:
        a = a - k
    return a,b

a,b,k=map(int,input().split(" "))
if len(str(a)) > 12 or len(str(b)) > 12 or len(str(k)) > 12:
  a=0
  b=0
  print(str(a),str(b))
  sys.exit()

else:
    if a > 0 and k > 0:
        A,B=check(a,b,k)
        print(str(A), str(B))
    elif a == 0 and b > k:
        b = b-k
        print(str(a), str(b))
    elif a+b < K:
        b = 0
        a = 0
        print(str(a), str(b))
    elif k ==0:
        print(str(a),str(b))

### FIXED CODE ###

a,b,k = map(int,(input().split(" ")))

if k <= a:
    print(str(a-k),str(b))
elif k <= a+b:
    print(str(0),str(b-(k-a)))
else:
    print(str(0),str(0))
import math

a, b, water = map(int, input().split())
pool = a ** 2 * b

if water > pool / 2:
    high = 2 * (pool - water) / (a ** 2)
    ans = 90 - math.degrees(math.atan(a / high))
elif water == pool / 2:
    ans = 45
else:
    high = 2 * water / (a * b)
    ans = 90 - math.degrees(math.atan(high / b))

print(ans)

### FIXED CODE ###

import math

a, b, water = map(int, input().split())
pool = a ** 2 * b

if water == pool:
    ans = 0
elif water > pool / 2:
    high = 2 * (pool - water) / (a ** 2)
    ans = 90 - math.degrees(math.atan(a / high))
elif water == pool / 2:
    ans = 45
else:
    high = 2 * water / (a * b)
    ans = 90 - math.degrees(math.atan(high / b))

print(ans)
a,b,c,d,e=int(input())
print(a)

### FIXED CODE ###

import math
a=int(input());b=int(input());c=int(input());d=int(input());e=int(input())

N=math.ceil(a/10)*10+math.ceil(b/10)*10+math.ceil(c/10)*10+math.ceil(d/10)*10+math.ceil(e/10)*10
X=[a%10,b%10,c%10,d%10,e%10]
n=0
while(n!=5):
  if X[n]==0:
    X[n]=10
  n+=1

else:
  print(N-(10-min(X)))