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

Fixed submission:
N=int(input())  #数値入力 「N」だけの入力のとき
A=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

# from functools import lru_cache
# @lru_cache(maxsize=100000)

# 一度差を出してから，どんどんi-1, i+1の和で縮めていく．

def check_distance():
    ret = []
    left = A[0]
    right = sum(A[1:])
    tmp_a = abs(left - right)
    ret.append(tmp_a)

    for i in range(1, N-1):
        left += A[i]
        right -= A[i]
        tmp_a = abs(left - right)
        ret.append(tmp_a)
    return min(ret)

print(check_distance())

Buggy submission (verdict: Runtime Error):
N=int(input())  #数値入力 「N」だけの入力のとき
A=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

# from functools import lru_cache
# @lru_cache(maxsize=100000)

# 一度差を出してから，どんどんi-1, i+1の和で縮めていく．

def check_distance():
    ret = []
    left = A[0]
    right = sum(A[1:])

    for i in range(1, N-1):
        left += A[i]
        right -= A[i]
        tmp_a = abs(left - right)
        ret.append(tmp_a)
    return min(ret)

print(check_distance())
Problem p02861 (python)

Fixed submission:
n=int(input())
s=[list(map(int,list(input().split()))) for i in range(n)]  # 二次元配列入力　二次元マップみたいな入力のとき

# print("n", n)
# print("s:", s)

import math

def calc_distance(a, b):
    tmp = (a[0]-b[0])**2 + (a[1]-b[1])**2
    return math.sqrt(tmp)

sum = 0
for i in s: 
    for j in s:
        dist = calc_distance(i, j)
        sum += dist

print(float(sum/n))

Buggy submission (verdict: Runtime Error):
n=int(input())
s=[list(map(int,list(input().split()))) for i in range(n)]  # 二次元配列入力　二次元マップみたいな入力のとき

import math
from functools import lru_cache

@lru_cache(maxsize=100000)
def calc_distance(a, b):
    tmp = (a[0]-b[0])**2 + (a[1]-b[1])**2
    return math.sqrt(tmp)


import itertools
sum = 0
for all in itertools.permutations(s, 3):
    for i in range(n-1):
        # tupleにすることで、lru_cacheを使用可能にする．
        # listはハッシュ出来ないが、tupleはハッシュ可能．
        sum += calc_distance(tuple(all[i]), tuple(all[i+1])) 

kaizyo = math.factorial(n)
# print("sum:", sum)
# print("kaizyo:", kaizyo)

print(sum/kaizyo)
Problem p02639 (python)

Fixed submission:
xs = list(map(int,input().split()))
print(xs.index(0)+1)

Buggy submission (verdict: Runtime Error):
xs = list(map(int,input().split()))
print(xs.index(0)+1)1
Problem p02681 (python)

Fixed submission:
S = input()
T = input()
s_len = len(S)
print("Yes" if S==T[:len(S)] else "No")

Buggy submission (verdict: Runtime Error):
def main():
    N,K = map(int,input().split())
    As = list(map(int,input().split()))
    route = [0]
    pre = 0
    i = 0
    r_append = route.append
    for _ in range(N):
        i = As[i]-1
        if i in route:
            pre = route.index(i)
            route = route[pre:]
            break
        r_append(i)
        len_route += 1
    # print(route)
    mod = len(route)
    print(route[(K-pre)%mod]+1)

if __name__ == "__main__":
    main()
Problem p02684 (python)

Fixed submission:
N,K = map(int,input().split())
As = list(map(int,input().split()))
towns = [0]*N
route = [0]
pre = 0
i = 0
towns[0] = 1
for _ in range(K):
    i = As[i]-1
    if towns[i]>0:
        pre = route.index(i)
        route = route[pre:]
        break
    route.append(i)
    towns[i] = 1
mod = len(route)
print(route[(K-pre)%mod]+1)

Buggy submission (verdict: Runtime Error):
def main():
    N,K = map(int,input().split())
    As = list(map(int,input().split()))
    route = [0]
    pre = 0
    i = 0
    r_append = route.append
    for _ in range(N):
        i = As[i]-1
        if i in route:
            pre = route.index(i)
            route = route[pre:]
            break
        r_append(i)
        len_route += 1
    # print(route)
    mod = len(route)
    print(route[(K-pre)%mod]+1)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N,K = map(int,input().split())
    As = list(map(int,input().split()))
    route = [0]
    pre = 0
    i = 0
    r_append = route.append
    for _ in range(N):
        i = As[i]-1
        if i in route:
            pre = route.index(i)
            route = route[pre:]
            break
        r_append(i)
        len_route += 1
    # print(route)
    mod = len(route)
    print(route[(K-pre)%mod]+1)

if __name__ == "__main__":
    main()
Problem p02687 (python)

Fixed submission:
s = input()
print("ABC" if s== "ARC" else "ARC")

Buggy submission (verdict: Runtime Error):
import sys
import itertools
X = int(input())
N = 120
ABs = []
for i in range(N):
    ABs.append(i**5)
    
for i in range(N):
    for j in range(N):
        if ABs[i]-ABs[j] == X:
            print(i,j)
            sys.exit()
        elif ABs[i]+ABs[j] == X:
            print(i,-j)
            sys.exit()

Buggy submission (verdict: Runtime Error):
s = input()
print("ARC" if input()=="ABC" else "ABC")
Problem p02696 (python)

Fixed submission:
a,b,n=map(int,input().split())
s=n//b
nmax = (a*n)//b - a*(n//b)
# b_n = b
# b_nn = 0
# while b_n <= n:
#     x = b_n -1
#     t = (a*x)//b - a*b_nn
#     if t > nmax:
#         nmax = t
#     b_n += b
#     b_nn +=1
if s>0:
    x = b*s-1
    t = (a*x)//b - a*(s-1)
    if t > nmax:
        nmax = t
print(nmax)

Buggy submission (verdict: Runtime Error):
a,b,n=map(int,input().split())
s=n//b
nmax = (a*n)//b - a*(n//b)
# for i in range(1,s+1):
#     x = b*i-1
#     t = (a*x)//b - a*(x//b)
#     if t > nmax:
#         nmax = t
# b_n = b
# b_nn = 0
# while b_n <= n:
#     x = b_n -1
#     t = (a*x)//b - a*b_nn
#     if t > nmax:
#         nmax = t
#     b_n += b
#     b_nn +=1
x = b*s-1
t = (a*x)//b - a*b_nn
if t > nmax:
    nmax = t
print(nmax)
Problem p02702 (python)

Fixed submission:
s = input()
len_s = len(s)
pre = 0
mod = [0]*2019
mod[0]=1
x = 1
for i in range(len_s):
    pre = (x*int(s[len_s-i-1])+pre)%2019
    mod[pre] += 1
    x *= 10
    x %= 2019
print(sum([m*(m-1)//2 for m in mod]))

Buggy submission (verdict: Runtime Error):
s = input()
c = 0
for i in range(len(s)):
    for j in range(i+4,len(s)+1):
        a = int(s[i:j])
        if a>=2019 and a%3==0 a%673==0:
            c += 1
print(c)
Problem p02818 (python)

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

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
print(max(0,A-K),max(0,B-max(0,K-A)))
Problem p02945 (python)

Fixed submission:
a,b=map(int,input().split())
print(max(a+b,a-b,a*b))

Buggy submission (verdict: Runtime Error):
a.b=map(int,input().split())
print(max(a+b,a-b,a*b))
Problem p03086 (python)

Fixed submission:
S = input()
T = "ACGT"
ans = 0
cnt = 0
for s in S:
    if s in T:
        cnt += 1
    else:
        if cnt > ans:
            ans = cnt
        cnt = 0
if cnt>ans:
    ans = cnt
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
T = "ACGT"
ans = 0
for s in S:
    if s in T:
        cnt += 1
    else:
        if cnt > ans:
            ans = cnt
        cnt = 0
print(ans)
Problem p03219 (python)

Fixed submission:
x,y=map(int,input().split())
print(int(x+y/2))

Buggy submission (verdict: Runtime Error):
x,y=map(int,input().split())
print(int(x+y/2)
Problem p03377 (python)

Fixed submission:
a,b,x=map(int, input().split())
print("YES" if a+b>=x and a<=x else "NO")

Buggy submission (verdict: Runtime Error):
a,b,x=map(int, input().split())
print("YES" if a+b>=x and a=<x else "NO")
Problem p03415 (python)

Fixed submission:
l=list(input() for i in range(3))
print(l[0][0]+l[1][1]+l[2][2])

Buggy submission (verdict: Runtime Error):
l=list(input().split() for i in range(3))
print(l[0][0]+l[1][1]+l[2][2])
Problem p03635 (python)

Fixed submission:
a,b=map(int,input().split())
print((a-1)*(b-1))

Buggy submission (verdict: Runtime Error):
print(int(input())*2)
Problem p02691 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
X = dict()
ans = 0
for i in range(N):
    L = i + A[i]
    if L not in X:
        X[L] = 1
    else:
        X[L] += 1

for j in range(N):
    R = j - A[j]
    if R in X:
        ans += X[R]

print(ans)

Buggy submission (verdict: Runtime Error):
def input(): return sys.stdin.readline().rstrip()

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

ans = 0
for i in range(n):
    a = A[i]
    ato = i+a
    if i+a > n:
        ato = n
    for j in range(ato,n):
        if j-i == A[i]+A[j]:
            ans += 1

print(ans)
Problem p02702 (python)

Fixed submission:
S=input()
N=len(S)
M=2019

remainder=[0]*M
val=0
for i in range(N):
  val=(int(S[N-1-i])*pow(10,i,M)+val)%M
  remainder[val]+=1

ans=remainder[0]
for i in range(2019):
  ans+=remainder[i]*(remainder[i]-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
s = deque(input())
n = len(s)

temp = [0]*2019
t = 1
num = 0
for i in range(n):
    num += int(s.pop())*t % 2019
    temp[num] += 1
    t *= 10

ans = temp[0]
for t in temp:
    if t > 1:
        ans += t*(t-1)/2

print(int(ans))

Buggy submission (verdict: Runtime Error):
s = input()
num = len(s)

dp = [0]*num
temp = [0]*2019
for i in range(num):
    temp[i] += 1

ans = temp[0]
for t in temp:
    if t > 1:
        ans += t*(t-1)/2

print(int(ans))
Problem p02780 (python)

Fixed submission:
n,k = map(int,input().split())
P = list(map(int,input().split()))

total = 0
ans = 0
for i,a in enumerate(P):
    total += (a+1)/2
    if i >= k:
        total -= (P[i-k]+1)/2
    if i >= k-1:
        ans = max(total,ans)
    
print(ans)

Buggy submission (verdict: Runtime Error):

A ,B = [int(x) for x in input().split()]
C = [(int(x)+1)/2 for x in input().split()]
ans = 0
count = 0
D = [0]*A
sum = 0
for i in range(A):
    sum += C[i]
    D[i] = sum
    if i >= B:
        dif = sum - D[i-B]
        if dif > ans:
            ans = dif
    
if A==B:
    ans=sum[A-1]
    
print(ans)

Buggy submission (verdict: Runtime Error):
A ,B = [int(x) for x in input().split()]
C = [(int(x)+1)/2 for x in input().split()]
ans = 0
count = 0
D = [0]*A
sum = 0
for i in range(A):
    sum += C[i]
    D[i] = sum
    if i >= B:
        dif = sum[i] - D[i-B]
        if dif > ans:
            ans = dif
    
if A==B:
    ans=sum[A-1]
    
print(ans)
Problem p02924 (python)

Fixed submission:
A = int(input())  - 1
if A ==0 :print(A)
else : print(int(A*(A+1)//2))

Buggy submission (verdict: Runtime Error):
A = int(input())  
else : print(int(A*(A-1)//2))

Buggy submission (verdict: Runtime Error):

A = int(input())  1
if A ==0 :print(A)
else : print(int(A*(A-1)/2))
Problem p02995 (python)

Fixed submission:
import fractions

a,b,c,d = map(int,input().split()) 

cd = (c * d) // fractions.gcd(c, d)
b_c = b // c
b_d = b // d
b_cd = b // cd
a_c = a // c
a_d = a // d
a_cd = a // cd

ans = b - b_c - b_d + b_cd - a + a_c + a_d - a_cd

if a % c != 0 and a % d!= 0:
    ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
S = list(input())
count = 0
ans = [0]*(len(S))
for i in range(len(S)):
    if S[i] == "R":
        count += 1
    else:
        if count % 2 == 0:
            ans[i] += count//2
            ans[i-1] += count//2
            count = 0
        else:
            ans[i] += count//2 + 1
            ans[i-1] += count//2
            count = 0
	
S.reverse()
	
for i in range(len(S)):
    if S[i] == "L":
        count += 1
    else:
        if count % 2 == 0:
            ans[len(S)-i] += count//2
            ans[len(S)-i-1] += count//2
            count = 0
        else:
            ans[len(S)-i] += count//2 
            ans[len(S)-i-1] += count//2 +1
            count = 0

for a in ans:
    print(a, end=" ")

Buggy submission (verdict: Runtime Error):
import math

a,b,c,d = map(int,input().split()) 

cd = (c * d) // math.gcd(c, d)
b_c = b // c
b_d = b // d
b_cd = b // cd
a_c = a // c
a_d = a // d
a_cd = a // cd

ans = b - b_c - b_d + b_cd - a + a_c + a_d - a_cd

if a % c != 0 and a % d!= 0:
    ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import math
def cal_lcm(x, y):
    return (x * y) // math.gcd(x, y)

a,b,c,d = map(int,input().split()) 

cd = cal_lcm(c,d)
b_c = b // c
b_d = b // d
b_cd = b // cd
a_c = a // c
a_d = a // d
a_cd = a // cd

ans = b - b_c - b_d + b_cd - a + a_c + a_d - a_cd

if a % c != 0 and a % d!= 0:
    ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split()) 

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

cd = lcm(c,d)
b_c = b // c
b_d = b // d
b_cd = b // cd
a_c = a // c
a_d = a // d
a_cd = a // cd

ans = b - b_c - b_d + b_cd - a + a_c + a_d - a_cd

if a % c != 0 and a % d!= 0:
    ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split()) 

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

cd = lcm(c,d)
b_c = b // c
b_d = b // d
b_cd = b // cd
a_c = a // c
a_d = a // d
a_cd = a // cd

ans = b - b_c - b_d + b_cd - a + a_c + a_d - a_cd

if a % c != 0 and a % d!= 0:
    ans += 1

print(ans)
Problem p03043 (python)

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

L = [0]*N
num =1
for i in range(N):
    num = 1
    if i < K:
        while num*(i+1) < K:
            num *= 2
        L[i]= 1/N * 1/num
    else:
        L[i] = 1/N

ans = 0
for i in range(N):
        ans +=L[i]

print(ans)

Buggy submission (verdict: Runtime Error):
N,K =  [int(x) for x in input().split()]
num = 1
while num < K:
    num *= 2

L = [0.0000]*N

for i in range(N):
    if N < K:
        if num/(i+1) < K:
            num = num/2
        L[i]= 1/N * 1/num    
    else:
        L[i] = 1/N

ans = 0
for i in range(N):
        ans +=L[i]

print(ans)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)

def dfs(v, p, dist):
    for u, w in tree[v]:
        if u == p:
            continue
        else:
            dist[u] = dist[v] + w
            dfs(u, v, dist)
 
 
n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    tree[u - 1].append((v - 1, w))
    tree[v - 1].append((u - 1, w))
 
dist = [0 for _ in range(n)]
dfs(0, -1, dist)
 
for i in dist:
    if i % 2 == 0:
        print(0)
    else:
        print(1)

Buggy submission (verdict: Runtime Error):
import sys
sys.getrecursionlimit(10**7)

def dfs(v,p,dist):
    for u,v in tree[v]:
        if u==p:
            continue
        else:
            dist[u]=dist[v]+w
            dfs(u,v,dist)
    
n =int(input())
tree = [[] for _ in range(n)]
for _ in range(n-1):
    u,v,w =map(int,input.split())
    tree[u-1].append((v-1,w))
    tree[v-1].append((u-1,w))
dist =[0]*N
dfs(0,-1,dist)

for num in dist:
    if num % 2==0:
        print("1")
    else:
        print("0")

Buggy submission (verdict: Runtime Error):
def dfs(v, p, dist):
    for u, w in tree[v]:
        if u == p:
            continue
        else:
            dist[u] = dist[v] + w
            dfs(u, v, dist)
 
 
n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    tree[u - 1].append((v - 1, w))
    tree[v - 1].append((u - 1, w))
 
dist = [0 for _ in range(n)]
dfs(0, -1, dist)
 
for i in dist:
    if i % 2 == 0:
        print(0)
    else:
        print(1)
Problem p03145 (python)

Fixed submission:
L = list(map(int,input().split()))
     
print(L[0]*L[1]//2)

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

print(L[0]*l[1]//2)
Problem p03160 (python)

Fixed submission:
n = int(input())
H = list(map(int,input().split()))
dp = [0]*n

for i in range(1,n):
    if i == 1 or i == 2:
        dp[i] = abs(H[i]-H[0])
    else:
        dp[i] = min(abs(H[i]-H[i-2])+dp[i-2],abs(H[i]-H[i-1])+dp[i-1])

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
H = list(map(int,input().split()))
dp = [0]*n

def rec(i):
    res = 0
    if i == 1 or i == 2:
        res = abs(H[i]-H[0])
        dp[i] = res
        return res
    elif i == 0:
        return 0
    if dp[i] != 0:
        return dp[i]
    else:
        res = min(abs(H[i]-H[i-2])+rec(i-2),abs(H[i]-H[i-1])+rec(i-1))
        dp[i] = res
    return res

rec(n-1)

print(dp[n-1])
Problem p03162 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

n = int(input())
dp = [[0]*3  for _ in range(n)] 
ABC = []
for _ in range(n):
    a,b,c = map(int,input().split())
    ABC.append([a,b,c])

def rec(flag,num):# flag は A=0,B=1,C=2を表す。 numは何番目かを表す。
    if dp[num][flag] != 0:
        return dp[num][flag]
    if num == 0:
        dp[num][flag] = ABC[num][flag]
        return dp[num][flag]
    else:
        res = 0
        if flag == 0:
            res = max(rec(1,num-1),rec(2,num-1))+ABC[num][flag]
        elif flag == 1:
            res = max(rec(0,num-1),rec(2,num-1))+ABC[num][flag]
        else:
            res = max(rec(1,num-1),rec(0,num-1))+ABC[num][flag]
        dp[num][flag] = res
        return dp[num][flag]

rec(0,n-1)
rec(1,n-1)
rec(2,n-1)

print(max(dp[n-1]))

Buggy submission (verdict: Runtime Error):
n = int(input())
dp = [[0]*3  for _ in range(n)] 
ABC = []
for _ in range(n):
    a,b,c = map(int,input().split())
    ABC.append([a,b,c])

def rec(flag,num):# flag は A=0,B=1,C=2を表す。 numは何番目かを表す。
    if dp[num][flag] != 0:
        return dp[num][flag]
    if num == 0:
        dp[num][flag] = ABC[num][flag]
        return dp[num][flag]
    else:
        res = 0
        if flag == 0:
            res = max(rec(1,num-1),rec(2,num-1))+ABC[num][flag]
        elif flag == 1:
            res = max(rec(0,num-1),rec(2,num-1))+ABC[num][flag]
        else:
            res = max(rec(1,num-1),rec(0,num-1))+ABC[num][flag]
        dp[num][flag] = res
        return dp[num][flag]

rec(0,n-1)
rec(1,n-1)
rec(2,n-1)

print(max(dp[n-1]))
Problem p03163 (python)

Fixed submission:
import numpy as np
n,w=map(int,input().split())
 
dp=np.zeros(w+1,np.int64)
for i in range(n):
    w,v = map(int,input().split())
    dp[w:] = np.maximum(dp[w:], dp[:-w] + v)
    
print(np.max(dp))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

import numpy as np
N,W = map(int,input().split())
WV = [(list(map(int,input().split()))) for _ in range(N)]
DP = np.array([[0]*(W+1) for _ in range(N+1)], dtype=np.int64)

def rec(i,w,v):
    if DP[i][w] != 0:
        return DP[i][w]
    if i == N:
        return v
    if w == 0:
        return v
    else:
        res = rec(i+1,w,v)
        if w-WV[i][0] >= 0:
            res = max(res,rec(i+1,w-WV[i][0],v+WV[i][1]))
        DP[i][w] = res
        return DP[i][w]

rec(0,W,0)
print(np.max(DP))

Buggy submission (verdict: Runtime Error):
import numpy as np
N,W = map(int,input().split())
WV = [(list(map(int,input().split()))) for _ in range(N)]
DP = np.array([[0]*(W+1) for _ in range(N+1)], dtype=np.int64)

def rec(i,w,v):
    if DP[i][w] != 0:
        return DP[i][w]
    if i == N:
        return v
    if w == 0:
        return v
    else:
        res = rec(i+1,w,v)
        if w-WV[i][0] >= 0:
            res = max(res,rec(i+1,w-WV[i][0],v+WV[i][1]))
        DP[i][w] = res
        return DP[i][w]

rec(0,W,0)
print(np.max(DP))
Problem p03219 (python)

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

print(L[0]+L[1]//2)

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

print(L[0]+l[1]//2)
Problem p03231 (python)

Fixed submission:
import fractions

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

n,m = map(int,input().split())
S = input()
T = input()

l = lcm(n,m)
i = 0
j = 0
ans = l
while i < n or j < m:
    temp_n = i*l//n+1
    temp_m = j*l//m+1
    if temp_n == temp_m:
        if S[i] != T[j]:
            ans = -1
            break
        i += 1
        j += 1
    elif temp_m > temp_n:
        i += 1
    else:
        j += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import fractions

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

n,m = map(int,input().split())
S = input()
T = input()

l = lcm(n,m)
c_max = max(n,m)
ans_s = [" "]*(l+1)
ans_t = [" "]*(l+1)
for i in range(n):
    ans_s[i*l//n+1] = S[i]
for i in range(m):
    ans_t[i*l//m+1] = T[i]
    
ans = l
for i in range(l+1):
    if ans_s[i] != " " and ans_t[i] != " " and ans_s[i] != ans_t[i]:
        ans = -1

print(ans)

Buggy submission (verdict: Runtime Error):
import math

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

n,m = map(int,input().split())
S = input()
T = input()

l = lcm(n,m)
c_max = max(n,m)
ans_s = [" "]*(l+1)
ans_t = [" "]*(l+1)
for i in range(n):
    ans_s[i*l//n+1] = S[i]
for i in range(m):
    ans_t[i*l//m+1] = T[i]
    
ans = l
for i in range(l+1):
    if ans_s[i] != " " and ans_t[i] != " " and ans_s[i] != ans_t[i]:
        ans = -1

print(ans)

Buggy submission (verdict: Runtime Error):
import math

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

n,m = map(int,input().split())
S = input()
T = input()

l = lcm(n,m)
c_max = max(n,m)
ans_s = [" "]*(l+1)
ans_t = [" "]*(l+1)
for i in range(n):
    ans_s[i*l//n+1] = S[i]
for i in range(m):
    ans_t[i*l//m+1] = T[i]
    
ans = l
for i in range(l+1):
    if ans_s[i] != " " and ans_t[i] != " " and ans_s[i] != ans_t[i]:
        ans = -1

print(ans)
Problem p03280 (python)

Fixed submission:
a,b = map(int,input().split())
#A = list(map(int,input().split()))
ans = (a-1)*(b-1)
 
print(ans)

Buggy submission (verdict: Runtime Error):
#n = int(input())
a,b = map(str,input().split())
#A = list(map(int,input().split()))
ans = (a-1)*(b-1)

print(ans)
Problem p02613 (python)

Fixed submission:
l = []
for i in range(int(input())):
   l.append(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in l:
    if i == "AC":
        ac+=1
    if i == "TLE":
        tle+=1
    if i == "WA":
        wa+=1
    if i == "RE":
        re+=1
print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re))

Buggy submission (verdict: Runtime Error):
l = []
for i in range(int(input()):
   l.append(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in l:
    if i == "AC":
        ac+=1
    if i == "TLE":
        tle+=1
    if i == "WA":
        wa+=1
    if i == "RE":
        re+=1
print("AC X "+str(ac))
print("WA X "+str(wa))
print("TLE X "+str(tle))
print("RE X "+str(re))
Problem p03161 (python)

Fixed submission:
n, k = [int(e) for e in input().split()]
arr = [int(e) for e in input().split()]
dp = [0]*len(arr)
 
for i in range(1,len(arr)):
  dp[i] = min(dp[j] + abs(arr[i]-arr[j]) for j in range(max(i-k,0),i))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
x,k = map(int,input().split())
arr = list(map(int,input().split()))


dp = [0]*len(arr)
for i in range(1,k):
  dp[i] = abs(arr[i]-arr[0])

for i in range(k,len(arr)):
  curr = float("inf")
  for j in range(1,k+1):
    curr = min(curr,dp[i-j] + abs(arr[i]-arr[i-j]))
  dp[i] = curr
print(dp[-1])
Problem p02630 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
q=int(input())
d=[0]*100001
for i in a:
    d[i-1]+=1
s=0
for num,i in enumerate(d):
    s+=i*(num+1)

bb=[]
cc=[]
for i in range(q):
    b,c=map(int,input().split())
    bb.append(b)
    cc.append(c)

for b,c in zip(bb,cc):
    k=d[b-1]
    s+=(c-b)*k
    d[b-1]=0
    d[c-1]+=k

    print(s)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
q=int(input())
d=[0]*1000
for i in a:
    d[i-1]+=1
s=0
for num,i in enumerate(d):
    s+=i*(num+1)

bb=[]
cc=[]
for i in range(q):
    b,c=map(int,input().split())
    bb.append(b)
    cc.append(c)

for b,c in zip(bb,cc):
    k=d[b-1]
    s+=(c-b)*k
    d[b-1]=0
    d[c-1]+=k

    print(s)
Problem p02642 (python)

Fixed submission:
n=int(input())
a=sorted(list(map(int,input().split())))

M=1000005
l=[0 for i in range(M)]
for i in a:
    if(l[i]!=0):
        l[i]=2
        continue
    for j in range(i,M,i):
        l[j]+=1
ans=0
for i in a:
    if(l[i]==1):ans+=1
print(ans)

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



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

max=a[-1]
ans=0
if(len(a)!=len(set(a))):ans-=1
primeNum = []
while a:
    primeNum.append(a[0])
    tmp=a[0]
    a=[i for i in a if i % tmp != 0]
primeNum.extend(a)
ans+=len(primeNum)


print(ans)