Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
"""
D
"""
import sys
input=sys.stdin.readline

def match_count(lst_1,lst_2):
    l_1,l_2=len(lst_1),len(lst_2)
    kkk=0
    zzz=0
    ttt=0
    while kkk<l_1:
        while zzz<l_2:
            if lst_1[kkk]>lst_2[zzz]:
                zzz+=1
                continue
            else:
                if lst_1[kkk]==lst_2[zzz]:
                    zzz+=1
                    ttt+=1
                break
        else:
            break
        kkk+=1
    return ttt

N,M,K=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(M)]
CD=[list(map(int,input().split())) for i in range(K)]
data1=[[] for i in range(N+1)]
data2=[[] for i in range(N+1)]
for A,B in AB:
    data1[A].append(B)
    data1[B].append(A)
for C,D in CD:
    data2[C].append(D)
    data2[D].append(C)
    
for i in range(N+1):
    data1[i].sort()
    data2[i].sort()
    
    
    
ans=[0]*(N+1)
flag=[0]*(N+1)
for i in range(1,N+1):
    if flag[i]==1:
        continue
    que=[i]
    H=[i]
    flag[i]=1
    while que:
        u=que.pop()
        for v in data1[u]:
            if flag[v]==0:
                flag[v]=1
                que.append(v)
                H.append(v)
                
    H.sort()
    for u in H:
        ans[u]=len(H)-len(data1[u])-match_count(H,data2[u])-1

print(*ans[1:])



Fixed submission:
#頂点xの親を求める
def find_parent(x):
    y=parent[x]
    if y<0:
        return x
    parent[x]=find_parent(y)
    return parent[x]

#頂点aと頂点bのグループをつなげる
def connect(a,b):
    c=find_parent(a)
    d=find_parent(b)
    if c==d:
        return
    if parent[c]<parent[d]:
        parent[c]+=parent[d]
        parent[d]=c
    else:
        parent[d]+=parent[c]
        parent[c]=d
    return

#N個の頂点、M本の道で、i個目の道がAi-Biとなるような
#グラフについてグループ化する
N,M,K=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(M)]
CD=[list(map(int,input().split())) for i in range(K)]
parent=[-1]*(N+1)
for A,B in AB:
    connect(A,B)
ans=[0]*(N+1)
for i in range(1,N+1):
    ans[i]=-parent[find_parent(i)]-1
for A,B in AB:
    ans[A]-=1
    ans[B]-=1
for C,D in CD:
    if find_parent(C)==find_parent(D):
        ans[C]-=1
        ans[D]-=1
print(*ans[1:])
Buggy python submission (verdict: Time Limit Exceeded):
"""
F
"""
import sys
input=sys.stdin.readline
mod=10**9+7
MAX=2*10**6+100

g1=[1,1]
for i in range(2,MAX+1):
    num_1=g1[-1]*i%mod
    g1.append(num_1)
    
def cmb(n,r):
    return (g1[n]*pow(g1[r],mod-2,mod)%mod)*pow(g1[n-r],mod-2,mod)%mod

r1,c1,r2,c2=map(int,input().split())
if r2-r1<c2-c1:
    c1,r1=r1,c1
    c2,r2=r2,c2

S=cmb(r1+c1,r1)
ans=S
table1=[]
table2=[]
num1=c1+1
num2=r1+1
for i in range(c2-c1):
    S=((2*S+cmb(num1+i+r1-1,r1-1))%mod+cmb(num2+i+c1-1,c1-1))%mod
    ans=(ans+S)%mod  
    
num1=r1
num2=r1+c2-c1+1
for i in range(r2-(r1+c2-c1)):
    S=((2*S-cmb(num1+i+c2,c2))%mod+cmb(num2+i+c1-1,c1-1))%mod
    ans=(ans+S)%mod  
    
num1=c1
num2=r2-(c2-c1)
for i in range(c2-c1):
    S=((2*S-cmb(num1+i+r2,r2))%mod-cmb(num2+i+c2,c2))%mod
    ans=(ans+S)%mod  

print(ans)

Fixed submission:
import sys
input=sys.stdin.readline

mod=10**9+7
MAX=2*10**6+100

g1=[1,1]
g2=[1,1]
for i in range(2,MAX+1):
    num_1=g1[-1]*i%mod
    g1.append(num_1)
    g2.append(pow(num_1,mod-2,mod))
    
def cmb(n,r):
    return g1[n]*g2[r]*g2[n-r]%mod

def g(x,y):
    return cmb(x+y+2,y+1)-1

r1,c1,r2,c2=map(int,input().split())

num=(g(r2,c2)-g(r2,c1-1)-g(r1-1,c2)+g(r1-1,c1-1))%mod
print(num)

Buggy python submission (verdict: Time Limit Exceeded):
"""
F
"""
import sys
input=sys.stdin.readline
mod=10**9+7
MAX=2*10**6+100

g1=[1,1]
g2=[1,1]
for i in range(2,MAX+1):
    num_1=g1[-1]*i%mod
    g1.append(num_1)
    g2.append(pow(num_1,mod-2,mod))
    
def cmb(n,r):
    return g1[n]*g2[r]*g2[n-r]%mod

r1,c1,r2,c2=map(int,input().split())
if r2-r1<c2-c1:
    c1,r1=r1,c1
    c2,r2=r2,c2

S=cmb(r1+c1,r1)
ans=S
table1=[]
table2=[]
num1=c1+1
num2=r1+1
for i in range(c2-c1):
    S=(2*S+cmb(num1+i+r1-1,r1-1)+cmb(num2+i+c1-1,c1-1))%mod
    ans=(ans+S)%mod  
    
num1=r1
num2=r1+c2-c1+1
for i in range(r2-(r1+c2-c1)):
    S=(2*S-cmb(num1+i+c2,c2)+cmb(num2+i+c1-1,c1-1))%mod
    ans=(ans+S)%mod  
    
num1=c1
num2=r2-(c2-c1)
for i in range(c2-c1):
    S=(2*S-cmb(num1+i+r2,r2)-cmb(num2+i+c2,c2))%mod
    ans=(ans+S)%mod  

print(ans)

Fixed submission:
import sys
input=sys.stdin.readline

mod=10**9+7
MAX=2*10**6+100

g1=[1,1]
g2=[1,1]
for i in range(2,MAX+1):
    num_1=g1[-1]*i%mod
    g1.append(num_1)
    g2.append(pow(num_1,mod-2,mod))
    
def cmb(n,r):
    return g1[n]*g2[r]*g2[n-r]%mod

def g(x,y):
    return cmb(x+y+2,y+1)-1

r1,c1,r2,c2=map(int,input().split())

num=(g(r2,c2)-g(r2,c1-1)-g(r1-1,c2)+g(r1-1,c1-1))%mod
print(num)
Buggy python submission (verdict: Runtime Error):
H,N=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]

inf=float("inf")
dp=[inf]*(H+1)
dp[0]=0
ans=inf
for i in range(N):
    A,B=AB[i]
    for j in range(H-A+1):
        dp[j+A]=min(dp[j+A],dp[j]+B)
    for j in range(H-A+1,H):
        ans=min(ans,dp[j]+B)
ans=min(ans,dp[H])

print(ans)

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

inf=float("inf")
dp=[inf]*(H+1)
dp[0]=0
ans=inf
for i in range(N):
    A,B=AB[i]
    for j in range(max(0,H-A+1)):
        dp[j+A]=min(dp[j+A],dp[j]+B)
    for j in range(max(0,H-A+1),H):
        ans=min(ans,dp[j]+B)
ans=min(ans,dp[H])

print(ans)
Buggy python submission (verdict: Runtime Error):
#E

def prime_factorize(n):
    a=[]
    while n%2==0:
        a.append(2)
        n//=2
    f=3
    while f*f<=n:
        if n%f==0:
            a.append(f)
            n//=f
        else:
            f+=2
    if n!=1:
        a.append(n)
    return a

N=int(input())
A=list(map(int,input().split()))
mod=10**9+7

Ainv=[]
for i in range(N):
    Ainv.append(pow(A[i],mod-2,mod))
SSS=0
for u in Ainv:
    SSS=(SSS+u)%mod
    
data=[0]*(max(A)+1)
for i in range(N):
    h=prime_factorize(A[i])
    cnt=1
    for i in range(1,len(h)):
        if h[i]==h[i-1]:
            cnt+=1
        else:
            data[h[i-1]]=max(data[h[i-1]],cnt)
            cnt=1
    data[h[-1]]=max(data[h[-1]],cnt)
ans=1
for i in range(1,len(data)):
    if data[i]==0:
        continue
    else:
        ans=ans*pow(i,data[i],mod)%mod
print(ans*SSS%mod)

Fixed submission:
#E
mod=10**9+7
def prime_factorize(n):
    a=[]
    while n%2==0:
        a.append(2)
        n//=2
    f=3
    while f*f<=n:
        if n%f==0:
            a.append(f)
            n//=f
        else:
            f+=2
    if n!=1:
        a.append(n)
    return a

N=int(input())
A=list(map(int,input().split()))
Ainv=[]
for i in range(N):
    Ainv.append(pow(A[i],mod-2,mod))
SSS=0
for u in Ainv:
    SSS=(SSS+u)%mod
    
data=[0]*(max(A)+1)
for i in range(N):
    h=prime_factorize(A[i])
    cnt=1
    for i in range(1,len(h)):
        if h[i]==h[i-1]:
            cnt+=1
        else:
            data[h[i-1]]=max(data[h[i-1]],cnt)
            cnt=1
    if h:
        data[h[-1]]=max(data[h[-1]],cnt)
ans=1
for i in range(1,len(data)):
    if data[i]==0:
        continue
    else:
        ans=ans*pow(i,data[i],mod)%mod
print(ans*SSS%mod)
Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())
S=[list(input()) for i in range(H)]
inf=float("inf")
d=[[1,0],[0,1],[-1,0],[0,-1]]
ans=0
for sx in range(H):
    for sy in range(W):
        for gx in range(H):
            for gy in range(W):
                if S[sx][sy]==S[gx][gy]==".":
                    data=[[inf]*W for i in range(H)]
                    que=[[sx,sy]]
                    data[sx][sy]=0
                    count=1
                    while que:
                        h=[]
                        for x,y in que:
                            for dx,dy in d:
                                nx,ny=x+dx,y+dy
                                if 0<=nx<H and 0<=ny<W and S[nx][ny]=="." and data[nx][ny]==inf:
                                    h.append([nx,ny])
                                    data[nx][ny]=count
                        que=h
                        count+=1
                    ans=max(ans,data[gx][gy])
print(ans)

Fixed submission:
H,W=map(int,input().split())
S=[list(input()) for i in range(H)]
inf=float("inf")
d=[[1,0],[0,1],[-1,0],[0,-1]]
ans=0
for sx in range(H):
    for sy in range(W):
        if S[sx][sy]==".":
            data=[[inf]*W for i in range(H)]
            que=[[sx,sy]]
            data[sx][sy]=0
            count=1
            while que:
                h=[]
                for x,y in que:
                    for dx,dy in d:
                        nx,ny=x+dx,y+dy
                        if 0<=nx<H and 0<=ny<W and S[nx][ny]=="." and data[nx][ny]==inf:
                            h.append([nx,ny])
                            data[nx][ny]=count
                que=h
                count+=1
            for i in range(H):
                for j in range(W):
                    if data[i][j]!=inf:
                        ans=max(ans,data[i][j])
print(ans)
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
A=[list(map(int,input().split())) for i in range(h)]
B=[list(map(int,input().split())) for i in range(h)]
C=[[0]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        C[i][j]=abs(A[i][j]-B[i][j])
    
dp=[[0]*w for i in range(h)]
m=80
dp[0][0] = (1<<m+C[0][0]) | (1<<m-C[i][j])

for i in range(h):
    for j in range(w):
        if i>=1:
            dp[i][j] |= (dp[i-1][j]<<C[i][j]) | (dp[i-1][j]>>C[i][j])
        if j>=1:
            dp[i][j] |= (dp[i][j-1]<<C[i][j]) | (dp[i][j-1]>>C[i][j])
        
b=dp[h-1][w-1]
for i in range(m):
    if (b>>m+i)&1==1:
        ans=i
        break
for i in range(m):
    if (b>>m-i)&1==1:
        ans=min(ans,i)
        break

print(ans)

Fixed submission:
h,w=map(int,input().split())
A=[list(map(int,input().split())) for i in range(h)]
B=[list(map(int,input().split())) for i in range(h)]
C=[[0]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        C[i][j]=abs(A[i][j]-B[i][j])
        
dp=[[0]*w for i in range(h)]
m=80
dp[0][0] = (1<<m+C[0][0]) | (1<<m-C[0][0])

for i in range(h):
    for j in range(w):
        if i>=1:
            dp[i][j] |= (dp[i-1][j]<<m+C[i][j]) | (dp[i-1][j]<<m-C[i][j])
        if j>=1:
            dp[i][j] |= (dp[i][j-1]<<m+C[i][j]) | (dp[i][j-1]<<m-C[i][j])
            
b=list(bin(dp[h-1][w-1]))[::-1]
ans=float("inf")

for i in range(len(b)):
    if b[i]=="1":
        ans=min(ans,abs(m*(h+w-1)-i))

print(ans)
Buggy python submission (verdict: Runtime Error):
n,x,d=map(int,input().split())
inf=float("inf")
data=[]
for k in range(n+1):
    z=2*k-n
    w=(2*n-k-1)*k-n*(n-1)//2
    y=(k-1)*k-n*(n-1)//2
    num_1=z*x+d*w
    num_2=z*x+d*y
    if num_1<num_2:
        data.append([num_1%(2*d),num_1,num_2])
    else:
        data.append([num_1%(2*d),num_2,num_1])
d=abs(d)
data.sort()
ans=(data[0][2]-data[0][1])//(2*d)+1
m=data[0][1]
for i in range(1,n+1):
    if data[i][0]==data[i-1][0]:
        if data[i][1]>m:
            ans+=(data[i][2]-data[i][1])//(2*d)+1
        else:
            if data[i][2]>m:
                ans+=(data[i][2]-m)//(2*d)
        m=max(m,data[i][2])
    else:
        ans+=(data[i][2]-data[i][1])//(2*d)+1
        m=data[i][2]

print(ans)

Fixed submission:
import sys

n,x,d=map(int,input().split())
if d==0:
    if x==0:
        print(1)
    else:
        print(n+1)
    sys.exit()
    
lst=[]
for k in range(n+1):
    a=k*x%d
    l=k*x+d*k*(k-1)//2
    r=k*x+d*k*(2*n-k-1)//2
    lst.append([a,min(l,r),max(l,r)])
lst.sort()

data=[]
h=[[lst[0][1],lst[0][2]]]
for i in range(1,n+1):
    if lst[i][0]==lst[i-1][0]:
        h.append([lst[i][1],lst[i][2]])
    else:
        data.append(h)
        h=[[lst[i][1],lst[i][2]]]
data.append(h)
d=abs(d)

ans=0
for h in data:
    left,right=h[0]
    for i in range(1,len(h)):
        if h[i][0]<=right:
            right=max(right,h[i][1])
        else:
            ans+=(right-left)//d+1
            left,right=h[i]
    ans+=(right-left)//d+1

print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=1
data=[0,0,0]
for u in a:
    cnt=0
    for i in range(3):
        if u==data[i]:
            k=i
            cnt+=1
    ans=ans*cnt%mod
    data[k]+=1
print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=1
data=[0,0,0]
for u in a:
    cnt=0
    k=-1
    for i in range(3):
        if u==data[i]:
            k=i
            cnt+=1
    ans=ans*cnt%mod
    if k!=-1:
        data[k]+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
n,t=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort()
dp=[[-1]*t for i in range(n)]
for i in range(n):
    dp[i][0]=0
a,b=ab[0]
dp[0][a]=b
for i in range(1,n):
    a,b=ab[i]
    for j in range(min(a,t)):
        dp[i][j]=dp[i-1][j]
    for j in range(a,t):
        if dp[i-1][j-a]==-1:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-a]+b)
table=[0]*n
table[n-1]=ab[n-1][1]
for i in range(n-2,-1,-1):
    table[i]=max(table[i+1],ab[i][1])
ans=0
for i in range(n-1):
    c=max(dp[i])
    ans=max(ans,c+table[i+1])
print(ans)

Fixed submission:
n,t=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort()
dp=[[-1]*t for i in range(n)]
for i in range(n):
    dp[i][0]=0
a,b=ab[0]
if a<t:
    dp[0][a]=b
for i in range(1,n):
    a,b=ab[i]
    for j in range(min(a,t)):
        dp[i][j]=dp[i-1][j]
    for j in range(a,t):
        if dp[i-1][j-a]==-1:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-a]+b)
table=[0]*n
table[n-1]=ab[n-1][1]
for i in range(n-2,-1,-1):
    table[i]=max(table[i+1],ab[i][1])
ans=0
for i in range(n-1):
    c=max(dp[i])
    ans=max(ans,c+table[i+1])
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
a,b,x=map(int,input().split())
if a*a*b>=x*2:
    c=2*x/(a*b)
    d=c**2+b**2
    d=d**(1/2)
    ans=np.arccos(c/d)
    print(ans*180/3.1415926535)
else:
    x=a*a*b-x
    c=2*x/(a*a)
    d=c**2+a**2
    d=d**(1/2)
    ans=np.arccos(a/d)
    print(ans*180/3.1415926535)

Fixed submission:
import math
a,b,x=map(int,input().split())
if a*a*b>=x*2:
    c=2*x/(a*b)
    d=c**2+b**2
    d=d**(1/2)
    ans=math.acos(c/d)
    print(ans*180/3.1415926535)
else:
    x=a*a*b-x
    c=2*x/(a*a)
    d=c**2+a**2
    d=d**(1/2)
    ans=math.acos(a/d)
    print(ans*180/3.1415926535)
Buggy python submission (verdict: Time Limit Exceeded):
# 二部グラフかどうかの判定法
import sys
n=int(input())
s=[list(input()) for _ in range(n)]
g=[[] for _ in range(n+1)]
for i in range(n):
    for j in range(i+1,n):
        if s[i][j]=="1":
            g[i+1].append(j+1)
            g[j+1].append(i+1)
#二部グラフかどうかの判定
flag=[-1]*(n+1)
forest=[]
for i in range(1,n+1):
    U=[]
    if flag[i]==-1:
        que=[[i]]
        j=1
        flag[i]=1
        while que:
            h=que.pop()
            H=[]
            for u in h:
                flag[u]=j%2
                U.append(u)
                for v in g[u]:
                    if flag[v]==-1:
                        H.append(v)
                        flag[v]=(j+1)%2
                    elif flag[v]==j%2:
                        print(-1)
                        sys.exit()
            if H:
                que.append(H)
            j+=1
    if U:
        forest.append(U)
#iからjまでの距離を求めていく。
sum=0
for lst in forest:
    m=0
    for i in lst:
        for j in lst:
            if i>=j:
                continue
            que=[[i]]
            flag=[0]*(n+1)
            flag[i]=1
            k=0
            while que:
                k+=1
                h=que.pop()
                H=[]
                for u in h:
                    if u==j:
                        break
                    for v in g[u]:
                        if flag[v]==0:
                            H.append(v)
                            flag[v]=1
                else:
                    if H:
                        que.append(H)
                    continue
                break
            m=max(m,k)
    sum+=m            
print(sum)

Fixed submission:
import sys
n=int(input())
data=[[] for i in range(n+1)]
for i in range(1,n+1):
    s=[None]+list(input())
    for j in range(1,n+1):
        if s[j]=="1":
            data[i].append(j)

#二部グラフ判定
flag=[-1]*(n+1)
for i in range(1,n+1):
    if flag[i]==-1:
        que=[[i]]
        flag[i]=0
        k=1
        while que[0]:
            h=que[0]
            H=[]
            for u in h:
                for v in data[u]:
                    if flag[v]==-1:
                        flag[v]=k
                        H.append(v)
                    else:
                        if flag[v]==k:
                            continue
                        else:
                            print(-1)
                            sys.exit()
            k=(k+1)%2
            que=[H]

#washall
inf=float("inf")
d=[[inf]*(n+1) for i in range(n+1)]
for i in range(1,n+1):
    d[i][i]=0
for i in range(1,n+1):
    for u in data[i]:
        d[i][u]=1
for k in range(1,n+1):
    for i in range(1,n+1):
        for j in range(1,n+1):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])
ans=0
for i in range(1,n+1):
    for j in range(1,n+1):
        ans=max(ans,d[i][j])

print(ans+1)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
X=input()
x=list(map(int,list(X)))
mod=998244353
pow_2=[0]*n
pow_2[n-1]=1
for i in range(1,n):
    pow_2[n-1-i]=(pow_2[n-i]*2)%mod
num=0
for i in range(n):
    if x[i]==1:
        num=(num+pow_2[i])%mod
#約数全列挙
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
li=make_divisors(n)
lst=[]
for i in li:
    if i%2==1 and i>2:
        lst.append(i)
lst.sort(reverse=True)
sum=0
count=0
s=[]
t=[]
for u in lst:
    U=u
    u=n//u
    cnt=0
    for i in range(1,u+1):
        if x[u-i]==1:
            cnt=(cnt+pow_2[-i])%mod
    y=X[:u]
    for i in range(u):
        if X[i]=="0":
            y+="1"
        else:
            y+="0"
    y*=(U+1)//2
    y=y[:n]
    if y<=X:
        cnt+=1
    for i in range(len(s)):
        if u%s[i]==0:
            cnt-=t[i]
    sum=(sum+(2*cnt*u)%mod)%mod
    s.append(u)
    t.append(cnt)
    count=(count+cnt)%mod
print((((num+1-count)*2*n)%mod+sum)%mod)

Fixed submission:
n=int(input())
X=input()
x=list(map(int,list(X)))
mod=998244353
pow_2=[0]*n
pow_2[n-1]=1
for i in range(1,n):
    pow_2[n-1-i]=(pow_2[n-i]*2)%mod
num=0
for i in range(n):
    if x[i]==1:
        num=(num+pow_2[i])%mod
#約数全列挙
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
li=make_divisors(n)
lst=[]
for i in li:
    if i%2==1 and i>2:
        lst.append(i)
lst.sort(reverse=True)
sum=0
count=0
s=[]
t=[]
for u in lst:
    U=u
    u=n//u
    cnt=0
    for i in range(1,u+1):
        if x[u-i]==1:
            cnt=(cnt+pow_2[-i])%mod
    y=list(X[:u])
    for i in range(u):
        if y[i]=="0":
            y.append("1")
        else:
            y.append("0")
    y="".join(y)
    y*=(U+1)//2
    y=y[:n]
    if y<=X:
        cnt+=1
    for i in range(len(s)):
        if u%s[i]==0:
            cnt-=t[i]
    sum=(sum+(2*cnt*u)%mod)%mod
    s.append(u)
    t.append(cnt)
    count=(count+cnt)%mod
print((((num+1-count)*2*n)%mod+sum)%mod)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
data=[[] for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    data[a].append(b)
lst=[]
for i in range(1,n+1):
    h=[str(i)]
    while h:
        H=[]
        for u in h:
            a=int(u[-1])
            for v in data[a]:
                if v==i:
                    lst.append(int(u))
                    break
                else:
                    H.append(u.join(str(v)))
            else:
                continue
            break
        else:
            h=H
            continue
        break
print(lst)
lst.sort()
li=[]
flag=[0]*(n+1)
for u in lst:
    u=list(str(u))
    for v in u:
        if flag[int(v)]==1:
            break
    else:
        for v in u:
            flag[int(v)]=1
        li.append(u)
print(li)
for u in li:
    a=int(u[0])
    que=[a]
    while h:
        H=[]
        for i in que:
            if i==a:
                break
            H+=data[i]
        else:
            h=H
            continue
        break
    for i in u:
        if i in h:
            break
    else:
        print(len(u))
        for i in u:
            print(i)
        break
else:
    print(-1)

Fixed submission:
N,M=map(int,input().split())
data=[[] for i in range(N+1)]
for i in range(M):
    A,B=map(int,input().split())
    data[A].append(B)
lst=[]
for i in range(1,N+1):
    flag=[0]*(N+1)
    parent=[0]*(N+1)
    que=[i]
    while que:
        h=[]
        for u in que:
            for v in data[u]:
                if flag[v]==0:
                    flag[v]=1
                    parent[v]=u
                    h.append(v)
        que=h
    if parent[i]==0:
        continue
    lsls=[i]
    zzz=i
    while True:
        zzz=parent[zzz]
        if zzz==i:
            break
        lsls.append(zzz)
    lst.append(lsls)
inf=float("inf")
k=inf
ans=None
for u in lst:
    if k>len(u):
        ans=u
        k=len(u)
if k==inf:
    print(-1)
else:
    print(k)
    for v in ans:
        print(v)
Buggy python submission (verdict: Time Limit Exceeded):
#AGC C
import fractions
n=int(input())
a=list(map(int,input().split()))
s=0
for i in range(n-1):
    for j in range(i+1,n):
        s=(s+(a[i]*(a[j]//fractions.gcd(a[i],a[j])))%998244353)%998244353
print(s) 

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
V=max(A)
mod=998244353
data=[0]*(V+1)
data[1]=1
for i in range(2,V+1):
    data[i]=-(mod//i)*data[mod%i]%mod
for i in range(1,V+1):
    for j in range(2,V//i+1):
        data[i*j]=(data[i*j]-data[i])%mod
lst=[0]*(V+1)
for a in A:
    lst[a]+=1
mod_2=pow(2,mod-2,mod)
ans=0
for i in range(1,V+1):
    sum_1=0
    sum_2=0
    for j in range(1,V//i+1):
        zzz=i*j
        sum_1+=zzz*lst[zzz]
        sum_2+=zzz**2*lst[zzz]
    ans=(ans+(sum_1**2-sum_2)*data[i]*mod_2)%mod
print(ans)

Buggy python submission (verdict: Runtime Error):
#AGC C
import math
n=int(input())
a=list(map(int,input().split()))
s=0
for i in range(n-1):
    for j in range(i+1,n):
        s=(s+(a[i]*a[j])//(math.gcd(a[i],a[j])))%998244353
print(s) 

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
V=max(A)
mod=998244353
data=[0]*(V+1)
data[1]=1
for i in range(2,V+1):
    data[i]=-(mod//i)*data[mod%i]%mod
for i in range(1,V+1):
    for j in range(2,V//i+1):
        data[i*j]=(data[i*j]-data[i])%mod
lst=[0]*(V+1)
for a in A:
    lst[a]+=1
mod_2=pow(2,mod-2,mod)
ans=0
for i in range(1,V+1):
    sum_1=0
    sum_2=0
    for j in range(1,V//i+1):
        zzz=i*j
        sum_1+=zzz*lst[zzz]
        sum_2+=zzz**2*lst[zzz]
    ans=(ans+(sum_1**2-sum_2)*data[i]*mod_2)%mod
print(ans)
Buggy python submission (verdict: Runtime Error):
#D
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
i=0
l=0
for k in range(m-1):
    if i==n-1:
        for j in range(n):
            a[j]=a[j]//2
    elif a[i]//2<a[i+1]:
        i+=1
    else:
        for j in range(i+1):
            a[j]=a[j]//2
            l+=1
for j in range(m-l):
    a[j]=a[j]//2
print(sum(a))

Fixed submission:
#D heapq
import heapq
def mainasu(n):
    return n*(-1)
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(mainasu,a))
b.sort()
for i in range(m):
    c=heapq.heappop(b)
    if c%2==0:
        heapq.heappush(b,c//2)
    else:
        heapq.heappush(b,c//2+1)
print((-1)*sum(b))
Buggy python submission (verdict: Runtime Error):
n=int(input())
print((int((n-1)*n)/2))

Fixed submission:
s=input()
t=input()
a=0
for i in range(3):
  if s[i]==t[i]:
    a+=1
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=0
for i in range(1,n):
    a+=i
print(a)

Fixed submission:
n=int(input())
print(int((n-1)*n//2))