Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
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)]


dp=[[set() for j in range(w)]for i in range(h)]
sub=a[0][0]-b[0][0]
dp[0][0].add(sub)
dp[0][0].add(-sub)

for c in range(h):
    for l in range(w):
        sub=a[c][l]-b[c][l]
        if c!=0:
            for p in dp[c-1][l]:
                dp[c][l].add(p+sub)
                dp[c][l].add(p-sub)
        if l!=0:
            for p in dp[c][l-1]:
                dp[c][l].add(p+sub)
                dp[c][l].add(p-sub)
st=dp[-1][-1]
for i in range(1000000):
    if (i in st)or(-i in st):
        print(i)
        break

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)]

pos = 160*80
dp=[[0]*w for i in range(h)]
sub=abs(a[0][0]-b[0][0])
dp[0][0]=1<<(pos-sub)
dp[0][0]=1<<(pos+sub)

for c in range(h):
    for l in range(w):
        sub=abs(a[c][l]-b[c][l])
        if l!=0:
            dp[c][l]|=dp[c][l-1]<<sub
            dp[c][l]|=dp[c][l-1]>>sub
        if c!=0:
            dp[c][l]|=dp[c-1][l]<<sub
            dp[c][l]|=dp[c-1][l]>>sub
bit=dp[-1][-1]
for i in range(pos):
    if (bit&1<<(pos+i))or(bit&1<<(pos-i)):
        print(i)
        break

Buggy python submission (verdict: Time Limit Exceeded):
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)]


dp=[[set() for j in range(w)]for i in range(h)]
sub=a[0][0]-b[0][0]
dp[0][0].add(sub)
dp[0][0].add(-sub)

for c in range(h):
    for l in range(w):
        sub=a[c][l]-b[c][l]
        if c!=0:
            for p in dp[c-1][l]:
                dp[c][l].add(p+sub)
                dp[c][l].add(p-sub)
        if l!=0:
            for p in dp[c][l-1]:
                dp[c][l].add(p+sub)
                dp[c][l].add(p-sub)
st=dp[-1][-1]
for i in range(1000000):
    if (i in st)or(-i in st):
        print(i)
        break

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)]

pos = 160*80
dp=[[0]*w for i in range(h)]
sub=abs(a[0][0]-b[0][0])
dp[0][0]=1<<(pos-sub)
dp[0][0]=1<<(pos+sub)

for c in range(h):
    for l in range(w):
        sub=abs(a[c][l]-b[c][l])
        if l!=0:
            dp[c][l]|=dp[c][l-1]<<sub
            dp[c][l]|=dp[c][l-1]>>sub
        if c!=0:
            dp[c][l]|=dp[c-1][l]<<sub
            dp[c][l]|=dp[c-1][l]>>sub
bit=dp[-1][-1]
for i in range(pos):
    if (bit&1<<(pos+i))or(bit&1<<(pos-i)):
        print(i)
        break
Buggy python submission (verdict: Runtime Error):
n,a,d=map(int,input().split())

dic={}

ans=0
for k in range(n+1):
    l=k*a+k*(k-1)*d//2
    r=l+k*(n-k)*d
    idx=l%d
    l//=d
    r//=d
    if idx in dic:
        prel,prer=dic[idx]
        #共通部分ありか、なしかで分岐
        if prer<l or prel>r:
            dic[idx]=(l,r)
            ans+=r-l+1 
        else:
            nl=min(prel,l)
            nr=max(prer,r)
            ans+=prel-nl+nr-prer
            dic[idx]=(nl,nr)
    else:
        ans+=r-l+1 
        dic[idx]=(l,r)
print(ans)

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

dic={}

ans=0

if d==0:
    if a==0:
        print(1)
    else:
        print(n+1)
else:
    for k in range(n+1):
        l=k*a+k*(k-1)*d//2
        r=l+k*(n-k)*d
        idx=l%d
        l//=d
        r//=d
        if idx in dic:
            prel,prer=dic[idx]
            #共通部分ありか、なしかで分岐
            if prer<l or prel>r:
                dic[idx]=(l,r)
                ans+=r-l+1 
            else:
                nl=min(prel,l)
                nr=max(prer,r)
                ans+=prel-nl+nr-prer
                dic[idx]=(nl,nr)
        else:
            ans+=r-l+1 
            dic[idx]=(l,r)
    print(ans)

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

dic={}

ans=0
for k in range(n+1):
    l=k*a+k*(k-1)*d//2
    r=l+k*(n-k)*d
    idx=l%d
    l//=d
    r//=d
    print(l,r,idx)
    if idx in dic:
        prel,prer=dic[idx]
        #共通部分ありか、なしかで分岐
        if prer<l or prel>r:
            dic[idx]=(l,r)
            ans+=r-l+1 
        else:
            nl=min(prel,l)
            nr=max(prer,r)
            ans+=prel-nl+nr-prer
            dic[idx]=(nl,nr)
    else:
        ans+=r-l+1 
        dic[idx]=(l,r)
print(ans)

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

dic={}

ans=0

if d==0:
    if a==0:
        print(1)
    else:
        print(n+1)
else:
    for k in range(n+1):
        l=k*a+k*(k-1)*d//2
        r=l+k*(n-k)*d
        idx=l%d
        l//=d
        r//=d
        if idx in dic:
            prel,prer=dic[idx]
            #共通部分ありか、なしかで分岐
            if prer<l or prel>r:
                dic[idx]=(l,r)
                ans+=r-l+1 
            else:
                nl=min(prel,l)
                nr=max(prer,r)
                ans+=prel-nl+nr-prer
                dic[idx]=(nl,nr)
        else:
            ans+=r-l+1 
            dic[idx]=(l,r)
    print(ans)
Buggy python submission (verdict: Runtime Error):

n = int(input())
vs = [[] for i in range(n)]
out = [0]*n


for i in range(n-1):
    a, b = [i+0,i+1]
    vs[a].append([b,i+1])
    vs[b].append([a,i+1])

nex = [[0,-1]]

def coloring(index,defColor):
    i=0
    for v in vs[index]:
        if i==defColor:
           i+=1
        out[v[1]]=i
        vs[v[0]].remove([index,v[1]])
        nex.append([v[0],i])
        i+=1
    out[0] = max(out[0],i-1)

while nex.__len__()>0:
    c,d = nex.pop()
    coloring(c,d)

for i in range(n):
    print(out[i]+1)





Fixed submission:
s = input()

l = ["SUN","MON","TUE","WED","THU","FRI","SAT"]

print(7-l.index(s))

Buggy python submission (verdict: Runtime Error):
def D(x):
    return str(x).__len__()

def price(x):
    return D(x)*b + a*x

d = 1

if price(1)>x:
    print(0)
else:
    while True:
        if price(d*10) <= x:
            d*=10
            if(d==1000000000):
                print(d)
                break
            continue
        else:
            print(max(d + (x-price(d))//a,d*10-1))
            break

Fixed submission:
s = input()

l = ["SUN","MON","TUE","WED","THU","FRI","SAT"]

print(7-l.index(s))
Buggy python submission (verdict: Runtime Error):
n = int(input())
vs = [[] for i in range(n)]
out = [0]*n

for i in range(n-1):
    a, b = [int(i) for i in input().split()]
    vs[a].append([b,i+1])
    vs[b].append([a,i+1])

nex = [[0,-1]]

def coloring(index,defColor):
    i=0
    for v in vs[index]:
        if i==defColor:
           i+=1
        out[v[1]]=i
        vs[v[0]].remove([index,v[1]])
        nex.append([v[0],i])
        i+=1
    out[0] = max(out[0],i-1)

while nex.__len__()>0:
    c,d = nex.pop()
    coloring(c,d)

for i in range(n):
    print(out[i]+1)





Fixed submission:
n = int(input())
vs = [[] for i in range(n)]
out = [0]*n

for i in range(n-1):
    a, b = [int(i)-1 for i in input().split()]
    vs[a].append([b,i+1])
    vs[b].append([a,i+1])

nex = [[0,-1]]

def coloring(index,defColor):
    i=0
    for v in vs[index]:
        if i==defColor:
           i+=1
        out[v[1]]=i
        vs[v[0]].remove([index,v[1]])
        nex.append([v[0],i])
        i+=1
    out[0] = max(out[0],i-1)

while nex.__len__()>0:
    c,d = nex.pop()
    coloring(c,d)

for i in range(n):
    print(out[i]+1)

Buggy python submission (verdict: Runtime Error):
n = int(input())
vs = [[] for i in range(n)]
out = [0]*n

for i in range(n-1):
    a, b = [int(i)-1 for i in input().split()]
    vs[a].append([b,i+1])
    vs[b].append([a,i+1])

def coloring(index,defColor):
    i=0
    for v in vs[index]:
        if i==defColor:
           i+=1
        out[v[1]]=i
        vs[v[0]].remove([index,v[1]])
        coloring(v[0],i)
        i+=1
    out[0] = max(out[0],i-1)

coloring(0,-1)
for i in range(n):
    print(out[i]+1)

Fixed submission:
n = int(input())
vs = [[] for i in range(n)]
out = [0]*n

for i in range(n-1):
    a, b = [int(i)-1 for i in input().split()]
    vs[a].append([b,i+1])
    vs[b].append([a,i+1])

nex = [[0,-1]]

def coloring(index,defColor):
    i=0
    for v in vs[index]:
        if i==defColor:
           i+=1
        out[v[1]]=i
        vs[v[0]].remove([index,v[1]])
        nex.append([v[0],i])
        i+=1
    out[0] = max(out[0],i-1)

while nex.__len__()>0:
    c,d = nex.pop()
    coloring(c,d)

for i in range(n):
    print(out[i]+1)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n,k=map(int,input().split())

a=np.array(input().split(),dtype=np.int64)
f=np.array(input().split(),dtype=np.int64)

a.sort()
f.sort()
f=f[::-1]
af=a*f

# r以下にするのに必要修行回数がk以内かどうか
def safe(r):
    return (np.maximum(0,(af-r+f-1)//f)).sum()<=k
    
m=-1
M=10**12

while True:
    pos=(m+M)//2
    if safe(pos):
        M=pos
    else:
        if m==pos:#終わり
            print(M)
            break
        m=pos



Fixed submission:
import numpy as np

n,k=map(int,input().split())

a=np.array(input().split(),dtype=np.int64)
f=np.array(input().split(),dtype=np.int64)

a.sort()
f.sort()
f=f[::-1]
af=a*f

# r以下にするのに必要修行回数がk以内かどうか
def safe(r):
    return (np.maximum(0,(af-r+f-1)//f)).sum()<=k
    
m=-1
M=10**12

while m+1<M:
    pos=(m+M)//2
    if safe(pos):
        M=pos
    else:
        m=pos
print(M)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n,k=map(int,input().split())

a=np.array(input().split(),dtype=np.int64)
f=np.array(input().split(),dtype=np.int64)
a.sort()
f.sort()
f=f[::-1]
af=a*f

# r以下にするのに必要修行回数がk以内かどうか
def safe(r):
    return sum(np.maximum(0,af-r+f-1)//f)<=k
    
m=-1
M=10**12

while True:
    pos=(m+M)//2
    if safe(pos):
        M=pos
    else:
        if m==pos:#終わり
            print(M)
            break
        m=pos



Fixed submission:
import numpy as np

n,k=map(int,input().split())

a=np.array(input().split(),dtype=np.int64)
f=np.array(input().split(),dtype=np.int64)

a.sort()
f.sort()
f=f[::-1]
af=a*f

# r以下にするのに必要修行回数がk以内かどうか
def safe(r):
    return (np.maximum(0,(af-r+f-1)//f)).sum()<=k
    
m=-1
M=10**12

while m+1<M:
    pos=(m+M)//2
    if safe(pos):
        M=pos
    else:
        m=pos
print(M)
Buggy python submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse import lil_matrix, csr_matrix
from scipy.sparse.csgraph import shortest_path

n,m,limit=map(int,input().split())
G=np.zeros((n,n),dtype=np.int64)
for i in range(m):
    a,b,cost=map(int,input().split())
    G[a-1,b-1]=cost
    G[b-1,a-1]=cost
G=shortest_path(G,method='FW')
for c in range(n):
    for l in range(n):
        if G[c][l]<=limit:
            G[c][l]=1
        else:
            G[c][l]=0
G=shortest_path(G,method='FW')
q=int(input())
Q=[map(int,input().split())for i in range(q)]
for a,b in Q:
    print(int(G[a-1][b-1])-1)

Fixed submission:
n,m,l=map(int,input().split())
cost=[[10**9+1]*n for i in range(n)]
length=[[10**9]*n for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    a-=1
    b-=1
    cost[a][b]=c
    cost[b][a]=c
q=int(input())
st=[map(int,input().split())for i in range(q)]

for k in range(n):
    for i in range(n):
        for j in range(n):
            cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j])
for i in range(n):
    length[i][i]=0
for i in range(n):
    for j in range(n):
        if cost[i][j]<=l:
            length[i][j]=0
for k in range(n):
    for i in range(n):
        for j in range(n):
            length[i][j]=min(length[i][j],length[i][k]+length[k][j]+1)
for s,t in st:
    ch=min(length[s-1][t-1],length[t-1][s-1])
    print(-1 if ch>10**8 else ch)
Buggy python submission (verdict: Runtime Error):
from math import gcd
a,b=map(int,input().split())
n=gcd(a,b)

#素数
def primes(n):
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1, int(n**0.5)//3+1):
        if sieve[i]:
            k = 3*i+1|1
            sieve[k*k//3::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
            sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2, 3] + [3*i+1|1 for i in range(1, n//3-correction) if sieve[i]]

#素因数分解
from collections import defaultdict
primelist=primes(int(n**0.5+1))+[n+1]
factors=defaultdict(lambda :0)
for prime in primelist:
    if prime>n:
        factors[n]+=1
        break
    while n%prime==0:
        n=n//prime
        factors[prime]+=1
factors[n]=1
print(len(factors))

Fixed submission:
from fractions import gcd
a,b=map(int,input().split())
n=gcd(a,b)

#素数
def primes(n):
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1, int(n**0.5)//3+1):
        if sieve[i]:
            k = 3*i+1|1
            sieve[k*k//3::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
            sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2, 3] + [3*i+1|1 for i in range(1, n//3-correction) if sieve[i]]

#素因数分解
from collections import defaultdict
primelist=primes(int(n**0.5+1))+[n+1]
factors=defaultdict(lambda :0)
for prime in primelist:
    if prime>n:
        factors[n]+=1
        break
    while n%prime==0:
        n=n//prime
        factors[prime]+=1
factors[n]=1
factors[1]=0
print(len(factors))

Buggy python submission (verdict: Runtime Error):
from math import gcd
a,b=map(int,input().split())
n=gcd(a,b)

#素数
def primes(n):
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1, int(n**0.5)//3+1):
        if sieve[i]:
            k = 3*i+1|1
            sieve[k*k//3::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
            sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2, 3] + [3*i+1|1 for i in range(1, n//3-correction) if sieve[i]]

#素因数分解
from collections import defaultdict
primelist=primes(int(n**0.5+1))+[n+1]
factors=defaultdict(lambda :0)
for prime in primelist:
    if prime>n:
        factors[n]+=1
        break
    while n%prime==0:
        n=n//prime
        factors[prime]+=1
print(len(factors))

Fixed submission:
from fractions import gcd
a,b=map(int,input().split())
n=gcd(a,b)

#素数
def primes(n):
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1, int(n**0.5)//3+1):
        if sieve[i]:
            k = 3*i+1|1
            sieve[k*k//3::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
            sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2, 3] + [3*i+1|1 for i in range(1, n//3-correction) if sieve[i]]

#素因数分解
from collections import defaultdict
primelist=primes(int(n**0.5+1))+[n+1]
factors=defaultdict(lambda :0)
for prime in primelist:
    if prime>n:
        factors[n]+=1
        break
    while n%prime==0:
        n=n//prime
        factors[prime]+=1
factors[n]=1
factors[1]=0
print(len(factors))
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
A=list(map(int,input().split()))

last=[-1]*(2*10**5+1)
nex=[-1]*n
prog=[0]*n

for i,a in enumerate(A*2):
    l=last[a]
    last[a]=i%n
    if nex[l]==-1 and l!=-1:
        nex[l]=(i+1)%n
        if i>=n or i+1==n:
            prog[l]=1
if nex[-1]==0:
    prog[-1]+=1

flag=False #いっぱいループ済か
stage=0
now=0
roop=[-1]*n
while True:
    if roop[now]!=-1 and flag==False:
        flag=True
        rr=stage-roop[now]
        stage=k-1-(k-1-stage)%rr
    if stage+prog[now]==k:
        break
    roop[now]=stage
    stage+=prog[now]
    now=nex[now]

A=A[now:]+A if k-1-stage else A[now:]
check=[0]*(2*10**5+1)
stack=[]
for a in A:
    if check[a]:
        while check[a]:
            check[stack.pop()]=0
        continue
    stack.append(a)
    check[a]=1

print(*stack)

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

last=[-1]*(2*10**5+1)
nex=[-1]*n
prog=[0]*n

for i,a in enumerate(A*2):
    l=last[a]
    last[a]=i%n
    if nex[l]==-1 and l!=-1:
        nex[l]=(i+1)%n
        if i>=n or i+1==n:
            prog[l]=1
if nex[-1]==0:
    prog[-1]+=1

flag=False #いっぱいループ済か
stage=0
now=0
roop=[-1]*n
while True:
    if roop[now]!=-1 and flag==False:
        flag=True
        rr=stage-roop[now]
        stage=k-1-(k-1-stage)%rr
    if stage+prog[now]>=k:
        break
    roop[now]=stage
    stage+=prog[now]
    now=nex[now]

A=A[now:]+A if k-1-stage else A[now:]
check=[0]*(2*10**5+1)
stack=[]
for a in A:
    if check[a]:
        while check[a]:
            check[stack.pop()]=0
        continue
    stack.append(a)
    check[a]=1

print(*stack)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())

flag=list(range(N))
def takeflag(p):
    stock=[]
    while flag[flag[p]]!=flag[p]:
        stock.append(p)
        p=flag[p]
    p=flag[p]
    for i in stock:
        flag[i]=p
    return p

for i in range(M):
    x,y,z = map(int,input().split())
    x,y = map(takeflag,(x,y))
    x,y = min(x,y),max(x,y)
    flag[x]=y

st=set()
for i in range(N):
    st.add(takeflag(i))

print(len(st))

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

flag=list(range(N))
def takeflag(p):
    stock=[]
    while flag[flag[p]]!=flag[p]:
        stock.append(p)
        p=flag[p]
    p=flag[p]
    for i in stock:
        flag[i]=p
    return p

for i in range(M):
    x,y,z = map(int,input().split())
    x,y=x-1,y-1
    x,y = map(takeflag,(x,y))
    x,y = min(x,y),max(x,y)
    flag[x]=y

st=set()
for i in range(N):
    st.add(takeflag(i))

print(len(st))
Buggy python submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))

L,R=[0]*n,[0]*n
L[0],R[-1]=A[0],A[-1]

from math import gcd

for i in range(1,n):
    L[i]=gcd(A[i],L[i-1])
for i in range(n-2,-1,-1):
    R[i]=gcd(A[i],R[i+1])

ans=max([L[-2],R[1]]+[gcd(L[i-1],R[i+1])for i in range(1,n-1)])
print(ans)

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

L,R=[0]*n,[0]*n
L[0],R[-1]=A[0],A[-1]

from fractions import gcd

for i in range(1,n):
    L[i]=gcd(A[i],L[i-1])
for i in range(n-2,-1,-1):
    R[i]=gcd(A[i],R[i+1])

ans=max([L[-2],R[1]]+[gcd(L[i-1],R[i+1])for i in range(1,n-1)])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=[int(i) for i in input().split()]
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    dp[i]=min([abs(h[j]-h[i])+dp[j] for j in range(max(0,i-k),i)])
print(dp[-1])

Fixed submission:
n,k=map(int,input().split())
h=[int(i) for i in input().split()]
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    dp[i]=min([abs(h[j]-h[i])+dp[j] for j in range(max(0,i-k),i)])
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
n,w=map(int,input().split())
wv=[[int(i) for i in input().split()]for _ in range(n)]

dp=[0]*(w+1)
dp[wv[0][0]]=wv[0][1]
for i in range(1,n):
    ww = wv[i][0]
    v = wv[i][1]
    for j in range(w,ww-1,-1):
        dp[j]=max(dp[j],dp[j-ww]+v)
print(max(dp))

Fixed submission:
n,W=map(int,input().split())
wv=[[int(i) for i in input().split()]for _ in range(n)]
dp=[W+1]*(10**5+1)
dp[0]=0
for i in range(0,n):
    w,v = wv[i]
    for j in range(10**5,v-1,-1):
        dp[j]=min(dp[j],dp[j-v]+w)
for i in range(10**5,-1,-1):
    if dp[i]<=W:
        print(i)
        break
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=[0]*3
for i in map(int,input().split()):
    A[i-1]+=1
dp=[[[0]*(n+2)for _ in range(n+2)]for __ in range(n+2)]
for i in range(n+1):
    for j in range(n+1):
        for k in range(n+1):
            if i+j+k!=0:
                dp[i][j][k]=(dp[i-1][j+1][k]*i+dp[i][j-1][k+1]*j+dp[i][j][k-1]*k+n)/(i+j+k)
i,j,k=A
print(dp[k][j][i])

Fixed submission:
n=int(input())
A=[0]*3
for i in map(int,input().split()):
    A[i-1]+=1
dp=[[[0]*(n+2)for _ in range(n+2)]for __ in range(n+2)]
for i in range(A[2]+1):
    for j in range(n-A[0]-i+1):
        for k in range(n-i-j+1):
            if i+j+k!=0:
                dp[i][j][k]=(dp[i-1][j+1][k]*i+dp[i][j-1][k+1]*j+dp[i][j][k-1]*k+n)/(i+j+k)
i,j,k=A
print(dp[k][j][i])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**5)

def main():
    n=int(input())
    nodes=[[]for _ in range(n)]
    mod=10**9+7

    for _ in range(n-1):
        x,y=map(int,input().split())
        nodes[x-1].append(y-1)
        nodes[y-1].append(x-1)

    def pick(n,excep=-1):
        white=1
        black=1
        for node in nodes[n]:
            if excep==node:
                continue
            p=pick(node,n)
            white=(white*(p[0]+p[1]))%mod
            black=(black*p[0])%mod
        return [white,black]
    p=pick(0)
    print(sum(p)%mod)
main()


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

def main():
    n=int(input())
    nodes=[[]for _ in range(n)]
    mod=10**9+7

    for _ in range(n-1):
        x,y=map(int,input().split())
        nodes[x-1].append(y-1)
        nodes[y-1].append(x-1)

    def pick(n,excep=-1):
        white=1
        black=1
        for node in nodes[n]:
            if excep==node:
                continue
            p=pick(node,n)
            white=(white*(p[0]+p[1]))%mod
            black=(black*p[0])%mod
        return [white,black]
    p=pick(0)
    print(sum(p)%mod)
main()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=[list(map(int,input().split()))for _ in range(n)]
S=[0]*(1<<n)
for i in range(1<<n):
	for j in range(n):
		if i&(1<<j):
			for k in range(j):
				if i&(1<<k):
					S[i]+=A[j][k]
dp=[-10**9]*(1<<n)
dp[0]=0
for i in range(1,1<<n):
	j=i
	b=i.bit_length()
	while j.bit_length()==b:
		dp[i]=max(dp[i],S[j]+dp[i-j])
	j=i&(j-1)
print(dp[-1])

Fixed submission:
n=int(input())
A=[list(map(int,input().split()))for _ in range(n)]

S=[0]*(1<<n)
for i in range(1<<n):
    for j in range(n):
        if i&(1<<j):
            for k in range(n):
                if i&(1<<k):
                    S[i]+=A[j][k]
dp=[-10**9]*(1<<n)
dp[0]=0
for i in range(1,1<<n):
    j=i
    b=i.bit_length()
    while j.bit_length()==b:
        dp[i]=max(dp[i],S[j]+dp[i-j])
        j=i&(j-1)
print(dp[-1]//2)
Buggy python submission (verdict: Runtime Error):
n,m,q = [int(i) for i in input().split()]
lr = [[int(x)-1 for x in input().split()] for i in range(m)]
pq = [[int(x)-1 for x in input().split()] for i in range(q)]
m = [[0]*500 for _ in range(500)]
for l,r in lr:
    m[0][r]+=1
    m[l+1][r]-=1
for i in range(500):
    for j in range(1,500):
        m[j][i]+=m[j-1][i]
for i in range(500):
    for j in range(1,500):
        m[i][j]+=m[i][j-1]
for p,q in pq:
    print(m[p][q])

Fixed submission:
n,m,q = [int(i) for i in input().split()]
lr = [[int(x)-1 for x in input().split()] for i in range(m)]
pq = [[int(x)-1 for x in input().split()] for i in range(q)]
m = [[0]*501 for _ in range(501)]
for l,r in lr:
    m[0][r]+=1
    m[l+1][r]-=1
for i in range(500):
    for j in range(1,500):
        m[j][i]+=m[j-1][i]
for i in range(500):
    for j in range(1,500):
        m[i][j]+=m[i][j-1]
for p,q in pq:
    print(m[p][q])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())
x=[int(i)for i in input().split()]
x=[np.array([(X>>i)&1 for i in range(20)])for X in x]

bit = 0
j=0
ans = 0

for i in range(n):
    bit += x[i]    
    while True:
        flag=False
        for b in bit:
            if b > 1:
                flag=True
                break
        if flag==True:
            bit -= x[j]
            j+=1
            continue
        else:
            break
    ans += i-j+1
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans=1
tmp = a[0]
l=0
for i in range(1,n):
    x = a[i]
    while tmp^x != tmp+x:
        tmp-=a[l]
        l+=1
    ans+=i-l+1
    tmp+=x
print(ans)