Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02801 (python)

Fixed submission:
C=input()
print(chr(ord(C)+1))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
grid = [[c for c in input()] for _ in range(N)]
mat = [[float('inf')]*(M*N) for _ in range(N*M)]

DX = [0, 0, 1, -1]
DY = [-1, 1, 0, 0]
for row in range(N):
    for col in range(M):
        if grid[row][col] == "#":
            continue
        for dx, dy in zip(DX, DY):
            if 0 <= row+dx < N and 0 <= col+dy < M:
                if grid[row+dx][col+dy] == "#":
                    continue
                mat[(row+dx)*M+col+dy][row*M+col] = 1
                mat[row*M+col][(row+dx)*M+col+dy] = 1
for k in range(N*M):
    for i in range(N*M):
        for j in range(N*M):
            mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j])
ans = 0
for srow in range(N):
    for scol in range(M):
        if grid[srow][scol] == "#":
            continue
        for erow in range(N):
            for ecol in range(M):
                if grid[erow][ecol] == "#":
                    continue
                else:
                    ans = max(mat[srow*M+scol][erow*M+ecol], ans)
print(ans)
Problem p02802 (python)

Fixed submission:
from collections import defaultdict
N, M = map(int, input().split())

aced = [False]*N
D = defaultdict(int)
ac = 0
pena = 0
for _ in range(M):
    id, judge = input().split()
    id = int(id)-1
    if judge == "WA":
        D[id] += 1
    else:
        if not aced[id]:
            aced[id] = True
            ac += 1
            pena += D[id]
print(ac, pena)

Buggy submission (verdict: Runtime Error):

from collection import defaultdict
N, M = map(int, input().split())

aced = [False]*N
D = defaultdict(int)
ac = 0
pena = 0
for _ in range(M):
    id, judge = input().split()
    id = int(id)-1
    if judge == "WA":
        D[id] += 1
    else:
        if not aced[id]:
            aced[id] = True
            ac += 1
            pena += D[id]
print(ac, pena)
Problem p02814 (python)

Fixed submission:
def cnt_div2(n):
    cnt=0
    while n%2==0:
        n//=2
        cnt+=1
    return cnt
def gcd(a,b):
    a,b = max(a,b),min(a,b)
    while b:
        a,b = b,a%b
    return a

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

N,M = map(int,input().split())
A = list(map(lambda x:int(x)//2,input().split()))

if(all(cnt_div2(A[0]) == cnt_div2(a) for a in A)):
    if N==1:
        lcm_A = A[0]
    else:
        lcm_A = lcm(A[0],A[1])
        for a in A[2:]:
            lcm_A = lcm(lcm_A,a)
    print(int((M/lcm_A+1)//2))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
    a,b = max(a,b),min(a,b)
    while b:
        a,b = b,a%b
    return a

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

N,M = map(int,input().split())
A = list(map(lambda x:int(x)//2,input().split()))

if(all(A[0]%2 == a%2 for a in A)):
    lcm_A = lcm(A[0],A[1])
    for a in A[2:]:
        lcm_A = lcm(lcm_A,a)
    print(int((M/lcm_A+1)//2))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
    a,b = max(a,b),min(a,b)
    while b:
        a,b = b,a%b
    return a

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

N,M = map(int,input().split())
A = list(map(lambda x:int(x)//2,input().split()))

if(all(A[0]%2 == a%2 for a in A)):
    lcm_A = lcm(A[0],A[1])
    for a in A[2:]:
        lcm_A = lcm(lcm_A,a)
    print((M/lcm_A+1)//2)
else:
    print(0)
Problem p02817 (python)

Fixed submission:
print("".join(list(reversed(list(map(str,input().split()))))))

Buggy submission (verdict: Runtime Error):
print("".join(list(reversed(list(map(str,input().split())))))
Problem p02824 (python)

Fixed submission:
N,M,V,P = map(int,input().split())
A = list(map(int,input().split()))

#二分探索するからAをsortする
A = sorted(A,reverse=True)

left=0
right=N-1

while left<=right:
    mid = (left+right)//2

    if mid<P:#そもそも入っている
        left = mid + 1
    elif A[mid] + M < A[P-1]:
        right = mid -1
    else:
        voted = P * M
        for _ in range(mid+1,N):
            voted += M

        for v in A[P-1:mid]:
            voted += A[mid]+M-v

        if voted >= M*V:
            left= mid+1
        else:
            right = mid-1

print(left)

Buggy submission (verdict: Runtime Error):
N,M,V,P = map(int,input().split())
A = list(map(int,input().split()))

#二分探索するからAをsortする
A = sorted(A,reverse=True)

left=0
right=N-1

while left<=right:
    mid = (left+right)//2

    if mid<P:#そもそも入っている
        left = mid + 1
    elif A[mid] + M < A[P-1]:
        right = mid - 1
    else:
        voted = P * M
        for _ in range(mid+1,N):
            voted += M

        for v in A[P-1:mid]:
            voted += min(max(A[mid]+M-v,0),M)

        if voted <=M*V:
            right = mid-1
        else:
            left= mid+1

print(low)

Buggy submission (verdict: Runtime Error):
N,M,V,P = map(int,input().split())
A = list(map(int,input().split()))

#二分探索するからAをsortする
A = sorted(A,reverse=True)

left=0
right=N

while left<=right:
    mid = (left+right)//2

    if mid<P:#そもそも入っている
        left = mid + 1
    elif A[mid] + M < A[P-1]:
        right = mid - 1
    else:
        voted = P * M
        voted += (N-mid-1)*M

        for v in A[P-1:mid]:
            voted += min(max(A[mid]+M-v,0),M)

        if voted <=M*V:
            right = mid-1
        else:
            left= mid+1

print(left)
Problem p02845 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7

ans = 1
dp = [0]*3
for a in A:
    cnt = 0
    for i in range(3):
        if a == dp[i]:
            cnt += 1
    for i in range(3):
        if a == dp[i]:
            dp[i] += 1
            break
    ans = ans*cnt % MOD
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7

ans = 1
dp = [0]*3
for a in A:
    ans = ans*dp.count(a) % MOD
    dp[dp.index(a)] += 1
print(ans)
Problem p02846 (python)

Fixed submission:
from math import ceil
T1,T2=map(int,input().split())
A1,A2=map(int,input().split())
B1,B2=map(int,input().split())


#A1>=B1にする
if A1>=B1:
    pass
else:
    A1,B1=B1,A1
    A2,B2=B2,A2

D1=(A1-B1)*T1#>=0
D2=(A2-B2)*T2#?

if D1==-D2:
    print("infinity")
elif D1+D2>=0:
    print("0")
else:
    diff = abs(D1+D2)#マイからこれだけ差が開く
    if D1%diff==0:
        print(D1//diff*2)
    else:
        print(ceil(D1/diff)*2-1)

Buggy submission (verdict: Runtime Error):
T1,T2=map(int,input().split())
A1,A2=map(int,input().split())
B1,B2=map(int,input().split())


#A1>=B1にする
if A1>=B1:
    pass
else:
    A1,B1=B1,A1
    A2,B2=B2,A2

D1=(A1-B1)*T1#>=0
D2=(A2-B2)*T2#?

if D1==-D2:
    print("infinity")
elif D1+D2>=0:
    print("0")
else:
    diff = abs(D1+D2)#マイからこれだけ差が開く
    if D1%diff==0:
        print(D1//diff*2)
    else:
        assert 1==2

Buggy submission (verdict: Runtime Error):
T1,T2=map(int,input().split())
A1,A2=map(int,input().split())
B1,B2=map(int,input().split())


#A1>=B1にする
if A1>=B1:
    pass
else:
    A1,B1=B1,A1
    A2,B2=B2,A2

D1=(A1-B1)*T1#>=0
D2=(A2-B2)*T2#?

if D1==-D2:
    print("infinity")
elif D2>=0:
    print("0")
else:
    diff = abs(D1+D2)#マイからこれだけ差が開く
    if D1%diff==0:
        print(D1//diff*2)
    else:
        assert 1==2

Buggy submission (verdict: Runtime Error):
T1,T2=map(int,input().split())
A1,A2=map(int,input().split())
B1,B2=map(int,input().split())


if A1>=B1:
    pass
else:
    A1,B1=B1,A1
    A2,B2=B2,A2
D1=(A1-B1)*T1
D2=(A2-B2)*T2

if D1==-D2:
    print("infinity")
elif D1*D2>0:
    print("0")
else:
    assert D1>=0 and D2<=0
    diff = abs(D1+D2)
    D1=abs(D1)
    if D1%diff==0:
        print(D1//diff*2+1)
    else:
        assert 1==2
Problem p02882 (python)

Fixed submission:
import numpy as np
A,B,X=map(int,input().split())
X/=A
if A*B/2<=X:
	print(np.rad2deg(np.arctan(2*(A*B-X)/(A*A))))
else:
    print(np.rad2deg(np.arctan(B*B/(2*X))))

Buggy submission (verdict: Runtime Error):
import numpy as np
A,B,X=map(int,input().split())
rad = np.arctan((A*B-X)/(A*A)*2)
print(np.rad2deg(rad))
Problem p02889 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def WF(mat, N):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                mat[i][j] = min(mat[i][j], mat[i][k]+mat[k][j])
    return mat


N, M, L = map(int, input().split())
roads = [[float('inf')]*N for _ in [0]*N]
kyuyu = [[float('inf')]*N for _ in [0]*N]
for _ in range(M):
    a, b, c = map(int, input().split())
    roads[a-1][b-1] = c
    roads[b-1][a-1] = c

roads = WF(roads, N)
for i in range(N):
    for j in range(i+1, N):
        if roads[i][j] <= L:
            kyuyu[i][j] = 1
            kyuyu[j][i] = 1
kyuyu = WF(kyuyu, N)
Q = int(input())
for _ in range(Q):
    s, t = map(lambda x: int(x)-1, input().split())
    dist = kyuyu[s][t]
    if dist == float('inf'):
        print(-1)
    else:
        print(dist-1)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def WF(mat, N):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                mat[i][j] = min(mat[i][j], mat[i][k]+mat[k][j])
    return mat


N, M, L = map(int, input().split())
roads = [[float('inf')]*N for _ in [0]*N]
kyuyu = [[float('inf')]*N for _ in [0]*N]
for _ in range(M):
    a, b, c = map(int, input().split())
    roads[a-1][b-1] = c
    roads[b-1][a-1] = c

roads = WF(roads)
for i in range(N):
    for j in range(i+1, N):
        if roads[i][j] <= L:
            kyuyu[i][j] = 1
            kyuyu[j][i] = 1
kyuyu = WF(kyuyu)
Q = int(input())
for _ in range(Q):
    s, t = map(lambda x: int(x)-1, input().split())
    dist = kyuyu[s][t]
    if dist == float('inf'):
        print(-1)
    else:
        print(dist-1)
Problem p02909 (python)

Fixed submission:
Wethers={"Sunny":0,"Cloudy":1,"Rainy":2}
Wether=["Sunny","Cloudy","Rainy"]
S=input()
S_id = Wethers[S]
print(Wether[(S_id+1)%3])

Buggy submission (verdict: Runtime Error):
Wethers={"Sunny":0,"Cloudy":1,"Rainy":2}
Wether=["Sunny","Cloudy","Rainy"]
S=input()
S_id = Wethers[S]
print(Wether(S_id+1)%3)

Buggy submission (verdict: Runtime Error):
Wethers={"Sunny":0,"Cloudy":1,"Rainy":2}
Wether=["Sunny","Cloudy","Rainy"]
S=input()[:-1]
S_id = Wethers[S]
print(Wether(S_id+1)%3)

Buggy submission (verdict: Runtime Error):
Wethers={"Sunny":0,"Cloudy":1,"Rainy":2}
Wether=["Sunny","Cloudy","Rainy"]
S=input()[:-1]
S_id = Wethers[S]
print((S_id+1)%3)
Problem p02921 (python)

Fixed submission:
S=input()
T=input()
print(sum([1 for u,v in zip(S,T) if u==v]))

Buggy submission (verdict: Runtime Error):
S=input
print(sum(u==v for u,v in zip(S(),T())))

Buggy submission (verdict: Runtime Error):
S=input
print(sum([u==v for u,v in zip(S(),T())]))
Problem p02937 (python)

Fixed submission:
import bisect
from collections import defaultdict
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

S = input()[:-1]
T = input()[:-1]

# 作れない場合
if any(t not in S for t in T):
    print(-1)
    exit()


D = defaultdict(lambda: [])
min_D = defaultdict(lambda: len(S)+1)
for i, s in enumerate(S):
    D[s].append(i)
    min_D[s] = min(i, min_D[s])

for s in D.keys():
    D[s] = sorted(D[s])

cur_pos = 0
repeat = 0
for t in T:
    #print("cur->", cur_pos)
    ind = bisect.bisect_left(D[t], cur_pos)
    if ind >= len(D[t]):
        repeat += 1
        cur_pos = min_D[t]+1
    else:
        cur_pos = D[t][ind]+1

print(len(S)*repeat+cur_pos)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

S = input()[:-1]
T = input()[:-1]

# 作れない場合
if any(t not in S for t in T):
    print(-1)
    exit()


D = defaultdict(lambda: set())
min_D = defaultdict(lambda: len(S)+1)
for i, s in enumerate(S):
    D[s].append(i)
    min_D[s] = min(i, min_D[s])

for s in D.keys():
  D[s]=sorted(D[s])
cur_pos = 0
repeat = 0
for t in T:
    for next_cand in D[t]:
        if next_cand >= cur_pos:
            cur_pos = next_cand+1
            break
    else:
        repeat += 1
        cur_pos = min_D[t]
print(len(S)*repeat+cur_pos)
Problem p02997 (python)

Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    N, K = map(int, input().split())

    if K > (N-1)*(N-2)//2:
        print(-1)
    else:
        edges = []
        m = N-1+(N-1)*(N-2)//2-K
        for i in range(2, N+1):
            edges.append("{} {}".format(1, i))

        add_edge = (N-1)*(N-2)//2-K

        fr = 2
        to = 3
        while add_edge:
            edges.append("{} {}".format(fr, to))
            to += 1
            if to > N:
                fr += 1
                to = fr+1
            add_edge -= 1
        print(m)
        print("\n".join(edges))


solve()

Buggy submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    N, K = map(int, input().split())

    if K > (N-1)*(N-2)//2:
        print(-1)
    else:
        edges = []
        m = N-1+(N-1)*(N-2)//2-K
        for i in range(1, N+1):
            edges.append("{} {}".format(1, i))

        add_edge = (N-1)*(N-2)//K

        fr = 2
        to = 3
        while add_edge:
            edges.append("{} {}".format(fr, to))
            to += 1
            if to >= N:
                fr += 1
                to = fr+1
            add_edge -= 1
        print(m)
        print("\n".join(edges))


solve()
Problem p02999 (python)

Fixed submission:
X,A=map(int,input().split())
print("1"*(X>=A)+"0")

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
import bisect
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, K = map(int, input().split())
A = list(map(int, input().split()))

A_acc = [0]+list(accumulate(A))
ans = 0
# スタート位置を固定して、にぶたん
for l in range(N):
    tmp_acc = [v-A_acc[l] for v in A_acc]
    right = bisect.bisect_left(tmp_acc, K)
    ans += max(N-right+1, 0)

print(ans)
Problem p03006 (python)

Fixed submission:
from collections import Counter
N = int(input())
P = list(tuple(map(int, input().split())) for _ in range(N))
P = sorted(P)

p_q_cand = []
for i in range(N):
    for j in range(i+1, N):
        diff_p = P[j][0]-P[i][0]
        diff_q = P[j][1]-P[i][1]
        p_q_cand.append((diff_p, diff_q))

if N == 1:
    print(1)
else:
    C = Counter(p_q_cand)
    ans = float('inf')
    for v, c in C.items():
        p = v[0]
        q = v[1]
        tmp = 0
        used = set()
        for a, b in sorted(list(P), key=lambda x: (x[0], x[1])):
            if (a-p, b-q) not in used:
                tmp += 1
            used.add((a, b))
        ans = min(ans, tmp)
    print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
P = set(tuple(map(int, input().split())) for _ in range(N))

p_q_cand = []
for p in P:
    for q in P:
        if p == q:
            continue
        diff_p = p[0]-q[0]
        diff_q = p[1]-q[1]
        p_q_cand.append((abs(diff_p), abs(diff_q)))

C = Counter(p_q_cand)
p, q = C.most_common()[0][0]
ans = 0
used = set()
for a, b in sorted(P):
    if (a-p, b-q) not in used:
        ans += 1
    used.add((a, b))
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
P = set(tuple(map(int, input().split())) for _ in range(N))

p_q_cand = []
for p in P:
    for q in P:
        if p == q:
            continue
        diff_p = p[0]-q[0]
        diff_q = p[1]-q[1]
        p_q_cand.append((abs(diff_p), abs(diff_q)))

C = Counter(p_q_cand)
p, q = C.most_common()[0][0]
ans = 0
used = set()
for a, b in sorted(P):
    if (a-p, b-q) not in used:
        ans += 1
    used.add((a, b))
print(ans)
Problem p03007 (python)

Fixed submission:
import bisect
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
sum_L = sum(L)
N_neg = bisect.bisect_left(L, 0)
process = []
if N_neg == 0:  # minのみ-にする
    ans = sum_L-min(L)*2
    l = min(L)
    for r in L[1:-1]:
        process.append(str(l)+" "+str(r))
        l -= r
    process.append(str(L[-1])+" "+str(l))
elif N_neg == N:  # maxのみを+にする
    ans = -sum_L+max(L)*2
    l = L[-1]
    for r in reversed(L[:-1]):
        process.append(str(l)+" "+str(r))
        l -= r
else:  # negのやつを-にする
    ans = sum([abs(v) for v in L])
    l = L[0]
    for r in L[N_neg:-1]:
        process.append(str(l)+" "+str(r))
        l -= r
    process.append(str(L[-1])+" "+str(l))
    l = L[-1]-l
    for r in L[1:N_neg]:
        process.append(str(l)+" "+str(r))
        l -= r
print(ans)
print("\n".join(process))

Buggy submission (verdict: Runtime Error):
import bisect
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
sum_L = sum(L)
N_neg = bisect.bisect_left(L, 0)
process = []
if N_neg == 0:  # minのみ-にする
    ans = sum_L-min(L)*2
    l = min(L)
    for r in L[1:-1]:
        process.append(str(l)+" "+str(r))
        l -= r
    process.append(str(L[-1])+" "+str(l))
elif N_neg == N:  # maxのみを+にする
    ans = -sum_L(L)+max(L)*2
    l = L[-1]
    for r in reversed(L[:-1]):
        process.append(str(l)+" "+str(r))
        l -= r
else:  # negのやつを-にする
    ans = sum([abs(v) for v in L])
    l = L[0]
    for r in L[N_neg:-1]:
        process.append(str(l)+" "+str(r))
        l -= r
    process.append(str(L[-1])+" "+str(l))
    l = L[-1]-l
    for r in L[1:N_neg]:
        process.append(str(l)+" "+str(r))
        l -= r
print(ans)
print("\n".join(process))
Problem p03031 (python)

Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def brute_force():
    N, M = map(int, input().split())
    lamps = [list(map(lambda x:int(x)-1, input().split()))[1:]
             for _ in range(M)]
    p = list(map(int, input().split()))
    ans = 0

    for i in range(1 << N):
        for r in range(M):
            on_sum = 0
            for j in range(N):
                if i >> j & 1 and j in lamps[r]:
                    on_sum += 1
            if on_sum % 2 != p[r]:
                break
        else:
            ans += 1
    print(ans)


brute_force()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def brute_force():
    N, M = map(int, input().split())
    lamps = [list(map(lambda x:int(x)-1, input().split()))[1:]
             for _ in range(M)]
    p = list(map(int, input().split()))
    ans = 0
    for i in range(1 << N):
        for r in range(M):
            on_sum = 0
            for j in range(M):
                if i >> j & 1 and lamps[r][0]<=j<=lamps[r][1]:
                    on_sum += 1
            if on_sum % 2 == p[r]:
                continue
            else:
                break
        else:
            ans += 1
    print(ans)


brute_force()
Problem p03037 (python)

Fixed submission:
from itertools import accumulate
N,M=map(int,input().split())
L = [0]*(N+1)
for _ in range(M):
  l,r = map(lambda x:int(x)-1,input().split())
  L[l]+=1
  L[r+1]-=1

L = list(accumulate(L))
print(L.count(M))

Buggy submission (verdict: Runtime Error):
from itertools import accumurate
N,M=map(int,input().split())
L = [0]*(N+1)
for _ in range(M):
  l,r = map(lambda x:int(x)-1,input().split())
  L[l]+=1
  L[r+1]+=1

L = list(accumurate(L))
print(L.count(M))
Problem p03061 (python)

Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


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


N = int(input())
A = list(map(int, input().split()))
L = [0]*(N+1)
R = [0]*(N+1)

for i in range(N):
    L[i+1] = gcd(L[i], A[i])

for i in reversed(range(N)):
    R[i] = gcd(R[i+1], A[i])

ans = max([gcd(x, y) for x, y in zip(L, R[1:])])
print(ans)

Buggy submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = set(map(int, input().split()))
A = sorted(A)

ans = 1
for i in range(1, A[1]+1):
    if A[0] % i != 0 and A[1] % i != 0:
        continue
    else:
        if len(list(filter(lambda x: x % i != 0, A))) <= 1:
            ans = i
print(ans)

Buggy submission (verdict: Runtime Error):
from functools import reduce
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


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


N = int(input())
A = set(map(int, input().split()))
A = sorted(A)

ans = 1
for i in range(1, A[1]+1):
    if len(list(filter(lambda x: x % i != 0, A))) <= 1:
        ans *= i
print(ans)

Buggy submission (verdict: Runtime Error):
from functools import reduce
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


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


N = int(input())
A = set(map(int, input().split()))
A = sorted(list(A))

ans = max(reduce(gcd, A[2:], A[0]), reduce(gcd, A[1:]))
print(ans)
Problem p03078 (python)

Fixed submission:
import heapq
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

X, Y, Z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)


def calc(x, y, z):
    return [-A[x]-B[y]-C[z], x, y, z]


def solve1(A, B, C, X, Y, Z, k):
    Q = []
    Q.append(calc(0, 0, 0))

    ans = []
    # dict
    memo = {(0, 0, 0): True}
    for _ in range(k):
        e, x, y, z = heapq.heappop(Q)
        ans.append(-e)
        if x+1 < X and (x+1, y, z) not in memo:
            heapq.heappush(Q, calc(x+1, y, z))
            memo[(x+1, y, z)] = True
        if y+1 < Y and (x, y+1, z) not in memo:
            heapq.heappush(Q, calc(x, y+1, z))
            memo[(x, y+1, z)] = True

        if z+1 < Z and (x, y, z+1) not in memo:
            heapq.heappush(Q, calc(x, y, z+1))
            memo[(x, y, z+1)] = True

    print("\n".join(map(str, ans[:k])))


solve1(A, B, C, X, Y, Z, k)

Buggy submission (verdict: Runtime Error):
import heapq
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))


def solve1():
    que = []
    for a in a:
        for b in b:
            for c in c:
                heapq.heappush(que, -(a+b+c))
    for _ in range(k):
        print(-heapq.heappop(que))


solve1()
Problem p03102 (python)

Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M, C = map(int, input().split())
B = list(map(int, input().split()))

cnt = 0
for _ in range(N):
    A = list(map(int, input().split()))
    s = sum([a*b for a, b in zip(A, B)])
    if s+C > 0:
        cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def f(a):
    """
    xor [0,a]
    """
    ans = 0
    l = []
    d = 2
    while (a+1)//d > 0:
        t = (a+1)//d*(d//2)+max((a+1) % d-d//2, 0)
        ans += (t % 2)*(d//2)
        l.append(t % 2)
        d *= 2
    ans += (((a+1)-d) % 2)*(d//2)
    l.append(((a+1)-d) % 2)
    return l


def solve2(a, b):
    rb = f(b)
    ra = f(a-1)
    for i in range(len(ra)):
        rb[i] ^= ra[i]
    ans = "".join(map(str, reversed(rb)))
    print(int(ans, 2))


A, B = map(int, input().split())
if A == 0 and B == 0:
    print(0)
else:
    solve2(A, B)