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

Fixed submission:

H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for i in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for i in range(Q)]
d = [0] * ((H*W)+1)
num_dict = {}
y = 0
for aa in A:
    x = 0
    for a in aa:
        num_dict[a] = [x, y]
        x += 1
    y += 1

for i in range(D+1, H*W+1):
    d[i] = d[i-D] + abs(num_dict[i][0]-num_dict[i-D][0]) + abs(num_dict[i][1]-num_dict[i-D][1])
for l, r in LR:
    print(d[r]-d[l])

Buggy submission (verdict: Runtime Error):

H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for i in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for i in range(Q)]
d = [0] * (H*W)
num_dict = {}
y = 0
for aa in A:
    x = 0
    for a in aa:
        num_dict[a] = [x, y]
        x += 1
    y += 1

for i in range(D+1, H*W):
    d[i] = d[i-D] + abs(num_dict[i][0]-num_dict[i-D][0]) + abs(num_dict[i][1]-num_dict[i-D][1])
for l, r in LR:
    print(d[r]-d[l])
Problem p03723 (python)

Fixed submission:
A, B, C = map(int, input().split())

if A == B == C and all(map(lambda x: x%2==0, [A, B, C])):
    print(-1)
else:
    ans = 0
    cookie = A+B+C
    while True:
        if all(map(lambda x: x%2==0, [A, B, C])):
            ans += 1
        else:
            print(ans)
            break
        A = (cookie-A) / 2
        B = (cookie-B) / 2
        C = (cookie-C) / 2

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

if A == B == C and all(lambda x: x%2==0, [A, B, C]):
    print(-1)
else:
    ans = 0
    cookie = A+B+C
    while True:
        if all(map(lambda x: x%2==0, [A, B, C])):
            ans += 1
        else:
            print(ans)
            break
        A = (cookie-A) / 2
        B = (cookie-B) / 2
        C = (cookie-C) / 2
Problem p03774 (python)

Fixed submission:
# B-Checkpoints
# 問題URL:http://abc057.contest.atcoder.jp/tasks/abc057_b

N, M = map(int, input().split()) #まずNとMを取得
ABs = [] # 学生のいる座標
CDs = [] #　チェックポイントの座標

# 2行目よりN行分学生の座標を取得してABsに格納
for i in range(N):
    ABs.append([int(x) for x in input().split()])

# 2+N行目よりM行分チェックポイントの座標を取得してCDsに格納
for i in range(M):
    CDs.append([int(x) for x in input().split()])

for a,b in ABs:
    #ABsの中身をa,b、CDsの中身をc,dとして取り出し各チェックポイントごとの距離を測定
    distance = [abs(a-c) + abs(b-d) for c,d in CDs]
    
    #　距離が同じ場合は最も番号が早いものを出力する。=(min()はもともとそのようにできている。早いもの優先）
    #+1はリストは0番目から、チェックポイントは1番目から始まるため
    print(distance.index(min(distance)) + 1)

Buggy submission (verdict: Runtime Error):
# B-Checkpoints
# 問題URL:http://abc057.contest.atcoder.jp/tasks/abc057_b

N, M = map(int, input().split()) #まずNとMを取得
ABs = [] # 学生のいる座標
CDs = [] #　チェックポイントの座標

# 2行目よりN行分学生の座標を取得してABsに格納
for i in range(N):
    ABs.append([int(x) for x in input().split()])

# 2+N行目よりM行分チェックポイントの座標を取得してCDsに格納
for i in range(N):
    CDs.append([int(x) for x in input().split()])

for a,b in ABs:
    #ABsの中身をa,b、CDsの中身をc,dとして取り出し各チェックポイントごとの距離を測定
    distance = [abs(a-c) + abs(b-d) for c,d in CDs]
    
    #　距離が同じ場合は最も番号が早いものを出力する。=(min()はもともとそのようにできている。早いもの優先）
    #+1はリストは0番目から、チェックポイントは1番目から始まるため
    print(distance.index(min(distance)) + 1)

Buggy submission (verdict: Runtime Error):
# B-Checkpoints
# 問題URL:http://abc057.contest.atcoder.jp/tasks/abc057_b

N, M = map(int, input().split()) #まずNとMを取得
ABs = [] # 学生のいる座標
CDs = [] #　チェックポイントの座標

# 2行目よりN行分学生の座標を取得してABsに格納
for i in range(N):
    ABs.append([int(x) for x in input().split()])

# 2+N行目よりM行分チェックポイントの座標を取得してCDsに格納
for i in range(N):
    CDs.append([int(x) for x in input().split()])

for a,b in ABs:
    #ABsの中身をa,b、CDsの中身をc,dとして取り出し各チェックポイントごとの距離を測定
    distance = [abs(a-c) + abs(b-d) for c,d in CDs]
    print(distance)
    
    #　距離が同じ場合は最も番号が早いものを出力する。=(min()はもともとそのようにできている。早いもの優先）
    #+1はリストは0番目から、チェックポイントは1番目から始まるため
    print(distance.index(min(distance)) + 1)
Problem p03775 (python)

Fixed submission:
from math import sqrt

# C-Digits in Multiplication
# 問題URl:http://abc057.contest.atcoder.jp/tasks/abc057_c

N = int(input())
F = 999;
for i in range(1,int(sqrt(N))+1):
    
    if N%i == 0: #余りが0 = iは整数なので整数同士の割り算ということ(余りを求める際には少数まで商を求めない）
        F =  min(F , max( len(str(i)) , len(str(N//i)) ) )
print(F)

Buggy submission (verdict: Runtime Error):
N = int(input())
F = 999;
for i in range(1,int(sqrt(N))+1):
    
    if N%i == 0: #余りが0 = iは整数なので整数同士の割り算ということ(余りを求める際には少数まで商を求めない）
        F =  min(F , max( len(str(i)) , len(str(N//i)) ) )
print(F)

Buggy submission (verdict: Runtime Error):
N = int(input())
F = 999;
for i in range(1,int(sqrt(N))+1):
    if N%i == 0: #余りが0 = iは整数なので整数同士の割り算ということ(余りを求める際には少数まで商を求めない）
        F =  min(F , max( len(str(i)) , len(str(N//i)) ) )
print(F)

Buggy submission (verdict: Runtime Error):
N = int(input())
F = 999;
for i in range(1,int(sqrt(N))+1):
    print(i)
    
    if N%i == 0: #余りが0 = iは整数なので整数同士の割り算ということ(余りを求める際には少数まで商を求めない）
        F =  min(F , max( len(str(i)) , len(str(N//i)) ) )
print(F)
Problem p03804 (python)

Fixed submission:
N , M = map(int , input().split())
A = []
B = []
flg = False

for i in range(N):
    A.append([j for j in input()])
for i in range(M):
    B.append([j for j in input()])

for i in range(N-M+1):
    for k in range(N-M+1):
        if flg:
            break
        flg = True
        for j in range(M):
            for l in range(M):
                if B[j][l] != A[j+i][l+k]:
                    flg = False
                    
            
 
if flg:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N , M = map(int , input().split())
A = []
B = []
flg=True

for i in range(N):
    A.append([j for j in input()])
for i in range(M):
    B.append([j for j in input()])

for i in range((N-M-1)*(N-M-1)):
    for j in range(M):
        for l in range(M):
            if B[j][l] != A[j+i][l+i]:
                flg = False
                break
 
if flg:
    print("Yes")
else:
    print("No")
Problem p02779 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort()
for i in range(len(a)-1):
    if a[i] == a[i+1]:
        print('NO')
        exit()
print('YES')

Buggy submission (verdict: Runtime Error):
function Main(input) {
	var str = input;
	var ans = "YES";
	str = str.split("\n");
	var l = str[1].split(" "); 
	loop:
	for(var j =0;j< l.length-1;j++){	
 		for(var i =1; i<l.length;i++){
 			 if(l[j]===l[i]){
	 			ans = "NO";
	 			break loop;
 			}	 	
 		}
	} 	
	console.log(ans);
}
 //*おまじない
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
Problem p02793 (python)

Fixed submission:
import fractions
# import math as fractions
mod = 10**9+7
n = int(input())
a = list(map(int, input().split()))

if n == 1:
    print(1)
    exit()

g = fractions.gcd(a[0], a[1])
f = a[0]*a[1]//g
ans = a[0]//g+a[1]//g

for i in range(2, n):
    # print(ans, g, f)
    h = fractions.gcd(f, a[i])
    g = a[i] // h
    f = f*a[i]// h
    ans *= g
    ans += f // a[i]
    ans %= mod
print(ans%mod)

Buggy submission (verdict: Runtime Error):
# import fractions
import math as fractions
n = int(input())
a = list(map(int, input().split()))
ans = a[0]
mod = 10**9+7
for i in range(1, n):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
print(ans)
sum = 0
for i in range(n):
    sum += ans//a[i]
    sum %= mod
print(sum)
Problem p02831 (python)

Fixed submission:
import fractions

a, b = map(int, input().split())
print(a*b//fractions.gcd(a,b))

Buggy submission (verdict: Runtime Error):
import math

a, b = map(int, input().split())
print(a*b//math.gcd(a,b))
Problem p02862 (python)

Fixed submission:
import math
x, y = map(int, input().split())
if (2*x-y)%3 != 0 or (-x+2*y)%3 != 0:
    print(0)
    exit()
a = (2*x-y)//3
b = (-x+2*y)//3
if a < 0 or b < 0:
    print(0)
    exit()
def comb(n, r, mod):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod
print(comb(a+b, a, 10**9+7))

Buggy submission (verdict: Runtime Error):
import math
x, y = map(int, input().split())
if (2*x-y)%3 != 0 or (-x+2*y)%3 != 0:
    print(0)
    exit()
a = (2*x-y)//3
b = (-x+2*y)//3
print(math.factorial(a+b)//(math.factorial(a)*math.factorial(b))%(10**9+7))
Problem p03011 (python)

Fixed submission:
a, b, c = map(int, input().split())
print(min([a+b, b+c, c+a]))

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
# 出力
print(min(a+b,b+c,c+A))
Problem p03013 (python)

Fixed submission:
import sys
n, m = map(int, input().split())
a=set(int(input()) for i in range(m))
ans = [0 for _ in range(n)]

for i in range(n):
    if i+1 in a:
        ans[i] = 0
    else:
        if i == 0:
            ans[i] = 1
        elif i == 1:
            ans[i] = 1+ans[i-1]
        else:
            ans[i] = (ans[i-1]+ans[i-2])%(10**9+7)
print(ans[-1])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())

def fib(n):
    if n == 0:
        return 0
    elif n <= 2:
        return 1
    else:
        return fib(n-1)+fib(n-2)

a = []
for i in range(m):
    a.append(int(input()))
ans = fib(a[0])
for i in range(m-1):
    ans *= fib(a[i+1]-a[i]-1)
    ans %= 1000000007
ans *= fib(n-a[-1])
print(ans%1000000007)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())

def fib(n):
    r5 = 5**0.5
    f = 1/r5*((0.5+r5/2)**n-(0.5-r5/2)**n)
    return int(f)

a = []
for i in range(m):
    a.append(int(input()))
ans = fib(a[0])
for i in range(m-1):
    ans *= fib(a[i+1]-a[i]-1)
    ans %= 1000000007
ans *= fib(n-a[-1])
print(ans%1000000007)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())

def fib(n):
    r5 = 5**0.5
    f = 1/r5*((0.5+r5/2)**n-(0.5-r5/2)**n)
    return int(f)

a = []
for i in range(m):
    a.append(int(input()))
ans = fib(a[0])
for i in range(m-1):
    ans *= fib(a[i+1]-a[i]-1)
ans *= fib(n-a[-1])
print(ans%1000000007)
Problem p03038 (python)

Fixed submission:
from heapq import heappush, heappop

n, m = map(int, input().split())
a = list(map(int, input().split()))
card = [list(map(int, input().split())) for _ in range(m)]
card = sorted(card, key=lambda x:-x[1])

hq = []
for i in range(n):
    heappush(hq, a[i])

ans = sum(a)
for i in range(m):
    for j in range(card[i][0]):
        if hq == []:
            break
        num = heappop(hq)
        if num >= card[i][1]:
            heappush(hq, num)
            break
        else:
            ans += card[i][1]-num
print(ans)

Buggy submission (verdict: Runtime Error):
from heapq import heappush, heappop

n, m = map(int, input().split())
a = list(map(int, input().split()))
card = [list(map(int, input().split())) for _ in range(m)]
card = sorted(card, key=lambda x:-x[1])

hq = []
for i in range(n):
    heappush(hq, a[i])

ans = sum(a)
for i in range(m):
    for j in range(card[i][0]):
        num = heappop(hq)
        if num >= card[i][1]:
            heappush(hq, num)
            break
        else:
            ans += card[i][1]-num
print(ans)
Problem p03127 (python)

Fixed submission:
import fractions

n = int(input())
a = list(map(int, input().split()))

ans = a[0]
for i in range(n-1):
    ans = fractions.gcd(ans, a[i+1])
print(ans)

Buggy submission (verdict: Runtime Error):
import fraction

n = int(input())
a = list(map(int, input().split()))

ans = a[0]
for i in range(n-1):
    ans = fraction.gcd(ans, a[i+1])
print(ans)

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
a = list(map(int, input().split()))

ans = a[0]
for i in range(n-1):
    ans = math.gcd(ans, a[i+1])
print(ans)
Problem p03209 (python)

Fixed submission:
import sys
n, x = map(int, input().split())
ans = 0
layer = [1 for _ in range(n+1)]
patty = [1 for _ in range(n+1)]
for i in range(1,n+1):
    layer[i] = 2*layer[i-1]+3
    patty[i] = 2*patty[i-1]+1
def eat(n, x):
    if n == 0:
        return 1
    if x == 1:
        return 0
    elif x <= 1+layer[n-1]:
        return eat(n-1, x-1)
    elif x == 2+layer[n-1]:
        return patty[n-1]+1
    elif x <= 2+2*layer[n-1]:
        return patty[n-1]+1+eat(n-1, x-2-layer[n-1])
    else:
        return 2*patty[n-1]+1
ans = eat(n, x)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
n, x = map(int, input().split())
ans = 0
layer = [1 for _ in range(n+1)]
patty = [1 for _ in range(n+1)]
for i in range(1,n+1):
    layer[i] = 2*layer[i-1]+3
    patty[i] = 2*patty[i-1]+1
def eat(n, x):
    global ans
    # print(n ,x ,layer[n], patty[n], ans)
    if x == 0:
        print(ans)
        sys.exit()
    if layer[n] <= x:
        ans += patty[n]
        x -= layer[n]
        return x
    else:
        x -= 1
        x = eat(n-1, x)
        x -= 1
        ans += 1
        x = eat(n-1, x)
        x -= 1
x = eat(n, x)
Problem p02659 (python)

Fixed submission:
from decimal import Decimal
a, b = map(str, input().split())
num = list(str(Decimal(a) * Decimal(b)))
ans = ''
for i in num:
    if i == '.':
        break
    ans += i
print(ans)

Buggy submission (verdict: Runtime Error):
s = input().split()
a = int(s[0])
b, c = map(int, s[1].split())
print(a * b + a * c // 100)
Problem p02862 (python)

Fixed submission:
x, y = map(int, input().split())
a = (2 * y - x) / 3
b = (2 * x - y) / 3

def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod

mod = 10 ** 9 + 7
N = 10 ** 6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

if a.is_integer() and b.is_integer():
    a = int(a)
    c = int(a + b)
    print(cmb(c, a, mod))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import math
x, y = map(int, input().split())
a = (2 * y - x) / 3
b = (2 * x - y) / 3
ans = 0
if a.is_integer() and b.is_integer():
    m = math.factorial(a + b)
    n = math.factorial(a) * math.factorial(b)
    ans = m // n
    ans %= 10 ** 9 + 7
print(ans)
Problem p02897 (python)

Fixed submission:
n = int(input())
print((n // 2 + n % 2) / n)

Buggy submission (verdict: Runtime Error):
n = int(input())
if n % 2 == 0:
    print((n / 2) / n)
elif:
    print(((n + 1) / 2) / n)
Problem p02987 (python)

Fixed submission:
s = str(input())
if len(set(s)) == 2:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
p = [int(i) for i in input().split()]
ctn = 0
for j in range(1, n-1):
    if p[j - 1] < p[j] < p[j + 1] or p[j + 1] < p[j] < p[j - 1]:
        ctn += 1
print(ctn)

Buggy submission (verdict: Runtime Error):
s = str(input())
l = set(list(s))
if range(l) == 2:
  print("Yes")
else:
  print("No")
Problem p03012 (python)

Fixed submission:
n = int(input())
w = list(map(int, input().split()))
ans = float('inf')
for i in range(n):
    s1 = sum(w[:i])
    s2 = sum(w[i:])
    z = abs(s1 - s2)
    ans = min(ans, z)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
w = [map(int, input().split())]
ans = float('inf')
for i in range(n):
    s1 = sum(w[:i])
    s2 = sum(w[i:])
    z = int(abs(s1 - s2))
    ans = min(ans, z)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
w = [map(int, input().split())]
ans = 0
for i in range(n):
    s1 = sum(w[:i])
    s2 = sum(w[i:])
    z = int(abs(s1 - s2))
    ans = min(ans, z)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
w = [map(int, input().split())]
ans = 0
for i in range(n):
    s1 = sum(w[:i])
    s2 = sum(w[i:])
    z = abs(s1 - s2)
    ans = min(ans, z)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
w = input().split()
s1 = w[0]
s2 = w[n-1]
for i in range(1, n-2):
    if s1 < s2:
        s1 += w[i]
    else:
        s2 += w[-i-1]
print(abs(s1 - s2))

Buggy submission (verdict: Runtime Error):
n = int(input())
w = [map(int, input().split())]
s1 = w[0]
s2 = w[n-1]
for i in range(1, n-2):
    if s1 < s2:
        s1 += w[i]
    else:
        s2 += w[-i-1]
print(abs(s1 - s2))

Buggy submission (verdict: Runtime Error):
n = int(input())
w = [int, input().split()]
s1 = w[0]
s2 = w[n-1]
for i in range(1, n-2):
    if s1 < s2:
        s1 += w[i]
    else:
        s2 += w[-i-1]
print(abs(s1 - s2))
Problem p03072 (python)

Fixed submission:
n = int(input())
h = [int(i) for i in input().split()]
maxi = 0
ans = 0
for i in range(n):
    if maxi <= h[i]:
        ans += 1
        maxi = h[i]
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    if h[i:] = max(h[i:]):
        ans += 1
print(ans)
Problem p03077 (python)

Fixed submission:
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
num = min(a, b, c, d, e)
cnt = n // num if n % num == 0 else n // num + 1
print(cnt + 4)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
num = min(a, b, c, d, e)
cnt = n // nu if n % num == 0 else n // num + 1
print(cnt + 4)
Problem p03286 (python)

Fixed submission:
n = int(input())
ans = ''
while n != 0:
    if n % (-2) == 0:
        ans = '0' + ans
    else:
        ans = '1' + ans
        n -= 1
    n /= -2
if ans == '':
    ans = '0'
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = ''`
while n != 0:
    if n % (-2) == 0:
        ans = '0' + ans
    else:
        ans = '1' + ans
        n -= 1
    n /= -2
if ans == '':
    ans = '0'
print(ans)
Problem p03315 (python)

Fixed submission:
s = input()
print(s.count('+') - s.count('-'))

Buggy submission (verdict: Runtime Error):
s = list(map(str, input().split()))
ans = 0
for i in range(4):
    if s[i] == '+':
        ans += 1
    else:
        ans -= 1
print(ans)
Problem p03327 (python)

Fixed submission:
n = int(input())
print('ABC' if n < 1000 else 'ABD')

Buggy submission (verdict: Runtime Error):
n = int(input())
print('ABC' + n if n < 1000 else 'ABD' + n)
Problem p03631 (python)

Fixed submission:
n = input()
if n == n[::-1]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n = list(input())
m = n.reverse()
print('Yes' if ''.join(n) == ''.join(m) else 'No')
Problem p03803 (python)

Fixed submission:
a, b = map(int, input().split())
if a == b:
    print('Draw')
elif (a > b and not b == 1) or a == 1:
    print('Alice')
else:
    print('Bob')

Buggy submission (verdict: Runtime Error):
from itertools import permutations
n, m = map(int, input().split())
ab = [[] for i in range(n)]
for i in range(m):
    a, b = map(lambda x: int(x) - 1, input().split())
    ab[a].append(b)
    ab[b].append(a)
cnt = 0
if n == 2:
    if 1 in ab[0]:
        print(1)
    else:
        print(0)
    exit()
for p in permutations(range(1, n)):
    if p[0] in ab[0]:
        flag = True
        for i in range(n - 2):
            if p[i + 1] not in ab[p[i]]:
                flag = False
                break
        if flag:
            cnt += 1
print(cnt)
Problem p02580 (python)

Fixed submission:
from itertools import product

H, W, M = map(int, input().split())

HL = [0]*H
WL = [0]*W
B = []

for _ in range(M):
  h, w = map(int, input().split())
  B.append((h, w))
  HL[h-1] += 1
  WL[w-1] += 1

HM = max(HL)
WM = max(WL)

H_ans = [0]*H
W_ans = [0]*W

for i in range(H):
  if HL[i] == HM:
    H_ans[i] += 1

for j in range(W):
  if WL[j] == WM:
    W_ans[j] += 1

if sum(H_ans)*sum(W_ans) > M:
  print(HM+WM)
else:
  cnt = 0
  for h, w in B:
    if H_ans[h-1] + W_ans[w-1] == 2:
      cnt += 1
  if sum(H_ans)*sum(W_ans) > cnt:
    print(HM+WM)
  else:
    print(HM+WM-1)

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

HL, WL = [0]*H, [0]*W
B = []

for _ in range(M):
  h, w = map(lambda x:int(x)-1, input().split())
  B.append((h, w))
  HL[h] += 1
  WL[w] += 1

HM, WM = max(HL), max(WL)
K = HL.count(HM) * WM.count(WL)

cnt = 0
for h, w in B:
  if HL[h] == HM and WL[w] == WM:
    cnt += 1

if K > cnt:
  print(HM+WM)
else:
  print(HM+WM-1)
Problem p02598 (python)

Fixed submission:
from bisect import bisect_left,bisect
import math

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

m = 0
M = max(A) + 1

while M - m > 1:
  temp = (M + m) // 2
  L = bisect(A, temp)
  cnt = 0
  for i in range(L, N):
    p, q = divmod(A[i], temp)
    if q == 0:
      cnt += p-1
    else:
      cnt += p
  if cnt > K:
    m = temp
  else:
    M = temp

print(M)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left,bisect
import math

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

def is_ok(arg):
  L = bisect(A, arg)
  cnt = 0
  for i in range(L, N):
    p, q = divmod(A[i], arg)
    if q == 0:
      cnt += p-1
    else:
      cnt += p
  return cnt <= K

ng = -1
ok = max(A) + 1

def m_bisect(ng, ok):
  while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid):
      ok = mid
    else:
      ng = mid
  return ok

print(m_bisect(ng, ok))
Problem p02659 (python)

Fixed submission:
from decimal import *
getcontext().prec = 18

a, b = input().split()
ans = int(a) * Decimal(b)
print(int(str(ans)[:-3]))

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

print(int(A*B))
Problem p02729 (python)

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

print( (N*(N-1))//2 + (M*(M-1))//2 )

Buggy submission (verdict: Runtime Error):
import math

N, M = map(int, imput().split())
count = 0

def nCr(n):
  if n >= 2:
    return math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))
  else:
    return 0

print(nCr(N)+nCr(M))
Problem p02793 (python)

Fixed submission:
import math

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

mod = 10**9+7

def lcm(x, y):
  return (x // math.gcd(x, y)) * y

LCM = A[0]
for i in range(N-1):
  LCM = lcm(LCM, A[i+1])

LCM %= mod

ans = 0
for a in A:
  ans += LCM * pow(a, mod-2, mod) % mod
  ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
import math

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

mod = 10**9+7

primes = [0]*(10**3+1)

def prime_fac(n):
  temp = n
  Flag = True
  for i in range(2, int(math.sqrt(n)) + 1):
    if temp % i == 0:
      cnt = 0
      while temp % i == 0:
        cnt += 1
        temp //= i
      primes[i] = max(primes[i], cnt)
      Flag = False
  if temp != 1:
    primes[temp] = max(primes[temp], 1)
  if Flag:
    primes[n] = max(primes[n], 1)

for a in A:
  prime_fac(a)

LCM = 1
for p, i in enumerate(primes):
  if i:
    LCM *= pow(p, i, mod)
    LCM %= mod

ans = 0
for a in A:
  ans += LCM * pow(a, mod-2, mod) % mod
  ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
import math

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

mod = 10**9+7

primes = [0]*(10**3+1)

def prime_fac(n):
  temp = n
  Flag = True
  for i in range(2, int(math.sqrt(n)) + 1):
    if temp % i == 0:
      cnt = 0
      while temp % i == 0:
        cnt += 1
        temp //= i
      primes[i] = max(primes[i], cnt)
      Flag = False
  if temp != 1:
    primes[temp] = max(primes[temp], 1)
  if Flag:
    primes[n] = max(primes[n], 1)

for a in A:
  prime_fac(a)

LCM = 1
for p, i in enumerate(primes):
  if p:
    LCM *= pow(p, i, mod)
    LCM %= mod

ans = 0
for a in A:
  ans += LCM * pow(a, mod-2, mod) % mod
  ans %= mod

print(ans)

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

mod = 10**9+7
#mod = 11

LCM = A[0]
for i in range(N-1):
  LCM = lcm(LCM, A[i+1])

ans = 0
for a in A:
  ans += LCM // a
  ans %= mod

print(ans)

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

mod = 10**9+7

LCM = A[0]
for i in range(N-1):
  LCM = lcm(LCM, A[i+1])

ans = 0
for a in A:
  ans += LCM // a
  ans %= mod

print(ans)
Problem p02831 (python)

Fixed submission:
from fractions import gcd

A, B = map(int, input().split())

def lcm(x, y):
  return (x * y) // gcd(x, y)

print(lcm(A, B))

Buggy submission (verdict: Runtime Error):
import math

A, B = map(int, input().split())

def lcm(x, y):
  return (x * y)//math.gcd(x, y)

print(lcm(A, B))