Harryxun/stf_run huggingface dataset:
n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]
cheby = []
for i in range(n):
    l = [xy[i][0]-xy[i][1],xy[i][0]+xy[i][1]]
    cheby.append(l)

xmax = 0
xmin = 10**9
ymax = 0
ymin = 10**9
for i in range(n):
    if cheby[i][0] > xmax :
        xmax = cheby[i][0]
        xa = i
    if cheby[i][0] < xmin :
        xmin = cheby[i][0]
        xi = i
    if cheby[i][1] > ymax :
        ymax = cheby[i][1]
        ya = i
    if cheby[i][1] < ymin :
        ymin = cheby[i][1]
        yi = i

if abs(xmax-xmin) > abs(ymax-ymin):
    print(abs(xy[xa][0]-xy[xi][0])+abs(xy[xa][1]-xy[xi][1]))
else :
    print(abs(xy[ya][0]-xy[yi][0])+abs(xy[ya][1]-xy[yi][1]))


### FIXED CODE ###

n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]
cheby = []
for i in range(n):
    l = [xy[i][0]-xy[i][1],xy[i][0]+xy[i][1]]
    cheby.append(l)

xmax = -10**10
xmin = 10**10
ymax = -10**10
ymin = 10**10
for i in range(n):
    if cheby[i][0] > xmax :
        xmax = cheby[i][0]
        xa = i
    if cheby[i][0] < xmin :
        xmin = cheby[i][0]
        xi = i
    if cheby[i][1] > ymax :
        ymax = cheby[i][1]
        ya = i
    if cheby[i][1] < ymin :
        ymin = cheby[i][1]
        yi = i

if abs(xmax-xmin) > abs(ymax-ymin):
    print(abs(xy[xa][0]-xy[xi][0])+abs(xy[xa][1]-xy[xi][1]))
else :
    print(abs(xy[ya][0]-xy[yi][0])+abs(xy[ya][1]-xy[yi][1]))
S = input()
w = int(input())
l = len(S)
ret = ""
if S % w:
  for i in range(1 + S // w):
    ret += S[i * w]
else:
  for i in range(S // w):
    ret += S[i * w]
print(ret)

### FIXED CODE ###

S = input()
w = int(input())
l = len(S)
ret = ""
if l % w:
  for i in range(1 + l // w):
    ret += S[i * w]
else:
  for i in range(l // w):
    ret += S[i * w]
print(ret)
import sys
sys.setrecursionlimit(2000000001)

def solve(n,k,ar,dp,x):
	ab = abs; mn = min
    if x>=n-2: return dp[x]
	if dp[x] != -1: return dp[x]
	m = 1e9
	for i in range(x+1,mn(n,x+k+1)):
		t = ab(ar[x]-ar[i])+solve(n,k,ar,dp,i)
		m = t if t<m else m
	dp[x] = m
	# pr(f'{x} => {dp[x]}')
	return dp[x]

def main():
    I = lambda:map(int,sys.stdin.readline().split())
    pr = lambda x:sys.stdout.write(f'{x}\n')
	n,k, ar = *I(), [*I()]
	dp = [-1]*(n-2) + [abs(ar[-2]-ar[-1]),0]
	# pr((n,k,ar,dp))
	pr(solve(n,k,ar,dp,0))

main()

### FIXED CODE ###

import sys
from functools import reduce
sys.setrecursionlimit(2000000001)

def solve(n,k,ar,dp,x):
	ab = abs; mn = min
	if x>=n-2: return dp[x]
	if not dp[x] is -1: return dp[x]
	# t = [ for i in range(x+1,mn(n,x+k+1))]
	t = map(lambda i:ab(ar[x]-ar[i])+solve(n,k,ar,dp,i), range(x+1,mn(n,x+k+1)))
	dp[x] = reduce(lambda a,b : a if a < b else b,t)
	return dp[x]

def main():
	I = lambda:map(int,sys.stdin.readline().split())
	pr = lambda x:sys.stdout.write(f'{x}\n')
	n,k, ar = *I(), [*I()]
	dp = [-1]*(n-2) + [abs(ar[-2]-ar[-1]),0]
	pr(solve(n,k,ar,dp,0))

main()
s = list(input())
s = set(s)
s = sorted(s)
m = 'abcdefghijklmnopqrstuvwxyz'

for i in range(len(m)):
    if s[i] != m[i]:
        print(m[i])
        exit(0)

print('None')

### FIXED CODE ###

s = list(input())
s = set(s)
s = sorted(s)
m = 'abcdefghijklmnopqrstuvwxyz'

for i in range(len(m)):
    if s[i] != m[i]:
        print(m[i])
        exit(0)

    if i + 1 != len(m) and i + 1 == len(s):
        print(m[i + 1])
        exit(0)

print('None')
x, a, b = map(int, input().split())

if a>=b:
  print("delicious")
else:
  if x=<b:
    print("safe")
  if a+x+1 <= b:
    print("dangerous")

### FIXED CODE ###

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

if a>=b:
  print("delicious")
else:
  if b-a<=x:
    print("safe")
  if a+x+1 <= b:
    print("dangerous")
l =map(int,input().split());a=sum(l[:2])-sum(l[3:]);print('Left') if a>0 else print('Right')if a<0 else print('Balanced')

### FIXED CODE ###

l =list(map(int,input().split()));a=sum(l[:2])-sum(l[2:]);print('Left') if a>0 else print('Right')if a<0 else print('Balanced')
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
dp = [0]
cost = [0,2,5,5,4,5,6,3,7,6]
for i in range(1, N+1):
    dp.append(-(2<<10))
    for a in A:
        if i >= cost[a]: 
            dp[i] = max(dp[i - cost[a]] + 1, dp[i])
ans = ""
while N > 0:
    for e in A:
        if dp[N] - 1 == dp[N - cost[e]]:
            if dp[N] == 1:
                if N != cost[e]: continue
            N -= cost[e]
            ans += str(e)
            break
print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
dp = [0]
cost = [0,2,5,5,4,5,6,3,7,6]
for i in range(1, N+1):
    dp.append(-(2<<10))
    for a in A:
        if i >= cost[a]: 
            dp[i] = max(dp[i - cost[a]] + 1, dp[i])
ans = ""
while N > 0:
    for e in A:
        if N >= cost[e] and dp[N] - 1 == dp[N - cost[e]]:
            if dp[N] == 1:
                if N != cost[e]: continue
            N -= cost[e]
            ans += str(e)
            break
print(ans)
n = int(input())
a = input().split()
b = set(a)
if len(b)<len(a):
    print("NO")
else:
    print("YES")

### FIXED CODE ###


s, t = input().split()
a,b = map(int, input().split())
u = input()
res = {
    s: a,
    t: b
}
res[u] -= 1
print(res[s], res[t])
a,b=input().split()
print(a/b)

### FIXED CODE ###

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

lis = [0] * (10000+1)

s  = n**0.5

for i in range(1, s):
    for j in range(1, s):
        for k in range(1, s):
            t = i**2 + j**2 + k**2 + i*j + j*k + i*k
            tmp = [i,j,k]
            
            if t <= 10001:
                if len(set(tmp)) == 1:
                    lis[t-1] = 1
                elif len(set(tmp)) == 2:
                    lis[t-1] = 3
                else:
                    lis[t-1] = 6

for i in range(n):
    print(lis[i])

### FIXED CODE ###

n = int(input())

lis = [0] * (n+1)


for i in range(1, 100):
    for j in range(1, 100):
        for k in range(1, 100):
            t = i**2 + j**2 + k**2 + i*j + j*k + i*k
            tmp = [i,j,k]
            
            if t <= n:
                lis[t] += 1

for i in range(1,n+1):
    print(lis[i])
import math
x=int(input())
x=180-x

ans=360//math.gcd(360,x)

if(ans>=6):
    print(1//0)
else:
    print(ans)

#for i in range(1,180):
#    if(360//math.gcd(360,i)<10):
#        print(i,360//math.gcd(360,i))
#    if(i==x):
#        print("問題の箇所",x,ans)

### FIXED CODE ###

import math
x=int(input())
x=180-x

ans=360//math.gcd(360,x)

ex=[60,120]

if(x in ex):
    x=180-x
    ans=360//math.gcd(360,x)
print(ans)
#for i in range(1,180):
#    if(360//math.gcd(360,i)==6):
#        print(i,360//math.gcd(360,i))
#    if(i==x):
        #print("問題の箇所",x,ans)
a,b,c,d,e=map(int,input().split())

if a=0
    print('1')
if b=0
    print('2')
if c=0
    print('3')
if d=0
    print('4')
if e=0
    print('5')




### FIXED CODE ###

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

if a==0:
    print('1')
if b==0:
    print('2')
if c==0:
    print('3')
if d==0:
    print('4')
if e==0:
    print('5')
k,s = map(int, input().split())

count = 0

for x in range(k+1):
  for i in range(k+1):
    z = S - (x + y)
    
    if 0 <= z <= k:
      count += 1
      
print(count)

### FIXED CODE ###

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

count = 0

for x in range(k+1):
  for y in range(k+1):
    z = s - (x + y)
    
    if 0 <= z <= k:
      count += 1
      
print(count)
N = int(input())

def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]



def insu(num):
    from collections import defaultdict
    primes = get_sieve_of_eratosthenes(int(num**(1 / 2)) + 1)
    res = defaultdict(int)
    for p in primes:
        while num % p == 0:
            res.append(p)
            num //= p
    return res
ins = insu(N)
ans = 0
for v in ins.values():
    counter = 1
    while v >= counter:
        v -= counter
        counter += 1
        ans += 1
print(ans)


### FIXED CODE ###

N = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    divisors.sort()
    return divisors
def is_prime(n):
    if n == 1:
        return False
    for k in range(2, int(n**0.5) + 1):
        if n % k == 0:
            return False
    return True

def insu(num):
    from collections import defaultdict
    div_prime = [d for d in make_divisors(num) if is_prime(d)]
    res = defaultdict(int)
    for d in div_prime:
        while num % d == 0:
            num //= d
            res[d] += 1
    return res
ins = insu(N)
ans = 0
for v in ins.values():
    counter = 1
    while v >= counter:
        v -= counter
        counter += 1
        ans += 1
print(ans)
def check(s):
  for i in range(1, len(s)):
    if i - 1 in s[i:]:
      return "no"
  return "yes"

s = input()
print(check(s))

### FIXED CODE ###

def varied(s):
	for i in range(1, len(s)):
		if s[i-1] in s[i:]:
			return "no"
	return "yes"

s = input()
print(varied(s))
a,b,n=map(int,input().split())
max=0
for i in range(1,n+1):
    if a%b*i%b!=0:
        if a%b*i%b<a%b
            ans=a*i//b -a*(i//b)
            if max<ans:
                max=ans

print(max)

### FIXED CODE ###

# a,b,n=map(int,input().split())
# max=0
# for i in range(1,n+1):
#     if a%b*i%b<i%b:
#         ans=a*i//b -a*(i//b)
#         if max<ans:
#             max=ans

# print(max)

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

if b>n:
    x=n
    ans=(a*x)//b -a*(x//b)

else:
    x=b-1
    ans=(a*x)//b -a*(x//b)

print(ans)
T = input()
ans = ""
i = 0
while i < len(T)-1:
    if T[i] == "D":
        if T[i+1] != "D":
            ans += "DP"
        else:
            ans += "DD"
        i += 1
    elif T[i] == "P":
        if T[i+1] == "D":
            ans += "PD"
            i += 1
        elif T[i+1] == "?":
            ans += "PD"
            i += 1
        else:
            ans += "P"
    else:
        if T[i+1] == "D":
            ans += "PD"
            i += 1
        elif T[i+1] == "P":
            ans += "D"
        else:
            if ans[-1] == "D":
                ans += "P"
            else:
                ans += "D"
    i += 1
if len(ans) != len(T):
    if T[-1] == "P":
        ans += "P"
    else:
        ans += "D"
print(ans)

### FIXED CODE ###

T = input()
ans = ""
# i = 0
# while i < len(T)-1:
#     if T[i] == "D":
#         ans += "D"
#     elif T[i] == "P":
#         ans += "P"
#     else:
#         if ans == "":
#             ans += "D"
#         elif ans[-1] == "P":
#             ans += "D"
#         else:

#     i += 1
# if len(ans) != len(T):
#     if T[-1] == "P":
#         ans += "P"
#     else:
#         ans += "D"
for i in range(len(T)):
    if T[i] == "?":
        ans += "D"
    else:
        ans += T[i]
print(ans)
from itertools import product
n,m = map(int,(input().split()))
sw =[list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

ans = 0
for bit in product([0, 1], repeat=n):
    onoff = [1] * n # 1がon 0がoff
    ele = True
    for i, j in enumerate(bit):
        if j == 1:
            onoff[i] = 0
    #switchの状態を確認
    #print(bit,i,j)
    for k in range(m):
        cnt = 0
        #print(onoff)
        for l in range(sw[0][k]): #電球のループ
            if onoff[sw[k][l]-1]  == 1:
                cnt += 1
        if cnt % 2 != p[k]:
            ele = False
            break
    if ele :
        ans += 1

        
print(ans)

### FIXED CODE ###

import itertools
n,m = map(int,(input().split()))
sw =[list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
result = 0

for i in itertools.product([0, 1], repeat=n):
    onof = True
    for j in range(m):
        counter = 0
        for k in sw[j][1:]:
            counter += i[k-1]
        if counter % 2 != p[j]:
            onof = False
            break
    if onof:
        result += 1
print(result)
w,h,x,y,r=map(int,input().split())
if x<r or y<r or x+r>w or y+r>h:
    print("No")
else:



### FIXED CODE ###

w,h,x,y,r=map(int,input().split())
if x<r or y<r or x+r>w or y+r>h:
    print("No")
else:
    print("Yes")
n,m = map(int,input().split())


def judge():
    ans="-"*n
    for i in range(m):
        s,c = map(int,input().split())
        if ans[s-1]!="-" and int(ans[s-1])!=c:
            return -1
        else:
            a = list(ans)
            a[s-1] = str(c)
            ans = "".join(a)
    ans=ans.replace("-","0")
    if ans[s-1]==str(0):
        if n==0:
            return 0
        else:
            return -1
    return ans

print(judge())

### FIXED CODE ###

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


def judge():
    ans="-"*n
    if m==0:
        if n==1:
            return 0
    for i in range(m):
        s,c = map(int,input().split())
        if ans[s-1]!="-" and int(ans[s-1])!=c:
            return -1
        else:
            a = list(ans)
            a[s-1] = str(c)
            ans = "".join(a)
    if ans[0]=="-":
        a=list(ans)
        a[0]="1"
        ans="".join(a)
    ans=ans.replace("-","0")
    # print(ans[0])
    if ans[0]==str(0):
        if n==1:
            return 0
        else:
            return -1
    return ans

print(judge())
import math
# 二分探索で効率的に数値を探す。
A, B, X  = map(int,input().split())

def buy(N):
    if N <= 0:
        return 0
    else:
        s = A*N + B*((math.log10(N)//1)+1)
        return int(s)

n = 10**9
L = 1
H = n
if buy(n) <= X:
    print(n)
elif buy(1) > X:
    print(0)
else:
    while H - L > 1:
        mid = int((L+H)/2)
        if buy(mid) <= X:
            L = mid
        elif buy(mid) > X:
            H = mid
    print(L)

### FIXED CODE ###

S = str(input())
day = 0
if S == "SUN":
    day = 7
elif S == 'MON':
    day = 6
elif S == 'TUE':
    day = 5
elif S == 'WED':
    day = 4
elif S == 'THU':
    day = 3
elif S == 'FRI':
    day = 2
elif S == 'SAT':
    day = 1
print(day)
a,b = map(int,input().split())
if (a+b) % 2 == 0:
  print((abs(x)+abs(y))//2)
else:
  print('IMPOSSIBLE')

### FIXED CODE ###

A,B=map(int,input().split())
 
if((A+B)%2==0):
    print((A+B)//2)
else:
    print("IMPOSSIBLE")
n = list(map(int,input().split()))
 if n.count(int 5) == 2 and n.count(int 7) == 1:
    print("YES")
  else:
    print("NO")
 

### FIXED CODE ###

n = list(map (int, input().split()))
if n.count(int (5)) == 2 and n.count(int (7)) == 1:
  print("YES")
else:
  print("NO")
import functools


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    a = list(map(lambda x: int(x), inputs))
    a[1] = -1
    return wh(a, 2, 0, len(a))


def wh(a, search, count, N):
    counts = []

    if search == 1:
        return count
    elif count > N:
        return -1

    for i, value in enumerate(a):
        if value == search:
            counts.append(wh(a, i + 1, count + 1, N))

    counts_ignore_minus = list(filter(lambda x: x != -1, counts))

    if len(counts_ignore_minus) == 0:
        return -1

    min = counts_ignore_minus[0]
    for c in counts_ignore_minus:
        if min > c:
            min = c
    return min


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)


### FIXED CODE ###

import functools


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    a = list(map(lambda x: int(x), inputs))

    count = 0
    light = 1
    N = len(a)
    while 1:
        next_light = a[light - 1]
        count += 1
        if next_light == 2:
            return count
        elif count > N:
            return -1
        light = next_light


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)
import sys


def check(t):
    maxx, minx, maxy, miny = -1e9, 1e9, -1e9, 1e9
    for x, y in dots['R']:
        maxx = max(maxx, x + t)
        minx = min(minx, x + t)
        maxy = max(maxy, y)
        miny = min(miny, y)
    for x, y in dots['L']:
        maxx = max(maxx, x - t)
        minx = min(minx, x - t)
        maxy = max(maxy, y)
        miny = min(miny, y)
    for x, y in dots['U']:
        maxx = max(maxx, x)
        minx = min(minx, x)
        maxy = max(maxy, y + t)
        miny = min(miny, y + t)
    for x, y in dots['D']:
        maxx = max(maxx, x)
        minx = min(minx, x)
        maxy = max(maxy, y - t)
        miny = min(miny, y - t)
    return (maxx - minx) * (maxy - miny)


n = int(input())
dots = {'R': set(), 'L': set(), 'U': set(), 'D': set()}
for line in sys.stdin():
    x, y, d = line.rstrip().split()
    x, y = int(x), int(y)
    dots[d].add((x, y))

l = 0
r = 2 * (10 ** 8)

while l < r:
    m1 = (l + r) / 2
    m2 = m1 + 0.5
    c1 = check(m1)
    c2 = check(m2)
    if c1 > c2:
        l = m1
    else:
        r = m2

ans = 10 ** 18
l = int(l * 2) / 2
while l <= r:
    ans = min(ans, check(l))
    l += 0.5
print(ans)


### FIXED CODE ###

import sys

from math import floor


def check(t):
    maxx, minx, maxy, miny = ud_maxx, ud_minx, lr_maxy, lr_miny
    for x, y in dots['R']:
        maxx = max(maxx, x + t)
        minx = min(minx, x + t)
    for x, y in dots['L']:
        maxx = max(maxx, x - t)
        minx = min(minx, x - t)
    for x, y in dots['U']:
        maxy = max(maxy, y + t)
        miny = min(miny, y + t)
    for x, y in dots['D']:
        maxy = max(maxy, y - t)
        miny = min(miny, y - t)
    return (maxx - minx) * (maxy - miny)


n = int(input())
dots = {'R': set(), 'L': set(), 'U': set(), 'D': set()}
lr_maxy, lr_miny, ud_maxx, ud_minx = -1e9, 1e9, -1e9, 1e9
for line in sys.stdin:
    x, y, d = line.rstrip().split()
    x, y = int(x), int(y)
    dots[d].add((x, y))
    if d in 'LR':
        lr_maxy = max(lr_maxy, y)
        lr_miny = min(lr_miny, y)
    else:
        ud_maxx = max(ud_maxx, x)
        ud_minx = min(ud_minx, x)

l = 0.0
r = float(1 << 30)

while l < r - 1:
    m1 = l + floor((r - l) / 3 * 2) / 2
    m2 = l + floor((r - l) / 3 * 4) / 2
    c1 = check(m1)
    c2 = check(m2)
    # print(l, r, m1, m2, c1, c2)
    if c1 >= c2:
        l = m1
    else:
        r = m2

ans = float(1e17)
l = max(0.0, floor(l * 2 - 16) / 2)
while l <= r + 8:
    ans = min(ans, check(l))
    l += 0.5
print(ans)
import numpy

### FIXED CODE ###

n = int(input())
a = map(int, input().split())
result = a.__next__()

for nb in a:
    na = result
    result *= nb
    while nb > 0:
        na, nb = nb, na%nb
    result //= na

print(result)
#################################
#配列を二つに分ける
#引数
# values: 配列
# a,b   : 配列の格納先
#戻り値
# なし
#################################
def separate(values,a,b):
    for v in values:
        a.append(v)
        a,b = b,a


##############################
#登場回数の多い数と登場回数を返す
#引数
# values: ソートされた配列
#戻り値
# 辞書型配列
##############################
def getCount(values):
    currentNum=0
    currentCount=0
    ret={'First' :{'Num':[],'Cnt':0},
         'Second':{'Num':[],'Cnt':0}}
    for v in values:
        if v==currentNum:
            currentCount+=1
        else:
            #別の数字が表れた場合
            if ret['First']['Cnt'] < currentCount:
                #最大値より大きい場合、それが新たな最大値になる
                ret['Second']=ret['First'].copy()
                ret['First']={'Num':[currentNum],'Cnt':currentCount}
            elif ret['First']['Cnt'] == currentCount:
                #最大値タイ
                ret['First']['Num'].append(currentNum)
            elif ret['Second']['Cnt'] < currentCount:
                #2番目より大きい場合、それが新たな2番目になる。
                ret['Second']={'Num':[currentNum],'Cnt':currentCount}
            elif ret['Second']['Cnt'] == currentCount:
                #2位タイ
                ret['Second']['Num'].append(currentNum)

            currentNum=v
            currentCount=1

    #配列の最後まで来た場合
    if ret['First']['Cnt'] < currentCount:
        ret['Second']=ret['First'].copy()
        ret['First']={'Num':[currentNum],'Cnt':currentCount}
    elif ret['First']['Cnt'] == currentCount:
        ret['First']['Num'].append(currentNum)
    elif ret['Second']['Cnt'] < currentCount:
        ret['Second']={'Num':[currentNum],'Cnt':currentCount}
    elif ret['Second']['Cnt'] == currentCount:
        ret['Second']['Num'].append(currentNum)

    return ret


#############################
# メイン
#############################
n = input()
vars = input ()
a=[]
b=[]
varArray=vars.split(" ")
separate(varArray,a,b)
a.sort()
b.sort()
a_result=getCount(a)
b_result=getCount(b)
if (len(a_result['First']['Num'])>1 or
    len(b_result['First']['Num'])>1):
    #最頻値が複数ある場合は素直に計算可
    xa=len(a)-a_result['First']['Cnt']
    xb=len(b)-b_result['First']['Cnt']
    x=xa+xb
else:
    #abどちらも最頻値が1種類の場合
    if a_result['First']['Num'][0]!=b_result['First']['Num'][0]:
        #abの最頻値が異なる場合は素直に計算可
        xa=len(a)-a_result['First']['Cnt']
        xb=len(b)-b_result['First']['Cnt']
        x=xa+xb
    else:
        #abの最頻値が同じ値の場合、どちらかは2番目の値を採用する必要あり
        xaa=len(a)-a_result['First']['Cnt']
        xab=len(b)-b_result['Second']['Cnt']
        xa=xaa+xab
        xba=len(a)-a_result['Second']['Cnt']
        xbb=len(b)-b_result['First']['Cnt']
        xb=xba+xbb
        x=xa if xa<xb else xb

print(x)


### FIXED CODE ###

n=int(input())
d=1
for i in range(3):
    x=n//d%10
    if x==1:
        n+=8*d
    elif x==9:
        n-=8*d
    d*=10

print(n)
import numpy as np
N,K = map(int,input().split())
A = list(map(int,input().split()))
already_town =[1]
now_town=1
count = 0
for i in range(K):
    already_town.append(A[now_town-1])
    now_town = A[now_town-1]
    count =i+1
    if(len(set(already_town))!=len(already_town)):
        break
beark_len=len(already_town)-1
cicle_start=already_town.index(already_town[-1])

print(already_town[(K)%(count-already_town.index(already_town[-1]))])


### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
already_town_check =[False]*(N+1)
already_town_check[1] = True
already_town = [1]
now_town=1
check=False
my_append = already_town.append
for i in range(K):
    check_town=A[now_town-1]
    if(already_town_check[check_town]):
        cicle_start_value=check_town
        check=True
        break
    already_town_check[check_town]=True
    my_append(check_town)
    now_town = check_town

if(check==False):
    print(now_town)
else:
    cicle_start=already_town.index(cicle_start_value)
    roop_town=already_town[cicle_start:]
    print(roop_town[(K-cicle_start)%((i+1)-cicle_start)])
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
suf = 0
for i in range (n):
  men1 = a[i]
  men2 = a[i + 1] 
  suf += b[men1]
  if (men1 != n - 1 )and(men1 + 1 == men2):
    suf += c[men1]
print(suf)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
suf = 0
for i in range (n):
  suf += b[i]
  if i >= 1 and a[i - 1]  + 1 == a[i]:
    suf += c[a[i - 1] - 1]
print(suf)