Harryxun/stf_run huggingface dataset:
s = input()
s = s.split(" ")
N = s[0]
K = int(s[1])

s = input()
s = s.split(" ")
ds = [int(digit) for digit in s]

minNum = min([digit for digit in range(0, 10) if digit not in ds])
maxNum = max([digit for digit in range(0, 10) if digit not in ds])

digits = [int(digit) for digit in N]

result = N
for index in range(0, len(digits)):
  digit = digits[index]
  if digit in ds:
    i = index
    if digit > maxNum:
      i = index - 1
      while i >= 0 and digits[i] == maxNum:
        i -= 1
    
    if i < 0:
      result = str(minNum) * (len(N) + 1)
    else:
      biggerDigit = min([d for d in range(0, 10) if d not in ds and d > digits[i]])
      result = N[:i] + str(biggerDigit) + (str(minNum) * (len(N) - i - 1))

print(result)


### FIXED CODE ###

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

s = input()
s = s.split(" ")
ds = [int(digit) for digit in s]

minNum = min([digit for digit in range(0, 10) if digit not in ds])
nonZerominNum = min([digit for digit in range(1, 10) if digit not in ds])
maxNum = max([digit for digit in range(0, 10) if digit not in ds])

digits = [int(digit) for digit in N]

result = N
for index in range(0, len(digits)):
  digit = digits[index]
  if digit in ds:
    i = index
    if digit > maxNum:
      i = index - 1
      while i >= 0 and digits[i] == maxNum:
        i -= 1
    
    if i < 0:
      result = str(nonZerominNum) + (str(minNum) * len(N))
    else:
      biggerDigit = min([d for d in range(0, 10) if d not in ds and d > digits[i]])
      digits[i] = biggerDigit
      for j in range(i+1, len(digits)):
        digits[j] = minNum
      result = "".join([str(digit) for digit in digits])
    break

print(result)
h, w = map(int, input().split())

print(h*w, 2*h+2*w)



### FIXED CODE ###

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

print(h*w, 2*h+2*w)
a1 = list(map(int,input().split()))
a2 =list(map(int,input().split()))
a3 =list(map(int,input().split()))
n = int(input())
b = []

for i in range(1,n + 1):
    bc = int(input())
    b.append(bc)

for i in range(n):
    for m in range(3):
        if a1[m] == b[i]:
            a1[m] = 0
        elif a2[m] == b[i]:
            a2[m] = 0
        elif a3[m] == b[i]:
            a3[m] = 0

for i in range(3):
    if a1[i] == 0 and a2[i] == 0 and a3[i] == 0:
        print('縦')
        exit()

if a1.count(0) == 3 or a2.count(0) ==3 or a3.count(0) == 3:
    print('横')
    exit()

if a2[2] == 0:
    if a1[1] == 0 and a3[3] == 0 or a3[1] ==0 and a1[3] == 0:
        print('斜め')
        exit()

print('No')

### FIXED CODE ###

A = []
a1 = []
a2 = []
a3 = []
for i in range(3):
    a = list(map(int,input().split()))
    for K in range(3):
        A.append(a[K])


N = int(input())
for i in range(N):
    b = int(input())
    for k in range(9):
        if b == A[k]:
            A[k] = 0




for i in range(9):
    if 0 <= i <= 2:
        a1.append(A[i])
    elif 3 <= i <= 5:
        a2.append(A[i])
    else:
        a3.append(A[i])

x = 0
y = 0
z = 0
for i in range(3):
    if a1[i] == 0:
        x += 1
    if a2[i] == 0:
        y += 1
    if a3[i] == 0:
        z += 1

if x == 3 or y == 3 or z == 3:
    print('Yes')
    exit()

for i in range(3):
    if a1[i] == 0 and a2[i] == 0 and a3[i] == 0:
        print('Yes')
        exit()

if a2[1] == 0:
    if a1[0] == 0 and a3[2] == 0 or a1[2] == 0 and a3[0] == 0:
        print('Yes')
        exit()

print('No')
# -*- coding: utf-8 -*-
import random
random.seed(0)

D = int(input())
C = list(map(int, input().split()))
list_S = [list(map(int, input().split())) for _ in range(D)]

answer = []
L = [0 for _ in range(26)]
for S in list_S:
  contest_index = -1
  contest_manzoku = -10**9
  for i in range(26):
    i_manzoku = S[i]+C[i]+L[i]
    if i_manzoku > contest_manzoku:
      contest_index = i
      contest_manzoku = i_manzoku
  answer.append(contest_index)
  for i in range(26):
    if i==contest_index:
      L[i] = 0
    else:
      L[i] += C[i]

def manzoku(A):
  score = 0
  L = [0 for _ in range(26)]
  for i in range(D):
    contest_index = A[i]
    for j in range(26):
      if j==contest_index:
        L[j] = 0
        score += S[i][contest_index]
      else:
        L[j] += C[j]
        score -= L[j] 
  return score

manzoku_now = manzoku(answer)
answer_tmp = [answer[i] for i in range(D)]
for j in range(365):
  day = j%D
  contest = random.randrange(26)
  answer_tmp = [answer[i] for i in range(D)]
  answer_tmp[day] = contest
  manzoku_tmp = manzoku(answer_tmp)
  if manzoku_now < manzoku_tmp:
    manzoku_now = manzoku_tmp
    answer[day] = contest
  else:
    answer_tmp[day] = answer[day]

for index in answer:
  print(index+1)

### FIXED CODE ###

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

D = int(input())
C = list(map(int, input().split()))
L = [0 for _ in range(26)]

for _ in range(1,D+1):
  S = list(map(int, input().split()))
  contest_index = -1
  contest_manzoku = -10**9
  for i in range(26):
    i_manzoku = S[i]+C[i]+L[i]
    if i_manzoku > contest_manzoku:
      contest_index = i
      contest_manzoku = i_manzoku
  print(contest_index+1)
  for i in range(26):
    if i==contest_index:
      L[i] = 0
    else:
      L[i] += C[i]
File Edit Options Buffers Tools Python Help                                                                            
import numpy as np

a, b, c = map(int, raw_input().split())

if b > a:
    temp = a
    a = b
    b = temp

res = c - a
res = res - b
temp = 4*a*b

if res**2 > temp:
    print "Yes"
else:
    print "No"


### FIXED CODE ###

import numpy as np

a, b, c = map(int, raw_input().split())

if b > a:
    temp = a
    a = b
    b = temp

res = c - a
res = res - b
temp = 4*a*b


if res <0:
    print "No"
elif res**2 > temp:
    print "Yes"
else:
    print "No"
#coding: utf-8
N = int(input())
ans = 0
l_B = 0
r_A = 0
lbra = 0
for _ in range(N):
	tmp = input()
	ans += tmp.count("AB")
	if tmp[0] == "B":
		if tmp[-1] == "A":
			lbra += 1
		else:
			l_B += 1
	elif tmp[-1] == "A":
		r_A += 1
l.sort()
print(ans + lbra + min(l_B, r_A))

### FIXED CODE ###

#coding: utf-8
N = int(input())
ans = 0
l_B = 0
r_A = 0
lbra = 0
for _ in range(N):
	tmp = input()
	ans += tmp.count("AB")
	if tmp[0] == "B":
		if tmp[-1] == "A":
			lbra += 1
		else:
			l_B += 1
	elif tmp[-1] == "A":
		r_A += 1
        
if lbra == 0:
    ans += min(l_B, r_A)
else:
    if l_B + r_A > 0:
        ans += lbra + min(l_B, r_A)
    else:
        ans += lbra - 1
print(ans)
A, B, K = map(int, input().split())
nums = []
num_range = list(range(A, B + 1))
if A == B:
    print(A)
else:
    for i in range(K if len(num_range) > K else len(num_range)):
        nums.append(num_range[i])
        nums.append(num_range[- (i + 1)])
    for num in sorted(list(set(nums))):
        print(num)


### FIXED CODE ###

A, B, K = map(int, input().split())
num_range = range(A, B + 1)
for i in sorted(set(num_range[:K]) | set(num_range[-K:])):
    print(i)
from collections import deque


def inside(x, l, r):
    return l <= x < r


H, W = map(int, input().split())
A = [list(input()) for i in range(H)]
qu = deque()

rest = H * W
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            rest -= 1
            qu.put((i, j))

ans = 0
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
while True:
    if rest == 0:
        break
    ans += 1
    qu2 = deque()
    while qu:
        i0, j0 = qu.get()
        for k in range(4):
            ni = i0 + dx[k]
            nj = j0 + dy[k]
            if not (inside(ni, 0, H) and inside(nj, 0, W)):
                continue
            if A[ni][nj] == '.':
                A[ni][nj] = '#'
                rest -= 1
                qu2.put((ni, nj))
    qu = qu2
print(ans)


### FIXED CODE ###

# 参考

import numpy

H, W = map(int, input().split())
values = [None] * H

for y in range(H):
    values[y] = [0 if v == "#" else H + W for v in input()]
values = numpy.array(values)

for x in range(W - 1):
    values[:, x + 1] = numpy.minimum(values[:, x] + 1, values[:, x + 1])

for x in range(W - 1, 0, -1):
    values[:, x - 1] = numpy.minimum(values[:, x] + 1, values[:, x - 1])

for y in range(H - 1):
    values[y + 1, :] = numpy.minimum(values[y, :] + 1, values[y + 1, :])

for y in range(H - 1, 0, -1):
    values[y - 1, :] = numpy.minimum(values[y, :] + 1, values[y - 1, :])

print(numpy.max(values))
#input = raw_input

res = None
G = None

def dfs(jibun_v, p, jibun_c):
    global res
    global G

    res[jibun_v] = jibun_c
    #print(jibun_v, p, jibun_c)

    tonari_nodes = G[jibun_v]
    for tonari_v, w in tonari_nodes:
        if tonari_v == p:
            continue

        if w % 2 == 0:
            tonari_c = jibun_c
        else:
            tonari_c = 1 - jibun_c

        dfs(tonari_v, jibun_v, tonari_c)
    

def main():
    N= int(input())

    global G
    G = [[] for _ in range(N)]

    for i in range(N-1):
        u, v, w = map(int, input().split(" "))
        u -= 1
        v -= 1
        w = w % 2
        G[u].append([v, w])
        G[v].append([u, w])

    global res
    res = [-1 for _ in range(N)]
    
    jibun_v = 0
    p = -1
    jibun_c = 0
    dfs(jibun_v, p, jibun_c)

    for i in range(N):
        print(res[i])

main()
        

### FIXED CODE ###

import sys
if sys.version_info[0] == 2:
    input = raw_input
sys.setrecursionlimit(2 ** 31 -1)

res = None
G = None

def dfs(jibun_v, p, jibun_c):
    global res
    global G

    res[jibun_v] = jibun_c
    #print(jibun_v, p, jibun_c)

    tonari_nodes = G[jibun_v]
    for tonari_v, w in tonari_nodes:
        #if tonari_v == p: # only no loop
        #if tonari_v == p or res[tonari_v] != -1:
        if res[tonari_v] != -1:
            continue

        else:
            if w % 2 == 0:
                tonari_c = jibun_c
            else:
                tonari_c = 1 - jibun_c

            dfs(tonari_v, jibun_v, tonari_c)
    

def main():
    N= int(input())

    global G
    G = [[] for _ in range(N)]

    for i in range(N-1):
        u, v, w = map(int, input().split(" "))
        u -= 1
        v -= 1
        w = w % 2
        G[u].append([v, w])
        G[v].append([u, w])

    global res
    res = [-1 for _ in range(N)]
    
    jibun_v = 0
    p = -1
    jibun_c = 0
    dfs(jibun_v, p, jibun_c)

    for i in range(N):
        print(res[i])

main()
import math
from functools import reduce
def func():
    n,x0 = map(int,input().split())
    x = [int(i) for i in input().split()]
    x.append(x0)
    x.sort()
    x.reverse()
    
    l = []
    before = 0
    before = None
    for xi in x:
        if before == None:
            before = xi
            continue
        l.append(xi-before)
        before = xi
    
    print(reduce(math.gcd,l))
func()

### FIXED CODE ###

import fractions
from functools import reduce
def func():
    n,x0 = map(int,input().split())
    x = [int(i) for i in input().split()]
    x.append(x0)
    x.sort()
    x.reverse()
    
    l = []
    before = 0
    before = None
    for xi in x:
        if before == None:
            before = xi
            continue
        l.append(xi-before)
        before = xi
    
    print(abs(reduce(fractions.gcd,l)))
func()
def actual(a, b, k):
    if a >= k:
        # return f'{a - k} {b}'
        return '{} {}'.format((a - k), b)

    if b > (k - a):
        # return f'0 {b - (k - a)}'
        return f'0 {}'.format(b - (k - a))

    return '0 0'

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

### FIXED CODE ###

def actual(a, b, k):
    if a >= k:
        # return f'{a - k} {b}'
        return '{} {}'.format((a - k), b)

    if b > (k - a):
        # return f'0 {b - (k - a)}'
        return '0 {}'.format(b - (k - a))

    return '0 0'

a, b, k = map(int, input().split())
print(actual(a, b, k))
from sys import stdin
import sys
n, m = map(int, stdin.readline().split())
edges = [set() for _ in range(n)]
for _ in [0] * m:
    s, t = map(int, stdin.readline().split())
    edges[s].add(t)
    edges[t].add(s)
prenum = [None] * n
parent = [None] * n
lowest = [None] * n
counter = 0
def dfs(cur, prev):
    global counter
    prenum[cur] = lowest[cur] = counter
    counter += 1
    for edge in edges[cur]:
        if prenum[edge] is not None:
            if edge != prev:
                lowest[cur] = min(lowest[cur], prenum[edge])
            continue
        parent[edge] = cur
        dfs(edge, cur)
        lowest[cur] = min(lowest[cur], lowest[edge])
dfs(0, 1)
ap = [False] * n
r = 0
for _ in filter(lambda x: x == 0, parent):
    r += 1
    if r > 1:
        ap[0] = True
        break
for i in range(1, n):
    p = parent[i]
    if p and prenum[p] <= lowest[i]:
        ap[p] = True
for i, e in enumerate(ap):
    if e: print(i)

### FIXED CODE ###

from sys import stdin
import sys
from math import isinf
INF = float("inf")
sys.setrecursionlimit(100000)
def dfs(v, tm):
    dts[v] = est[v] = tm + 1
    child = 0
    for i in adj[v]:
        if est[i] == float('inf'):
            child += 1
            parents[i] = v
            dfs(i, tm + 1)
            est[v] = min(est[v], est[i])
            if parents[v] is None and child > 1: aps[v] = True
            if parents[v] is not None and est[i] >= dts[v]: aps[v] = True
        elif parents[v] != i:
            est[v] = min(est[v], dts[i])
n, m = map(int, stdin.readline().split())
adj = [[] for _ in range(n)]
est = [float('inf')] * n
parents = [None] * n
aps = [False] * n
dts = [0] * n
for _ in range(m):
    s, t = map(int, stdin.readline().split())
    adj[s].append(t)
    adj[t].append(s)
dfs(0, 0)
for i in range(n):
    if aps[i]:
        print(i)
import math
A,B = list(map(float,input().split()))
print(math.floor((A*(B*100))/100)

### FIXED CODE ###

import decimal
import math
A,B = input().split()
A = int(A)
B = decimal.Decimal(B)
print(math.floor(A*B))
n=input()
b=list(map(int,input(). split ()))
c=1
if 0 in b:
  print(0)
else:
  c=1
  for i in b:
    c=c*i
    if c>10**18:
      print(-1)
      return
print(c)

### FIXED CODE ###

n=int(input())
a=list(map(int, input().split( )))
if 0 in a:
  print(0)
  
else:
    c=1
    for i in a:
        c= c*i
        if c> 10**18:
            c=-1
            break
    print(c)
# -*- coding: utf-8 -*-

def main():
    h, w = map(int, raw_input().split())

    square = []
    for i in range(h):
        square.append(raw_input())

    for i in range(h):
        for j in range(w):
            if square[i][j] == '.':
                continue
            else:
                if check(square, i, j, h, w):
                    continue
                else:
                    print("No")
                    exit()

    print("Yes")

def check(square, i, j, h, w):
    if i-1 >= 0:
        if square[i-1][j] == '#':
            return True
    if i+1 < h:
        if square[i+1][j] == '#':
            return True
    if j-1 >= 0:
        if square[i][j-1] == '#':
            return True
    if j+1 < w:
        if square[i][j+1] == '#':
            return True

    return False

if __name__ == '__main__':
    main()


### FIXED CODE ###

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

def main():
    a, b = map(int, raw_input().split())

    if a <= b:
        print(a)
    else:
        print(a-1)

if __name__ == '__main__':
    main()
while True:
 a,op,b = map(int,raw_input().split())

 if(op=='*'):
  print '%d'%(a*b)
 elif(op=='/'):
  print a/b
 elif(op==+):
  x=a+b
  print x
 elif(op==-):
  x=a-b
  print x
 else:
  break
 

### FIXED CODE ###

while True:
 a,op,b = map(str,raw_input().split())
 a=int(a)
 b=int(b)

 if(op=='?'):
  break
 if(op=='+'):
  print a+b
 elif(op=='-'):
  print a-b
 elif(op=='*'):
  print a*b
 elif(op=='/'):
  print a/b
# 文字が2種類になるまで減る
# 2種類になったら終了
# 両端の文字が違うならその2種類が残る→偶数個残る
# 両端の文字が同じならその文字+1種→奇数個残る

s = input()
iseven = len(S)&1==0
issame = S[0]==S[-1]
print('First' if iseven^issame else 'Second')

### FIXED CODE ###

# 文字が2種類になるまで減る
# 2種類になったら終了
# 両端の文字が違うならその2種類が残る→偶数個残る
# 両端の文字が同じならその文字+1種→奇数個残る

s = input()
iseven = len(s)&1==0
issame = s[0]==s[-1]
print('Second' if iseven^issame else 'First')
S = list(map(int, input().rstrip()))
for i in range(4):
  if S[i]==S[i+1]:
    print("Bad")
    exit()
print("Yes")

### FIXED CODE ###

S = list(map(int, input().rstrip()))
for i in range(3):
  if S[i]==S[i+1]:
    print("Bad")
    exit()
print("Good")
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
Z = []
for i in range(1, N):
    Z.append(abs(A[i] - A[i - 1]))
Z.sort()
i = 0
while True:
    if i <= len(A):
        break
    if Z[i] == 0:
        del Z[i]
        i -= 1
    i += 1
    
ans = -1
for i in range(1, len(Z)):
    if Z[i - 1] % Z[i] != 0:
        ans = 1
        break
for i in A:
    if K == i:
        ans = 1
if K >= max(A):
    ans = -1
if ans == -1:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")


### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
import copy
Z = copy.deepcopy(A)
#for i in range(1, N):
 #   Z.append(abs(A[i] - A[i - 1]))
Z.sort()
i = 0

while True:
    if i >= len(Z):
        break
    if Z[i] == 0:
        del Z[i]
        i -= 1
    elif i > 0 and Z[i] == Z[i - 1]:
        del Z[i]
        i -= 1
    i += 1

ans = -1

import fractions
gcd = Z[0]
for i in range(1, len(Z)):
    gcd = fractions.gcd(gcd, Z[i])

if K % gcd == 0:
    ans = 1
    
if K > max(A):
    ans = -1
       
for i in A:
    if K == i:
        ans = 1
        break

if ans == -1:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")
import sys
from itertools import combinations, permutations, product, combinations_with_replacement, accumulate
from heapq import heapify, heappop, heappush, heappushpop
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from math import sqrt, log, floor, ceil, factorial, cos, sin, pi, gcd
from collections import deque
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
INF = float('inf')
LINF = 2**63-1
NIL = -LINF
MOD = 10**9+7
MGN = 4
def II(): return int(input())
def IF(): return float(input())
def IS(): return input().replace('\n', '')
def ILCI(n: int): return [II() for _ in range(n)]
def ILCF(n: int): return [IF() for _ in range(n)]
def ILI(): return list(map(int, input().split()))
def ILLI(n: int): return [[int(j) for j in input().split()] for i in range(n)]
def ILF(): return list(map(float, input().split()))
def ILLF(n: int): return [[float(j) for j in input().split()] for i in range(n)]
def LTOS(lst: list, sep: str = ' '): return sep.join(map(str, lst))
def DEC(lst: list): return list(map(lambda x: x-1, lst))
def INC(lst: list): return list(map(lambda x: x+1, lst))


def main():
    S = IS()

    ans = "Yes"
    if S[0] == S[1] and S[1] == S[2]:
        ans = "No"
    
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
INF = float('inf')
LINF = 2**63-1
NIL = -LINF
MOD = 10**9+7
MGN = 4
def II(): return int(input())
def IF(): return float(input())
def IS(): return str(input())
def ILCI(n: int): return [II() for _ in range(n)]
def ILCF(n: int): return [IF() for _ in range(n)]
def ILI(): return list(map(int, input().split()))
def ILLI(n: int): return [[int(j) for j in input().split()] for i in range(n)]
def ILF(): return list(map(float, input().split()))
def ILLF(n: int): return [[float(j) for j in input().split()] for i in range(n)]
def LTOS(lst: list, sep: str = ' '): return sep.join(map(str, lst))
def DEC(lst: list): return list(map(lambda x: x-1, lst))
def INC(lst: list): return list(map(lambda x: x+1, lst))


def main():
    S = IS()

    ans = "Yes"
    if S[0] == S[1] and S[1] == S[2]:
        ans = "No"
    
    print(ans)


if __name__ == '__main__':
    main()
n,t,a,*h=map(int,open(0).read().spilt())
d,i=10**18,0
for j in range(n):
  if abs(a-t+h[j]*0.006)<d:
    d=abs(a-t+h[j]*0.006)
    i=j
print(i+1)

### FIXED CODE ###

n,t,a,*h=map(int,open(0).read().split())
d,i=10**18,0
for j in range(n):
  if abs(a-t+h[j]*0.006)<d:
    d=abs(a-t+h[j]*0.006)
    i=j
print(i+1)
N, W = list(map(int, input().split()))
w = list()
v = list()

dp = list()

for i in range (0, N):
	inp = list(map(int, input().split()))

	w.append(inp[0])
	v.append(inp[1])	

for i in range (0, N + 1):
	dp.append([0] * ( W + 1 ))

for i in range(0, N):
	for j in range(1, W+1):
		if(j >= w[i]):
			dp[i+1][j] = max(dp[i][j-w[i]] + v[i], dp[i][j])
		else:
			dp[i+1][j] = dp[i][j]

print(dp[N][W])

### FIXED CODE ###

# DP practice
# https://atcoder.jp/contests/dp/tasks/dp_a

# 入力方法としてはこれが手軽
N = int(input())
h = list(map(int, input().split()))

dp = list()

# N = 0, 1 の時の処理も必要。だが省く
dp.append(0)
dp.append(dp[0] + abs(h[1] - h[0]))

for i in range(2, N):
	dp.append(min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1])))


print(dp[N-1])
no=int(input())
s=[*map(int,input().split())]
q=0
p=0
le=len(s)
if no==2:
    print(abs(s[1]-s[0]))
if no==3:
    print(abs(s[2]-s[0]))
else:
    a=abs(s[1]-s[0])
    b=abs(s[2]-s[0])
    if no%2==0:
        for i in range(1,len(s)-1,2):
            q=q+abs(s[i]-s[i+2])
        q+=a
        for k in range(2,len(s)-2,2):
            p=p+abs(s[k]-s[k+2])    
        p+=b
        p=p+(abs((s[le-1])-(s[le-2])))
        print(min(q,p))
    else:
        for i in range(1,len(s)-2,2):
            q=q+abs(s[i]-s[i+2])
        q+=a
        q=q+(abs((s[le-1])-(s[le-2])))
        for k in range(2,len(s)-1,2):
            p=p+abs(s[k]-s[k+2])    
        p+=b
        print(min(q,p))
        

### FIXED CODE ###

no=int(input())
s=list(map(int,input().split()))
a=[0]
a.append(abs(s[1]-s[0]))
for i in range(2,no):
    a.append(min(abs((s[i]-s[i-1]))+a[i-1],abs((s[i]-s[i-2]))+a[i-2]))
print(a[-1])
#!/usr/bin/env python
# -*- coding: utf-8 -*-

(A, B, C) = [int(x) for x in raw_input().split(" ")]

if A == B:
    print(C)
elif A == C:
    print(B)
else:
    print(A)


### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

(A, B, C) = [int(x) for x in input().split(" ")]

if A == B:
    print(C)
elif A == C:
    print(B)
else:
    print(A)
num = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
a = int(input())
print(num[a])


### FIXED CODE ###

num = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
a = int(input())
print(num[a-1])
N, Q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
px = [list(map(int, input().split())) for _ in range(Q)]

root = [[] for _ in range(N)]
result = [0] * N

for i in range(N - 1):
    a = ab[i][0] - 1
    b = ab[i][1] - 1
    root[a].append(b)
    root[b].append(a)

for i in range(Q):
    p = px[i][0] - 1
    x = px[i][1]
    result[p] += x


def dfs(now, prev):
    for next in root[now]:
        if next == prev:
            continue
        else:
            result[next] += result[now]
            dfs(next, now)


dfs(0, -1)
print(*result)

### FIXED CODE ###

N, Q = map(int,input().split()) # 複数の数字を変数に格納
List_ab = [list(map(int,input().split())) for i in range(N-1)] # [[1,2],[3,4],[5,6]]
List_px = [list(map(int,input().split())) for i in range(Q)] # [[1,2],[3,4],[5,6]]

count_list = [0]*N

List_ab.sort()

for i in range(Q):
    count_list[List_px[i][0]-1] += List_px[i][1]
        
for i in range(N-1):
    count_list[List_ab[i][1]-1] += count_list[List_ab[i][0]-1]
    
print(*count_list)
S = [input() for _ in range(3)]

next = 0
lens = [len(i) for i in S]
counts = [0]*3

while True:
  if counts[next] == len[next]:
    if next == 0:
      print('a')
    elif next == 1:
      print('b')
    else:
      print('c')
    exit()
  next = S[next][counts[next]]
  counts[next] += 1

### FIXED CODE ###

S = {}
S['a'] = input()
S['b'] = input()
S['c'] = input()


next = 'a'
lens = {'a':len(S['a']), 'b':len(S['b']), 'c':len(S['c'])}
counts = {'a':0, 'b':0, 'c':0}

while True:
  now = next
  counts[now]
  if counts[now] == lens[now]:
    print(now.upper())
    exit()
  next = S[now][counts[now]]
  counts[now] += 1