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

r = False
for _ in range(Q):
    q = input().split()
    if q[0] == '1':
        r = not r
    else:
        if (q[1] == '1' and not r) or (q[1] == '2' and r):
            S = q[2] + S
        else:
            S = S + q[2]
            
if r:
    S = ''.join(reversed(S))
print(S)

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

S = input()
Q = int(input())

u = ''
t = ''

r = False
for _ in range(Q):
    q = readline().split()
    if q[0] == '1':
        u, t = t, u
        r = not r
    else:
        if q[1] == '1':
            t += q[2]
        else:
            u += q[2]
            
if r:
    print(t[::-1]+S[::-1]+u)
else:
    print(t[::-1]+S+u)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N = int(input())
P = [int(i) for i in input().split()]

res = 1

for i in range(N-1, 0, -1):
    m = min(P[:i])
    if m > P[i]:
        res += 1

print(res)

Fixed submission:
import numpy as np

N = int(input())
P = list(map(int, input().split()))

res = 0
min_ = 2*10**5

for i in range(0, N):
    if P[i] <= min_:
        res += 1
    
        min_ = P[i]

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N = int(input())
P = [int(i) for i in input().split()]

res = 1

for i in range(N-1, 0, -1):
    m = min(P[:i])
    if m > P[-1]:
        res += 1
    P = P[:-1]

print(res)

Fixed submission:
import numpy as np

N = int(input())
P = list(map(int, input().split()))

res = 0
min_ = 2*10**5

for i in range(0, N):
    if P[i] <= min_:
        res += 1
    
        min_ = P[i]

print(res)
Buggy python submission (verdict: Runtime Error):
N = int(input())

res = 0
freq = {}

for i in range(0, 10):
    for j in range(0, 10):
        freq[f'{i}{j}'] = 0

for i in range(1, N):
    si = str(i)
    freq[f'{si[0]}{si[-1]}'] += 1
    
for i in range(1, N):
    si = str(i)
    res += freq[f'{si[-1]}{si[0]}']
        
print(res)

Fixed submission:
from collections import defaultdict
N = int(input())

res = 0
freq = defaultdict(int)

for i in range(1, N+1):
    si = str(i)
    freq['{}{}'.format(si[0], si[-1])] += 1
    
for i in range(1, N+1):
    si = str(i)
    res += freq['{}{}'.format(si[-1], si[0])]
        
print(res)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N = int(input())

res = 0
freq = defaultdict(int)

for i in range(1, N):
    si = str(i)
    freq[f'{si[0]}{si[-1]}'] += 1
    
for i in range(1, N):
    si = str(i)
    res += freq[f'{si[-1]}{si[0]}']
        
print(res)

Fixed submission:
from collections import defaultdict
N = int(input())

res = 0
freq = defaultdict(int)

for i in range(1, N+1):
    si = str(i)
    freq['{}{}'.format(si[0], si[-1])] += 1
    
for i in range(1, N+1):
    si = str(i)
    res += freq['{}{}'.format(si[-1], si[0])]
        
print(res)
Buggy python submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
    print((B - A) // 2)
else:
    if B - A == 1: 
        print(min(N-A, B-1))
    elif A == 1:
        print(1+(B-1-A)//2)
    elif B == N:
        print(1+(B-A-1)//2)
    else:
        print(min((A+(B-A-1)//2, N-B+1+(B-A+1)//2))

Fixed submission:
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
    print((B - A) // 2)
else:
    print(min(A-1, N-B)+1+(B-A-1)//2)

Buggy python submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
    print((B - A) // 2)
else:
    if B - A == 1: 
        print(min(N-A, B-1))
    elif A == 1 or B == N:
        print((B - A - 1) // 2 + 1)
    else:
        print(min((A-1)+1+(B-2-1)//2), (N-B)+1+(N-A-2)//2)

Fixed submission:
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
    print((B - A) // 2)
else:
    print(min(A-1, N-B)+1+(B-A-1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    N = II()
    S = input()

    ans = []
    for i in range(2**N, 2**(N+1)):
        if bin(i)[3:].count('1') == N - 3:
            t = ''
            for s, b in zip(S, bin(i)[3:]):
                if b != '1':
                    t += s
            ans.append(t)
        
    print(len(set(ans)))

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    # N = II()
    # S = input()

    # ans = []
    # for i in range(2**N, 2**(N+1)):
    #     if bin(i)[3:].count('1') == N - 3:
    #         t = ''
    #         for s, b in zip(S, bin(i)[3:]):
    #             if b != '1':
    #                 t += s
    #         ans.append(t)
        
    # print(len(set(ans)))

    N = II()
    S = input()

    ans = 0
    for i in range(10):
        a = S.find(str(i))
        if a != -1:
            for j in range(10):
                b = S.find(str(j), a+1)
                if b != -1:
                    for k in range(10):
                        c = S.find(str(k), b+1)
                        if c != -1:
                            ans += 1

    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
N = int(input())
E = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    E[a].append((b, i))
    E[b].append((a, i))

K = max(len(e) for e in E)
print(K)

Ans = [-1] * (N-1)
def dfs(v, pc=-1, p=-1):
    c = 1
    for u, idx in E[v]:
        if (u == p):
            continue
        if (c == pc): 
            c += 1
        Ans[idx] = c
        dfs(u, c, v)
        c += 1

dfs(1)
print("\n".join(map(str, Ans)))

Fixed submission:
import sys
sys.setrecursionlimit(500000)

N = int(input())
E = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    E[a].append((b, i))
    E[b].append((a, i))

K = max(len(e) for e in E)
print(K)

Ans = [-1] * (N-1)
def dfs(v, pc=-1, p=-1):
    c = 1
    for u, idx in E[v]:
        if (u == p):
            continue
        if (c == pc): 
            c += 1
        Ans[idx] = c
        dfs(u, c, v)
        c += 1

dfs(1)
print("\n".join(map(str, Ans)))

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

K = max(len(e) for e in E)
print(K)

Ans = [-1] * (N-1)
def dfs(v, pc=-1, p=-1):
    c = 1
    for u, idx in E[v]:
        if (u == p):
            continue
        if (c == pc): 
            c += 1
        Ans[idx] = c
        c += 1
        dfs(u, c, v)
        
dfs(1)
print("\n".join(map(str, Ans)))

Fixed submission:
import sys
sys.setrecursionlimit(500000)

N = int(input())
E = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    E[a].append((b, i))
    E[b].append((a, i))

K = max(len(e) for e in E)
print(K)

Ans = [-1] * (N-1)
def dfs(v, pc=-1, p=-1):
    c = 1
    for u, idx in E[v]:
        if (u == p):
            continue
        if (c == pc): 
            c += 1
        Ans[idx] = c
        dfs(u, c, v)
        c += 1

dfs(1)
print("\n".join(map(str, Ans)))
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

from collections import Counter

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    N = II()
    D = LII()

   if D[0] != 0 or D.count(0) > 1:
       print(0)
       return 
    
    mx = max(D)
    cnt = 1
    for i in range(1, mx+1):
        pre = D.count(i)
        post = D.count(i+1)
        cnt *= pre ** post
    print(cnt)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3

from collections import Counter

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

MOD = 998244353

def main():
    N = II()
    D = LII()

    if D[0] != 0 or D.count(0) > 1:
       print(0)
       return 
    
    c = Counter(D)
    res = 1

    if c[0] > 1:
       print(0)
       return
    
    mx = max(c.keys())
    for i in range(1, mx+1):
        if i not in c:
            print(0)
            return
        
        res = (res * c[i-1] ** c[i]) % MOD

    print(res)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
N = int(input())

for i in range(1, 10):
  if N % i == 0 and N / i <10:
    print("Yes")
    return 
  
print("No")


Fixed submission:
def solve():
    N = int(input())

    for i in range(1, 10):
        if N % i == 0 and N / i <10:
            print("Yes")
            return 

    print("No")
    
solve()
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def solve():
    N = int(input())
    
    r = 1e12
    for i in range(N - 1, int(np.sqrt(N)) - 1, -1):
        if N % i == 0:
            r = min(r, (N / i - 1) + (i - 1))
            
    
    print(int(r))

solve()

Fixed submission:
import numpy as np

def solve():
    N = int(input())
    
    r = 1e12
    for i in range(1, int(np.sqrt(N)) + 1):
        if N % i == 0:
            r = min(r, (N / i - 1) + (i - 1))
            
    
    print(int(r))

solve()

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    N = int(input())
    
    r = 1e12
    for i in range(N - 1, 0, -1):
        if N % i == 0:
            r = min(r, (N / i - 1) + (i - 1))
            
    
    print(int(r))

solve()

Fixed submission:
import numpy as np

def solve():
    N = int(input())
    
    r = 1e12
    for i in range(1, int(np.sqrt(N)) + 1):
        if N % i == 0:
            r = min(r, (N / i - 1) + (i - 1))
            
    
    print(int(r))

solve()
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
L = list(map(int, input().split()))
ans = 0
c = 0

L.sort()

for i in range(n-2):
    for j in range(i+1, n):
        c = L[i]+L[j]
        l = j
        r = bisect.bisect_left(L, c, lo=l) -1
        ans += (r-l)

print(ans)

Fixed submission:
import bisect

n=int(input())
L=sorted(list(map(int,input().split())))

ans=0
for i in range(n-1):
  for j in range(i+1,n):
    idx=bisect.bisect_left(L,L[j]+L[i])
    ans+=max(0,idx-j-1)

print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
L = list(map(int, input().split()))
ans = 0
c = 0

L.sort()

for i in range(n-2):
    for j in range(i+1, n):
        c = L[i]+L[j]
        l = j
        r = bisect.bisect_left(L, c, lo=l) -1
        ans += (r-l)

print(ans)

Fixed submission:
import bisect

n=int(input())
L=sorted(list(map(int,input().split())))

ans=0
for i in range(n-1):
  for j in range(i+1,n):
    idx=bisect.bisect_left(L,L[j]+L[i])
    ans+=max(0,idx-j-1)

print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
L = list(map(int, input().split()))
ans = 0
c = 0

L.sort()

for i in range(n-2):
    for j in range(i+1, n):
        c = L[i]+L[j]
        l = j
        r = bisect.bisect_left(L, c, lo=l) -1
        ans += (r-l)

print(ans)

Fixed submission:
import bisect

n=int(input())
L=sorted(list(map(int,input().split())))

ans=0
for i in range(n-1):
  for j in range(i+1,n):
    idx=bisect.bisect_left(L,L[j]+L[i])
    ans+=max(0,idx-j-1)

print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
L = list(map(int, input().split())
ans = 0
c = 0

L.sort()

for i in range(n-2):
  for j in range(i+1, n):
    c = L[i]+L[j]
    l = j
    r = bisect.bisect_left(L, c, lo=l) -1
    ans += (r-l)

print(ans)

Fixed submission:
import bisect

n=int(input())
L=sorted(list(map(int,input().split())))

ans=0
for i in range(n-1):
  for j in range(i+1,n):
    idx=bisect.bisect_left(L,L[j]+L[i])
    ans+=max(0,idx-j-1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
d = list(map(int, input().split()))

s = 0
for i, di in enumerate(d):
    d2 = d[i+1:]
    for j, dj in enumerate(d2):
        d3 = d2[j+1:]
        for dk in d3:
            if (di < dj + dk) and (dj < di + dk) and (dk < di + dj):
                s += 1

print(s)

Fixed submission:
import bisect

n=int(input())
L=sorted(list(map(int,input().split())))

ans=0
for i in range(n-1):
  for j in range(i+1,n):
    idx=bisect.bisect_left(L,L[j]+L[i])
    ans+=max(0,idx-j-1)

print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import groupby

def solve():
    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupgy(S)]
    
    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            return a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1)
            ans += sum(n // 2 for n in a[1:-1]) * K
            return ans
    else:
        return sum(n // 2 for n in a) * K
    
print(solve())

Fixed submission:
from itertools import groupby

def solve():
    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupby(S)]
    
    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            return a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1)
            ans += sum(n // 2 for n in a[1:-1]) * K
            return ans
    else:
        return sum(n // 2 for n in a) * K
    
print(solve())

Buggy python submission (verdict: Runtime Error):
def solve():
    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupgy(S)]
    
    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            return a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1)
            ans += sum(n // 2 for n in a[1:-1]) * K
            return ans
    else:
        return sum(n // 2 for n in a) * K
    
print(solve())

Fixed submission:
from itertools import groupby

def solve():
    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupby(S)]
    
    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            return a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1)
            ans += sum(n // 2 for n in a[1:-1]) * K
            return ans
    else:
        return sum(n // 2 for n in a) * K
    
print(solve())
Buggy python submission (verdict: Runtime Error):
N = int(intput())

print(round(N / 2) / N)

Fixed submission:
N = int(input())

if N % 2 == 0:
  print(1 / 2)
else:
  print((N // 2 + 1) / N)
Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    
    for _ in range(M):
        A.sort()
        A[N-1] = A[N-1] // 2
        if A[N-1] < A[N-2]:
            A[N-1], A[N-2] = A[N-2], A[N-1]
    
    return sum(A)

print(solve())

Fixed submission:
import heapq

def solve():
    N, M = map(int, input().split())
    A = list(map(lambda x: int(x) * -1, input().split()))
    
    heapq.heapify(A)
    
    for _ in range(M):
      t = heapq.heappop(A)
      heapq.heappush(A, -1*(-t//2))
    
    return -sum(A)

print(solve())
Buggy python submission (verdict: Runtime Error):
m = 0
t = 0
pre = H[0]
for hi in H[1:]:
    if pre > hi:
        t += 1
    else:
        m = max(m, t)
        t = 0
    pre = hi
    
m = max(m, t)
if N == 1:
    print(1)
else:
    print(m)

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

m = 0
t = 0

pre = H[0]
for hi in H[1:]:
    if pre >= hi:
        t += 1
    else:
        m = max(m, t)
        t = 0
    pre = hi

print(max(m, t))
Buggy python submission (verdict: Runtime Error):
S = input()
ans, prev, cur = 0, "", ""
for s in S:
    cur += 
    if cur != prev:
        ans += 1
        prev, cur = cur, ""
print(ans)

Fixed submission:
S = input()
ans, prev, cur = 0, "", ""
for s in S:
    cur += s
    if cur != prev:
        ans += 1
        prev, cur = cur, ""
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
H = map(int, input().split())
 
f = True
 
for i in range(N - 1):
  if H[i + 1] - H[i] > 1:
    f = False
    break
    
if f:
  print('Yes')
else:
  print('No')

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

cur = H[0]

f = True
for hi in H[1:]:
  if cur <= hi:
    cur = hi
  elif cur <= hi + 1:
    cur = hi + 1
  else:
    f = False

if f:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
N = int(input())
H = map(int, input().split())

f = True

for i in range(N - 1):
  if H[i] - H[i + 1] > 1:
    f = False
    break
    
if f:
  print('Yes')
else:
  print('No')
    

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

cur = H[0]

f = True
for hi in H[1:]:
  if cur <= hi:
    cur = hi
  elif cur <= hi + 1:
    cur = hi + 1
  else:
    f = False

if f:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
, B = map(int, input().split())
     
if (A + B) % 2 == 0:
  print((A + B) / 2)
else:
  print("IMPOSSIBLE")

Fixed submission:
A, B = map(int, input().split())
     
if (A + B) % 2 == 0:
  print((A + B) // 2)
else:
  print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())

flag = True
for k in range(max(A, B)):
  if abs(A - k) == abs(B - k):
    print(k)
    flag = False

if flag:
  print("IMPOSSIBLE")

Fixed submission:
A, B = map(int, input().split())
     
if (A + B) % 2 == 0:
  print((A + B) // 2)
else:
  print("IMPOSSIBLE")

Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())

for k in range(max(A, B)):
  if abs(A - k) == abs(B - k):
    print(k)
    return
    
print("IMPOSSIBLE")

Fixed submission:
A, B = map(int, input().split())
     
if (A + B) % 2 == 0:
  print((A + B) // 2)
else:
  print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
import numpy as np

N, D = map(int, input().split())

X = []

for i in range(N):
    X.append([int(i) for i in list(input().split())])

res = 0
X = np.array(X)
for i in range(N):
    if i == j:
        continue
    for j in range(i + 1, N):
        if np.linalg.norm(X[i] - X[j]).is_integer():
            res += 1

print(res)

Fixed submission:
import numpy as np

N, D = map(int, input().split())

X = []

for i in range(N):
    X.append([int(i) for i in list(input().split())])

res = 0
X = np.array(X)
for i in range(N):
    for j in range(i + 1, N):
        if np.linalg.norm(X[i] - X[j]).is_integer():
            res += 1

print(res)

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

N, D = map(int, input().split())

X = []

for i in range(N):
    X.append([int(i) for i in list(input().split())])

res = 0
X = np.array(X)
for i in range(N):
    if i == j:
        continue
    for j in range(i + 1, N):
        if np.linalg.norm(X[i] - X[j]).is_integer():
            res += 1

print(res)

Fixed submission:
import numpy as np

N, D = map(int, input().split())

X = []

for i in range(N):
    X.append([int(i) for i in list(input().split())])

res = 0
X = np.array(X)
for i in range(N):
    for j in range(i + 1, N):
        if np.linalg.norm(X[i] - X[j]).is_integer():
            res += 1

print(res)
Buggy python submission (verdict: Runtime Error):
L, R = map(int, input().split())

res = 1000000007

if R - L + 1 > 2019:
    print(0)
else:
    amari = [i % 2019 for i in range(L, R + 1)]
    l = len(amari)
    for i in range(l + 1):
        a = amari[i]
        for j in range(i + 1, l + 1):
            b = amari[j]
            res = min(res, a * b % 2019)

    print(res)

Fixed submission:
L, R = map(int, input().split())

res = 1000000007

if R - L + 1 > 2019:
    print(0)
else:
    amari = [i % 2019 for i in range(L, R + 1)]
    l = len(amari)
    for i in range(l):
        a = amari[i]
        for j in range(i + 1, l):
            b = amari[j]
            res = min(res, a * b % 2019)

    print(res)

Buggy python submission (verdict: Runtime Error):
L, R = map(int, input().split())

res = 1000000007

amari = [i % 2019 for i in range(L, R + 1)]
l = len(amari)

if R - L + 1 > 2019:
    print(0)
else:
    for i in range(l + 1):
        a = amari[i]
        for j in range(i + 1, l + 1):
            b = amari[j]
            res = min(res, a * b % 2019)

    print(res)

Fixed submission:
L, R = map(int, input().split())

res = 1000000007

if R - L + 1 > 2019:
    print(0)
else:
    amari = [i % 2019 for i in range(L, R + 1)]
    l = len(amari)
    for i in range(l):
        a = amari[i]
        for j in range(i + 1, l):
            b = amari[j]
            res = min(res, a * b % 2019)

    print(res)

Buggy python submission (verdict: Runtime Error):
L, R = map(int, input().split())

res = 1000000007

if R - L > 2019:
    print(0)
else:
    for i in range(L, R + 1):
    a = i % 2019
    for j in range(i + 1, R + 1):
        b = j % 2019
        res = min(res, a * b % 2019)

print(res)

Fixed submission:
L, R = map(int, input().split())

res = 1000000007

if R - L + 1 > 2019:
    print(0)
else:
    amari = [i % 2019 for i in range(L, R + 1)]
    l = len(amari)
    for i in range(l):
        a = amari[i]
        for j in range(i + 1, l):
            b = amari[j]
            res = min(res, a * b % 2019)

    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())

res = 1000000007

for i in range(L, R + 1):
    a = i % 2019
    for j in range(i + 1, R + 1):
        b = j % 2019
        res = min(res, a * b % 2019)

print(res)

Fixed submission:
L, R = map(int, input().split())

res = 1000000007

if R - L + 1 > 2019:
    print(0)
else:
    amari = [i % 2019 for i in range(L, R + 1)]
    l = len(amari)
    for i in range(l):
        a = amari[i]
        for j in range(i + 1, l):
            b = amari[j]
            res = min(res, a * b % 2019)

    print(res)
Buggy python submission (verdict: Runtime Error):
    A[max_idx] -= b


Fixed submission:
input()
a=[int(x) for x in input().split()]
b=sum(a)-2*sum(a[1::2])
ans = [b]
for x in a:
    b = x*2-b
    ans.append(b)
print(*ans[:-1])
Buggy python submission (verdict: Runtime Error):
import math

def lcm(x, y):
    return int((x * y) / math.gcd(x, y))

A, B, C, D = map(int, input().split())

a = int((A - 1) / C)
b = int(B / C)

c = int((A - 1) / D)
d = int(B / D)

l = lcm(C, D)

e = int((A - 1) / l)
f = int(B / l)

res = (B - A + 1) - ((b - a) + (d - c)) + (f - e)

print(res)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

A, B, C, D = map(int, input().split())

a = (A - 1) // C
b = B // C

c = (A - 1) // D
d = B // D

l = lcm(C, D)

e = (A - 1) // l
f = B // l
    
res = (B - A + 1) - ((b - a) + (d - c) - (f - e))

print(res)

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

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A, B, C, D = map(int, input().split())

a = (A - 1) // C
b = B // C

c = (A - 1) // D
d = B // D

l = lcm(C, D)

e = (A - 1) // l
f = B // l

res = (B - A + 1) - ((b - a) + (d - c)) + (f - e)

print(res)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

A, B, C, D = map(int, input().split())

a = (A - 1) // C
b = B // C

c = (A - 1) // D
d = B // D

l = lcm(C, D)

e = (A - 1) // l
f = B // l
    
res = (B - A + 1) - ((b - a) + (d - c) - (f - e))

print(res)
Buggy python submission (verdict: Runtime Error):
condition = (N - 1) * (N - 2) // 2 - K
if condition < 0:
    print(-1)

M = 0
for i in range(2, N+1):
    M += 1
    print(1, i)

for i in range(3, 3 + N - 1 - K):
    M += 1
    print(2, i)

Fixed submission:
N, K = map(int, input().split())

con= (N - 1) * (N - 2) // 2 - K
if con < 0:
    print(-1)
else:
    M = N - 1 + con
    print(M)
    for i in range(2, N+1):
        print(1, i)
    cnt = 0
    for i in range(2, N):
        for j in range(i + 1, N + 1):
            cnt += 1
            if cnt > con:
                break
            print(i, j)
        if cnt > con:
            break