Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, M, Q = [int(_) for _ in input().split()]
LR = [[int(_) for _ in input().split()] for i in range(M)]
PQ = [[int(_) for _ in input().split()] for i in range(Q)]

x = [[0] * (N+1) for i in range(N+1)]
for l, r in LR:
    x[l][r] += 1

from itertools import accumulate

t = [list(accumulate(row)) for row in x]

for p, q in PQ:
    result = 0
    for i in range(p, q+1):
        result += t[i][q] - t[i][p-1]
    print(result)


Fixed submission:
N, M, Q = [int(_) for _ in input().split()]
LR = [[int(_) for _ in input().split()] for i in range(M)]
PQ = [[int(_) for _ in input().split()] for i in range(Q)]

from collections import defaultdict
from itertools import accumulate

C = [[0]*(N+1) for i in range(N+2)]

for l, r in LR:
    C[1][r] += 1
    C[l + 1][r] -= 1

#print(C)

T = [list(accumulate(row)) for row in C]
T = [list(accumulate(row)) for row in zip(*T)]

#print(T)

for p, q in PQ:
    print(T[q][p])

Buggy python submission (verdict: Runtime Error):
N, M, Q = [int(_) for _ in input().split()]
LR = [[int(_) for _ in input().split()] for i in range(M)]
PQ = [[int(_) for _ in input().split()] for i in range(Q)]

LR = sorted(LR)

W = []
x = 0
for i in range(N):
    while x < M and LR[x][0] < i:
        x += 1
    W.append(x)

from itertools import accumulate

for p, q in PQ:
    xs = LR[W[p]:]
    ys = [0] * (N+1)
    for x in xs:
        ys[x[1]] += 1
    zs = list(accumulate(ys))
    print(zs[q])



Fixed submission:
N, M, Q = [int(_) for _ in input().split()]
LR = [[int(_) for _ in input().split()] for i in range(M)]
PQ = [[int(_) for _ in input().split()] for i in range(Q)]

from collections import defaultdict
from itertools import accumulate

C = [[0]*(N+1) for i in range(N+2)]

for l, r in LR:
    C[1][r] += 1
    C[l + 1][r] -= 1

#print(C)

T = [list(accumulate(row)) for row in C]
T = [list(accumulate(row)) for row in zip(*T)]

#print(T)

for p, q in PQ:
    print(T[q][p])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

from itertools import accumulate

xs = list(accumulate(A)) + [0]

result = 0

for i in range(N):
    for j in range(i, N):
        if (xs[j] - xs[i-1]) % M == 0:
            result += 1

print(result)



Fixed submission:
N, M = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

from itertools import accumulate

from collections import defaultdict

ts = defaultdict(int)

ts[0] = 1

t = 0
for a in A:
    t = (t + a) % M
    ts[t] += 1

result = 0

for t in ts:
    result += ts[t] * (ts[t] - 1) // 2

print(result)
Buggy python submission (verdict: Runtime Error):
print(-int(input())+sum(map(input().split(),int)))

Fixed submission:
N = int(input())
A = [int(_) for _ in input().split()]

def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

#l = 1
#for a in A:
#    l = lcm(l, a)

#r = sum((l - 1) % a for a in A)
r = sum(a - 1 for a in A)

print(r)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

def calc(n):
    m = 0
    while n:
        n, d = divmod(n, 10)
        m += d
    return m

def find(xs, i):
    ri, rv = None, 10**20
    for j in range(i, len(xs)):
        if xs[j] < rv:
            ri = j
            rv = xs[j]
    return ri, rv

c = 0
i = 1
while 1:
    n = i
    r = 0
    k = 0
    vs = []
    while 1:
        n, m = divmod(n, 10)
        r += m
        if n == 0:
            break
        k += 1
        vs.append((n + 1) * 10**k - 1)
    if (not vs) or i / r <= min(v / calc(v) for v in vs):
        print(i)
        c += 1
        if c >= K:
            break
    i += 1


Fixed submission:
K = int(input())

def calc(n):
    m = 0
    while n:
        n, d = divmod(n, 10)
        m += d
    return m

def find(xs, i):
    ri, rv = None, 10**20
    for j in range(i, len(xs)):
        if xs[j] < rv:
            ri = j
            rv = xs[j]
    return ri, rv

c = 0
i = 1
prev = 0
d = 1
while 1:
    n = i
    r = 0
    k = 0
    vs = []
    while 1:
        n, m = divmod(n, 10)
        r += m
        if n == 0:
            break
        k += 1
        vs.append((n + 1) * 10**k - 1)
    if (not vs) or i / r <= min(v / calc(v) for v in vs):
        print(i)
        d = max(d, i - prev)
        prev = i
        c += 1
        if c >= K:
            break
    i += d
Buggy python submission (verdict: Time Limit Exceeded):
N, C = [int(_) for _ in input().split()]
xv = [[int(_) for _ in input().split()] for i in range(N)]

def solve(C, xv):
    
    N = len(xv)

    def mk(xv):
        ts = []
        t = 0
        for i, _ in enumerate(xv):
            x, v = _
            t += v
            ts.append((t - x, x, i))
        return ts        

    ts1 = mk(xv)
    ts2 = mk([(C - x, v) for x, v in xv[::-1]])

    result = 0

    for i in range(N):
        r0 = ts1[i][0]
        result = max(result, r0)
        for j in range(N - i - 1):
            r = r0 + ts2[j][0] - ts2[j][1]
            result = max(result, r)

    for i in range(N):
        r0 = ts2[i][0]
        result = max(result, r0)
        for j in range(N - i - 1):
            r = r0 + ts1[j][0] - ts1[j][1]
            result = max(result, r)

    return result
    
print(solve(C, xv))


Fixed submission:
N, C = [int(_) for _ in input().split()]
xv = [[int(_) for _ in input().split()] for i in range(N)]

def solve(N, C, xv):
    
    from itertools import accumulate

    xs = [0] + [_[0] for _ in xv] + [C]
    vs = [0] + [_[1] for _ in xv] + [0]
    xs_rev = [C - x for x in xs[::-1]]
    vs_rev = vs[::-1]

    ts = accumulate(vs)
    txs = [t - x for x, t in zip(xs, ts)]
    maxtxs = list(accumulate(txs, max))

    ts_rev = accumulate(vs_rev)
    txs_rev = [t - x for x, t in zip(xs_rev, ts_rev)]
    maxtxs_rev = list(accumulate(txs_rev, max))

    result = 0
    for i, tx in enumerate(txs_rev[:-1]):
        r = tx - xs_rev[i] + maxtxs[N - i]
        result = max(result, r)
    for i, tx in enumerate(txs[:-1]):
        r = tx - xs[i] + maxtxs_rev[N - i]
        result = max(result, r)

    return result

print(solve(N, C, xv))
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = [int(_) for _ in input().split()]

for n in range(A, B + 1):
    if n < A + K or n > B - K:
        print(n)
        


Fixed submission:
A, B, K = [int(_) for _ in input().split()]

nums = set(
    [n for n in range(A, min(A + K, B + 1))] +
    [n for n in range(max(B - K + 1, A), B + 1)]
)

for n in sorted(nums):
    print(n)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

K = int(input())
A = [int(x) for x in input().split()]

if A[-1] != 2:
    print(-1)
    sys.exit()

r = set([2, 3])

for i in range(len(A) - 2, -1, -1):
    m = A[i]
    nr = set([])
    for x in r:
        if x % m == 0:
            nr |= set(range(x, x + m))
    r = nr
    if len(r) == 0:
        print(-1)
        sys.exit()

print(min(r), max(r))



Fixed submission:
import sys

K = int(input())
A = [int(x) for x in input().split()]

if A[-1] != 2:
    print(-1)
    sys.exit()

minn = 2
maxn = 3

for i in range(len(A) - 2, -1, -1):
    m = A[i]
    a = (minn + m - 1) // m * m
    b = maxn // m * m
    if b < a:
        print(-1)
        sys.exit()
    minn = a
    maxn = b + m - 1

print(minn, maxn)
Buggy python submission (verdict: Runtime Error):
import sys
 
N, Y = [int(x) for x in sys.stdin.readline().strip().split()]
 
a = Y // 10000
b = (Y - a * 10000) // 5000
c = (Y - a * 10000 - b * 5000) // 1000
 
t = a + b + c
if N >= t + 9:
    l = (N - t - 9) // 9
    a -= l
    c += l * 10
 
t = a + b + c
if N >= t + 4:
    l = (N - t - 4) // 4
    b -= l
    c += l * 5
 
t = a + b + c
if N >= t:
    l = N - t
    a -= l
    b += l * 2
 
if a + b + c > N and a >= 0 and b >= 0 and c >= 0:
    print("-1 -1 -1")
else:
    print(a, b, c)


Fixed submission:
import sys

line = sys.stdin.readline().strip()
print(line[:3]+"8"+line[4:])
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N, H = [int(x) for x in sys.stdin.readline().strip().split()]
A = []
B = []
for i in range(N):
    a, b = [int(x) for x in sys.stdin.readline().strip().split()]
    A.append(a)
    B.append(b)

r = 1000000000000
for i in range(N):
    p = A[i]
    qs = [B[i] for i in range(N) if B[i] > p]
    rr = ((H - sum(qs) + (p - 1)) // p) + len(qs)
    r = min(r, rr)

print(r)


Fixed submission:
import sys

N, H = [int(x) for x in sys.stdin.readline().strip().split()]
AB = [tuple(int(x) for x in sys.stdin.readline().strip().split()) for i in range(N)]
AB.sort(key=lambda x:(-x[0],x[1]))

p = AB[0][0]
qs = [AB[j][1] for j in range(N) if AB[j][1] > p]
qs.sort(key=lambda x:-x)
r = 0
for i in range(len(qs)):
    if H <= 0:
        break
    H -= qs[i]
    r += 1

if H > 0:
    r = r + (H + (p - 1)) // p

print(r)
Buggy python submission (verdict: Runtime Error):
import sys

Q = int(sys.stdin.readline().strip())
LR = []
for i in range(Q):
    LR.append([int(x) for x in sys.stdin.readline().strip().split()])

N = 10**5
Primes = list(range(N+1))
Primes[1] = 0

for p in Primes:
    if p * p > N+1: break
    if p == 0: continue
    for i in range(p + p, N+1, p):
        Primes[i] = 0

primes = [p for p in Primes if p > 0]

likes = []
r = 0
for n in range(N):
    if n%2 == 1 and Primes[n] > 0 and Primes[n//2+1] > 0:
        r += 1
    likes.append(r)

for i in range(Q):
    print(likes[LR[i][1] + 1] - likes[LR[i][0]-1])


Fixed submission:
import sys

Q = int(sys.stdin.readline().strip())
LR = []
for i in range(Q):
    LR.append([int(x) for x in sys.stdin.readline().strip().split()])

N = 10**5+1
Primes = list(range(N+1))
Primes[1] = 0

for p in Primes:
    if p * p > N+1: break
    if p == 0: continue
    for i in range(p + p, N+1, p):
        Primes[i] = 0

primes = [p for p in Primes if p > 0]

likes = []
r = 0
for n in range(N):
    if n%2 == 1 and Primes[n] > 0 and Primes[n//2+1] > 0:
        r += 1
    likes.append(r)

for i in range(Q):
    print(likes[LR[i][1]] - likes[LR[i][0]-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def solve1(s, cache={}):
    n = len(s)
    if n == 1:
        return 1
    r = n
    while 1:
        i = 1
        while i < n:
            if s[i] != s[0]:
                for k in range(i):
                    s[k] = s[i]
                break
            if s[-i-1] != s[-1]:
                for k in range(i):
                    s[-k-1] = s[-i-1]
                break
            i += 1
        if n == i:
            break
        r = min(r, n - i)
    return r


line = sys.stdin.readline().strip()
print(solve1(list(line)))


Fixed submission:
import sys

def solve1(s):
    n = len(s)
    i = 0
    while i <= n // 2:
        if s[n // 2] != s[n // 2 - i]:
            break
        if s[(n - 1) // 2] != s[(n - 1) // 2 + i]:
            break
        i += 1
    return (n - 1) // 2 + i


line = sys.stdin.readline().strip()
print(solve1(list(line)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys

inv = {"0": "1", "1": "0"}

def solve(s, cache={}):
    n = len(s)
    if n == 1:
        return 1
    i = 1
    while i < n and s[i] == s[0]:
        i += 1
    j = 1
    while j < n and s[-j-1] == s[-1]:
        j += 1
    if i == n:
        return n
    if i < j:
        rs = n - i
        ss = s[:i] + "".join([inv[c] for c in s[i:]])
        return min(solve(ss), rs)
    else:
        rs = n - j
        ss = "".join([inv[c] for c in s[:-j]]) + s[-j:]
        return min(solve(ss), rs)

line = sys.stdin.readline().strip()
print(solve(line))


Fixed submission:
import sys

def solve1(s):
    n = len(s)
    i = 0
    while i <= n // 2:
        if s[n // 2] != s[n // 2 - i]:
            break
        if s[(n - 1) // 2] != s[(n - 1) // 2 + i]:
            break
        i += 1
    return (n - 1) // 2 + i


line = sys.stdin.readline().strip()
print(solve1(list(line)))

Buggy python submission (verdict: Runtime Error):
import sys

def solve(s, cache={}):
    if s in cache:
        return cache[s]
    n = len(s)
    if n == 1:
        return 1
    if s == "0" * n or s == "1" * n:
        return n
    r1 = solve("0" + s[1:-1])
    r2 = solve("1" + s[1:-1])
    r3 = solve(s[1:-1] + "0")
    r4 = solve(s[1:-1] + "1")
    r = max(r1, r2, r3, r4)
    cache[s] = r
    return r

line = sys.stdin.readline().strip()

print(solve(line))


Fixed submission:
import sys

def solve1(s):
    n = len(s)
    i = 0
    while i <= n // 2:
        if s[n // 2] != s[n // 2 - i]:
            break
        if s[(n - 1) // 2] != s[(n - 1) // 2 + i]:
            break
        i += 1
    return (n - 1) // 2 + i


line = sys.stdin.readline().strip()
print(solve1(list(line)))
Buggy python submission (verdict: Runtime Error):
import sys

def check(s, x, y):

    while s and s[0] == "F":
        s = s[1:]
        x -= 1
    while s and s[-1] == "T":
        s = s[:-1]

    d = 0
    vxs = []
    vys = []
    while s:
        while s and s[0] == "T":
            s = s[1:]
            d ^= 1
        l = 0
        while s and s[0] == "F":
            s = s[1:]
            l += 1
        if d:
            vys.append(l)
        else:
            vxs.append(l)

    def check1(vs, t):
        def check2(i, p, cache={}):
            if i == 0:
                return p == t
            if (i, p) in cache:
                return cache[i, p]
            r =  check2(i - 1, p - vs[i-1]) or check2(i - 1, p + vs[i-1])
            cache[i, p] = r
            return r
        return check2(len(vs), 0)

    r = check1(vxs, x) and check1(vys, y)
    return r

if __name__ == "__main__":
    s = sys.stdin.readline().strip()
    x, y = [int(n) for n in sys.stdin.readline().strip().split()]
    if check(s, x, y):
        print("Yes")
    else:
        print("No")


Fixed submission:
import sys

def check(s, x, y):

    while s and s[0] == "F":
        s = s[1:]
        x -= 1
    while s and s[-1] == "T":
        s = s[:-1]

    d = 0
    vxs = []
    vys = []
    while s:
        while s and s[0] == "T":
            s = s[1:]
            d ^= 1
        l = 0
        while s and s[0] == "F":
            s = s[1:]
            l += 1
        if d:
            vys.append(l)
        else:
            vxs.append(l)

    def check1(vs, t):
        a = 0
        for v in sorted(vs, reverse=True):
            if t < a:
                a -= v
            else:
                a += v
        return a == t

    r = check1(vxs, x) and check1(vys, y)
    return r

if __name__ == "__main__":
    s = sys.stdin.readline().strip()
    x, y = [int(n) for n in sys.stdin.readline().strip().split()]
    if check(s, x, y):
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
import sys
line = sys.stdin.readline().strip()
n, z, w = map(int, line.split()[:3])
line = sys.stdin.readline().strip()
a = list(map(int, line.split()[:n]))
#print(n, z, w)
#print(a)

def think_x(z, w, a, turn):
    if len(a) == 0:
        return abs(z - w)
    result = 0
    result_i = None
    for i in range(len(a)):
        r = think_y(a[i], w, a[i+1:], turn + 1)
        if r >= result:
            result = r
            result_i = i
    #print("# X", turn, result_i, result)
    return result

def think_y(z, w, a, turn):
    if len(a) == 0:
        return abs(z - w)
    result = 9999999999999999999999
    result_i = None
    for i in range(len(a)):
        r = think_x(z, a[i], a[i+1:], turn + 1)
        if r <= result:
            result = r
            result_i = i
    #print("# Y", turn, result_i, result)
    return result

print(think_x(z, w, a, 1))


Fixed submission:
import sys
line = sys.stdin.readline().strip()
n, z, w = map(int, line.split()[:3])
line = sys.stdin.readline().strip()
a = list(map(int, line.split()[:n]))
#print(n, z, w)
#print(a)

if n > 2:
  result = max(
    abs(a[-1] - w),
    abs(a[-2] - a[-1])
  )
else:
  result = abs(a[-1] - w)

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
def solve(K):
    checked = [99999999999] * (K + 1)
    queue = [(1, 1)]
    checked[1] = 1
    while queue:
        x, n = queue.pop(0)
        if x == 0:
            return n
        _ = (x * 10) % K 
        if n < checked[_]:
            queue.insert(0, (_, n))
            checked[_] = n
        _ = (x + 1) % K 
        if n + 1 < checked[_]:
            queue.append((_, n + 1))
            checked[_] = n + 1
    return None

K = int(input())
print(solve(K))



Fixed submission:
from collections import deque

def solve(K):
    checked = [99999999999] * (K + 1)
    queue = deque()
    queue.append((1, 1))
    checked[1] = 1
    while queue:
        x, n = queue.popleft()
        if x == 0:
            return n
        _ = (x * 10) % K 
        if n < checked[_]:
            queue.appendleft((_, n))
            checked[_] = n
        _ = (x + 1) % K 
        if n + 1 < checked[_]:
            queue.append((_, n + 1))
            checked[_] = n + 1
    return None

K = int(input())
print(solve(K))

Buggy python submission (verdict: Time Limit Exceeded):
def solve(K):
    checked = [0] * (K + 1)
    queue = [(1, 1)]
    checked[1] = 1
    while queue:
        x, n = queue.pop(0)
        # print((x, n), queue)
        if x == 0:
            return n
        _ = (x * 10) % K 
        if checked[_] == 0 or n < checked[_]:
            queue.insert(0, (_, n))
            checked[_] = n
        _ = (x + 1) % K 
        if checked[_] == 0 or n + 1 < checked[_]:
            queue.append((_, n + 1))
            checked[_] = n + 1
    return None

K = int(input())
print(solve(K))



Fixed submission:
from collections import deque

def solve(K):
    checked = [99999999999] * (K + 1)
    queue = deque()
    queue.append((1, 1))
    checked[1] = 1
    while queue:
        x, n = queue.popleft()
        if x == 0:
            return n
        _ = (x * 10) % K 
        if n < checked[_]:
            queue.appendleft((_, n))
            checked[_] = n
        _ = (x + 1) % K 
        if n + 1 < checked[_]:
            queue.append((_, n + 1))
            checked[_] = n + 1
    return None

K = int(input())
print(solve(K))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [[int(_) for _ in input().split()] for i in range(N)]

def calc(N, A):
    r = 0
    for i in range(0, N):
        for j in range(i + 1, N):
            a = A[i][j]
            d = min(A[i][k] + A[k][j] for k in range(0, N) if k != i and k != j)
            if a > d:
                return -1
            if a < d:
                r += a
    return r
    
print(calc(N, A))


Fixed submission:
N = int(input())
A = [[int(_) for _ in input().split()] for i in range(N)]

def calc(N, A):
    r = 0
    if N == 1:
        return 0
    if N == 2:
        return A[0][1]
    for i in range(0, N):
        for j in range(i + 1, N):
            a = A[i][j]
            d = min(A[i][k] + A[k][j] for k in range(0, N) if k != i and k != j)
            if a > d:
                return -1
            if a < d:
                r += a
    return r

print(calc(N, A))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
xy = [[int(_) for _ in input().split()] for i in range(N)]

from heapq import *

isused = [0] * N

h = []

heappush(h, (0, 0))

result = 0

while h:
    d, n = heappop(h)
    if isused[n]:
        continue
    result += d
    isused[n] = 1
    for i in range(N):
        if not isused[i]:
            d1 = min(abs(xy[n][0] - xy[i][0]), abs(xy[n][1] - xy[i][1]))
            heappush(h, (d1, i))
    
print(result)


Fixed submission:
N = int(input())
xy = [[int(_) for _ in input().split()] for i in range(N)]

xsort_n = sorted(range(N), key=lambda n:xy[n][0])
ysort_n = sorted(range(N), key=lambda n:xy[n][1])

from collections import defaultdict

neighbors = defaultdict(list)

for i in range(N - 1):
    x1 = xsort_n[i]
    x2 = xsort_n[i+1]
    y1 = ysort_n[i]
    y2 = ysort_n[i+1]
    neighbors[x1].append(x2)
    neighbors[x2].append(x1)
    neighbors[y1].append(y2)
    neighbors[y2].append(y1)

from heapq import *

isused = [0] * N

h = []

heappush(h, (0, 0))

result = 0

while h:
    d, n = heappop(h)
    if isused[n]:
        continue
    result += d
    isused[n] = 1
    for i in neighbors[n]:
        if not isused[i]:
            d1 = min(abs(xy[n][0] - xy[i][0]), abs(xy[n][1] - xy[i][1]))
            heappush(h, (d1, i))
    
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
xy = [[int(_) for _ in input().split()] for i in range(N)]

from heapq import *

isused = [0] * N

h = []

heappush(h, (0, 0))

result = 0

while h:
    d, n = heappop(h)
    if isused[n]:
        continue
    result += d
    isused[n] = 1
    for i in range(N):
        if not isused[i]:
            d1 = min(abs(xy[n][0] - xy[i][0]), abs(xy[n][1] - xy[i][1]))
            heappush(h, (d1, i))
    
print(result)


Fixed submission:
N = int(input())
xy = [[int(_) for _ in input().split()] for i in range(N)]

xsort_n = sorted(range(N), key=lambda n:xy[n][0])
ysort_n = sorted(range(N), key=lambda n:xy[n][1])

from collections import defaultdict

neighbors = defaultdict(list)

for i in range(N - 1):
    x1 = xsort_n[i]
    x2 = xsort_n[i+1]
    y1 = ysort_n[i]
    y2 = ysort_n[i+1]
    neighbors[x1].append(x2)
    neighbors[x2].append(x1)
    neighbors[y1].append(y2)
    neighbors[y2].append(y1)

from heapq import *

isused = [0] * N

h = []

heappush(h, (0, 0))

result = 0

while h:
    d, n = heappop(h)
    if isused[n]:
        continue
    result += d
    isused[n] = 1
    for i in neighbors[n]:
        if not isused[i]:
            d1 = min(abs(xy[n][0] - xy[i][0]), abs(xy[n][1] - xy[i][1]))
            heappush(h, (d1, i))
    
print(result)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(_) for _ in input().split()]

def calc(A, y):
    result = abs(A[0] - y)
    t = y
    for a in A[1:N]:
        tt = t + a
        if t * tt >= 0:
            m =  -t // abs(t)
            result += abs(m - tt)
            tt = m
        t = tt
    return result

result = min(calc(A, A[0]), calc(A, -A[1]-1),  calc(A, -A[1]+1))

print(result)


Fixed submission:
N = int(input())
A = [int(_) for _ in input().split()]

def calc(A, y):
    result = abs(A[0] - y)
    t = y
    if t == 0:
        return 10**30
    for a in A[1:N]:
        tt = t + a
        if t * tt >= 0:
            m =  -t // abs(t)
            result += abs(m - tt)
            tt = m
        t = tt
    return result

result = min(calc(A, A[0]), calc(A, -1),  calc(A, +1))

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
N, X = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

def solve(N, X, A):
    A2 = A + A
    T = [
        [min(A2[N+j+1-i-1:N+j+1]) for j in range(N)]
        for i in range(N)
    ]
    mins = [
        sum(T[i]) + i * X
        for i in range(N)
    ]
    result = min(mins)
    return result

print(solve(N, X, A))


Fixed submission:
N, X = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

def solve0(N, X, A):
    A2 = A + A
    T = [
        [min(A2[N+j+1-i-1:N+j+1]) for j in range(N)]
        for i in range(N)
    ]
    mins = [
        sum(T[i]) + i * X
        for i in range(N)
    ]
    result = min(mins)
    return result

def solve(N, X, A):
    M = A[:]
    result = sum(M)
    for i in range(1, N):
        M = [min(M[j], A[(j-i)%N]) for j in range(N)]
        r = sum(M) + X * i
        result = min(result, r)
    return result

print(solve(N, X, A))
Buggy python submission (verdict: Runtime Error):
M = 10**9 + 7
L = 200000
 
Fm = {}
inverseFm = {}
x = 1
for i in range(L):
    Fm[i] = x
    x = x * (i + 1) % M
 
def inverseFm(x):
    result = pow(Fm[x], M - 2, M)
    return result
 
def C(n, r):
    result = Fm[n] * inverseFm(r) * inverseFm(n - r) % M
    return result
 
def solve(H, W, A, B):
    result = 0
    for i in range(B + 1, W + 1):
        result += C(i + H - A - 1 - 1, i - 1) * C(W - i + A - 1, W - i)
    return result % M
 
H, W, A, B = [int(_) for _ in input().split()]
 
print(solve(H, W, A, B))


Fixed submission:
ABC = [int(_) for _ in input().split()]

if sorted(ABC) == [5, 5, 7]:
    print("YES")
else:
    print("NO")