Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
ans = 0
for i in range(60):
    count = sum(1 for j in a if j>>i & 1)
    ans += count * (n-count) * pow(2,i,mod)
print(ans % mod)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
ans = 0
for i in range(60):
    mask = 1 << i
    count = sum(1 for j in a if mask & j == 0)
    ans += count * (n-count) * pow(2,i,mod)
print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
ans = 0
for i in range(60):
    count = 0
    for j in a:
        if j >> i & 1:
            count += 1
    ans += count * (n-count) * pow(2,i,mod)
print(ans % mod)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
ans = 0
for i in range(60):
    mask = 1 << i
    count = sum(1 for j in a if mask & j == 0)
    ans += count * (n-count) * pow(2,i,mod)
print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
ans = 0
for i in range(60):
    count = 0
    for j in a:
        if j >> i & 1:
            count += 1
    ans += count * (n-count) * 2** i
print(ans % mod)    

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
ans = 0
for i in range(60):
    mask = 1 << i
    count = sum(1 for j in a if mask & j == 0)
    ans += count * (n-count) * pow(2,i,mod)
print(ans % mod)
Buggy python submission (verdict: Runtime Error):
n = int(input())
for i in range(n):
    if int(i*1.08) = n:
        print(i)
        exit()
print(":(")


Fixed submission:
n = int(input())
for i in range(n+1):
    if int(i*1.08) == n:
        print(i)
        exit()
print(":(")
Buggy python submission (verdict: Runtime Error):
from functools import reduce
import sys
sys.setrecursionlimit(100000)
mod = 10**9+7
def mul(a,b):
    return a*b % mod
def cmb(n,r,mod):
    above = reduce(mul,range(n-r+1,n+1)) 
    below = reduce(mul,range(1,r+1)) 
    ans = above*pow(below,mod-2,mod) % mod
    if ans < 0:
        ans += mod
    return ans
x,y = map(int,input().split())
if 2*x-y < 0 or 2*y-x<0 or (2*x-y) % 3 != 0:
    print(0)
    exit()
a = (2*x-y)//3
b = (2*y-x)//3
print(cmb(a+b,min(a,b),mod))


Fixed submission:
from functools import reduce
mod = 10**9+7
def mul(a,b):
    return a*b % mod
def cmb(n,r,mod):
    if r == 0:
        return 1
    if r == 1:
        return n % mod 
    above = reduce(mul,range(n-r+1,n+1)) 
    below = reduce(mul,range(1,r+1)) 
    ans = above*pow(below,mod-2,mod) % mod
    if ans < 0:
        ans += mod
    return ans
x,y = map(int,input().split())
if 2*x-y < 0 or 2*y-x<0 or (2*x-y) % 3 != 0:
    print(0)
    exit()
a = (2*x-y)//3
b = (2*y-x)//3
print(cmb(a+b,min(a,b),mod))

Buggy python submission (verdict: Runtime Error):
from functools import reduce
mod = 10**9+7
def mul(a,b):
    return a*b % mod
def cmb(n,r,mod):
    above = reduce(mul,range(n-r+1,n+1)) 
    below = reduce(mul,range(1,r+1)) 
    ans = above*pow(below,mod-2,mod) % mod
    if ans < 0:
        ans += mod
    return ans
x,y = map(int,input().split())
if 2*x-y < 0 or 2*y-x<0 or (2*x-y) % 3 != 0:
    print(0)
    exit()
a = (2*x-y)//3
b = (2*y-x)//3
print(cmb(a+b,min(a,b),mod))


Fixed submission:
from functools import reduce
mod = 10**9+7
def mul(a,b):
    return a*b % mod
def cmb(n,r,mod):
    if r == 0:
        return 1
    if r == 1:
        return n % mod 
    above = reduce(mul,range(n-r+1,n+1)) 
    below = reduce(mul,range(1,r+1)) 
    ans = above*pow(below,mod-2,mod) % mod
    if ans < 0:
        ans += mod
    return ans
x,y = map(int,input().split())
if 2*x-y < 0 or 2*y-x<0 or (2*x-y) % 3 != 0:
    print(0)
    exit()
a = (2*x-y)//3
b = (2*y-x)//3
print(cmb(a+b,min(a,b),mod))
Buggy python submission (verdict: Runtime Error):
def warshall_floid(d):
    for k in range(1,n+1):
        for i in range(1,n+1):
            for j in range(1,n+1):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d

n,m,l = map(int,input().split())
d = [10**13]*(n+1) for i in range(n+1)]
for i in range(m):
    a,b,c = map(int,input().split())
    d[a][b] = c
    d[b][a] = c
for i in range(1,n+1):
    d[i][i] = 0
d = warshall_floid(d)
for i in range(1,n+1):
    for j in range(1,n+1):
        if d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = 10**13
d = warshall_floid(d)
q = int(input())
for i in range(q):
    s,t = map(int,input().split())
    if d[s][t] >= 10**13:
        print(-1)
    else:
        print(d[s][t]-1)


Fixed submission:
a,b = map(int,input().split())
if a-2*b > 0:
    print(a-2*b)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
lst = []
for i in range(n):
    lst.append(a.index(i+1))
print(" ".join(map(str,[i+1 for i in lst])))

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
dic = {}
ans = []
for i in range(n):
    dic [a[i]-1] = i+1
for i in range(n):
    ans.append(dic[i])
print(" ".join(map(str,ans)))
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
import math
a,b = map(int,input().split())
n = gcd(a,b)
integer = [i for i in range(2,n+1)]
prime = set()
while integer[0] <= math.sqrt(n):
    p = integer[0] 
    prime.add(p)
    integer = [i for i in integer if i % p != 0]
prime = prime | set(integer)
count = 1
for i in prime:
    if n == 1:
        break
    if n % i == 0:
        count += 1
        while n % i == 0:
            n //= i
print(count)


Fixed submission:
from fractions import gcd
import math
a,b = map(int,input().split())
n = gcd(a,b)
if n == 1:
    print(1)
    exit()
count = 1
for i in range(2,math.ceil(math.sqrt(n))+1):
    if n % i == 0:
        count += 1
        while n % i == 0:
            n //= i
if n > 1:
    count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
ss = s+s
NEXT = [[-1]*(len(s)+1) for _ in range(26)]
cur = [-1]*26
for i in range(len(ss)):
    char = ord(ss[i])-97
    if cur[char] < len(s):
        for j in range(cur[char],min(i,len(s))):
            NEXT[char][j+1] = i
            cur[char] = i
ans = 0
tmp = -1
for i in range(len(t)):
    char = ord(t[i])-97
    if NEXT[char][tmp+1] == -1:
        print(-1)
        exit()
    ans += NEXT[char][tmp+1]-tmp
    tmp = NEXT[char][tmp+1]
    if tmp >= len(s)+1:
        tmp -= len(s)
print(ans)


Fixed submission:
s = input()
t = input()
ss = s+s
NEXT = [[-1]*(len(s)+1) for _ in range(26)]
cur = [-1]*26
for i in range(len(ss)):
    char = ord(ss[i])-97
    if cur[char] < len(s):
        for j in range(cur[char],min(i,len(s))):
            NEXT[char][j+1] = i
            cur[char] = i
ans = 0
tmp = -1
for i in range(len(t)):
    char = ord(t[i])-97
    if NEXT[char][tmp+1] == -1:
        print(-1)
        exit()
    ans += NEXT[char][tmp+1]-tmp
    tmp = NEXT[char][tmp+1]
    if tmp >= len(s):
        tmp -= len(s)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N,M,P = map(int,input().split())
INF = 10**18
edge = []
rev_edge = [[] for _ in range(N+1)]
dis = [INF]*(N+1)
dis[1] = 0
for i in range(M):
    A,B,C = map(int,input().split())
    edge.append((A,B,P-C))
    rev_edge[B].append(A)
d = deque()
can_arrive = set()
d.append(N)
while d:
    x = d.popleft()
    can_arrive.add(x)
    for y in rev_edge[x]:
        if not y in can_arrive:
            d.append(y)

for i in range(N):
    update = False
    for j in range(M):
        A,B,cost = edge[j]
        if dis[A] != INF and dis[B] > dis[A]+cost:
            dis[B] = dis[A]+cost
            if B in can_arrive:
                update = True
ans = dis[N]
if update:
    print(-1)
else:
    print(max(0,-ans))

Fixed submission:
from collections import deque
N,M,P = map(int,input().split())
INF = 10**18
edge = []
rev_edge = [[] for _ in range(N+1)]
dis = [INF]*(N+1)
dis[1] = 0
for i in range(M):
    A,B,C = map(int,input().split())
    edge.append((A,B,P-C))
    rev_edge[B].append(A)
d = deque()
can_arrive = set()
d.append(N)
can_arrive.add(N)
while d:
    x = d.popleft()
    for y in rev_edge[x]:
        if not y in can_arrive:
            d.append(y)
            can_arrive.add(y)

for i in range(N):
    update = False
    for j in range(M):
        A,B,cost = edge[j]
        if dis[A] != INF and dis[B] > dis[A]+cost:
            dis[B] = dis[A]+cost
            if B in can_arrive:
                update = True
ans = dis[N]
if update:
    print(-1)
else:
    print(max(0,-ans))
Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9+7
s = list(reversed(list(input())))
n = len(s)
dp = [[0,0,0,0,0,0,0,0,0,0,0,0,0]for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
    if s[i] == '?':
        for k in range(10):
            x = k*pow(10,i,13) % 13
            for j in range(13):
                dp[i+1][(j+x) % 13] += dp[i][j] % mod
    else:
        x = int(s[i])*pow(10,i,13) % 13
        for j in range(13):
            dp[i+1][(j+x) % 13] += dp[i][j] % mod
print(dp[n][5] % mod)



Fixed submission:
mod = 10**9+7
s = list(reversed(list(input())))
n = len(s)
dp = [[0,0,0,0,0,0,0,0,0,0,0,0,0]for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
    if s[i] == '?':
        for k in range(10):
            x = k*pow(10,i,13) % 13
            for j in range(13):
                dp[i+1][(j+x) % 13] += dp[i][j] % mod
    else:
        x = int(s[i])*pow(10,i,13) % 13
        for j in range(13):
            dp[i+1][(j+x) % 13] += dp[i][j] % mod
print(dp[n][5] % mod)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input()))
x = 0
for i in range(N):
    x ^=  a[i]
if x:
    print('No')
else:
    print('Yes')

Fixed submission:
N = int(input())
a = list(map(int,input().split()))
if N % 3 != 0:
    if any(a):
        print('No')
    else:
        print('Yes')
else:
    a.sort()
    a1 = set(a[:N//3])
    a2 = set(a[N//3:2*N//3])
    a3 = set(a[2*N//3:])
    if len(a1) == 1 and len(a2) == 1 and len(a3) == 1:
        if a1.pop()^a2.pop()^a3.pop() == 0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
from functools import reduce
mod = 10**9+7
def mul(a,b):
    return a*b % mod
def cmb(n,r,mod):
    r = min(r,n-r)
    if r == 0:
        return 1
    r = min(n-r,r)
    above = reduce(mul,range(n-r+1,n+1)) 
    below = reduce(mul,range(1,r+1)) 
    ans = above*pow(below,mod-2,mod) % mod
    if ans < 0:
        ans += mod
    return ans

n,k = map(int,input().split())
for i in range(1,k+1):
    print(cmb(n-k+1,i,mod)*cmb(k-1,i-1,mod) % mod)

Fixed submission:
from functools import reduce
mod = 10**9+7
def mul(a,b):
    return a*b % mod
def cmb(n,r,mod):
    r = min(r,n-r)
    if r == 0:
        return 1
    r = min(n-r,r)
    above = reduce(mul,range(n-r+1,n+1)) 
    below = reduce(mul,range(1,r+1)) 
    ans = above*pow(below,mod-2,mod) % mod
    if ans < 0:
        ans += mod
    return ans

n,k = map(int,input().split())
for i in range(1,k+1):
    if n-k+1  < i :
        print(0)
    else:
        print(cmb(n-k+1,i,mod)*cmb(k-1,i-1,mod) % mod)
Buggy python submission (verdict: Runtime Error):
mod = 10**9+7
N,M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))
dp = [[1]*(N+1) for _ in range(M+1)]
for i in range(1,N+1):
    for j in range(1,M+1):
        if S[i-1] == T[j-1]:
            dp[i][j] = (dp[i-1][j]+dp[i][j-1]) % mod
        else:
            dp[i][j] = (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]) % mod
print(dp[N][M])

Fixed submission:
mod = 10**9+7
N,M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))
dp = [[1]*(M+1) for _ in range(N+1)]
for i in range(1,N+1):
    for j in range(1,M+1):
        if S[i-1] == T[j-1]:
            dp[i][j] = (dp[i-1][j]+dp[i][j-1]) % mod
        else:
            dp[i][j] = (dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]) % mod
print(dp[N][M])
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n = int(input())
li = []
for i in range(n):
    xi,yi = map(int,input().split())
    li.append((xi,yi))
if n == 1:
    print(1)
dic = defaultdict(int)
for i in range(n):
    for j in range(n):
        if i != j:
            xi = li[i][0]
            yi = li[i][1]
            xj = li[j][0]
            yj = li[j][1]
            dic[(xi-xj,yi-yj)] += 1
print(n-max(dic.values()))

Fixed submission:
from collections import defaultdict
n = int(input())
li = []
for i in range(n):
    xi,yi = map(int,input().split())
    li.append((xi,yi))
if n == 1:
    print(1)
    exit()
dic = defaultdict(int)
for i in range(n):
    for j in range(n):
        if i != j:
            xi = li[i][0]
            yi = li[i][1]
            xj = li[j][0]
            yj = li[j][1]
            dic[(xi-xj,yi-yj)] += 1
print(n-max(dic.values()))

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n = int(input())
li = []
for i in range(n):
    xi,yi = map(int,input().split())
    li.append((xi,yi))
dic = defaultdict(int)
for i in range(n):
    for j in range(n):
        if i != j:
            xi = li[i][0]
            yi = li[i][1]
            xj = li[j][0]
            yj = li[j][1]
            dic[(xi-xj,yi-yj)] += 1
print(n-max(dic.values()))

Fixed submission:
from collections import defaultdict
n = int(input())
li = []
for i in range(n):
    xi,yi = map(int,input().split())
    li.append((xi,yi))
if n == 1:
    print(1)
    exit()
dic = defaultdict(int)
for i in range(n):
    for j in range(n):
        if i != j:
            xi = li[i][0]
            yi = li[i][1]
            xj = li[j][0]
            yj = li[j][1]
            dic[(xi-xj,yi-yj)] += 1
print(n-max(dic.values()))
Buggy python submission (verdict: Runtime Error):
N,A,B,C,D = map(int,input().split())
S = ['#']+list(input())
CanReach = True
CanChange = False
for i in range(A,C):
    if S[i] == '#' and S[i+1] == '#':
        CanReach = False
for i in range(B,D):
    if S[i] == '#' and S[i+1] == '#':
        CanReach = False
if C < D:
    CanChange = True
for i in range(B,D+1):
    if S[i-1] == '.' and S[i] == '.' and S[i+1] == '.':
        CanChange = True
if CanReach and CanChange:
    print('Yes')
else:
    print('No')

Fixed submission:
N,A,B,C,D = map(int,input().split())
S = ['#']+list(input())
CanReach = True
CanChange = False
for i in range(A,C):
    if S[i] == '#' and S[i+1] == '#':
        CanReach = False
for i in range(B,D):
    if S[i] == '#' and S[i+1] == '#':
        CanReach = False
if C < D:
    CanChange = True
else:
    for i in range(B,D+1):
        if S[i-1] == '.' and S[i] == '.' and S[i+1] == '.':
            CanChange = True
if CanReach and CanChange:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import heapq
from collections import deque
from copy import copy
n,k = map(int,input().split())
d = deque(list(map(int,input().split())))
maxvalue = 0
for i in range(k):
    for j in range(k-i+1):
        jewel = []
        x = copy(d)
        for _ in range(i):
            jewel.append(x.popleft())
        for _ in range(j):
            jewel.append(x.pop())
        heapq.heapify(jewel)
        for _ in range(k-i-j):
            if jewel:
                a = heapq.heappop(jewel)
                if a >= 0:
                    jewel.append(a)
                    break
        maxvalue = max(maxvalue,sum(jewel))
print(maxvalue)

        

Fixed submission:
import heapq
from collections import deque
from copy import copy
n,k = map(int,input().split())
d = deque(list(map(int,input().split())))
maxvalue = 0
for i in range(k+1):
    for j in range(k-i+1):
        jewel = []
        x = copy(d)
        for _ in range(i):
            if x:
                jewel.append(x.popleft())
        for _ in range(j):
            if x:
                jewel.append(x.pop())
        heapq.heapify(jewel)
        for _ in range(k-i-j):
            if jewel:
                a = heapq.heappop(jewel)
                if a >= 0:
                    jewel.append(a)
                    break
        maxvalue = max(maxvalue,sum(jewel))
print(maxvalue)
Buggy python submission (verdict: Time Limit Exceeded):
def cmb(a,b,c):
    b = min(b,a-b)
    num = 1
    for i in range(b):
        num = num*(a-i) % c
    den = 1
    for i in range(b):
        den = den*(i+1) % c
    return num * pow(den,c-2,c) % c
n,m,k = map(int,input().split())
mod = 10**9+7
ans = 0
for i in range(1,n):
    ans += i*(n-i)*m**2*cmb(n*m-2,k-2,mod)
    ans %= mod
for i in range(1,m):
    ans += i*(m-i)*n**2*cmb(n*m-2,k-2,mod)
    ans %= mod
print(ans)


Fixed submission:
def cmb(a,b,c):
    b = min(b,a-b)
    num = 1
    for i in range(b):
        num = num*(a-i) % c
    den = 1
    for i in range(b):
        den = den*(i+1) % c
    return num * pow(den,c-2,c) % c
n,m,k = map(int,input().split())
mod = 10**9+7
ans = 0
C = cmb(n*m-2,k-2,mod)
for i in range(1,n):
    ans += i*(n-i)*m**2*C
    ans %= mod
for i in range(1,m):
    ans += i*(m-i)*n**2*C
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def cmb(a,b,c):
    b = min(b,a-b)
    num = 1
    for i in range(b):
        num = num*(a-i) % c
    den = 1
    for i in range(b):
        den = den*(i+1) % c
    return num * pow(den,c-2,c) % c
n,m,k = map(int,input().split())
mod = 10**9+7
ans = 0
for i in range(1,n):
    ans += i*(n-i)*m**2*cmb(n*m-2,k-2,mod)
    ans %= mod
for i in range(1,m):
    ans += i*(m-i)*n**2*cmb(n*m-2,k-2,mod)
    ans %= mod
print(ans)


Fixed submission:
def cmb(a,b,c):
    b = min(b,a-b)
    num = 1
    for i in range(b):
        num = num*(a-i) % c
    den = 1
    for i in range(b):
        den = den*(i+1) % c
    return num * pow(den,c-2,c) % c
n,m,k = map(int,input().split())
mod = 10**9+7
ans = 0
C = cmb(n*m-2,k-2,mod)
for i in range(1,n):
    ans += i*(n-i)*m**2*C
    ans %= mod
for i in range(1,m):
    ans += i*(m-i)*n**2*C
    ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
s = list(map(int,list(input()))
a = s[0]*10+s[1]
b = s[2]*10+s[3]
lst = [1,2,3,4,5,6,7,8,9,10,11,12]
if a in lst:
    if b in lst:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if b in lst:
        print('YYMM')
    else:
        print('NA')

Fixed submission:
s = list(map(int,list(input())))
a = s[0]*10+s[1]
b = s[2]*10+s[3]
lst = [1,2,3,4,5,6,7,8,9,10,11,12]
if a in lst:
    if b in lst:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if b in lst:
        print('YYMM')
    else:
        print('NA')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())
lst = [[set(),set()] for i in range(n)]
a = set([1])
b = set()
for i in range(n-1):
    u,v,w = map(int,input().split())
    if w % 2 == 0:
        lst[u-1][0].add(v)
        lst[v-1][0].add(u)
    else:
        lst[u-1][1].add(v)
        lst[v-1][1].add(u)
q = deque([1])
while q:
    i = q.popleft()
    if i in a:
        for j in lst[i-1][0]:
            lst[j-1][0].discard(i)
            q.append(j)
            a.add(j)
        for j in lst[i-1][1]:
            lst[j-1][1].discard(i)
            q.append(j)
            b.add(j)
    if i in b:
        for j in lst[i-1][0]:
            lst[j-1][1].discard(i)
            q.append(j)
            b.add(j)
        for j in lst[i-1][1]:
            lst[j-1][0].discard(i)
            q.append(j)
            a.add(j)
for i in range(1,n+1):
    if i in a:
        print(0)
    else:
        print(1)

Fixed submission:
from collections import deque
n = int(input())
graph = [[] for _ in range(n+1)]
for _ in range(n-1):
    u,v,w = map(int,input().split())
    graph[u].append((v,w))
    graph[v].append((u,w))
q = deque([1])
ans = [0] * (n+1)
parent = [0]*(n+1)
while q:
    x = q.popleft()
    for y,w in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        ans[y] = ans[x]^(w&1)
        q.append(y)
for i in range(1,n+1):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
m,k = map(int,input().split())
if m == 1:
    if k == 0:
        print(0,0,1,1)
    else:
        print(-1)
elif 2**m <= k:
    print(-1)
else:
    remain = set(range(2**m))
    use = set()
    count = 0
    while k:
        if k & 1:
            remain.remove(2**count)
            use.add(2**count)
        k >>= 1
        count += 1
ans = []
remain = list(remain)
use = list(use)
for i in remain:
    ans.append(str(i))
for i in use:
    ans.append(str(i))
for i in remain[::-1]:
    ans.append(str(i))
for i in use[::-1]:
    ans.append(str(i))
print(" ".join(ans))

Fixed submission:
m,k = map(int,input().split())
if m == 1:
    if k == 0:
        print(0,0,1,1)
    else:
        print(-1)
elif 2**m <= k:
    print(-1)
else:
    remain = set(range(2**m))
    use = set()
    count = 0
    while k:
        if k & 1:
            remain.remove(2**count)
            use.add(2**count)
        k >>= 1
        count += 1
    ans = []
    remain = list(remain)
    use = list(use)
    for i in remain:
        ans.append(str(i))
    for i in use:
        ans.append(str(i))
    for i in remain[::-1]:
        ans.append(str(i))
    for i in use[::-1]:
        ans.append(str(i))
    print(" ".join(ans))
Buggy python submission (verdict: Runtime Error):
from math import gcd
n = int(input())
a = list(map(int,input().split()))
left = []
right = []

left.append(a[0])
for i in range(1,n-1):
    left.append(gcd(left[-1],a[i]))
a = a[::-1]
right.append(a[0])
for i in range(1,n-1):
    right.append(gcd(right[-1],a[i]))
ans = 1
for i in range(n-1):
    ans = max(ans,gcd(left[i],right[n-i-3]))
ans = max(ans,left[n-2],right[n-2])
print(ans)


Fixed submission:
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
GCD= a[0]
dp = [set() for i in range(n)]
dp[1].add(a[0])
dp[1].add(a[1])
for i in range(1,n):
    x = a[i]
    for j in dp[i-1]:
            dp[i].add(gcd(j,x))
    if x % GCD != 0:
        dp[i].add(GCD)
        GCD = gcd(GCD,x)
print(max(dp[n-1]))
Buggy python submission (verdict: Runtime Error):
h,w = map(int,input().split())
grid = []
ans = []
for i in range(h):
    grid.append(list(map(int,input().split())))
cur = [0,0]
while cur[0] != h or (cur[1] != 0 and cur[1] != w-1):
    y,x = cur[0],cur[1]
    if y % 2 == 0:
        if x != w-1:
            if grid[y][x] % 2 == 1:
                grid[y][x] -= 1
                grid[y][x+1] += 1
                ans.append((y+1,x+1,y+1,x+2))
            cur[1] += 1
        else:
            if grid[y][x] % 2 == 1:
                grid[y][x] -= 1
                grid[y+1][x] += 1
                ans.append((y+1,x+1,y+2,x+1))
            cur[0] += 1
    else:
        if x != 0:
            if grid[y][x] % 2 == 1:
                grid[y][x] -= 1
                grid[y][x-1] += 1
                ans.append((y+1,x+1,y+1,x))
            cur[1] -= 1
        else:
            if grid[y][x] % 2 == 1:
                grid[y][x] -= 1
                grid[y+1][x] += 1
                ans.append((y+1,x+1,y+2,x+1))
            cur[0] += 1
for i in ans:
    print(i[0],i[1],i[2],i[3])

Fixed submission:
h,w = map(int,input().split())
coins = []
ans = []
for i in range(h):
    coins.append(list(map(int,input().split())))
for i in range(h-1):
    for j in range(w):
        if coins[i][j] % 2 != 0:
            coins[i][j] -= 1
            coins[i+1][j] += 1
            ans.append((i+1,j+1,i+2,j+1))
for i in range(w-1):
    if coins[h-1][i] % 2 != 0:
        coins[h-1][i] -= 1
        coins[h-1][i+1] += 1
        ans.append((h,i+1,h,i+2))
print(len(ans))
for i in range(len(ans)):
    print(*ans[i])