Harryxun/stf_run huggingface dataset:
import math


def main():
    A, B, C, D = [int(x) for x in input().split()]
    N = B - A + 1
    g = math.gcd(C, D)
    l = (C * D) / g
    b = anti(B, C, D, l)
    a = anti((A-1), C, D, l)
    print(N - (b - a))


def anti(x, y, z, l):
    return int(x / y) + int(x / z) - int(x / l)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from fractions import gcd


def main():
    A, B, C, D = [int(x) for x in input().split()]
    l = (C * D) // gcd(C, D)
    b = B - anti(B, C, D, l)
    a = (A - 1) - anti((A - 1), C, D, l)
    print(int(b - a))


def anti(x, y, z, l):
    return (x // y) + (x // z) - (x // l)


if __name__ == "__main__":
    main()
if W >= S:
  print('unsafe')
else:
  print('safe')

### FIXED CODE ###

S, W = [int(x) for x in input().split()]
 
if W >= S:
  print('unsafe')
else:
  print('safe')
if __name__ == "__main__":
    S = Counter(input())
    if len(S) == 2 and all(v == 2 for v in S.values()):
        print("Yes")
    else:
        print("No")




### FIXED CODE ###

from collections import Counter
if __name__ == "__main__":
    S = Counter(input())
    if len(S) == 2 and all(v == 2 for v in S.values()):
        print("Yes")
    else:
        print("No")
n = int(input())
ans = 1
ans1 = 1
ans2 = 1
mod = 1000000007
for i in range(n):
	ans = (ans*10)%mod
    ans2 = (ans2*8)%mod
	ans1 = (ans1*9)%mod
ans = (ans - ans1 + mod)%mod
ans = (ans - ans1 + mod)%mod
ans = (ans + ans2)%mod
print(ans)


### FIXED CODE ###

n = int(input())
ans = 1
ans1 = 1
ans2 = 1
mod = 1000000007
for i in range(n):
	ans = (ans*10)%mod
	ans2 = (ans2*8)%mod
	ans1 = (ans1*9)%mod
ans = (ans - ans1 + mod)%mod
ans = (ans - ans1 + mod)%mod
ans = (ans + ans2)%mod
print(ans)
N = int(input())

List = list(map,input().split())

m = 1
cnt = 0

for i in range(N):
  a = List[i]
  if a <= m :
    cnt += 1
    m = a
    
print(int(cnt))

### FIXED CODE ###

N = int(input())

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

m = 10 ** 10
cnt = 0

for i in range(N):
  a = List[i]
  if a <= m :
    cnt += 1
    m = a
    
print(int(cnt))
N  = input()
ans = 0
for i in range(N+1):
  ans += i
print(ans)

### FIXED CODE ###

N  = int(input())
ans = 0
for i in range(N+1):
  ans += i
print(ans)
import math

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

deg = 0
enp = a*a*b - x

if(enp < a*a*b/2):
    ans  = math.atan2(a*a*a,enp)
else:
    ans = math.atan(a,b)
    
print(math.degrees(ans))

### FIXED CODE ###

import math

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

deg = 0
enp = a*a*b - x

if(x == a*a*b/2): #半分
    ans = 45
elif(x > a*a*b/2): #多い
    ans = math.degrees(math.atan2(2*enp,a*a*a))
else: #少ない
    ans = math.degrees(math.atan2(a*b*b,2*x))
    
print(ans)
num = int(input())

list = [[0 for col in range(2)] for row in range(num)]

total  = 0
nowMax = 0

#下に降りるタイミングを決めるためのループ
for w in range(num):
    #1段目の合計を足すためのループ
    for x in range(0,w+1):
        total = total + list[0][x]

    for y in range(w+1,num):
        total = total + list[1][y]

    if total < nowMax:
        nowMax = total

print(total)


### FIXED CODE ###

num = int(input())

nowMax = 0

retu       = input().split()
list_up   = list( map((lambda x:int(x)),retu))
retu       = input().split()
list_down = list( map((lambda x:int(x)),retu))

#下に降りるタイミングを決めるためのループ
for w in range(num):
    total = 0

    #1段目の合計を足すためのループ
    for x in range(0,w+1):
        total = total + list_up[x]

    for y in range(w,num):
        total = total + list_down[y]

    if total > nowMax:
        nowMax = total

print(nowMax)
c = 0
A =input().split(" ")
a,b = A[0],A[1]
for i in range(1,a-b):
    c = c + i
print(a-c)


### FIXED CODE ###

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

for i in range(1,c):
    d = i + d

print(d - a)
while 1:
  h, w = map(int, input().split())
  if h == w == 0:
    break
  for i in  range(h):
    if i == 0 or i == h-1:
      print "#" * w
    else:
      print "#" + "." * (w - 2) + "#"
  print ""

### FIXED CODE ###

while 1:
  h, w = map(int, raw_input().split())
  if h == w == 0:
    break
  for i in  range(h):
    if i == 0 or i == h-1:
      print "#" * w
    else:
      print "#" + "." * (w - 2) + "#"
  print ""
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
colors = [[i+1]*a[i] for i in n]
ans=[[0 for _ in range(w)] for _ in range(h)]
temp=0
for i in range(h):
    for j in range(w):
        if i%2==0:
            j = w-h-1
        ans[i][j]=colors[temp]
        temp+=1
        
for i in range(h):
    for j in range(2):
        print(ans[i][j], end="")
    print()

### FIXED CODE ###

h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
colors=[]
for i in range(n):
    for _ in range(a[i]):
        colors.append(i+1)
ans=[[0 for _ in range(w)] for _ in range(h)]
temp=0
for i in range(h):
    for j in range(w):
        if i%2!=0:
            j = w-j-1
        ans[i][j]=colors[temp]
        temp+=1

for i in range(h):
    for j in range(w):
        print(ans[i][j], end=" ")
    print()
n,m = map(int,input().split())
alis = list(map(int,input().split()))
lis = [list(map(int,input().split())) for x in range(m)]
clis = [[x[1]]*x[0] for x in lis]
clis=(sum(clis,[]))
clis.sort(reverse=True)
alis.sort()
print(a)
ans_lis=[x if x>=y else y for x,y in zip(alis,clis)]
if len(clis) < len(alis):
    ans__ = sum(alis[len(clis):])
    ans_=sum(ans_lis)
    print(ans_+ans__)
else:
    print(sum(ans_lis))


### FIXED CODE ###

n,m = map(int,input().split())
alis = list(map(int,input().split()))
lis = [list(map(int,input().split())) for x in range(m)]
for x in alis:
    lis.append([1,x])
lis.sort(reverse=True,key=lambda x:x[1])
ans = 0
for x in lis:
    (number,point) = x
    if number >= n:
        number = n
        ans += number * point
        #print(n)
        #print(ans,'+=',number,'*',point)
        break
    ans += number * point
    n -= number
    #print(n)
    #print(ans,'+=',number,'*',point)
print(ans)
#print(lis)
import itertools
A = int(input())
B = int(input())
C = int(input())
AL = [500*i for i in range(A)]
BL = [100*i for i in range(B)]
CL = [50*i for i in range(C)]
num = 0

for comb in itertools.product(AL,BL,CL):
  x,y,z = comb
  if x+y+z == X:
    num += 1
print(num)

### FIXED CODE ###

import itertools
A = int(input())
B = int(input())
C = int(input())
X = int(input())
AL = [500*i for i in range(A+1)]
BL = [100*i for i in range(B+1)]
CL = [50*i for i in range(C+1)]
num = 0

for comb in itertools.product(AL,BL,CL):
  x,y,z = comb
  if x + y + z == X:
    num += 1
print(num)
from collections import defaultdict
if __name__ == '__main__':
    N = int(input())
    xyh = [None]*N
    for i in range(N):
        xyh[i] = list(map(int, input().split()))
    
    H = 0
    for i in range(N):
        if xyh[i][2] >= H:
            X = xyh[i][0]
            Y = xyh[i][1]
            H = xyh[i][2]
    
    flag = True
    for i in range(0, N):
        if xyh[i][2] != 0:
            if H != xyh[i][2] + abs(xyh[i][0] - X) + abs(xyh[i][1] - Y):
                flag = False
        else:
            if abs(xyh[i][0] - X) + abs(xyh[i][1] - Y) < H:
                flag = False
    
    if flag:
        print(1/0)
    
    if not flag:
        for x in range(0, 101):
            for y in range(0, 101):
                flag = True
                height = 0
                for i in range(0, N):
                    if xyh[i][2] != 0:
                        if height == 0:
                            height = xyh[i][2] + abs(xyh[i][0] - x) + abs(xyh[i][1] - y)
                        if height != xyh[i][2] + abs(xyh[i][0] - x) + abs(xyh[i][1] - y):
                            flag = False
                            break
                    else:
                        if abs(xyh[i][0] - x) + abs(xyh[i][1] - y) < height:
                            flag = False
                            break
                if flag and height:
                    X = x
                    Y = y
        
        
    H = xyh[0][2] + abs(xyh[0][0] - X) + abs(xyh[0][1] - Y)
    
    print(X, Y, H)

### FIXED CODE ###

from collections import defaultdict
if __name__ == '__main__':
    N = int(input())
    xyh = [None]*N
    for i in range(N):
        xyh[i] = list(map(int, input().split()))
    
    H = 0
    for i in range(N):
        if xyh[i][2] >= H:
            X = xyh[i][0]
            Y = xyh[i][1]
            H = xyh[i][2]
            I = i
    
    flag = True
    for i in range(0, N):
        if xyh[i][2] != max(H - abs(xyh[i][0] - X) - abs(xyh[i][1] - Y), 0):
            flag = False
            break
    
        
    if not flag:
        for x in range(0, 101):
            for y in range(0, 101):
                flag = True
                height = 0
                for i in range(0, N):
                    if xyh[i][2] != 0:
                        if height == 0:
                            height = xyh[i][2] + abs(xyh[i][0] - x) + abs(xyh[i][1] - y)
                        if height != xyh[i][2] + abs(xyh[i][0] - x) + abs(xyh[i][1] - y):
                            flag = False
                            break
                    else:
                        if abs(xyh[i][0] - x) + abs(xyh[i][1] - y) < height:
                            flag = False
                            break
                if flag and height:
                    X = x
                    Y = y
    
    H = xyh[I][2] + abs(xyh[I][0] - X) + abs(xyh[I][1] - Y)
     
    print(X, Y, H)
import sys
 
N,M = map(int,input().split())
s = []
c = []
if M >= 1:
    for i in range (M):
        s,c = map(int,input().split())
        s.append(s)
        c.append(c)
    
    for i in range(M):
        if s[i] == 1 and c[i] == 0:
            print("-1")
            sys.exit()
a = zip(s, c)
a.sort()
s, c = zip(*a)
s = list(s)
c = list(c)
    if M >= 2:
        for i in range(1,M):
            if s[i - 1] == s[i] and c[i - 1] != c[i]:
                print("-1")
                sys.exit()
        if s[M - 1] == s[M] and c[M - 1] != c[M]:
            print("-1")
            sys.exit()
    for i in range(M):
        cc = [0] * N
        cc[s[i] - 1] = c[i]
    for i in range(min(s[i])):
        cc[i] = 1
    print(cc)
if M == 0:
    cc = [0] * N
    cc[0] = 1
    print(cc)

### FIXED CODE ###

N = int(input())

if N % 2 == 0:
    print("{}".format(int(N / 2)))
else:
    print("{}".format(int((N + 1) / 2)))
N,K = map(int, input().split())
A = list(map(int,input().split()))
MAX = 10**5+1
nxt = [-1 for i in range(MAX)]

last_index = [-1 for i in range(MAX)]
next_index = [-1 for i in range(N)]
first_index = [-1 for i in range(MAX)]
for i in range(N):
	a = A[i]
	last = last_index[a]
	if last >= 0:
		next_index[last] = i
	else:
		first_index[a] = i
	last_index[a] = i

start_stat = 0
while True:
	current = first_index[start_stat] + 1
	while current < N and next_index[current] != -1:
		current = next_index[current] + 1
	if current >= N:
		nxt[start_stat] = 0
		break
	else:
		stat = A[current]
		nxt[start_stat] = A[current]
		if nxt[A[current]] == -1:
			start_stat = A[current]
		else:
			break

order = [0]
in_order = [False for i in range(MAX)]
in_order[0] = True
last_stat = nxt[0]
while not in_order[last_stat]:
	order.append(last_stat)
	in_order[last_stat] = True
	last_stat = nxt[last_stat]
a,b = 0,len(order)
for x in order:
	if x == last_stat:
		break
	else:
		a += 1
		b -= 1
stat_index = K if K < a else (K-a) % b
init_status = order[stat_index]
before_stat = order[(stat_index - 1) % len(order)]
current = first_index[before_stat] + 1
if init_status == 0:
	print("")
	exit()
ans = []
while current < N:
	if next_index[current] != -1:
		current = next_index[current] + 1
	else:
		ans.append(A[current])
		current += 1
print( " ".join(list(map(str, ans))))


### FIXED CODE ###

N,K = map(int, input().split())
A = list(map(int,input().split()))
MAX = 2 * 10**5+1
nxt = [-1 for i in range(MAX)]

last_index = [-1 for i in range(MAX)]
next_index = [-1 for i in range(MAX)]
first_index = [-1 for i in range(MAX)]
for i in range(N):
	a = A[i]
	last = last_index[a]
	if last >= 0:
		next_index[last] = i
	else:
		first_index[a] = i
	last_index[a] = i

start_stat = 0
while True:
	current = first_index[start_stat] + 1
	while current < N and next_index[current] != -1:
		current = next_index[current] + 1
	if current >= N:
		nxt[start_stat] = 0
		break
	else:
		stat = A[current]
		nxt[start_stat] = A[current]
		if nxt[A[current]] == -1:
			start_stat = A[current]
			continue
		else:
			break

order = [0]
in_order = [False for i in range(MAX)]
in_order[0] = True
last_stat = nxt[0]
while not in_order[last_stat]:
	order.append(last_stat)
	in_order[last_stat] = True
	last_stat = nxt[last_stat]
a,b = 0,len(order)
for x in order:
	if x == last_stat:
		break
	else:
		a += 1
		b -= 1
stat_index = K if K < a else (K-a) % b
init_status = order[stat_index]
before_stat = order[(stat_index - 1) % len(order)]
current = first_index[before_stat] + 1
if init_status == 0:
	print("")
	exit()
ans = []
while current < N:
	if next_index[current] != -1:
		current = next_index[current] + 1
	else:
		ans.append(A[current])
		current += 1
print( " ".join(list(map(str, ans))))
S == 'ABC'

if S == 'ABC' :
 print('ARC')
else :
 print('ABC')

### FIXED CODE ###

s=input()
print("ABC" if s=="ARC" else "ARC")
import bisect

n=int(input())
*L,=map(int,input().split())

L.sort()

ans=0
for i in range(n-1):
      for j in range(i+1,n):
            index=bisect.bisect_left(L,L[i]+L[j])
            ans+=index-L[j+1]
print(ans)            


### FIXED CODE ###

import bisect

n=int(input())
L=[int(i) for i in input().split()]

L.sort()

s=0
for i in range(n-1):
      for j in range(i+1,n):
            index=bisect.bisect_left(L,L[i]+L[j])
            s+=index-(j+1)
print(s)
d = [0, 1, 0, -1]
def f(x, y, n, m):
    if m[x][y] == "#" or m[x][y] == " ":
        return
    if m[x][y] == "." or m[x][y] > n:
        m[x][y] = n
        for i in xrange(4):
            f(x+d[i], y+d[i+1&3], n+1, m)

h, w = map(int, raw_input().split())
m = list()
m.append([" " for _ in xrange(w+2)])
for _ in xrange(h):
    m.append([" "]+list(raw_input())+[" "])
m.append([" " for _ in xrange(w+2)])
dat = len(filter(lambda x:x==".", [i for j in m for i in j]))
f(1, 1, 1, m)
try:
    print dat-m[h][w]
except:
    print -1


### FIXED CODE ###

from Queue import Queue
d = [0, 1, 0, -1]
h, w = map(int, raw_input().split())
m = list()
m.append(["#" for _ in xrange(w+2)])
for _ in xrange(h):
    m.append(["#"]+list(raw_input())+["#"])
m.append(["#" for _ in xrange(w+2)])
dat = len(filter(lambda x:x==".", [i for j in m for i in j]))

q = Queue()
q.put((1,1,1))

while not q.empty():
    xy = q.get()
    if not m[xy[0]][xy[1]] == ".":
        continue
    m[xy[0]][xy[1]] = xy[2]
    for i in xrange(4):
        e = (xy[0]+d[i], xy[1]+d[i+1&3], xy[2]+1)
        if m[xy[0]+d[i]][xy[1]+d[i+1&3]] == ".":
            q.put(e)

try:
    print dat-m[h][w]
except:
    print -1
x=int(input())
a=(x-x%500)/500
y=x-500a
b=(y-y%50)/50
print(a*1000+b*5)

### FIXED CODE ###

x=int(input())
a =x // 500
y = x-500*a
b = y // 5
happy = a*1000+b*5
print(happy)
N,X = map(int,input().split())
L = list(map(input().split()))

cnt=1
dist=0

for l in L:
  cnt+=1
  dist+=l
  if dist>=X:
    break
    
print(cnt)
  

### FIXED CODE ###

N,X = map(int,input().split())
L = list(map(int,input().split()))

cnt=1
dist=0

for l in L:
  dist+=l
  if dist>X:
    break
  cnt+=1
    
print(cnt)
r=int(input())
print(int(3*r**))

### FIXED CODE ###

r=int(input())
print(int(3*r*r))
H, W = map(int,input().split())
MAP = []
INF = 10 ** 8
for _ in range(H):
    MAP.append(list(input()))
tx = [1,0,-1,0]
ty = [0,-1,0,1]
def dfs(x, y, index):
    if x < 0 or H <= x or y < 0 or W <= y:
        return INF
    if MAP[x][y] == '#':
        return INF
    if x == H - 1 and y == W - 1:
        return index
    ret = INF
    MAP[x][y] = '#'
    for i in range(4):
        nx = x + tx[i]
        ny = y + ty[i]
        ret = min(ret, dfs(nx, ny, index+1))
    return ret
cnt = 0
for i in range(H):
    for j in range(W):
        if MAP[i][j] == '#':
            cnt += 1
cnt += dfs(0,0,1)
ans = H * W - cnt
print(ans)

### FIXED CODE ###

from queue import Queue
H, W = map(int,input().split())
MAP = []
for _ in range(H):
    MAP.append(list(input()))
tx = [1,0,-1,0]
ty = [0,1,0,-1]
cnt = 0
INF = 10 ** 8
for i in range(H):
    for j in range(W):
        if MAP[i][j] == '#':
            cnt += 1
d = [[INF for i in range(W)] for j in range(H)]
q = Queue()
q.put([0,0])
d[0][0] = 1
flag = 1
while not q.empty():
    x, y = q.get()
    if x == H - 1 and y == W - 1:
        flag = 0
        break
    for i in range(4):
        nx = x + tx[i]
        ny = y + ty[i]
        if 0 <= nx <= H-1 and 0 <= ny <= W-1 and MAP[nx][ny] == '.' and d[nx][ny] == INF:
            d[nx][ny] = d[x][y] + 1
            q.put([nx,ny])
if flag:
    print(-1)
else:
    ans = H * W - d[H-1][W-1] - cnt
    print(ans)
import sys

def main(input):
    return input if len(input) == 2 else input[::-1]

if __name__ == "__main__":
    print main(sys.stdin.readline().strip())


### FIXED CODE ###

#!/usr/bin/env python3

import sys


def main(input):
    return input if len(input) == 2 else input[::-1]

if __name__ == "__main__":
    print(main(sys.stdin.readline().strip()))
l = input().split()

l[0], l[1] = l[1], 1[0]
l[0], l[2] = l[2], 1[0]

print(l)

### FIXED CODE ###

a = list(map(int,input().split()))
a[0], a[1] = a[1], a[0]
a[0], a[2] = a[2], a[0]
 
print(a[0], a[1], a[2])
n=int(input())
a=list(map(int,input().split())

cnt=0
l=[]
for i in a:
  p=i//400
  if p<=7:
    l.append(p)
  else:
    cnt+=1

def=len(set(l))
if def==0:
  def+=1
print(def,def+cnt)

### FIXED CODE ###

n=int(input())
a_l=list(map(int,input().split()))
a,b,c,d,e,f,g,h=0,0,0,0,0,0,0,0
cnt=0
for i in a_l:
    if i<400*1:
        a+=1
    elif 400*1<=i<400*2:
        b+=1
    elif 400*2<=i<400*3:
        c+=1
    elif 400*3<=i<400*4:
        d+=1
    elif 400*4<=i<400*5:
        e+=1
    elif 400*5<=i<400*6:
        f+=1
    elif 400*6<=i<400*7:
        g+=1
    elif 400*7<=i<400*8:
        h+=1
    else:
        cnt+=1
ans=0
for i in [a,b,c,d,e,f,g,h]:
    if i!=0:
        ans+=1
if ans!=0:
    print(ans, ans+cnt)
else:
    print(1,cnt)
k = ['R','U','D']
g = ['L','U','D']

s = input()
for i in s:
  if i == 'U' or i == 'D':
    continue
  else:
    if i%2 == 0:
      if i != 'L':
        print("No")
        exit()
    else:
      if i != 'R':
        print("No")
        exit()
print("Yes")

### FIXED CODE ###

k = ['R','U','D']
g = ['L','U','D']

s = input()
for i in range(len(s)):
  if s[i] == 'U' or s[i] == 'D':
    continue
  else:
    if i%2 != 0:
      if s[i] != 'L':
        print("No")
        exit()
    else:
      if s[i] != 'R':
        print("No")
        exit()
print("Yes")
from collections import defaultdict as dd
from collections import deque
from copy import deepcopy as dc
N, M = map(int, input().split())
e = dd(list)
inf = 10 ** 9
for _ in range(M):
  u, v = map(int, input().split())
  e[u].append(v)
S, T = map(int, input().split())

stopped = [inf] * (N + 1)
Q = deque()
Q.append(S)
stopped[S] = 0
saw2 = {i: 0 for i in range(1, N + 1)}
saw3 = {i: 0 for i in range(1, N + 1)}
while len(Q) != 0:
  s2 = dc(saw2)
  s3 = dc(saw3)
  p = Q.popleft()
  if stopped[p] >= stopped[T]:
    break
  for q in e[p]:
    for r in e[q]:
      if s2[r] == 1:
        continue
      else:
        s2[r] = 1
      for s in e[r]:
        if s3[s] == 1:
          continue
        else:
          s3[s] = 1
        if stopped[s] > stopped[p] + 1:
          Q.append(s)
          stopped[s] = stopped[p] + 1
if stopped[T] == inf:
  print(-1)
else:
  print(stopped[T])

### FIXED CODE ###

n=int(input());d=sorted(list(map(int,input().split())));print(d[n//2]-d[n//2-1])
print(x = int(input())
print(x ** 3)


### FIXED CODE ###

x = int(input())
#print(x)
print(x ** 3)
s=input()
ans=0
for x in range(1,len(s)+1):
	for left in range(s-x+1):
		z=s[left:left+x]
		flag=True
		for i in range(x):
			if z[i]!="A" and z[i]!="G" and z[i]!="C" and z[i]!="T":
				flag=False
				break
		if flag:
			ans+=1
			break
print(ans)

### FIXED CODE ###

s=input()
ans=0
for x in range(1,len(s)+1):
	for left in range(len(s)-x+1):
		z=s[left:left+x]
		flag=True
		for i in range(x):
			if z[i]!="A" and z[i]!="G" and z[i]!="C" and z[i]!="T":
				flag=False
				break
		if flag==True:
			ans+=1
			break
print(ans)
d=int(input())
print('Christmas' if d==25 else 'Christmas Eve' if d==24 else 'Christmas Eve Eve' d==23 else 'Christmas Eve Eve Eve')


### FIXED CODE ###

d=int(input())
print('Christmas' if d==25 else 'Christmas Eve' if d==24 else 'Christmas Eve Eve' if d==23 else 'Christmas Eve Eve Eve')
n = int(input())

h = [int(i) for i in input().split()]

def dp(cost, p):
  if p == n-1:
    return cost
  if p < n-2:
    return min(dp(cost+abs(h[p]-h[p+1]), p+1), dp(cost+abs(h[p]-h[p+2]), p+2))
  if p == n-2:
    return dp(cost+abs(h[p]-h[p+1]), p+1)

print(dp(0, 0))

### FIXED CODE ###

import sys
sys.setrecursionlimit(200000)
 
n = int(input())
 
h = [int(i) for i in input().split()]
 
d = {}
 
def dp(p):
  if p in d:
    return d[p]
  if p == n-1:
    return 0
  if p < n-2:
    m = min(dp(p+1)+abs(h[p]-h[p+1]), dp(p+2)+abs(h[p]-h[p+2]))
    d[p] = m
    return m
  if p == n-2:
    return dp(p+1)+abs(h[p]-h[p+1])

print(dp(0))
s=list(map(int,input().split()))
t=[int(input()) for i in range(s[1])]
list=[]
mod=1000000007
d=1
for k in range(1010):
  list.append(0)
def fib(x):
  list[0]=list[1]=0
  list[2]=list[3]=1
  for l in range(4,x+3):
    list[l]=list[l-1]+list[l-2]
fib(1000)
for j in range(s[1]+1):
  if j==0:
    d*=list[t[j]+1]
    d=d%mod
    e=t[j]
  elif j==s[1]:
    d*=list[s[0]-t[j-1]+1]
    d=d%mod
  else:
    d*=list[t[j]-t[j-1]]
    d=d%mod
print(d)

### FIXED CODE ###

N,M=map(int,input().split())
a=[int(input()) for _ in range(M)]
m=10**9+7
a.append(N+1)
def mul(a,b):
    c=[[0]*len(b[0])for i in range(len(a))]
    for i in range(len(a)):
        for k in range(len(b)):
            for j in range(len(b[0])):
                c[i][j]=(c[i][j]+a[i][k]*b[k][j])%m
    return c
def pow(a,n):
    b=[[0]*len(a) for i in range(len(a))]
    for i in range(len(a)):
        b[i][i]=1
    while 0<n:
        if n&1==1:
            b=mul(a,b)
        a=mul(a,a)
        n=n>>1
    return b                
if M==0:
  A=[[1,1],[1,0]]
  print(pow(A,N+1)[1][0])
elif M==1:
  A=[[1,1],[1,0]]
  print((pow(A,a[0])[1][0]*pow(A,N-a[0])[1][0])%m)
else:
  ans=1
  for i in range(M+1):
    A=[[1,1],[1,0]]
    if a[i]+1==a[i-1]:
      ans=0
      break
    if i==0:
      if a[i]!=1:
        ans=ans*pow(A,a[0])[1][0]
        ans=ans%m
    elif i==M:
      ans=ans*pow(A,a[i]-a[i-1]-1)[1][0]
      ans=ans%m
    else:
      ans=ans*pow(A,a[i]-a[i-1]-1)[1][0]
      ans=ans%m
  print(ans)
k = input()
w= input()
l = len(w)
if l <= k:
 	 
    print(w)
else:
   	 print(w[:k])


### FIXED CODE ###

k = int(input())
s = input()
if int(len(s)) <= k:
  	print(str(s))
else:
  	print(((str(s))[0:k]) + "...")
n,m=map(int,input().split())
nums=list(map(int,input().split()))
nums.sort(reverse=True)
changers=[]
for i in range(m):
  a,b=map(int,input().split())
  for j in range(a):
    changers.append(b)
changers.sort()
ans=0
for i in range(n):
  if changers[-i] == None:
    ans+=nums[-i]
  ans+=max(nums[-i],changers[-i])
print(ans)


### FIXED CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
changer=[]
cl=0
flag=0
for i in range(m):
  b=list(map(int,input().split()))
  changer.append(b)
changer.sort(key=lambda x:x[1],reverse=True)
for i in range(m):
  if flag==1:
    break
  for j in range(cl,min(cl+changer[i][0],n)):
    if a[j]<changer[i][1]:
      a[j]=changer[i][1]
    else:
      flag=1
      break
  cl+=changer[i][0]
print(sum(a))
N = int(input())
H = list(map(int, input().split()))

H_reversed = list(reversed(H))
for i in range(N):
    if H_reversed[i+1] - H_reversed[i] == 1:
        H_reversed[i+1] -= 1
    elif H_reversed[i+1] - H_reversed[i] > 1:
        print('No')
        break
print('Yes')


### FIXED CODE ###

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

exit_flag = False
for i in range(N-1, 0, -1):
    if H[i-1] - H[i] == 1:
        H[i-1] -= 1
    elif H[i-1] - H[i] > 1:
        exit_flag = True
        print('No')
        break

if not exit_flag:
    print('Yes')