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

Fixed submission:
N = int(input())
xys = []
for i in range(N):
    x,y = map(int, input().split())
    xys.append((x,y))

xys.sort()
diffs = []
count = []
# 全探索して、一番共通項が多い差分から計算する
for i in range(N):
    for j in range(i+1,N):
        x1,y1 = xys[i]
        x2,y2 = xys[j]
        diff = (x1-x2, y1-y2)
        if diff not in diffs:
            diffs.append(diff)
            count.append(1)
        else:
            k = diffs.index(diff)
            count[k] += 1
if N == 1:
    print(1)
else:
    print(N-max(count))

Buggy submission (verdict: Runtime Error):
N = int(input())
xys = []
for i in range(N):
    x,y = map(int, input().split())
    xys.append((x,y))

xys.sort()
diffs = []
count = []
# 全探索して、一番共通項が多い差分から計算する
for i in range(N):
    for j in range(i+1,N):
        x1,y1 = xys[i]
        x2,y2 = xys[j]
        diff = (x1-x2, y1-y2)
        if diff not in diffs:
            diffs.append(diff)
            count.append(1)
        else:
            k = diffs.index(diff)
            count[k] += 1

print(N-max(count))
Problem p03014 (python)

Fixed submission:
H,W = map(int,input().split())
S = [input() for i in range(H)]

# 4方向の累積和をとって計算する
Rs = [[0]*W for i in range(H)]
Ls = [[0]*W for i in range(H)]
Ds = [[0]*W for i in range(H)]
Us = [[0]*W for i in range(H)]

for i in range(H):
    tmp = 0
    # 順方向(左にどれだけ伸びてるか)
    for j in range(W):
        if S[i][j] == '#':
            tmp = 0
        else:
            tmp += 1
            Ls[i][j] = tmp
    tmp = 0
    # 逆方向(右にどれだけ伸びてるか)
    for j in reversed(range(W)):
        if S[i][j] == '#':
            tmp = 0
        else:
            tmp += 1
            Rs[i][j] = tmp

# 行列転置 順番逆にするだけ
for j in range(W):
    tmp = 0
    # 順方向 上にどれだけ伸びているか
    for i in range(H):
        if S[i][j] == '#':
            tmp = 0
        else:
            tmp += 1
            Us[i][j] = tmp
    tmp = 0
    # 順方向 下にどれだけ伸びているか
    for i in reversed(range(H)):
        if S[i][j] == '#':
            tmp = 0
        else:
            tmp += 1
            Ds[i][j] = tmp

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#': 
            continue
        # 上下左右に伸びた数を重なっている部分引く
        tmp = Rs[i][j] + Ls[i][j] + Ds[i][j] + Us[i][j] - 3
        ans = max(ans, tmp)
print(ans)

Buggy submission (verdict: Runtime Error):

"""
左・上からゴリゴリ攻めていくパターン
一回通ったかどうかのフラグが必要
"""

cnt = [[0] * (W+1) for i in range(H+1)]
# 横
for i in range(H):
    done = [False] * (W+1)
    for j in range(W):
        l = 0
        if done[j]: continue
        if S[i][j] == ".":
            while j+l < W:
                if S[i][j+l] == ".":
                    l += 1
                else:
                    break
        for k in range(j,j+l):
            cnt[i][k] += l
            done[k] = True

# 縦
for j in range(W):
    done = [False] * (H+1)
    for i in range(H):
        l = 0
        if done[i]: continue
        if S[i][j] == ".":
            while i+l < H:
                if S[i+l][j] == ".":
                    l += 1
                else:
                    break
        for k in range(i,i+l):
            cnt[k][j] += l
            done[k] = True

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans,cnt[i][j])
print(ans-1)
Problem p03037 (python)

Fixed submission:
N, M = map(int,input().split())
Ls,Rs = [],[]
for i in range(M):
    L,R = map(int,input().split())
    Ls.append(L)
    Rs.append(R)

print(max(0,min(Rs)-max(Ls)+1))

Buggy submission (verdict: Runtime Error):
"""
imos
"""
N, M = map(int,input().split())

from itertools import accumulate
imos = [0]*(N+1)
for i in range(M):
    L,R = map(int,input().split())
    imos[L] += 1
    imos[R+1] -= 1
acc = list(accumulate(imos))
print(sum([1 for a in acc if a == M]))
Problem p03039 (python)

Fixed submission:

"""
xi,xjのペアにおいて、このペアは何通り出てくるか
sum(全通り)sum(i)sum(j){|xi-xj|+|yi-yj|}
和なので、どんな順序でもいい

sum(i)sum(j)sum(全通り){|xi-xj|}
sum(i)sum(j)sum(全通り){|yi-yj|}

あるi,jで固定して、sum(全通り){|xi-xj|}を求めるヤツ
固定したi,jが現れる回数は、

pat = NM-2_C_K-2 こいつはどこでも一緒

pat*sum(i)sum(j){|xi-xj|}を計算する
すべてのi,j(i>j)ペアにおいて、xi,xjの和は
sum(i=1,N){i*(N-i)}
"""
from math import factorial

N,M,K = map(int,input().split())
mod = 10**9+7
fa = 1
num = N*M - 2
# 固定したときの通り数
# フェルマーの小定理をつかって、mod(M)でのcombinationが高速で求まる
# http://keita-matsushita.hatenablog.com/entry/2016/12/05/184011
def mod_combination(n,r,mod):
    if n<0 or r<0 or n<r:
        return 0
    if n==0 or r == 0:
        return 1
    a = factorial(n) % mod
    b = factorial(r) % mod
    c = factorial(n-r) % mod
    return (a*pow(b,mod-2,mod)*pow(c,mod-2,mod)) % mod 

pat = mod_combination(N*M-2,K-2,mod)

n_x = M**2*((N-1)*N*(N+1))//6
n_y = N**2*((M-1)*M*(M+1))//6
print(pat*(n_x+n_y)%mod)

Buggy submission (verdict: Runtime Error):

"""
xi,xjのペアにおいて、このペアは何通り出てくるか
sum(全通り)sum(i)sum(j){|xi-xj|+|yi-yj|}
和なので、どんな順序でもいい

sum(i)sum(j)sum(全通り){|xi-xj|}
sum(i)sum(j)sum(全通り){|yi-yj|}

あるi,jで固定して、sum(全通り){|xi-xj|}を求めるヤツ
固定したi,jが現れる回数は、

pat = NM-2_C_K-2 こいつはどこでも一緒

pat*sum(i)sum(j){|xi-xj|}を計算する
すべてのi,j(i>j)ペアにおいて、xi,xjの和は
sum(i=1,N){i*(N-i)}
"""
from math import factorial

N,M,K = map(int,input().split())
mod = 10**9+7
fa = 1
num = N*M - 2
# 固定したときの通り数
cut = min(K-2, N*M-K)]
# このfor文は少ないほうが良い
for i in range(num,1,-1):
    if num-i == cut:
        break
    fa *= i
pat = fa//factorial(cut)

# print(pat)
# xi-xj
n_x = M**2*((N-1)*N*(N+1))//6
n_y = N**2*((M-1)*M*(M+1))//6
print(pat*(n_x+n_y)%mod)
Problem p03046 (python)

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


if M == 1 and K == 1:
    print(-1)
elif M==1 and K == 0:
    print("0 0 1 1")
elif K >= 2**M:
    print(-1)
else:
    M = [i for i in range(2**M)]
    M.remove(K)
    ans = M + [K] + M[::-1] + [K]
    anstr = ""
    for a in ans:
        anstr += str(a) + " "
    print(anstr[:-1])

Buggy submission (verdict: Runtime Error):
M, K = map(int,input().split())


if M == 1 and K == 1:
    print(-1)
elif M==1 and K == 0:
    print("0 0 1 1")
elif K >= 2**M:
    print(-1)
else:
    else:
        M = [i for i in range(2**M)]
        M.remove(K)
        ans = M + [K] + M[::-1] + [K]
        anstr = ""
        for a in ans:
            anstr += str(a) + " "
        print(anstr[:-1])
Problem p03068 (python)

Fixed submission:
N = int(input())
S = input()
K = int(input())

letter = S[K-1]

ans = ""
for s in S:
    if s != letter:
        ans += "*"
    else:
        ans += s
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
K = int(input())

letter = S[K]
ans = ""
for s in S:
    if s != letter:
        ans += "*"
    else:
        ans += s
print(ans)
Problem p03074 (python)

Fixed submission:
from itertools import accumulate

N, K = map(int,input().split())
S = input()

nums = []
tmp = "1" #はじめに0が入ったら、0からスタートというのがわかる。
count = 0
for s in S:
    if tmp == s:
        count += 1
    else:
        nums.append(count)
        count = 1
        tmp = s
nums.append(count)
if tmp == "0":
    nums.append(0) #エッジの条件

# print(nums)
# 累積和表示にする(listって足し算できるのね)
# これによって、各文字最初の値が明らかになる
acc = [0]+list(accumulate(nums))
# print(acc)
n = len(nums)
w = 2*K + 1

if len(nums) <= w:
    print(N)
else:
    ans = 0
    for i in range(0,n-w+1,2): #2個飛ばし
        ans = max(ans,acc[i+w]-acc[i])

    print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate

N, K = map(int,input().split())
S = input()

nums = []
tmp = "1" #はじめに0が入ったら、0からスタートというのがわかる。
count = 0
for s in S:
    if tmp == s:
        count += 1
    else:
        nums.append(count)
        count = 1
        tmp = s
nums.append(count)
if tmp == "0":
    l.append(0) #エッジの条件

# print(nums)
# 累積和表示にする(listって足し算できるのね)
# これによって、各文字最初の値が明らかになる
acc = [0]+list(accumulate(nums))
# print(acc)
n = len(nums)
w = 2*K + 1

if len(nums) <= w:
    print(N)
else:
    ans = 0
    for i in range(0,n-w+1,2): #2個飛ばし
        ans = max(ans,acc[i+w]-acc[i])

    print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate

N, K = map(int,input().split())
S = input()

nums = []
tmp = "1" #はじめに0が入ったら、0からスタートというのがわかる。
count = 0
for s in S:
    if tmp == s:
        count += 1
    else:
        nums.append(count)
        count = 1
        tmp = s
nums.append(count)

# print(nums)
# 累積和表示にする(listって足し算できるのね)
# これによって、各文字最初の値が明らかになる
acc = [0]+list(accumulate(nums))
# print(acc)
n = len(nums)
w = min(2*K + 1)

ans = 0
for i in range(0,n-w+1,2): #2個飛ばし
    ans = max(ans,acc[i+w]-acc[i])
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate

N, K = map(int,input().split())
S = input()

nums = []
tmp = "1" #はじめに0が入ったら、0からスタートというのがわかる。
count = 0
for s in S:
    if tmp == s:
        count += 1
    else:
        nums.append(count)
        count = 1
        tmp = s
nums.append(count)

# print(nums)
# 累積和表示にする(listって足し算できるのね)
# これによって、各文字最初の値が明らかになる
acc = [0]+list(accumulate(nums))
# print(acc)
n = len(nums)
w = min(2*K + 1)

ans = 0
for i in range(0,n-w+1,2): #2個飛ばし
    ans = max(ans,acc[i+w]-acc[i])
print(ans)
Problem p03078 (python)

Fixed submission:
# どうやって自明な条件で計算量を落としていくか
# 不等式に注目。pythonが耐えるのは10^6程度
X,Y,Z,K = map(int,input().split())
As = sorted(list(map(int,input().split())),reverse=True)
Bs = sorted(list(map(int,input().split())),reverse=True)
Cs = sorted(list(map(int,input().split())),reverse=True)

# ABでソート
AB = []
for A in As:
    for B in Bs:
        AB.append(A+B)
ABs = sorted(AB,reverse=True)

# その中からK番目まで
ABC = []
for i in range(min(len(ABs),K)):
    for C in Cs:
        ABC.append(ABs[i]+C)

ABCs = sorted(ABC,reverse=True)
for i in range(K):
    print(ABCs[i])

Buggy submission (verdict: Runtime Error):
# どうやって自明な条件で計算量を落としていくか
# 不等式に注目。pythonが耐えるのは10^6程度
import numpy as np
X,Y,Z,K = map(int,input().split())
As = sorted(list(map(int,input().split())),reverse=True)
Bs = sorted(list(map(int,input().split())),reverse=True)
Cs = sorted(list(map(int,input().split())),reverse=True)

# ABでソート
AB = []
for A in As:
    for B in Bs:
        AB.append(A+B)
ABs = sorted(AB,reverse=True)

# その中からK番目まで
ABC = []
for i in range(min(len(ABs),K)):
    for C in Cs:
        ABC.append(ABs[i]+C)

ABCs = sorted(ABC,reverse=True)
for i in range(K):
    print(ABCs[i])

Buggy submission (verdict: Runtime Error):
# どうやって自明な条件で計算量を落としていくか
# 不等式に注目。pythonが耐えるのは10^6程度
import numpy as np
X,Y,Z,K = map(int,input().split())
As = sorted(list(map(int,input().split())),reverse=True)
Bs = sorted(list(map(int,input().split())),reverse=True)
Cs = sorted(list(map(int,input().split())),reverse=True)

# ABでソート
AB = []
for A in As:
    for B in Bs:
        AB.append(A+B)
ABs = sorted(AB,reverse=True)

# その中からK番目まで
ABC = []
for i in range(min(len(AB),K)):
    for C in Cs:
        ABC.append(AB[i]+C)

ABCs = sorted(ABC,reverse=True)
for i in range(K):
    print(ABCs[i])
Problem p03096 (python)

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
cs = [int(input()) for _ in range(n)]

from collections import defaultdict
prev = -1
c_comp = []
# 連続する色はまとめて良い
for c in cs:
    if prev != c:
        c_comp.append(c)
    prev = c

d = defaultdict(list)
for i,c in enumerate(c_comp):
    d[c].append(i)


dp = [0] * 220000
mod = 10**9 + 7

# 何個目まで見たか
inds = defaultdict(int)
ans = 0
dp[0] = 1
for i,c in enumerate(c_comp):
    i_prev = d[c][inds[c]-1]
    if inds[c] >= 1:
        # かぶっていないそれ以前の場合の数を足す
        dp[i+1] += dp[i] + dp[i_prev+1]
    else:
        # 前の色が無い or 異なる場合はなにもしない
        dp[i+1] = dp[i]
    dp[i+1] %= mod
    inds[c] += 1
print(dp[len(c_comp)])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
cs = [int(input()) for _ in range(n)]

from collections import defaultdict
prev = -1
c_comp = []
# 連続する色はまとめて良い
for c in cs:
    if prev != c:
        c_comp.append(c)
    prev = c

d = defaultdict(list)
for i,c in enumerate(c_comp):
    d[c].append(i)


dp = [0] * 110000
mod = 10**9 + 7

# 何個目まで見たか
inds = defaultdict(int)
ans = 0
dp[0] = 1
for i,c in enumerate(c_comp):
    i_prev = d[c][inds[c]-1]
    if inds[c] >= 1:
        # かぶっていないそれ以前の場合の数を足す
        dp[i+1] += dp[i] + dp[i_prev+1]
    else:
        # 前の色が無い or 異なる場合はなにもしない
        dp[i+1] = dp[i]
    dp[i+1] %= mod
    inds[c] += 1
print(dp[len(c_comp)])
Problem p03106 (python)

Fixed submission:
A,B,K = map(int,input().split())
cnt = 0
l = []
for i in range(max(A+1,B+1),0,-1):
    if A%i == 0 and B%i == 0:
        cnt +=1
        if cnt == K:
            ans = i
            break
print(ans)

Buggy submission (verdict: Runtime Error):
A,B,K = map(int,input().split())
cnt = 1
l = []
for i in range(2,max(A+1,B+1)):
    if A%i == 0 and B%i == 0:
        l.append(i)
if K == 1:
    ans = 1
else:
    ans = l[-K]
print(ans)
Problem p03112 (python)

Fixed submission:
from bisect import bisect_right as binarysearch
A, B, Q = map(int,input().split())

ss = [-10**10]+[int(input()) for _ in range(A)]+[2*10**10]
ts = [-10**10]+[int(input()) for _ in range(B)]+[2*10**10]
xs = [int(input()) for _ in range(Q)]
for x in xs:
    sind = binarysearch(ss,x)-1
    tind = binarysearch(ts,x)-1
    
    s0,s1,t0,t1 = ss[sind],ss[sind+1],ts[tind],ts[tind+1]
    d1,d2,d3,d4 = 10**10,10**10,10**10,10**10

    d1 = max(x-s0,x-t0)
    d2 = min((t1-x)*2+(x-s0),(x-s0)*2+(t1-x))
    d3 = min((s1-x)*2+(x-t0),(x-t0)*2+(s1-x))
    d4 = max(s1-x, t1-x)
    print(min(d1,d2,d3,d4))

Buggy submission (verdict: Runtime Error):
A, B, Q = map(int,input().split())

ss = [-10**10]+[int(input()) for _ in range(A)]+[2*10**10]
ts = [-10**10]+[int(input()) for _ in range(B)]+[2*10**10]
xs = [int(input()) for _ in range(Q)]

def binarysearch(ls,x):
    n = len(ls)
    width = n//2
    pos = n//2
    while True:
        width = (width+1)//2
        if ls[pos] < x < ls[pos+1]:
            index = pos
            break    
        elif x < ls[pos]:
            pos -= width
        elif ls[pos+1] < x:
            pos += width
    return index

for x in xs:
    sind = binarysearch(ss,x)
    tind = binarysearch(ts,x)
    
    s0,s1,t0,t1 = ss[sind],ss[sind+1],ts[tind],ts[tind+1]
    d1,d2,d3,d4 = 10**10,10**10,10**10,10**10
    
    d1 = max(x-s0,x-t0)
    d2 = min((t1-x)*2+(x-s0),(x-s0)*2+(t1-x))
    d3 = min((s1-x)*2+(x-t0),(x-t0)*2+(s1-x))
    d4 = max(s1-x, t1-x)
    print(min(d1,d2,d3,d4))
Problem p03160 (python)

Fixed submission:
import numpy as np
N = int(input())
hs = [int(i) for i in input().split()]
dp = np.zeros(N)
for i,h in enumerate(hs):
    if i == 0:        
        # 0は初期化されている
        dp[i] = 0
        continue
    elif i == 1:
        # 1は1通りしか無い
        dp[i] = dp[i-1] + abs(hs[i-1]-h)
    else:
        # 1個前か2個前で、コストが最小になるやつ
        dp[i] = min(dp[i-1]+abs(hs[i-1]-h),dp[i-2]+abs(hs[i-2]-h))
# print(dp)
print(int(dp[-1]))

Buggy submission (verdict: Runtime Error):

"""
dp[i] : 足場iに到達するにあたって、たどり着く最小回数
"""
INF = 10**10
dp = [INF]*11000
N = int(input())
hs  = list(map(int, input().split())) + [INF,INF]
dp[0] = 0
for i in range(N):
    dp[i+1] = min(dp[i+1], dp[i]+abs(hs[i+1]-hs[i]))
    dp[i+2] = min(dp[i+2], dp[i]+abs(hs[i+2]-hs[i]))
print(dp[N-1])
Problem p03161 (python)

Fixed submission:
N, K = map(int,input().split())
hs = [int(i) for i in input().split()]

dp = [1000000]*N
dp[0] = 0
for i in range(1,N):
    # for k in range(K+1):
    x = max(0, i-K)
    # dp[i] = min(dp[i], dp[min_ind]+abs(hs[min_ind]-hs[i]))
    dp[i] = min([dpj + abs(hs[i] - hj) for hj, dpj in zip(hs[x:i], dp[x:i])])
# print(dp)
print(dp[-1])

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
hs = [int(i) for i in input().split()]

dp = [1000000]*N
dp[0] = 0
for i in range(1,N):
    min_ind = max(0, i-K)
    dp[i] = min(dp[i], dp[min_ind]+abs(hs[min_ind]-hs[i]))
    for k in range(1,K+1):
        dp[i] = min(dp[i], dp[i-k]+abs(hs[i-k]-hs[i]))

print(dp[-1])
Problem p03238 (python)

Fixed submission:
N = int(input())
if N == 1:
    print("Hello World")
else:
    A = int(input())
    B = int(input())
    print(A+B)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
data = np.zeros((N,3))
for i in range(N):
    data[i] = np.array(input().split())

for n in range(10201):
    C_x = n // 101
    C_y = n % 101
    correctflg = True
    unsetflg = True
    for i,(x,y,h) in enumerate(data):
        if unsetflg:
            if h >= 1:
                H = abs(x-C_x)+abs(y-C_y)+h
                unsetflg = False
        else:
            if h >= 1 and H != abs(x-C_x)+abs(y-C_y)+h:
                correctflg = False
                break 
    if correctflg:
        print(C_x,C_y,int(H))
        break
Problem p03240 (python)

Fixed submission:
import numpy as np
N = int(input())
data = np.zeros((N,3))
for i in range(N):
    data[i] = np.array(input().split())

# data = np.array([[2,3,0],[2,1,0],[1,2,0],[3,2,5]])

if len(np.where(data[:,2]!=0)[0]) == 1:
    C_x, C_y, H = map(int,data[np.where(data[:,2]!=0)[0][0]])
    print(C_x, C_y, H)
else:
    for n in range(10201):
        C_x = n // 101
        C_y = n % 101
        correctflg = True
        unsetflg = True
        for x,y,h in data:
            if unsetflg:
                if h >= 1:
                    H = abs(x-C_x)+abs(y-C_y)+h
                    unsetflg = False
            else:
                if h >= 1 and H != abs(x-C_x)+abs(y-C_y)+h:
                    correctflg = False
                    break 
        if correctflg:
            print(C_x,C_y,int(H))
            break

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
data = np.zeros((N,3))
for i in range(N):
    data[i] = np.array(input().split())

# data = np.array([[2,3,5],[2,1,5],[1,2,0],[3,2,5]])

for n in range(10201):
    C_x = n // 101
    C_y = n % 101
    flg = True
    unsetflg = True
    for i,(x,y,h) in enumerate(data):
        if unsetflg and h>=1:
            H = abs(x-C_x)+abs(y-C_y)+h
            unsetflg = False
        else
            if h>=1 and H != abs(x-C_x)+abs(y-C_y)+h:
                flg = False
                break 
    if flg:
        print(C_x,C_y,int(H))
        break

Buggy submission (verdict: Runtime Error):
import numpy as np
# N = int(input())
# data = np.zeros((N,3))
# for i in range(N):
#     data[i] = np.array(input().split())

data = np.array([[2,3,5],[2,1,5],[1,2,5],[3,2,5]])

for n in range(10201):
    C_x = n // 101
    C_y = n % 101
    flg = True
    unsetflg = True
    for i,(x,y,h) in enumerate(data):
        if unsetflg
        	if h>0:
            	H = abs(x-C_x)+abs(y-C_y)+h
            	unsetflg = False
        elif h>0:
            if H != abs(x-C_x)+abs(y-C_y)+h:
                flg = False
                break 
    if flg:
        print(C_x,C_y,int(H))
        break
Problem p03262 (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, X = map(int,input().split())
xs = [int(i) for i in input().split()]

xs.append(X)
xs = sorted(xs)
if len(xs) == 2:
    print(abs(xs[0]-xs[1]))
else:
    diffs = [xs[i]-xs[i-1] for i in range(1,len(xs))] #差を取る
    gcd_min = gcd(diffs[0],diffs[1])
    for i in range(2,len(diffs)):
        gcd_min = gcd(gcd_min, diffs[i])

    print(gcd_min)

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, X = map(int,input().split())
xs = [int(i) for i in input().split()]
xs.append(X)
xs = sorted(xs)
diffs = [xs[i]-xs[i-1] for i in range(1,len(xs))] #差を取る
gcd_min = gcd(diffs[0],diffs[1])
for i in range(2,len(diffs)):
    gcd_min = gcd(gcd_min, diffs[i])

print(gcd_min)
Problem p03263 (python)

Fixed submission:
### 予め一筆書きルートを作る
H, W = map(int,input().split())
As = []
for i in range(H):
    As.append(list(map(int,input().split())))
routes = []
for i in range(H):
    for j in range(W):
        if i%2 == 0:
            routes.append((i+1,j+1))
        else:
            routes.append((i+1,W-j))
n = len(routes)
mvs = []
cnt = 0
for i in range(n-1):
    hi,wi = routes[i]
    hi2,wi2 = routes[i+1]
    if As[hi-1][wi-1] % 2 == 1:
        As[hi2-1][wi2-1] += 1
        mvs.append([hi,wi,hi2,wi2])
        cnt += 1

print(cnt)
for h1,w1,h2,w2 in mvs:
    print(h1,w1,h2,w2)

Buggy submission (verdict: Runtime Error):
"""
07:26:30
奇数が2つで2つの偶数になる
片方どちらかが1の場合は、奇数が2つで1つの偶数になる
0でswapは分断される
H,W<=500なので全探索？O(HW)くらいか
端っこから決めていく
"""

H, W  = map(int, input().split())
right = []
ans = []
for i in range(H):
    As = list(map(int, input().split()))
    for j in range(W-1):
        if As[j]%2 == 1:
            ans.append([i+1,j+1,i+1,j+1+1])
            As[j] -= 1
            As[j+1] += 1
    right.append(As[j+1])
for i in range(H-1):
    if right[i]%2 == 1:
        ans.append([i+1,j+1,i+1+1,j+1])
        right[i] -= 1
        right[i+1] += 1
print(len(ans))
for a in ans:
    print(*a)

Buggy submission (verdict: Runtime Error):

H, W  = map(int, input().split())
right = []
ans = []
for i in range(H):
    As = list(map(int, input().split()))
    for j in range(W-1):
        if As[j]%2 == 1:
            ans.append([i+1,j+1,i+1,j+1+1])
            As[j] -= 1
            As[j+1] += 1
    right.append(As[j])

for i in range(H-1):
    if right[i]%2 == 1:
        ans.append([i+1,j+1,i+1+1,j+1])
print(len(ans))
for a in ans:
    print(*a)
Problem p03290 (python)

Fixed submission:
# """
# コンプリートするものと、せざるものに分ける
# コンプリートしないものに関しては、得点の高い方から一個だけ潰す
# """

D, G = map(int, input().split())
ps_ini,cs = [], []
for i in range(D):
    p,c = map(int,input().split())
    ps_ini.append(p)
    cs.append(c)

q_min = 1000000
for i in range(2**D):
    Gtmp = G
    ps = [p for p in ps_ini]
    s = "{:010b}".format(i)[::-1]
    q_all = 0
    for j,(p,c) in enumerate(zip(ps,cs)):
        # ボーナスの考慮
        Gtmp -= (p*(j+1)*100+c)*int(s[j]) 
        q_all += p*int(s[j])
        ps[j] -= p*int(s[j])
    # print(s,ps)
    if Gtmp <= 0:
        q_min = min(q_min, q_all)
    else:
        # コンプしていない問題で一番大きいやつ
        ind = 0
        for i,p in enumerate(ps):
            if p != 0:
                ind = i
        # print(Gtmp,ind,Gtmp//((ind+1)*100))
        # 比較
        if Gtmp//((ind+1)*100) > ps[ind]:
            continue
        if Gtmp%((ind+1)*100) == 0:           #割り切れない
            q_all += (Gtmp//((ind+1)*100))
        else:                           #割り切れる
            q_all += (Gtmp//((ind+1)*100) + 1) #最大値をコンプする以外ありえん
        q_min = min(q_min, q_all)
print(q_min)

Buggy submission (verdict: Runtime Error):
D,G = map(int, input().split())
INF = 10**10
# 各点数を得るときの、最小の問題数
n = 3*10**4
dp = [INF] * n
dp[0] = 0
for i in range(1,D+1):
    p,c = map(int, input().split())
    c //= 100
    tmp = dp[:]
    for j in range(G//100+1):
        if tmp[j] == INF: continue
        for k in range(1,p+1):
            dp[j+i*k] = min(tmp[j]+k, dp[j+i*k])
        dp[j+i*p+c] = min(tmp[j]+p, dp[j+i*p+c])

ans = INF
for score in dp[G//100:]:
    if score == INF: continue
    ans = min(score, ans)
print(ans)

Buggy submission (verdict: Runtime Error):
# """
# コンプリートするものと、せざるものに分ける
# コンプリートしないものに関しては、得点の高い方から一個だけ潰す
# """

D, G = map(int, input().split())
ps_ini,cs = [], []
for i in range(D):
    p,c = map(int,input().split())
    ps_ini.append(p)
    cs.append(c)
q_min = 1000000
for i in range(2**D):
    Gtmp = G
    ps = [p for p in ps_ini]
    s = "{:05b}".format(i)[::-1]
    q_all = 0
    for j,(p,c) in enumerate(zip(ps,cs)):
        # ボーナスの考慮
        Gtmp -= (p*(j+1)*100+c)*int(s[j]) 
        q_all += p*int(s[j])
        ps[j] -= p*int(s[j])
    # print(s,ps)
    if Gtmp <= 0:
        q_min = min(q_min, q_all)
    else:
        # コンプしていない問題で一番大きいやつ
        ind = 0
        for i,p in enumerate(ps):
            if p != 0:
                ind = i
        # print(Gtmp,ind,Gtmp//((ind+1)*100))
        # 比較
        if Gtmp//((ind+1)*100) > ps[ind]:
            continue
        if Gtmp%((ind+1)*100) == 0:           #割り切れない
            q_all += (Gtmp//((ind+1)*100))
        else:                           #割り切れる
            q_all += (Gtmp//((ind+1)*100) + 1) #最大値をコンプする以外ありえん
        q_min = min(q_min, q_all)
print(q_min)