Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, q = [int(i) for i in input().split()]
s = input()
td = reversed([input().split() for _ in range(q)])

l = 0
r = n - 1
for t, d in td:
    if d == "L":
        if s[l] == t:
            l = min(l + 1, n)

        if r + 1 < n and s[r + 1] == t:
            r = min(r + 1, n)
    else:
        if 0 < l and s[l - 1] == t:
            l = max(0, l - 1)

        if s[r] == t:
            r = max(0, r - 1)


'''
    if s[l] == t:
        if d == "L":
            l += 1
        else:
            l -= 1
        l = max(0, min(n - 1, l))
    if s[r] == t:
        if d == "L":
            r += 1
        else:
            r -= 1
        r = max(0, min(n - 1, r))
'''
print(max(0, r-l+1))


Fixed submission:
n, q = [int(i) for i in input().split()]
s = input()
td = reversed([input().split() for _ in range(q)])

l = 0
r = n - 1
for t, d in td:
    if d == "L":
        if 0 <= l < n and s[l] == t:
            l = l + 1

        if 0 <= r + 1 < n and s[r + 1] == t:
            r = min(r + 1, n - 1)
    else:
        if 0 <= l-1 < n and s[l - 1] == t:
            l = max(0, l - 1)

        if 0 <= r < n and s[r] == t:
            r = r - 1


'''
    if s[l] == t:
        if d == "L":
            l += 1
        else:
            l -= 1
        l = max(0, min(n - 1, l))
    if s[r] == t:
        if d == "L":
            r += 1
        else:
            r -= 1
        r = max(0, min(n - 1, r))
'''
print(max(0, r-l+1))

Buggy python submission (verdict: Runtime Error):
n, q = [int(i) for i in input().split()]
s = input()
td = reversed([input().split() for _ in range(q)])

l = 0
r = n - 1
for t, d in td:
    if d == "L":
        if s[l] == t:
            l = min(l + 1, n)

        if r + 1 < n and s[r + 1] == t:
            r = min(r + 1, n)
    else:
        if 0 < l and s[l - 1] == t:
            l -= 1

        if s[r] == t:
            r -= 1


'''
    if s[l] == t:
        if d == "L":
            l += 1
        else:
            l -= 1
        l = max(0, min(n - 1, l))
    if s[r] == t:
        if d == "L":
            r += 1
        else:
            r -= 1
        r = max(0, min(n - 1, r))
'''
print(max(0, r-l+1))


Fixed submission:
n, q = [int(i) for i in input().split()]
s = input()
td = reversed([input().split() for _ in range(q)])

l = 0
r = n - 1
for t, d in td:
    if d == "L":
        if 0 <= l < n and s[l] == t:
            l = l + 1

        if 0 <= r + 1 < n and s[r + 1] == t:
            r = min(r + 1, n - 1)
    else:
        if 0 <= l-1 < n and s[l - 1] == t:
            l = max(0, l - 1)

        if 0 <= r < n and s[r] == t:
            r = r - 1


'''
    if s[l] == t:
        if d == "L":
            l += 1
        else:
            l -= 1
        l = max(0, min(n - 1, l))
    if s[r] == t:
        if d == "L":
            r += 1
        else:
            r -= 1
        r = max(0, min(n - 1, r))
'''
print(max(0, r-l+1))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

dp = [""] * (n+1)
dp[0] = "0"
ma = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

for i in range(n):
    if dp[i] == "":
        continue
    elif dp[i] == "0":
        for j in a:
            k = i + ma[j]
            if k <= n:
                if dp[k] == "":
                    dp[k] = "0"
                dp[k] = max(dp[k], str(j), key=int)
    else:
        for j in a:
            k = i + ma[j]
            if k <= n:
                if dp[k] == "":
                    dp[k] = "0"
                dp[k] = max(dp[k], dp[i] + str(j), key=int)
                dp[k] = max(dp[k], str(j)+dp[i], key=int)

print(dp[-1])


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

dp = [(0, 0)] * (n+1)
ma = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

for i in range(n):
    if i!=0 and dp[i] == (0, 0):
        continue
    for j in a:
        t = dp[i]
        k = i + ma[j]
        if k <= n:
            dp[k] = max(dp[k], (t[0] + j * 10 ** t[1], t[1] + 1))
            dp[k] = max(dp[k], (t[0]*10 + j, t[1] + 1))

print(dp[-1][0])

Buggy python submission (verdict: Time Limit Exceeded):
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

dp = [""] * (n+1)
dp[0] = "0"
ma = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

for i in range(n):
    if dp[i] == "":
        continue
    elif dp[i] == "0":
        for j in a:
            k = i + ma[j]
            if k <= n:
                if dp[k] == "":
                    dp[k] = "0"
                dp[k] = max(dp[k], str(j), key=int)
    else:
        for j in a:
            k = i + ma[j]
            if k <= n:
                if dp[k] == "":
                    dp[k] = "0"
                dp[k] = max(dp[k], dp[i] + str(j), key=int)
                dp[k] = max(dp[k], str(j)+dp[i], key=int)

print(dp[-1])


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

dp = [(0, 0)] * (n+1)
ma = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

for i in range(n):
    if i!=0 and dp[i] == (0, 0):
        continue
    for j in a:
        t = dp[i]
        k = i + ma[j]
        if k <= n:
            dp[k] = max(dp[k], (t[0] + j * 10 ** t[1], t[1] + 1))
            dp[k] = max(dp[k], (t[0]*10 + j, t[1] + 1))

print(dp[-1][0])
Buggy python submission (verdict: Time Limit Exceeded):
n, w = [int(i) for i in input().split()]
a = [0] * (w + 1)
for _ in range(n):
    b, c = [int(i) for i in input().split()]
    for i in reversed(range(w + 1)):
        if i + b >= w + 1:
            continue
        d = i + b
        a[d] = max(a[d], a[i] + c)
print(a[-1])


Fixed submission:
n, w = [int(i) for i in input().split()]
a = [0] * (w + 1)
for _ in range(n):
    b, c = [int(i) for i in input().split()]
    for i in reversed(range(w + 1)):
        if i + b >= w + 1:
            continue
        d = i + b
        a[d] = max(a[d], a[i] + c)
print(a[-1])
Buggy python submission (verdict: Runtime Error):
n, w = [int(i) for i in input().split()]
a = [0] * (w + 1)
for _ in range(n):
    b, c = [int(i) for i in input().split()]
    for i in reversed(range(w + 1)):
        if i + b >= w + 1:
            continue
        d = i + b
        a[d] = max(a[d], a[i] + c)
print(a[-1])


Fixed submission:
n, w = [int(i) for i in input().split()]
dp = [10 ** 18] * (10 ** 5 + 1)
dp[0] = 0
for _ in range(n):
    u, v = [int(i) for i in input().split()]
    for i in reversed(range(len(dp))):
        if i + v < len(dp) and dp[i]+u <= w:
            dp[i + v] = min(dp[i + v], dp[i] + u)
ans = 0
for i, j in enumerate(dp):
    if j != 10 ** 18:
        ans = max(ans, i)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
e = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = [int(i) - 1 for i in input().split()]
    e[a].append(b)
    e[b].append(a)

mod = 10**9+7

def dfs(i=0, r=-1):
    b = w = 1
    for j in e[i]:
        if j == r:
            continue
        bb, ww = dfs(j, i)
        b = b * ww % mod
        w = w * (bb + ww) % mod
    return b, w

print(sum(dfs()))


Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()
n = int(input())
e = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = [int(i) - 1 for i in input().split()]
    e[a].append(b)
    e[b].append(a)

mod = 10**9+7

def dfs(i=0, r=-1):
    b = w = 1
    for j in e[i]:
        if j == r:
            continue
        bb, ww = dfs(j, i)
        b = b * ww % mod
        w = w * (bb + ww) % mod
    return b, w

print(sum(dfs())%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
dp = [1] * n
mod = 10 ** 9 + 7
for ind, i in enumerate(s):
    dp2 = [0] * n
    if i == ">":
        s = 0
        for j in reversed(range(n-ind)):
            dp2[j] = s
            s += dp[j]
            s %= mod
    else:
        s = 0
        for j in range(n):
            s += dp[j]
            dp2[j] = s
            s %= mod
    dp = dp2
print(dp[0])
a = 0


Fixed submission:
n = int(input())
s = input()
dp = [1] * n
mod = 10 ** 9 + 7
for ind, i in enumerate(s):
    dp2 = [0] * n
    if i == ">":
        s = 0
        for j in reversed(range(n-ind)):
            dp2[j] = s
            s += dp[j]
            s %= mod
    else:
        s = 0
        for j in range(n):
            s += dp[j]
            dp2[j] = s
            s %= mod
    dp = dp2
print(dp[0])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()
n, m = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = [int(i) - 1 for i in input().split()]
    e[a].append(b)
    e[b].append(a)
dp1 = [0] * n


def dfs1(i=0, r=-1):
    s = 1
    for j in e[i]:
        if j != r:
            s *= dfs1(j, i)
            s %= m
    dp1[i] = s
    return s + 1


dfs1()
dp2 = [0] * n
dp2[0] = dp1[0]


def dfs2(i=0, r=-1, s=1):
    a = [1]
    for j in e[i]:
        if j != r:
            a.append(a[-1] * (dp1[j]+1) % m)
    b = [1]
    for j in reversed(e[i]):
        if j != r:
            b.append(b[-1] * (dp1[j]+1) % m)
    b.reverse()

    k = 0
    for j in e[i]:
        if j != r:
            l = (a[k] * b[k + 1] * s + 1)%m
            dp2[j] = l * dp1[j] % m
            dfs2(j, i, l)
            k += 1


dfs2()
print("\n".join(map(str,dp2)))


Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()
n, m = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = [int(i) - 1 for i in input().split()]
    e[a].append(b)
    e[b].append(a)
dp1 = [0] * n


def dfs1(i=0, r=-1):
    s = 1
    for j in e[i]:
        if j != r:
            s *= dfs1(j, i)
            s %= m
    dp1[i] = s
    return s + 1


dfs1()
dp2 = [0] * n
dp2[0] = dp1[0]


def dfs2(i=0, r=-1, s=1):
    a = [1]
    for j in e[i]:
        if j != r:
            a.append(a[-1] * (dp1[j]+1) % m)
    b = [1]
    for j in reversed(e[i]):
        if j != r:
            b.append(b[-1] * (dp1[j]+1) % m)
    b.reverse()

    k = 0
    for j in e[i]:
        if j != r:
            l = (a[k] * b[k + 1] * s + 1)%m
            dp2[j] = l * dp1[j] % m
            dfs2(j, i, l)
            k += 1


dfs2()
print("\n".join(map(str,dp2)))
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n == 1:
  orint("Hello World")
else:
  a = int(input())
  b = int(input())
  print(a+b)

Fixed submission:
n = int(input())
if n == 1:
  print("Hello World")
else:
  a = int(input())
  b = int(input())
  print(a+b)
Buggy python submission (verdict: Runtime Error):
n = [input(i) for i in input().split()]
n.sort(reverse=True)
print(n[0]*10*n[1]+n[2])

Fixed submission:
n = [int(i) for i in input().split()]
n.sort(reverse=True)
print(n[0]*10+n[1]+n[2])
Buggy python submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]


def fact(x):
    a = []
    for i in range(2, int(x ** 0.5) + 1):
        if x % i == 0:
            j = 0
            while x % i == 0:
                x //= i
                j += 1
        a.append((i, j))
    if x != 1:
        a.append((x,1))
    return a


f = fact(m)


def conv(a, b):
    c = 1
    for i in range(b, b - a, -1):
        c *= i
    for i in range(1, a + 1):
        c //= i
    return c % (10 ** 9 + 7)


ans = 1
for i in f:
    ans *= conv(n - 1, n + i[1] - 1)
    ans %= 10 ** 9 + 7
print(ans)


Fixed submission:
n, m = [int(i) for i in input().split()]
prime = 10 ** 9 + 7

def fact(x):
    a = []
    for i in range(2, int(x ** 0.5) + 1):
        if x % i == 0:
            j = 0
            while x % i == 0:
                x //= i
                j += 1
            a.append((i, j))
    if x != 1:
        a.append((x,1))
    return a


f = fact(m)
def kai(x):
    a = 1
    for i in range(a, x + 1):
        a *= i
        a %= prime
    return a

def conv(a, b):
    c = kai(b)
    c *= pow(kai(a), prime - 2, prime)
    c %= prime
    c *= pow(kai(b - a), prime - 2, prime)
    return c % prime


ans = 1
for i in f:
    ans *= conv(n - 1, n + i[1] - 1)
    ans %= prime
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]

b = [0]
for i in a:
    b.append(b[-1] + i)


def get(i, j):
    i, j = min(i, j), max(i, j)
    return b[j]-b[i]


j = 0
k = 0
ans = 10**18
for i in range(n):
    while j < n and abs(get(0, j) - get(j, i)) > abs(get(0, j + 1) - get(j + 1, i)):
        j += 1
    while k < n and abs(get(i, k) - get(k, n)) > abs(get(i, k + 1) - get(k + 1, n)):
        k += 1
    an = [get(0, j), get(j, i), get(i, k), get(k, n)]
    ans = min(ans,max(an)-min(an))
print(ans)

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

b = [0]
for i in a:
    b.append(b[-1] + i)


def get(i, j):
    i, j = min(i, j), max(i, j)
    return b[j]-b[i]


j = 0
k = 0
ans = 10**18
for i in range(n):
    while j < n and abs(get(0, j) - get(j, i)) > abs(get(0, j + 1) - get(j + 1, i)):
        j += 1
    while k < n and abs(get(i, k) - get(k, n)) > abs(get(i, k + 1) - get(k + 1, n)):
        k += 1
    an = [get(0, j), get(j, i), get(i, k), get(k, n)]
    ans = min(ans,max(an)-min(an))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()
    
n, m = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(m):
    a, b = [int(i) - 1 for i in input().split()]
    e[a].append(b)
    e[b].append(a)

ok = False
tag = [-1] * n


def dfs(i=0, c=0):
    global ok, tag
    if tag[i] != -1:
        if tag[i] != c:
            ok = True
        return
    tag[i] = c
    for j in e[i]:
        dfs(j, (c + 1) % 2)


dfs()

if ok:
    print(n * (n - 1) // 2 - m)
else:
    s = sum(tag)
    print(s * (n - s) - m)


Fixed submission:
import sys
sys.setrecursionlimit(1000000)


def input():
    return sys.stdin.readline()


n, m = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(m):
    a, b = [int(i) - 1 for i in input().split()]
    e[a].append(b)
    e[b].append(a)

ok = False
tag = [-1] * n


def dfs(i=0, c=0, r=-1):
    global ok, tag
    if tag[i] != -1:
        if tag[i] != c:
            ok = True
        return
    tag[i] = c
    for j in e[i]:
        if j == r:
            continue
        dfs(j, (c + 1) % 2, i)


dfs()

if ok:
    print(n * (n - 1) // 2 - m)
else:
    s = sum(tag)
    print(s * (n - s) - m)

Buggy python submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(m):
    a, b = [int(i) - 1 for i in input().split()]
    e[a].append(b)
    e[b].append(a)

ok = False
tag = [-1] * n


def dfs(i=0, c=0):
    global ok, tag
    if tag[i] != -1:
        if tag[i] != c:
            ok = True
        return
    tag[i] = c
    for j in e[i]:
        dfs(j, (c + 1) % 2)


dfs()

if ok:
    print(n * (n - 1) // 2 - m)
else:
    s = sum(tag)
    print(s * (n - s) - m)


Fixed submission:
import sys
sys.setrecursionlimit(1000000)


def input():
    return sys.stdin.readline()


n, m = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(m):
    a, b = [int(i) - 1 for i in input().split()]
    e[a].append(b)
    e[b].append(a)

ok = False
tag = [-1] * n


def dfs(i=0, c=0, r=-1):
    global ok, tag
    if tag[i] != -1:
        if tag[i] != c:
            ok = True
        return
    tag[i] = c
    for j in e[i]:
        if j == r:
            continue
        dfs(j, (c + 1) % 2, i)


dfs()

if ok:
    print(n * (n - 1) // 2 - m)
else:
    s = sum(tag)
    print(s * (n - s) - m)
Buggy python submission (verdict: Runtime Error):
n, m, p = [int(i) for i in input().split()]
e = [[int(i) for i in input().split()] for _ in range(m)]

for i in e:
    i[0] -= 1
    i[1] -= 1
    i[2] -= p

d = [0] * n
ok = [False] * n
ok[0] = True

for _ in range(n):
    for a, b, c in e:
        if ok[a]:
            d[b] = max(d[b], d[a] + c)
            ok[b] = True

aa = d[-1]

for _ in range(2*n):
    for a, b, c in e:
        if ok[a]:
            d[b] = max(d[b], d[a] + c)
            ok[b] = True

bb = d[-1]

if aa != bb:
    print("-1")
else:
    print(max(aa, 0))


Fixed submission:
n = int(input())
s1 = input()
s2 = input()
mod = 10**9+7
ans = 3
i = 0
j = -1
while i < n:
    if s1[i] == s2[i]:
        if j == 0:
            ans *= 2
        i += 1
        j = 0
    else:
        if j == 1:
            ans *= 3
        else:
            ans *= 2
        j = 1
        i += 2
    ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
q = int(input())
mod = 10**9+7
for _ in range(q):
    x, y = sorted(map(int, input().split()))

    ma = 0
    i, j = 1, 1
    while j <= x and i+j <= y:
        i, j = j, i+j
        ma += 1
    if x == 1 or y<=2:
        print(1, x*y % mod)
    else:
        ans = 0
        if x >= i:
            ans += max(0, (y-j) // i+1)
        if y >= i:
            ans += max(0, (x-j) // i+1)
        i, j = 1, 1
        for c in range(ma-1):
            k, l = j, i+j*2
            if gcd(k, l) == 1:
                for _ in range(ma-c-1):
                    k, l = l, k+l
                if x >= k:
                    ans += max(0, (y-l) // k+1)
                if y >= k:
                    ans += max(0, (x-l) // k+1)
            i, j = j, i+j
        print(ma, ans % mod)


Fixed submission:
from math import gcd
q = int(input())
mod = 10**9+7
tan = 100
tab = [[[0]*2 for _ in range(tan)] for _ in range(tan)]

for _ in range(q):
    x, y = sorted(map(int, input().split()))

    ma = 0
    i, j = 1, 1
    while j <= x and i+j <= y:
        i, j = j, i+j
        ma += 1
    if x == 1 or y <= 2:
        print(1, x*y % mod)
    else:
        ans = 0
        if x >= i:
            ans += max(0, (y-j) // i+1)
        if y >= i:
            ans += max(0, (x-j) // i+1)
        i, j = 1, 1
        for c in range(ma-1):
            k, l = j, i+j*2
            for _ in range(ma-c-1):
                k, l = l, k+l
            if x >= k:
                ans += max(0, (y-l) // k+1)
            if y >= k:
                ans += max(0, (x-l) // k+1)
            i, j = j, i+j
        print(ma, ans % mod)
Buggy python submission (verdict: Runtime Error):
import heapq

n, x = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
tt = [[] for _ in range(10 ** 5 + 1)]
for i in range(n):
    tt[t[i]].append(-a[i])


def max_score(time):
    q = []
    heapq.heapify(q)
    for i in range(time, 10 ** 5 + 1):
        for j in tt[i]:
            heapq.heappush(q, j)

    ans = 0
    for i in reversed(range(time)):
        if q:
            ans += heapq.heappop(q)
        for j in tt[i]:
            heapq.heappush(q, j)
    return -ans


if max_score(10 ** 5) < x:
    print(-1)
    exit()

mi = 0
ma = 10 ** 5

while mi != ma:
    m = (mi + ma) // 2
    if max_score(m) >= x:
        ma = m
    else:
        mi += 1
print(mi)


Fixed submission:
n, m = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(m):
    a, b = [int(i)-1 for i in input().split()]
    e[a].append(b)
    e[b].append(a)

used = [False] * n
used[0] = True
ans1 = [1]
ans2 = []
i = 0
while True:
    for j in e[i]:
        if not used[j]:
            i = j
            ans1.append(j + 1)
            used[j] = True
            break
    else:
        break
i = 0
while True:
    for j in e[i]:
        if not used[j]:
            i = j
            ans2.append(j + 1)
            used[j] = True
            break
    else:
        break

ans = list(reversed(ans2)) + ans1

print(len(ans))
print(" ".join(map(str, ans)))
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
if n%2 == 1:
  if a[0]!=0:
    print(0)
    exit()
  for i,j,k in zip(a[1::2],a[2::2],range(,n,2)):
    if not i==j==k:
      print(0)
      exit()
  print(2**(n//2))
  exit()
for i,j,k in zip(a[::2],a[1::2],range(,n,2)):
  if not i==j==k:
    print(0)
    exit()
print(2**(n//2))

Fixed submission:
i=input
n=int(i())
print([0,pow(2,n//2,10**9+7)][sorted(i().split(),key=int)==[str((j+n%2)//2*2+1-n%2)for j in range(n)]])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [-int(i) for i in input().split()]


class SparseTable:
    def __init__(self, a, func=max, one=-10**18):
        self.table = [a[:]]
        self.n = len(a)
        self.logn = self.n.bit_length()
        self.func = func
        self.one = one

        for i in map(lambda x: 1 << x, range(self.logn - 1)):
            self.table.append([])
            for j in range(self.n - i * 2 + 1):
                self.table[-1].append(self.func(self.table[-2][j],
                                                self.table[-2][j + i]))

    def get_section(self, i, j):
        length = j - i
        log = length.bit_length() - 1
        if length <= 0:
            return self.one
        return self.func(self.table[log][i], self.table[log][j - (1 << log)])


sp = SparseTable(a)
ans = 0
for i in range(n):
    mi = 0
    ma = i
    while mi != ma:
        mm = (mi + ma) // 2
        if sp.get_section(mm, i) <= a[i]:
            ma = mm
        else:
            mi = mm + 1
    j = i - mi + 1

    mi = i - 1
    ma = n - 1
    while mi != ma:
        mm = (mi + ma) // 2 + 1
        if sp.get_section(i, mm + 1) <= a[i]:
            mi = mm
        else:
            ma = mm - 1
    k = mi - i + 1
    ans += j * k * a[i]
print(-ans)


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


class SparseTable:
    def __init__(self, a, func=max, one=-10**18):
        self.table = [a[:]]
        self.n = len(a)
        self.logn = self.n.bit_length()
        self.func = func
        self.one = one

        for i in map(lambda x: 1 << x, range(self.logn - 1)):
            self.table.append([])
            for j in range(self.n - i * 2 + 1):
                self.table[-1].append(self.func(self.table[-2][j],
                                                self.table[-2][j + i]))

    def get_section(self, i, j):
        length = j - i
        log = length.bit_length() - 1
        if length <= 0:
            return self.one
        return self.func(self.table[log][i], self.table[log][j - (1 << log)])


sp = SparseTable(a)
ans = 0
for i in range(n):
    mi = 0
    ma = i
    while mi != ma:
        mm = (mi + ma) // 2
        if sp.get_section(mm, i) <= a[i]:
            ma = mm
        else:
            mi = mm + 1
    j = i - mi + 1

    mi = i - 1
    ma = n - 1
    while mi != ma:
        mm = (mi + ma) // 2 + 1
        if sp.get_section(i, mm + 1) <= a[i]:
            mi = mm
        else:
            ma = mm - 1
    k = mi - i + 1
    ans += j * k * a[i]
print(-ans)
Buggy python submission (verdict: Runtime Error):
a,b=[int(i) fro i in input().split()]
if 0<a and 0<b:
  print("Positive")
elif a*b<=0:
  print("Zero")
elif (b-a)%2==1:
  print("Positive")
else:
  print("Negative")

Fixed submission:
a,b=[int(i) for i in input().split()]
if 0<a and 0<b:
  print("Positive")
elif a*b<=0:
  print("Zero")
elif (b-a)%2==1:
  print("Positive")
else:
  print("Negative")