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

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def MI(): return map(int,sys.stdin.readline().rstrip().split())


class SCC:
    def __init__(self,N):
        self.N = N
        self.graph = [[] for _ in range(N)]
        self.graph_rev = [[] for _ in range(N)]
        self.flag = [False]*N

    def add_edge(self,start,end):
        if start == end:
            return
        self.graph[start].append(end)
        self.graph_rev[end].append(start)

    def dfs(self,node,graph):
        self.flag[node] = True
        for n in graph[node]:
            if self.flag[n]:
                continue
            self.dfs(n,graph)
        self.order.append(node)

    def first_dfs(self):
        self.flag = [False]*self.N
        self.order = []
        for i in range(self.N):
            if self.flag[i] == False:
                self.dfs(i,self.graph)

    def second_dfs(self):
        self.flag = [False]*self.N
        self.ans = []
        for n in reversed(self.order):
            if self.flag[n]:
                continue
            self.flag[n] = True
            self.order = []
            self.dfs(n,self.graph_rev)
            self.order.reverse()
            self.ans.append(self.order)

    def scc(self):
        self.first_dfs()
        self.second_dfs()
        return self.ans


N,M = MI()
SCC = SCC(N)

for _ in range(M):
    a,b = MI()
    SCC.add_edge(a,b)

ANS = SCC.scc()

print(len(ANS))
for s in ANS:
    print(*([len(s)]+s))

Buggy submission (verdict: Runtime Error):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


class SCC:
    def __init__(self,N):
        self.N = N
        self.graph = [[] for _ in range(N)]
        self.graph_rev = [[] for _ in range(N)]
        self.flag = [False]*N

    def add_edge(self,start,end):
        if start == end:
            return
        self.graph[start].append(end)
        self.graph_rev[end].append(start)

    def dfs(self,node,graph):
        self.flag[node] = True
        for n in graph[node]:
            if self.flag[n]:
                continue
            self.dfs(n,graph)
        self.order.append(node)

    def first_dfs(self):
        self.flag = [False]*self.N
        self.order = []
        for i in range(self.N):
            if self.flag[i] == False:
                self.dfs(i,self.graph)

    def second_dfs(self):
        self.flag = [False]*self.N
        self.ans = []
        for n in reversed(self.order):
            if self.flag[n]:
                continue
            self.flag[n] = True
            self.order = []
            self.dfs(n,self.graph_rev)
            self.order.reverse()
            self.ans.append(self.order)

    def scc(self):
        self.first_dfs()
        self.second_dfs()
        return self.ans


N,M = MI()
SCC = SCC(N)

for _ in range(M):
    a,b = MI()
    SCC.add_edge(a,b)

ANS = SCC.scc()

print(len(ANS))
for s in ANS:
    print(*([len(s)]+s))
Problem p02632 (python)

Fixed submission:
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

K = I()
n = len(LS2())
mod = 10**9+7

# 完成図は、
# (S[0]以外からなる文字列)S[0](S[1]以外からなる文字列)S[1]…(S[n-1]以外からなる文字列)S[n-1](任意の文字列)
# この表記は一意
# 形式的冪級数で考えると,
# 求めたいものは (1-25x)^(-n)*(1-26x)^(-1) の x^K の係数であり、
# これは、(i+n-1)_C_(n-1)*25^i*26^(K-i) を i=0,…,K にわたって足し合わせたものである

C = [1]
for i in range(1,K+1):
    C.append((C[-1]*(i+n-1)*pow(i,mod-2,mod)) % mod)
# C[i] = (i+n-1)_C_(n-1)

ans = 0
for i in range(K+1):
    ans += C[i]*pow(25,i,mod)*pow(26,K-i,mod)
    ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

K = I()
S = LI2()
s = len(S)
mod = 10**9+7

dp1 = [0]*(K+s)
dp2 = [0]*(K+s)

for i in range(K+s):
    if i == s-1:
        dp1[i] = pow(26,i,mod)-1
    elif i == s:
        dp2[i] = pow(26,i,mod)-1
    else:
        dp1[i] = dp1[i-1]*26+dp2[i-1]*25
        dp1[i] %= mod
        dp2[i] = dp2[i-1]*26 + dp1[i-1]*25
        dp2[i] %= mod



print((dp1[K+s-1]*26 + (dp2[K+s-1]-dp1[K+s-1])*25) % mod)
Problem p02713 (python)

Fixed submission:
K = int(input())

from math import gcd

def g(a,b,c):
  return gcd(gcd(a,b),c)

a = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      a += g(i,j,k)

print(a)

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

import gcd from math

def g(a,b,c):
  retunr gcd(gcd(a,b),c)

a = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      a += g(i,j,k)

print(a)
Problem p02716 (python)

Fixed submission:
import math

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

B = [{} for _ in range(N+1)]


for i in range(1,N+1):
  if i == 1:
    B[1][0] = 0
    B[1][1] = A[0]
  elif i == 2:
    B[2][1] = max(A[0],A[1])
    if N % 2 == 1:
      B[2][0] = 0
  else:
    if N % 2 == 0:
      for j in range(math.ceil((i-1)/2),(i+1)//2+1):
        m1 = B[i-2][j-1]+A[i-1] if j-1 in B[i-2] else -float('inf')
        m2 = B[i-1][j] if j in B[i-1] else -float('inf')
        B[i][j] = max(m1,m2)
    else:
      for j in range(math.ceil((i-2)/2),(i+1)//2+1):
        m1 = B[i-2][j-1]+A[i-1] if j-1 in B[i-2] else -float('inf')
        m2 = B[i-1][j] if j in B[i-1] else -float('inf')
        B[i][j] = max(m1,m2)
      

print(B[N][N//2])

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]

def f(i,j):
  a = 0
  if not 2*j-1 <= i <= 2*j+1+(N-2*int(N/2)):
    a = 0
  elif i == 1 and j == 0:
    a = 0
  elif i == 1 and j == 1:
    a = A[0]
  elif i == 2 and j == 1:
    a = max(A[0],A[1])
  elif i == 2 and j == 0:
    a = 0
  else:
    a = max(f(i-2,j-1)+A[i-1],f(i-1,j))
  return a

print(f(N,int(N/2)))
Problem p02761 (python)

Fixed submission:
N,M = map(int,input().split())
data = [list(map(int,input().split())) for i in range(M)]

A = [[] for i in range(3)]

for i in range(M):
    if data[i][0] == 1 and data[i][1] == 0 and N != 1:
        print(-1)
        exit()
    else:
        A[data[i][0]-1].append(data[i][1])

for i in range(N):
    A[i] = set(A[i])
    if len(A[i]) > 1:
        print(-1)
        exit()

B = []
for i in range(N):
    if len(A[i]) == 1:
        for s in A[i]:
            if i == 0 and s == 0 and N != 1:
                B.append(1)
            else:
                B.append(s)
    else:
        if i == 0 and N != 1:
            B.append(1)
        else:
            B.append(0)

ans = str(B[0])
for i in range(1,N):
    ans += str(B[i])

print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
data = [list(map(int,input().split())) for i in range(M)]

A = [[] for i in range(3)]

for i in range(M):
    if data[i][0] == 1 and data[i][1] == 0:
        print(-1)
        exit()
    else:
        A[data[i][0]-1].append(data[i][1])

for i in range(N):
    A[i] = set(A[i])
    if len(A[i]) > 1:
        print(-1)
        exit()

B = []
for i in range(N):
    if len(A[i]) == 1:
        for s in A[i]:
            B.append(s)
    else:
        B.append(0)

ans = str(B[0])
for i in range(1,3):
    ans += str(B[i])

print(ans)
Problem p02803 (python)

Fixed submission:
from collections import deque

H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]
directions = [[0,1],[1,0],[0,-1],[-1,0]]

def f(h,w): #スタートが(h,w)
  if S[h][w] == '#':
    return 0
  else:
    d = [[-1]*W for i in range(H)]
    d[h][w] = 0
    
    q = deque([[h,w]])
    
    while q:
      nh,nw = q.pop()
      
      for dh,dw in directions:
        if not (0<=nh+dh<H and 0<=nw+dw<W):
          continue
        if S[nh+dh][nw+dw] == '#':
          continue
        if d[nh+dh][nw+dw] != -1:
          continue
        d[nh+dh][nw+dw] = d[nh][nw]+1
        q.appendleft([nh+dh,nw+dw])
     
    return max([max(i) for i in d])

a = 0
for h in range(H):
  for w in range(W):
    a = max(a,f(h,w))
    
print(a)

Buggy submission (verdict: Runtime Error):
from collections import deque

H,W = map(int,input().split())
S = [list(input().split()) for _ in range(H)]
a = 0

for h in range(H):
  for w in range(W): #スタートが(h,w)
    if S[h][w] == '#':
      continue
    d = [[-1]*W for i in range(H)]
    d[h][w] = 0
    
    q = deque([[h,w]])
    
    while q:
      nh,nw = q.pop()
      
      if nw+1<W and S[nh][nw+1]=='.' and d[nh][nw+1]==-1:
        d[nh][nw+1] = d[nh][nw]+1
        q.append([nh,nw+1])
      if 0<=nw-1 and S[nh][nw-1]=='.' and d[nh][nw-1]==-1:
        d[nh][nw-1] = d[nh][nw]+1
        q.append([nh,nw-1])
      if nh+1<H and S[nh+1][nw]=='.' and d[nh+1][nw]==-1:
        d[nh+1][nw] = d[nh][nw]+1
        q.append([nh+1,nw])
      if 0<=nh-1 and S[nh-1][nw]=='.' and d[nh-1][nw]==-1:
        d[nh-1][nw] = d[nh][nw]+1
        q.append([nh-1,nw])
    a = max(a,max([max(i) for i in d]))
    
print(a)
Problem p02823 (python)

Fixed submission:
N,A,B = map(int,input().split())
if (B-A) % 2 == 0:
  print((B-A)//2)
elif A-1 <= N-B:
  print((A+B-1)//2)
else:
  print(N+1-(B+A+1)//2)

Buggy submission (verdict: Runtime Error):
S = list(input())
s = len(S)
K = int(input())
A = []
j = 1

for i in range(0,s-1,1):
  if S[i] == S[i+1]:
    j += 1
  else:
    A.append(j)
    j = 1
A.append(j)

a = len(A)

b = 0
for i in range(a):
  b += i//2
  
x = b*K

if S[s-1] == S[0] and A[a-1] % 2 == 1 and A[1] % 2 == 1:
  x += K-1
  
print(x)
Problem p02910 (python)

Fixed submission:
import sys
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


S = LS2()
N = len(S)
S1 = S[::2]
S2 = S[1::2]

r = sum(s in ['R','U','D'] for s in S1) + sum(s in ['L','U','D'] for s in S2)
print('Yes' if r == N else 'No')

Buggy submission (verdict: Runtime Error):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N,K,Q = MI()

X = [0]*(N+1)  # 各参加者の正解数
for _ in range(Q):
    a = I()
    X[a] += 1

for i in range(1,N+1):
    x = X[i]
    print('Yes' if K-(Q-x) > 0 else 'No')
Problem p02936 (python)

Fixed submission:
N,Q = map(int,input().split())
A = [list(map(int,input().split())) for i in range(N-1)]
B = [list(map(int,input().split())) for i in range(Q)]

G = {}
for i in range(1,N+1):
    G[i] = []

for i in range(N-1):
    G[A[i][0]].append(A[i][1])
    G[A[i][1]].append(A[i][0])

from collections import deque

H = {}
for i in range(1,N+1):
    H[i] = 0

for i in range(Q):
    H[B[i][0]] += B[i][1]

#bfs

r = 0
P = [0]*(N+1)  #ポイント

D = [0]+[-1]*(N)
D[1] = 1
P[1] = H[1]
q = deque([1])

while q:
    n = q.pop()
    for d in G[n]:
        if D[d] != -1:
            continue
        else:
            D[d] = 1
            q.appendleft(d)
            P[d] = P[n] + H[d]
del P[0]

print(*P)

Buggy submission (verdict: Runtime Error):
P = [0]*(N+1)  #ポイント

D = [0]+[-1]*(N)
D[1] = 1
P[1] = H[1]
q = deque([1])

while q:
    n = q.pop()
    for d in G[n]:
        if D[d] != -1:
            continue
        else:
            D[d] = 1
            q.appendleft(d)
            P[d] = P[n] + H[d]
del P[0]

print(*P)
Problem p02993 (python)

Fixed submission:
S = list(input())

for i in range(len(S)-1):
  if S[i] == S[i+1]:
    print('Bad')
    break
else:
  print('Good')

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

A = []

for i in range(N):
    A.append((data[i][1],data[i][0]))

A = sorted(A)

a = 0  #i番目にやった仕事の終了時間
for i in range(N):
    a += A[i][1]
    if a > A[i][0]:
        print('No')
        break
    else:
        continue
else:
    print('Yes')
Problem p03060 (python)

Fixed submission:
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
V = LI()
C = LI()

ans = 0
for i in range(N):
    v,c = V[i],C[i]
    if v-c > 0:
        ans += v-c

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()

ans = 0
for i in range(N):
    v,c = LI()
    if v-c > 0:
        ans += v-c

print(ans)
Problem p03061 (python)

Fixed submission:
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
A = LI()

from fractions import gcd

L = [0]*N  # L[i] = A[0]からA[i]までの最大公約数
R = [0]*N  # R[i] = A[i]からA[N-1]までの最大公約数

for i in range(N-1):
    if i == 0:
        L[i] = A[i]
        R[N-1-i] = A[N-1-i]
    else:
        L[i] = gcd(L[i-1],A[i])
        R[N-1-i] = gcd(R[N-i],A[N-1-i])

a = max(L[N-2],R[1])

if N == 2:
    print(a)
else:
    print(max(a,max(gcd(L[i],R[i+2]) for i in range(N-2))))

Buggy submission (verdict: Runtime Error):
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
A = LI()

from functions import gcd

L = [0]*N  # L[i] = A[0]からA[i]までの最大公約数
R = [0]*N  # R[i] = A[i]からA[N-1]までの最大公約数

for i in range(N-1):
    if i == 0:
        L[i] = A[i]
        R[N-1-i] = A[N-1-i]
    else:
        L[i] = gcd(L[i-1],A[i])
        R[N-1-i] = gcd(R[N-i],A[N-1-i])

a = max(L[N-1],R[1])

if N == 2:
    print(a)
else:
    print(max(a,max(gcd(L[i],R[i+2]) for i in range(N-2))))

Buggy submission (verdict: Runtime Error):
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
A = LI()

from math import gcd

L = [0]*N  # L[i] = A[0]からA[i]までの最大公約数
R = [0]*N  # R[i] = A[i]からA[N-1]までの最大公約数

for i in range(N-1):
    if i == 0:
        L[i] = A[i]
        R[N-1-i] = A[N-1-i]
    else:
        L[i] = gcd(L[i-1],A[i])
        R[N-1-i] = gcd(R[N-i],A[N-1-i])

a = max(L[N-1],R[1])

if N == 2:
    print(a)
else:
    print(max(a,max(gcd(L[i],R[i+2]) for i in range(N-2))))
Problem p03246 (python)

Fixed submission:
from collections import Counter

n = int(input())
v = [int(i) for i in input().split()]

A = []
B = []
for i in range(n):
    if i % 2 == 0:
        A.append(v[i])
    else:
        B.append(v[i])

C = Counter(A)
D = Counter(B)

E = C.most_common()
F = D.most_common()

E += [(-1,0)]
F += [(-1,0)]

if E[0][0] != F[0][0]:
    print(n-E[0][1]-F[0][1])
else:
    print(n-max(E[0][1]+F[1][1],E[1][1]+F[0][1]))

Buggy submission (verdict: Runtime Error):
rom collections import Counter

n = int(input())
v = [int(i) for i in input().split()]

A = []
B = []
for i in range(n):
    if i % 2 == 0:
        A.append(v[i])
    else:
        B.append(v[i])

C = Counter(A)
D = Counter(B)

E = C.most_common()
F = D.most_common()

E += [(-1,0)]
F += [(-1,0)]

if E[0][0] != F[0][0]:
    print(n-E[0][1]-F[0][1])
else:
    print(n-max(E[0][1]+F[1][1],E[1][1]+F[0][1]))
Problem p03285 (python)

Fixed submission:
import sys

def I():
    return int(sys.stdin.readline().rstrip())

N = I()

A = [1,2,3,5,6,9,10,13,17]
if N in A:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
import sys

N,K = map(int,sys.stdin.readline().rstrip().split())

print(0 if N % K == 0 else 1)
Problem p03311 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
A = LI()
for i in range(N):
    A[i] -= i+1
A.sort()


def f(x):
    return sum(abs(A[i]-x) for i in range(N))


print(f((A[(N-1)//2]+A[N//2])//2))

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
A = LI()
for i in range(N):
    A[i] -= i+1
A.sort()

x = A[N//2]
y = A[(N-1)//2]
z = (A[x]+A[y])//2

print(sum(abs(A[i]-z) for i in range(N)))
Problem p03402 (python)

Fixed submission:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

A,B = MI()

q1,r1 = (B-1)//50,(B-1)%50
q1 += 1
q2,r2 = (A-1)//50,(A-1)%50
q2 += 1

if B > 1 and A > 1:
    print(2*(q1+q2),100)
elif (B == 1 and A > 1) or (B > 1 and A == 1):
    print(2*(q1+q2)-1,100)
else:
    print(2,100)

if B > 1:
    for i in range(2 * q1):
        if i % 2 == 1:
            print(''.join(['.'] * 100))
        elif i != 2 * q1 - 2:
            print(''.join(['.', '#'] * 50))
        else:
            print(''.join(['.', '#'] * r1 + ['.'] * (100 - 2 * r1)))
else:
    print(''.join(['.']*100))


if A > 1:
    for i in range(2 * q2):
        if i % 2 == 0:
            print(''.join(['#'] * 100))
        elif i != 2 * q2 - 1:
            print(''.join(['#', '.'] * 50))
        else:
            print(''.join(['#', '.'] * r2 + ['#'] * (100 - 2 * r2)))
else:
    print(''.join(['#']*100))

Buggy submission (verdict: Runtime Error):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

A,B = MI()

if B > 1:
    q1,r1 = (B-1)//50,(B-1)%50
    q1 += 1
else:
    q1 = 0
if A > 1:
    q2,r2 = (A-1)//50,(A-1)%50
    q2 += 1
else:
    q2 = 0

print(2*(q1+q2),100)

for i in range(2*q1):
    if i % 2 == 1:
        print(''.join(['.']*100))
    elif i != 2*q1-2:
        print(''.join(*['.','#']*50))
    else:
        print(''.join(['.','#']*r1 + ['.']*(100-2*r1)))

for i in range(2*q2):
    if i % 2 == 0:
        print(''.join(['#']*100))
    elif i != 2*q2-1:
        print(''.join(['#','.']*50))
    else:
        print(''.join(['#','.']*r2 + ['#']*(100-2*r2)))
Problem p03504 (python)

Fixed submission:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N,C = MI()
A = [[0]*(10**5+2) for i in range(C+1)]
for i in range(N):
    s,t,c = MI()
    A[c][s] += 1
    A[c][t+1] -= 1

from itertools import accumulate

for i in range(1,C+1):
    A[i] = list(accumulate(A[i]))

# A[i][j] が正 ⇔ チャンネル i が時刻 j に録画機が必要

ans = 0
for j in range(10**5+2):
    ans = max(ans,sum(A[i][j] > 0 for i in range(1,C+1)))

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N,C = MI()
A = [[0]*(10**5+1) for i in range(C+1)]
for i in range(N):
    s,t,c = MI()
    A[c][s] += 1
    A[c][t+1] -= 1

from itertools import accumulate

for i in range(1,C+1):
    A[i] = list(accumulate(A[i]))

# A[i][j] が正 ⇔ チャンネル i が時刻 j に録画機が必要

ans = 0
for j in range(10**5+1):
    ans = max(ans,sum(A[i][j] > 0 for i in range(1,C+1)))

print(ans)
Problem p03558 (python)

Fixed submission:
import sys
def I(): return int(sys.stdin.readline().rstrip())

K = I()

Graph = [0]*K
for i in range(K):
    if (i+1) % K != (10*i) % K:
        Graph[i] = [((i+1) % K,1),((10*i) % K,0)]  # 1を加える,10倍する
    else:
        Graph[i] = [((10*i) % K,0)]

from collections import deque

q = deque([1])
d = [100]*K
d[1] = 1
# 01-BFS
while q:
    n = q.pop()
    if n == 0:
        continue
    else:
        for a,b in Graph[n]:
            if d[a] > d[n]+b:
                d[a] = d[n]+b
                if b == 0:
                    q.append(a)
                else:
                    q.appendleft(a)

print(d[0])

Buggy submission (verdict: Runtime Error):
import sys
def I(): return int(sys.stdin.readline().rstrip())

K = I()

Graph = [0]*K
for i in range(K):
    if (i+1) % K != (10*i) % K:
        Graph[i] = [(1,(i+1) % K),(0,(10*i) % K)]  # 1を加える,10倍する
    else:
        Graph[i] = [(0,(10*i) % K)]

# dijkstra

from heapq import heappush,heappop

d = [100]*K
d[1] = 1
q = []
heappush(q,(1,1))
v = [False]*K
while q:
    a,n = heappop(q)
    if v[n]:
        continue
    v[a] = True
    for da,dn in Graph[n]:
        if v[dn]:
            continue
        if a+da < d[dn]:
            d[dn] = a+da
            heappush(q,(a+da,dn))

print(d[0])
Problem p03633 (python)

Fixed submission:
import sys

def I(): return int(sys.stdin.readline().rstrip())

N = I()
T = [I() for _ in range(N)]

from fractions import gcd

ans = T[0]
for i in range(N-1):
    ans = (ans*T[i+1])//gcd(ans,T[i+1])

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

def I(): return int(sys.stdin.readline().rstrip())

N = I()
T = [I() for _ in range(N)]

from math import gcd

ans = T[0]
for i in range(N-1):
    ans = (ans*T[i+1])//gcd(ans,T[i+1])

print(ans)
Problem p03818 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
A = LI()
B = sorted(set(A))
d = {}
for b in B:
    d[b] = 0
for a in A:
    d[a] += 1

C = [d[b] for b in B]

ans = len(B)
x = sum(c-1 for c in C)
if x % 2 == 1:
    ans -= 1

print(ans)

Buggy submission (verdict: Runtime Error):
N = I()
A = LI()
B = [0]*(10**5+1)
for a in A:
    B[a] += 1

print(sum(B[i] != 0 for i in range(10**5+1))-(sum(max(0,B[i]-1) for i in range(10**5+1)) % 2))
Problem p03059 (python)

Fixed submission:
A, B, T = (int(i) for i in input().split())

count = 0
for i in range(0, int(T/A)):
    count += B

print(count)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
T = int(input())

count = 0
x = int((T+0.5)/A)
for i in range(1,x+1):
    count += B

print(count)
Problem p02534 (python)

Fixed submission:
k = int(input())
s = ''
for i in range(k):
  s += 'ACL'
print(s)

Buggy submission (verdict: Runtime Error):
k = int(input())
s = ''
for i in range(K):
  s += 'ACL'
print(s)
Problem p02677 (python)

Fixed submission:
# import sys
import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

# mod = int(1e9+7)
mod = 998244353
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def main():
    a,b,h,m = readInt()
    v1 = 30
    v2 = 6
    r1 = h * v1 + (m / 60) * v1
    r2 = m * v2
    r = abs(r1-r2)
    if r>180:
        r = 360 - r
    ans = math.sqrt(a * a + b * b - 2 * a * b * math.cos(math.radians(r)))
    print(ans)
    return

if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
# import sys
import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

# mod = int(1e9+7)
mod = 998244353
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def main():
    a,b,h,m = readInt()
    # 時針、分針の進んだ角度とその差を求める
    r1 = h * 30 + (m / 60) * v1
    r2 = m * 6
    r = abs(r1-r2)
    if r>180:
        r = 360 - r
    # 余弦定理から辺の長さを計算する
    ans = math.sqrt(a * a + b * b - 2 * a * b * math.cos(math.radians(r)))
    print(ans)
    return

if __name__=='__main__':
    main()