Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))
idx=dict()
mod=10**9+7
for i in range(1+n):
    if A[i] in idx:
        x=idx[A[i]]
        y=i
        break
    idx[A[i]]=i
gawa=n-1-(y-x-1)
zentai=n-1
gawa_conb=[1]
for i in range(1,1+gawa):
    if i<1+gawa//2:
        gawa_conb.append(gawa_conb[-1]*(gawa-i+1)//i)
    else:
        gawa_conb.append(gawa_conb[gawa-i])
gawa_conb+=[0]*(zentai-gawa)
zentai_conb=[1]
for i in range(1,1+zentai):
    if i<1+zentai//2:
        zentai_conb.append(zentai_conb[-1]*(zentai-i+1)//i)
    else:
        zentai_conb.append((zentai_conb[zentai-i]))
if n>1:
    print((zentai_conb[1]+zentai_conb[0]*2-gawa_conb[0])%mod)
    for i in range(2,n):
        print((zentai_conb[i-2]+zentai_conb[i]+zentai_conb[i-1]*2-gawa_conb[i-1])%mod)
    print((zentai_conb[n-2]+zentai_conb[n-1]*2-gawa_conb[n-1])%mod)
    print((zentai_conb[n-1])%mod)
else:
    print(1)
    print(1)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
idx=dict()
mod=10**9+7
for i in range(1+n):
    if A[i] in idx:
        x=idx[A[i]]
        y=i
        break
    idx[A[i]]=i
kaijo=[1]
for i in range(1,n+2):
    kaijo.append((kaijo[-1]*i)%mod)
gyaku=[pow(kaijo[n+1],mod-2,mod)]
from collections import deque
gyaku=deque(gyaku)
for i in range(n+1,0,-1):
    gyaku.appendleft((gyaku[0]*i)%mod)
gawa=n-1-(y-x-1)
zentai=n-1
gawa_conb=[1]
for i in range(1,1+gawa):
    if i<1+gawa//2:
        gawa_conb.append((kaijo[gawa]*gyaku[i]*gyaku[gawa-i])%mod)
    else:
        gawa_conb.append(gawa_conb[gawa-i])
gawa_conb+=[0]*(zentai-gawa)
zentai_conb=[1]
for i in range(1,1+zentai):
    if i<1+zentai//2:
        zentai_conb.append((kaijo[zentai]*gyaku[i]*gyaku[zentai-i])%mod)
    else:
        zentai_conb.append((zentai_conb[zentai-i]))
if n>1:
    print((zentai_conb[1]+zentai_conb[0]*2-gawa_conb[0])%mod)
    for i in range(2,n):
        print((zentai_conb[i-2]+zentai_conb[i]+zentai_conb[i-1]*2-gawa_conb[i-1])%mod)
    print((zentai_conb[n-2]+zentai_conb[n-1]*2-gawa_conb[n-1])%mod)
    print((zentai_conb[n-1])%mod)
else:
    print(1)
    print(1)
Buggy python submission (verdict: Runtime Error):
N=int(input())
city=[]
for i in range(N):
    x,y=map(int,input().split())
    city.append((i,x,y))
city.sort(key=lambda x:x[1])
data=[]
for i in range(N-1):
    data.append((city[i][0],city[i+1][0],city[i+1][1]-city[i][1]))
city.sort(key=lambda y:y[2])
for i in range(N-1):
    data.append((city[i][0],city[i+1][0],city[i+1][2]-city[i][2]))
data.sort(key=lambda d:d[2])
idx=[-1]*N
def find(idx,x):
    if idx[x]<0:
        return x
    elif idx[x]>=0:
        idx[x]=find(idx,idx[x])
        return idx[x]
ans=0
for q in range(len(data)):
    i,j,d=data[q]
    iidx=find(idx,i)
    jidx=find(idx,j)
    if iidx==jidx:
        continue
    elif idx[iidx]>=idx[jidx]:
        idx[iidx]+=idx[jidx]
        idx[jidx]=iidx
        ans+=d
    elif idx[iidx]<idx[jidx]:
        idx[jidx]+=idx[iidx]
        idx[iidx]=jidx
        ans+=d
print(ans)

Fixed submission:
N=int(input())
city=[]
for i in range(N):
    x,y=map(int,input().split())
    city.append((i,x,y))

data=[]
city.sort(key=lambda x:x[1])
for i in range(N-1):
    data.append((city[i][0],city[i+1][0],city[i+1][1]-city[i][1]))
city.sort(key=lambda y:y[2])
for i in range(N-1):
    data.append((city[i][0],city[i+1][0],city[i+1][2]-city[i][2]))
data.sort(key=lambda d:d[2])

idx=[-1]*N
def find(idx,x):
    if idx[x]<0:
        return x
    elif idx[x]>=0:
        idx[x]=find(idx,idx[x])
        return idx[x]

ans=0
for q in range(len(data)):
    i,j,d=data[q]
    iidx=find(idx,i)
    jidx=find(idx,j)
    if iidx==jidx:
        continue
    elif idx[iidx]<=idx[jidx]:
        idx[iidx]+=idx[jidx]
        idx[jidx]=iidx
        ans+=d
    elif idx[iidx]>idx[jidx]:
        idx[jidx]+=idx[iidx]
        idx[iidx]=jidx
        ans+=d
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
city=[0]*N
for i in range(N):
    x,y=map(int,input().split())
    city[i]=(i,x,y)
city.sort(key=lambda x:x[1])
data=[(city[i][0],city[i+1][0],city[i+1][1]-city[i][1]) for i in range(N-1)]
city.sort(key=lambda x:x[2])
data+=[(city[i][0],city[i+1][0],city[i+1][2]-city[i][2]) for i in range(N-1)]
data.sort(key=lambda x:x[2])
root=[-1]*N
def search(i):
    global root
    if root[i]>=0:
        root[i]=search(root[i])
        return root[i]
    return i
cost=0
for i,j,k in data:
    ri=search(i)
    rj=search(j)
    if ri==rj:
        continue
    elif root[ri]>=root[rj]:
        cost+=k
        root[ri]+=root[rj]
        root[rj]=ri
    elif root[ri]<root[rj]:
        cost+=k
        root[rj]+=root[ri]
        root[ri]=rj
print(cost)

Fixed submission:
N=int(input())
city=[0]*N
for i in range(N):
    x,y=map(int,input().split())
    city[i]=(i,x,y)
city.sort(key=lambda x:x[1])
data=[(city[i][0],city[i+1][0],city[i+1][1]-city[i][1]) for i in range(N-1)]
city.sort(key=lambda x:x[2])
data+=[(city[i][0],city[i+1][0],city[i+1][2]-city[i][2]) for i in range(N-1)]
data.sort(key=lambda x:x[2])
root=[-1]*N
def search(i):
    global root
    if root[i]>=0:
        root[i]=search(root[i])
        return root[i]
    return i
cost=0
for i,j,k in data:
    ri=search(i)
    rj=search(j)
    if ri==rj:
        continue
    elif root[ri]<=root[rj]:
        cost+=k
        root[ri]+=root[rj]
        root[rj]=ri
    elif root[ri]>root[rj]:
        cost+=k
        root[rj]+=root[ri]
        root[ri]=rj
print(cost)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
from collections import defaultdict
data=defaultdict(int)
for n in range(N):
    a,b=map(int,input().split())
    data[a]+=b
now=0
for i in range(len(data)):
    idx=min(data.keys())
    now+=data[idx]
    if now>=K:
        print(idx)
        break
    data.pop(idx)

Fixed submission:
N,K=map(int,input().split())
from collections import defaultdict
data=[]
for n in range(N):
    data.append(tuple(map(int,input().split())))
data.sort(key=lambda x:x[0])
now=0
for i in range(len(data)):
    now+=data[i][1]
    if now>=K:
        print(data[i][0])
        break
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
if sum(A)%(N*(N+1)//2)!=0:
    print('NO')
    exit()
import numpy as np
from numpy.linalg import inv
D=np.array(([[1+(N+i-j)%N for j in range(N)] for i in range(N)]))
A=np.array(A)
X=np.dot(inv(D),A.T)
flag=True
m=10**(-8)
for x in X:
    xx=x
    if int(x)-m<=x<=int(x)+m:
        if int(x)>=0:
            continue
    elif int(x)+1-m<=x<=int(x)+1+m:
        if int(x)+1>=0:
            continue
    else:
        flag=False
        break
if flag:
    print('YES')
else:
    print('NO')

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
if sum(A)%(N*(N+1)//2)!=0:
    print('NO')
    exit()
ALL=sum(A)//(N*(N+1)//2)
X=[0]*N
if (A[N-1]-A[0]+ALL)%N!=0:
    print('NO')
    exit()
elif (A[N-1]-A[0]+ALL)//N<0:
    print('NO')
    exit()
for i in range(1,N):
    if (A[i-1]-A[i]+ALL)%N!=0:
        print('NO')
        exit()
    elif (A[i-1]-A[i]+ALL)//N<0:
        print('NO')
        exit()
print('YES')
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
if n%2==0:
    ans=0
    for i in range(n//2):
        if a.count(2*i+1)!=2:
            ans=1
            break
    if ans==1:print(0)
    elif ans==0:
        res=1
        for j in range(n//2):
            res=(res*2)%(10**9+7)
        print(res)
elif n%2==1:
    ans=0
    if a.count(0)!=1:ans=1
    for i in range(n//2):
        if ans==1:break
        if a.count(2*i+2)!=2:ans=1
    if ans==1:print(0)
    elif ans==0:
        res=1
        for j in range(n//2):
            res=(res*2)%(10**9+7)
        print(res)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
res=1
for i in range(n//2):
    res=(res*2)%(10**9+7)
from collections import defaultdict
data=defaultdict(int)
for i in a:
    data[i]+=1
ans=0
if n%2==0:
    for i in range(n//2):
        if data[2*i+1]!=2:
            ans=1
            break
elif n%2==1:
    for i in range(n//2):
        if data[2*i+2]!=2:
            ans=1
            break
if ans==1:print(0)
elif ans==0:print(res)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
def check(s):
    x=s[-3:]
    if x=='eam':
        if s[-5:]=='dream':
            return 'dream'
    elif x=='mer':
        if s[-7:]=='dreamer':
            return 'dreamer'
    elif x=='ase':
        if s[-5:]=='erase':
            return 'erase'
    elif x=='ser':
        if s[-6:]=='eraser':
            return 'eraser'
    else: return 'False'

count=0
while len(s)>0 and count==0:
    if check(s)=='False':
        count+=1
        print('NO')
    elif check(s)=='dream' or check(s)=='erase':
        if len(s)!=5:s=s[:-5]
        elif len(s)==5:s=''
    elif check(s)=='eraser':
        if len(s)!=6:s=s[:-6]
        elif len(s)==6:s=''
    elif check(s)=='dreamer':
        if len(s)!=7:s=s[:-7]
        elif len(s)==7:s=''

if count==0:print('YES')

Fixed submission:
s=input()
def check(s):
    if s[-5:]=='dream':
        return 'dream'
    elif s[-7:]=='dreamer':
        return 'dreamer'
    elif s[-5:]=='erase':
        return 'erase'
    elif s[-6:]=='eraser':
        return 'eraser'
    else: return 'False'

count=0
while len(s)>0 and count==0:
    if check(s)=='False':
        count+=1
        print('NO')
    elif check(s)=='dream' or check(s)=='erase':
        s=s[:-5]
    elif check(s)=='eraser':
        s=s[:-6]
    elif check(s)=='dreamer':
        s=s[:-7]

if count==0:print('YES')
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
from collections import defaultdict
branch=defaultdict(set)
lang=defaultdict(set)
inp=[]
for i in range(N):
    X=list(map(int,input().split()))
    for k in range(X[0]):
        lang[X[k+1]]|={i}
    inp.append(X[1:])
for i in range(N):
    for l in inp[i]:
        branch[i]|=lang[l]
checked={0}
check={0}
while len(check)>0:
    now=check.pop()
    check|=branch[now]-checked
    checked|=branch[now]
    if len(checked)==N:
        break
if len(checked)==N:
    print('YES')
else:
    print('NO')

Fixed submission:
N,M=map(int,input().split())
from collections import defaultdict
lang=[-1]*(M+1)
data=defaultdict(int)
def search(l):
    if lang[l]>=0:
        lang[l]=search(lang[l])
    elif lang[l]<0:
        return l
    return lang[l]
def union(i,j,lang):
    iidx=search(i)
    jidx=search(j)
    if iidx==jidx:
        return lang
    elif lang[iidx]<=lang[jidx]:
        lang[iidx]+=lang[jidx]
        lang[jidx]=iidx
    else:
        lang[jidx]+=lang[iidx]
        lang[iidx]=jidx
    return lang
for i in range(N):
    line=list(map(int,input().split()))
    data[line[1]]+=1
    for k in range(1,line[0]):
        data[line[k+1]]+=1
        lang=union(line[k],line[k+1],lang)
L=set()
for k in range(1,1+M):
    if data[k]==0:continue
    L|={search(k)}
if len(L)>1:
    print('NO')
elif len(L)==1:
    print('YES')

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
from collections import defaultdict
dist=[d]*N
branch=defaultdict(set)
lang=defaultdict(set)
inp=[]
for i in range(N):
    X=list(map(int,input().split()))
    for k in range(X[0]):
        lang[X[k+1]]|={i}
    inp.append(X[1:])
for i in range(N):
    for l in inp[i]:
        branch[i]|=lang[l]
checked={0}
check={0}
while len(check)>0:
    now=check.pop()
    check|=branch[now]-checked
    checked|=branch[now]
    if len(checked)==N:
        break
if len(checked)==N:
    print('YES')
else:
    print('NO')

Fixed submission:
N,M=map(int,input().split())
from collections import defaultdict
lang=[-1]*(M+1)
data=defaultdict(int)
def search(l):
    if lang[l]>=0:
        lang[l]=search(lang[l])
    elif lang[l]<0:
        return l
    return lang[l]
def union(i,j,lang):
    iidx=search(i)
    jidx=search(j)
    if iidx==jidx:
        return lang
    elif lang[iidx]<=lang[jidx]:
        lang[iidx]+=lang[jidx]
        lang[jidx]=iidx
    else:
        lang[jidx]+=lang[iidx]
        lang[iidx]=jidx
    return lang
for i in range(N):
    line=list(map(int,input().split()))
    data[line[1]]+=1
    for k in range(1,line[0]):
        data[line[k+1]]+=1
        lang=union(line[k],line[k+1],lang)
L=set()
for k in range(1,1+M):
    if data[k]==0:continue
    L|={search(k)}
if len(L)>1:
    print('NO')
elif len(L)==1:
    print('YES')
Buggy python submission (verdict: Runtime Error):
alpha='abcdefghijklmnopqrstuvwxyz'
S=input()
K=int(input())
ans=''
for s in S:
    idx=alpha.index(s)
    if idx==0 or 26-idx>K:
        ans+=s
        continue
    else:
        K-=26-idx
        ans+='a'
if K>0:
    tar=ans[-1]
    idx=alpha.index(tar)
    ans=ans[:-1]+alpha[idx+K]
print(ans)

Fixed submission:
#CODEFESTIVAL2016qualA
alpha='abcdefghijklmnopqrstuvwxyz'
S=input()
K=int(input())
ans=''
for s in S:
    idx=alpha.index(s)
    if idx==0 or 26-idx>K:
        ans+=s
        continue
    else:
        K-=26-idx
        ans+='a'
if K>0:
    tar=ans[-1]
    idx=alpha.index(tar)
    ans=ans[:-1]+alpha[(idx+K)%26]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H,W,N=map(int,input().split())
ans=[0 for i in range(10)]

data=[]
origin=[]
def check(a,b):
    if a>0 and a<H-1 and b>0 and b<W-1:return True
    else:return False

def count(a,b):
    for i in range(a-2,a+1):
        for j in range(b-2,b+1):
            if check(i,j):
                x=(i,j)
                data.append(x)
                if x not in origin:origin.append(x)
                
for k in range(N):
    a,b=map(int,input().split())
    count(a,b)

for x in origin:
    c = data.count(x)
    ans[c]+=1
zero = (H-2)*(W-2)-sum(ans)
ans[0]=zero
for i in range(10):
    print(ans[i])
    
#http://arc061.contest.atcoder.jp/data/arc/061/editorial.pdf

Fixed submission:
from collections import defaultdict
H,W,N=map(int,input().split())
ans=[0 for i in range(10)]

data=defaultdict(int)
def check(a,b):
    if a>0 and a<H-1 and b>0 and b<W-1:return True
    else:return False

def count(a,b):
    for i in range(a-2,a+1):
        for j in range(b-2,b+1):
            if check(i,j):
                x=(i,j)
                data[x]+=1
                
for k in range(N):
    a,b=map(int,input().split())
    count(a,b)

for v in data.values():
    ans[v]+=1

ans[0]=(H-2)*(W-2)-sum(ans[1:])
for i in range(10):
    print(ans[i])
    
#http://arc061.contest.atcoder.jp/data/arc/061/editorial.pdf
#https://atcoder.jp/contests/abc045/submissions/4024831
#https://atcoder.jp/contests/abc045/submissions/4017890

Buggy python submission (verdict: Time Limit Exceeded):
H,W,N=map(int,input().split())
data=[[0 for i in range(W-2)] for j in range(H-2)]
def check(a,b):
    if a>1 and b>1:
        data[a-2][b-2]+=1
    if a>1 and b>0 and b<W-1:
        data[a-2][b-1]+=1
    if a>1 and b<W-2:
        data[a-2][b]+=1
    if a>0 and a<H-1 and b>1:
        data[a-1][b-2]+=1
    if a>0 and a<H-1 and b>0 and b<W-1:
        data[a-1][b-1]+=1
    if a>0 and a<H-1 and b<W-2:
        data[a-1][b]+=1
    if a<H-2 and b>1:
        data[a][b-2]+=1
    if a<H-2 and b>0 and b<W-1:
        data[a][b-1]+=1
    if a<H-2 and b<W-2:
        data[a][b]+=1
    return
for k in range(N):
    a,b=map(int,input().split())
    a-=1
    b-=1
    check(a,b)
for i in range(10):
    count=0
    for j in range(len(data)):
        count+=data[j].count(i)
    print(count)

Fixed submission:
from collections import defaultdict
H,W,N=map(int,input().split())
ans=[0 for i in range(10)]

data=defaultdict(int)
def check(a,b):
    if a>0 and a<H-1 and b>0 and b<W-1:return True
    else:return False

def count(a,b):
    for i in range(a-2,a+1):
        for j in range(b-2,b+1):
            if check(i,j):
                x=(i,j)
                data[x]+=1
                
for k in range(N):
    a,b=map(int,input().split())
    count(a,b)

for v in data.values():
    ans[v]+=1

ans[0]=(H-2)*(W-2)-sum(ans[1:])
for i in range(10):
    print(ans[i])
    
#http://arc061.contest.atcoder.jp/data/arc/061/editorial.pdf
#https://atcoder.jp/contests/abc045/submissions/4024831
#https://atcoder.jp/contests/abc045/submissions/4017890
Buggy python submission (verdict: Runtime Error):
#2-1-1 #ABC045C
s=input()
lenth=len(s)
kugiri=set()
def roop(before,now,kugiri):
    if now==lenth:
        kugiri|={before,}
        return kugiri
    kugiri = roop(before+(0,),now+1,kugiri)
    kugiri = roop(before+(1,),now+1,kugiri)
    return kugiri
kugiri = roop((0,),2,kugiri)
kugiri = roop((1,),2,kugiri)
def calc(ans,kugiri,s):
    test=s
    now=test[0]
    test=test[1:]
    for i in range(len(s)-1):
        k=kugiri[i]
        if k==0:
            now+=test[0]
        elif k==1:
            ans+=int(now)
            now=test[0]
        test=test[1:]
        if i==len(s)-2:ans+=int(now)
    return ans
            
ans=0
for i in kugiri:
    ans=calc(ans,i,s)
print(ans)

Fixed submission:
#2-1-1 #ARC061C
s=input()
lenth=len(s)
kugiri=set()
def roop(before,now,kugiri):
    if now==lenth:
        kugiri|={before,}
        return kugiri
    kugiri = roop(before+(0,),now+1,kugiri)
    kugiri = roop(before+(1,),now+1,kugiri)
    return kugiri


def calc(ans,kugiri,s):
    test=s
    now=test[0]
    test=test[1:]
    for i in range(len(s)-1):
        k=kugiri[i]
        if k==0:
            now+=test[0]
        elif k==1:
            ans+=int(now)
            now=test[0]
        test=test[1:]
        if i==len(s)-2:ans+=int(now)
    return ans
            
ans=0
if len(s)!=1:
    kugiri = roop((0,),2,kugiri)
    kugiri = roop((1,),2,kugiri)
    for i in kugiri:
        ans=calc(ans,i,s)
    print(ans)
elif len(s)==1:print(int(s))
Buggy python submission (verdict: Time Limit Exceeded):
#ABC044C
n,a=map(int,input().split())
x=list(map(int,input().split()))
res=[[0  for i in range(max(1+a*n,1+sum(x)))] for j in range(n+1)]
res[0][0]+=1
for i in range(n):
    for k in range(sum(x),0,-1):
        for j in range(1,n+1):
            if k-x[i]>=0:
                res[j][k]+=res[j-1][k-x[i]]
ans=0
for i in range(1,n+1):
    ans+=res[i][a*i]
print(ans)

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

for i in range(N):
    x[i]=int(x[i])
X=max(max(x),A)
for i in range(N):
    x[i]=x[i]-A
dp=[[0 for t in range(2*N*X+1)] for j in range(N+1)]

for j in range(N+1):
    for t in range(2*N*X+1):
        if j==0 and t==N*X:dp[j][t]=1
        elif j>=1:
            if t-x[j-1]<0 or t-x[j-1]>2*N*X:
                dp[j][t]=dp[j-1][t]
            elif t-x[j-1]>=0 and t-x[j-1]<=2*N*X:
                dp[j][t]=dp[j-1][t]+dp[j-1][t-x[j-1]]
print(dp[N][N*X]-1)
#http://arc060.contest.atcoder.jp/data/arc/060/editorial.pdf

Buggy python submission (verdict: Runtime Error):
N,A=map(int,input().split())
x=input().split()
for i in range(N):
    x[i]=int(x[i])
ans=0
y=[0 for i in range(N)]
def check(ans,y):
    ave=0
    for i in range(N):
        ave+=x[i]*y[i]
    if sum(y)!=0:
        ave=ave/sum(y)
    if sum(y)==0:
        ave=0
    if ave==A:ans+=1
    return ans

def branch(ans,now,pre,y):
    if now==0 and pre==-1:
        if y[now]==0:
            y[now]=1
            now+=1
            pre=1
            ans,now,pre=branch(ans,now,pre,y)
        elif y[now]==1:
            return ans,now,pre

    elif now==N-1:
        ans,now,pre=last(ans,now,pre,y)
        ans,now,pre=branch(ans,now,pre,y)
    
    elif now!=0 and pre==-1:
        if y[now]==0:
            y[now]=1
            pre=1
            now+=1
            ans,now,pre=branch(ans,now,pre,y)
        elif y[now]==1:
            y[now]=0
            now-=1
            ans,now,pre=branch(ans,now,pre,y)
    elif pre==1 and now!=N-1:
        now+=1
        ans,now,pre=branch(ans,now,pre,y)
    return ans,now,pre

def last(ans,now,pre,y):
    y[-1]=0
    ans = check(ans,y)
    y[-1]=1
    ans = check(ans,y)
    y[-1]=0
    pre=-1
    now-=1
    return ans,now,pre
now=0
pre=1
ans,now,pre=branch(ans,now,pre,y)
print(ans)

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

for i in range(N):
    x[i]=int(x[i])
X=max(max(x),A)
for i in range(N):
    x[i]=x[i]-A
dp=[[0 for t in range(2*N*X+1)] for j in range(N+1)]

for j in range(N+1):
    for t in range(2*N*X+1):
        if j==0 and t==N*X:dp[j][t]=1
        elif j>=1:
            if t-x[j-1]<0 or t-x[j-1]>2*N*X:
                dp[j][t]=dp[j-1][t]
            elif t-x[j-1]>=0 and t-x[j-1]<=2*N*X:
                dp[j][t]=dp[j-1][t]+dp[j-1][t-x[j-1]]
print(dp[N][N*X]-1)
#http://arc060.contest.atcoder.jp/data/arc/060/editorial.pdf
Buggy python submission (verdict: Time Limit Exceeded):
mondai = input()
s=[]
for i in range(len(mondai)):
    s.append(mondai[i])
alpha = 'abcdefghijklmnopqrstuvwxyz'
def check(s):
    if len(s)<2:return False
    border=len(s)//2
    for a in range(len(alpha)):
        k = s.count(alpha[a])
        if k>border:return True
    return False
def main(s):
    l = len(s)
    for i in range(l):
        target=''
        for j in range(i,l):
            target+=s[j]
            if check(target):
                return str(i+1)+' '+str(j+1)
    return '-1 -1'
print(main(s))

Fixed submission:
mondai = input()
s=[]
for i in range(len(mondai)):
    s.append(mondai[i])
alpha = 'abcdefghijklmnopqrstuvwxyz'
def main(s):
    now=[]
    ind=len(s)
    for i in range(len(s)):
        x=s.pop()
        k = len(now)
        if k==0:now.append(x)
        if k==1:
            if x in now:return str(ind)+' '+str(ind+1)
            now.append(x)
        if k==2:
            if x in now:return str(ind)+' '+str(ind+2)
            if x not in now:
                now = now[1:]
                now.append(x)
        ind-=1
    return '-1 -1'
print(main(s))
Buggy python submission (verdict: Runtime Error):
mondai = input(),split()
if mondai.count('5')==2 and mondai.count('7')==1:print('Yes')
else:print('No')

Fixed submission:
x = input().split()
five = x.count('5')
seven = x.count('7')
if five==2 and seven==1:print('YES')
else:print('NO')