Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03037 (python)

Fixed submission:
l = raw_input().split()
N = int(l[0])
M = int(l[1])

L = []
R = []

for i in range(M):
    l = raw_input().split()
    L.append(int(l[0]))
    R.append(int(l[1]))

l = max(L)
r = min(R)
# print(l, r)
if l > r:
    print(0)
else:
    print(r - l + 1)

Buggy submission (verdict: Runtime Error):
l = raw_input().split()
N = int(l[0])
M = int(l[1])

L = []
R = []

for i in range(M):
    l = raw_input().split()
    L.append(int(l[0]))
    R.append(int(l[1]))

l = max(L)
#r = min(R)
print(l, r)
if l > r:
    print(0)
else:
    print(r - l + 1)
Problem p03076 (python)

Fixed submission:
import sys

M = []
N = []
for i in range(5):
    l = int(raw_input().split()[0])
    if l % 10 == 0:
        M.append(l)
    else:
        N.append(l)
N = sorted(N,  key=lambda x: 10 - (x % 10))
# print(M, N)

ret = 0
for m in M:
    ret += m
for n in N:
    ret += n
    ret += (10 - (n % 10))
if len(N) != 0:
    ret -= (10 - (N[-1] % 10))
print(ret)

Buggy submission (verdict: Runtime Error):
import sys

M = []
N = []
for i in range(5):
    l = int(raw_input().split()[0])
    if l % 10 == 0:
        M.append(l)
    else:
        N.append(l)
N = sorted(N,  key=lambda x: 10 - (x % 10))
# print(M, N)

ret = 0
for m in M:
    ret += m
for n in N:
    ret += n
    ret += (10 - (n % 10))
ret -= (10 - (N[-1] % 10))
print(ret)
Problem p03105 (python)

Fixed submission:
import sys

l = raw_input().split()
a = int(l[0])
b = int(l[1])
c = int(l[2])

ret = int(b/a)
if ret >= c:
    ret =c

print(ret)

Buggy submission (verdict: Runtime Error):
import sys

args = sys.argv
a = int(args[1])
b = int(args[2])
c = int(args[3])

ret = int(b/a)
if ret >= c:
    ret =c

print(ret)
Problem p03274 (python)

Fixed submission:
def main():
    N, K = map(int, input().split())
    X = list(map(int, input().split()))
    D = [0]*(N - 1)
    for i in range(1, N):
        D[i-1] = X[i] - X[i - 1]
    ans = 0
    t = 0
    T = [0]*(N - K + 1)
    for i in range(1, N):
        t += D[i-1]
        if i < K:
            if i == K - 1:
                T[0] = t
            continue
        t -= D[i - K]
        T[i - K + 1] = t
    # print(D, T)
    ans = K * 10**8
    for i in range(N - K + 1):
        a = T[i] + min(abs(X[i]), abs(X[i + K - 1]))
        ans = min(a, ans)
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N, K = map(int, input().split())
    X = list(map(int, input().split()))
    D = [0]*(N - 1)
    for i in range(1, N):
        D[i-1] = X[i] - X[i - 1]
    ans = 0
    t = 0
    T = [0]*(N - K + 1)
    for i in range(1, N):
        t += D[i-1]
        if i < K:
            if i == K - 1:
                T[0] = t
            continue
        t -= D[i - K]
        T[i - K + 1] = t
    # print(D, T)
    ans = K * 10**8
    for i in range(N - K + 1):
        a = T[i] + min(abs(X[i]), abs(X[i + K - 1])]
        ans = min(a, ans)
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N, K = map(int, input().split())
    X = list(map(int, input().split()))
    D = [0]*(N - 1)
    for i in range(1, N):
        D[i-1] = X[i] - X[i - 1]
    ans = 0
    t = 0
    T = [0]*(N - K + 1)
    for i in range(1, N):
        t += D[i-1]
        if i < K:
            if i == K - 1:
                T[0] = t
            continue
        t -= D[i - K]
        T[i - K + 1] = t
    # print(D, T)
    ans = K * 10**8
    for i in range(N - K + 1):
        a = T[i] + min(abs(X[i]), abs[X[i + K - 1])]
        ans = min(a, ans)
    print(ans)

if __name__ == '__main__':
    main()
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())
# print(S, K)
for i in range(len(S)):
    s = S[i]
    if i >= K:
        break
    if s != '1':
        print(s)
        exit()
print('1')

Buggy submission (verdict: Runtime Error):
S,K,c=input(),int(input()),0
while c<K and S[c]=='1':c+=1
print(S[c])

Buggy submission (verdict: Runtime Error):
S=input()
K=int(input())
c=0
a='1'
while c<K and S[c]=='1':
 c+=1
print(S[c])

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
# print(S, K)
for i in range(len(S)):
    if i >= K:
        break
    if s != '1':
        print(s)
        exit()
print('1')
Problem p03575 (python)

Fixed submission:
l = input().split()
N = int(l[0])
M = int(l[1])

C = []

for i in range(M):
    l = input().split()
    C.append([int(x) - 1 for x in l])

# print(N, M, C)

def visit(s, G, visited):
    # print(s, G, visited)
    visited.add(s)
    for g in G:
        if g[0] in visited:
            n = g[1]
            G.remove(g)
            return visit(n, G, visited)
        elif g[1] in visited:
            n = g[0]
            G.remove(g)
            return visit(n, G, visited)
    return

ans = 0
for i in range(M):
    D = []
    for j in range(M):
        if i != j:
            D.append(C[j])
    visited = set()
    visit(0, D, visited)
    # print(i, len(visited))
    if len(visited) != N:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
l = input().split()
N = int(l[0])
M = int(l[1])

C = []

for i in range(M):
    l = input().split()
    C.append([int(x) - 1 for x in l])

# print(N, M, C)

def visit(s, G, visited):
    # print(s, G, visited)
    visited.add(s)
    for g in G:
        if g[0] in visited:
            n = g[1]
            G.remove(g)
            return visit(n, G, visited)
        elif g[1] in visited:
            n = g[0]
            G.remove(g)
            return visit(n, G, visited)
    return

ans = 0
for i in range(N):
    D = []
    for j in range(N):
        if i != j:
            D.append(C[j])
    visited = set()
    visit(0, D, visited)
    # print(i, len(visited))
    if len(visited) != N:
        ans += 1

print(ans)
Problem p03645 (python)

Fixed submission:
N, M = map(int, input().split())
T = {}
for i in range(M):
    a, b = map(int, input().split())
    if a not in T:
        T[a] = []
    T[a].append(b)
    if b not in T:
        T[b] = []
    T[b].append(a)
# print(N, M, T)
FROM_1 = T[1]

for f in FROM_1:
    if N in T[f]:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
def solve():
    N, M = map(int, input().split())
    T = {}
    for i in range(M):
        a, b = map(int, input().split())
        if a not in T:
            T[a] = []
        T[a].append(b)
        if b not in T:
            T[b] = []
        T[b].append(a)
    # print(N, M, T)
    FROM_1 = set(T[1])
    TO_N = set(T[N])
    ans = FROM_1 & TO_N
    print('POSSIBLE') if ans else print('IMPOSSIBLE')

if __name__ == '__main__':
    solve()
Problem p02767 (python)

Fixed submission:
n = int(input())
x = list(map(int,input().split()))
ans = []
if len(set(x)) == 1:
    print(0)
else: 
    for p in range(min(x), max(x)):
        meter = 0
        for xi in x:
            meter += pow((xi-p),2)
        ans.append(meter)
    print(min(ans))

Buggy submission (verdict: Runtime Error):
n = int(input())
x = list(map(int,input().split()))
ans = []
for p in range(min(x), max(x)):
    meter = 0
    for xi in x:
        meter += pow((xi-p),2)
    ans.append(meter)
print(min(ans))
Problem p03086 (python)

Fixed submission:
s =  list(input())
combo = False
cnt = 0
ans = [0,] 
for mozi in s:
    if(mozi == "A" or mozi == "G" or mozi == "C" or mozi == "T"):
        cnt = cnt + 1 
        if combo != True:
            combo = True
    else:
        if combo:
            ans.append(cnt)
            cnt = 0
            combo = False
ans.append(cnt)
print(max(ans))

Buggy submission (verdict: Runtime Error):
s =  list(input())
combo = False
cnt = 0
ans = [] 
for mozi in s:
    if(mozi == "A" or mozi == "G" or mozi == "C" or mozi == "T"):
        cnt = cnt + 1 
        if combo != True:
            combo = True
    elif combo:
        ans.append(cnt)
        cnt = 0
        combo = False
print(max(ans))
Problem p03469 (python)

Fixed submission:
datestr = input()

if (datestr[0:8] == '2017/01/'):
    ans = datestr.replace("2017",'2018')
    
print(ans)

Buggy submission (verdict: Runtime Error):
num = int(input())
mochi = [int(input()) for m in range(0, num)]
maisuu = len(set([n for n in mochi]))
print(maisuu)
Problem p03957 (python)

Fixed submission:
s =  list(input())
if ("C" in s and "F" in s):
    if(s.count("F") == 1):
        if(s.index("C") < s.index("F")):
            print("Yes")
        else:
            print("No")
    else:
        if(s.index("C") < s.index("F",1)):
            print("Yes")
        else:
            print("No")

else:
    print("No")

Buggy submission (verdict: Runtime Error):
s =  list(input())
if ("C" in s and "F" in s):
    
    if(s.index("C") < s.index("F",1)):
       print("Yes")
    else:
       print("No")
else:
    print("No")
Problem p03308 (python)

Fixed submission:
input()
a=list(map(int,input().split()))
print(max(a)-min(a))

Buggy submission (verdict: Runtime Error):
input()
a=map(int,input().split())
print(max(a)-min(a))
Problem p03323 (python)

Fixed submission:
a,b = map(int,input().split())
if a<=8 and b<=8:
    print("Yay!")
else:
    print(":(")

Buggy submission (verdict: Runtime Error):
a = []
b = []
mem = {}
ans = 0
def flip(f):
    for i in range(len(a)):
        for j in range(3):
            if f & (1 << j) == 1:
                a[i][j] = - a[i][j]
def solve(n,m):
    if(mem.get((n,m))!=None):
        return mem[(n,m)]
    if m == 0:
        return 0
    if n == m:
        mem[(n,m)] = sum(b[:n])
        return mem[(n,m)]
    ans = max([solve(n-1,m-1) + b[n-1] , solve(n-1,m)])
    mem[(n,m)] = ans
    return ans
n,m = map(int,input().split())
for i in range(n):
    a.append(list(map(int,input().split())))
for f in range(8):
    b.clear()
    flip(f)
    for x in a:
        b.append(sum(x))
    mem.clear()
    ans = max([ans,solve(n,m)])
    flip(f)
print(ans)
Problem p03439 (python)

Fixed submission:
n = int(input())
l = 0
r = n-1
mid = (l+r)/2
print(l)
s1 = raw_input()
if s1 == 'Vacant':
    exit(0)
print(mid)
s2 = raw_input()
if s2 == 'Vacant':
    exit(0)
while True:
    #print("before:",l,r)
    if (mid-l) % 2 == int(s1 != s2):
        l = mid
        s1 = s2
    else:
        r = mid
    #print("after:",l,r)
    mid = (l+r)/2
    if mid == l:
        break
    print(mid)
    s2 = raw_input()
    if s2 == 'Vacant':
        exit(0)
print(mid+1)
s1 = raw_input()

Buggy submission (verdict: Runtime Error):
n = int(input())
l = 0
r = n-1
mid = (l+r)/2
print(l)
s1 = raw_input()
if s1 == 'Vacant':
    exit(0)
print(mid)
s2 = raw_input()
if s2 == 'Vacant':
    exit(0)
while True:
    print("before:",l,r)
    if (mid-l) % 2 == int(s1 != s2):
        l = mid
        s1 = s2
    else:
        r = mid
    print("after:",l,r)
    mid = (l+r)/2
    if mid == l:
        break
    print(mid)
    s2 = raw_input()
    if s2 == 'Vacant':
        break
print(mid+1)
s1 = raw_input()

Buggy submission (verdict: Runtime Error):
n = int(input())
l = 0
r = n-1
mid = (l+r)/2
print(l)
s1 = raw_input()
if s1 == 'Vacant':
    exit()
print(mid)
s2 = raw_input()
if s2 == 'Vacant':
    exit()
while True:
    print("before:",l,r)
    if (mid-l) % 2 == int(s1 != s2):
        l = mid
        s1 = s2
    else:
        r = mid
    print("after:",l,r)
    mid = (l+r)/2
    if mid == l:
        break
    print(mid)
    s2 = raw_input()
    if s2 == 'Vacant':
        break
print(mid+1)
s1 = raw_input()
Problem p02615 (python)

Fixed submission:

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

a[0]=10**10

m=int((n-2)/2)

a=sorted(a,reverse=True)

comfort=a[1]
if(n==2):
  print(comfort)
else:
  
  for i in range(2,m+2):
    comfort+=(2*a[i])

  if(n%2 ==0):
    print(comfort)
  else:
    print(comfort+a[m+2])

Buggy submission (verdict: Runtime Error):
n=int(input())
a=input().split()
a=[0 for i in range(n+1)]
for i in range(1,n+1):
  a[i]=int(a[i-1])

a[0]=1000000000

m=floor((n-2)/2)

a=sorted(a,reverse=True)
comfort=a[1]
if(n==2):
  print(comfort)
else:
  if(n%2 ==0):
    for i in range(2,m+2):
      comfort+=(2*a[i])
  else:
    for i in range(2,m+2):
      comfort+=(2*a[i])

    comfort+=a[m+2]

Buggy submission (verdict: Runtime Error):
n=int(input())
a=input().split()
a=[0 for i in range(n+1)]
for i in range(1,n+1):
  a[i]=int(a[i-1])

a[0]=1000000000

m=floor((n-2)/2)

a=sorted(a,reverse=True)
comfort=a[1]
if(n==2):
  print(comfort)
else:
  if(n%2 ==0):
    for i in range(2,m+2):
      comfort+=(2*a[i])
  else:
    for i in range(2,m+2):
      comfort+=(2*a[i])

    comfort+=a[m+2]
Problem p02747 (python)

Fixed submission:
def main():
    S = list(input())
    k = 0
    ans = False
    
    while True :
        if len(S) % 2 != 0 :
            break 
        elif k == len(S):
            ans = True
            break
        elif S[k] + S[ k + 1] != "hi":
            break
        else :
            k += 2
    if ans : print("Yes")
    else: print("No")
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    S = list(input())
    k = 0
    ans = False
    while True :
        if k >= len(S):
            ans = True
            break
        elif S[k] + S[ k + 1] != "hi":
            break
        else :
            k += 2
    if ans : print("Yes")
    else: print("No")
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    S = list(input())
    k = 0
    ans = False
    while True :
        if k == len(S):
            ans = True
            break
        elif S[k] + S[ k + 1] != "hi":
            break
        else :
            k += 2
    if ans : print("Yes")
    else: print("No")
if __name__ == '__main__':
    main()
Problem p02756 (python)

Fixed submission:
S = input()
N = int(input())
Q = [[] for _ in range(N)]
for i in range(N):
    line = input().split()
    Q[i] = line
reverse = 0
r_b = ""
r_f = ""
for i in range(N):
    if Q[i][0] == '1' :
        reverse = (reverse + 1) % 2
    else :
        if reverse == 0 :
            if Q[i][1] == '1' :
                r_f = Q[i][2] + r_f
            else :
                r_b = r_b +Q[i][2]
        else:
            if Q[i][1] == '1':
                r_b = r_b +Q[i][2]
            else:
                r_f = Q[i][2] + r_f
if reverse == 0 :
    print(r_f + S + r_b)
else:
    r_f = r_f[::-1]
    r_b = r_b[::-1]
    S = S[::-1]
    print(r_b + S + r_f)

Buggy submission (verdict: Runtime Error):
S = input().split()
N = int(input())
reverse = 0
r_b = []
r_f = []
for i in range(N):
    line = input().split()
    if line[i][0] == '1' :
        reverse = (reverse + 1) % 2
    else :
        if reverse == 0 :
            if line[i][1] == '1' :
                r_f = [line[i][2]] + r_f
            else :
                r_b.append(line[i][2])
        else:
            if line[i][1] == '1':
                r_b.append(line[i][2])
            else:
                r_f = [line[i][2]] + r_f

if reverse == 0 :
    S = r_f + S + r_b
    print("".join(S))
else:
    S.reverse()
    r_b.reverse()
    r_f.reverse()
    S = r_b + S + r_f
    print("".join(S))
Problem p02900 (python)

Fixed submission:
def gcd(x, y):
    if y == 0 :
        return x
    else:
        return gcd(y,x%y)
def prime(x):
    global  ans
    m = x ** (0.5)
    for i in range(2,int(m+1)):
        if x % i == 0 :
            while True:
                if x % i != 0 :
                    break
                else:
                    x = (x//i)
            ans +=1
    if x != 1 :
        ans += 1
    return ans
A,B = map(int,input().split())
t = gcd(A,B)
ans = 1
print(prime(t))

Buggy submission (verdict: Runtime Error):
def check2(x,y,p,t):
    for i in range(p,t,1):
        if x % i == 0 and y % i == 0 :
            return int(i)
    if (i+1) == t :
        return 1
A,B = map(int,input().split())
ans = 1
p = 2
while True :
    t = min(A, B)
    p = check2(A,B,p,t)
    if p ==  1  :
        break
    while True :
        if A % p == 0 and B % p == 0 :
            A = (A//p)
            B = (B//p)
        else :
            break
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
def check2(x,y,p,t):
    for i in range(p,t,1):
        if x % i == 0 and y % i == 0 :
            return i
        if i * i > t :
            return -1
A,B = map(int,input().split())
ans = 1
p = 2
t = min(A, B)
while True :
    p = check2(A,B,p,t)
    if p == -1 :
        break
    while True :
        if A % p == 0 and B % p == 0 :
            A = (A//p)
            B = (B//p)
        else :
            break
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
def check2(x,y,p,t):
    for i in range(p+1,t+1,1):
        if x % i == 0 and y % i == 0 :
            return i
        if i == t :
          return 1 
A,B = map(int,input().split())
ans = 1
p = 1
t = min(A,B)
while True :
    p = check2(A,B,p,t)
    if p == 1 :
        break
    while True :
        if A % p == 0 and B % p == 0 :
            A = (A//p)
            B = (B//p)
        else :
            break
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
def check2(x,y,p):
    t = min(x,y)
    for i in range(p+1,t):
        if x % i == 0 and y % i == 0 :
            return i
        if i * i >= t :
            return 0
A,B = map(int,input().split())
ans = 1
p = 1
while True :
    p = check2(A,B,p)
    if p == 0 :
        break
    A = (A // p)
    B = (B // p)
    while True :
        if A % p == 0 and B % p == 0 :
            A = (A//p)
            B = (B//p)
        else :
            break
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
def check(a,b):
    if b == 0 :
        return a
    return check(b,a%b)
def check2(x,y,p):
    t = min(x,y)
    for i in range(p+1,t):
        if x % i == 0 and y % i == 0 :
            return i
A,B = map(int,input().split())
ans = 1
p = 1
while True :
    c = check(A,B)
    if c == 1 :
        break
    p = check2(A,B,p)
    while True :
        if A % p == 0 and B % p == 0 :
            A = (A//p)
            B = (B//p)
        else :
            break
    ans += 1
print(ans)
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.readline
N,Q =  map(int,input().split())
graph = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,readline().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

val = [0 for i in range(N)]
for i in range(Q):
    a,b = map(int,readline().split())
    val[a-1] += b 

def dps(i,parent): 
    for j in graph[i]:
        if j == parent:
            continue
        val[j] += val[i]
        dps(j,i)
                
dps(0,-1)
print(*val)

Buggy submission (verdict: Runtime Error):
N,Q =  map(int,input().split())
graph = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
 
val = [0 for i in range(N)]
for i in range(Q):
    a,b = map(int,input().split())
    val[a-1] += b 
visited = [True for i in range(N)]
def dps(i):
    visited[i] = False
    if i == N :
        return 1
    else :
        for j in graph[i]:
            if visited[j]:
                val[j] += val[i]
                dps(j)
dps(0)
for i in val:
  print(i,end = " ")

Buggy submission (verdict: Runtime Error):
N,Q =  map(int,input().split())
graph = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

val = [0 for i in range(N)]
for i in range(Q):
    a,b = map(int,input().split())
    val[a-1] += b 
visited = [True for i in range(N)]
def dps(i):
    visited[i] = False
    if i == N :
        return 1
    else :
        for j in graph[i]:
            if visited[j]:
                val[j] += val[i]
                dps(j)
dps(0)
for i in val:
  print(val,end = " ")

Buggy submission (verdict: Runtime Error):
N,Q =  map(int,input().split())
graph = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

val = [0 for i in range(N)]
for i in range(Q):
    a,b = map(int,input().split())
    val[a-1] += b 
visited = [True for i in range(N)]
def dps(i):
    visited[i] = False
    if i == N :
        return 1
    else :
        for j in graph[i]:
            if visited[j]:
                val[j] += val[i]
                dps(j)
dps(0)
print(val,end="")
Problem p03071 (python)

Fixed submission:
a,b = [int(i) for i in input().split()]

x = 0
for i in range(2) :
    c = max(a,b)
    if c == a :
        x += a 
        a = a - 1
    else : 
        x += b
        b = b -1

print(x)

Buggy submission (verdict: Runtime Error):
input_val = []
for i in range(6) :
    input_val.append(int(input()))

input_size = len(input_val)
count = 0
for i in range(5) :
    stan_val = input_val[i]
    for j in range(i+1,5) :
        diff = abs(stan_val - input_val[j])
        if diff > input_val[5] :
            count += 1
            
        else : count = count

if count == 0 :
   print("Yay!")
else : print(":(")
Problem p03087 (python)

Fixed submission:
N, Q = map(int,input().split())
S = list(input())

dp = [float("inf") for i in range(N)]
dp[0] = 0
for i in range(1,N):
    if S[i-1] == "A" and S[i] == "C" :
        dp[i] = dp[i-1] + 1
    else :
        dp[i] = dp[i-1]
val = [[] for i in range(Q)]
for i in range(Q) :
    a,b = map(int,input().split())
    val[i] = [a-1,b-1]
for i in range(Q):
    print("{}".format(dp[val[i][1]]-dp[val[i][0]]))

Buggy submission (verdict: Runtime Error):
N, Q = map(int,input().split())
S = list(input())
'''
dp[i]: 1 ~ i 番目までにacが何個あるのか　
 dp[i+1] = dp[i] (S[i]=="A" and S[i+1] == "C")
         = dp[i] (else)
'''
dp = [0 for i in range(N+10)]
for i in range(1,N+1):
    if S[i-1] == "A" and S[i] == "C" :
        dp[i] = dp[i-1] + 1
    else :
        dp[i] = dp[i-1]

for i in range(Q) :
    a,b = map(int,input().split())
    print("{}".format(dp[b-1]-dp[a-1]))
Problem p03147 (python)

Fixed submission:
N = int(input())
height = [int(i) for i in input().split()] + [0]
k = 0
while True :
    if sum(height) == 0 :
        break 
    for i in range(N):
        if height[i] > 0 :
            lv = i 
            break 

    for i in range(lv,N+1):
        if height[i] == 0 :
            uv = i 
            break 
    for i in range(lv,uv):
        height[i] -= 1
    k += 1
print(k)

Buggy submission (verdict: Runtime Error):
N = int(input())
height = [int(i) for i in input().split()] + [0]
k = 0
while True :
    for i in range(N):
        if height[i] > 0 :
            lv = i 
            break 

    for i in range(lv,N+1):
        if height[i] == 0 :
            uv = i 
            break 
    for i in range(lv,uv):
        height[i] -= 1
    k += 1
    if sum(height) == 0 :
        break 
print(k)