Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S=input()
d=deque(S)
rev=False
Q=int(input())
for i in range(Q):
    Que=input().split()
    if(Que[0]=='1'):
        rev=not rev
    else:
        if(Que[1]=='1'):
            if(not rev):
                d.appendleft(Que[2])
            else:
                d.append(Que[2])
        else:
            if(not rev):
                d.append(Que[2])
            else:
                d.appendleft(Que[2])
if(not rev):
    for i in range(len(d)):
        print(d[i],end='')
else:
    for i in reversed(range(len(d))):
        print(d[i],end='')

Fixed submission:
from collections import deque
S=input()
d=deque(S)
rev=False
Q=int(input())
for i in range(Q):
    Que=input()
    if(Que=='1'):
        rev=True if not rev else False
    else:
        T,F,C=map(str,Que.split())
        if(F=='1'):
            if(not rev):
                d.appendleft(C)
            else:
                d.append(C)
        elif(F=='2'):
            if(not rev):
                d.append(C)
            else:
                d.appendleft(C)
if(not rev):
    for i in range(len(d)):
        print(d[i],end='')
else:
    for i in reversed(range(len(d))):
        print(d[i],end='')

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S=input()
d=deque(S)
rev=False
Q=int(input())
for i in range(Q):
    Que=input()
    if(Que=='1'):
        rev=True if not rev else False
    else:
        T,F,C=map(str,Que.split())
        if(F=='1'):
            if(not rev):
                d.appendleft(C)
            else:
                d.append(C)
        elif(F=='2'):
            if(not rev):
                d.append(C)
            else:
                d.appendleft(C)
if(not rev):
    for i in range(len(d)):
        print(d[i],end='')
else:
    for i in reversed(range(len(d))):
        print(d[i],end='')

Fixed submission:
from collections import deque
S=input()
d=deque(S)
rev=False
Q=int(input())
for i in range(Q):
    Que=input()
    if(Que=='1'):
        rev=True if not rev else False
    else:
        T,F,C=map(str,Que.split())
        if(F=='1'):
            if(not rev):
                d.appendleft(C)
            else:
                d.append(C)
        elif(F=='2'):
            if(not rev):
                d.append(C)
            else:
                d.appendleft(C)
if(not rev):
    for i in range(len(d)):
        print(d[i],end='')
else:
    for i in reversed(range(len(d))):
        print(d[i],end='')
Buggy python submission (verdict: Runtime Error):
from collections import deque
import collections
from collections import Counter
import bisect
import math
import fractions
import itertools
import scipy
import numpy
from scipy.special import comb

N=int(input())
if(N%2==1):
    print((N//2)+1)
else:
    print(N//2)

Fixed submission:
N=int(input())
if(N%2==1):
    print((N//2)+1)
else:
    print(N//2)
Buggy python submission (verdict: Time Limit Exceeded):
def initialize(N):
    i=1
    while i<N:
        i*=2
    return [0]*(2*i-1),i

def update(i,x):
    i+=d-1
    bit=ord(x)-97
    SEG[i]=0 | (1<<bit)
    while i>0:
        i=(i-1)//2
        SEG[i]=SEG[i*2+1]|SEG[i*2+2]
        
def find(a,b,k,l,r):
    if r<=a or b<=l:
        return 0
    if a<=l and r<=b:
        return SEG[k]
    else:
        c1=find(a,b,2*k+1,l,(l+r)//2)
        c2=find(a,b,2*k+2,(l+r)//2,r)
        return c1|c2
        
N=int(input())
S=input()
Q=int(input())

SEG,d=initialize(N)
for i in range(N):
    update(i,S[i])

for i in range(Q):
    com,s,t=map(str,input().split())
    if(com=='1'):
        update(int(s)-1,t)
    else:
        cnt=0
        bit=find(int(s)-1,int(t),0,0,d)
        while(bit>0):
            if(bit&1):
                cnt+=1
            bit//=2
        print(cnt)

Fixed submission:
def initialize(N):
    i=1
    while i<N:
        i*=2
    return [0]*(2*i-1),i

def update(i,x):
    i+=d-1
    bit=ord(x)-97
    SEG[i]=0 | (1<<bit)
    while i>0:
        i=(i-1)//2
        SEG[i]=SEG[i*2+1]|SEG[i*2+2]
        
def find(a,b,k,l,r):
    if r<=a or b<=l:
        return 0
    if a<=l and r<=b:
        return SEG[k]
    else:
        c1=find(a,b,2*k+1,l,(l+r)//2)
        c2=find(a,b,2*k+2,(l+r)//2,r)
        return c1|c2
        
N=int(input())
S=input()
Q=int(input())

SEG,d=initialize(N)
for i in range(N):
    update(i,S[i])

for i in range(Q):
    com,s,t=map(str,input().split())
    if(com=='1'):
        update(int(s)-1,t)
    else:
        cnt=0
        bit=find(int(s)-1,int(t),0,0,d)
        while(bit>0):
            if(bit&1):
                cnt+=1
            bit//=2
        print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
MOD=10**9+7
def facinv(N):
    fac,finv,inv=[0]*(N+1),[0]*(N+1),[0]*(N+1)
    fac[0]=1;fac[1]=1;finv[0]=1;finv[1]=1;inv[1]=1
    for i in range(2,N+1):
        fac[i]=fac[i-1]*i%MOD
        inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
        finv[i]=finv[i-1]*inv[i]%MOD
    return fac,finv,inv

def COM(n,r):
    if n<r or r<0:
        return 0
    else:
        return ((fac[n]*finv[r])%MOD*finv[n-r])%MOD
        
r1,c1,r2,c2=map(int,input().split())

fac,finv,inv=facinv(r2+c2+1)

ans=0

for i in range(r1,r2+1):
    ans=(ans+COM(c2+i+1,i+1)-COM(c1+i,i+1)+MOD)%MOD
print(ans)

Fixed submission:
MOD=10**9+7
def facinv(N):
    fac,finv,inv=[0]*(N+1),[0]*(N+1),[0]*(N+1)
    fac[0]=1;fac[1]=1;finv[0]=1;finv[1]=1;inv[1]=1
    for i in range(2,N+1):
        fac[i]=fac[i-1]*i%MOD
        inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
        finv[i]=finv[i-1]*inv[i]%MOD
    return fac,finv,inv

def COM(n,r):
    if n<r or r<0:
        return 0
    else:
        return ((fac[n]*finv[r])%MOD*finv[n-r])%MOD
        
r1,c1,r2,c2=map(int,input().split())

fac,finv,inv=facinv(r2+c2+1)

ans=0

for i in range(r1,r2+1):
    ans=(ans+COM(c2+i+1,i+1)-COM(c1+i,i+1)+MOD)%MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
INF=10**30
H,N=map(int,input().split())
A,B=[],[]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a);B.append(b)
dp=[INF]*(H+10)
dp[0]=0
for i in range(N):
    for j in range(H+1):
        if(j<A[i]):
            dp[j]=min(dp[j],dp[0]+B[i])
        else:
            dp[j]=min(dp[j],dp[j-A[i]]+B[i])
print(dp[H])

Fixed submission:
INF=10**30
H,N=map(int,input().split())
A,B=[],[]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a);B.append(b)
dp=[[INF]*(H+10) for i in range(N+1)]
dp[0][0]=0
for i in range(N):
    for j in range(H+1):
        if(j<A[i]):
            dp[i+1][j]=min(dp[i][j],dp[i][0]+B[i])
        else:
            dp[i+1][j]=min(dp[i][j],dp[i+1][j-A[i]]+B[i])
print(dp[N][H])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
def justM(x,N):
    sum_=0
    for i in range(N):
        b=bisect.bisect_left(A,x-A[i])
        sum_+=N-b
    return sum_

N,M=map(int,input().split())
A=sorted(map(int,input().split()))
left,right=-1,10**20
while(right-left>1):
    mid=(right+left)//2
    s=justM(mid,N)
    if s<M:
        right=mid
    else:
        left=mid
D=left
r=[0]*(N+1)
ans=0
for i in range(N):
    r[i+1]=r[i]+A[i]
cnt=0
for i in range(N):
    b=bisect.bisect_left(A,D-A[i])
    ans+=A[i]*(N-b)
    cnt+=N-b
    ans+=r[N]-r[b]
print(ans-D*(cnt-M))


Fixed submission:
import bisect
def justM(x,N):
    sum_=0
    for i in range(N):
        b=bisect.bisect_left(A,x-A[i])
        sum_+=N-b
    return sum_

N,M=map(int,input().split())
A=sorted(map(int,input().split()))
left,right=-1,(10**5)*2+1
while(right-left>1):
    mid=(right+left)//2
    s=justM(mid,N)
    if s<M:
        right=mid
    else:
        left=mid
D=left
r=[0]*(N+1)
ans=0
for i in range(N):
    r[i+1]=r[i]+A[i]
cnt=0
for i in range(N):
    b=bisect.bisect_left(A,D-A[i])
    ans+=A[i]*(N-b)+(r[N]-r[b])
    cnt+=N-b
print(ans-D*(cnt-M))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
def justM(x,N):
    sum_=0
    for i in range(N):
        b=bisect.bisect_left(A,x-A[i])
        sum_+=N-b
    return sum_

N,M=map(int,input().split())
A=sorted(map(int,input().split()))
left,right=-1,10**20
while(right-left>1):
    mid=(right+left)//2
    s=justM(mid,N)
    if s<M:
        right=mid
    else:
        left=mid
D=left
r=[0]*(N+1)
ans=0
for i in range(N):
    r[i+1]=r[i]+A[i]
cnt=0
for i in range(N):
    b=bisect.bisect_left(A,D-A[i])
    ans+=A[i]*(N-b)
    cnt+=N-b
    ans+=r[N]-r[b]
print(ans-D*(cnt-M))

Fixed submission:
import bisect
def justM(x,N):
    sum_=0
    for i in range(N):
        b=bisect.bisect_left(A,x-A[i])
        sum_+=N-b
    return sum_

N,M=map(int,input().split())
A=sorted(map(int,input().split()))
left,right=-1,(10**5)*2+1
while(right-left>1):
    mid=(right+left)//2
    s=justM(mid,N)
    if s<M:
        right=mid
    else:
        left=mid
D=left
r=[0]*(N+1)
ans=0
for i in range(N):
    r[i+1]=r[i]+A[i]
cnt=0
for i in range(N):
    b=bisect.bisect_left(A,D-A[i])
    ans+=A[i]*(N-b)+(r[N]-r[b])
    cnt+=N-b
print(ans-D*(cnt-M))
Buggy python submission (verdict: Runtime Error):
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
bit=[[0]*60 for i in range(N+1)]
for i in range(1,N+1):
    for j in range(60):
        if(A[i-1]>>j&1):
            bit[i][j]=bit[i-1][j]+1
        else:
            bit[i][j]=bit[i-1][j]
res=0
for i in range(N):
    for j in range(60):
        if not (A[i]>>j&1):
            res=(res+(2**j)*bit[i][j])%MOD
        else:
            res=(res+(2**j)*(i-bit[i][j]))%MOD
print(res)

Fixed submission:
A=list(map(int,input().split()))
if(sum(A)>21):
    print("bust")
else:
    print("win")
Buggy python submission (verdict: Time Limit Exceeded):
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
res=0
bit=[0]*60
for i in range(1,N+1):
    for j in range(60):
        if(A[i-1]>>j&1):
            bit[j]+=1
            res=(res+(2**j)*(i-bit[j]))%MOD
        else:
            res=(res+(2**j)*bit[j])%MOD
print(res)

Fixed submission:
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
ans=0
for j in range(60):
    k=2**j
    count=0
    for i in range(N):
        if(A[i]&k):
            ans=(ans+(2**j)*(i-count))%MOD
            count+=1
        else:
            ans=(ans+(2**j)*count)%MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
res=0
bit=[[0]*60 for i in range(N+1)]
for i in range(1,N+1):
    for j in range(60):
        if(A[i-1]>>j&1):
            bit[i][j]=bit[i-1][j]+1
            res=(res+(2**j)*(i-bit[i][j]))%MOD
        else:
            bit[i][j]=bit[i-1][j]
            res=(res+(2**j)*bit[i][j])%MOD
print(res)

Fixed submission:
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
ans=0
for j in range(60):
    k=2**j
    count=0
    for i in range(N):
        if(A[i]&k):
            ans=(ans+(2**j)*(i-count))%MOD
            count+=1
        else:
            ans=(ans+(2**j)*count)%MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
bit=[[0]*60 for i in range(N+1)]
for i in range(1,N+1):
    for j in range(60):
        if(A[i-1]>>j&1):
            bit[i][j]=bit[i-1][j]+1
        else:
            bit[i][j]=bit[i-1][j]
res=0
for i in range(N):
    for j in range(60):
        if not (A[i]>>j&1):
            res=(res+(2**j)*bit[i][j])%MOD
        else:
            res=(res+(2**j)*(i-bit[i][j]))%MOD
print(res)

Fixed submission:
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
ans=0
for j in range(60):
    k=2**j
    count=0
    for i in range(N):
        if(A[i]&k):
            ans=(ans+(2**j)*(i-count))%MOD
            count+=1
        else:
            ans=(ans+(2**j)*count)%MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
bit=[[0]*60 for i in range(N+1)]
for i in range(1,N+1):
    for j in range(60):
        if(A[i-1]>>j&1):
            bit[i][j]=bit[i-1][j]+1
        else:
            bit[i][j]=bit[i-1][j]
res=0
for i in range(N):
    for j in range(60):
        if not (A[i]>>j&1):
            res=(res+(2**j)*bit[i][j])%MOD
        else:
            res=(res+(2**j)*(i-bit[i][j]))%MOD
print(res)

Fixed submission:
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
ans=0
for j in range(60):
    k=2**j
    count=0
    for i in range(N):
        if(A[i]&k):
            ans=(ans+(2**j)*(i-count))%MOD
            count+=1
        else:
            ans=(ans+(2**j)*count)%MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]
for i in range(H):
    B=list(map(int,input().split()))
    for j in range(W):
        A[i][j]=abs(A[i][j]-B[j])
dp=[[set() for i in range(W)] for i in range(H)]
dp[0][0].add(A[0][0])
for i in range(H):
    for j in range(W):
        for nx,ny in [(i+1,j),(i,j+1)]:
            if nx>=H or ny>=W:
                continue
            for k in dp[i][j]:
                p=k+A[nx][ny]
                m=abs(k-A[nx][ny])
                dp[nx][ny].add(p)
                dp[nx][ny].add(m)
ans=10**18
for k in dp[H-1][W-1]:
    ans=min(ans,k)
print(ans)

Fixed submission:
H,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]
for i in range(H):
    B=list(map(int,input().split()))
    for j in range(W):
        A[i][j]=abs(A[i][j]-B[j])
D=80*(H+W)+1
D2=D*2
dp=[[0]*W for i in range(H)]
dp[0][0]|=1<<(D+A[0][0])
dp[0][0]|=1<<(D-A[0][0])
for i in range(H):
    for j in range(W):
        if i:
            dp[i][j]|=dp[i-1][j]<<A[i][j]
            dp[i][j]|=dp[i-1][j]>>A[i][j]
        if j:
            dp[i][j]|=dp[i][j-1]<<A[i][j]
            dp[i][j]|=dp[i][j-1]>>A[i][j]
res=dp[-1][-1]
ans=10**18
for i in range(D2):
    if res>>i&1:
        ans=min(ans,abs(D-i))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
INF=10**18
H,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]
for i in range(H):
    B=list(map(int,input().split()))
    for j in range(W):
        A[i][j]=abs(A[i][j]-B[j])

dp=[[[False]*(80*H*W-1) for i in range(W)] for i in range(H)]
dp[0][0][A[0][0]]=True
for i in range(H):
    for j in range(W):
        for x,y in [(0,1),(1,0)]:
            nx,ny=i+x,j+y
            if nx>=H or ny>=W:
                continue
            for x in range(81):
                if dp[i][j][x]:
                    if x+A[nx][ny]<=80:
                        dp[nx][ny][x+A[nx][ny]]=True
                        dp[nx][ny][abs(x-A[nx][ny])]=True
for x in range(81):
    if dp[i][j][x]:
        print(x)
        exit()

Fixed submission:
H,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]
for i in range(H):
    B=list(map(int,input().split()))
    for j in range(W):
        A[i][j]=abs(A[i][j]-B[j])
D=80*(H+W)+1
D2=D*2
dp=[[0]*W for i in range(H)]
dp[0][0]|=1<<(D+A[0][0])
dp[0][0]|=1<<(D-A[0][0])
for i in range(H):
    for j in range(W):
        if i:
            dp[i][j]|=dp[i-1][j]<<A[i][j]
            dp[i][j]|=dp[i-1][j]>>A[i][j]
        if j:
            dp[i][j]|=dp[i][j-1]<<A[i][j]
            dp[i][j]|=dp[i][j-1]>>A[i][j]
res=dp[-1][-1]
ans=10**18
for i in range(D2):
    if res>>i&1:
        ans=min(ans,abs(D-i))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,T=map(int,input().split())
A,B=[],[]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a);B.append(b)
dp=[[[0,0] for i in range(T)] for i in range(N+1)]

for i in range(N):
    for j in range(T):
        if j-A[i]>=0:
            dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j-A[i]][0]+B[i])
            dp[i+1][j][1]=max(dp[i+1][j][1],dp[i][j-A[i]][1]+B[i])
        dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][0])
        dp[i+1][j][1]=max([dp[i+1][j][1],dp[i][j][0]+B[i],dp[i][j][1]])
ans=max(dp[N][T-1][0],dp[N][T-1][1])
print(ans)

Fixed submission:
N,T=map(int,input().split())
A,B=[],[]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a);B.append(b)
dp=[[0,0] for i in range(T)]

for i in range(N):
    for j in reversed(range(T)):
        dp[j][1]=max(dp[j][1],dp[j][0]+B[i])
        if j-A[i]>=0:
            dp[j][0]=max(dp[j-A[i]][0]+B[i],dp[j][0])
            dp[j][1]=max(dp[j-A[i]][1]+B[i],dp[j][1])
ans=max(dp[T-1][0],dp[T-1][1])
print(ans)
Buggy python submission (verdict: Runtime Error):
S=input()
li=[]
cnt=1
now=S[0]
for i in range(1,len(S)):
    if(S[i]==now):
        cnt+=1
        if(i==len(S)-1):
            li.append([now,cnt])
    else:
        li.append([now,cnt])
        now=S[i]
        cnt=1
        if(i==len(S)-1):
            li.append([now,cnt])
res=0
if(li[0][0]=='>'):
    res+=li[0][1]
if(li[-1][0]=='<'):
    res+=li[-1][1]
for i in range(len(li)-1):
    if(li[i][0]=='<' and li[i+1][0]=='>'):
        max_=max(li[i][1],li[i+1][1])
        min_=min(li[i][1],li[i+1][1])
        res+=((max_+1)*max_)//2
        res+=((min_)*(min_-1))//2
print(res)

Fixed submission:
S=input()
n=len(S)
A=[0]*(n+1)
for i in range(n):
    if(S[i]=='<'):
        A[i+1]=A[i]+1
for i in reversed(range(n)):
    if(S[i]=='>'):
        A[i]=max(A[i],A[i+1]+1)
print(sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N=int(input())
L=sorted(map(int,input().split()))
cnt=0
for i in range(N):
    for j in range(i):
        a=L[i]
        b=L[j]
        right=a+b
        left=abs(a-b)
        res=bisect.bisect_left(L,right)-bisect.bisect_right(L,left)
        if(left<a<right):
            res-=1
        if(left<b<right):
            res-=1
        cnt+=res
print(cnt//3)


Fixed submission:
import bisect
N=int(input())
L=sorted(map(int,input().split()))
cnt=0
for i in range(N):
    for j in range(i):
        a=L[i]
        b=L[j]
        right=a+b
        left=abs(a-b)
        rind=bisect.bisect_left(L,right)
        lind=bisect.bisect_right(L,left)
        res=rind-lind
        if(left<a<right):
            res-=1
        if(left<b<right):
            res-=1
        cnt+=res
print(cnt//3)
Buggy python submission (verdict: Runtime Error):
import math
def factorization(n):
    arr=[]
    tmp=n
    for i in range(2,int(n**0.5)+1):
        if(tmp%i==0):
            cnt=0
            while tmp%i==0:
                cnt+=1
                tmp//=i
            arr.append([i,cnt])
    arr.append([1,1])
    if(tmp!=1):
        arr.append([tmp,1])
    return arr
A,B=map(int,input().split())
g=math.gcd(A,B)
li=factorization(g)
print(len(li))

Fixed submission:
import fractions
def factorization(n):
    arr=[]
    tmp=n
    for i in range(2,int(n**0.5)+1):
        if(tmp%i==0):
            cnt=0
            while tmp%i==0:
                cnt+=1
                tmp//=i
            arr.append([i,cnt])
    arr.append([1,1])
    if(tmp!=1):
        arr.append([tmp,1])
    return arr
A,B=map(int,input().split())
g=fractions.gcd(A,B)
li=factorization(g)
print(len(li))
Buggy python submission (verdict: Time Limit Exceeded):
INF=10**18
N,M=map(int,input().split())

a,c=[],[]
for i in range(M):
    A,B=map(int,input().split())  
    C=list(map(int,input().split()))
    tmp=0
    for j in range(B):
      tmp+=1<<(C[j]-1)
    a.append(A)
    c.append(tmp)
    
dp=[[INF]*(1<<N) for i in range(M+1)]
dp[0][0]=0
for i in range(M):
    for j in range(1<<N):
        dp[i+1][j]=min(dp[i+1][j],dp[i][j])
        o=(j | c[i])
        dp[i+1][o]=min(dp[i+1][o],dp[i][j]+a[i])
ans=dp[M][2**N-1]
print(ans if ans!=INF else -1)

Fixed submission:
INF=10**18
N,M=map(int,input().split())

a,c=[],[]
for i in range(M):
    A,B=map(int,input().split())  
    C=list(map(int,input().split()))
    tmp=0
    for j in range(B):
      tmp+=1<<(C[j]-1)
    a.append(A)
    c.append(tmp)
    
dp=[[INF]*(1<<N) for i in range(M+1)]
dp[0][0]=0
for i in range(M):
    for j in range(1<<N):
        dp[i+1][j]=min(dp[i+1][j],dp[i][j])
        o=(j | c[i])
        dp[i+1][o]=min(dp[i+1][o],dp[i][j]+a[i])
ans=dp[M][2**N-1]
print(ans if ans!=INF else -1)
Buggy python submission (verdict: Runtime Error):
class RollingHash:
    def __init__(self,S,base,M):
        self.N=len(S)
        self.M=M
        self.H=[0]*(self.N+1)
        self.B=[0]*(self.N+1)
        self.B[0]=1
        for i in range(self.N):
            self.B[i+1]=self.B[i]*base%M
            self.H[i+1]=(self.H[i]*base+(ord(S[i])-96))%M
    def get(self,l,r):
        return (self.H[r]-self.H[l]*self.B[r-l]+self.M)%self.M
    def getall(self,L):
        arr=[]
        for i in range(L,self.N+1):
            arr.append(self.get(i-L,i))
        return arr

def Hash(S,base,M):
    H=0
    for c in S:
        H=(H*base+ord(c)-96)%M
    return H
    
def isbad(L):
    arr=RH.getall(L)
    s=set()
    for i in range(L,N-L+1):
        s.add(arr[i-L])
        if arr[i] in s:
            return False
    return True
    
import random
N=int(input())
S=input()
MOD=2**61-1
base=random.randrange(100,MOD)
RH=RollingHash(S,base,MOD)
l,r=-1,N+1
while(r-l>1):
    mid=(l+r)//2
    if isbad(mid):
        r=mid
    else:
        l=mid
print(l)

Fixed submission:
S=input()
print('Sunny' if S=='Rainy' else 'Cloudy' if S=='Sunny' else 'Rainy')
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
def dfs(G,v,p):
    for nv in G[v]:
        if(nv==p):
            continue
        point[nv]+=point[v]
        dfs(G,nv,v)

N,Q=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
point=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    point[p-1]+=x
dfs(G,0,-1)
print(*point)

Fixed submission:
a=int(input())
s=input()
if(a>=3200):
    print(s)
else:
    print("red")
Buggy python submission (verdict: Time Limit Exceeded):
MOD=10**9+7

S=input()
S=S[::-1]
N=len(S)

def POWt(N):
    arr=[1]
    for i in range(1,N+1):
        arr.append(arr[-1]*10%13)
    return arr

dp=[[0]*13 for i in range(N+1)]
dp[0][0]=1
POW=POWt(N)
for i in range(N):
    for j in range(13):
        if(S[i]!='?'):
            dp[i+1][(j+(int(S[i])*POW[i]%13))%13]=(dp[i+1][(j+(int(S[i])*POW[i])%13)%13]+dp[i][j])%MOD
        else:
            for k in range(10):
                dp[i+1][(j+k*POW[i]%13)%13]=(dp[i+1][(j+k*POW[i]%13)%13]+dp[i][j])%MOD
print(dp[N][5])

Fixed submission:
MOD=10**9+7

S=input()
S=S[::-1]
N=len(S)

def POWt(N):
    arr=[1]
    for i in range(1,N+1):
        arr.append(arr[-1]*10%13)
    return arr

dp=[[0]*13 for i in range(N+1)]
dp[0][0]=1
POW=POWt(N)
for i in range(N):
    for j in range(13):
        if(S[i]!='?'):
            dp[i+1][(j+(int(S[i])*POW[i]%13))%13]=(dp[i+1][(j+(int(S[i])*POW[i])%13)%13]+dp[i][j])%MOD
        else:
            for k in range(10):
                dp[i+1][(j+k*POW[i]%13)%13]=(dp[i+1][(j+k*POW[i]%13)%13]+dp[i][j])%MOD
print(dp[N][5])
Buggy python submission (verdict: Time Limit Exceeded):
def factor(N):
    arr=[]
    for i in range(1,int(N**0.5)+1):
        if(N%i==0):
            arr.append(i)
            if(N//i!=i):
                arr.append(N//i)
    return arr
N=int(input())
fac=[factor(i+1) for i in range(N)]
A=list(map(int,input().split()))
ball=[0]*N
res=[]
for i in reversed(range(N)):
    y=0
    if ball[i]!=A[i]:
        y=1
        ball[i]=(ball[i]+1)%2
        res.append(i+1)
        for k in fac[i]:
            ball[k-1]=(ball[k-1]+1)%2
print(len(res))
print(*res,sep=' ')

Fixed submission:
def factor(N):
    arr=[]
    for i in range(1,int(N**0.5)+1):
        if(N%i==0):
            arr.append(i)
            if(N//i!=i):
                arr.append(N//i)
    return arr
N=int(input())
fac=[factor(i+1) for i in range(N)]
A=list(map(int,input().split()))
ball=[0]*N
res=[]
for i in reversed(range(N)):
    y=0
    if ball[i]!=A[i]:
        y=1
        ball[i]=(ball[i]+1)%2
        res.append(i+1)
        for k in fac[i]:
            ball[k-1]=(ball[k-1]+1)%2
print(len(res))
print(*res,sep=' ')