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

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
if N==1:
    if A[0]==0:
        print(1)
    else:
        print(0)
else:
    C = {}
    for i in range(N):
        a = A[i]
        if a not in C:
            C[a]=0
        C[a] += 1
    flag = 0
    if N%2==0:
        for i in range(1,N,2):
            if i in C and C[i]==2:continue
            flag=1
            break
    else:
        for i in range(2,N,2):
            if i in C and C[i]==2:continue
            flag = 1
            break
        if 0 not in C or C[0]!=1:
            flag = 1
    if flag==1:
        print(0)
    else:
        p = 10**9+7
        k = N//2
        ans = 1
        cnt = 1
        while cnt<=k:
            ans = (ans*2)%p
            cnt += 1
        print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
if N==1:
    if A[0]==0:
        print(1)
    else:
        print(0)
else:
    C = {}
    for i in range(N):
        a = A[i]
        if a not in C:
            C[a]=0
        C[a] += 1
    flag = 0
    if N%2==0:
        for i in range(1,N,2):
            if C[i]==2:continue
            flag=1
            break
    else:
        for i in range(2,N,2):
            if C[i]==2:continue
            flag = 1
            break
        if C[0]!=1:
            flag = 1
    if flag==1:
        print(0)
    else:
        p = 10**9+7
        k = N//2
        ans = 1
        cnt = 1
        while cnt<=k:
            ans = (ans*2)%p
            cnt += 1
        print(ans)
Problem p03959 (python)

Fixed submission:
p = 10**9+7
N = int(input())
T = list(map(int,input().split()))
A = list(map(int,input().split()))
H = [0 for _ in range(N)]
cnt = 1
H[0] = T[0]
for i in range(1,N):
    if T[i]>T[i-1]:
        H[i] = T[i]
if H[-1]>0 and H[-1]!=A[-1]:
    cnt = 0
else:
    H[-1] = A[-1]
    for i in range(-2,-N-1,-1):
        if H[i]==0 and A[i]>A[i+1]:
            if A[i]<=T[i]:
                H[i] = A[i]
            else:
                cnt = 0
                break
        elif H[i]>0 and A[i]>A[i+1]:
            if H[i]==A[i]:continue
            else:
                cnt = 0
                break
    if cnt==1:
        for i in range(1,N-1):
            if H[i]==0:
                cnt = (cnt*min(T[i],A[i]))%p
print(cnt)

Buggy submission (verdict: Runtime Error):
p = 10**9+7
N = int(input())
T = list(map(int,input().split()))
A = list(map(int,input().split()))
H = [0 for _ in range(N)]
flag = 0
if T[N-1]!=A[0]:
    flag = 1
if flag==0:
    indmaxT=0
    H[0] = T[0]
    for i in range(1,N):
        if T[i]>T[i-1]:
            H[i] = T[i]
            if H[i]==hmax:
                indmaxT = i
                break
    indmaxA = N-1
    H[N-1] = A[N-1]
    for i in range(N-2,-1,-1):
        if A[i]>A[i+1]:
            H[i]=A[i]
            if H[i]==hmax:
                indmaxA = i
                break
    if indmaxA<indmaxT:
        flag = 1
if flag==1:
    print(0)
else:
    hmax = max(H)
    cnt = 1
    cur = 0
    indH=0
    for i in range(1,indmaxT):
        if H[i]==0:
            cnt = (cnt*H[cur])%p
        elif H[i]>0:
            cur = i
    cur = N-1
    for i in range(N-2,indmaxA,-1):
        if H[i]==0:
            cnt = (cnt*H[cur])%p
        elif H[i]>0:
            cur = i
    for i in range(indmaxT+1,indmaxA):
        cnt = (cnt*hmax)%p
    print(cnt)

Buggy submission (verdict: Runtime Error):
p = 10**9+7
N = int(input())
T = list(map(int,input().split()))
A = list(map(int,input().split()))
H = [0 for _ in range(N)]
flag = 0
if T[N-1]!=A[0]:
    flag = 1
if flag==0:
    H[0] = T[0]
    for i in range(1,N):
        if T[i]<T[i-1]:
            flag = 1
            break
        if T[i]>T[i-1]:
            H[i] = T[i]
if flag==0:
    H[N-1] = A[N-1]
    for i in range(N-2,-1,-1):
        if A[i]<A[i+1]:
            flag = 1
            break
        if A[i]>A[i+1]:
            if H[i]>0 and H[i]!=A[i]:
                flag = 1
                break
            else:
                H[i]=A[i]
if flag==1:
    print(0)
else:
    hmax = max(H)
    cnt = 1
    cur = 0
    for i in range(1,N):
        if H[i]==hmax:
            indH=i
            break
        if H[i]==0:
            cnt = (cnt*H[cur])%p
        elif H[i]>0:
            cur = i
    cur = N-1
    for i in range(N-2,-1,-1):
        if H[i]==hmax:
            indA = i
            break
        if H[i]==0:
            cnt = (cnt*H[cur])%p
        elif H[i]>0:
            cur = i
    for i in range(indH+1,indA):
        cnt = (cnt*hmax)%p
    print(cnt)
Problem p03966 (python)

Fixed submission:
import math
N = int(input())
T,A = 1,1
for _ in range(N):
    t,a = map(int,input().split())
    k1 = T//t
    if T%t>0:
        k1 += 1
    k2 = A//a
    if A%a>0:
        k2 += 1
    k = max(k1,k2)
    T = k*t
    A = k*a
print(T+A)

Buggy submission (verdict: Runtime Error):
import math
def f(x1,y1,x2,y2,z):
    a = gcd(x1,x2)
    z = max(z,math.ceil((x2+y2)*x1/x2))
    x = x2+y2
    n = z//x
    k = z%x
    if k==0:
        z = n*x
        x1 = (z*x2)//x
        y1 = (z*y2)//x
        return z,x1,y1
    else:
        z = (n+1)*x
        x1 = (z*x2)//x
        y1 = (z*y2)//x
        return z,x1,y1
N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]
x1,y1 = A[0]
s = x1+y1
for i in range(1,N):
    t,a = A[i]
    s,x1,y1 = f(x1,y1,t,a,s)
print(s)
Problem p04020 (python)

Fixed submission:
N = int(input())
A = []
a = []
for i in range(N):
    x = int(input())
    if x==0:
        b = a[:]
        A.append(b)
        a = []
    else:
        a.append(x)
A.append(a)
cnt = 0
for a in A:
    c = sum(a)
    cnt += c//2
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
cnt = 0
for i in range(N):
    cnt += A[i]//2
    A[i] = A[i]%2
for i in range(1,N-1):
    if A[i-1]+A[i]==2:
        cnt += 1
        A[i]=0
print(cnt)
Problem p04029 (python)

Fixed submission:
N = int(input())
print((N*(N+1))//2)

Buggy submission (verdict: Runtime Error):
N = int(input())
print(N*(N+1))//2)
Problem p04032 (python)

Fixed submission:
s = input().strip()
a = -1
b = -1
if s[0]==s[1]:
    a = 1
    b = 2
elif len(s)>2 and s[1]==s[2]:
    a = 2
    b = 3
elif len(s)>2 and s[0]==s[2]:
    a = 1
    b = 3
else:
    for i in range(3,len(s)):
        if s[i]==s[i-1]:
            a = i
            b = i+1
            break
        elif s[i]==s[i-2]:
            a = i-1
            b = i+1
            break
print(a,b)

Buggy submission (verdict: Runtime Error):
s = input().strip()
a = -1
b = -1
if s[0]==s[1]:
    a = 1
    b = 2
elif s[1]==s[2]:
    a = 2
    b = 3
elif s[0]==s[2]:
    a = 1
    b = 3
else:
    for i in range(3,len(s)):
        if s[i]==s[i-1]:
            a = i
            b = i+1
            break
        elif s[i]==s[i-2]:
            a = i-1
            b = i+1
            break
print(a,b)
Problem p04045 (python)

Fixed submission:
import itertools
N,K = map(int,input().split())
D = list(map(int,input().split()))
A = []
for i in range(10):
    if i not in D:
        A.append(i)
cmin = 100000
k = len(str(N))
for i in range(k,6):
    for x in itertools.product(A,repeat=i):
        cnt = 0
        for j in range(i):
            cnt += x[j]*10**(i-1-j)
        if cnt>=N:
            cmin = min(cmin,cnt)
print(cmin)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
D = list(map(int,input().split()))
E = []
for i in range(10):
    if i not in D:
        E.append(i)
E = sorted(E)
N = str(N)
ind = len(N)
for i in range(len(N)):
    if int(N[i]) not in E:
        ind = i
        break
if ind==len(N):
    print(N)
else:
    flag = 0
    x = ""
    for i in range(ind-1,-1,-1):
        n = int(N[i])
        if n==E[-1]:continue
        else:
            for e in E:
                if e>n:
                    x = N[:i]+str(e)+str(E[0])*(len(N)-i-1)
                    flag = 1
                    break
            if flag==1:break
    if flag==0:
        for e in E:
            if e>int(N[0]):
                a = e
                flag = 1
                break
        x = str(a)+str(E[0])*(len(N)-1)
        if flag==0:
            if E[0]>0:
                a = E[0]
            else:
                a = E[1]
            x = str(a)+str(E[0])*len(N)
    print(x)
Problem p02574 (python)

Fixed submission:
from math import gcd

n = int(input())
a = list(map(int, input().split()))

d = a[0]
m = a[0]

g = True

for i in range(1, n):
    d = gcd(d, a[i])

if d != 1:
    print("not coprime")
else:
    while len(a) > 1:
        b = []
        for i in range(0, len(a), 2):
            #print(i, a)
            if i == len(a)-1:
                b.append(a[i])
            else:
                e = gcd(a[i], a[i+1])
                if e != 1:
                    g = False
                    break
                else:
                    b.append(a[i] * a[i+1])
        a = b.copy()
        #print(a)


    if not g:
        print("setwise coprime")
    else:
        print("pairwise coprime")

Buggy submission (verdict: Runtime Error):
from math import gcd

n = int(input())
a = list(map(int, input().split()))

d = a[0]
m = a[0]

g = True

for i in range(1, n):
    d = gcd(d, a[i])

if d != 1:
    print("not coprime")
else:
    while len(a) > 1:
        b = []
        for i in range(0, len(a), 2):
            #print(i, a)
            if i == n-1:
                b.append(a[i])
            else:
                e = gcd(a[i], a[i+1])
                if e != 1:
                    g = False
                    break
                else:
                    b.append(a[i] * a[i+1])
        a = b.copy()
        #print(a)


    if not g:
        print("setwise coprime")
    else:
        print("pairwise coprime")
Problem p02642 (python)

Fixed submission:
import sys
from collections import deque

input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))

a.sort()
tf = [True] * a[-1]
dup = [False] * a[-1]


for i in range(n):
    if tf[a[i]-1] == True:
        #print(a[i])
        if dup[a[i]-1] == True:
            tf[a[i]-1] = False
        else:
            dup[a[i]-1] = True
            for j in range(a[i]*2, a[-1]+1, a[i]):
                tf[j-1] = False
                

c = 0

#print(tf)

for x in a:
    if tf[x-1]:
        c += 1

print(c)

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque

input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))

a.sort()
tf = [True] * n

for j in range(n):
    if not tf[j]:
        pass
    else:
        for k in range(j+1, n):
            if tf[k] and a[k] % a[j] == 0:
                tf[k] = False
    #print(tf)

if a[0] % a[1] == 0:
    tf[0] = False

print(tf.count(True))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))

a.sort()

s = 0

for i in range(n):
    j = 0
    while j < i:
        if a[i] % a[j] == 0:
            #print(0, a[i], a[j])
            break
        elif a[j] ** 2 > a[i]:
            s += 1
            #print(1, a[i], a[j])
            break
        j += 1

if a[0] != a[1]:
    s += 1

print(s)
Problem p02683 (python)

Fixed submission:
import numpy as np
from numpy import array


n, m, x = list(map(int, input().split()))
a = []
for i in range(n):
    a.append(list(map(int, input().split())))

a = array(a)

c_min = 0
flag = False

for i in range(1, 2 ** n ):
    b = np.zeros(m+1)

    for k in range(n):
        if ((i >> k) & 1):
            b += a[k]
    
    if np.all(b[1:] >= x):
        if flag == False:
            c_min = b[0]
            flag = True
        else:
            c_min = min(c_min, b[0])
        

c_min = int(c_min)

if flag == False:
    c_min = -1

print(c_min)

Buggy submission (verdict: Runtime Error):
import numpy as np
from numpy import array


n, m, x = list(map(int, input().split()))
a = []
for i in range(n):
    a.append(list(map(int, input().split())))

a = array(a)

c_min = 0
flag = False

for i in range(1, 2 ** n ):
    b = np.zeros(m+1)

    for k in range(n):
        if ((i >> k) & 1):
            b += a[k]
    
    if np.all(b[1:] >= x):
        if flag == False:
            c_min = b[0]
            flag = True
        else:
            c_min = min(c_min, b[0])
        

c_min = int(c_min)

if flag == False:
    c_min = -1

print(c_min)

Buggy submission (verdict: Runtime Error):
import numpy as np
from numpy import array


n, m, x = list(map(int, input().split()))
a = []
for i in range(n):
    a.append(list(map(int, input().split())))

a = array(a)

c_min = 1e5 * n
flag = False

for i in range(1, n ** 2 + 1):
    j = str(bin(i))

    b = np.zeros(m+1)

    for k in range(n):
        if j[k] == 1:
            b += a[k]
    
    if np.all(b[1:] >= m):
        c_min = min(c_min, b[0])
        flag = True

if flag == False:
    c_min = -1

print(c_min)
Problem p02684 (python)

Fixed submission:
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

s = 1
g = 0
i = 1
history = [s]
flag = [False] * n
flag[0] = True

while True:
    g = a[s-1]
    if flag[g-1] == True:
        break
    else:
        flag[g-1] = True
        history.append(g)
        s = g
        i += 1


x = history.index(g)

if k < i:
    ans = history[k]
else:
    d = (k-x) % (i - x)

    ans = history[x + d]

print(ans)

Buggy submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

s = 1
g = 0
i = 1
history = [s]
flag = [False] * n
flag[0] = True

while True:
    g = a[s-1]
    if flag[g-1] == True:
        break
    else:
        flag[g-1] = True
        history.append(g)
        s = g
        i += 1


x = history.index(g)

if k < n:
    ans = history[k]
else:
    d = (k-x) % (i - x)

    ans = history[x + d]

print(ans)

Buggy submission (verdict: Runtime Error):
import collections

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

h = []
i = 0
s = 1

ans = 0
while i < 2*n: 
  g = a[s-1]
  h.append(g)
  if i == k - 1:
    ans = g
    sys.exit()
  else:
    s = g
    i+=1
j = collections.Counter(h)
m = j.most_common()[0][0]
l = [i for i, x in enumerate(h) if x == m]

d = (k - l[0]) % (l[1]-l[0])
ans = h[l[0]+d-1]

print(ans)
Problem p02702 (python)

Fixed submission:
from collections import defaultdict

s = input()

rests = [0]
n = 0
a = 0
m = 1
c = defaultdict(int)
c[0] += 1
for i in list(s)[::-1]:
    n = n + int(i)*m

    c[n % 2019] += 1
    m = m * 10 % 2019

for v in c.values():
    a += v * (v-1) // 2
print(a)

Buggy submission (verdict: Runtime Error):
inp = input()

s = 0

for i in range(len(inp)-3):
	num = int(inp[i:-1])
    while num >2019:
		if num % 2019 == 0:
			s += 1
		num = num / 10

print(s)
Problem p02706 (python)

Fixed submission:
n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
 
print(max(n - sum(a), -1))

Buggy submission (verdict: Runtime Error):
n,m = list(map(int, input().split()))
a =  list(map(int, input().split()))

print(max(n - sum(a), -1)
Problem p02768 (python)

Fixed submission:
import math

n, a, b = list(map(int, input().split()))

MOD = int(1e9) + 7

s = pow(2, n, MOD)-1

def cbn(n, a, MOD):
    x = 1
    for i in range(a):
        x = (x * (n-i)) % MOD

    y = math.factorial(a) % MOD
    return x * pow(y, MOD-2, MOD) %MOD

s = (s- cbn(n, a, MOD)) %MOD
s = (s- cbn(n, b, MOD)) %MOD


print(s)

Buggy submission (verdict: Runtime Error):
import math

n, a, b = list(map(int, input().split()))

MOD = 10**9 + 7

def make_fact_list(n, MOD):
    # make factorial list from 0 to n
    fact = [0] * (n+1)
    inv = [0] * (n+1)
    factinv = [0] * (n+1)

    fact[0]=fact[1]=1
    inv[1]=1
    factinv[0]=factinv[1]=1

    for i in range(2,n+1):
        fact[i] = fact[i-1] * i % MOD
        inv[i] = MOD - (( inv[MOD % i] *  (MOD // i)) % MOD )
        factinv[i] = factinv[i-1] * inv[i] % MOD
    
    return fact, factinv

def cbn(n_f, k, MOD, fact = [], factinv = []):
    if len(fact) == 0 and len(factinv) == 0:
        fact, factinv = make_fact_list(n, MOD)
    return fact[n] * factinv[n-k] * factinv[k] % MOD

def power_with_mod(x, n, MOD):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return power_with_mod(x*x % MOD , n // 2, MOD) % MOD
    else:
        return x * power_with_mod(x * x % MOD, n // 2, MOD) % MOD

s = power_with_mod(2, n, MOD)-1

fact, factinv = make_fact_list(n, MOD)

s -= cbn(n, a, MOD, fact, factinv)
s -= cbn(n, b, MOD, fact, factinv)


print(s)

Buggy submission (verdict: Runtime Error):
import math

n, a, b = list(map(int, input().split()))

MOD = 10**9 + 7

def make_fact_list(n, MOD):
    # make factorial list from 0 to n
    fact = [0] * (n+1)
    inv = [0] * (n+1)
    factinv = [0] * (n+1)

    fact[0]=fact[1]=1
    inv[1]=1
    factinv[0]=factinv[1]=1

    for i in range(2,n+1):
        fact[i] = fact[i-1] * i % MOD
        inv[i] = MOD - (( inv[MOD % i] *  (MOD // i)) % MOD )
        factinv[i] = factinv[i-1] * inv[i] % MOD
    
    return fact, factinv

def cbn(n_f, k, MOD, fact = [], factinv = []):
    if len(fact) == 0 and len(factinv) == 0:
        fact, factinv = make_fact_list(n, MOD)
    return fact[n] * factinv[n-k] * factinv[k] % MOD

def power_with_mod(x, n, MOD):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return power_with_mod(x*x % MOD , n // 2, MOD) % MOD
    else:
        return x * power_with_mod(x * x % MOD, n // 2, MOD) % MOD

s = power_with_mod(2, n, MOD)-1

fact, factinv = make_fact_list(b, MOD)

s -= cbn(n, a, MOD, fact, factinv)
s -= cbn(n, b, MOD, fact, factinv)


print(s)
Problem p02780 (python)

Fixed submission:
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))

e = [(1+p[i]) / 2 for i in range(n)]
#print(e)

s = sum(e[:k])
ans = [s]
for i in range(n-k):
    s = s-e[i] + e[i+k]
    ans.append(s)

#print(ans)
print(max(ans))

Buggy submission (verdict: Runtime Error):
import math
import itertools

n = int(input())
k = int(input())

if (n < 99 and k == 3) or (n < 9 and k == 2):
    print(0) 

else:
    f = len(str(n))

    #f-1桁以内に収まる数

    en = 1
    for i in range(k):
        en *= f-1-i

    de = math.factorial(k)


    s = en // de * pow(9, k)

    #print(s)
    #f桁目によって絞る

    kami = int(str(n)[0])

    en_2 = 1
    for i in range(k-1):
        en_2 *= f-1-i

    de_2 = math.factorial(k-1)


    s += (en_2 // de_2 * pow(9, k-1)) * (kami-1)


    #以下上1桁は同じ数字

    keta = list(range(f-1))
    num = list(range(1,10))

    b =  kami * pow(10, f-1)
    m = 0

    if k == 1:
        s += 1
    elif k == 2:
        s += 9*(f-2) + int(str(n)[1])
    else:
        kami2 = int(str(n)[1])

        en_3 = (f-2)*(f-3)

        de_3 = 2


        s += (en_3 // de_3 * pow(9, k-1))  + kami2 * 9 * (f-2)

    print(s)
Problem p02838 (python)

Fixed submission:
import sys
input = sys.stdin.readline
MOD = pow(10, 9) + 7


n = int(input())
a = list(map(int, input().split()))

m = max(a)

num = [0] * 61

for x in a:
    for j in range(61):
        if (x >> j) & 1:
            num[j] += 1

s = 0

#print(num)

for i in range(61):
    s += (n - num[i]) * num[i] * pow(2, i, MOD) % MOD

print(s % MOD)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
MOD = pow(10, 9) + 7

def make_fact_list(n, MOD):
    # make factorial list from 0 to n
    fact = [0] * (n+1)
    inv = [0] * (n+1)
    factinv = [0] * (n+1)

    fact[0]=fact[1]=1
    inv[1]=1
    factinv[0]=factinv[1]=1

    for i in range(2,n+1):
        fact[i] = fact[i-1] * i % MOD
        inv[i] = MOD - (( inv[MOD % i] *  (MOD // i)) % MOD )
        factinv[i] = factinv[i-1] * inv[i] % MOD
    
    return fact, factinv

def cbn(n, k, MOD, fact = [], factinv = []):
    if len(fact) == 0 and len(factinv) == 0:
        fact, factinv = make_fact_list(n, MOD)
    return fact[n] * factinv[n-k] * factinv[k] % MOD



n = int(input())
a = list(map(int, input().split()))

m = max(a)

k = len(format(m, 'b'))

num = [0] * k

for x in a:
    for j in range(k):
        if (x >> j) & 1:
            num[j] += 1

fact, factinv = make_fact_list(max(num), MOD)

s = 0

#print(num)

for i in range(k):
    s += (n - num[i]) * num[i] * pow(2, i, MOD) % MOD

print(s % MOD)
Problem p03074 (python)

Fixed submission:
n, k = list(map(int, input().split()))
s = list(input())

start = []
end = []
flag = True

m = 0

for i in range(n):
    if flag and s[i] == "1":
        flag = False
        start.append(i)
    elif not flag and s[i] == "0":
        flag = True
        end.append(i-1)

if len(start) <= 0 or start[0] != 0:
    start = [0] + start
    end = [0] + end

end.append(n-1)

#print(start, end)

if len(end) <= k:
    print(n)
else:
    m = 0
    for i in range(len(end)-k):
        m = max(m, end[i+k] - start[i] + 1)
    print(m)

Buggy submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))
s = list(input())

start = []
end = []
flag = True

m = 0

for i in range(n):
    if flag and s[i] == "1":
        flag = False
        start.append(i)
    elif not flag and s[i] == "0":
        flag = True
        end.append(i-1)

if start[0] != 0:
    start = [0] + start
    end = [0] + end

end.append(n-1)

#print(start, end)

if len(end) <= k:
    print(n)
else:
    m = 0
    for i in range(len(end)-k):
        m = max(m, end[i+k] - start[i] + 1)
    print(m)
Problem p03145 (python)

Fixed submission:
a, b, c = list(map(int, input().split()))

print(a * b // 2)

Buggy submission (verdict: Runtime Error):
import numpy as np

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

s = 0

for i in range(max(h)+1):
    flag = False
    for j in range(n):
        if flag and h[j] == 0:
            s += 1
            flag = False
        elif not flag and h[j] > 0:
            flag = True

        h[j] = max(h[j]-1, 0)
    if flag:
        s += 1

print(s)
Problem p03147 (python)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))

s = 0

for i in range(max(h)+1):
    flag = False
    for j in range(n):
        if flag and h[j] == 0:
            s += 1
            flag = False
        elif not flag and h[j] > 0:
            flag = True

        h[j] = max(h[j]-1, 0)
    if flag:
        s += 1

print(s)

Buggy submission (verdict: Runtime Error):
import numpy as np

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

s = 0

for i in range(max(h)+1):
    flag = False
    for j in range(n):
        if flag and h[j] == 0:
            s += 1
            flag = False
        elif not flag and h[j] > 0:
            flag = True

        h[j] = max(h[j]-1, 0)
    if flag:
        s += 1

print(s)
Problem p03309 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

b = [a[i] - (i+1) for i in range(n)]

b.sort()

m1 = b[n//2]
s1 = sum([abs(b[i] - m1) for i in range(n)])

if n % 2 == 1:
    m1 = b[n//2]
    s1 = sum([abs(b[i] - m1) for i in range(n)])
    print(s1)
else:
    m1 = b[n//2-1]
    m2 = b[n//2]
    if (m1 + m2) % 2 == 0:
        l1 = (m1 + m2) // 2
        s1 = sum([abs(b[i] - l1) for i in range(n)])
        print(s1)
    else:
        l1 = (m1 + m2) // 2
        l2 = l1 + 1
        s1 = sum([abs(b[i] - l1) for i in range(n)])
        s2 = sum([abs(b[i] - l2) for i in range(n)]) 

        print(min(s1, s2))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

b = [a[i] - (i+1) for i in range(n)]

b.sort()

m1 = b[n//2]
s1 = sum([abs(b[i] - m1) for i in range(n)])

m2 = b[n//2 + 1]
s2 = sum([abs(b[i] - (m2)) for i in range(n)]) 

print(min(s1, s2))