Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,X,M=map(int,input().split())

seen=[-2]*M
seen[X]
A=[X]
i=1
while(i<N):
    T=A[-1]**2%M
    if seen[T]!=-2:
        Roop=i-seen[T]
        Left,Right=seen[T],i
        break
    A.append(T)
    seen[T]=i
    i+=1

if i==N:
    print(sum(A)+T)
    exit()

Roopsum=0
for i in range(Left,Right):
    Roopsum+=A[i]

Rest=N-len(A)

ans=sum(A)

ans+=Rest//Roop*Roopsum

for i in range(Rest%Roop):
    ans+=T
    T=T**2%M
print(ans)

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

seen=[-2]*M
seen[X]
A=[X]
i=1
while(i<N):
    T=A[-1]**2%M
    if seen[T]!=-2:
        Roop=i-seen[T]
        Left,Right=seen[T],i
        break
    A.append(T)
    seen[T]=i
    i+=1

if i==N:
    print(sum(A))
    exit()

Roopsum=0
for i in range(Left,Right):
    Roopsum+=A[i]

Rest=N-len(A)

ans=sum(A)

ans+=Rest//Roop*Roopsum

for i in range(Rest%Roop):
    ans+=T
    T=T**2%M
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys,itertools,collections,bisect
from collections import deque,Counter,defaultdict
from heapq import heappush,heappop,heapify
read=sys.stdin.readline
sys.setrecursionlimit(10**6)

MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
cum=[0]*(N+1)
for i in range(N):
    cum[i+1]=(cum[i]+A[i])%MOD

ans=0
for i in range(N):
    res=(cum[N]-cum[i+1]+MOD)%MOD*A[i]%MOD
    ans=(ans+res)%MOD
print(ans)


Fixed submission:
D,T,S=map(int,input().split())

if T*S>=D:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
INF=10**20
from heapq import heappop,heappush,heapify
def dijkstra(G,H,W,sh,sw):
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    que=[(0,sh,sw)]
    dist=[[INF]*W for i in range(H)]
    dist[sh][sw]=0
    while que:
        mincost,h,w=heappop(que)
        if(mincost>dist[h][w]):
            continue
        for di in range(4):
            nh=h+dx[di]
            nw=w+dy[di]
            if(nh>H-1 or nh<0 or nw>W-1 or nw<0):
                continue
            if(G[nh][nw]=='#'):
                continue
            if(dist[h][w]<dist[nh][nw]):
                dist[nh][nw]=dist[h][w]
                heappush(que,(dist[nh][nw],nh,nw))
        for nh in range(h-2,h+3):
            for nw in range(w-2,w+3):
                if (nh>H-1 or nh<0 or nw>W-1 or nw<0):
                    continue
                if(G[nh][nw]=='#'):
                    continue
                if dist[h][w]+1<dist[nh][nw]:
                    dist[nh][nw]=dist[h][w]+1
                    heappush(que,(dist[nh][nw],nh,nw))
    return dist

H,W=map(int,input().split())
Ch,Cw=map(lambda x:int(x)-1,input().split())
Dh,Dw=map(lambda x:int(x)-1,input().split())
G=[list(input()) for i in range(H)]
dist=dijkstra(G,H,W,Ch,Cw)
ans=dist[Dh][Dw]
if ans!=INF:
    print(ans)
else:
    print(-1)

Fixed submission:
INF=float('inf')
from collections import deque
def mbfs(G,sh,sw,H,W):
    dist=[[INF]*W for i in range(H)]
    dist[sh][sw]=0

    d=deque()
    d.append([sh,sw])
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    while(len(d)!=0):
        h=d[0][0]
        w=d[0][1]
        d.popleft()
        for dir in range(4):
            nh=h+dx[dir]
            nw=w+dy[dir]
            if(nh>H-1 or nh<0 or nw>W-1 or nw<0):
                continue
            if(G[nh][nw]=='#'):
                continue
            if dist[nh][nw]>dist[h][w]:
                dist[nh][nw]=dist[h][w]
                d.appendleft([nh,nw])
        for i in range(h-2,h+3):
            for j in range(w-2,w+3):
                if (i>H-1 or i<0 or j>W-1 or j<0):
                    continue
                if (G[i][j]=='#'):
                    continue
                if dist[i][j]>dist[h][w]+1:
                    dist[i][j]=dist[h][w]+1
                    d.append([i,j])
    return dist

H,W=map(int,input().split())
Ch,Cw=map(lambda x:int(x)-1,input().split())
Dh,Dw=map(lambda x:int(x)-1,input().split())
G=[list(input()) for i in range(H)]

dist=mbfs(G,Ch,Cw,H,W)
if dist[Dh][Dw]!=INF:
    print(dist[Dh][Dw])
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
H,W,K=map(int,input().split())
G=[[0]*W for i in range(H)]

for i in range(K):
    r,c,v=map(int,input().split())
    r,c=r-1,c-1
    G[r][c]=v

dp=[[[-1,-1,-1,-1] for i in range(W)] for i in range(H)]

dp[0][0][0]=0
if G[0][0]!=0:
    dp[0][0][1]=G[0][0]

for i in range(H):
    for j in range(W):
        m=max(dp[i][j])
        if i+1<H:
            dp[i+1][j][1]=max(dp[i+1][j][1],m+G[i+1][j])
            dp[i+1][j][0]=max(dp[i+1][j][0],m)
        if j+1<W:
                dp[i][j+1][0]=0
                dp[i][j+1][1]=max(dp[i][j+1][1],dp[i][j][1],dp[i][j][0]+G[i][j+1])
                dp[i][j+1][2]=max(dp[i][j+1][2],dp[i][j][2],dp[i][j][1]+G[i][j+1])
                dp[i][j+1][3]=max(dp[i][j+1][3],dp[i][j][3],dp[i][j][2]+G[i][j+1])
print(max(dp[H-1][W-1]))

Fixed submission:
import sys
input=sys.stdin.readline
H,W,K=map(int,input().split())
G=[[0]*W for i in range(H)]

for i in range(K):
    r,c,v=map(int,input().split())
    r,c=r-1,c-1
    G[r][c]=v


dp0=[[-1 for i in range(W)] for i in range(H)]
dp1=[[-1 for i in range(W)] for i in range(H)]
dp2=[[-1 for i in range(W)] for i in range(H)]
dp3=[[-1 for i in range(W)] for i in range(H)]

dp0[0][0]=0
if G[0][0]!=0:
    dp1[0][0]=G[0][0]

for i in range(H):
    for j in range(W):
        m=max(dp0[i][j],dp1[i][j],dp2[i][j],dp3[i][j])
        if i+1<H:
            dp1[i+1][j]=max(dp1[i+1][j],m+G[i+1][j])
            dp0[i+1][j]=max(dp0[i+1][j],m)
        if j+1<W:
                dp0[i][j+1]=0
                dp1[i][j+1]=max(dp1[i][j+1],dp1[i][j],dp0[i][j]+G[i][j+1])
                dp2[i][j+1]=max(dp2[i][j+1],dp2[i][j],dp1[i][j]+G[i][j+1])
                dp3[i][j+1]=max(dp3[i][j+1],dp3[i][j],dp2[i][j]+G[i][j+1])
print(max(dp0[H-1][W-1],dp1[H-1][W-1],dp2[H-1][W-1],dp3[H-1][W-1]))
Buggy python submission (verdict: Runtime Error):
def popcount(x):
    if x in memo:
        return memo[x]
    res=0
    while(x>0):
        if x&1:
            res+=1
        x//=2
    memo[x]=res
    return res
memo={}

N=int(input())
X=input()[::-1]
c=X.count('1')
count=[0]*(c+2)
for i in range(c+2):
    x=i
    cnt=0
    while(x>0):
        x=x%popcount(x)
        cnt+=1
    count[i]=cnt

if X[0]=='0':
    summ,sumn,sump=0,0,0
else:
    summ,sumn,sump=1,1,1
bitm,bitn,bitp=[0]*N,[0]*N,[0]*N
bitm[0],bitn[0],bitp[0]=1,1,1
for i in range(1,N):
    bitm[i]=bitm[i-1]*2%(c-1)
    bitn[i]=bitn[i-1]*2%c
    bitp[i]=bitp[i-1]*2%(c+1)
    if X[i]=='1':
        summ=(summ+bitm[i])%(c-1)
        sumn=(sumn+bitn[i])%c
        sump=(sump+bitp[i])%(c+1)
ans=[]
for i in range(N):
    if X[i]=='0':
        x=(sump+bitp[i])%(c+1)
        ans.append(count[x]+1)
    else:
        x=(summ-bitm[i]+c-1)%(c-1)
        ans.append(count[x]+1)
print(*ans[::-1],sep='\n')

Fixed submission:
def popcount(x):
    if x in memo:
        return memo[x]
    res=0
    while(x>0):
        if x&1:
            res+=1
        x//=2
    memo[x]=res
    return res
memo={}

N=int(input())
X=input()[::-1]
c=X.count('1')
count=[0]*(c+2)
for i in range(c+2):
    x=i
    cnt=0
    while(x>0):
        x=x%popcount(x)
        cnt+=1
    count[i]=cnt

if X[0]=='0':
    summ,sumn,sump=0,0,0
else:
    summ,sumn,sump=1,1,1
bitm,bitn,bitp=[0]*N,[0]*N,[0]*N
bitm[0],bitn[0],bitp[0]=1,1,1
for i in range(1,N):
    if c>1:
        bitm[i]=bitm[i-1]*2%(c-1)
    bitn[i]=bitn[i-1]*2%c
    bitp[i]=bitp[i-1]*2%(c+1)
    if X[i]=='1':
        if c>1:
            summ=(summ+bitm[i])%(c-1)
        sumn=(sumn+bitn[i])%c
        sump=(sump+bitp[i])%(c+1)
ans=[]
for i in range(N):
    if X[i]=='0':
        x=(sump+bitp[i])%(c+1)
        ans.append(count[x]+1)
    else:
        if c==1:
            ans.append(0)
        else:
            x=(summ-bitm[i]+c-1)%(c-1)
            ans.append(count[x]+1)
print(*ans[::-1],sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
import time
import random

def test(li):
    m=0
    for i in range(D):
        m+=s[i][li[i]-1]
        last[li[i]-1]=i+1
        for j in range(26):
            m-=c[j]*(i+1-last[j])
    return m

start=time.time()
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]
last=[0]*26
t=[random.randrange(1,27) for i in range(D)]

res=test(t)

while(True):
    if time.time()-start>=1.90:
        break
    for i in range(D):
        if time.time()-start>=1.90:
            break
        q=random.randrange(1,27)
        li=t.copy()
        li[i]=q
        r=test(li)
        if r>res:
            res=r
            t[i]=q
print(*t,sep='\n')

Fixed submission:
import random
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]
for i in range(D):
    print(random.randrange(1,27))
Buggy python submission (verdict: Runtime Error):
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

i,j=0,0
time=0
cnt=0

while time<K and (i<N or j<M):
    if i==N:
        if time+B[j]>K:
            break
        time+=B[j]
        cnt+=1
        j+=1
    elif j==N:
        if time+A[i]>K:
            break
        time+=A[i]
        cnt+=1
        i+=1
    elif A[i]<B[j]:
        if time+A[i]>K:
            break
        time+=A[i]
        cnt+=1
        i+=1
    elif B[j]<A[i]:
        if time+B[j]>K:
            break
        time+=B[j]
        cnt+=1
        j+=1
    else:
        if time+A[i]>K:
            break
        if j==M-1 and i==N-1:
            time+=A[i]
            cnt+=1
            i+=1
        elif j==M-1:
            time+=A[i]
            cnt+=1
            i+=1
        elif i==N-1:
            time+=B[j]
            cnt+=1
            j+=1
        else:
            if A[i+1]<B[j+1]:
                time+=A[i]
                cnt+=1
                i+=1
            elif A[i+1]>B[j+1]:
                time+=B[j]
                cnt+=1
                j+=1
            else:
                time+=A[i]
                cnt+=1
                i+=1
print(cnt)

Fixed submission:
from bisect import bisect_left
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

cumA=[0]*(N+1)
cumB=[0]*(M+1)

for i in range(N):
    cumA[i+1]=cumA[i]+A[i]
for i in range(M):
    cumB[i+1]=cumB[i]+B[i]

ans=0
for i in range(N+1):
    r=K-cumA[i]
    if r<0:
        break
    b=bisect_left(cumB,r)
    if b==M+1:
        ans=max(ans,i+M)
    else:
        if cumB[b]!=r:
            b-=1
        ans=max(ans,i+b)
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=sorted(map(int,input().split()))

ans=0
dp=[True]*(max(A)+1)
for i in range(N):
    if not dp[A[i]]:
        continue
    if i==N-1:
        ans+=1
    elif i<N-1 and A[i+1]!=A[i]:
        ans+=1
    for j in range(1,max(A)//A[i]+1):
        dp[A[i]*j]=False
print(ans)

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

for i in range(5):
    if x[i]==0:
        print(i+1)
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=list(map(int,input().split()))

for i in range(K):
    B=[0]*(N+1)
    for j in range(N):
        l=max(0,j-A[j])
        r=min(N-1,j+A[j])
        B[l]+=1
        B[r+1]-=1
    for j in range(1,N):
        B[j]=B[j]+B[j-1]
    ok=True
    for j in range(N):
        if B[j]!=N:
            ok=False
            break
    if ok:
        print(*B[:N])
        exit()
        
    A=B.copy()
print(*A[:N])

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))

for i in range(K):
    B=[0]*(N+1)
    for j in range(N):
        l=max(0,j-A[j])
        r=min(N-1,j+A[j])
        B[l]+=1
        B[r+1]-=1
    for j in range(1,N):
        B[j]=B[j]+B[j-1]
    ok=True
    for j in range(N):
        if B[j]!=N:
            ok=False
            break
    if ok:
        print(*B[:N])
        exit()
        
    A=B.copy()
print(*A[:N])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
ans=1
for i in range(N):
    ans=ans*A[i]
print(ans if ans<=10**18 else -1)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
ans=1
if 0 in A:
    print(0)
    exit()
for i in range(N):
    ans=ans*A[i]
    if ans>10**18:
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
MOD=998244353
n,s=map(int,input().split())
a=list(map(int,input().split()))
al=sum(a)
dp=[[0]*(al+1) for i in range(n+1)]
dp[0][0]=1
for i in range(n):
    for j in range(al+1):
        if j==0:
            dp[i+1][j]=pow(2,i+1,MOD)
            continue
        dp[i+1][j]=(dp[i+1][j]+(dp[i][j]*2%MOD))%MOD
        if j-a[i]>=0:
            dp[i+1][j]=(dp[i+1][j]+dp[i][j-a[i]])%MOD
print(dp[n][s])

Fixed submission:
MOD=998244353
n,s=map(int,input().split())
a=list(map(int,input().split()))
al=sum(a)
dp=[[0]*3001 for i in range(n+1)]
dp[0][0]=1
for i in range(n):
    for j in range(3001):
        if j==0:
            dp[i+1][j]=pow(2,i+1,MOD)
            continue
        dp[i+1][j]=(dp[i+1][j]+(dp[i][j]*2%MOD))%MOD
        if j-a[i]>=0:
            dp[i+1][j]=(dp[i+1][j]+dp[i][j-a[i]])%MOD
print(dp[n][s])
Buggy python submission (verdict: Runtime Error):
from collections import Counter
import math
MOD=10**9+7
N=int(input())
li=[]
for i in range(N):
    A,B=map(int,input().split())
    g=math.gcd(A,B)
    li.append((A//g,B//g))
c=Counter(li)
dic={}
ans=1
for a,b in c.keys():
    if (a,b) in dic:
        continue
    l,r=(-b,a),(b,-a)
    s=c.get(l,0)+c.get(r,0)
    dic[l],dic[r]=1,1
    res=(pow(2,c[(a,b)],MOD)+pow(2,s,MOD)-1)%MOD
    ans=(ans*res)%MOD
print(ans-1)

Fixed submission:
from collections import Counter
import math
MOD=10**9+7
N=int(input())
li=[]
zcnt=0
az,bz=0,0
for i in range(N):
    A,B=map(int,input().split())
    if A==0 and B==0:
        zcnt+=1
        continue
    if A!=0 and B==0:
        bz+=1
        continue
    elif A==0 and B!=0:
        az+=1
        continue
    g=math.gcd(A,B)
    if A<0 and B<0:
        li.append((-(A//g),-(B//g)))
    elif A<0 and B>0:
        li.append((-(A//g),-(B//g)))
    else:
        li.append((A//g,B//g))
c=Counter(li)
dic={}
ans=(pow(2,az,MOD)+pow(2,bz,MOD)-1+MOD)%MOD
for a,b in c.keys():
    if (a,b) in dic:
        continue
    l,r=(-b,a),(b,-a)
    s=c.get(l,0)+c.get(r,0)
    dic[l],dic[r]=1,1
    res=(pow(2,c[(a,b)],MOD)+pow(2,s,MOD)-1+MOD)%MOD
    ans=(ans*res)%MOD
print((ans-1+zcnt)%MOD)
Buggy python submission (verdict: Runtime Error):
ans=''
def dfs(a,b,c,t):
    global ans
    if a<0 or b<0 or c<0:
        return False
    if t==N:
        return True
    if s[t]=='AB':
        if dfs(a-1,b+1,c,t+1):
            ans+='B'
            return True
        elif dfs(a+1,b-1,c,t+1):
            ans+='A'
            return True
    if s[t]=='BC':
        if dfs(a,b-1,c+1,t+1):
            ans+='C'
            return True
        elif dfs(a,b+1,c-1,t+1):
            ans+='B'
            return True
    if s[t]=='AC':
        if dfs(a+1,b,c-1,t+1):
            ans+='A'
            return True
        if dfs(a-1,b,c+1,t+1):
            ans+='C'
            return True
    return False

N,A,B,C=map(int,input().split())
s=[input() for i in range(N)]

if dfs(A,B,C,0):
    print('Yes')
    print(*ans[::-1],sep='\n')
else:
    print('No')

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
ans=''
def dfs(a,b,c,t):
    global ans
    if a<0 or b<0 or c<0:
        return False
    if t==N:
        return True
    if s[t]=='AB':
        if dfs(a-1,b+1,c,t+1):
            ans+='B'
            return True
        elif dfs(a+1,b-1,c,t+1):
            ans+='A'
            return True
    if s[t]=='BC':
        if dfs(a,b-1,c+1,t+1):
            ans+='C'
            return True
        elif dfs(a,b+1,c-1,t+1):
            ans+='B'
            return True
    if s[t]=='AC':
        if dfs(a+1,b,c-1,t+1):
            ans+='A'
            return True
        if dfs(a-1,b,c+1,t+1):
            ans+='C'
            return True
    return False

N,A,B,C=map(int,input().split())
s=[input() for i in range(N)]

if dfs(A,B,C,0):
    print('Yes')
    print(*ans[::-1],sep='\n')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
MOD=2019
S=input();N=len(S)
Cum=[0]*(N+1)
for i in range(N):
    Cum[i+1]=(Cum[i]+int(S[N-i-1])*(10**i))%MOD
res=0
c=Counter(Cum).most_common()
for a,b in c:
    res+=b*(b-1)//2
    if(b==1):
        break
print(res)

Fixed submission:
from collections import Counter
MOD=2019
S=input();N=len(S)
Cum=[0]*(N+1)
for i in range(N):
    Cum[i+1]=(Cum[i]+int(S[N-i-1])*pow(10,i,MOD))%MOD
res=0
c=Counter(Cum).most_common()
for a,b in c:
    res+=b*(b-1)//2
    if(b==1):
        break
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
MOD=2019
S=input();N=len(S)
Cum=[0]*(N+1)
for i in range(N):
    Cum[i+1]=(Cum[i]+int(S[N-i-1])*(10**i))%MOD
res=0
c=Counter(Cum).most_common()
for a,b in c:
    res+=b*(b-1)//2
    if(b==1):
        break
print(res)

Fixed submission:
from collections import Counter
MOD=2019
S=input();N=len(S)
Cum=[0]*(N+1)
for i in range(N):
    Cum[i+1]=(Cum[i]+int(S[N-i-1])*pow(10,i,MOD))%MOD
res=0
c=Counter(Cum).most_common()
for a,b in c:
    res+=b*(b-1)//2
    if(b==1):
        break
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter,deque
def bfs(G,s,N):
    dist=[-1]*(N+1)
    d=deque()
    dist[s]=0
    d.append(s)
    while(len(d)!=0):
        v=d[0]
        d.popleft()
        for nv in G[v]:
            if(dist[nv]!=-1):
                continue
            #発見した地点への操作
            dist[nv]=dist[v]+1
            d.append(nv)
            #ここまで
    return dist

N,X,Y=map(int,input().split())
G=[[] for i in range(N+1)]
for i in range(1,N):
    G[i].append(i+1)
    G[i+1].append(i)
G[X].append(Y);G[Y].append(X)
Count=[0]*(N+1)
for i in range(1,N+1):
    li=bfs(G,i,N)
    c=Counter(li)
    for i in range(1,N+1):
        Count[i]+=c[i]
for i in range(1,N):
    print(Count[i]//2)


Fixed submission:
from collections import Counter,deque
def bfs(G,s,N):
    dist=[-1]*(N+1)
    d=deque()
    dist[s]=0
    d.append(s)
    while(len(d)!=0):
        v=d[0]
        d.popleft()
        for nv in G[v]:
            if(dist[nv]!=-1):
                continue
            #発見した地点への操作
            dist[nv]=dist[v]+1
            d.append(nv)
            #ここまで
    return dist

N,X,Y=map(int,input().split())
G=[[] for i in range(N+1)]
for i in range(1,N):
    G[i].append(i+1)
    G[i+1].append(i)
G[X].append(Y);G[Y].append(X)
Count=[0]*(N+1)
for i in range(1,N+1):
    li=bfs(G,i,N)
    c=Counter(li)
    for i in range(1,N+1):
        Count[i]+=c[i]
for i in range(1,N):
    print(Count[i]//2)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter,deque
def bfs(G,s,N):
    dist=[-1]*(N+1)
    d=deque()
    dist[s]=0
    d.append(s)
    while(len(d)!=0):
        v=d[0]
        d.popleft()
        for nv in G[v]:
            if(dist[nv]!=-1):
                continue
            #発見した地点への操作
            dist[nv]=dist[v]+1
            d.append(nv)
            #ここまで
    return dist

N,X,Y=map(int,input().split())
G=[[] for i in range(N+1)]
for i in range(1,N):
    G[i].append(i+1)
    G[i+1].append(i)
G[X].append(Y);G[Y].append(X)
Count=[0]*(N+1)
for i in range(1,N+1):
    li=bfs(G,i,N)
    c=Counter(li)
    for i in range(1,N+1):
        Count[i]+=c[i]
for i in range(1,N):
    print(Count[i]//2)

Fixed submission:
from collections import Counter,deque
def bfs(G,s,N):
    dist=[-1]*(N+1)
    d=deque()
    dist[s]=0
    d.append(s)
    while(len(d)!=0):
        v=d[0]
        d.popleft()
        for nv in G[v]:
            if(dist[nv]!=-1):
                continue
            #発見した地点への操作
            dist[nv]=dist[v]+1
            d.append(nv)
            #ここまで
    return dist

N,X,Y=map(int,input().split())
G=[[] for i in range(N+1)]
for i in range(1,N):
    G[i].append(i+1)
    G[i+1].append(i)
G[X].append(Y);G[Y].append(X)
Count=[0]*(N+1)
for i in range(1,N+1):
    li=bfs(G,i,N)
    c=Counter(li)
    for i in range(1,N+1):
        Count[i]+=c[i]
for i in range(1,N):
    print(Count[i]//2)
Buggy python submission (verdict: Time Limit Exceeded):
H,W,K=map(int,input().split())
S=[list(map(int,list(input()))) for i in range(H)]
ans=H+W-2
for bit in range(2**(H-1)):
    divH=[0]
    for j in range(H-1):
        if(bit>>j&1):
            divH.append(j+1)
    divH.append(H)
    glen=len(divH)-1
    group=[0]*(glen)
    res=glen-1
    go=True
    w=0
    while w<W:
        ok=True
        c=[0]*(glen)
        for g in range(glen):
            cum=0
            for h in range(divH[g],divH[g+1]):
                if cum>K:
                    go=False
                cum+=S[h][w]
            c[g]+=cum
            if cum+group[g]>K:
                ok=False
        if not go:
            break
        if not ok:
            res+=1
            group=[0]*glen
        else:
            for i in range(glen):
                group[i]+=c[i]
            w+=1
    if not go:
        continue
    ans=min(ans,res)
print(ans)

Fixed submission:
H,W,K=map(int,input().split())
S=[list(map(int,list(input()))) for i in range(H)]
ans=H+W-2
for bit in range(2**(H-1)):
    divH=[0]
    for j in range(H-1):
        if(bit>>j&1):
            divH.append(j+1)
    divH.append(H)
    glen=len(divH)-1
    group=[0]*(glen)
    res=glen-1
    go=True
    w=0
    while w<W:
        ok=True
        c=[0]*(glen)
        for g in range(glen):
            cum=0
            for h in range(divH[g],divH[g+1]):
                cum+=S[h][w]
            c[g]+=cum
            if cum>K:
                go=False
                break
            if c[g]+group[g]>K:
                ok=False
        if not go:
            break
        if not ok:
            res+=1
            group=[0]*glen
        else:
            for i in range(glen):
                group[i]+=c[i]
            w+=1
    if not go:
        continue
    ans=min(ans,res)
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
a,b,c=map(int,input().split())
a*=10**12;b*=10**12;c*=10**12
if(np.sqrt(a)+np.sqrt(b)-np.sqrt(c)>=0):
    print("No")
else:
    print("Yes")

Fixed submission:
from decimal import Decimal
a,b,c=list(map(int,input().split()))
if(Decimal(a).sqrt()+Decimal(b).sqrt()<Decimal(c).sqrt()):
    print("Yes")
else:
    print("No")