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

Fixed submission:
import sys
input=sys.stdin.readline
from string import ascii_lowercase

class BIT(): #1-indexed
    def __init__(self,n): #n: 要素数
        self.size=n
        self.bit=[0]*(n+1)
    def add(self,i,x): #i番目(1-indexed)にxを加算
        while i<=self.size:
            self.bit[i]+=x
            i+=i&-i
    def sum_1_to_i(self,i): #1番目からi番目(含む)までの総和(1-indexed)
        s=0
        while i>0:
            s+=self.bit[i]
            i-=i&-i
        return s
    def sum_i_to_j(self,i,j): #i番目からj番目(含む)までの総和(1-indexed)
        return self.sum_1_to_i(j)-self.sum_1_to_i(i-1)
    def reset(self): #初期化
        self.bit=[0]*(self.size+1)

def main():
    A=ascii_lowercase
    D=dict()
    for i,a in enumerate(A):
        D[a]=i
    n=int(input())
    S=list(input().strip())
    L=[BIT(n) for _ in range(26)]
    for i,s in enumerate(S):
        L[D[s]].add(i+1,1)
    q=int(input())
    for _ in range(q):
        k,a,b=input().split()
        if k=='1':
            i=int(a)-1
            s=S[i]
            L[D[b]].add(i+1,1)
            L[D[s]].add(i+1,-1)
            S[i]=b
        else:
            l=int(a); r=int(b)
            ans=0
            for i in range(26):
                ans+=L[i].sum_i_to_j(l,r)>0
            print(ans)
    
if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
from string import ascii_lowercase

class BIT(): #1-indexed
    def __init__(self,n): #n: 要素数
        self.size=n
        self.bit=[0]*(n+1)
    def add(self,i,x): #i番目(1-indexed)にxを加算
        while i<=self.size:
            self.bit[i]+=x
            i+=i&-i
    def sum_1_to_i(self,i): #1番目からi番目(含む)までの総和(1-indexed)
        s=0
        while i>0:
            s+=self.bit[i]
            i-=i&-i
        return s
    def sum_i_to_j(self,i,j): #i番目からj番目(含む)までの総和(1-indexed)
        return self.sum_1_to_i(j)-self.sum_1_to_i(i-1)
    def reset(self): #初期化
        self.bit=[0]*(self.size+1)

def main():
    A=ascii_lowercase
    D=dict()
    for i,a in enumerate(A):
        D[a]=i
    n=int(input())
    S=list(input())
    L=[BIT(n) for _ in range(26)]
    for i,s in enumerate(S):
        k=D[s]
        L[k].add(i+1,1)
    q=int(input())
    for _ in range(q):
        k,a,b=input().split()
        if k=='1':
            i=int(a)-1
            s=S[i]
            l1=D[s]
            l2=D[b]
            L[l2].add(i+1,1)
            L[l1].add(i+1,-1)
        else:
            l=int(a); r=int(b)
            ans=0
            for i in range(26):
                ans+=L[i].sum_i_to_j(l,r)>0
            print(ans)
    
if __name__=='__main__':
    main()
Problem p03013 (python)

Fixed submission:
mod=10**9+7
n,m=map(int,input().split())
A=[int(input()) for _ in range(m)]
A=list(set(A))
A.sort()
DP=[0]*(n+1)
DP[0]=1
if A:
    j=0
    if A[0]!=1:
        DP[1]=1
    else:
        if j<len(A)-1:
            j+=1
    for i in range(2,n+1):
        if i==A[j]:
            if j<len(A)-1:
                j+=1
        else:
            DP[i]=DP[i-1]+DP[i-2]
            DP[i]%=mod
    print(DP[-1])
else:
    DP[1]=1
    for i in range(2,n+1):
        DP[i]=DP[i-1]+DP[i-2]
        DP[i]%=mod
    print(DP[-1])

Buggy submission (verdict: Runtime Error):
mod=10**9+7
n,m=map(int,input().split())
A=[int(input()) for _ in range(m)]
A=list(set(A))
A.sort()
DP=[0]*(n+1)
DP[0]=1
if A:
    j=0
    if A[0]!=1:
        DP[1]=1
    else:
        j+=1
    for i in range(2,n+1):
        if i==A[j]:
            if j<len(A)-1:
                j+=1
        else:
            DP[i]=DP[i-1]+DP[i-2]
            DP[i]%=mod
    print(DP[-1])
else:
    DP[1]=1
    for i in range(2,n+1):
        DP[i]=DP[i-1]+DP[i-2]
        DP[i]%=mod
    print(DP[-1])
Problem p03307 (python)

Fixed submission:
n=int(input())
if n%2:
  ans=2*n
else:
  ans=n
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))
print(max(A)-min(A))
Problem p03631 (python)

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

Buggy submission (verdict: Runtime Error):
n=int(input())
t=list(map(int,[input() for i in range(n)]))

def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
def lcm(x,y):
    return x*y//gcd(x,y)

if n==1:
    print(t[0])
else:
    ans=lcm(t[0],t[1])
    for i in range(n-1):
        ans=lcm(ans,lcm(t[i],t[i+1]))
    print(ans)
Problem p03634 (python)

Fixed submission:
import heapq
import itertools
n=int(input())
edges=[[] for _ in range(n)]
for _ in range(n-1):
    a,b,c=map(int, input().split())
    a,b=a-1,b-1
    edges[a].append((b,c))
    edges[b].append((a,c))

def dijkstra(x,route):
    d=[float('inf')]*n
    d[x]=0
    visited={x}
    hq=[(0,x)]
    while hq:
        u=heapq.heappop(hq)[1]
        visited.add(u)
        for node,cost in route[u]:
            if (node not in visited) and d[node]>d[u]+cost:
                d[node]=d[u]+cost
                heapq.heappush(hq,(d[node],node))
    return d
q,k=map(int,input().split())
k-=1
dist=dijkstra(k,edges)
for _ in range(q):
    start,goal=map(int,input().split())
    print(dist[start-1]+dist[goal-1])

Buggy submission (verdict: Runtime Error):
n=int(input())
TREE=[[] for _ in range(n)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    a-=1
    b-=1
    TREE[a].append([b,c])
    TREE[b].append([a,c])
q,k=map(int,input().split())
k-=1
cost=[0]*n
visited=[False]*n

def DFS(s,d):
    cost[s]=d
    visited[s]=True
    for i in TREE[s]:
        if not visited[i[0]]:
            DFS(i[0],d+i[1])
    return

DFS(k,0)
for _ in range(q):
    start,goal=map(int,input().split())
    print(cost[start-1]+cost[goal-1])

Buggy submission (verdict: Runtime Error):
n=int(input())
TREE=[[] for _ in range(n)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    a-=1
    b-=1
    TREE[a].append([b,c])
    TREE[b].append([a,c])
q,k=map(int,input().split())
k-=1
depth=[0]*n
visited=[False for _ in range(n)]

def DFS(s,d):
    depth[s]=d
    visited[s]=True
    for i in TREE[s]:
        if not visited[i[0]]:
            DFS(i[0],d+i[1])
    return

DFS(k,0)
for _ in range(q):
    start,goal=map(int,input().split())
    print(depth[start-1]+depth[goal-1])

Buggy submission (verdict: Runtime Error):
n=int(input())
TREE=[[] for _ in range(n)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    a-=1
    b-=1
    TREE[a].append([b,c])
    TREE[b].append([a,c])
q,k=map(int,input().split())
k-=1
depth=[0]*n
visited=[False for i in range(n)]

def DFS(s,d):
    depth[s]=d
    visited[s]=True
    for i in TREE[s]:
        if not visited[i[0]]:
            DFS(i[0],d+i[1])
    return

DFS(k,0)
for i in range(q):
    start,goal=map(int, input().split())
    print(depth[start-1]+depth[goal-1])
Problem p03723 (python)

Fixed submission:
a,b,c=map(int,input().split())
if a==b==c:
    print(-int(not a%2))
else:
    cnt=0
    while not (a%2 or b%2 or c%2):
        cnt+=1
        a,b,c=(b+c)//2,(c+a)//2,(a+b)//2
    print(cnt)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
from collections import deque
from math import ceil

def dist(h,w,x,y):
    return min(x-1,h-x,y-1,w-y)

h,w,k=map(int,input().split())
MAP=[]
A=['#']*(w+2)
MAP.append(A)
for i in range(h):
    s='#'+input().strip()+'#'
    for j,t in enumerate(s):
        if t=='S':
            sx,sy=i+1,j
    MAP.append(list(s))
MAP.append(A)
delta=[[1,0],[0,1],[-1,0],[0,-1]]
P=[]
Visited=[[False]*(w+2) for _ in range(h+2)]
Visited[sx][sy]=True
q=deque()
q.append((sx,sy,k))
while q:
    x,y,t=q.popleft()
    if t<0:
        break
    P.append([x,y])
    t-=1
    for dx,dy in delta:
        if MAP[y+dy][x+dx]=='.' and not Visited[x+dx][y+dy]:
            q.append((y+dy,x+dx,t))
            Visited[x+dx][y+dy]=True
ans=float('inf')
for x,y in P:
    ans=min(ans,1+ceil(dist(h,w,x,y)/k))
print(ans)
Problem p02793 (python)

Fixed submission:
import sys

n = int(input())
a = [int(x) for x in input().split()]
am = max(a)
mod = 10**9+7
if n==1:
    print(1)
    sys.exit()
li = [0]*(am+1)
lcm = 1
for k in range(n):
    z = a[k]
    for i in range(2,int(z**0.5)+1):
        x = 0
        while z%i==0:
            x += 1
            z//=i
        li[i] = max(li[i],x)
    if z!=1 and li[z]==0:
        li[z] = 1

for i in range(2,am+1):
    if li[i]>0:
        lcm = lcm * i**li[i] % mod

ans = 0
for i in range(n):
    m = pow(a[i],mod-2,mod)
    ans = (ans+(lcm*m)%mod)%mod
print(ans%mod)

Buggy submission (verdict: Runtime Error):
import sys

n = int(input())
a = [int(x) for x in input().split()]
if n==1:
    print(1)
    sys.exit()
li = [0]*(10**3+1)
lcm = 1
for k in range(n):
    z = a[k]
    for i in range(2,int(z**0.5)+1):
        x = 0
        while z%i==0:
            x += 1
            z//=i
        if li[i]<x:
            if li[i]==0:
                li[i] = x
            else:
                lcm //= ((-1)*li[i])
                li[i] = x
    if z!=1 and li[z]==0:
        li[z] = -z
        lcm *= z

for i in range(2,10**3+1):
    if li[i]>0:
        lcm *= i*li[i]

mod = 10**9+7
ans = 0
for i in range(n):
    ans = (ans + lcm//a[i])%mod
print(ans)
Problem p02623 (python)

Fixed submission:
from collections import deque

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = deque(a)
b = deque(b)
t = 0
book = deque()
while len(b):
    if b[0]+t <= k:
        t += b[0]
        book.append(b.popleft())
    else:
        break
nn = len(book)
# 逆じゅん
new_book = deque()
for i in range(nn):
    new_book.append(book.pop())
book = new_book
# aも詰め込めるだけ
while len(a):
    if a[0]+t <= k:
        t += a[0]
        book.append(a.popleft())
    else:
        break
ans = len(book)
for i in range(nn):
    t -= book.popleft()
    while len(a) and t+a[0]<=k:
        ta = a.popleft()
        t += ta
        book.append(ta)
    ans = max(ans, len(book))

print(ans)

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

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = deque(a)
b = deque(b)
t = 0
ans = 0
while True:
    if len(a) == 0 and len(b) == 0:
        break
    elif len(a) == 0:
        if t+b[0] > k:
            break
        ans += 1
        t += b.popleft()
    elif len(b) == 0:
        if t+a[0] > k:
            break
        ans += 1
        t += a.popleft()
    else:
        if a[0] < b[0]:
            if t+a[0] > k:
                break
            ans += 1
            t += a.popleft()
        elif a[0] > b[0]:
            if t+b[0] > k:
                break
            ans += 1
            t += b.popleft()
        else:
            if len(a) == 1:
                if t+b[0] > k:
                    break
                ans += 1
                t += b.popleft()
            elif len(a) == 1:
                if t+a[0] > k:
                    break
                ans += 1
                t += a.popleft()
            else:
                if a[1] < b[1]:
                    if t+a[0] > k:
                        break
                    ans += 1
                    t += a.popleft()
                else:
                    if t+b[0] > k:
                        break
                    ans += 1
                    t += b.popleft()
print(ans)
Problem p02762 (python)

Fixed submission:
# 小さい方の木を大きい方にくっつける O(logN)
# 経路縮約(メモ化) ならしO(logN)
# 両方やると、ならしO(α(N)) α: カルマン関数

# 実装
# 子: 親のID, 根: -サイズ (非負: 子, 負: 根)
# atcoder ABC 158 解説に詳細
class UnionFind():

    def __init__(self, n=0):
        self.d = [-1 for _ in range(N)] # 経路縮約のためのメモ
    
    def find(self, x): # xが所属するグループの親を返す
        if self.d[x]<0:
            return x
        res = self.find(self.d[x])
        self.d[x] = res # 経路縮約の箇所
        return res
    
    def unite(self, x, y): # x, yが所属するグループを結合する, 結合に成功したらTrue, すでに結合していたらFalse
        # まずx, yをそれぞれの親にする
        x = self.find(x)
        y = self.find(y) 
        if x==y:
            return False
        # xの方が大きい木になるようにする (サイズは負であることに注意)
        if self.d[x] > self.d[y]: 
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        return True
    
    def same(self, x, y): # 同じ集合に属しているかどうかを判定する
        return self.find(x) == self.find(y)
    
    def size(self, x): # xが所属しているグループのサイズを返す
        return -self.d[self.find(x)]

N, M, K=map(int, input().split())
AB=[list(map(int, input().split())) for _ in range(M)]
CD=[list(map(int, input().split())) for _ in range(K)]

uf = UnionFind(N)
deg = [0 for _ in range(N)] # 友達関係にある人の個数(グラフにおける各頂点の次数)を保持
to = [[] for _ in range(N)] # ブロック関係にある人に枝を張る

# 友達関係
for i in range(M):
    a, b = AB[i]
    a-=1
    b-=1
    deg[a]+=1
    deg[b]+=1
    uf.unite(a, b)
# ブロック関係
for i in range(K):
    c, d = CD[i]
    c-=1
    d-=1
    to[c].append(d)
    to[d].append(c)
# 答え
ans=[0 for _ in range(N)]
for i in range(N):
    # 各人(頂点)の所属するグループのサイズから、自分自身と、直接の友達関係を引く
    ans[i]=uf.size(i)-1-deg[i]
    # 各人のブロック関係にある人が同じグループに所属している場合は、答えを-する
    for u in to[i]:
        if uf.same(i, u):
            ans[i]-=1
print(*ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(200000+10)

N, M, K=map(int, input().split())
AB=[list(map(int, input().split())) for _ in range(M)]
CD=[list(map(int, input().split())) for _ in range(K)]
if M==0:
    print("haha")
else:
    AB.sort(key=lambda x:(x[0], x[1]))
    if K!=0:
        CD.sort(key=lambda x:(x[0], x[1]))

    fr=[[] for _ in range(N)] # friends relation
    br=[[] for _ in range(N)] # block relation

    AB.sort(key=lambda x:(x[0], x[1]))
    CD.sort(key=lambda x:(x[0], x[1]))
    for A, B in AB:
        A-=1
        B-=1
        fr[A].append(B)
        fr[B].append(A)
    for C, D in CD:
        C-=1
        D-=1
        br[C].append(D)
        br[D].append(C)

    counts=[0 for _ in range(N)]
    visited=[False for _ in range(N)]

    def dfs(u, p=-1, nodes=[]):
        visited[u]=True
        for n in nodes:
            if n not in fr[u] and n not in br[u]:
                counts[u]+=1
                counts[n]+=1
        nodes.append(u)
        for v in fr[u]:
            if v==p:
                continue
            if visited[v]:
                continue
            dfs(v, p=u, nodes=nodes)

    for i in range(N):
        if not visited[i]:
            dfs(i, p=-1, nodes=[])

print(*counts)
Problem p02835 (python)

Fixed submission:
A=list(map(int, input().split()))
if sum(A)>=22:
    print('bust')
else:
    print('win')

Buggy submission (verdict: Runtime Error):
H, W=map(int, input().split())
maxK=80*80+1
A=[list(map(int, input().split())) for _ in range(H)]
B=[list(map(int, input().split())) for _ in range(H)]
C=[[abs(A[i][j]-B[i][j]) for j in range(W)] for i in range(H)]
dp=[[[0 for _ in range(maxK+1)] for _ in range(W+1)] for _ in range(H+1)]
dp[1][1][C[0][0]]=1
for i in range(1, H+1):
    for j in range(1, W+1):
        for k in range(maxK):
            if dp[i-1][j][k]==1 or dp[i][j-1][k]==1:
                k_candidate1, k_candidate2=abs(k-C[i-1][j-1]), abs(k+C[i-1][j-1])
                if k_candidate1<maxK:
                    dp[i][j][k_candidate1]=1
                if k_candidate2<maxK:
                    dp[i][j][k_candidate2]=1
for k in range(maxK):
    if dp[H][W][k]==1:
        print(k)
        break
Problem p02863 (python)

Fixed submission:
N, T=map(int, input().split())
lst=[list(map(int, input().split())) for _ in range(N)]
MAXN, MAXT=3001, 3001
dp1=[[0 for _ in range(MAXT)] for _ in range(MAXN+1)]
dp2=[[0 for _ in range(MAXT)] for _ in range(MAXN+1)]
for i in range(1, N+1):
  A, B=lst[i-1]
  for j in range(1, MAXT):
    dp1[i][j]=max(dp1[i-1][j], dp1[i-1][j-A]+B) if j>=A else dp1[i-1][j]
for i in range(N, 0, -1):
  A, B=lst[i-1]
  for j in range(1, MAXT):
    dp2[i][j]=max(dp2[i+1][j], dp2[i+1][j-A]+B) if j>=A else dp2[i+1][j]
ans=dp1[N-1][T-1]+lst[-1][1]
for i in range(1, N):
  A, B=lst[i-1]
  for j in range(T):
    ans=max(ans, dp1[i-1][j]+dp2[i+1][T-1-j]+B)
print(ans)

Buggy submission (verdict: Runtime Error):
N, T=map(int, input().split())
lst=[list(map(int, input().split())) for _ in range(N)]
MAXN, MAXT=3001, 3001
dp1=[[0 for _ in range(MAXT)] for _ in range(MAXN)]
dp2=[[0 for _ in range(MAXT)] for _ in range(MAXN)]
for i in range(1, N+1):
  A, B=lst[i-1]
  for j in range(1, MAXT):
    dp1[i][j]=max(dp1[i-1][j], dp1[i-1][j-A]+B) if j>=A else dp1[i-1][j]
for i in range(N, 0, -1):
  A, B=lst[i-1]
  for j in range(1, MAXT):
    dp2[i][j]=max(dp2[i+1][j], dp2[i+1][j-A]+B) if j>=A else dp2[i+1][j]
ans=dp1[N-1][T-1]+lst[-1][1]
for i in range(1, N):
  A, B=lst[i-1]
  for j in range(T):
    ans=max(ans, dp1[i-1][j]+dp2[i+1][T-1-j]+B)
print(ans)
Problem p02891 (python)

Fixed submission:
S=input()
K=int(input())
SS=S+S
SSS=SS+S
count_single=count_double=count_triple=0
flag=True
for i in range(1, len(S)):
  if not flag:
    flag=True
    continue
  if S[i-1]==S[i]:
    count_single+=1
    flag=False
flag=True
for i in range(1, len(SS)):
  if not flag:
    flag=True
    continue
  if SS[i-1]==SS[i]:
    count_double+=1
    flag=False
flag=True
for i in range(1, len(SSS)):
  if not flag:
    flag=True
    continue
  if SSS[i-1]==SSS[i]:
    count_triple+=1
    flag=False
if K==1:
  print(count_single)
elif K==2:
  print(count_double)
else:
  diff21=count_double-count_single
  diff32=count_triple-count_double
  print(count_single+(K//2)*diff21+((K-1)//2)*diff32)

Buggy submission (verdict: Runtime Error):
S=input()
K=int(input())
count=0
SS=S*K
flag=True
for i in range(1, len(SS)):
  if not flag:
    flag=True
    continue
  if SS[i-1]==SS[i]:
    count+=1
    flag=False
print(count)

Buggy submission (verdict: Runtime Error):
S=input()
K=int(input())
count=0
SS=S*K
flag=True
for i in range(1, len(SS)):
  if not flag:
    flag=True
    continue
  else:
    count+=1
    flag=False
print(count)

Buggy submission (verdict: Runtime Error):
S=input()
K=int(input())
count=0
SS=S*K
flag=True
print(SS)
for i in range(1, len(SS)):
  if not flag:
    flag=True
    continue
Problem p02912 (python)

Fixed submission:
import heapq
N, M=map(int, input().split())
A=list(map(int, input().split()))
A=list(map(lambda x: -x, A))
heapq.heapify(A)
for i in range(M):
  heapq.heappush(A, (heapq.heappop(A)+1)//2)
print(-sum(A))

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
N, M=map(int, input().split())
A=list(map(int, input().split()))
A.sort()
for i in range(M):
  tmp=A[-1]//2
  A.pop(N-1)
  A.insert(bisect_left(A, tmp), tmp)
  if A[-1]=0:
    break
print(sum(A))

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
N, M=map(int, input().split())
A=list(map(int, input().split()))
A.sort()
while M>0:
  while M>0 and A[-1]>A[-2]:
    A[-1]=A[-1]//2
    M-=1
  idx=bisect_left(A, A[-1])
  A.insert(idx, A[-1])
  A.pop()
print(sum(A))
Problem p02925 (python)

Fixed submission:
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
    for j in range(n-1):
        a[i][j] -= 1

MAXN = 1005
MAXV = MAXN*(MAXN-1)//2

to = [[] for _ in range(MAXV)]
# 頂点番号
id = [[0 for _ in range(MAXN)] for _ in range(MAXN)]
def toID(i, j):
    if i > j:
        i, j = j, i
    return id[i][j]

# 頂点番号のラベリング
V = 0
for i in range(n):
    for j in range(n):
        if i < j:
            id[i][j] += V
            V += 1

# aを、頂点番号に書き換え、試合の依存関係を表す辺を張る(辺の向きは逆にする)
for i in range(n):
    for j in range(n-1):
        a[i][j] = toID(i, a[i][j])
    for j in range(n-2):
        to[a[i][j+1]].append(a[i][j])

# dfsする
visited = [False for _ in range(MAXV)]
calculated = [False for _ in range(MAXV)] # loop 検出用
dp = [0 for _ in range(MAXV)] # max length of path from v
def dfs(v):
    if visited[v]:
        if not calculated[v]:
            return -1
        return dp[v]
    visited[v] = True
    dp[v] = 1
    for u in to[v]:
        res = dfs(u)
        if res == -1:
            return -1
        dp[v] = max(dp[v], res+1)
    calculated[v] = True
    return dp[v]

ans = 0
ok = True
for i in range(V):
    res = dfs(i)
    if res == -1:
        ok = False
        break
    ans = max(ans, res)
if ok:
    print(ans)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
    for j in range(n-1):
        a[i][j] -= 1

MAXN = 1005
MAXV = MAXN*(MAXN-1)//2

to = [[] for _ in range(MAXV)]
# 頂点番号
id = [[0 for _ in range(MAXN)] for _ in range(MAXN)]
def toID(i, j):
    if i > j:
        i, j = j, i
    return id[i][j]

# 頂点番号のラベリング
V = 0
for i in range(n):
    for j in range(n):
        if i < j:
            id[i][j] += V
            V += 1

# aを、頂点番号に書き換え、試合の依存関係を表す辺を張る(辺の向きは逆にする)
for i in range(n):
    for j in range(n-1):
        a[i][j] = toID(i, a[i][j])
    for j in range(n-2):
        to[a[i][j+1]].append(a[i][j])

# dfsする
visited = [False for _ in range(MAXV)]
calculated = [False for _ in range(MAXV)] # loop 検出用
dp = [0 for _ in range(MAXV)] # max length of path from v
def dfs(v):
    if visited[v]:
        if not calculated[v]:
            return -1
        return dp[v]
    visited[v] = True
    dp[v] = 1
    for u in to[v]:
        res = dfs(u)
        if res == -1:
            return -1
        dp[v] = max(dp[v], res+1)
    calculated[v] = True
    return dp[v]

ans = 0
ok = True
for i in range(V):
    res = dfs(i)
    if res == -1:
        ok = False
        break
    ans = max(ans, res)
if ok:
    print(ans)
else:
    print(-1)
Problem p02933 (python)

Fixed submission:
a=int(input())
s=input()
if a >= 3200:
  print(s)
else:
  print("red")

Buggy submission (verdict: Runtime Error):
a=input()
s=input()
if a >= 3200:
  print(s)
else:
  print("red")

Buggy submission (verdict: Runtime Error):
a=input()
s=input()
print(s if a>=3200 else "red")
Problem p02948 (python)

Fixed submission:
import heapq
from collections import deque

N, M=map(int, input().split())
AB=[list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x:(x[0], x[1]))
for i in range(N):
  AB[i][1]=-AB[i][1]
d=deque(AB)
ans=0
h=[]
for i in range(M+1):
  if not d and not h:
    break
  while d and d[0][0]<=i:
    heapq.heappush(h, d.popleft()[1])
  if h:
    ans-=heapq.heappop(h)
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
n, m = map(int, input().split())
work = [list(map(int, input().split())) for i in range(n)]
dic = {}
for w in work:
    a, b = w[0], w[1]
    if a not in dic.keys():
        dic[a]=[b]
    else:
        index=bisect.bisect_right(dic[a], b)
        dic[a].insert(index, b)
dic_=sorted(dic.items(), key=lambda x:x[0])
res = 0
while m > 0:
    print(dic_)
    flag=True
    for i in range(len(dic_)):
        if dic_[i][0] >= m:
            flag=False
            if i==0:
                break
            res+=dic_[i][1].pop(-1)
    if flag:
        dic_[-1][1].pop(-1)
    m-=1

Buggy submission (verdict: Runtime Error):
from itertools import bisect
n, m = map(int, input().split())
work = [map(int, input().split()) for i in range(n)]
dic = {}
for w in work:
  a, b = w[0], w[1]
  if a not in dic.keys():
    dic[a]=[b]
  else:
    index=bisect.bisect_right(dic[a], b)
    dic[a].insert(index, b)
res = 0
while m > 0:
  index=bisect.bisect_left(dic.keys(), m)
  res+=dic[index].pos(len(dic[index])-1)
print(res)
Problem p03013 (python)

Fixed submission:
N, M=map(int, input().split())
A=[int(input()) for _ in range(M)]
mod=10**9+7
step=[1]*(N+1)
for a in A:
  step[a]=0
for i in range(2, N+1):
  step[i]=(step[i-1]+step[i-2])%mod*step[i]
print(step[-1])

Buggy submission (verdict: Runtime Error):
N, M=map(int, input().split())
A=[int(input()) for _ in range(M)]
mod=10**9+7
step=[0]*(N+1)
step[1]=0 if 1 in A else 0
step[2]=0 if 2 in A else 1 if 1 in A else 0
for i in range(3, N+1):
  if i in A:
    continue
  step[i]=(step[i-1]+step[i-2])%mod
print(step[-1])
Problem p02711 (python)

Fixed submission:
N = input()

if "7" in N:
    print('Yes')
else:
    print('No')

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

DP = [0,0,0]
m = N//2*2
if N%2 == 0:
    for i in range(0,m,2):
        DP[0] += A[i]
        DP[1] += A[i+1]
        DP[1] = max(DP[0],DP[1])

    print(DP[1])

else:
    for i in range(0,m,2):
        DP[0] += A[i]
        DP[1] += A[i+1]
        DP[2] += A[i+2]

        DP[1] = max(DP[0],DP[1])
        DP[2] = max(DP[1],DP[2])

    print(DP[2])