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

Fixed submission:
from fractions import gcd
N = int(input())
As = list(map(int, input().split()))

lcm = 1
mod = 10**9+7

def getprime(n):
    if not isinstance(n, int):
        raise TypeError("Input int")
    if n < 2:
        raise ValueError("N >= 2")
    prime = []
    # 約数はsqrt(N)まで調べればOK
    data = [i+1 for i in range(1,n)]
    while True:
        p = data[0]
        if p >= int(n**0.5):
            return prime+data
        prime.append(p)
        # pで割り切れないものだけを残す
        data = [d for d in data if d%p != 0]

from collections import defaultdict
def factorization(n):
    factors = defaultdict(int)
    if n == 2 or n == 3:
        factors[n] = 1
        return factors
    primes = getprime(int(n**0.5))
    for prime in primes:
        while n % prime == 0:
            factors[prime] += 1
            n //= prime
            # print(factors,n)
    if n != 1:
        factors[n] += 1
    return factors

d = defaultdict(int)
factors_list = []
cnt_1 = 0
for a in As:
    if a == 1:
        cnt_1 += 1
        continue
    factors = factorization(a)
    factors_list.append(factors)
    for f in factors.keys():
        d[f] = max(d[f],factors[f])

for f in d.keys():
    lcm *= f ** d[f]
    lcm %= mod

As_inv = [pow(a,mod-2,mod) for a in As]
a = sum(As_inv)%mod



print((lcm*a)%mod)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
N = int(input())
As = list(map(int, input().split()))

lcm = 1
mod = 10**9+7

def getprime(n):
    if not isinstance(n, int):
        raise TypeError("Input int")
    if n < 2:
        raise ValueError("N >= 2")
    prime = []
    # 約数はsqrt(N)まで調べればOK
    data = [i+1 for i in range(1,n)]
    while True:
        p = data[0]
        if p >= int(n**0.5):
            return prime+data
        prime.append(p)
        # pで割り切れないものだけを残す
        data = [d for d in data if d%p != 0]

from collections import defaultdict
def factorization(n):
    factors = defaultdict(int)
    if n == 2 or n == 3:
        factors[n] = 1
        return factors
    primes = getprime(int(n**0.5))
    for prime in primes:
        while n % prime == 0:
            factors[prime] += 1
            n //= prime
    if n != 1:
        factors[n] += 1
    return factors

d = defaultdict(int)
for a in As:
    factors = factorization(a)
    for f in factors.keys():
        d[f] = max(d[f],factors[f])

for f in d.keys():
    lcm *= f ** d[f]

ans = 0
for a in As:
    ans += lcm//a
    ans %= mod
print(ans%mod)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
As = list(map(int, input().split()))
lcm = 1

for a in As:
    gcd_now = math.gcd(lcm,a)
    lcm = lcm*a//gcd_now

mod = 10**9+7
ans = 0
for a in As:
    ans += (lcm//a)
    ans %= mod
print(ans)
Problem p02925 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import defaultdict, deque
n = int(input())
X = 10000
INF = 1 << 50
edges = defaultdict(list)
edges_r = defaultdict(list)
def topological_sort(G):

    cnt_in = defaultdict(int)
    for k in G.keys():
        for v in G[k]:
            cnt_in[v] += 1
    # print(cnt_in)
    res = []
    # 入次数==0
    q = deque([i for i in list(G.keys()) if cnt_in[i]==0])
    while len(q) > 0:
        v = q.popleft()
        res.append(v)
        for next_v in G[v]:
            # 入次数を下げていく
            cnt_in[next_v] -= 1
            # 入次数が0に残ったところを次に追加
            if cnt_in[next_v] == 0:
                q.append(next_v)
    # トポソ不可能！
    if len(G) != len(res):
        print(-1)
        exit()
    return res

for i in range(n):
    r = list(map(int, input().split()))
    # 初期
    mn = min(i, r[0]-1)
    mx = max(i, r[0]-1)
    prev = mn * n + mx
    for e in r[1:]:
        e -= 1
        mn = min(i,e)
        mx = max(i,e)
        now = mn*n+mx
        edges[prev].append(now)
        edges_r[now].append(prev)
        prev = now
vs = topological_sort(edges)

# トポソの順番で経路長を入れていく
used = [0] * n**2
# for V in vs:
#     if used[V]: continue
#     used[V] = 1
#     q = deque([V])
#     while len(q) > 0:
#         v = q.popleft()
#         for u in edges[v]: 
#             if used[u] <= used[v]:
#                 q.append(u)
#                 used[u] = max(used[u], used[v] + 1)

for V in vs:
    if used[V]:continue
    used[V] = 1
    mx = 1
    for b in edges_r[V]:
        mx = max(mx, used[b]+1)
    used[V] = mx
# print(used)
print(max(used))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
A = []
for i in range(n):
    rs = list(map(int, input().split()))
    rs = [r-1 for r in rs]
    A.append(rs)

cnts = [0] * n
days = 1
while True:
    tekis = []
    # print("Day",days, cnts)
    fin = 0
    for cnt,a in zip(cnts, A):
        if cnt == n-1: 
            tekis.append(-1)
            fin += 1
        else: 
            tekis.append(a[cnt])
    if fin == n: 
        print(days-1)
        exit()
    # 敵の敵が自分だったらマッチング成立
    flg = False
    matched = [False] * n
    for i,teki in enumerate(tekis):
        if matched[teki] or teki==-1:continue
        if tekis[teki] == i:
            cnts[i] += 1
            matched[i] = True
            cnts[teki] += 1
            matched[teki] = True
            flg = True
            # print("{}vs{}".format(i,teki))
    # マッチングが一つも成立しない
    days > 50000:
        print(-1)
    if not flg:
        print(-1)
        exit()
    days += 1
Problem p02935 (python)

Fixed submission:

N = int(input())
vs  = sorted(list(map(int, input().split())))
ans = 0
ans = vs[0]+vs[1]
for i,v in enumerate(vs[2:]):
    ans += v*2**(i+1)
ans/=2**(N-1)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
vs = sorted(list(map(int,input().split())))
ans = (vs[0]+v[1])/2
for v in vs[2:]:
  ans = (ans + v)/2
print(ans)
Problem p02990 (python)

Fixed submission:
from operator import mul
from functools import reduce

N,K = map(int, input().split())
mod = 10**9 +7

if N - K > K - 1:
    m = K
else:
    m = N - K + 1

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

for i in range(1,K+1):
    if i <= m:
        a = cmb(K-1, i-1)%mod
        b = cmb(N-K+1, N-K-i+1)%mod
        print(a*b%mod)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
from scipy.special import comb
N,K = map(int, input().split())
mod = 10**9 +7
m = 0
if N - K > K - 1:
    m = K
else:
    m = N - K + 1

for i in range(1,m+1):
    a = comb(K-1, i-1, exact=True)%mod
    b = comb(N-K+1, N-K-i+1, exact=True)%mod
    print(a*b%mod)
Problem p03033 (python)

Fixed submission:

# 二部探索で決めていく。dpですでに見られたかどうかは把握
"""
工事 finish  1 eve削除
工事 start   2 eve追加
di start     3
この時間を混ぜてソート。上から順番に捌く
（区間がxi,xjで重なっていたらsetに入れられないのか。）

同じ時刻だった場合
工事finish -> 工事start -> di通過
の順番
"""
import sys
from operator import itemgetter
input = sys.stdin.readline
n,q  = map(int, input().split())
events = []
E = 10**10
for i in range(n):
    s,t,x = map(int, input().split())
    # st
    events.append((s-x,1,x))
    # gl
    events.append((t-x,0,x))
ds = [(int(input()),2,i) for i in range(q)]
events.extend(ds)
ans = [-1] * q
events.sort()
works = set()
upd = True
mn = 10**10
for t, e, x in events:
    if e == 1:
        works.add(x)
        if mn > x:
            mn = x
            upd = False
    elif e == 0:
        works.remove(x)
        if x == mn:
            upd = True
    else:
        if len(works) == 0:
            ans[x] = -1
        else:
            if upd:
                mn = min(works)
                upd = False
            ans[x] = mn
print(*ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
# 二部探索で決めていく。dpですでに見られたかどうかは把握
from bisect import bisect_left
n,q  = map(int, input().split())
events = []
"""
工事 start   0 eve追加
di start     2
工事 finish  1 eve削除
この時間を混ぜてソート。上から順番に捌く
（区間がxi,xjで重なっていたらsetに入れられないのか。）

同じ時刻だった場合
工事finish -> 工事start -> di通過
の順番
"""
for i in range(n):
    s,t,x = map(int, input().split())
    events.append((s-x,1,x))
    events.append((t-x,-1,x))
    
for i in range(q):
    d = int(input())
    events.append((d,2,i))
ans = [-1] * q
events.sort()
works = set()
for t, e, x in events:
    if e == 1:
        works.add(x)
    elif e == -1:
        works.remove(x)
    else:
        if len(works) == 0:
            ans[x] = -1
        else:
            ans[x] = min(works)
print(*ans)

Buggy submission (verdict: Runtime Error):
# 二部探索で決めていく。dpですでに見られたかどうかは把握
from bisect import bisect_left
n,q  = map(int, input().split())
imos = [0] * n
roadworks = []
for i in range(n):
    s,t,x = map(int, input().split())
    roadworks.append((s,t,x))
roadworks.sort()

ds = [(int(input()),i) for i in range(q)]  
ds.sort()
ix = [d[1] for d in ds]
ds = [d[0] for d in ds]
xs = [-1]*(n+10)
for s,t,x in roadworks:
    # print(s-x,t-x)
    l = bisect_left(ds,s-x-0.5)
    r = bisect_left(ds,t-x-0.5)
    for i in range(l,r):
        if xs[i] != -1:continue
        xs[i] = x
    # print("index",l,r)

for i in range(q):
    print(xs[i])
Problem p03038 (python)

Fixed submission:
import heapq
N,M = map(int,input().split())
As = list(map(int,input().split()))

As = sorted(As)
BCs = []
heapq.heapify(BCs)
for i in range(M):
    B,C =   map(int,input().split())
    heapq.heappush(BCs,(-C,B))

ind = 0
ans = 0
flg = False
for i in range(M):
    _C,B = heapq.heappop(BCs)
    for i in range(B):
        if As[ind+i] > -_C:
            flg = True
            ind += i
            break
        else:
            ans -= _C
        if ind+i+1 > N-1:
            flg = True
            ind += i+1
            break
    if flg: break
    ind += B
ans += sum(As[ind:])
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
N,M = map(int,input().split())
As = list(map(int,input().split()))

As = sorted(As)
BCs = []
heapq.heapify(BCs)
for i in range(M):
    B,C =   map(int,input().split())
    heapq.heappush(BCs,(-C,B))

ind = 0
ans = 0
flg = False
for i in range(M):
    _C,B = heapq.heappop(BCs)
    for i in range(B):
        if As[ind+i] > -_C:
            flg = True
            ind += i
            break
        else:
            ans -= _C
    if flg: break
    ind += B
ans += sum(As[ind:])
print(ans)
Problem p03104 (python)

Fixed submission:
N,M = map(int,input().split())
def xor_sum(N):
    N+=1
    value = 0
    value += (N//2)%2 # 2^0の位
    for i in range(1,40):
        # print(N%(2**(i+1))-2**i)
        cnt = max(0,N%(2**(i+1))-2**i) #mod2^(i+1)のcnt
        value += (cnt%2) * 2**i
    return value

# print(xor_sum(3))
print(xor_sum(M)^xor_sum(N-1))

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
print(int(bin(N^M),2)
Problem p03108 (python)

Fixed submission:
class UnionFind:
    def __init__(self, n):
        self.par = [-1 for i in range(n+1)]
        self.size = [1 for i in range(n+1)]
    # 検索
    def find(self, x):
        path = []
        curr = x
        # 親ノードの手前で止まる(どの根に紐づくかの情報を持ちながら)
        while self.par[curr] != -1:
            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)
            path.append(curr)
            curr = self.par[curr]
        for p in path:
            self.par[p] = curr
        return curr

    # 結合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        self.par[y] = x
        self.size[x] += self.size[y]
        self.size[y] = 1

    # 判定
    def judge(self,x,y):
        return self.find(x) == self.find(y)

N, M = map(int,input().split())
pairs = [tuple(map(int,input().split())) for _ in range(M)]
uf = UnionFind(N)
p = N*(N-1)//2
ans = [p]
for a,b in reversed(pairs[1:]):
    if not uf.judge(a,b):
        size_a = uf.size[uf.find(a)]
        size_b = uf.size[uf.find(b)]
        uf.union(a,b)
        size_a_update = uf.size[uf.find(a)]
        p = p + size_a*(size_a-1)//2 + size_b*(size_b-1)//2 - size_a_update*(size_a_update-1)//2

    ans.append(p)
for a in reversed(ans):
    print(a)

Buggy submission (verdict: Runtime Error):

from scipy.misc import comb


N, M = map(int,input().split())
pairs = []
for i in range(M):
    Ai, Bi = map(int,input().split())
    pairs.append([Ai,Bi])
connections = []
ans = [int(comb(N,2),exact=True)]
for Ai, Bi in pairs[::-1]:
    # connect_flg = False
    ind = []
    for i,connection in enumerate(connections):
        if Ai in connection and Bi in connection:
            ind = [0]
            continue
        elif Ai in connection:
            connections[i].append(Bi)
            # connect_flg = True
            ind.append(i)
        elif Bi in connection:
            connections[i].append(Ai)
            # connect_flg = True
            ind.append(i)
    # ２つをつなぐものは、一つにまとめる
    if len(ind) == 2:
        connections[ind[0]].extend(connections[ind[1]])
        connections[ind[0]] = list(set(connections[ind[0]]))
        connections.remove(connections[ind[1]])            
    elif len(ind) == 0:
        connections.append([Ai,Bi])
    # 不便度の計算
    cnt = int(comb(N,2,exact=True))
    # print(connections,cnt)
    for connection in connections:
        cnt -= int(comb(len(connection),2,exact=True))
    ans.append(cnt)
for a in ans[::-1][1:]:
    print(a)
Problem p03221 (python)

Fixed submission:
from collections import defaultdict
from bisect import bisect_left
N, M = map(int, input().split())
A = []
B = defaultdict(list)
 
for i in range(M):
    p, y = map(int, input().split())
    A.append([p, y])
    B[p].append(y)
 
for key in B.keys():
    B[key].sort()

# print(A,B)
# for a in A:
#     print(a[0],a[1],B[a[0]],bisect_left(B[a[0]],a[1]))
for a in A:
    print("%06d%06d" % (a[0], bisect_left(B[a[0]], a[1])+1))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from bisect import bisect_left
N, M = map(int, input().split())
A = []
B = defaultdict(list)
 
for i in range(M):
    p, y = map(int, input().split())
    A.append([p, y])
    B[p].append(y)
 
for key in B.keys():
    B[key].sort()

print(A,B)
for a in A:
    print(a[0],a[1],B[a[0]],bisect_left(B[a[0]],a[1]))
for a in A:
    print("%06d%06d" % (a[0], bisect_left(B[a[0]], a[1])+1))

Buggy submission (verdict: Runtime Error):
import numpy as np
N, M = map(int,input().split())
Ps = [[] for _ in range(N)]
for i in range(M):
    j, Y = map(int,input().split())
    Ps[j-1].append([i,Y])

rets = [""]*M
for i,P in enumerate(Ps):
    inds = np.array(P)[:,0]
    years = np.array(P)[:,1]
    sorts = np.argsort(years)
    for (j,y,s) in zip(inds,years,sorts):
        rets[j] = "{:06d}{:06d}".format(i+1,s+1)
for ret in rets:
    print(ret)
Problem p03253 (python)

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

# 素因数分解(小さい方から順に割っていく。sqrt(2)まで)
def factorize(n):
    i = 2
    table = [0]
    cnt= [0]
    while i * i <= n:
        while n % i == 0:
            n /= i
            if table[-1] != i:
                table.append(i)
                cnt.append(0)
            cnt[-1] += 1
        i += 1
    if n > 1:
        table.append(n)
        cnt.append(1)
    return table,cnt


fs,ns = factorize(M)
ans = 1
for n in ns[1:]:
    a = 1
    for i in range(N,n+N):
        a *= i
    ans *= a//factorial(n)
print(ans%(10**9+7))

Buggy submission (verdict: Runtime Error):
"""
8:30:00
"""

from collections import defaultdict
def getprime(n):
    if not isinstance(n, int):
        raise TypeError("Input int")
    if n < 2:
        raise ValueError("N >= 2")
    prime = []
    # 約数はsqrt(N)まで調べればOK
    data = [i+1 for i in range(1,n)]
    while True:
        p = data[0]
        if p >= int(n**0.5):
            return prime+data
        prime.append(p)
        # pで割り切れないものだけを残す
        data = [d for d in data if d%p != 0]

def factorization(n):
    factors = defaultdict(int)
    primes = getprime(int(n**0.5))
    for prime in primes:
        while n % prime == 0:
            factors[prime] += 1
            n //= prime
            # print(factors,n)
    if n != 1:
        factors[n] += 1
    return factors


def modconb(n,k,mod):
    # テーブルを作る
    fac = [0]*(n+1)
    finv = [0]*(n+1)
    inv = [0]*(n+1)  

    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1

    for i in range(2,n+1):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod%i] * (mod//i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

    if n<k: return 0
    if n<0 or k<0: return 0
    return(fac[n]*(finv[k]*finv[n-k]%mod)%mod)

"""
1 * 1 * 1のどこに素因数をかけるか
3^3だとして
どこかで3回3をかけないといけない
a + b + c = 3 //重複組合せ
3*3-1C3
こいつをかけ合わせると答えになる
modconbいる
"""

mod = 10**9 + 7
n, m = map(int, input().split())

factors = factorization(m)
ans = 1
for k in factors.keys():
    x = factors[k]
    ans *= modconb(x+n-1,x,mod)
    ans %= mod
print(ans)
Problem p03295 (python)

Fixed submission:
"""
- N個の島とN-1個の橋
- i番目の橋は島iと島i+1を接続する
- ai番目とbi番目の島の間での諍いを止めたい
    - aiとbi番目の島を隔離する
- こんな要望がM個

始点と終点が必要そうだから、2次元に値を保存してみる⇨遅い。ダメ
"""
import heapq
N,M = map(int, input().split())

# たくさん値を持っておく必要はない
# 左端を固定しながら、右端の一番近いところを算出していく
# 一番近いところを切れれば、それより遠いところも自ずと切れる
dic = {}
for i in range(M):
    a, b = map(int, input().split())
    if a not in dic or dic[a] > b:
        dic[a] = b

# 条件が厳しい右から考えていくパターン
# a,bで考えて,まだ着られていない(最後に切られたposより右にある)なら、aで切る(最も左端)
# 切った左端よりも左側にあるならもう一回切る必要がある。そうじゃないなら切る必要なし
cnt = 0
pos = 1000000000000
for j in sorted(dic.keys(),reverse=True): # 降順に並べる(右側から)
    if dic[j] <= pos:
        cnt += 1
        pos = j
print(cnt)

Buggy submission (verdict: Runtime Error):
from operator import itemgetter
bridges = []
for i in range(M):
    bridges.append(list(map(int, input().split())))
bridges.sort(key=itemgetter(1))
b_right = 0
cnt = 0
for a,b in bridges:
    if a > b_right:
        b_right = b - 1
        cnt += 1
print(cnt)
Problem p03307 (python)

Fixed submission:
def gcd(n, m):
    # 最大公約数
    a = max(n,m)
    b = min(n,m)
    while b:
        a, b = b, a % b
    return a

n = int(input())
print(2*n//gcd(2,n))

Buggy submission (verdict: Runtime Error):
def gcd(n, m):
    # 最大公約数
    a = max(n,m)
    b = min(n,m)
    while b:
        a, b = b, a % b
    return a

n = input()
print(2*n/gcd(2,n))
Problem p03426 (python)

Fixed submission:
H,W,D = map(int, input().split())
fields = []
amaris = [[0] * (H*W//D+1) for i in range(D)] # あまり
for i in range(H):
    row = list(map(int, input().split()))
    # あまりがいくつかで分類
    for j,e in enumerate(row):
        n = (e-1) // D
        m = (e-1) % D
        amaris[m][n] = (i,j)

# あまりごとに累積和を取っておく
acc = [[0] * (H*W//D+1) for i in range(D)]
for i in range(D):
    cnt = 0
    x_pre, y_pre = amaris[i][0]
    for j in range(1,(H*W)//D+1):
        coords = amaris[i][j]
        if isinstance(coords,int): break
        x = coords[0]
        y = coords[1]
        cnt += abs(x-x_pre)+abs(y-y_pre)
        acc[i][j] = cnt
        x_pre = x
        y_pre = y
# print(acc)

Q = int(input())
for i in range(Q):
    l,r  = map(int, input().split())
    m = (l-1) % D
    s = (l-1) // D
    g = (r-1) // D
    ans = acc[m][g] - acc[m][s]
    print(ans)

Buggy submission (verdict: Runtime Error):
H,W,D = map(int, input().split())
fields = []
amaris = [[0] * (H*W)//D+1 for i in range(D)] # あまり
for i in range(H):
    row = list(map(int, input().split()))
    # あまりがいくつかで分類
    for j,e in enumerate(row):
        n = (e-1) // D
        m = (e-1) % D
        amaris[m][n] = (i,j)

# print(amaris[:10])
# あまりごとに累積和を取っておく
acc = [[0] * (H*W)//D+1 for i in range(D)]
for i in range(D):
    cnt = 0
    x_pre, y_pre = amaris[i][0]
    for j in range(1,(H*W)//D+1):
        coords = amaris[i][j]
        if isinstance(coords,int): break
        x = coords[0]
        y = coords[1]
        cnt += abs(x-x_pre)+abs(y-y_pre)
        acc[i][j] = cnt
        x_pre = x
        y_pre = y

# print(acc)

Q = int(input())
for i in range(Q):
    l,r  = map(int, input().split())
    m = (l-1) % D
    s = (l-1) // D
    g = (r-1) // D
    ans = acc[m][g] - acc[m][s]
    print(ans)

Buggy submission (verdict: Runtime Error):
H,W,D = map(int, input().split())
fields = []
amaris = [[0] * (H*W) for i in range(D)] # あまり
for i in range(H):
    row = list(map(int, input().split()))
    # あまりがいくつかで分類
    for j,e in enumerate(row):
        n = (e-1) // D
        m = (e-1) % D
        amaris[m][n] = (i,j)

# print(amaris[:10])
# あまりごとに累積和を取っておく
acc = [[0] * (H*W) for i in range(D)]
for i in range(D):
    cnt = 0
    x_pre, y_pre = amaris[i][0]
    for j in range(1,(H*W)//D+1):
        coords = amaris[i][j]
        if isinstance(coords,int): break
        x = coords[0]
        y = coords[1]
        cnt += abs(x-x_pre)+abs(y-y_pre)
        acc[i][j] = cnt
        x_pre = x
        y_pre = y


Q = int(input())
for i in range(Q):
    l,r  = map(int, input().split())
    m = (l-1) % D
    s = (l-1) // D
    g = (r-1) // D
    ans = acc[m][g] - acc[m][s]
    print(ans)
Problem p03464 (python)

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

def f(n):
    for a in As:
        n = a * (n//a)
    return n

ng,ok = 1, 10**20
while ok-ng > 1:
    m = (ok+ng)//2
    if f(m) >= 2: #2以上ならTrue
        ok = m
    else:
        ng = m
mn = ok
# print(ng,ok)

ok,ng = 1, 10**20
while ng-ok > 1:
    m = (ok+ng)//2
    if f(m) <= 2: #2以下の範囲
        ok = m
    else:
        ng = m
mx = ok

# print(ok,ng)
if mn > mx:
    print(-1)
else:
    print(mn,mx)

Buggy submission (verdict: Runtime Error):
n = int(input())
As = list(map(int, input().split()))
    
def f(m):
    debug = m
    for a in As:
        i = m // a
        m = i * a
    return m

# 二部探索?
l = 1
r = 10**5+1
while r-l > 1:
    m = (r+l)//2
    if f(m) <= 1: l = m
    else: r = m
ans1 = r
l = 1
r = 10**5 + 1
while r-l > 1:
    m = (r+l)//2
    if f(m) <= 2: l= m
    else: r = m
ans2 = l

if ans1 >= ans2:
    print(-1)
else:
    print(ans1[1],ans2[0])
Problem p03724 (python)

Fixed submission:
"""
rootを決めて、aから必ずrootを通ってbに到達するとする
aとbのlcaより上は、+2されることになるので、実質通っていないのと同値
どんな木であっても、自分自身が偶数回(0を含む)でてこないと
ノードの値は偶数にはなりえない
"""
n, m = map(int, input().split())
cnts = [0] * (n+1) 
for i in range(m):
    a,b = map(int, input().split())
    cnts[a] += 1
    cnts[b] += 1
if all([c%2 == 0 for c in cnts]):
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
"""
rootを決めて、aから必ずrootを通ってbに到達するとする
aとbのlcaより上は、+2されることになるので、実質通っていないのと同値
どんな木であっても、自分自身が偶数回(0を含む)でてこないと
ノードの値は偶数にはなりえない
"""
n, m = map(int, input().split())
cnts = [0] * (n+1) 
for i in range(n):
    a,b = map(int, input().split())
    cnts[a] += 1
    cnts[b] += 1
if all([c%2 == 0 for c in cnts]):
    print("YES")
else:
    print("NO")
Problem p02572 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
c=0
d=sum(A)
for i in range(0,N-1):
    d-=A[i]
    c+=A[i]*d
    if(c>10**9+7):
        c%=(10**9+7)
print(c)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
A2=0
for i in ragne(len(A)):
  A2+=A[i]**2
c=(sum(A))**2-A2
print(c//2)
Problem p02578 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
c=0
for i in range(N-1):
  j=i+1
  if A[j]<A[j-1]:
    gap=A[j-1]-A[j]
    c+=gap
    A[j]+=gap
    
print(c)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
MOD=10**9+7
c=0
for i in range(len(A)):
  c+=A[i]*(pow(sum(A)-A[i],-1,MOD)
print(c//2%MOD)
Problem p02707 (python)

Fixed submission:
N = int(input())
A = map(int,input().split())
c=[]
for i in range (N):
  c.append(0)
for j in A:
  c[j-1]+=1

for C in c:
  print(C)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = map(int,input().split())
c=[]
for i in range N:
  c[i]=0
for j in A:
  c[j-1]+=1

for C in c:
  print(C)
Problem p02711 (python)

Fixed submission:
N = input()
if N[0]!=('7') and N[1]!=('7') and N[2]!=('7'):
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
N= input()
for i in range 3:
  if N[i]=='7':
    print('Yes')
    exit()

print('No')
Problem p02835 (python)

Fixed submission:
A,B,C =map(int,input().split())
if A+B+C>=22:
  print('bust')
else:
  print('win')

Buggy submission (verdict: Runtime Error):
A,B,C = int(input())
if A+B+C >=22:
  print('bust')
else:
  print('win')
Problem p03265 (python)

Fixed submission:
a,b,c,d=map(int,input().split())
e=(d-b)
f=(c-a)
print(c-e,d+f,a-e,b+f)

Buggy submission (verdict: Runtime Error):
a,b,c,d=map(int,input(),split())
e=(d-b)
f=(c-a)
print(c-e,d+f,a-e,b+f)