Harryxun/stf_run huggingface dataset:
menu = []
for i in range(5):
    menu.append(int(input()))

menu_kiriage = []
min_reminder = 10
for i in range(5):
    reminder = menu[i]%10
    if reminder < min_reminder and reminder != 0:
        min_reminder = reminder
        min_menu = i

total = 0
for i in range(5):
    if min_menu == i:
        total += menu[i]
    else:
        total += menu[i]+10-menu[i]%10 if menu[i]%10 != 0 else menu[i]
        
print(total)

### FIXED CODE ###

menu = []
for i in range(5):
    menu.append(int(input()))

min_reminder = 10
min_menu = 5
for i in range(5):
    reminder = menu[i]%10
    if reminder < min_reminder and reminder != 0:
        min_reminder = reminder
        min_menu = i
 
total = 0
for i in range(5):
    if min_menu == i or menu[i]%10 == 0:
        total += menu[i]
    else:
        total += menu[i]+10-menu[i]%10
        
print(total)
A,B,C=map(int,input().split())
if A==B and B==C and C==A:
  print("No")
elif A!=B and B!=C and C!=A:
  print("No")
alse:
  print("Yes")

### FIXED CODE ###

A,B,C=map(int,input().split())
if A==B and B==C and C==A:
  print("No")
elif A!=B and B!=C and C!=A:
  print("No")
else:
  print("Yes")
S = input(int)


foo=(str(S//3600)+':'+str(S//60%60)+':'+str(S%60))
print(foo)



### FIXED CODE ###

S = int(input())


print(f'{S//3600}:{S//60%60}:{S%60}')
def main():
	# s = int(input())
	# s = str(input())
	a,b = map(int,input().split())
	#1行R列
	# a = list(map(int,input().split()))
	#R行1列
	# l = [str(input()) for i in range(n)]
	#R行C列
	# qu = [list(map(str,input().split())) for x in range(q)]
	# print(' '.join(map(str,)))
	import math
	def combinations_count(n, r):
		return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

	if b == 0 or b == 1:
		print(combinations_count(a,2))
	else:
		print(combinations_count(a,2) + combinations_count(b,2))


if __name__ == '__main__':
	main()

### FIXED CODE ###

def main():
	# s = int(input())
	# s = str(input())
	a,b = map(int,input().split())
	#1行R列
	# a = list(map(int,input().split()))
	#R行1列
	# l = [str(input()) for i in range(n)]
	#R行C列
	# qu = [list(map(str,input().split())) for x in range(q)]
	# print(' '.join(map(str,)))
	import math
	def combinations_count(n, r):
		return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

	if a <= 1 and b > 1:
		print(combinations_count(b,2))
	elif a <= 1 and b <= 1:
		print(0)
	elif a > 1 and b <= 1:
		print(combinations_count(a,2))
	else:
		print(combinations_count(a,2) + combinations_count(b,2))


if __name__ == '__main__':
	main()
r=0
s=input()
for n in len(s):
  if s[n] != s[(-1)*(n+1)]:
    r+=1
print(r/2)

### FIXED CODE ###

f = map(int, input().split())
s = sum(f)
def u(n):
  if n>=22:
    return "bust"
  else:
    return "win"
print(u(s))
p = int(input().split()[1])
s = input()
#if 10 % p:
#  s = reversed(s)
a = enumerate(s, 1)
if 10 % p == 0:
  r = sum(i for i, x in a if x % p == 0)
else:
  d = [1] + [0] * (p - 1)
  t, y = 0, 1
  for i, x in a:
    t = (t + x * y) % p
    d[t] += 1
    y = y * 10 % p;
  r = sum(i * (i - 1) // 2 for i in d)
print(r)


### FIXED CODE ###

from itertools import accumulate
from collections import Counter

p = int(input().split()[1])
a = list(map(int, input()))
if 10 % p == 0:
  r = sum(i for i, x in enumerate(a, 1) if x % p == 0)
else:
  a = accumulate(x * pow(10, i, p) for i, x in enumerate(reversed(a), 1))
  c = Counter(x % p for x in a) 
  c[0] += 1
  r = sum(i * (i - 1) // 2 for i in c.values())
print(r)
def dfs(v):
    if d[v] != -1:
        return d[v]
    res = -1
    for u in e[v]:
        res = max(res, dfs(u))
    res += 1
    d[v] = res
    return res


n, m = map(int, input().split())
e = tuple(set() for _ in range(n))
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    e[x].add(y)

d = [-1] * n
res = -1
for v in range(n):
    res = max(res, dfs(v))
print(res)


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 9)


def rec(v):
    if dp[v] != -1:
        return dp[v]

    res = 0
    for nv in g[v]:
        res = max(res, rec(nv) + 1)
    dp[v] = res
    return res


N, M = map(int, input().split())
g = [[] for _ in range(N)]
for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    g[x].append(y)

dp = [-1 for _ in range(N)]

ans = 0
for t in range(N):
    ans = max(ans, rec(t))
print(ans)
A=10000
B=5000
C=1000
x,y=map(int,input().split())
for a in range(x+1):
  for b in range(x-a+1):
    for c in range(x-a-b+1):
      if a*A+b*B+c*C=y:
        ans_A=a
        ans_B=b
        ans_C=c
        break
print(ans_A,ans_B,ans_C)
      

### FIXED CODE ###

A=10000
B=5000
C=1000
ans_A=-1
ans_B=-1
ans_C=-1
x,y=map(int,input().split())
for a in range(x+1):
  for b in range(x-a+1):
    c=x-a-b
    if a*A+b*B+c*C==y:
      ans_A=a
      ans_B=b
      ans_C=c
print(ans_A,ans_B,ans_C)
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();
        int b = inp.nextInt();
        inp.close();
        System.out.println((a + b) < 10 ? a + b : "error");
    }
}

### FIXED CODE ###

p = sum(map(int, input().split()))
if p < 10:
    print(p)
else:
    print("error")
a,b,x = map(int, input().split())
right = b // x + 1
if a = 0:
  left = 0
else:
  left = (a - 1) // x + 1
print(right - left)

### FIXED CODE ###

a,b,x = map(int, input().split())
right = b // x + 1
if a == 0:
  left = 0
else:
  left = (a - 1) // x + 1
print(right - left)
N = int(input())
H = [int(i) for i in  input().split()]
length = len(H)
def z_counter(start):
  cnt = 0
  for i in range(start+1, length):
    if H[i] <= H[i-1]:
      cnt += 1
    else:
      break
  return cnt
ans = []
for i in range(1, length):
  ans.append(z_counter(i))

print(max(ans))

### FIXED CODE ###

N=int(input())
H=list(map(int,input().split()))
h=[0]*N
count=0
for i in range(1,N):
    if H[i-1]>=H[i]:
        count+=1
    else:
        count=0
    h[i]=count
print(max(h))
N = int(input())
X = str(input())

import functools


def popcount(bits: str):
    return len([elm for elm in bits if elm == '1'])


@functools.lru_cache(maxsize=200000)
def f(num):
    if num == 0:
        return 0
    else:
        pc = popcount('{:b}'.format(num))
        return 1 + f(num % pc)


def reverse_bit(bits: str, digit):
    def toggle(a):
        if a == '1':
            return '0'
        else:
            return '1'

    ret = list(bits)
    ret[digit-1] = toggle(bits[digit-1])
    return ''.join(ret)

def convert(x: str):
    ans = 0
    i = 0
    for elm in list(x)[::-1]:
        if elm == '1':
            ans += 2 ** i
        i += 1
    return ans


for i in range(1, N+1):
    bits = reverse_bit(X, i)
    pc = popcount(bits)
    # print(f'# {bits} {convert(bits)} {pc}')
    print(f(convert(bits)))

### FIXED CODE ###

L, R, d = [int(x) for x in input().split()]

lst = list(range(d, 101, d))

ret = list(filter(lambda x: L <= x <= R, lst))

# print(ret)
print(len(ret))
a,b=map(int,input().split())
s=a//b
r=a%b
f=double(a)/b
print(s,r,f)


### FIXED CODE ###

a,b=map(int,input().split())
print(a//b,a%b,"{0:10.20f}".format(a/b))
A = [0]*(len(B)+1)

A[0] = B[0]
for i in range(len(B)):
    if A[i]>=B[i]:
        A[i]=B[i]
    A[i+1]=B[i]
print(sum(A))

### FIXED CODE ###

N = int(input())
B = list(map(int, input().split()))
A = [0]*(len(B)+1)

A[0] = B[0]
for i in range(len(B)):
    if A[i]>=B[i]:
        A[i]=B[i]
    A[i+1]=B[i]
print(sum(A))
import sys

N = int(input())
XY = [[int(_) for _ in input().split()] for i in range(N)]

mc = [0, 0]
maxl = 0

for x, y in XY:
    l = abs(x) + abs(y)
    maxl = max(maxl, l)
    mc[l % 2] += 1

if mc[0] > 0 and mc[1] > 0:
    print(-1)
    sys.exit()

if maxl > 20:
    raise
    
print(maxl)
print(*([1]*maxl))

for x, y in XY:
    w = ""
    if x < 0:
        w += "L" * (-x)
    if x > 0:
        w += "R" * (+x)
    if y < 0:
        w += "D" * (-y)
    if y > 0:
        w += "U" * (+y)
    a = (maxl - len(w)) // 2
    if a > 0:
        if x == 0:
            w = "R"*a + w + "L"*a
        elif y < 0:
            w = "U"*a + w + "D"*a
        else:
            w = "D"*a + w + "U"*a
    print(w)


### FIXED CODE ###

import sys

N = int(input())
XY = [[int(_) for _ in input().split()] for i in range(N)]

mc = [0, 0]
maxl = 0

for x, y in XY:
    l = abs(x) + abs(y)
    maxl = max(maxl, l)
    mc[l % 2] += 1

if mc[0] > 0 and mc[1] > 0:
    print(-1)
    sys.exit()

#print(maxl)

def calc(sx, sy, ex, ey, d):
    dx, dy = ex - sx, ey - sy
    rx, ry = dx - dy, dx + dy
    if rx > 0:
        if ry > 0:
            d, x, y = "R", sx + d, sy
        else:
            d, x, y = "D", sx, sy - d
    else:
        if ry > 0:
            d, x, y = "U", sx, sy + d
        else:
            d, x, y = "L", sx - d, sy
    return d, x, y

import math

l = math.ceil(math.log(maxl + 1, 2))

ms = [2 ** (l - i - 1) for i in range(l)]

rms = ms

if mc[0] > 0:
    rms = [1] + ms

print(len(rms))
print(*rms)

for ex, ey in XY:
    x, y = 0, 0
    w = ""
    if mc[0] > 0:
        w = "R"
        x += 1
    for m in ms:
        d, x, y = calc(x, y, ex, ey, m)
        w += d
    print(w)
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 = [x for y in clis for x in y]
clis.sort(reverse=True)
alis.sort()
ans_lis=[x if x>=y else y for x,y in zip(alis,clis)]
print(a)
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 numpy

A = int(input())
S = input()

if A >= 3200:
    print(S)
else:
    print("red")

### FIXED CODE ###

import numpy

A = int(input())
S = input()

if A >= 3200:
    print(S)
else:
    print("red")
a=input()
b=input()
for i in range(len(a)):
    if a==b:
        print("Yes")
        break
    
    a=a[-1]+a
    a=a[:len(a)-1]
else:
    print("No"

### FIXED CODE ###

a=input()
b=input()
for i in range(len(a)):
    if a==b:
        print("Yes")
        break
    
    a=a[-1]+a
    a=a[:len(a)-1]
else:
    print("No")
s=input()
t=input()
st=''
for i in range(len(s)):
    st+=s[i]
    st+=t[i]
print(st)

### FIXED CODE ###

s=input()+' '
t=input()+' '
st=''

for i in range(min(len(s),len(t))):
    st+=s[i]
    st+=t[i]
print(st.strip())
costs = map(int,input().split())
costs.sort()
cnt = 0
for i in range(len(costs)-1):
  cnt += costs[i+1] - costs[i]
print(cnt)

### FIXED CODE ###

costs = list(map(int,input().split()))
costs.sort()
cnt = 0
for i in range(len(costs)-1):
  cnt += costs[i+1] - costs[i]
print(cnt)
import sys

N,M, K = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(M)]
CD = [list(map(int,input().split())) for i in range(K)]


#xの木の根を求める
def root(x,li): 
    if li[x] == x:
        return x
    else:
        li[x] = root(li[x],li)
        return li[x]

#xとyが同じ集合に属するかの判定
def find(x,y,li):
    return root(x,li) == root(y,li)

#xとｙを併合
def union(x,y,li):
    x = root(x,li)
    y = root(y,li)
    if x==y:
        return
    else:
        li[x] = y

li1 = [i for i in range(N)]
li2 = [i for i in range(N)]

for i in range(M):
    a = AB[i][0]
    b = AB[i][1]
    union(a-1,b-1,li1)
# for i in range(K):
#     c = CD[i][0]
#     d = CD[i][1]
#     union(c-1,d-1,li2)
sys.exit()
mm = [0 for i in range(max(li1))]
for i in range(N):
    m = root(i,li1)
    mm[m-1] += 1

# print(li1)
# print(mm)
ans = [mm[li1[i]-1]-1 for i in range(N)]
# print(ans)

for i in range(M):
    a = AB[i][0]
    b = AB[i][1]
    ans[a-1] -= 1
    ans[b-1] -= 1


for i in range(K):
    c = CD[i][0]
    d = CD[i][1]
    if find(c-1,d-1,li1):
        ans[c-1] -= 1
        ans[d-1] -= 1
print(*ans)





### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

N,M, K = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(M)]
CD = [list(map(int,input().split())) for i in range(K)]


#xの木の根を求める
def root(x,li): 
    if li[x] == x:
        return x
    else:
        li[x] = root(li[x],li)
        return li[x]

#xとyが同じ集合に属するかの判定
def find(x,y,li):
    return root(x,li) == root(y,li)

#xとｙを併合
def union(x,y,li):
    x = root(x,li)
    y = root(y,li)
    if x==y:
        return
    else:
        li[x]=y

li1 = [i for i in range(N)]
li2 = [i for i in range(N)]

for i in range(M):
    a = AB[i][0]
    b = AB[i][1]
    # print(str(i)+" ",end="")
    union(min(a-1,b-1),max(a-1,b-1),li1)
# for i in range(K):
#     c = CD[i][0]
#     d = CD[i][1]
#     union(c-1,d-1,li2)

mm = [0 for i in range(max(li1)+1)]
for i in range(N):
    m = root(i,li1)
    mm[m] += 1

# print(li1)
# print(mm)
ans = [mm[li1[i]]-1 for i in range(N)]
# print(ans)

for i in range(M):
    a = AB[i][0]
    b = AB[i][1]
    ans[a-1] -= 1
    ans[b-1] -= 1


for i in range(K):
    c = CD[i][0]
    d = CD[i][1]
    if find(c-1,d-1,li1):
        ans[c-1] -= 1
        ans[d-1] -= 1
print(*ans)
n,k = map(int, input().split())
num = 1
for i in range(n):
    if num*2 < num+k:
        num += num*2
    else:
        num += num+k
print(num)


### FIXED CODE ###

n = int(input())
k = int(input())
num = 1
for i in range(n):
    num = min(num+k,num*2)
print(num)
n, k = map(int, input().split())
d = list(input().split())


def validate(strNum):
    for i in strNum:
        if i in d:
            return False
    print(strNum)
    exit()


for i in range(0, 10001):
    _ = validate(str(n))
    n += 1


### FIXED CODE ###

li = list(map(int, input().split()))
count5 = count7 = 0
for l in li:
    if l == 5:
        count5 += 1
    elif l == 7:
        count7 += 1
    else:
        print("NO")
        exit()
if count5 == 2 and count7 == 1:
    print("YES")
else:
    print("NO")
a = "Yes"
for i,s in enumerate(S):
    if i % 2 == 0:
        if s in ["R", "U", "D"]:
            pass
        else:
            a = "No"
            break
    else:
        if s in ["L", "U", "D"]:
            pass
        else:
            a = "No"
            break
            
print(a)
      

### FIXED CODE ###

S  = list(input())

a = "Yes"
for i,s in enumerate(S):
    if i % 2 == 0:
        if s in ["R", "U", "D"]:
            pass
        else:
            a = "No"
            break
    else:
        if s in ["L", "U", "D"]:
            pass
        else:
            a = "No"
            break
            
print(a)
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
q.sort()
r.sort()
pcount=0
qcount=0
rcount=0
ans=[]
for i in range(x):
  ans.append(p[-1-i])
for i in range(y):
  ans.append(q[-1-i])
ans.sort()
for i in range(c):
  if (rcount+1)<=len(r) and ans[i]<=r[-1-rcount]:
    ans[i]=r[-1-rcount]
    rcount+=1
print(sum(ans))
  

### FIXED CODE ###

x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
q.sort()
r.sort(reverse=True)
rcount=0
ans=[]
for i in range(x):
  ans.append(p[-1-i])
for i in range(y):
  ans.append(q[-1-i])
ans.sort()
for i in range(min(len(ans),c)):
  if ans[i]<=r[rcount]:
    ans[i]=r[rcount]
    rcount+=1
print(sum(ans))
x=list(int(input()) for i in range())
k=int(input())

if x[-1]-x[0]<=k:
  print("Yay!")
else:
  print(":(")

### FIXED CODE ###

x=[int(input()) for i in range(5)]
k=int(input())

if x[-1]-x[0]<=k:
  print("Yay!")
else:
  print(":(")
a,b = map(in(),input().split())
if(b%2 == 0):
  print(a+b)
else:
  print(b-a)

### FIXED CODE ###

a,b = map(int,input().split())
if(b%a == 0):
  print(a+b)
else:
  print(b-a)
H,W=map(int,input().split())
prev=0
for i in range(H):
  s=input()
  id = s.index("#")
  if id >= prev:
    flag=False
    prev = id
    for j in range(prev,W):
      if flag ans s[j]=="#":
        print("Impossible")
        exit(0)
      if s[j]==".":
        flag=True
print("Possible")
  

### FIXED CODE ###

H,W=map(int,input().split())
prev=0
for i in range(H):
  s=input()
  id = s.index("#")
  if id >= prev:
    flag=False
    prev = W-1 - s[::-1].index("#")
    for j in range(id,W):
      if flag and s[j]=="#":
        print("Impossible")
        exit(0)
      if s[j]==".":
        flag=True
  else:
    print("Impossible")
    exit(0)
print("Possible")
N=int(input())
r=[0]
inp=input().split()
for k in range(N):
  r.append(int(inp[k]))
def rec(x,y,i,N):
    if len(x)==1:
        for k in range(len(y)):
            print(y[k])
        return(y)
    if i==N+1:
        if len(y)==0:
            print(-1)
            return -1
        else:
            m=y[0]
            del y[0]
            x.insert(m,m)
            rec(x,y,m+1,N)     
    if x[i]==i:
        x.pop(i)
        y.insert(0,i)
        rec(x,y,1,N)
        
    else:
        if x[i] < i:
            rec(x,y,i+1,N)
        else:
            if len(y)>0:
                m=y[0]
                del y[0]
                x.insert(m,m)
                rec(x,y,m+1,N)  
            else:
                print(-1)
                return -1
                
                
            
        
            
        
    
rec(r,[],1,3)      
  

### FIXED CODE ###

N=int(input())
x=[0]
inp=input().split()
for k in range(N):
  x.append(int(inp[k]))
y=[]
OK=True
for k in range(N):
  ok=False
  for i in range(len(x)-1,0,-1):
    if x[i]==i:
      y.insert(0,i)
      del x[i]
      ok=True
      break
  if ok==False:
    print(-1)
    OK=False
    break
if OK==True:
  for k in range(len(y)):
    print(y[k])
n=int(input())
a=[0]
r=list(map(int,input().split()))
for i in range(n):
  a.append(r[i])
b=[0 for i in range(n+1)]


for i in range((n//2+1),n+1):
  b[i]=a[i]
for i in range(n//2,0,-1):

  j=2
  b[i]=a[i]
  while(j*i=<n):
    b[i]^=a[j*i]
    j+=1

m=0
for i in range(n):
  m+=b[i]
print(m)
print(b)
for i in range(n):
  if b[i]==1:
    print(i)
    
  

### FIXED CODE ###

n=int(input())
a=[0]
r=list(map(int,input().split()))
for i in range(n):
  a.append(r[i])
b=[0 for i in range(n+1)]


for i in range((n//2+1),n+1):
  b[i]=a[i]
for i in range(n//2,0,-1):
  j=2
  b[i]=a[i]
  while(j*i<=n):
    b[i]^=b[j*i]
    j+=1

m=0
for i in range(n+1):
  m+=b[i]
print(m)
for i in range(1,n+1):
  if b[i]==1:
    print(i)
a=int(input())
print('8') if 400<=a<=599
print('7') if 600<=a<=799
print('6') if 800<=a<=999
print('5') if 1000<=a<=1199
print('4') if 1200<=a<=1399
print('3') if 1400<=a<=1599
print('2') if 1600<=a<=1799
print('1') if 1800<=a<=1999

### FIXED CODE ###

a=int(input())
if 400<=a<=599:
  print(8) 
if 600<=a<=799:
  print(7)
if 800<=a<=999:
  print(6)
if 1000<=a<=1199:
  print(5)
if 1200<=a<=1399:
  print(4)
if 1400<=a<=1599:
  print(3)
if 1600<=a<=1799:
  print(2)
if 1800<=a<=1999:
  print(1)
list = [input() for i in range(3)]
print(list[0][0] + list[1][1] + list[2][2]

### FIXED CODE ###

list = [input() for i in range(3)]
print(list[0][0] + list[1][1] + list[2][2])
li1 = []
li2 = []
ans = 0
for i, s in enumerate(input()):
    if s == "\\":
        li1.append(i)
    elif s == "/" and li1:
        j = li1.pop()
        c = i - j
        ans += c
        while li2 and li2[-1][0] > j:
            c += li2[-1][1]
            li2.pop()
        li2.append((j, c))
print(ans)
print(len(li2), *list(zip(*li2))[1])



### FIXED CODE ###

li1 = []
li2 = []
for i, s in enumerate(input()):
    if s == "\\":
        li1.append(i)
    elif s == "/" and li1:
        j = li1.pop()
        c = i - j
        while li2 and li2[-1][0] > j:
            c += li2[-1][1]
            li2.pop()
        li2.append((j, c))
if li2:
    li3 = list(zip(*li2))[1]
    print(sum(li3))
    print(len(li3), *li3)
else:
    print(0, 0, sep="\n")
"""
0で断絶が生じなければ、一番低い部分は共通で処理できる

Nもhも小さいので、貪欲？にやればもんだいなさそう。
0以外で連続してる部分それぞれについて、実際に水やりを行う。
伸ばすよりはhを短くする方が処理的に楽
"""




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

ans = 0
l,r = 0,0
while True:
    if l > N-1 or r > N-1:
        l,r = 0,0

    while l < N H[l] == 0:
        l += 1

    if l >= N:
        break

    r = l
    while r < N and H[r] != 0:
        r += 1

    tmp = min(H[l:min(r,N)])
    for i in range(l,min(r,N)):
        H[i] -= tmp
    ans += tmp
    l = r + 1

    

print(ans)

### FIXED CODE ###

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

ans = 0
current_height = 0
for i in range(N):
  # h[i-1]までの高さにはh[i]も育っているので、その差分だけ水をやる必要がある
  # current_height は一つ手前の花の高さ
  if h[i] > current_height:
    ans += h[i] - current_height
    current_height = h[i]
  else:
    # i-1番目の花の高さのほうがi番目より高いなら、水を新たにやる必要はない（i-1に水をやるときに同時に達成できるので）
    current_height = h[i]



print(ans)
a = int(input())

b = []

for i in a:
    b.append(list(input().split())

res = 0

for i in b:
    if (b[1] == 'BTC'):
        res += i[0]*380000
    else:
        res += i[0]

print(res)

### FIXED CODE ###

a = int(input())

b = []

for i in range(a):
    b.append(input().split())

res = 0

for i in b:
    if (i[1] == 'BTC'):
        res += float(i[0])*380000
    else:
        res += int(i[0])

print(res)
N = int(input())

frames = []
for i range(N):
  frames.append(int(input()))

mean = sum(frames) / N

sa = 100
ind = 0
for i in range(N):
  if sa > abs(frames[i] - mean):
    sa = abs(frames[i] - mean)
    ind = i
    
print(ind)


### FIXED CODE ###

N = int(input())

frames = list(map(int, input().split(" ")))

mean = sum(frames) / N

sa = 100
ind = 0
for i in range(N):
  if sa > abs(frames[i] - mean):
    sa = abs(frames[i] - mean)
    ind = i
    
print(ind)
import math

N,M = map(int,input().split())
#Nは偶数
#Mは奇数

#偶数偶数
Nf = math.factorial(N)/math.factorial(N-2)/2

#奇数奇数
Mf = math.factorial(M)/math.factorial(M-2)/2

ans = int(Nf + Mf)

print(ans)

### FIXED CODE ###

import math

N,M = map(int,input().split())
#Nは偶数
#Mは奇数

#偶数偶数
if N >= 2:
  Nf = math.factorial(N)//(math.factorial(N-2)*2)
else:
  Nf = 0
#奇数奇数
if M >= 2:
  Mf = math.factorial(M)//(math.factorial(M-2)*2)
else:
  Mf = 0
ans = int(Nf + Mf)
print(ans)
mod = 10 ** 9 + 7

N, M = map(int, input().split())
S = input().split()
T = input().split()

dp = [[0] * (N + 2) for _ in range(M + 2)]
for i in range(N+1):
    dp[i][0] = 1
for j in range(M+1):
    dp[0][j] = 1

for i, s in enumerate(S, 1):
    for j, t in enumerate(T, 1):
        dp[i][j] += dp[i - 1][j]
        dp[i][j] += dp[i][j - 1]
        if s == t:
            dp[i][j] += dp[i - 1][j - 1]
        dp[i][j] -= dp[i - 1][j - 1]
        dp[i][j] += mod
        dp[i][j] %= mod

print(dp[N][M])

### FIXED CODE ###

mod = 10 ** 9 + 7

N, M = map(int, input().split())
S = input().split()
T = input().split()

dp = [[0] * (M + 2) for _ in range(N + 2)]
for i in range(N+1):
    dp[i][0] = 1
for j in range(M+1):
    dp[0][j] = 1

for i, s in enumerate(S, 1):
    for j, t in enumerate(T, 1):
        dp[i][j] += dp[i - 1][j]
        dp[i][j] += dp[i][j - 1]
        if s == t:
            dp[i][j] += dp[i - 1][j - 1]
        dp[i][j] -= dp[i - 1][j - 1]
        dp[i][j] += mod
        dp[i][j] %= mod

print(dp[N][M])