Harryxun/stf_run huggingface dataset:
check = 2
kensa = 0
kekka = ""
num = []
hantei = "OK"
INF = input().split()
gyosu = int(INF[1])
keta = int(INF[0])
out = []
for l in range(keta):
  out.append(0)


for i in range(gyosu):
  num.append([int(j) for j in input().split()])

if gyosu >0:
  for j in range(gyosu-1):
    for k in range(gyosu-1):
      if num[j][0] == num[k + 1][0]:
        if num[j][1] != num[k + 1][1]:
          hantei = "NG"
    
    if int(num[j][0]) < check:
      check = int(num[j][0])
if num[check-1][1] == 0:
  hantei ="NG"

if hantei == "NG":
  print("-1")
else:
  for m in range(gyosu):
    
    out[(num[m][0] - 1)] = num[m][1]
    #print(out)
  for n in range(keta):
    kekka = kekka + str(out[n])

  for p  in kekka:
      if p == "0":
        kensa = kensa + 1
      else:
        break
  for q in range(kensa):
    kekka = kekka.lstrip("0")

#    if n == 0 and keta != 1 and gyosu != 0:
      #print("-1")
      #hantei = "NG"

if hantei == "OK":
  if gyosu == 0:
    print(0)
  else:
    print(kekka)

### FIXED CODE ###

check = 0
check2 = 0
kensa = 0
kekka = "" 
num = []
hantei = "OK"
INF = input().split()
gyosu = int(INF[1])
keta = int(INF[0])
out = []
for l in range(keta):
  out.append(0)


for i in range(gyosu):
  num.append([int(j) for j in input().split()])

if gyosu > 0 :
  check = int(num[0][0])
  check2 = int(num[0][1])
  
  for j in range(gyosu-1):
    for k in range(gyosu-1):
      if num[j][0] == num[k + 1][0]:
        if num[j][1] != num[k + 1][1]:
          hantei = "NG"
    
    if int(num[j][0]) < check: # 入力値にある最大桁数を計算
      check = int(num[j][0])
      check2 = int(num[j][1])
  if check2 == 0:
    if check == 1 and keta == 3:
      hantei = "NG"
    if check == 2:
      hantei = "tokubetu2"
    if check == 3:
      hantei = "tokubetu"

if hantei == "NG":
  print("-1")
else:
  for m in range(gyosu):
    
    out[(num[m][0] - 1)] = num[m][1]
  for n in range(keta):
    kekka = kekka + str(out[n])

  for p  in kekka:
      if p == "0":
        kensa = kensa + 1
      else:
        break
  kekka2 = kekka
  for q in range(kensa):
    if keta != 1:
      kekka = kekka.lstrip("0")
if hantei == "OK":
  if gyosu == 0:
    if keta == 1:
      print("0")
    elif keta == 2:
      print("10")
    else:
      print("100")
  else:
    if keta == 2:
      if kensa == 1:
        kekka = "1" + kekka
    if keta == 3:
      if kensa == 1:
        kekka = "1" + kekka
      if kensa == 2:
        kekka = "10" + kekka
    print(kekka)

if hantei == "tokubetu":
  print("0")


if hantei == "tokubetu2":
  #kekka2 = kekka2.lstrip("0")
  kekka2 = kekka2[1:]
  kekka2 = "1" + kekka2
  print(kekka2)
from fractions import gcd

N = int(input())
A = list(map(int,input().split()))
'''
res = 0
for i in range(N):
    tmp = A[i+1:] + A[:i]
    ans = tmp[0]
    for i in range(1,N-1):
        ans = gcd(ans,tmp[i])
    res = max(ans,res)
print(res)
'''

L = [0] * N
R = [0] * N

for i in range(N):
    L[i+1] = gcd(L[i],A[i])
    R[N-i-1] = gcd(R[N-i],A[N-i-1])
ans = 0
for i in range(N):
    ans = max(ans,gcd(L[i],R[i+1]))

print(ans)

### FIXED CODE ###

from fractions import gcd

N = int(input())
A = list(map(int,input().split()))
'''
res = 0
for i in range(N):
    tmp = A[i+1:] + A[:i]
    ans = tmp[0]
    for i in range(1,N-1):
        ans = gcd(ans,tmp[i])
    res = max(ans,res)
print(res)
'''

L = [0] * (N+1)
R = [0] * (N+1)

for i in range(N):
    L[i+1] = gcd(L[i],A[i])
    R[N-i-1] = gcd(R[N-i],A[N-i-1])
ans = 0
for i in range(N):
    ans = max(ans,gcd(L[i],R[i+1]))

print(ans)
a = map(str,input().split)

b = a + 1
i = 0
while i < b:
    c = a[i]
    if c == 7:
        print('yes')
        break
    elif c==a:
          print('no')
        
    i += 1

### FIXED CODE ###

a = input()
if '7' in a:
   print('Yes')
else:
   print('No')
INF = float('inf')
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
c = [0,2,5,5,4,5,6,3,7,6]

dp = [-INF]*(N+1)
dp[0] = 0
for a in A:
    if c[a] <= N:
        dp[c[a]] = 1

for i in range(N+1):
    for a in A:
        if i-c[a]>=0:
            dp[i] = max(dp[i],dp[i-c[a]]+1)

ans = ''
n = N
for a in A:
    while dp[n] == dp[n-c[a]]+1:
        n -= c[a]
        ans = ans + str(a)
print(ans)

### FIXED CODE ###

d = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
d_ = {}
for i in range(M):
    d_[d[A[i]]] = A[i]
diff = [(d_[key],key) for key in d_]
diff.sort()

DP = ['']*(10**4+1)
for a,l in diff:
    DP[l] = str(a)
    
for i in range(N+1):
    for a,l in diff:
        if i-l >= 0:
            if len(DP[i-l])+1>=len(DP[i]) and DP[i-l]!='':
                    DP[i] = str(a)+DP[i-l]

ans = list(DP[N])
ans.sort()
ans.reverse()
ans = ''.join(ans)
print(ans)
import bisect

Q = int(input())

L = [1 for i in range(100001)]
L[0] = 0
L[1] = 0
for i in range(100001):
	if L[i] == 1:
		c = 2
		while True:
			if i * c <= 100000:
				L[i * c] = 0
				c += 1
			else:
				break
p2017 = []
for i in range(3, 100001):
	if i % 2 != 0:
		if L[i] == 1 and L[int((i + 1) // 2)] == 1:
			p2017.append(i)

for i in range(Q):
	l, r = list(map(int, input().split()))
	a = bisect.bisect_left(p2017, l)
	b = bisect.bisect_left(p2017, r)
	if p2017[b] == r:
		b += 1
	print(b - a)

### FIXED CODE ###

import bisect

Q = int(input())

L = [1 for i in range(100001)]
L[0] = 0
L[1] = 0
for i in range(100001):
	if L[i] == 1:
		c = 2
		while True:
			if i * c <= 100000:
				L[i * c] = 0
				c += 1
			else:
				break
p2017 = []
for i in range(3, 100001):
	if i % 2 != 0:
		if L[i] == 1 and L[int((i + 1) // 2)] == 1:
			p2017.append(i)


for i in range(Q):
	l, r = list(map(int, input().split()))
	a = bisect.bisect_left(p2017, l)
	b = bisect.bisect_right(p2017, r)
	print(b - a)
x = int(input())
a = False
while a = True:
  b = range(x) + 1
  c = x/b
  d = [d.is_integer() for d in c[1:-1]]
  if any(d):
    a = True
    break
  x = x + 1
print(x)

### FIXED CODE ###

x = int(input())
a = False
while a == False:
  b = list(range(1,x) ) 
  c = [x/c for c in b]
  d = [d.is_integer() for d in c[1:-1]]
  if not any(d):
    a = True
    break    
  else:
    x = x + 1
print(x)
N/X * T

### FIXED CODE ###

def calculate(N,X,T):
    x = N // X
    if x ==0:
        return T
    elif not N % X == 0:
        return (x + 1)*T;
    else:
        return x*T
N,X,T = map(int,input().split())
result = calculate(N,X,T)
print(result)
def f(x,y,z):
    if x=="S" and y=="o":
        return z
    if x=="S" and y=="x":
        return g(z)
    if x=="W" and y=="o":
        return g(z)
    if x=="W" and y=="x":
        return z
def g(x):
    if x=="S":
        return "W"
    if x=="W":
        return "S"
def check(x,y):
    t[0]=x
    t[1]=y
    for j in range(1,N-1):
        t[j+1] = f(t[j],s[j],t[j-1])
    x1 = f(t[N-1],s[N-1],t[N-2])
    y1 = f(x1,s[0],t[N-1])
    if x==x1 and y==y1:
        return True
    else:
        return False
N = int(input())
s = input().strip()
t = [0 for _ in range(N)]
if check("S","S"):
    print("".join(t))
elif check("S","W"):
    print("".join(t))
elif check("W","S"):
    print("".joint(t))
elif check("W","W"):
    print("".join(t))
else:
    print(-1)

### FIXED CODE ###

def f(x,y,z):
    if x=="S" and y=="o":
        return z
    if x=="S" and y=="x":
        return g(z)
    if x=="W" and y=="o":
        return g(z)
    if x=="W" and y=="x":
        return z
def g(x):
    if x=="S":
        return "W"
    if x=="W":
        return "S"
def check(x,y):
    t[0]=x
    t[1]=y
    for j in range(1,N-1):
        t[j+1] = f(t[j],s[j],t[j-1])
    x1 = f(t[N-1],s[N-1],t[N-2])
    y1 = f(x1,s[0],t[N-1])
    if x==x1 and y==y1:
        return True
    else:
        return False
N = int(input())
s = input().strip()
t = [0 for _ in range(N)]
if check("S","S"):
    print("".join(t))
elif check("S","W"):
    print("".join(t))
elif check("W","S"):
    print("".join(t))
elif check("W","W"):
    print("".join(t))
else:
    print(-1)
#ABC176
#D - Wizard in Maze

h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())
b=[ch-1,cw-1]
a,c,d,f=[],[],[],[]
c.append(b)
d.append(b)
y=0

for i in range(h):
  a.append(list(input()))

warp=0

def def1():
  global c,d
  if 0<=ch1<h and 0<=cw1<w:
    e=[ch1,cw1]
    if a[ch1][cw1]=="." and d not in e:
      c.append(e)
      d.append(e)
def def2():
  global f
  if 0<=ch2<h and 0<=cw2<w:
    e=[ch2,cw2]
    if a[ch2][cw2]=="." and f not in e:
      f.append(e)

while len(c)>0 or len(f)>0 or y==0:
  while len(c)>0 or y==0:
    ch,cw=c[0]
    if ch==dh-1 and cw==dw-1:
        y=1
    if a[ch][cw]==".":
      a[ch][cw]=str(warp)
    c.pop(0)
    ch1,cw1=ch-1,cw
    def1()
    ch1,cw1=ch+1,cw
    def1()
    ch1,cw1=ch,cw-1
    def1()
    ch1,cw1=ch,cw+1
    def1()

    for i in range(5):
      ch2=ch-2+i
      for j in range(5):
        cw2=cw-2+j
        def2()
  for i in f:
    if i not in d:
      c.append(i)
  f=[]
  warp=warp+1
z=a[dh-1][dw-1]
if z==".":
  print(1)
else:
  print(z)

### FIXED CODE ###

n,x,t=map(int,input().split())
a=n//x

if x*a!=n:
  a=a+1

print(a*t)
N,C=map(int,input().split())

D=[list(map(int,input().split())) for i in range(C)]
grid=[list(map(int,input().split())) for i in range(N)]

a=[[0]*C for i in range(3)]


for i in range(N):
    tmp=i%3
    for j in range(N):
        a[tmp][grid[i][j]-1]+=1
        tmp=(tmp+1)%3

b=[[0]*C for i in range(3)]
for i in range(3):
    for j in range(C):
        b[i][j]=sum([ D[k][j] * a[i][k] for k in range(C)])

b=[ sorted([ [b[i][j],j] for j in range(C)]) for i in range(3)]

ans=1000000000
for i in range(3):
    for j in range(3):
        for k in range(3):
            if b[0][i][1]!=b[1][j][1] and b[1][j][1]!=b[2][k][1] and b[2][k][1]!=b[0][i][1]:
                ans=min(ans,b[0][i][0]+b[1][j][0]+b[2][k][0])

print(ans)

### FIXED CODE ###

n=int(input())
print("ABC" if n<1000 else "ABD")
N = int(input())

d = {}
l = []
p = 0

for i in range(N):
  l.append(list(map(int, input().split())))

while True:
  if(l[0][2] == 0):
    l.append(l[0])
    l.remove[0]
  else:
    x, y, h= l[0]
    for i in range(101):
      for j in range(101):
        d[(i, j)] = abs(i- x)+ abs(j- y)+ h
    break

for k in range(N- 1):
  x, y, h = l[k+ 1]
  if(h == 0):
    for i in range(101):
      for j in range(101):
        if(d[(i, j)]- abs(i- x)- abs(j- y)> 0):
          del d[(i, j)]
  else:
    for i in range(101):
      for j in range(101):
        if((i, j) in d):
          if(d[(i, j)] != abs(i- x)+ abs(j- y)+ h):
            del d[(i, j)]


zahyou, height = list(d.items())[0]
  
print("{0[0]} {0[1]} {1}".format(zahyou, height))

### FIXED CODE ###

N = int(input())

d = {}
l = []
p = 0

for i in range(N):
  l.append(list(map(int, input().split())))

while True:
  if(l[0][2] == 0):
    l.append(l[0])
    del l[0]
  else:
    x, y, h= l[0]
    for i in range(101):
      for j in range(101):
        d[(i, j)] = abs(i- x)+ abs(j- y)+ h
    break

for k in range(N- 1):
  x, y, h = l[k+ 1]
  if(h == 0):
    for i in range(101):
      for j in range(101):
        if((i, j) in d):
          if(d[(i, j)]- abs(i- x)- abs(j- y)> 0):
            del d[(i, j)]
  else:
    for i in range(101):
      for j in range(101):
        if((i, j) in d):
          if(d[(i, j)] != abs(i- x)+ abs(j- y)+ h):
            del d[(i, j)]

zahyou, height = list(d.items())[0]
  
print("{0[0]} {0[1]} {1}".format(zahyou, height))
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(100000)

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

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

mod=10**9+7
cand=[0]

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

def comb(n):
    if n==N-1:
        return 0
    
    if n<K-2:
        cand.append(0)
    elif n==K-2:
        cand.append(1)
    else:
        cand.append((cand[-1]*n)%mod*mod_inv((n-K+2),mod)%mod)
        
    comb(n+1)
    
    return 0

comb(0)

for i in range(N-1):
    cand[i+1]=cand[i]+cand[i+1]

up=sorted(A)
down=sorted(A,reverse=True)
down=list(map(lambda x:-x,down))

ans=0
for i in range(N):
    ans+=(up[i]+down[i])*cand[i]

print(int(ans%mod))

### FIXED CODE ###

# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10000000)

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

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

mod=10**9+7
cand=[0]

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

def comb(n):
    if n==N-1:
        return 0
    
    if n<K-2:
        cand.append(0)
    elif n==K-2:
        cand.append(1)
    else:
        cand.append((cand[-1]*n)%mod*mod_inv((n-K+2),mod)%mod)
        
    comb(n+1)
    
    return 0

comb(0)

for i in range(N-1):
    cand[i+1]=cand[i]+cand[i+1]

up=sorted(A)
down=sorted(A,reverse=True)
down=list(map(lambda x:-x,down))

ans=0
for i in range(N):
    ans+=(up[i]+down[i])*cand[i]

print(int(ans%mod))
N, Q = map(int, input().split())
edges = [[] for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)

tally = [0 for i in range(N+1)]
for i in range(Q):
    p, x = map(int, input().split())
    tally[p] += x

count = [0 for i in range(N + 1)]
visited = [False for i in range(N+1)]
def dfs(root, curCount):
    visited[root] = True
    curCount += tally[root]
    count[root] = curCount
    for neighbour in edges[root]:
        if visited[neighbour]: continue
        dfs(neighbour, curCount)

dfs(1, 0)

print(*count[1:])


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

N, Q = map(int, input().split())
edges = [[] for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)

tally = [0 for i in range(N+1)]
for i in range(Q):
    p, x = map(int, input().split())
    tally[p] += x

count = [0 for i in range(N + 1)]
visited = [False for i in range(N+1)]

stack = [(1, 0)]
while stack:
    root, curCount = stack.pop()
    
    visited[root] = True
    curCount += tally[root]
    count[root] = curCount
    for neighbour in edges[root]:
        if visited[neighbour]: continue
        stack.append((neighbour, curCount))

print(*count[1:])
N = int(input())

print('ABC' + N)

### FIXED CODE ###

n = str(input())

print('ABC' + n)
# 
import sys

from sys import stdin
input = lambda: stdin.readline().rstrip()

N = int(input())

l = [0] * N
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            v = x**2+y**2+z**2+x*y+y*z+z*x
            if v <= N:
                l[v-1] = l[v-1] + 1

import matplotlib.pyplot as plt

for i in l:
    print(i)

### FIXED CODE ###

# 
import sys

from sys import stdin
input = lambda: stdin.readline().rstrip()

N = int(input())

l = [0] * N
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            v = x**2+y**2+z**2+x*y+y*z+z*x
            if v <= N:
                l[v-1] = l[v-1] + 1

for i in l:
    print(i)
N = input()
l = [int(i) for i in l]
if 7 is in l:
  return 'Yes'
return 'No'

### FIXED CODE ###

N = input()
l = [i for i in N]
if '7' in l:
  print('Yes')
else:
  print('No')
N, K = map(int, input().split())
A = list(map(int, input().split()))
zero_idx = 0
for idx in range(N):
    if A[idx] > 0:
        zero_idx = idx
        break
if zero_idx == 0 and A[0] < 0:
  print(A[N-K])
elif zero_idx == 0 and A[0] > 0:
  print(A[K-1])
else 
  ans = 3*10**5
  for plus in range(N-zero_idx+1):
    if plus > K:
        break
    minus = K - plus
    if minus > zero_idx:
    	continue
    p_dis = A[zero_idx+plus-1]
    if plus == 0:
        p_dis = 0
    m_dis = A[zero_idx-minus]
    if minus == 0:
        m_dis = 0
    if p_dis >= abs(m_dis):
        ans = min(ans, p_dis+abs(m_dis)*2)
    else:
        ans = min(ans, abs(m_dis)+p_dis*2)
  print(ans)


### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 10**9
for i in range(N-K+1):
  if A[i]*A[i+K-1] <= 0:
    if abs(A[i]) < abs(A[i+K-1]):
      ans = min(ans, (abs(A[i]))*2+A[i+K-1])
    else:
      ans = min(ans, abs(A[i])+A[i+K-1]*2)
  else:
    if abs(A[i]) < abs(A[i+K-1]):
      ans = min(ans, abs(A[i+K-1]))
    else:
      ans = min(ans, abs(A[i]))
print(ans)
n,u,v=map(int,input().split())
E=[[] for _ in range(n+1)]
for _ in range(n-1):
    a,b=map(int,input().split())
    E[a].append(b)
    E[b].append(a)
depth=[-1]*(n+1)
dis=[-1]*(n+1)
def dsf_1(p,d):
    depth[p]=d
    for c in E[p]:
        if depth[c]==-1:
            dsf_1(c,d+1)
dsf_1(v,0)
def dsf_2(p,d):
    dis[p]=d
    for c in E[p]:
        if dis[c]==-1:
            dsf_2(c,d+1)
dsf_2(u,0)
ans=0
for i in range(1,n+1):
    if len(E[i])==1 and i!=v:
        if dis[i]<depth[i]:
           ans=max(ans,depth[i]-1)
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
n,u,v=map(int,input().split())
E=[[] for _ in range(n+1)]
for _ in range(n-1):
    a,b=map(int,input().split())
    E[a].append(b)
    E[b].append(a)
depth=[-1]*(n+1)
dis=[-1]*(n+1)
def dsf_1(p,d):
    depth[p]=d
    for c in E[p]:
        if depth[c]==-1:
            dsf_1(c,d+1)
dsf_1(v,0)
def dsf_2(p,d):
    dis[p]=d
    for c in E[p]:
        if dis[c]==-1:
            dsf_2(c,d+1)
dsf_2(u,0)
ans=0
for i in range(1,n+1):
    if len(E[i])==1 and i!=v:
        if dis[i]<depth[i]:
           ans=max(ans,depth[i]-1)
print(ans)
a, b, c = map(int,input().split())
if |a-b| > |a-c|:
 print("B")
else:
 print("A")

### FIXED CODE ###

a, b, c =map(int,input().split())
import math
if abs(a-b) > abs(a-c):
 print("B")
else:
 print("A")
W, H, x, y = map(int, input().split())
if x=W:
    if H-y < y:
        y = H-y
    print(y*W, "0")    
elif y=H:
    if W-x < x:
        x = W-x
    print(x*H, "0")
    
else:
    if W-x < x:
        x = W-x
    if H-y < y:
        y = H-y

    if x*H > y*W: 
        print(y*W, "0")
    elif x*H < y*W:
        print(x*H, "0")
    else:
        print(x*H, "1")

### FIXED CODE ###



W, H, x, y = map(float, input().split())

if x/W == 0.5 and y/H == 0.5:   
	print(W*H/2,"1")
else:
	print(W*H/2,"0")
from sys import stdin


def dp_solve(k, h, dp):
    if 0 <= dp[k]:
        return dp[k]
    if k == 1:
        dp[1] = abs(h[1]-h[0])
        return dp[1]
    if k == 2:
        dp[2] = min(abs((h[2]-h[1])+abs(h[1]-h[0])), abs(h[2]-h[0]))
        return dp[2]

    dp[k] = min(abs(dp_solve(k-1, h, dp)) + abs(h[k-1]-h[k]),
                abs(dp_solve(k-2, h, dp))+abs(h[k-2]-h[k]))
    return dp[k]


if __name__ == "__main__":
    n = int(input())
    h = list(map(int, stdin.readline().split()))
    dp = [-1]*n

    print(dp_solve(n-1, h, dp))


### FIXED CODE ###

from sys import stdin
from sys import setrecursionlimit

setrecursionlimit(10**8)


def dp_solve(k, h, dp):
    if dp[k] < inf:
        return dp[k]
    if k == 1:
        dp[1] = abs(h[1]-h[0])
        return dp[1]
    if k == 2:
        dp[2] = min(abs(h[2]-h[1])+abs(h[1]-h[0]), abs(h[2]-h[0]))
        return dp[2]

    dp[k] = min(dp_solve(k-1, h, dp) + abs(h[k]-h[k-1]),
                dp_solve(k-2, h, dp)+abs(h[k]-h[k-2]))
    return dp[k]


if __name__ == "__main__":
    n = int(input())
    h = list(map(int, stdin.readline().split()))
    inf = float('inf')
    dp = [inf]*n

    print(dp_solve(n-1, h, dp))
H, W = map(int, input().split())
S = [input() for _ in range(H)]
M = {(0, 0): 1}


def dfs(x, y, c):
    cc = float('inf')
    for xx, yy in [(x + 1, y), (x, y + 1), (x - 1, y), (x, y - 1)]:
        if (H, W) == (yy + 1, xx + 1):
            return c + 1
        if 0 <= yy < H and 0 <= xx < W and S[yy][xx] == '.' and \
                ((xx, yy) not in M or M[(xx, yy)] > c + 1):
            M[(xx, yy)] = c + 1
            cc = min(cc, dfs(xx, yy, c + 1))
    return cc


def main():
    dfs(0, 0, 1)
    # ans = 0
    # for i in range(H):
    #     ans += S[i].count('.')
    # c = dfs(0, 0, 1)
    # if c == float('inf'):
    #     print(-1)
    # else:
    #     print(ans - c)


main()


### FIXED CODE ###

H, W = map(int, input().split())
S = [input() for _ in range(H)]


def bfs():
    q = [(0, 0)]
    nq = []
    m = []
    c = 1
    while len(q) > 0:
        while len(q) > 0:
            x, y = q.pop(0)
            for xx, yy in [(x + 1, y), (x, y + 1), (x - 1, y), (x, y - 1)]:
                if (H, W) == (yy + 1, xx + 1):
                    return c + 1
                if 0 <= yy < H and 0 <= xx < W and S[yy][xx] == '.' and \
                        (xx, yy) not in m:
                    m.append((xx, yy))
                    nq.append((xx, yy))
        q = nq
        nq = []
        c += 1
    return -1


def main():
    ans = 0
    for i in range(H):
        ans += S[i].count('.')
    c = bfs()
    if c == -1:
        print(-1)
    else:
        print(ans - c)


main()
N = int(input())
ans = {}
for i in range(N):
    a = input()
    ans[a] = ans.get(a,0) + 1

ans2 = [k for k, v in ans.items() if v == max(ans.values())]
ans2.sort()
[print(i) for i in ans2]


### FIXED CODE ###

A, B, C = map(int, input().split())
if (A ==B and A !=C) or (B == C and A != B) or (A == C and A!=B):
    print('Yes')
else:
    print('No')
def lcs(x,y):
    xs = len(x)
    ys = len(y)
    x = " " + x
    y = " " + y
    c = [[0 for i in xrange(len(x))] for j in xrange(len(y))]
    for i in xrange (1,ys+1):
        for j in xrange (1,xs+1):
            if x[j] == y[i]:
                a = 1
            else:
                a = 0
            c[i][j] = max(c[i][j-1],c[i-1][j],c[i-1][j-1] + a)
        m = max(m,c[i][j])
    return max(max(c))
n = input() 
for i in xrange (n): 
    x = raw_input()
    y = raw_input() 
    print lcs(x,y)
    

### FIXED CODE ###

def lcs():
    x, y = raw_input(), raw_input()
    b1 = [0 for k in range(len(y)+1)]
    for i in xrange(len(x)):
        a = x[i]
        b2 = b1 + []
        for j in xrange(len(y)):
            if a == y[j]:
                b1[j+1] = b2[j] + 1
            elif b1[j+1] < b1[j]:
                b1[j+1] = b1[j]
    print max(b1)
 
n = input()
for i in xrange(n):
    lcs()
N = int(input())
l = [int(x) for x in input().split()]

L = sorted(l,reverse=True)
a = 0

for x in range(0,N-3):
  for y in range(x+1,N-2):
	for i in range(y+1,N-1):
	  if L[i] > L[x] - L[y]:
		a += 1
print(a)

### FIXED CODE ###

N = int(input())
l = [int(x) for x in input().split()]
l.sort(reverse=True)
 
ans = 0
 
for i in range(N-2):
  j = i + 1
  k = N - 1
  while j < k:
    if l[i] < l[j] + l[k]:
      ans += k - j
      j += 1
    else:
      k -= 1
print(ans)
import numpy as np

N = int(input())
hs = list(map(int, input().split()))

# init
dp = np.zeros((N + 1, max(hs) + 1)).astype(int)
for i in range(1, N + 1):
    h = hs[i - 1]
    # i + 1
    if i < N:
        h1 = hs[i]
        if dp[i + 1][h1] == 0:
            dp[i + 1][h1] = dp[i][h] + abs(h1 - h)
        else:
            dp[i + 1][h1] = min(dp[i][h] + abs(h1 - h), dp[i + 1][h1])
    # i + 2
    if i < N - 1:
        h2 = hs[i + 1]
        if dp[i + 2][h2] == 0:
            dp[i + 2][h2] = dp[i][h] + abs(h2 - h)
        else:
            dp[i + 2][h2] = min(dp[i][h] + abs(h2 - h), dp[i + 2][h2])

# output
print(dp[N][hs[-1]])

### FIXED CODE ###

import numpy as np

N = int(input())
hs = list(map(int, input().split()))
hs = [0] + hs

# init
dp = np.zeros(N + 1).astype(int)
dp[2] = abs(hs[2] - hs[1])
# loop
if N > 2:
    for i in range(3, N + 1):
        dp[i] = min(
            dp[i-2] + abs(hs[i] - hs[i-2]),
            dp[i-1] + abs(hs[i] - hs[i-1]))

# output
print(dp[N])
K = int(input())
ans = []
i = 1

while len(ans) < K :
  l = len(str(i)) - 1
  que = 'yes'
  for k in range(l):
    a = str(i)
    if abs( int(a[k])- int(a[k+1]) ) >= 2:
      que = 'no'
      break

  if que == 'yes':
    ans = ans + [i]


  i +=1

print(i)

### FIXED CODE ###

X,Y,Z = map(str, input().split())


print(Z + ' ' + X + ' ' +Y )