Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a = input()

c = 0
for i in range(1,n//2 +1):
  for j in range(n):
    if j + 2*i < n:
      if a[j] != a[j+i] and a[j+i] != a[j+2*i] and a[j] != a[j+2*i]:
        c+=1

ans = a.count("R") * a.count("G") * a.count("B") - c
print(ans)

Fixed submission:
n=int(input())
a = input()

c = 0
for i in range(1,n//2 +1):
  for j in range(n-2*i):
    if a[j] != a[j+i] and a[j+i] != a[j+2*i] and a[j] != a[j+2*i]:
      c+=1

ans = a.count("R") * a.count("G") * a.count("B") - c
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a = input()

c = 0
for i in range(n):
  for j in range(n):
    if j + 2*i < n:
      if a[j] != a[j+i] and a[j+i] != a[j+2*i] and a[j] != a[j+2*i]:
        c+=1

ans = a.count("R") * a.count("G") * a.count("B") - c
print(ans)

Fixed submission:
n=int(input())
a = input()

c = 0
for i in range(1,n//2 +1):
  for j in range(n-2*i):
    if a[j] != a[j+i] and a[j+i] != a[j+2*i] and a[j] != a[j+2*i]:
      c+=1

ans = a.count("R") * a.count("G") * a.count("B") - c
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a = input()

c = 0
for i in range(n):
  for j in range(i+1, n):
    if a[i] != a[j]:
      for k in range(j+1,n):
        if (a[i] != a[k]) and (a[j]!=a[k]) and j-i != k-j:
          c += 1

print(c)

Fixed submission:
n=int(input())
a = input()

c = 0
for i in range(1,n//2 +1):
  for j in range(n-2*i):
    if a[j] != a[j+i] and a[j+i] != a[j+2*i] and a[j] != a[j+2*i]:
      c+=1

ans = a.count("R") * a.count("G") * a.count("B") - c
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x, y, a, b, c = list(map(int, input().split()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

p = P[:x]
q = Q[:y]
r = []

i = 0

def check(z , l):
    return z > l[-1]

while len(p) ** 2 + len(q) ** 2 > 0 and i < len(R):
    if len(p) * len(q) != 0:
        if R[i] > p[-1] or R[i] > q[-1]:
            r.append(R[i])
            if p[-1] > q[-1]:
                q = q[:-1]
            else:
                p = p[:-1]
    elif len(p) != 0:
        if R[i] > p[-1]:
            r.append(R[i])
            p = p[:-1]

    elif len(q) != 0:
        if R[i] > q[-1]:
            r.append(R[i])
            q = q[:-1]
    
    i +=1

print(sum(p)+sum(q)+sum(r))

Fixed submission:
x, y, a, b, c = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)


i, j, k = x, y, 0

def check(z , l):
    return z > l[-1]

while i**2 + j**2 > 0 and k < len(r):
    if i*j != 0:
        if r[k] > p[i-1] or r[k] > q[j-1]:
            if p[i-1] > q[j-1]:
                j -= 1
            else:
                i -= 1
        else:
            break
    elif i > 0:
        if r[k] > p[i-1]:
            i -= 1
        else:
            break

    elif j > 0:
        if r[k] > q[j-1]:
            j -= 1
        else:
            break


    k += 1

print(sum(p[:i])+sum(q[:j])+sum(r[:k]))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

query = [input().split() for i in range(q)]

a = s

flag = True

for i in range(len(query)):
    if query[i][0] == "1":
        flag = not(flag)
    else:
        if (query[i][1] == "1" and flag) or (query[i][1] != "1" and not(flag)):
            a = query[i][2] + a
        else:
            a = a + query[i][2]

if not(flag):
    a = a[::-1]

print(a)

Fixed submission:
from collections import deque

s = input()
q = int(input())

query = [input().split() for i in range(q)]

a = deque([s])

flag = True

for i in range(q):
    if query[i][0] == "1":
        flag = not(flag)
    else:
        if (query[i][1] == "1" and flag) or (query[i][1] != "1" and not(flag)):
            a.appendleft(query[i][2])
        else:
            a.append(query[i][2])

b = "".join(a)
if not(flag):
    b = b[::-1]

print(b)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

query = [input().split() for i in range(q)]

a = s
for i in range(len(query)):
    if query[i][0] == "1":
        a = a[::-1]
    else:
        if query[i][1] == "1":
            a = query[i][2] + a
        else:
            a = a + query[i][2]

print(a)

Fixed submission:
from collections import deque

s = input()
q = int(input())

query = [input().split() for i in range(q)]

a = deque([s])

flag = True

for i in range(q):
    if query[i][0] == "1":
        flag = not(flag)
    else:
        if (query[i][1] == "1" and flag) or (query[i][1] != "1" and not(flag)):
            a.appendleft(query[i][2])
        else:
            a.append(query[i][2])

b = "".join(a)
if not(flag):
    b = b[::-1]

print(b)
Buggy python submission (verdict: Runtime Error):
from collections import Counter

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

s = int(input())

a = 0
t = []

while s > 0:
    d = s // 10
    r = s % 10
    t.append(r)
    s = d

if p == 2:
    for i in range(len(t)):
        if t[i] % 2 == 0:
            a += len(t) - i 
elif p == 5:
        if t[i] % 5 == 0:
            a += len(t) - i 

else:
    u = []
    k = 1
    for i in range(len(t)):
        if i == 0:
            u.append(t[i]*k % p)
        else:
            u.append((u[i-1] + t[i]*k) % p)
        k *= 10
    c = Counter(u)

    a += c[0]
    for i in c.values():
        if i > 1:
            a += i * (i-1) // 2


print(a)




Fixed submission:
from collections import Counter

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

s = input()


a = 0
t = list(map(int, list(s)))
t.reverse()


if p == 2:
    for i in range(n):
        if t[i] % 2 == 0:
            a += len(t) - i 
elif p == 5:
    for i in range(n):
        if t[i] % 5 == 0:
            a += len(t) - i 

else:
    u = []
    k = 1
    l = 0
    for i in t:
        l = (l + i*k) % p
        u.append(l)
        k = k * 10 % p

    c = Counter(u)
    a += c[0]
    for i in c.values():
        if i > 1:
            a += i * (i-1) // 2


print(a)

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

s = int(input())

a = 0
t = []

while s > 0:
    d = s // 10
    r = s % 10
    t.append(r)
    s = d

if p == 2:
    for i in range(len(t)):
        if t[i] % 2 == 0:
            a += len(t) - i 
elif p == 5:
        if t[i] % 5 == 0:
            a += len(t) - i 

else:
    u = []
    k = 1
    for i in range(len(t)):
        u.append(t[i]*k % p)
        k *= 10

    for i in range(len(u)):
        for j in range(i, len(u)):
            if sum(u[i:j+1]) % p == 0:
                a += 1

print(a)




Fixed submission:
from collections import Counter

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

s = input()


a = 0
t = list(map(int, list(s)))
t.reverse()


if p == 2:
    for i in range(n):
        if t[i] % 2 == 0:
            a += len(t) - i 
elif p == 5:
    for i in range(n):
        if t[i] % 5 == 0:
            a += len(t) - i 

else:
    u = []
    k = 1
    l = 0
    for i in t:
        l = (l + i*k) % p
        u.append(l)
        k = k * 10 % p

    c = Counter(u)
    a += c[0]
    for i in c.values():
        if i > 1:
            a += i * (i-1) // 2


print(a)
Buggy python 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)

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 python 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)

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 python 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)

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 python 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)

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 python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

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


MOD = pow(10, 9) + 7
x, y = list(map(int, input().split()))

if (2*x-y) % 3 != 0 or (2*y-x) % 3 != 0:
    print(0)
else:
    s = (2*x-y) // 3
    t = (2*y-x) // 3

    fact, factinv = make_fact_list(s + t, MOD)
    print(cbn(s+t, s, MOD, fact, factinv))

Fixed submission:
import sys
input = sys.stdin.readline

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


MOD = pow(10, 9) + 7
x, y = list(map(int, input().split()))

if (2*x-y) % 3 != 0 or (2*y-x) % 3 != 0:
    print(0)
elif (2*x-y) // 3 < 0 or (2*y-x) // 3 < 0:
    print(0)
else:
    s = (2*x-y) // 3
    t = (2*y-x) // 3

    fact, factinv = make_fact_list(s + t + 1, MOD)
    print(cbn(s+t, s, MOD, fact, factinv) % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))

s = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if l[i] < l[j] + l[k] and l[j] < l[k] + l[i] and l[k] < l[i] + l[j]:
                s += 1

print(s)


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

s = 0

l.sort()

for i in range(n-2):
    j = n-2
    k = n-1
    while i < j:
        if l[k] >= l[i] + l[j] and j < k:
            #print(0, i, j, k)
            k -= 1
        else:
            #print(1, i, j, k)
            s += k - j
            j -= 1


print(s)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
from fractions import Fraction

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

a = list(map(lambda x: Fraction(1, int(x)), input().split()))

heapq.heapify(a)

for i in range(m):
    x = heapq.heappop(a)
    heapq.heappush(a, Fraction(x.numerator * 2, x.denominator))

s = 0


for j in range(n):
    s += int(Fraction(a[j].denominator, a[j].numerator))

print(s)


Fixed submission:
import heapq
from fractions import Fraction

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

a = list(map(lambda x: Fraction(1, int(x)), input().split()))

heapq.heapify(a)

for i in range(m):
    x = heapq.heappop(a)
    y = Fraction(x.numerator * 2, x.denominator)
    if y.numerator < y.denominator:
        heapq.heappush(a, y)
    elif len(a) == 0:
        break

s = 0


for j in range(len(a)):
    s += int(Fraction(a[j].denominator, a[j].numerator))

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

MOD = pow(10, 9) + 7

dp = [0] * (n+1)

dp[0] = 1

broken = [False] * (n+1)
for i in range(m):
    broken[int(input())] = True

c = 1

for i in range(1, n+1):
    if broken[i]:
        dp[i] = 0
    else:
        if i == 1:
            dp[i] = dp[i-1] % MOD
        else:
            dp[i] = (dp[i-1] + dp[i-2]) % MOD

print(dp[-1] % MOD) 


Fixed submission:
p, q, r = list(map(int, input().split()))

print(p + q + r - max([p, q, r]))
Buggy python submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))

MOD = pow(10, 9) + 7

dp = [0] * (n+1)

dp[0] = 1

broken = int(input())
c = 1

for i in range(1, n+1):
    if i == broken:
        dp[i] = 0
        if c < m:
            broken = int(input())
            c += 1
    else:
        if i == 1:
            dp[i] = dp[i-1] % MOD
        else:
            dp[i] = (dp[i-1] + dp[i-2]) % MOD

print(dp[n] % MOD) 


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

MOD = pow(10, 9) + 7

dp = [0] * (n+1)

dp[0] = 1

broken = [False] * (n+1)
for i in range(m):
    broken[int(input())] = True

c = 1

for i in range(1, n+1):
    if broken[i]:
        dp[i] = 0
    else:
        if i == 1:
            dp[i] = dp[i-1] % MOD
        else:
            dp[i] = (dp[i-1] + dp[i-2]) % MOD

print(dp[-1] % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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

s = [list(input()) for _ in range(h)]

yoko = [[0] * w for _ in range(h)]
#tate = [[0] * w for _ in range(h)]

q = deque([])
c = 0

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            q.append((i, j))
            c += 1
        
        if s[i][j] == "#" or j == w-1:
            while len(q) > 0:
                x, y = q.pop()
                yoko[x][y] = c
            c = 0



m = 0

#print(yoko)

c = 0
for j in range(w):
    for i in range(h):
        if s[i][j] == ".":
            q.append((i, j))
            c += 1

        if s[i][j] == "#" or i == h-1:
            while len(q) > 0:
                x, y = q.pop()
                m = max(m, yoko[x][y] + c - 1)
            c = 0


print(m)


Fixed submission:
from collections import deque

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

s = [list(input()) for _ in range(h)]

yoko = [[0] * w for _ in range(h)]
#tate = [[0] * w for _ in range(h)]

q = deque([])
c = 0

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            q.append((i, j))
            c += 1
        
        if s[i][j] == "#" or j == w-1:
            while len(q) > 0:
                x, y = q.pop()
                yoko[x][y] = c
            c = 0



m = 0

#print(yoko)

c = 0
for j in range(w):
    for i in range(h):
        if s[i][j] == ".":
            q.append((i, j))
            c += 1

        if s[i][j] == "#" or i == h-1:
            while len(q) > 0:
                x, y = q.pop()
                m = max(m, yoko[x][y] + c - 1)
            c = 0


print(m)
Buggy python 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)

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 python 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)



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

print(a * b // 2)
Buggy python 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)



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 python submission (verdict: Runtime Error):
from collections import Counter

n, m = list(map(int, input().split()))
MOD = pow(10, 9) + 7

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

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


d = Counter(prime_factorize(m)).most_common()

l = d[0][1] + n 

fact, factinv = make_fact_list(l, MOD)

a = 1

for k, v in d:
    a *= cbn(v + n - 1, v, MOD, fact = fact, factinv = factinv) % MOD

print(a % MOD)

Fixed submission:
from collections import Counter

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

if m == 1:
    print(1)
else:

    MOD = pow(10, 9) + 7

    def prime_factorize(n):
        a = []
        while n % 2 == 0:
            a.append(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                a.append(f)
                n //= f
            else:
                f += 2
        if n != 1:
            a.append(n)
        return a

    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


    d = Counter(prime_factorize(m)).most_common()

    l = d[0][1] + n 

    fact, factinv = make_fact_list(l, MOD)

    a = 1

    for k, v in d:
        a *= cbn(v + n - 1, v, MOD, fact = fact, factinv = factinv) % MOD

    print(a % MOD)