qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
n = int(input())
a = input()
b = input()
c = input()
d = 0
for i in range(0, n):
  if a[i] != b[i] != c[i]:
    d += 2
  if a[i] == b[i] == c[i]:
    d += 0
  if a[i] != b[i] == c[i] or a[i] == b[i] != c[i] or b[i] == a[i] != c[i]:
    d += 1
print(d)

# Fixed code:
n = int(input())
a = input()
b = input()
c = input()
d = 0
for i in range(0, n):
  if a[i:i+1] != b[i:i+1] and b[i:i+1] != c[i:i+1] and a[i:i+1] != c[i:i+1]:
    d += 2
  if a[i:i+1] == b[i:i+1] and b[i:i+1] == c[i:i+1] and a[i:i+1] == c[i:i+1]:
    d += 0
  if a[i:i+1] != b[i:i+1] and b[i:i+1] == c[i:i+1] and c[i:i+1] != a[i:i+1]:
    d += 1
  if a[i:i+1] == b[i:i+1] and b[i:i+1] != c[i:i+1] and c[i:i+1] != a[i:i+1]:
    d += 1
  if a[i:i+1] != b[i:i+1] and b[i:i+1] != c[i:i+1] and c[i:i+1] == a[i:i+1]:
    d += 1
print(d)
# Buggy code:
import sys
n = int(input())
a,b,c = sys.stdin
count = 0
for i in range(n):
  if a[i] == b[i] == c[i]:
    continue
  elif a[i] == b[i] or a[i] == b[i] or b[i] == c[i]:
    count += 1
  else:
    count += 2
print(count)

# Fixed code:
import sys
n = int(input())
a,b,c = sys.stdin
count = 0
for i in range(n):
  if a[i] == b[i] == c[i]:
    continue
  elif a[i] == b[i] or a[i] == c[i] or b[i] == c[i]:
    count += 1
  else:
    count += 2
print(count)
# Buggy code:
#coding:utf-8
n = int(input())
a = input()
b = input()
c = input()
ans = 0

for i in range(n):
  ans += len(set(a[i], b[i], c[i])) - 1 
  
print(ans)


# Fixed code:
#coding:utf-8
n = int(input())
a = input()
b = input()
c = input()
ans = 0
 
for i in range(n):
  ans += len(set([a[i], b[i], c[i]])) - 1 
  
print(ans)
# Buggy code:
n=int(input())
a=input()
b=input()
c=input()
ans=0
for i in range(n):
  if a[i]==b[i]:
    if not b[i]==c[i]:
      ans+=1
  else:
    if b[i]==c[i]:
      ans+=1
    else:
      ans+=2
print(ans)

# Fixed code:
n=int(input())
a=input()
b=input()
c=input()
ans=0
for i in range(n):
    if a[i]==b[i]==c[i]:
        ans+=0
    elif a[i]==b[i]:
        ans+=1
    elif b[i]==c[i]:
        ans+=1
    elif a[i]==c[i]:
        ans+=1
    else:
        ans+=2
print(ans)
# Buggy code:
n = int(input())
a = input()
b = input()
c = input()
count = 0 
for i in range(n):
    if a[i] != b[i]:
        count += 1
    if b[i] != c[i]:
        count += 1
    if a[i] == c[i]:
        count -= 1
print(count)

# Fixed code:
n = int(input())
a = input()
b = input()
c = input()
count = 0

for i in range(n):
    if a[i] != b[i]:
        count += 1
    if b[i] != c[i]:
        if a[i] != c[i]:
            count += 1
print(count)
# Buggy code:
n = int(input())
a = input()
b = input()
c = input()
ans = 0
for i in range(n):
  if (a[i] == b[i]) & (b[i] == c[i]):
    continue
  if (a[i] == b[i]) | (b[i] == c[i]):
    ans += 1
    continue
  ans += 2
print(ans)

# Fixed code:
n = int(input())
a = input()
b = input()
c = input()
ans = 0
for i in range(n):
  if (a[i] == b[i]) & (b[i] == c[i]):
    continue
  if (a[i] == b[i]) | (b[i] == c[i]) | (c[i] == a[i]):
    ans += 1
    continue
  ans += 2
print(ans)
# Buggy code:
n=int(input())
a=input()
b=input()
c=input()
ans=0
for j in range(n):
    d=a[j]
    e=b[j]
    f=c[j]
    if d==e and d!=f:
      ans+=1
    elif d==f and d!=e:
      ans+=1
    elif e==f and e!=d:
      ans+=1
    elif d!=e and e!=f and f!=d:
      ans+=2

# Fixed code:
n=int(input())
a=input()
b=input()
c=input()
ans=0
for j in range(n):
    d=a[j]
    e=b[j]
    f=c[j]
    if d==e and d!=f:
      ans+=1
    elif d==f and d!=e:
      ans+=1
    elif e==f and e!=d:
      ans+=1
    elif d!=e and e!=f and f!=d:
      ans+=2
    
print(ans)
# Buggy code:
n=int(input())
a=input()
b=input()
c=input()
abc=list('0000')
for i in range(n):
    if a[i]==b[i]:
        abc[i]=a[i]
    if b[i]==c[i]:
        abc[i]=b[i]
    if c[i]==a[i]:
        abc[i]=c[i]
count=0
for i in range(n):
    if a[i]!=abc[i]:
        count+=1
    if b[i]!=abc[i]:
        count+=1
    if c[i]!=abc[i]:
        count+=1
print(count)

# Fixed code:
n=int(input())
a=input()
b=input()
c=input()
abc=list('0'*n)
for i in range(n):
    if a[i]==b[i]:
        abc[i]=a[i]
    if b[i]==c[i]:
        abc[i]=b[i]
    if c[i]==a[i]:
        abc[i]=c[i]
    if abc[i]=='0':
        abc[i]=a[i]
count=0
for i in range(n):
    if a[i]!=abc[i]:
        count+=1
    if b[i]!=abc[i]:
        count+=1
    if c[i]!=abc[i]:
        count+=1
print(count)
# Buggy code:
target_list = []
for a, b, c in zip(A, B, C):
    if a==b and b==c:
        target_list.append(3)
    elif a==b or a==c:
        target_list.append(2)
    else:
        target_list.append(1)
print(N*3 - sum(target_list))

# Fixed code:
N = int(input())
A = input()
B = input()
C = input()
target_list = []
for a, b, c in zip(A, B, C):
    if a==b and b==c and c==a:
        target_list.append(3)
    elif a==b or b==c or c==a: 
        target_list.append(2)
    else:
        target_list.append(1)
print(N*3 - sum(target_list))
# Buggy code:
n=int(input())
a=input()
b=input()
c=input()
d=0
for i in range(n):
  if a[i]==b[i]==c[i]:
    continue
  elif a[i]==b[i] or b[i]==c[i]:
    d+=1
  else:
    d+=2
print(d)

# Fixed code:
n=int(input())
a=input()
b=input()
c=input()
d=0
for i in range(n):
  if a[i]==b[i]==c[i]:
    continue
  elif a[i]==b[i] or b[i]==c[i] or a[i]==c[i]:
    d+=1
  else:
    d+=2
print(d)
# Buggy code:
n = int(input())
a = input()
b = input()
c = input()
ans = 0
for i in range(n):
    if not (a[i] == b[i] and b[i] == c[i]):
        ans += 1

print(ans)

# Fixed code:
n = int(input())
a = input()
b = input()
c = input()

ans = 0

for i in range(n):
    if a[i] != b[i]:
        ans += 1
    if a[i] != c[i] and b[i] != c[i]:
        ans += 1
        
print(ans)
# Buggy code:
n = int(input())
a,b,c = input(),input(),input()

count = 0
for i in range(n):
    count += len(set(a[i],b[i],c[i]))-1
print(count)

# Fixed code:
n = int(input())
a = input()
b = input()
c = input()

q = 0
for i in range(n):
  q += len(set([a[i], b[i], c[i]])) - 1
print(q)
# Buggy code:
N = int(input())
A = input()
B = input()
C = input()
cnt = 0

for idx in range(N):
    if A[idx] == B[idx] and A[idx] == C[idx] and B[idx] == C[idx]:
        print(0)
        continue
    elif A[idx] == B[idx]:
        C = C[:idx] + A[idx] + C[idx+1:]
        cnt += 1
    elif A[idx] == C[idx]:
        B = B[:idx] + A[idx] + B[idx+1:]
        cnt += 1
    elif B[idx] == C[idx]:
        A = A[:idx] + B[idx] + A[idx+1:]
        cnt += 1
    else:
        B = B[:idx] + A[idx] + B[idx+1:]
        C = C[:idx] + A[idx] + C[idx+1:]
        cnt += 2
#print(A,B,C)
print(cnt)

# Fixed code:
N = int(input())
A = input()
B = input()
C = input()
cnt = 0

for idx in range(N):
    if A[idx] == B[idx] and A[idx] == C[idx] and B[idx] == C[idx]:
        continue
    elif A[idx] == B[idx]:
        C = C[:idx] + A[idx] + C[idx+1:]
        cnt += 1
    elif A[idx] == C[idx]:
        B = B[:idx] + A[idx] + B[idx+1:]
        cnt += 1
    elif B[idx] == C[idx]:
        A = A[:idx] + B[idx] + A[idx+1:]
        cnt += 1
    else:
        B = B[:idx] + A[idx] + B[idx+1:]
        C = C[:idx] + A[idx] + C[idx+1:]
        cnt += 2
#print(A,B,C)
print(cnt)
# Buggy code:
N = int(input())
A = input()
B = input()
C = input()

ans = 0
for i in range(N):
      if A[i] != B[i] != C[i]:
        ans += 2

      elif A[i] != B[i]:
        ans += 1

      elif A[i] != C[i]:
        ans += 1

      elif B[i] != C[i]:
        ans += 1

print(ans)

# Fixed code:
N = int(input())
A = list(input())
B = list(input())
C = list(input())
ans = 0
for i in range(N):
    if A[i] == B[i]:
        if A[i] != C[i]:
            ans += 1
    else:
        if A[i] == C[i]:
            ans += 1
        elif B[i] == C[i]:
            ans += 1
        else:
            ans += 2
print(ans)
# Buggy code:
N = int(input())
A = [input() for i in range(N)]
ans = 0
for i in range(N):
  ans += len(set(A[0][i],A[1][i],A[2][i]))-1
print(ans)

# Fixed code:
N = int(input())
A = [input() for i in range(3)]
ans = 0
for i in range(N):
  ans += len(set([A[0][i],A[1][i],A[2][i]]))-1
print(ans)
# Buggy code:
N=int(input())
A=list(input())
B=list(input())
C=list(input())
litter=[]
c=0
for s in range(N):
    print(len(set([A[s],B[s],C[s]])))
    c+=[0,0,1,2][len(set([A[s],B[s],C[s]]))]
print(c)

# Fixed code:
N=int(input())
A=list(input())
B=list(input())
C=list(input())
litter=[]
c=0
for s in range(N):
    c+=[0,0,1,2][len(set([A[s],B[s],C[s]]))]
print(c)
# Buggy code:
n=int(input())
a=list(input())
b=list(input())
c=list(input())

print(a,b,c)

ans=0

for i in range(n):

    s=[a[i],b[i],c[i]]
    buff=set(s)
    ans += len(buff)-1

print(ans)

# Fixed code:
n=int(input())
a=list(input())
b=list(input())
c=list(input())

ans=0

for i in range(n):

    s=[a[i],b[i],c[i]]
    buff=set(s)
    ans += len(buff)-1

print(ans)
# Buggy code:
N = int(input())
A = input()
B = input()
C = input()
count = 0

for i in range(N):
  if A[i] != B[i]:
    count += 1
for i in range(N):
  if A[i] != C[i]:
    count += 1

print(count)


# Fixed code:
N = int(input())
A = input()
B = input()
C = input()
count = 0
for i in range(N):
    if A[i]!=B[i]:
        count += 1
    if A[i]!=C[i]:
        if B[i] != C[i]:
            count += 1
print(count)
# Buggy code:
a = int(input())
b = (input())
c = (input())
d = (input())
count = 0
for i in range(a):
    if b[i] == c[i] == d[i]:
        count += 0
    elif b[i] == c[i] or b[i] == d[i] == c[i] == d[i]:
        count += 1
    else:
        count += 2
print(count)


# Fixed code:
a = int(input())
b = (input())
c = (input())
d = (input())
count = 0
for i in range(a):
    if b[i] == c[i] == d[i]:
        count += 0
    elif b[i] == c[i] or b[i] == d[i]  or  c[i] == d[i]:
        count += 1
    else:
        count += 2
print(count)
# Buggy code:
n = int(input())
s = [input() in range(3)]
ans = 2*n
for i in range(n):
  if s[0][i] == s[1][i]: ans -= 1
  if s[0][i] == s[2][i]: ans -= 1
  if s[2][i] == s[1][i]: ans -= 1
  if s[0][i] == s[1][i] and s[2][i] == s[1][i] : ans += 1
print(ans)

# Fixed code:
n = int(input())
s = [input() for _ in range(3)]
ans = 2*n
for i in range(n):
  if s[0][i] == s[1][i]: ans -= 1
  if s[0][i] == s[2][i]: ans -= 1
  if s[2][i] == s[1][i]: ans -= 1
  if s[0][i] == s[1][i] and s[2][i] == s[1][i] : ans += 1
print(ans)
# Buggy code:
N = int(input())
a = []
for i in range(3):
    a.append(input())

ans = 0
for i in range(N):
    if a[0][i] != a[1][i] and a[1][i] != a[2][i]:
        ans += 2
    elif a[0][i] == a[1][i] and a[1][i] == a[2][i]:
        continue
    else:
        ans += 1
print(ans)

# Fixed code:
N = int(input())
a = []
for i in range(3):
    a.append(input())

ans = 0
for i in range(N):
    if a[0][i] != a[1][i] and a[1][i] != a[2][i] and a[0][i] != a[2][i]:
        ans += 2
    elif a[0][i] == a[1][i] and a[1][i] == a[2][i] and a[0][i] == a[2][i]:
        continue
    else:
        ans += 1
print(ans)
# Buggy code:
n=int(input())
a=input()
b=input()
c=input()
ans=0
for i in range(n):
  if len(set([a,b,c]))==3:
    ans+=2
  elif len(set([a,b,c]))==2:
    ans+=1
print(ans)
    

# Fixed code:
n = int(input())
a = input()
b = input()
c = input()
ans = 0
for i in range(n):
  s = len(set([a[i], b[i], c[i]]))
  if (s == 3):
    ans += 2
  elif (s == 2):
    ans += 1
print(ans)
# Buggy code:
N = int(input())
A = input()
B = input()
C = input()
ans = 0

for i in range(N):
    if A[i] == B[i] and B[i] == C[i]:
        continue
    elif A[i] != B[i] and B[i] != C[i]:
        ans += 2
    else:
        ans += 1

print(ans)

# Fixed code:
N = int(input())
A = (input())
B = (input())
C = (input())

ans = 0
for i in range(N):
    if A[i]==B[i]==C[i]:
        continue
    elif A[i]!=B[i] and B[i]!=C[i] and C[i] !=A[i]:
        ans +=2
    else:
        ans +=1

print(ans)
# Buggy code:
n = int(input())
a = input().strip()
b = input().strip()
c = input().strip()
ans = 0
for _a, _b, _c in zip(a, b, c):
  if _a != _b and _b != _c:
    ans += 2
  elif _a == _b and _b == _c:
    continue
  else:
    ans += 1
print(ans)

# Fixed code:
n = int(input())
a = input().strip()
b = input().strip()
c = input().strip()
ans = 0
for _a, _b, _c in zip(a, b, c):
  if _a != _b and _b != _c and _a != _c:
    ans += 2
  elif _a == _b and _b == _c:
    continue
  else:
    ans += 1
print(ans)
# Buggy code:
N = int(input())
A = list(str(input()))
B = list(str(input()))
C = list(str(input()))

res = 0
for i in range(N):
    if A[i] != B[i]:
        res+=1
    if A[i] != C[i]:
        res+=1

print(res)


# Fixed code:
N = int(input())
A = list(str(input()))
B = list(str(input()))
C = list(str(input()))

res = 0
for i in range(N):
    if A[i] != B[i] or  A[i] != C[i] or  B[i] != C[i]:
        res+=1
    if A[i] != B[i] and A[i] != C[i] and B[i] != C[i]:
        res+=1
print(res)
# Buggy code:
n=int(input())
a=input()
b=input()
c=input()
d=0
for i in range(n):
	if a[i]!=b[i]!=c[i]:
		d+=2
	elif not a[i]==b[i]==c[i]:
		d+=1
print(d)

# Fixed code:
n=int(input())
a=input()
b=input()
c=input()
d=0
for i in range(n):
	if a[i]!=b[i] and b[i]!=c[i] and a[i]!=c[i]:
		d+=2
	elif not a[i]==b[i]==c[i]:
		d+=1
print(d)
# Buggy code:
def diff(a, b, c):
    i = 0
    for aa, bb, cc in zip(a, b, c):
        if aa != bb or aa != cc:
            i += 1
    return i

n = int(input())
a = list(input())
b = list(input())
c = list(input())

print(diff(a, b, c))

# Fixed code:
def diff(a, b, c):
    i = 0
    for aa, bb, cc in zip(a, b, c):
        if aa != bb and aa != cc and bb != cc:
            i += 2
        elif aa != bb or bb != cc:
            i += 1
    return i

n = int(input())
a = list(input())
b = list(input())
c = list(input())

print(diff(a, b, c))
# Buggy code:
n = int(input())
flower = input().split()
for i in range(n):
    flower[i] = int(flower[i])
print(flower)
a = 0
def water():
    if sum(flower) == 0:
        a = -1
    elif 0 in flower:
        i = 0
        while flower[i] == 0:
            i += 1
        j = i
        try:
            while flower[j+1] != 0:
                j += 1
        except:
            abc = i
        for k in range(i,j+1):
            flower[k] -= 1
    else:
        for i in range(n):
            flower[i] -= 1
ans = 0
while sum(flower) != 0:
    water()
    ans += 1
print(ans)

# Fixed code:
n = int(input())
flower = input().split()
for i in range(n):
    flower[i] = int(flower[i])
a = 0
def water():
    if sum(flower) == 0:
        a = -1
    elif 0 in flower:
        i = 0
        while flower[i] == 0:
            i += 1
        j = i
        try:
            while flower[j+1] != 0:
                j += 1
        except:
            abc = i
        for k in range(i,j+1):
            flower[k] -= 1
    else:
        for i in range(n):
            flower[i] -= 1
ans = 0
while sum(flower) != 0:
    water()
    ans += 1
print(ans)
# Buggy code:
n=int(input())
h=list(map(int,input().split()))
l=[0]
c='plus'
for i in range(n-1):
    if c=='minus' and h[i]<=h[i+1]:
        l.append(i)
    if h[i]<=h[i+1]:c='plus'
    else:c='minus'

w=0
m=0
for i in range(len(l)-1):
    w+=max(h[l[i]:l[i+1]+1])-m
    m=h[l[i+1]]
w+=max(h[l[-1]:-1])-m
print(w)

# Fixed code:
n=int(input())
h=list(map(int,input().split()))
l=[0]
c='plus'
for i in range(n-1):
    if c=='minus' and h[i]<=h[i+1]:
        l.append(i)
    if h[i]<=h[i+1]:c='plus'
    else:c='minus'

w=0
m=0
for i in range(len(l)-1):
    w+=max(h[l[i]:l[i+1]+1])-m
    m=h[l[i+1]]
w+=max(h[l[-1]:n])-m
print(w)
# Buggy code:
N = int(input())
h = list(map(int, input().split()))

a = [0]*N
answer = 0
while(True):
    area_flag = False
    area = 0
    comp_cnt = 0
    # print(a)
    for i in range(N):
        if a[i]>=h[i] and h[i]==0:
            comp_cnt+=1
            if area_flag:
                area += 1
            area_flag = False
            continue
        elif a[i]>=h[i]:
            comp_cnt+=1
            if area_flag:
                area += 1
            area_flag = False
            continue
        area_flag = True
        a[i]+= 1
    if area_flag:
        area += 1
    answer += area
    # print(answer)
    if comp_cnt == N: 
        answer += min(h)
        break


print(answer)
        


# Fixed code:
N = int(input())
h = list(map(int, input().split()))

a = [0]*N
answer = 0
while(True):
    area_flag = False
    area = 0
    comp_cnt = 0
    # print(a)
    for i in range(N):
        if a[i]>=h[i] and h[i]==0:
            comp_cnt+=1
            if area_flag:
                area += 1
            area_flag = False
            continue
        elif a[i]>=h[i]:
            comp_cnt+=1
            if area_flag:
                area += 1
            area_flag = False
            continue
        area_flag = True
        a[i]+= 1
    if area_flag and comp_cnt!=0:
        area += 1
    answer += area
    # print(area)
    if comp_cnt == N: 
        answer += min(h)
        break


print(answer)
# Buggy code:
def get_nonzero_range(A):
    start, end = None, None
    N = len(A)
    for i in range(N):
        if A[i] != 0:
            start = i
            for j in range(i+1, N):
                if A[j] == 0:
                    end = j
                    return start, end
    else:
        return start, end

N = int(input())
H = list(map(int, input().split()))
H.append(0)
num = 0
print(H)
while True:
    start, end = get_nonzero_range(H)
    print(start, end)
    if start == None:
        break
    else:
        for i in range(start, end):
            H[i] -= 1
        num += 1
print(num)

# Fixed code:
def get_nonzero_range(A):
    start, end = None, None
    N = len(A)
    for i in range(N):
        if A[i] != 0:
            start = i
            for j in range(i+1, N):
                if A[j] == 0:
                    end = j
                    return start, end
    else:
        return start, end

N = int(input())
H = list(map(int, input().split()))
H.append(0)
num = 0
while True:
    start, end = get_nonzero_range(H)
    if start == None:
        break
    else:
        for i in range(start, end):
            H[i] -= 1
        num += 1
print(num)
# Buggy code:
N = int(input())
H = np.array(input().split(), dtype=np.int32)

def myfunc(left, right):
    if right<left:
        return 0
    idx = left+H[left:right+1].argmin()
    m = H[idx]
    H[left:right+1]-=m
    return m+myfunc(left, idx-1)+myfunc(right, idx+1)

print(myfunc(0, N-1))

# Fixed code:
import numpy as np

N = int(input())
H = np.array(input().split(), dtype=np.int32)

def myfunc(left, right):
    if right<left:
        return 0
    idx = left+H[left:right+1].argmin()
    m = H[idx]
    H[left:right+1]-=m
    return m+myfunc(left, idx-1)+myfunc(idx+1, right)

print(myfunc(0, N-1))
# Buggy code:
a = [int(i) for i in input().split()] 
n = 0
num = a[0]
for i in a:
  max = a[0]
  
  
  if i > a[n-1] and n > 0:
    num += (i-a[n-1])
  n += 1
print(num)  
  
  
  

# Fixed code:
l = input()
a = [int(i) for i in input().split()] 
n = 0
num = a[0]
for i in a:
  max = a[0]
  
  
  if i > a[n-1] and n > 0:
    num += (i-a[n-1])
  n += 1
print(num)
# Buggy code:
n = int(input())
heights = list(map(int, input().split()))

def nextgen(comb):
    lis = comb[0]
    j = comb[1]
    for i in range(len(lis)-1):
        if (i != len(lis) and (lis[i] == 0 and lis[i+1] != 0)) or (i == 0 and lis[i] != 0):
            j += 1
        if lis[i] != 0:
            lis[i] -= 1
    if lis[len(lis)-1] != 0:
        lis[len(lis)-1] -= 1
    return [lis, j]

comb = [heights, 0]
while (comb[0].count(0) != len(comb[0])):
    comb = test(comb)

print(comb[1])

# Fixed code:
n = int(input())
heights = list(map(int, input().split()))

def nextgen(comb):
    lis = comb[0]
    j = comb[1]
    if len(lis) == 1 and lis[0] != 0:
        j += 1  
    for i in range(len(lis)-1):
        if (i != len(lis) and (lis[i] == 0 and lis[i+1] != 0)) or (i == 0 and lis[i] != 0):
            j += 1
        if lis[i] != 0:
            lis[i] -= 1
    if lis[len(lis)-1] != 0:
        lis[len(lis)-1] -= 1
    return [lis, j]

comb = [heights, 0]
while (comb[0].count(0) != len(comb[0])):
    comb = nextgen(comb)

print(comb[1])
# Buggy code:
import numpy as np

def my_index(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

n = int(input())
h = list(map(int, input().split()))
h = np.array(h)

i = 0
min_h = h.min()
h -= min_h
ans = min_h

if np.all(h==0):
    print(h)
    quit()

split_h = []
zero_index = my_index(h, 0)

split_h = []
list_h = []
for elem in h:
    if elem != 0:
        list_h.append(elem)
    else:
        if list_h:
            split_h.append(np.array(list_h))
            list_h = []

while len(split_h):
    sph = split_h.pop()

    min_h = sph.min()
    sph -= min_h
    ans += min_h

    if np.all(sph == 0):
        continue

    for elem in sph:
        if elem != 0:
            list_h.append(elem)
        else:
            if list_h:
                split_h.append(np.array(list_h))
                list_h = []

print(ans)


# Fixed code:
import numpy as np

def my_index(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

n = int(input())
h = list(map(int, input().split()))
h = np.array(h)

split_h = []
split_h.append(h)

ans = 0
list_h = []
while len(split_h):
    sph = split_h.pop()

    min_h = sph.min()
    sph -= min_h
    ans += min_h

    if np.all(sph == 0):
        continue

    for elem in sph:
        if elem != 0:
            list_h.append(elem)
        else:
            if list_h:
                split_h.append(np.array(list_h))
                list_h = []
    if list_h:
        split_h.append(np.array(list_h))
        list_h = []

print(ans)
# Buggy code:
N = int(input())
h_ls = list(map(int,input().split(" ")))

h_ls = np.array(h_ls)
n = 0
h_len = len(h_ls)
while max(h_ls)!=0:
    max_ind = h_ls.argmax()
    d = 0
    while max_ind+d < h_len -1 and h_ls[max_ind+d+1]==h_ls[max_ind]:
        d+=1
    h_ls[max_ind:max_ind+d+1] =h_ls[max_ind:max_ind+d+1]-1
    n+=1
    print(h_ls)

print(n)


# Fixed code:
import numpy as np

N = int(input())
h_ls = list(map(int,input().split(" ")))

h_ls = np.array(h_ls)
n = 0
h_len = len(h_ls)
while max(h_ls)!=0:
    max_ind = h_ls.argmax()
    d = 0
    while max_ind+d < h_len -1 and h_ls[max_ind+d+1]==h_ls[max_ind]:
        d+=1
    h_ls[max_ind:max_ind+d+1] =h_ls[max_ind:max_ind+d+1]-1
    n+=1

print(n)
# Buggy code:
le = int(input())
ll = list(map(int, input().split()))
 
res = h[0]
for i in range(1, ll):
    if(ll[i-1] < ll[i]): res += ll[i]-ll[i-1]
print(res)

# Fixed code:
le = int(input())
ll = list(map(int, input().split()))
 
res = ll[0]
for i in range(1, le):
    if(ll[i-1] < ll[i]): res += ll[i]-ll[i-1]
print(res)
# Buggy code:
n=int(input())
x=list(map(int,input().split()))
ans=0
for i in range(n-1):
  ans+=max(0,x[i+1]-x[i])
print(ans)

# Fixed code:
n=int(input())
x=list(map(int,input().split()))
ans=0
for i in range(n-1):
  ans+=max(0,x[i+1]-x[i])
print(ans+x[0])
# Buggy code:
n = int(input())
h = list(map(int,input().split()))
a = 0
while sum(h) > 0:
    lst = [i for i, x in enumerate(h) if x > 0]
    mx = min(lst)
    for i in range(len(lst) -1):
        if lst[i] + 1 == lst[i+1]:
            mx += 1
        else:
            break
    h = [x - 1 if i >= min(lst) and  i <= mx else x for i, x in enumerate(h)]
    a += 1
    print(h)
print(a)

# Fixed code:
n = int(input())
h = list(map(int,input().split()))
a = 0
while sum(h) > 0:
    lst = [i for i, x in enumerate(h) if x > 0]
    mx = min(lst)
    for i in range(len(lst) -1):
        if lst[i] + 1 == lst[i+1]:
            mx += 1
        else:
            break
    h = [x - 1 if i >= min(lst) and i <= mx else x for i, x in enumerate(h)]
    a += 1
print(a)
# Buggy code:
N = int(input())
lst_h = list(map(int, input().split()))


ans = 0
now = 0
for i in range(N):
    if lst_h[i] > now:
        ans += now
    now = lst_h[i]


print(ans)

# Fixed code:
N = int(input())
lst_h = list(map(int, input().split()))


ans = 0
now = 0
for i in range(N):
    if lst_h[i] > now:
        ans += lst_h[i] - now
    now = lst_h[i]


print(ans)