Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
x = [int(i) for i in input().split()]
a = []
a2 = []
for i in x:
    if i < 0:
        a2.append(2 * abs(i))
    else:
        a.append(i)

if len(a2) == 0:
    print(a[K-1])
    exit()
a2 = sorted(a2)
c1 = float('inf')

for i, v in enumerate(a):
    if K - i > len(a2):
        continue
    c1 = min(c1, v + a2[K - i])

b = []
b2 = []
for i in x:
    if i > 0:
        b2.append(2 * abs(i))
    else:
        b.append(-i)
b = sorted(b)

if len(b2) == 0:
    print(b[K-1])
    exit()

c2 = float('inf')
for i, v in enumerate(b):
    if K - i > len(b2):
        continue
    c2 = min(c2, v + b2[K - i])

print(min(c1,c2))

Fixed submission:
N, K = map(int, input().split())
x = [int(i) for i in input().split()]
ans = float('inf')
for i in range(N-K+1):
    l = x[i]
    r = x[i+K-1]
    a = abs(l) + abs(r - l)
    b = abs(r) + abs(r - l)
    ans = min(a,b,ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
x = [int(i) for i in input().split()]
a = []
a2 = []
for i in x:
    if i < 0:
        a2.append(2 * abs(i))
    else:
        a.append(i)

if len(a2) == 0:
    print(a[K-1])
    exit()
a2 = sorted(a2)
c1 = float('inf')

for i, v in enumerate(a):
    i = i + 1
    c1 = min(c1, v + a2[K - i - 1])

print(c1)

Fixed submission:
N, K = map(int, input().split())
x = [int(i) for i in input().split()]
ans = float('inf')
for i in range(N-K+1):
    l = x[i]
    r = x[i+K-1]
    a = abs(l) + abs(r - l)
    b = abs(r) + abs(r - l)
    ans = min(a,b,ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
x = [int(i) for i in input().split()]
a = []
a2 = []
for i in x:
    if i < 0:
        a2.append(2 * abs(i))
    else:
        a.append(i)

if len(a2) == 0:
    print(a[K-1])
    exit()
a2 = sorted(a2)
c1 = float('inf')

for i, v in enumerate(a):
    i = i + 1
    c1 = min(c1, v + a2[K - i - 1])

b = []
b2 = []
for i in x:
    if i > 0:
        b2.append(2 * abs(i))
    else:
        b.append(-i)

if len(b2) == 0:
    print(b[K-1])
    exit()
b = sorted(b)
c2 = float('inf')
for i, v in enumerate(b):
    i = i + 1
    c2 = min(c2, v + b2[K - i - 1])

print(min(c1,c2))

Fixed submission:
N, K = map(int, input().split())
x = [int(i) for i in input().split()]
ans = float('inf')
for i in range(N-K+1):
    l = x[i]
    r = x[i+K-1]
    a = abs(l) + abs(r - l)
    b = abs(r) + abs(r - l)
    ans = min(a,b,ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
????C?????B??????A???????

Fixed submission:
S=input()
s=len(S)
dp=[[0,0,0,0]for i in range(s+1)]
dp[s][3]=1
for i in range(s-1,-1,-1):
    for j in[3,2,1,0]:
        dp[i][j]=(3 if S[i]=='?'else 1)*dp[i+1][j]
        if j!=3:dp[i][j]+=(1 if S[i]=='?'or S[i]=='ABC'[j]else 0)*dp[i+1][j+1]
        dp[i][j]%=(10**9+7)
print(dp[0][0])

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
s=len(S)
dp=[[0,0,0,0]for i in range(s+1)]
dp[s][3]=1
for i in range(s-1,-1,-1):
    for j in[3,2,1,0]:
        dp[i][j]=(3 if S[i]=='?'else 1)*dp[i+1][j]
        if j!=3:dp[i][j]+=(1 if S[i]=='?'or S[i]=='ABC'[j]else 0)*dp[i+1][j+1]
print(dp[0][0]%(10**9+7))

Fixed submission:
S=input()
s=len(S)
dp=[[0,0,0,0]for i in range(s+1)]
dp[s][3]=1
for i in range(s-1,-1,-1):
    for j in[3,2,1,0]:
        dp[i][j]=(3 if S[i]=='?'else 1)*dp[i+1][j]
        if j!=3:dp[i][j]+=(1 if S[i]=='?'or S[i]=='ABC'[j]else 0)*dp[i+1][j+1]
        dp[i][j]%=(10**9+7)
print(dp[0][0])

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
s=len(S)
dp=[[0,0,0,0]for i in range(s+1)]
dp[s][3]=1
for i in range(s-1,-1,-1):
    for j in[3,2,1,0]:
        dp[i][j]=(3 if S[i]=='?'else 1)*dp[i+1][j]
        if j!=3:dp[i][j]+=(1 if S[i]=='?'or S[i]=='ABC'[j]else 0)*dp[i+1][j+1]
print(dp[0][0]%(10**9+7))

Fixed submission:
S=input()
s=len(S)
dp=[[0,0,0,0]for i in range(s+1)]
dp[s][3]=1
for i in range(s-1,-1,-1):
    for j in[3,2,1,0]:
        dp[i][j]=(3 if S[i]=='?'else 1)*dp[i+1][j]
        if j!=3:dp[i][j]+=(1 if S[i]=='?'or S[i]=='ABC'[j]else 0)*dp[i+1][j+1]
        dp[i][j]%=(10**9+7)
print(dp[0][0])
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [int(i) for i in input().split()]
a = list(filter(lambda x: x%2==0, a))
if len(a) == 0:
    print(0)
else:
    a = sorted(a, reverse=True)
    ans = 0
    while len(a):
        a[0] /= 2
        for i in range(1,len(a)):
            a[i] *= 3
        a = list(filter(lambda x: x%2==0, a))
        a = sorted(a, reverse=True)
        ans += 1
    print(ans)

Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]
ans = 0
for i in a:
    while i % 2 == 0:
        i /= 2
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import log, floor
x = int(input())
ans = 1
for b in range(2, x):
    p = floor(log(x,b))
    if p <= 1: continue
    tmp = b**p
    tmp2 = b**(p+1)
    if tmp2 <= x:
        tmp = tmp2
    ans = max(ans, tmp)

print(ans)


Fixed submission:
s = input()
k = int(input())

l = []
for i in range(1, min(len(s)+1,k+1)):
    for j in range(0,len(s)):
        t = s[j:j+i]
        if len(t) != i:break
        if t in l: continue
        l.append(t)
l = sorted(l)
print(l[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial
n = int(input())
a = [int(i) for i in input().split()]
sa = sorted(a,reverse=True)
def comb(n, r):
    b = 1
    for i in range(r):
        b *= n - i
    return b//factorial(r)

sb = sa[1:]
l = len(sb)
n = sa[0]
a1 = sb[l//2 - 1]
a2 = sb[l//2]
k = comb(n,a1)
j = comb(n,a2)
if k > j:
    print(n, a1)
else:
    print(n, a2)

Fixed submission:
from math import factorial
n = int(input())
a = [int(i) for i in input().split()]
sa = sorted(a,reverse=True)
m = sa[0]
sb = sa[1:]
k = [i if m - i > i else m - i for i in sb]
i = k.index(max(k))
print(m, sb[i])
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int, input().split())
print(min(a,b) + min(c,d))

Fixed submission:
a,b,c,d=[int(input()) for i in range(4)]

print(min(a,b) + min(c,d))
Buggy python submission (verdict: Time Limit Exceeded):
h,w,d = map(int,input().split())
n2c = {i:None for i in range(1, h*w+1)}
for i in range(h):
    i += 1
    for j,v in enumerate(input().split()):
        j = j + 1
        v = int(v)
        n2c[v] = (i,j)


def c(x1,y1,x2,y2):
    return abs(x1-x2) + abs(y1-y2)

q = int(input())
for i in range(q):
    cost = 0
    l,r = map(int, input().split())
    lt = range(l,r+1,d)
    l = list(map(lambda x:n2c[x], lt))
    for i in range(len(l)-1):
        x1,y1 = l[i]
        x2,y2 = l[i+1]
        cost += c(x1,y1,x2,y2)
    print(cost) 

Fixed submission:
h,w,d = map(int,input().split())
n2c = {i:None for i in range(1, h*w+1)}
D = [0] * (h * w + 1)
for i in range(h):
    i += 1
    for j,v in enumerate(input().split()):
        j = j + 1
        v = int(v)
        n2c[v] = (i,j)

for i in range(d+1, h*w+1):
    D[i] = D[i - d] + abs(n2c[i][0] - n2c[i-d][0]) + abs(n2c[i][1] - n2c[i-d][1])

def c(x1,y1,x2,y2):
    return abs(x1-x2) + abs(y1-y2)

q = int(input())
for i in range(q):
    l,r = map(int, input().split())
    print(D[r] - D[l])

Buggy python submission (verdict: Time Limit Exceeded):
h,w,d = map(int,input().split())
n2c = {i:None for i in range(1, h*w+1)}
for i in range(h):
    i += 1
    for j,v in enumerate(input().split()):
        j = j + 1
        v = int(v)
        n2c[v] = (i,j)


def c(x1,y1,x2,y2):
    return abs(x1-x2) + abs(y1-y2)

q = int(input())
for i in range(q):
    cost = 0
    l,r = map(int, input().split())
    lt = range(l,r+1,d)
    l = list(map(lambda x:n2c[x], lt))
    for i in range(len(l)-1):
        x1,y1 = l[i]
        x2,y2 = l[i+1]
        cost += c(x1,y1,x2,y2)
    print(cost) 


Fixed submission:
h,w,d = map(int,input().split())
n2c = {i:None for i in range(1, h*w+1)}
D = [0] * (h * w + 1)
for i in range(h):
    i += 1
    for j,v in enumerate(input().split()):
        j = j + 1
        v = int(v)
        n2c[v] = (i,j)

for i in range(d+1, h*w+1):
    D[i] = D[i - d] + abs(n2c[i][0] - n2c[i-d][0]) + abs(n2c[i][1] - n2c[i-d][1])

def c(x1,y1,x2,y2):
    return abs(x1-x2) + abs(y1-y2)

q = int(input())
for i in range(q):
    l,r = map(int, input().split())
    print(D[r] - D[l])
Buggy python submission (verdict: Runtime Error):
from math import gcd
X, Y = map(int, input().split())
if X % Y == 0:
    print(-1)
else:
    print(X)

Fixed submission:
X, Y = map(int, input().split())
if X % Y == 0:
    print(-1)
else:
    print(X)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
a = [int(i) for i in input().split()]
m = sum([i for i in a]) - k + 2
l = []
for n in range(max(a), m+1):
    c = n
    q = 0
    for i in a:
        c -= c % i
        q += c // i
    if c == 2: l.append(n)
    if q > m + 1: break
    if c > 2: break
if len(l) == 0: print(-1)
else: print(l[0], l[-1])

Fixed submission:
from math import floor, ceil
k = int(input())
a = [int(i) for i in input().split()]
l,r = 2,2
for ai in a[::-1]:
    xi = ceil(l/ai)
    yi = floor(r/ai)
    if xi > yi:
        print(-1)
        exit()
    l = xi * ai
    r = yi * ai + ai - 1
print(l, r)

Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
a = [int(i) for i in input().split()]
m = sum([i-1 for i in a])
l = []
for n in range(max(a), m+3):
    c = n
    for i in a:
        c -= c % i
    if c == 2: l.append(n)
    if c > 2: break
if len(l) == 0: print(-1)
else: print(l[0], l[-1])

Fixed submission:
from math import floor, ceil
k = int(input())
a = [int(i) for i in input().split()]
l,r = 2,2
for ai in a[::-1]:
    xi = ceil(l/ai)
    yi = floor(r/ai)
    if xi > yi:
        print(-1)
        exit()
    l = xi * ai
    r = yi * ai + ai - 1
print(l, r)
Buggy python submission (verdict: Runtime Error):
from math import ceil
n, h = map(int, input().split())
a = []
b = []
for i in range(n):
    ai, bi = map(int,input().split())
    a.append(ai)
    b.append(bi)
ans = 0
maxa = max(a)
b2 = sorted([i for i in b if i > maxa],reverse=True)
for k in b2:
    if h > 0:
        ans += 1
        h -= k
if h > 0: ans += ceil(h/maxa)
print(ans)

Fixed submission:
n,y = map(int, input().split())
for i in range(min(n+1, y//10000+1)):
    for j in range(min(n-i+1, y//1000+1)):
        c = n-i-j
        if 10000 * i + 5000 * j + 1000 * c == y:
            print(i,j,c)
            exit()
print(-1,-1,-1)

Buggy python submission (verdict: Runtime Error):
n,y = map(int, input().split())
for i in range(min(n+1,y//10000+1)):
    for j in range(min(n-i+1,y/1000+1)):
        c = n-i-j
        if c >= 0 and 10000 * i + 5000 * j + 1000 * c == y:
            print(i,j,c)
            exit()
print(-1,-1,-1)

Fixed submission:
n,y = map(int, input().split())
for i in range(min(n+1, y//10000+1)):
    for j in range(min(n-i+1, y//1000+1)):
        c = n-i-j
        if 10000 * i + 5000 * j + 1000 * c == y:
            print(i,j,c)
            exit()
print(-1,-1,-1)

Buggy python submission (verdict: Time Limit Exceeded):
n,y = map(int, input().split())
y /= 1000
for i in range(int(y//10+1)):
    for j in range(int((y-i*10)//1+1)):
        c = n-i-j
        if c >= 0 and 10 * i + 5 * j + 1 * c == y:
            print(i,j,c)
            exit()
print(-1,-1,-1)

Fixed submission:
n,y = map(int, input().split())
for i in range(min(n+1, y//10000+1)):
    for j in range(min(n-i+1, y//1000+1)):
        c = n-i-j
        if 10000 * i + 5000 * j + 1000 * c == y:
            print(i,j,c)
            exit()
print(-1,-1,-1)
Buggy python submission (verdict: Runtime Error):
N, Z, W = map(int, input().split())
a = [int(i) for i in input().split()]
print(max(abs(a[-1] - W), abs(a[-2] - a[-1])))

Fixed submission:
N, Z, W = map(int, input().split())
a = [int(i) for i in input().split()]
if len(a) > 1:
    print(max(abs(a[-1] - W), abs(a[-2] - a[-1])))
else:
    print(abs(a[-1] - W))
Buggy python submission (verdict: Runtime Error):
N = int(input())
mn = 10**9 + 1
mx = 0
mnj = None
mxj = None
for i in range(N):
    Ai,Bi = map(int, input().split())
    if mn > Bi:
        mn = Bi
        mnj = Ai
    if mx < Bi:
        mx = Bi
        mxj = Ai
print(mxj + mnj - mxj + mn)

Fixed submission:
N = int(input())
mn = 10**9 + 1
mx = -1
mnj = 10**9 + 1
mxj = -1
for i in range(N):
    Ai,Bi = map(int, input().split())
    if mn > Bi:
        mn = Bi
        mnj = Ai
    if mx < Bi:
        mx = Bi
        mxj = Ai
print(mxj + mnj - mxj + mn)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
for a in range(1, 3501):
    for b in range(1, 3501):
        c2 = 4 * a * b - b * N - a * N
        if c2 <= 0:continue
        c1 = a * b * N
        if c1/c2 == c1//c2:
            print(a,b,c1//c2)
            exit()

Fixed submission:
N = int(input())
for a in range(1, 3501):
    for b in range(a+1, 3501):
        c2 = 4 * a * b - b * N - a * N
        if c2 <= 0:continue
        c1 = a * b * N
        if c1/c2 == c1//c2:
            print(a,b,c1//c2)
            exit()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
for a in range(1, 3501):
    for b in range(1, 3501):
        c1 = a * b * N
        c2 = 4 * a * b - b * N - a * N
        if c2 > 0 and c1/c2 == c1//2:
            print(a,b,c1//c2)
            exit()

Fixed submission:
N = int(input())
for a in range(1, 3501):
    for b in range(a+1, 3501):
        c2 = 4 * a * b - b * N - a * N
        if c2 <= 0:continue
        c1 = a * b * N
        if c1/c2 == c1//c2:
            print(a,b,c1//c2)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, D, E, F = map(int, input().split())
ans1 = 100 * A
ans2 = 0
n = 0
for x in range(100, F+1, 100):
    for y in range(F+1):
        if x + y == 0:
            continue        
        if x + y > F:
            continue
        if (x / 100) * E < y:
            continue

        s = []
        for i in range((y//C)+1):
            for j in range((y//D)+1):
                if y == i * C + j * D:
                    s.append((i, j))
                    break
            if len(s):
                break
        if len(s) == 0:
            continue

        w = []
        for i in range((x//(100*A))+1):
            for j in range((x//(100*B))+1):
                if x == 100 * A * i + 100 * B * j:
                    w.append((i, j))
                    break
            if len(w):
                break

        if len(w) == 0:
            continue

        if n < (y/(x+y)):
            n = y/(x+y)
            ans1 = x + y
            ans2 = y

print(ans1, ans2)


Fixed submission:
A, B, C, D, E, F = map(int, input().split())
ans1 = 100 * A
ans2 = 0
n = 0
for x in range(100, F+1, 100):
    for y in range(F+1):
        if x + y == 0:
            continue        
        if x + y > F:
            continue
        if (x / 100) * E < y:
            continue

        s = []
        for i in range((y//C)+1):
            for j in range((y//D)+1):
                if y == i * C + j * D:
                    s.append((i, j))
                    break
            if len(s):
                break
        if len(s) == 0:
            continue

        w = []
        for i in range((x//(100*A))+1):
            for j in range((x//(100*B))+1):
                if x == 100 * A * i + 100 * B * j:
                    w.append((i, j))
                    break
            if len(w):
                break

        if len(w) == 0:
            continue

        if n < (y/(x+y)):
            n = y/(x+y)
            ans1 = x + y
            ans2 = y

print(ans1, ans2)
Buggy python submission (verdict: Runtime Error):
N = input()
if N.index('9') != -1:
  print('Yes')
else:
  print('No')

Fixed submission:
N = input()
try:
  N.index('9')
  print('Yes')
except:
  print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
g = {i: []for i in range(1, N+1)}    

cache = {}
def dfs(g,start,end):
    stack = [(start, [start], 0)]
    while stack:
        (v, path, length) = stack.pop()
        for next,l in g[v]:
            if next in path: continue
            if next == end:
                return length + l
            else:
                stack.append((next, path + [next], length + l))

for i in range(N-1):
    a, b, c = map(int,input().split())
    g[a].append((b,c))
    g[b].append((a,c))
Q, K = map(int,input().split())

for v in range(1,N+1):
    cache[v] = dfs(g,v,K)

for q in range(Q):
    x, y = map(int,input().split())
    print(cache[x] + cache[y])

Fixed submission:
N = input()
if N == N[::-1]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
A,B,C,D = [int(i) for i in input().split()]
print(min(0,min(B,D) - max(A,C))

Fixed submission:
A,B,C,D = [int(i) for i in input().split()]
print(max(0,min(B,D) - max(A,C)))
Buggy python submission (verdict: Runtime Error):

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

print ((n-1)*(m-1)

Fixed submission:
n,m = list(map(int, input().split()))
 
print ((n-1)*(m-1))
Buggy python submission (verdict: Runtime Error):
K=int(input())
N=min(50,K)
a = list(range(N))

m = int(K / len(a))
b = K%len(a)
a=list(map(lambda x: x + m, a))
for i in range(b):
    a[i] += N
    for j in range(N):
        if j == i:
            continue
        a[j] -= 1
print(N)
print(' '.join(list(map(str,a))))


Fixed submission:
K=int(input())
N=50
a = list(range(N))
m = K // N
b = K % N
a=list(map(lambda x: x + m, a))
for i in range(b):
    a[i] += N
    for j in range(N):
        if j != i:
            a[j] -= 1
print(N)
print(' '.join(map(str,a)))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N, M=map(int, input().split())
m=[]
ans = 300

for i in range(N):
    m.append(list(map(int,input().split())))


def search(ln):
    #l = []
    cnt = Counter()
    for r in m:
        for col in r:
            if col in ln:
                cnt[col] += 1
                break
    s,c = cnt.most_common(1)[0]
    global ans
    if c < ans:
        ans = c
    ln.remove(s)
    if len(ln) == 0:
        return 
    search(ln)
search(list(range(1, M+1)))
print (ans)

Fixed submission:
from collections import Counter

N, M=map(int, input().split())
m=[]
ans = 300

for i in range(N):
    m.append(list(map(int,input().split())))

def search(ln):
    #l = []
    cnt = Counter()
    for r in m:
        cnt[r[0]] += 1
    s,c = cnt.most_common(1)[0]
    global ans
    ans = min(ans, c)
    ln.remove(s)
    for r in m:
        r.remove(s)
    if len(ln) == 0:
        return 
    search(ln)
search(list(range(1, M+1)))
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N, M=map(int, input().split())
m=[]
ans = 300

for i in range(N):
    m.append(list(map(int,input().split())))


def search(ln):
    l = []
    for r in m:
        for col in r:
            if col in ln:
                l.append(col)
                break
    s,c = Counter(l).most_common(1)[0]
    global ans
    if c < ans:
        ans = c
    ln.remove(s)
    if len(ln) == 0:
        return 
    search(ln)
search(list(range(1, M+1)))
print (ans)

Fixed submission:
from collections import Counter

N, M=map(int, input().split())
m=[]
ans = 300

for i in range(N):
    m.append(list(map(int,input().split())))

def search(ln):
    #l = []
    cnt = Counter()
    for r in m:
        cnt[r[0]] += 1
    s,c = cnt.most_common(1)[0]
    global ans
    ans = min(ans, c)
    ln.remove(s)
    for r in m:
        r.remove(s)
    if len(ln) == 0:
        return 
    search(ln)
search(list(range(1, M+1)))
print (ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
an=list(map(int,input().split()))
s = sum(an)
h = s/2
f=int(N/2)
x = sum(an[:f])
y = s - x
z=abs(x-y)
for i in range(f):
    if f+1 >= N:
        break
    t1=x + an[f+1]
    t2=y - an[f+1]
    t3=x - an[f-1]
    t4=y + an[f-1]
    print(t1,t2)
    k1=abs(t1-t2)
    k2=abs(t3-t4)
    p=0
    k = min(k1,k2)
    if k1 > k2:
        p = -1
    else:
        p = 1
    if z > k:
        f = f + p
        z = k
    else:
        break
print(z)

Fixed submission:
A,B=map(int,input().split())
if A % 3 == 0 or B % 3 == 0 or (A+B) % 3 == 0:
    print('Possible')
else:
    print('Impossible')
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
an=list(map(int,input().split()))
l=[]
for i in range(1,N):
    x=sum(an[:i])
    y=sum(an[i:])
    l.append(abs(x-y))
print(min(l))


Fixed submission:
N=int(input())
an=list(map(int,input().split()))
s=sum(an)
b = an[0]

l=[]
a = abs(s-2*b)
for i in range(1,N-1):
    b = b + an[i]
    a=min(a,abs(s-2*b))
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
an=list(map(int,input().split()))
s=sum(an)
l=[]
for i in range(1,N):
    b = sum(an[:i])
    l.append(abs(s-2*b))
print(min(l))

Fixed submission:
N=int(input())
an=list(map(int,input().split()))
s=sum(an)
b = an[0]

l=[]
a = abs(s-2*b)
for i in range(1,N-1):
    b = b + an[i]
    a=min(a,abs(s-2*b))
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
an=list(map(int,input().split()))
l=[]
for i in range(1,N):
    x=sum(an[:i])
    y=sum(an[i:])
    l.append(abs(x-y))
print(min(l))

Fixed submission:
N=int(input())
an=list(map(int,input().split()))
s=sum(an)
b = an[0]

l=[]
a = abs(s-2*b)
for i in range(1,N-1):
    b = b + an[i]
    a=min(a,abs(s-2*b))
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
b = []
for i in range(n):
    if i  % 2 == 0: b.append(a[i])
    else: b = [a[i]] + b
if i % 2 == 0: b.reverse()
print(*b)

Fixed submission:
from collections import deque
n = int(input())
a = [int(i) for i in input().split()]
b = deque()
f = True
for i in range(n):
    if f: b.append(a[i])
    else: b.appendleft(a[i])
    f = not f
if i % 2 == 0: b.reverse()
print(*b)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
b = []
for i in range(n):
    if i  % 2 == 0: b.append(a[i])
    else: b = [a[i]] + b
if i % 2 == 0: b.reverse()
print(*b)

Fixed submission:
from collections import deque
n = int(input())
a = [int(i) for i in input().split()]
b = deque()
f = True
for i in range(n):
    if f: b.append(a[i])
    else: b.appendleft(a[i])
    f = not f
if i % 2 == 0: b.reverse()
print(*b)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
b = []
for i in range(n):
    b.append(a[i])
    b.reverse()
print(*b)

Fixed submission:
from collections import deque
n = int(input())
a = [int(i) for i in input().split()]
b = deque()
f = True
for i in range(n):
    if f: b.append(a[i])
    else: b.appendleft(a[i])
    f = not f
if i % 2 == 0: b.reverse()
print(*b)
Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil
from numpy import array
n, a, b = map(int, input().split())
h = array(sorted([int(input()) for i in range(n)]))

def enough(T):
    global h
    c = 0
    h2 = h - b * T
    for i, f in enumerate(h2 > 0):
        if not f:continue
        c += ceil(h2[i]/(a - b))
    if c <= T: return 1
    else: return 0

def bisearch():
    lo = 0
    hi = ceil(max(h)/b)
    while lo < hi:
        mid = (lo + hi) // 2
        midval = enough(mid)
        if midval < 1: lo = mid + 1
        else: hi = mid
    return lo

print(bisearch())

Fixed submission:
from math import ceil
import numpy as np
n, a, b = map(int, input().split())
h = np.array(sorted([int(input()) for i in range(n)]))

def enough(T):
    global h
    h2 = h - b * T
    c = sum(np.ceil(h2[h2 > 0]/(a - b)))
    if c <= T: return 1
    else: return 0

def bisearch():
    lo = 0
    hi = ceil(max(h)/b)
    while lo < hi:
        mid = (lo + hi) // 2
        midval = enough(mid)
        if midval < 1: lo = mid + 1
        else: hi = mid
    return lo

print(bisearch())
Buggy python submission (verdict: Runtime Error):
1 1
z

Fixed submission:
H, W = map(int, input().split())
p = []
for i in range(H):
    p.append(input())
print('#' * (W+2))
for i in p:
    print('#'+i+'#')
print('#' * (W+2))