Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
card = [int(i) for i in input().split()]
s = sum(card)
min_sum = [abs(s - 2*sum(card[0:i])) for i in range(1, N)]
print(min(min_sum))

Fixed submission:
N = int(input())
card = list(map(int, input().split()))
s = sum(card)
p_sum = 0
min_sum = []
for i in card[:-1]:
    p_sum += i
    min_sum.append(abs(s- 2 * p_sum))
print(min(min_sum))

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

min_sum =  abs(sum(card[1:N])-card[0])
for i in range(2,N):
    if abs(sum(card[0:i])-sum(card[i:N])) < min_sum:
        min_sum = abs(sum(card[0:i])-sum(card[i:N]))

print(min_sum)

Fixed submission:
N = int(input())
card = list(map(int, input().split()))
s = sum(card)
p_sum = 0
min_sum = []
for i in card[:-1]:
    p_sum += i
    min_sum.append(abs(s- 2 * p_sum))
print(min(min_sum))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
power = 1
for i in range(1,N+1):
    power *= i
print(power % 1000000007)


Fixed submission:
N = int(input())
power = 1
for i in range(1,N+1):
    power = (power * i) % 1000000007
print(power)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
card = [int(i) for i in input().split()]
single = [i for i in card if card.count(i) == 1]
plural = sorted([i for i in card if i not in single])
while len(plural) > 0:
    min_A = plural.pop(0)
    max_A = plural.pop(-1)
    if plural.count(min_A) == 1:
        single.append(plural.pop(0))
    if plural.count(max_A) == 1:
        single.append(plural.pop(-1))

print(len(single))

Fixed submission:
#解説を確認後
N = int(input())
card = set([int(i) for i in input().split()])

if len(card) % 2 == 1:
    print(len(card))
else:
    print(len(card)-1)
Buggy python submission (verdict: Runtime Error):
a, b, c = input().split()
if a[-1] == b[0] and b[-1] == c[0]:
  print('YES')
 else:
  print('NO')

Fixed submission:
a, b, c = input().split()
if a[-1] == b[0] and b[-1] == c[0]:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
a = int(input())
print((a*800)-(math.floor(a/15)*200))


Fixed submission:
import math
a = int(input())
print((a*800)-(math.floor(a/15)*200))
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())


one = [i for i in range(a, b)]
two = [i for i in range(c, d)]

count = 0
for i in one:
    if i in two:
        count += 1
print(count)

Fixed submission:
n = input()

a = [i for i in n]
b = [i for i in reversed(n)]

if a == b:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
n = int(sys.stdin.readline().strip())
ar = [int(x) for x in sys.stdin.readline().split()]
stop = False

def ok(x, y):
	if x == -1: return True
	return (x*y)%4 == 0

def find(ctr, prev, mask, app):
	global stop
	if ctr == n:
		stop = True
	if stop == True: return
	for i in range(n):
		if mask[i] and ok(prev, ar[i]):
			mask[i] = False
			find(ctr+1, ar[i], mask, app + [ar[i]])
			mask[i] = True

find(0, -1, [True]*n, [])
print "Yes" if stop else "No"

Fixed submission:
import sys
n = int(sys.stdin.readline().strip())
ar = [int(x) for x in sys.stdin.readline().split()]
f4, odd, even = 0, 0, 0
for num in ar:
	if num%4==0:
		f4 +=1
	elif num%2==0:
		even+=1
	else:
		odd+=1
if odd-f4 == 0:
	print "Yes"
elif odd-f4 <= 1 and even == 0:
	print "Yes"
else:
	print "No"
Buggy python submission (verdict: Runtime Error):
sec = input().split(' ')
#sec = ['0','75','25','100']
#sec = ['0','33','66','99']
#print(sec[0],sec[1],sec[2],sec[3])
#開始時間選定
start = max(sec[0],sec[2])
#print('開始:' + start)
#終了時間選定
end = min(sec[1],sec[3])
#print('終了:' + end)
kekka =(int(end) - int(start))
if kekka < 1:
	kekka = 0
	print(kekka)
else:
	print(kekka)

Fixed submission:
kaibun = str(input())
#print(kaibun)
#print(kaibun[::-1])
if kaibun == kaibun[::-1]:
	print('Yes')
else:
	print('No')
Buggy python submission (verdict: Runtime Error):
import numpy as np
import pandas as pd


def main():
    print('vowel' if input() in 'aeiou' else 'consonant')

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    print('vowel' if input() in 'aeiou' else 'consonant')

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    n = int(input())
    a = [0] * n
    indices = {}
    for i in range(n):
        a[i] = int(input())
        indices[a[i]] = i
    b = sorted(a)
    for j in range(n - 1, -1, -1):
        i = indices[b[j]]
        while i + 2 < n and a[i] > a[i + 2]:
            tmp = a[i + 2]
            a[i + 2] = a[i]
            a[i] = tmp
            indices[a[i]] = i
            indices[a[i + 2]] = i + 2
            i += 2
    ans = 0
    for i in range(n - 1):
        if a[i] != b[i]:
            ans += 1
            tmp = a[i + 1]
            a[i + 1] = a[i]
            a[i] = tmp
    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()


Fixed submission:
def solve():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    e = [a[i] for i in range(0, n, 2)]
    a.sort()
    o = set(a[i] for i in range(1, n, 2))
    ans = 0
    for i in range((n + 1) // 2):
        if e[i] in o:
            ans += 1
    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    indices = {}
    for i in range(n):
        indices[a[i]] = i
    b = sorted(a)
    for j in range(n - 1, -1, -1):
        i = indices[b[j]]
        while i + 2 < n and a[i] > a[i + 2]:
            tmp = a[i + 2]
            a[i + 2] = a[i]
            a[i] = tmp
            indices[a[i]] = i
            indices[a[i + 2]] = i + 2
            i += 2
    ans = 0
    for i in range(n - 1):
        if a[i] != b[i]:
            ans += 1
            tmp = a[i + 1]
            a[i + 1] = a[i]
            a[i] = tmp
    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()


Fixed submission:
def solve():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    e = [a[i] for i in range(0, n, 2)]
    a.sort()
    o = set(a[i] for i in range(1, n, 2))
    ans = 0
    for i in range((n + 1) // 2):
        if e[i] in o:
            ans += 1
    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n=input()
if n[0]==n[-1]:
  return 'Yes'
else:
  return 'No'

Fixed submission:
n=input()
if n[0]==n[-1]:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
from math import gcd
from functools import reduce

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

N = int(input())
T = []
for _ in range(N):
    T.append(int(input()))
print(reduce(lcm, T))

Fixed submission:
from fractions import gcd
from functools import reduce

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

N = int(input())
T = []
for _ in range(N):
    T.append(int(input()))
print(reduce(lcm, T))
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())

if A > B:
    print("Alice")
if A == B:
    print("Draw")
if A < B:
    print("Bob")

Fixed submission:
l = input().split()

A = int(l[0])
B = int(l[1])

if A == 1:
    A = 14
if B == 1:
    B = 14
    
if A > B:
    print("Alice")
if A == B:
    print("Draw")
if A < B:
    print("Bob")

Buggy python submission (verdict: Runtime Error):
A = input("")
B = input("")

if A > B:
    print("Alice")
if A == B:
    print("Draw")
if A < B:
    print("Bob")

Fixed submission:
l = input().split()

A = int(l[0])
B = int(l[1])

if A == 1:
    A = 14
if B == 1:
    B = 14
    
if A > B:
    print("Alice")
if A == B:
    print("Draw")
if A < B:
    print("Bob")

Buggy python submission (verdict: Runtime Error):
A = input()
B = input()

if A > B:
    print("Alice")
if A == B:
    print("Draw")
if A < B:
    print("Bob")

Fixed submission:
l = input().split()

A = int(l[0])
B = int(l[1])

if A == 1:
    A = 14
if B == 1:
    B = 14
    
if A > B:
    print("Alice")
if A == B:
    print("Draw")
if A < B:
    print("Bob")
Buggy python submission (verdict: Runtime Error):
N = input()

s = input()

t = input()

temp = 0
flag = True

while(temp < N-1 & flag):
    temps = s[N-temp-1:N-1]
    tempt = t[:temp]
    if(temps==tempt):
        temp += 1
    else:
        flag = False

print(N+N-temp)

Fixed submission:
N = int(input())

s = input()

t = input()

temp = N
flag = True
if s==t:
    print(N)
else:
    while(temp > 0 and flag):
        temps = s[N-temp:N]
        tempt = t[:temp]
        if(temps==tempt):
            flag = False
        else:
            temp -= 1

    print(N+N-temp)
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline()

def main():
    s = list(input())
    n = int(input())
    A = []

    for c in s:
        if (ord('a') - ord(c)) % 26 <= n:
            A.append('a')
            n -= (ord('a') - ord(c)) % 26
        else:
            A.append(c)

    # print(''.join(*A))

    # for itm in A:
    #     print(itm,end = '')

    A[-1] = chr(ord(A[-1]) + n % 26)
    print(''.join(A))
if __name__ == '__main__':
    main()



Fixed submission:
s = input()
n = 4
for itm in range(n):
    print(s[itm],end='')

print("",end= " ")
for i in range(4,len(s)):
    print(s[i],end='')
print()
Buggy python submission (verdict: Runtime Error):
a, b, c = input().split(,)
print(a, b, c)

Fixed submission:
a, b, c = input().split(",")
print(a, b, c)

Buggy python submission (verdict: Runtime Error):
x, y ,z = input().split(,)
print(x, y, z)

Fixed submission:
a, b, c = input().split(",")
print(a, b, c)
Buggy python submission (verdict: Runtime Error):
n=int(input())
m=int(input())
print((n-1) * (m-1))

Fixed submission:
n, m = map(int, input().split())
print((n-1)*(m-1))

Buggy python submission (verdict: Runtime Error):
n, m =int(input())
print(n-1 * m-1)

Fixed submission:
n, m = map(int, input().split())
print((n-1)*(m-1))
Buggy python submission (verdict: Runtime Error):
s=input()
print(s[0] + int(len(s)-2) + s[-1])

Fixed submission:
s=input()

print(s[0] + str(len(s)-2) + s[len(s)-1])
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8-*-
strs = []
n,k = map(int,input().split())
hates = list(input().split())

give = n

while(True):
  stri = str(give)
  for hate in hates:
    if hate in stri:
      give = give + 1
      break
    else:
      print(give)
      exit()

Fixed submission:
# -*- coding: utf-8-*-
a = []
a = list(map(int,input().split()))
if (a[0] + a[1] + a[2] == 17) and (7 in a) and (5 in a):   
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8-*-
strs = []
n,k = map(int,input().split())
hates = list(input().split())

give = n

while(True):
  stri = str(give)
  for hate in hates:
    if hate in stri:
      give = give + 1
      break;
    else:
      print(give)
      exit()


Fixed submission:
# -*- coding: utf-8-*-
a = []
a = list(map(int,input().split()))
if (a[0] + a[1] + a[2] == 17) and (7 in a) and (5 in a):   
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
N = input(int(N))
K = input(int(K))
X = input(int(X))
Y = input(int(Y))
if N>K:
    print(K*X+Y(N-K))
else:
    print(N*X)



Fixed submission:
N = int(input())
K = int(input())
X = int(input())
Y = int(input())
if N>K:
    print(K*X+Y*(N-K))
else:
    print(N*X)
Buggy python submission (verdict: Runtime Error):
n, m=input().split()
print((n-1)*(m-1))

Fixed submission:
n, m=input().split()
print((int(n)-1)*(int(m)-1))

Buggy python submission (verdict: Runtime Error):
n, m=input().split()
print((n-1)*(m-1))

Fixed submission:
n, m=input().split()
print((int(n)-1)*(int(m)-1))
Buggy python submission (verdict: Runtime Error):
S=input()
f=S[0]
l=S[-1]
m=len(S)-2
print(str(f+m+l))

Fixed submission:
S=input()
f=S[0]
l=S[-1]
m=len(S)-2
print(f+str(m)+l)
Buggy python submission (verdict: Runtime Error):
n=input("east_west road:")
print(n)
m=input("north_south road:")
print(m)
block =(int(n)-1) * (int(m)-1)
print(block) 

Fixed submission:
n,m = list(map(int,input().split()))
print((n-1)*(m-1))

Buggy python submission (verdict: Runtime Error):
n=input("east_west road:")
m=input("north_south road:")
block =(int(n)-1) * (int(m)-1)
print(block) 


Fixed submission:
n,m = list(map(int,input().split()))
print((n-1)*(m-1))

Buggy python submission (verdict: Runtime Error):
n = input("east_west road:")
m =input("north_south road:")
block =(int(n)-1) * (int(m)-1)
print(block) 


Fixed submission:
n,m = list(map(int,input().split()))
print((n-1)*(m-1))
Buggy python submission (verdict: Runtime Error):
raw = raw_input().split(" ")
num = int(raw[0]) * 100 + int(raw[1]) * 10 + int(raw[2])
if not (num % 4):
    return 'YES'
else:
    return 'NO'


Fixed submission:

raw = raw_input().split(" ")
num = int(raw[0]) * 100 + int(raw[1]) * 10 + int(raw[2])
if not (num % 4):
    print 'YES'
else:
    print 'NO'

Buggy python submission (verdict: Runtime Error):
raw = raw_input().split(" ")
num = raw[0] * 100 + raw[1] * 10 + raw[2]
if not (num % 4):
  return "Yes"
return "No"

Fixed submission:

raw = raw_input().split(" ")
num = int(raw[0]) * 100 + int(raw[1]) * 10 + int(raw[2])
if not (num % 4):
    print 'YES'
else:
    print 'NO'

Buggy python submission (verdict: Runtime Error):
raw = raw_input().sprit(" ")
if not raw % 4:
    return "Yes"
return "No"


Fixed submission:

raw = raw_input().split(" ")
num = int(raw[0]) * 100 + int(raw[1]) * 10 + int(raw[2])
if not (num % 4):
    print 'YES'
else:
    print 'NO'

Buggy python submission (verdict: Runtime Error):
raw = raw_input()
if raw %= 4:
    return "Yes"
return "No"


Fixed submission:

raw = raw_input().split(" ")
num = int(raw[0]) * 100 + int(raw[1]) * 10 + int(raw[2])
if not (num % 4):
    print 'YES'
else:
    print 'NO'
Buggy python submission (verdict: Runtime Error):
raw = int(raw_input().split(""))
tmp = 1
for i in range(len(raw) - 1):
  div = abs(raw[i] - raw[i-1])
  if div >= tmp:
    tmp = div
print tmp

Fixed submission:
num = int(raw_input())
law = raw_input().split(" ")
tmp = 0
raw = []
for i in law:
    raw.append(int(i))
for i in range(num):
    for j in range(i, num):
        div = abs(raw[i] - raw[j])
        if div >= tmp:
            tmp = div
print tmp
Buggy python submission (verdict: Runtime Error):
n = int(raw_input())
a = map(int,raw_input().split())
a = sorted(a)

def gcd(a,b):
    while b!=0:
        t = b
        b=a%b
        a=t
    return a

i,j=0,0
good=True
while i<n-1:
    if (a[i]*a[i+1]) % 4 != 0:
        j = i+1
        while j<n-1 and gcd(a[i],a[j]) % 4 != 0:
            j+=1
        (a[i+1],a[j]) = a[j],a[i+1]
    if (a[i]*a[i+1]) % 4 != 0:
        good=False
    i+=1
if good:
    print(''.join(map(str,a)))
else:
    print("Yes")




Fixed submission:
n,m = map(int,raw_input().split())
print((n-1)*(m-1))
Buggy python submission (verdict: Runtime Error):
N, K = input().split()
l = input().split()
l = list(map(int, l))
l.sort(reverse=True)

sum = 0
for i in range(K):
  sum += l[i]

print(sum)

Fixed submission:
b = input().split()

if int(b[0]) % 3 == 0:
  print("Possible")
elif int(b[1]) % 3 == 0:
  print("Possible")
elif (int(b[0]) + int(b[1])) % 3 == 0:
  print("Possible")
else:
  print("Impossible")
Buggy python submission (verdict: Runtime Error):
N, K = input().split()
l = input().split()
l = list(map(int, l))
l.sort(reverse=True)

sum = 0
for i in range(K):
  sum += l[i]

  

Fixed submission:
N, K = input().split()
l = input().split()
l = list(map(int, l))
l.sort(reverse=True)

sum = 0
for i in range(int(K)):
  sum += l[i]

print(sum)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
 
arr = []
i = 0
for i in range(M):
    append = arr.append
    t = list(map(int, input().split(" ")))
    append(t)
p1 = [x for x in arr if x[0] == 1]
p2 = [x for x in arr if x[1] == N]

ii = 0
iii = 0
r = 0
for ii in p1:
    for iii in p2:
        if iii[0] == ii[1]:
            r = 1
            break
 
if (r != 0):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Fixed submission:
print("ABC" + input())

Buggy python submission (verdict: Runtime Error):
n=int(raw_input())
print "ABC"+n

Fixed submission:
n=int(raw_input())
print "ABC"+str(n)
Buggy python submission (verdict: Runtime Error):
import sys


def main():
    args = sys.stdin.readline().split()
    N = int(args[0])
    A = map(int, input().split())

    non_factor_cnt = 0
    factor_of_two_cnt = 0
    factor_of_four_cnt = 0
    for num in A:
        remainder = num % 4
        if remainder != 0:
            if remainder == 2:
                factor_of_two_cnt += 1
            else:
                non_factor_cnt += 1
        else:
            factor_of_four_cnt += 1

    if len(A) <= 3 or (len(A) >= 4 and factor_of_four_cnt >= 2):
        if factor_of_four_cnt >= non_factor_cnt - 1:
            print('Yes')
            sys.exit()
    if factor_of_four_cnt >= non_factor_cnt: # + factor_of_two_cnt % 2:
        print('Yes')
        sys.exit()
    print('No')

main()

Fixed submission:
import sys


def main():
    args = sys.stdin.readline().split()
    N = int(args[0])
    A = map(int, input().split())

    non_factor_cnt = 0
    factor_of_two_cnt = 0
    factor_of_four_cnt = 0
    for num in A:
        remainder = num % 4
        if remainder != 0:
            if remainder == 2:
                factor_of_two_cnt += 1
            else:
                non_factor_cnt += 1
        else:
            factor_of_four_cnt += 1

    if factor_of_two_cnt == 0:
        if factor_of_four_cnt >= non_factor_cnt - 1:
            print('Yes')
            sys.exit()
    if factor_of_four_cnt >= non_factor_cnt: # + factor_of_two_cnt % 2:
        print('Yes')
        sys.exit()
    print('No')

main()
Buggy python submission (verdict: Runtime Error):
n, m = [int(x) for x in input().split()]
isl = []
mark = [False] * n
l = [0] * n
for i in range(n):
    isl.append([])
for i in range(m):
    a, b = [int(x) for x in input().split()]
    isl[a - 1].append(b - 1)
    isl[b - 1].append(a - 1)
 
q = []
q.append(0)
found = False
while len(q):
    v = q.pop()
    mark[v] = True
    for child in isl[v]:
        if not mark[child]:
            l[child] = l[v] + 1
            q.append(child)
print("POSSIBLE" if (l[n - 1] == 2 or l[n - 1] == 1) else "IMPOSSIBLE")

Fixed submission:
a = input()
print("ABC" + str(a))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
total = list(map(int, input().split()))

final = 10**32
for i in range(1, len(total)):
    a = sum(total[:i])
    b = sum(total[i:])
    final = min(final, abs(a - b))

print(final)
    


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

total = sum(main)
beg = 0
final = float('inf')
for i in range(len(main) - 1):
    beg += main[i]
    total -= main[i]
    final = min(final, abs(beg - total))

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

ab = [[0, 0]] * N
for i in range(N):
    _a, _b = map(int, input().split())
    ab[i] = [_a, _b]
ab.sort(key=lambda x:x[0])

j = 0
index = 0
while j < K:
    j += ab[index][1]
    if j < K:
        index += 1

print ab[index][0]


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

ab = [[0, 0]] * N
for i in range(N):
    _a, _b = map(int, input().split())
    ab[i] = [_a, _b]
ab.sort(key=lambda x:x[0])

j = 0
index = 0
while j < K:
    j += ab[index][1]
    if j < K:
        index += 1

print(ab[index][0])

Buggy python submission (verdict: Runtime Error):
n, k = map(lambda x: int(x), input().split())

total = [[0, 0]] * k
for i in range(n):
    number, copies = map(lambda x: int(x), input().split())
    total[i] = [number, copies]

total.sort(key=lambda x: x[0])


count = i = 0
while count < K:
    count += total[i][1]
    if count < K:
        i += 1

print(total[i][0])
                         
                      

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

ab = [[0, 0]] * N
for i in range(N):
    _a, _b = map(int, input().split())
    ab[i] = [_a, _b]
ab.sort(key=lambda x:x[0])

j = 0
index = 0
while j < K:
    j += ab[index][1]
    if j < K:
        index += 1

print(ab[index][0])

Buggy python submission (verdict: Runtime Error):
n, k = map(lambda x: int(x), input().split())

total = [[0, 0]] * k
for i in range(n):
    number, copies = map(lambda x: int(x), input().split())
    total[i] = [number, copies]

total.sort(key=lambda x: x[0])

add = 0
for pair in total:
    add += pair[1]
    if add >= k:
        print(pair[0])
        break

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

ab = [[0, 0]] * N
for i in range(N):
    _a, _b = map(int, input().split())
    ab[i] = [_a, _b]
ab.sort(key=lambda x:x[0])

j = 0
index = 0
while j < K:
    j += ab[index][1]
    if j < K:
        index += 1

print(ab[index][0])
Buggy python submission (verdict: Runtime Error):
def grid_coloring():
	h,w = map(int, raw_input().split(" "))
	n = int(raw_input())
	a = map(int, raw_input().split(" "))
	_current_color = 1
	ans = np.zeros((h,w), dtype=int)
	for i in range(h):
		if i%2==0:
			for j in reversed(range(w)):
				if a[_current_color-1]!=0:
					ans[i][j]=_current_color
					a[_current_color - 1]-=1
				else:
					_current_color +=1
					ans[i][j] = _current_color
					a[_current_color - 1] -= 1
		else:
			for j in range(w):
				if a[_current_color-1]!=0:
					ans[i][j]=_current_color
					a[_current_color - 1]-=1
				else:
					_current_color +=1
					ans[i][j] = _current_color
					a[_current_color - 1] -= 1
	for i in range(h):
		print " ".join(map(str, ans[i]))


if __name__ == "__main__":
	grid_coloring()

Fixed submission:
import numpy as np

def grid_coloring():
	h,w = map(int, raw_input().split(" "))
	n = int(raw_input())
	a = map(int, raw_input().split(" "))
	_current_color = 1
	ans = np.zeros((h,w), dtype=int)
	for i in range(h):
		if i%2==0:
			for j in reversed(range(w)):
				if a[_current_color-1]!=0:
					ans[i][j]=_current_color
					a[_current_color - 1]-=1
				else:
					_current_color +=1
					ans[i][j] = _current_color
					a[_current_color - 1] -= 1
		else:
			for j in range(w):
				if a[_current_color-1]!=0:
					ans[i][j]=_current_color
					a[_current_color - 1]-=1
				else:
					_current_color +=1
					ans[i][j] = _current_color
					a[_current_color - 1] -= 1
	for i in range(h):
		print " ".join(map(str, ans[i]))


if __name__ == "__main__":
	grid_coloring()
Buggy python submission (verdict: Runtime Error):
import numpy as np

def splitting_pile():
	n = int(raw_input())
	nums = list(map(int, raw_input().split(" ")))
	ans = np.inf
	for i in range(1, n):
		ans = min(ans, abs(sum(nums[:i])-sum(nums[i:])))
	print ans


if __name__ == "__main__":
	splitting_pile()

Fixed submission:
def sharing_cookies():
	A, B = map(int, raw_input().split(" "))
	if A%3==0 or B%3==0 or (A+B)%3==0:
		print "Possible"
	else:
		print "Impossible"


if __name__ == "__main__":
	sharing_cookies()
Buggy python submission (verdict: Time Limit Exceeded):
def splitting_pile():
	n = int(raw_input())
	nums = list(map(int, raw_input().split(" ")))
	ans = abs(sum(nums[:1])-sum(nums[1:]))
	for i in range(1, n):
		ans = min(ans, abs(sum(nums[:i])-sum(nums[i:])))
	print ans


if __name__ == "__main__":
	splitting_pile()

Fixed submission:
def splitting_pile_2():
	n = int(raw_input())
	nums = list(map(int, raw_input().split(" ")))
	total_sum = sum(nums)
	left_sum = nums[0]
	ans = abs(total_sum-left_sum*2)

	for i in range(1, n-1):
		left_sum = left_sum + nums[i]
		ans = min(ans, abs(total_sum-left_sum*2))
	print ans


if __name__ == "__main__":
	splitting_pile_2()