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

Fixed submission:
import itertools

def read():
    N = str(input().strip())
    K = int(input().strip())
    return N, K

def solve(N, K):
    L = len(N)
    D = [int(N[i]) for i in range(L)]
    dp0 = [[0 for k in range(K+1)] for i in range(L+1)]
    dp1 = [[0 for k in range(K+1)] for i in range(L+1)]
    
    dp0[0][0] = 1
    for i in range(L):
        for k in range(K+1):
            if k < K and D[i] > 0:
                dp0[i+1][k+1] += dp0[i][k]
                for d in range(1, D[i]):
                    dp1[i+1][k+1] += dp0[i][k]
            if D[i] == 0:
                dp0[i+1][k] += dp0[i][k]
            else:
                dp1[i+1][k] += dp0[i][k]
            if k < K:
                for d in range(1, 10):
                    dp1[i+1][k+1] += dp1[i][k]
            dp1[i+1][k] += dp1[i][k]
    return dp0[L][K] + dp1[L][K]


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Buggy submission (verdict: Runtime Error):
import itertools

def read():
    N = str(input().strip())
    K = int(input().strip())
    return N, K

def nCk(n, k):
    return len(list(itertools.combinations(range(n), k)))

def count_nonzero(L, H, K):
    """
    [0-H][0-9]{L-1}にマッチするL桁の数字から、非ゼロがK個のものを数え上げ
    L: 桁数
    H: 上位1桁目の数字
    K: 範囲内に含まれるゼロでない数字の数
    """
    count = 0
    factor = [1, 9, 81, 729]
    count += nCk(L-1, K) * factor[K]
    for h in range(1, H+1):
        count += nCk(L-1, K-1) * factor[K-1]
    return count



def solve(N, K):
    L = len(N)
    intN = [int(N[i]) for i in range(L)]
    count = 0
    # 最上位桁が[0-(intN[0]-1)]のものをカウント
    if K >= 1:
        count += count_nonzero(L, intN[0]-1, K)
    # 最上位桁がintN[0]、2桁目が[0-(intN[1]-1)]のものをカウント
    if K >= 2:
        count += count_nonzero(L-1, intN[1]-1, K-1)
    # 上位桁がintN[0]intN[1]、3桁目が[0-(intN[2]-1)]のものをカウント
    if K >= 3:
        count += count_nonzero(L-2, intN[2]-1, K-2)
    # 上位桁がintN[0]intN[1]intN[2]のものをカウント (自分自身)
    count += 1
    return count


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))
Problem p02863 (python)

Fixed submission:
import itertools


def read():
    N, T = list(map(int, input().strip().split()))
    A = list()
    B = list()
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return N, T, A, B


def solve(N, T, A, B):
    dp1 = [[0 for j in range(T)] for i in range(N+2)]
    dp2 = [[0 for j in range(T)] for i in range(N+2)]
    for i, t in itertools.product(range(N), range(T)):
        u = t - A[i]
        if u >= 0:
            dp1[i+1][t] = max(dp1[i][u] + B[i], dp1[i][t])
        else:
            dp1[i+1][t] = dp1[i][t]
        u = t - A[N-1-i]
        if u >= 0:
            dp2[N-i][t] = max(dp2[N+1-i][u] + B[N-1-i], dp2[N+1-i][t])
        else:
            dp2[N-i][t] = dp2[N+1-i][t]
    v = 0
    for i, t in itertools.product(range(N), range(T)):
        v = max(v, dp1[i][t] + dp2[i+2][(T-1) - t] + B[i])
    return v


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Buggy submission (verdict: Runtime Error):
import numpy as np


def read():
    N, T = list(map(int, input().strip().split()))
    A = list()
    B = list()
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return N, T, A, B

def solve(N, T, A, B):
    dp1 = [[0 for j in range(T)] for i in range(N+2)]
    dp2 = [[0 for j in range(T)] for i in range(N+2)]
    for i in range(1, N+1, 1):
        for t in range(T):
            if A[i-1] <= t:
                dp1[i][t] = max(dp1[i-1][t-A[i-1]] + B[i-1], dp1[i-1][t])
            else:
                dp1[i][t] = dp1[i-1][t]
    for i in range(N, 0, -1):
        for t in range(T):
            if A[i-1] <= t:
                dp2[i][t] = max(dp2[i+1][t-A[i-1]] + B[i-1], dp2[i+1][t])
            else:
                dp2[i][t] = dp2[i-1][t]
    v = 0
    for i in range(1, N+1, 1):
        for j in range(T):
            v = max(v, dp1[i-1][j] + dp2[i+1][(T-1) - j] + B[i-1])
    return v


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Buggy submission (verdict: Runtime Error):
import numpy as np


def read():
    N, T = list(map(int, input().strip().split()))
    A = list()
    B = list()
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return N, T, A, B

def solve(N, T, A, B):
    a = np.array(A, dtype=np.int32)
    b = np.array(B, dtype=np.int32)
    v = 1.0 * b / a
    order = np.argsort(v)[::-1]
    v = v[order]
    a = a[order]
    b = b[order]
    asum = np.cumsum(a)  # 時間の累積和
    bsum = np.cumsum(b)  # おいしさの累積和
    amax = 0
    bmax = 0
    bmax = 0
    for i in range(N):
        l, r = np.searchsorted(asum, [T, T + a[i]], side='left')
        if r == N:
            bmax = max(bmax, bsum[-1])
        if i == r:
            bmax = max(bmax, bsum[r] - b[i])
        if i < r < N:
            bmax = max(bmax, bsum[r] - b[i])
        if l < i:
            bmax = max(bmax, bsum[l])
    return bmax

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))
Problem p02984 (python)

Fixed submission:
def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A

def solve(N, A):
    x = [0 for i in range(N)]
    x[0] = sum([A[i]*(-1)**i for i in range(0, N)]) // 2
    for i in range(0, N-1):
        x[i+1] = A[i] - x[i]
    x = [2 * x[i] for i in range(N)]
    return ' '.join(map(str, x))

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Buggy submission (verdict: Runtime Error):
# start -> ダム -> 山 -> end で2部グラフを作って最大流を求めれば求まるはず


MAX_V = 100002
used = [False] * MAX_V
edge = [[] for _ in range(MAX_V)]

class Edge():

    def __init__(self, to, cap, rev):
        self.to = to
        self.cap = cap
        self.rev = rev

def init_used():
    for i in range(MAX_V):
        used[i] = False

def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A

def build_graph(N, A, INF=10000000000):
    START = 2 * N
    END = 2 * N + 1
    for i in range(N):
        edge[START].append(Edge(i, A[i], len(edge[i])))
        edge[i].append(Edge(START, 0, len(edge[START])))
    for i in range(N):
        j = N + ((i - 1) % N)
        edge[i].append(Edge(N+i, INF, len(edge[N+i])))
        edge[j].append(Edge(N + j, INF, len(edge[N + j])))
        edge[N+i].append(Edge(N + i, 0, len(edge[i])))
        edge[N+j].append(Edge(N + j, 0, len(edge[j])))
    for i in range(N):
        edge[N+i].append(Edge(END, INF, len(edge[END])))
        edge[END].append(Edge(N+i, 0, len(edge[N+i])))
    return edge, START, END


def dfs(edge, weight, v, t, f=10000000000):
    if v == t:
        return f
    used[v] = True
    for i in range(len(edge[v])):
        to = edge[v][i]
        if not used[to] and weight[v][i] > 0:
            d = dfs(to, t, min(f, weight[v][i]))
            if d > 0:
                weight[v][i] -= d
                edge[v]


def maximum_flow(edge, s, t):
    V = len(edge)
    while True:
        init_used()
        d = dfs(edge, s, t)
        return 0
    

def solve(N, A):
    # 0~N-1: damu, N~2N-1: yama, 2N: s, 2N+1: t
    edge, START, END = build_graph(N, A)
    maximum_flow(edge, START, END)
    return 0


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))
Problem p02990 (python)

Fixed submission:
from operator import mul
from functools import reduce

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

def read():
    N, K = list(map(int, input().strip().split()))
    return N, K

def solve(N, K):
    for i in range(1, K + 1):
        count = nCr(N - K + 1, i) * nCr(K - 1, i - 1)
        print(count % (10**9 + 7))

if __name__ == '__main__':
    inputs = read()
    solve(*inputs)

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

def nCr(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

def read():
    N, K = list(map(int, input().strip().split()))
    return N, K

def solve(N, K):
    if N == K:
        print(1)
        for i in range(2, K + 1):
            print(0)
    else:
        for i in range(1, K + 1):
            count = nCr(N - K + 1, i) * nCr(K - 1, i - 1)
            print(count % (10**9 + 7))

if __name__ == '__main__':
    inputs = read()
    solve(*inputs)

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

def nCr(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

def read():
    N, K = list(map(int, input().strip().split()))
    return N, K

def solve(N, K):
    for i in range(1, K + 1):
        count = nCr(N - K + 1, i) * nCr(K - 1, i - 1)
        print(count % (10**9 + 7))

if __name__ == '__main__':
    inputs = read()
    solve(*inputs)
Problem p03038 (python)

Fixed submission:
def read():
    N, M = list(map(int, input().strip().split()))
    A = list(map(int, input().strip().split()))
    B = []
    C = []
    for m in range(M):
        b, c = list(map(int, input().strip().split()))
        B.append(b)
        C.append(c)
    return N, M, A, B, C


def solve(N, M, A, B, C):
    cindex_desc = sorted(range(M), key=lambda k: C[k])
    A = sorted(A)
    left_index = 0
    for i in reversed(cindex_desc):
        for j in range(B[i]):
            if left_index >= N:
                break
            if A[left_index] < C[i]:
                A[left_index] = C[i]
                left_index += 1
            else:
                break
    return sum(A)


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

def read():
    N, M = list(map(int, input().strip().split()))
    A = list(map(int, input().strip().split()))
    B = []
    C = []
    for m in range(M):
        b, c = list(map(int, input().strip().split()))
        B.append(b)
        C.append(c)
    return N, M, A, B, C


def solve(N, M, A, B, C):
    cindex_desc = sorted(range(M), key=lambda k: C[k])
    A = sorted(A)
    left_index = 0
    for i in reversed(cindex_desc):
        for j in range(B[i]):
            if A[left_index] < C[i]:
                A[left_index] = C[i]
                left_index += 1
            else:
                break
    return sum(A)


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))
Problem p03135 (python)

Fixed submission:
def read():
    T, X = map(int, input().strip().split())
    return T, X


def solve(T, X):
    return T / X


if __name__ == '__main__':
    inputs = read()
    print("%f" % solve(*inputs))

Buggy submission (verdict: Runtime Error):
def read():
    N, K = list(map(int, input().strip().split()))
    A = list(map(int, input().strip().split()))
    return N, K, A


def binary_digits(x):
    digit = 0
    while x > 0:
        x >>= 1
        digit += 1
    return digit


def maximum_X(N, K, A):
    digitK = binary_digits(K)
    counts = []
    bitmask = 1
    for d in range(digitK):
        count = 0
        for i in range(N):
            if A[i] & bitmask == bitmask:
                count += 1
        counts.append(count)
        bitmask <<= 1

    X = 0
    bitmask = 1
    for d in range(digitK):
        if counts[d] * 2 <= N:
            if K & bitmask == bitmask:
                X += bitmask
        bitmask <<= 1
    return X


def f(x, A):
    y = 0
    for a in A:
        y += (x ^ a)
    return y


def solve(N, K, A):
    X = maximum_X(N, K, A)
    return f(X, A)


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))
Problem p02757 (python)

Fixed submission:
import sys
input=sys.stdin.readline
n,p=map(int,input().split())
s=input().rstrip()
if p==2:
    ans=0
    for i in range(n):
        if int(s[i])%2==0:
            ans+=i+1
elif p==5:
    ans=0
    for i in range(n):
        if int(s[i])==0 or int(s[i])==5:
            ans+=i+1
else:
    count=[0]*p
    x=0
    y=1
    count[0]=1
    for i in range(n-1,-1,-1):
        x=x+y*int(s[i])
        x=x%p
        count[x]+=1
        y=(y*10)%p
    ans=0
    for i in count:
        ans+=i*(i-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n,p=map(int,input().split())
s=input().rstrip()
if p==2:
    for i in range(n):
        ans=0
        if s[i]%2==0:
            ans+=i+1
elif p==5:
    for i in range(n):
        ans=0
        if s[i]==0 or s[i]==5:
            ans+=i+1
else:
    count=[0]*p
    x=0
    y=1
    count[0]=1
    for i in range(n-1,-1,-1):
        x=x+y*int(s[i])
        x=x%p
        count[x]+=1
        y=(y*10)%p
    ans=0
    for i in count:
        ans+=i*(i-1)//2
print(ans)
Problem p02851 (python)

Fixed submission:
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
a=list(map(int,input().split()))
c1=[0]
c2=[k]
s=0
if k==1:
    print(0)
    sys.exit()
for i in range(n):
    s=(s+a[i])%k
    c1.append(s-i-1)
    c2.append(s+k-i-1)
d1={}
for i in range(1,n+1):
    if c1[i] in d1:
        d1[c1[i]]+=1
    else:
        d1[c1[i]]=1
ans=0
for i in range(n):
    if c1[i] in d1:
        ans+=d1[c1[i]]
    d1[c1[i+1]]-=1
d2={}
for i in range(1,min(k,n+1)):
    if c2[i] in d2:
        d2[c2[i]]+=1
    else:
        d2[c2[i]]=1
for i in range(n):
    if c1[i] in d2:
        ans+=d2[c1[i]]
    d2[c2[i+1]]-=1
    if i+k<=n:
        if c2[i+k] in d2:
            d2[c2[i+k]]+=1
        else:
            d2[c2[i+k]]=1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
a=list(map(int,input().split()))
c1=[0]
c2=[k]
s=0
if n==1:
    ans=0
    if a[0]%k==1:
        ans+=1
    print(ans)
    sys.exit()
for i in range(n):
    s=(s+a[i])%k
    c1.append(s-i-1)
    c2.append(s+k-i-1)
d1={}
for i in range(1,n+1):
    if c1[i] in d1:
        d1[c1[i]]+=1
    else:
        d1[c1[i]]=1
ans=0
for i in range(n):
    if c1[i] in d1:
        ans+=d1[c1[i]]
    d1[c1[i+1]]-=1
d2={}
for i in range(1,min(k,n+1)):
    if c2[i] in d2:
        d2[c2[i]]+=1
    else:
        d2[c2[i]]=1
for i in range(n):
    if c1[i] in d2:
        ans+=d2[c1[i]]
    d2[c2[i+1]]-=1
    if i+k<=n:
        if c2[i+k] in d2:
            d2[c2[i+k]]+=1
        else:
            d2[c2[i+k]]=1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
a=list(map(int,input().split()))
c1=[0]
c2=[k]
s=0
for i in range(n):
    s=(s+a[i])%k
    c1.append(s-i-1)
    c2.append(s+k-i-1)
d1={}
for i in range(1,n+1):
    if c1[i] in d1:
        d1[c1[i]]+=1
    else:
        d1[c1[i]]=1
ans=0
for i in range(n):
    if c1[i] in d1:
        ans+=d1[c1[i]]
    d1[c1[i+1]]-=1
d2={}
for i in range(1,min(k,n+1)):
    if c2[i] in d2:
        d2[c2[i]]+=1
    else:
        d2[c2[i]]=1
for i in range(n):
    if c1[i] in d2:
        ans+=d2[c1[i]]
    d2[c2[i+1]]-=1
    if i+k<=n:
        if c2[i+k] in d2:
            d2[c2[i+k]]+=1
        else:
            d2[c2[i+k]]=1
print(ans)
Problem p02990 (python)

Fixed submission:
n,k=map(int,input().split())
INF=10**9+7
def modcomb(n,k,m):
    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%m
        inv[i]=m-inv[m%i]*(m//i)%m
        finv[i]=finv[i-1]*inv[i]%m
    return fac[n]*(finv[k]*finv[n-k]%m)%m
for i in range(1,k+1):
    if n-k>=i-1:
        if k-1==0 and i-1==0:
            a=1
        else:
            a=modcomb(k-1,i-1,INF)
        if n-k+1==0 and i==0:
            b=1
        else:
            b=modcomb(n-k+1,i,INF)
        ans=(a*b)%INF
        print(ans)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
INF=10**9+7
def modcomb(n,k,m):
    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%m
        inv[i]=m-inv[m%i]*(m//i)%m
        finv[i]=finv[i-1]*inv[i]%m
    return fac[n]*(finv[k]*finv[n-k]%m)%m
for i in range(1,k+1):
    if n-k>=i-1:
        a=modcomb(k-1,i-1,INF)
        b=modcomb(n-k+1,i,INF)
        ans=(a*b)%INF
        print(ans)
    else:
        print(0)
Problem p03053 (python)

Fixed submission:
from collections import deque
h,w=map(int,input().split())
INF=10**9
check=[]
for i in range(h):
    sub_list=[]
    for j in range(w):
        sub_list.append(INF)
    check.append(sub_list)
black=deque([])
for i in range(h):
    sub_list=list(input())
    for j in range(w):
        if sub_list[j]=='#':
            black.append((i,j))
            check[i][j]=0
Max=0
while len(black)>0:
    now=black.popleft()
    U=(now[0]-1,now[1])
    D=(now[0]+1,now[1])
    L=(now[0],now[1]-1)
    R=(now[0],now[1]+1)
    for i in U,D,L,R:
        if 0<=i[0]<=h-1 and 0<=i[1]<=w-1 and check[i[0]][i[1]]==INF:
            check[i[0]][i[1]]=check[now[0]][now[1]]+1
            Max=max(Max,check[i[0]][i[1]])
            black.append(i)
print(Max)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
a_list=[]
for i in range(h):
    b=list(input())
    a_list.append(b)
dp=[]
for i in range(h):
    dps=[]
    for j in range(w):
        dps.append(10**9)
    dp.append(dps)
def f(x,y):
    if dp[x][y]<10**9:
        return dp[x][y]
    else:
        if a_list[x][y]=='#':
            dp[x][y]=0
            return 0
        else:
            dp[x][y]=10**8
            if x>0:
                k0=f(x-1,y)+1
            else:
                k0=10**9
            if x<h-1:
                k1=f(x+1,y)+1
            else:
                k1=10**9
            if y>0:
                k2=f(x,y-1)+1
            else:
                k2=10**9
            if y<w-1:
                k3=f(x,y+1)+1
            else:
                k3=10**9
            m=min(k0,k1,k2,k3)
            dp[x][y]=m
            return m
answer=0
for i in range(h):
    for j in range(w):
        answer=max(answer,f(i,j))
print(answer)
Problem p03127 (python)

Fixed submission:
n=int(input())
a_list=list(map(int,input().split()))
import fractions
answer=a_list[0]
for i in range(1,n):
    answer=fractions.gcd(answer,a_list[i])
print(answer)

Buggy submission (verdict: Runtime Error):
n=int(input())
a_list=list(map(int,input().split()))
import math
answer=a_list[0]
for i in range(1,n):
    answer=math.gcd(answer,a_list[i])
print(answer)
Problem p03634 (python)

Fixed submission:
n=int(input())
G=[[] for i in range(n)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    G[a-1].append((b-1,c))
    G[b-1].append((a-1,c))
q,k=map(int,input().split())
k=k-1
stack=[k]
dis=[-1]*n
dis[k]=0
while len(stack)>0:
    now=stack.pop()
    d=dis[now]
    for i in G[now]:
        if dis[i[0]]==-1:
            dis[i[0]]=d+i[1]
            stack.append(i[0])
for i in range(q):
    x,y=map(int,input().split())
    x=x-1
    y=y-1
    print(dis[x]+dis[y])

Buggy submission (verdict: Runtime Error):
n=int(input())
G=[[] for i in range(n)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    G[a-1].append((b-1,c))
    G[b-1].append((a-1,c))
q,k=map(int,input().split())
k=k-1
stack=[k]
dis=[-1]*n
dis[k]=0
while len(stack)!=[]:
    now=stack.pop()
    d=dis[now]
    for i in G[now]:
        if dis[i[0]]==-1:
            dis[i[0]]=d+i[1]
            stack.append(i[0])
for i in range(q):
    x,y=map(int,input().split())
    x=x-1
    y=y-1
    print(dis[x]+dis[y])

Buggy submission (verdict: Runtime Error):
n=int(input())
G=[[] for i in range(n)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    G[a-1].append((b-1,c))
    G[b-1].append((a-1,c))
q,k=map(int,input().split())
k=k-1
stack=[k]
dis=[-1]*n
dis[k]=0
import deque
stack=deque(stack)
while len(stack)>0:
    now=stack.pop()
    d=dis[now]
    for i in G[now]:
        if dis[i[0]]==-1:
            dis[i[0]]=d+i[1]
            stack.append(i[0])
for i in range(q):
    x,y=map(int,input().split())
    x=x-1
    y=y-1
    print(dis[x]+dis[y])
Problem p02580 (python)

Fixed submission:
import sys

H, W, M = map(int, sys.stdin.readline().strip().split())

h = [0] * H
w = [0] * W

# g = [[False] * W for _ in range(H)]
S = set()
for _ in range(M):
    Th, Tw = map(int, sys.stdin.readline().strip().split())

    h[Th - 1] += 1
    w[Tw - 1] += 1

    # g[Th - 1][Tw - 1] = True
    S.add((Th - 1, Tw - 1))

max_h = max(h)
max_w = max(w)
ans = max_h + max_w

index_h = [n for n, v in enumerate(h) if v == max_h]
index_w = [n for n, v in enumerate(w) if v == max_w]

sub = 1
# for ih in index_h:
#     for iv in index_w:
#         if g[ih][iv] is False:
#             sub = 0
#             break
#     else:
#         continue
#     break
# ans -= sub
# print(ans)


for ih in index_h:
    for iv in index_w:
        if not (ih, iv) in S:
            print(ans)
            exit()
print(ans - 1)

Buggy submission (verdict: Runtime Error):
import sys

H, W, M = map(int, sys.stdin.readline().strip().split())

h = [0] * H
w = [0] * W

g = [[False] * W for _ in range(H)]

for _ in range(M):
    Th, Tw = map(int, sys.stdin.readline().strip().split())

    h[Th - 1] += 1
    w[Tw - 1] += 1

    g[Th - 1][Tw - 1] = True

ans = max(h) + max(w)

index_h = [n for n, v in enumerate(h) if v == max(h)]
index_w = [n for n, v in enumerate(w) if v == max(w)]

sub = 1
for ih in index_h:
    for iv in index_w:
        if g[ih][iv] is false:
            sub = 0
            break
    else:
        continue
    break

ans -= sub
print(ans)
Problem p02862 (python)

Fixed submission:
# AtCoder Beginner Contest 145 D - Knight
import sys
from math import factorial

mod = 10 ** 9 + 7

X, Y = map(int, sys.stdin.readline().strip().split())

# 合計の移動回数は Total = X + Y / 3 
# 移動方法は A: (i + 1, j + 2)  B: (i + 2, j + 1) の2通り
# 移動回数は A: 2 * Total - X  B: X - Total 

# 到達不可能であるか判断する
if (X + Y) % 3 != 0:
    print(0)
    sys.exit()

if Y > 2 * X or Y < X * 0.5:
    print(0)
    sys.exit()


Total = (X + Y) // 3
A = Total * 2 - X
B = X - Total

# combination の計算
ans = 1
for i in range(1, Total + 1):
    ans *= i
    ans %= mod

ans = ans * pow(factorial(A), mod - 2, mod)
ans = ans * pow(factorial(B), mod - 2, mod)

print(ans % mod)

Buggy submission (verdict: Runtime Error):
hash_no = 10 ** 9 + 7
x, y = map(int, input().split())

counter = 0


def move(x, y, X, Y):
    global counter
    if x >X:
        return
    if y > Y:
        return
    if (x == X) and (y == Y):
        counter += 1
        return

    move(x + 1, y + 2, X, Y)
    move(x + 2, y + 1, X, Y)


move(0, 0, x, y)
print(counter / hash_no)
Problem p02682 (python)

Fixed submission:
a,b,c,k=map(int,input().split())
if(k>a+b):
    print(a-min(k-a-b,c))
elif(k>=a):
    print(a)
else:
    print(k)

Buggy submission (verdict: Runtime Error):
a,b,c,k=map(int,input().split())
if(k>a+b):
    print(A-min(k-a-b,c))
elif(k>=a):
    print(a)
else:
    print(k)