Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02841 (python)

Fixed submission:
m,d=map(int,input().split(" "))
mm,dd=map(int,input().split(" "))
if m==mm:print(0)
else:print(1)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
from itertools import combinations as cmb
n=int(input())
s=set(input())
combiset=set(cmb(s,3))
print(len(combiset))

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
from itertools import combinations as cmb
n=int(input())
s=list(input())
sss=[]
for i in s:
    sss.append(i)
combiset=set(cmb(sss,3))
print(len(combiset))

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline

n=int(input())
s=input()
dp=[[[False]*1000 for j in range(4)] for i in range(n+1)]

dp[0][0][0]=True

for i in range(n):
    for j in range(4):
        for k in range(1000):
            if dp[i][j][k]==False:continue
            dp[i+1][j][k]=True
            if j<=2:
                dp[i+1][j+1][k*10+int(s[i])]=True
cnt=0
for i in range(1000):
    if dp[n][3][i]==1:cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
# 動的計画法

n=int(input())
s=input()
dp=[[[False for k in range(1000)] for j in range(4)] for i in range(n+1)]

dp[0][0][0]=True

for i in range(n):
    for j in range(4):
        for k in range(1000):
            if dp[i][j][k]==False:continue
            dp[i+1][j][k]=True
            if j<=2:
                dp[i+1][j+1][k*10+int(s[i])]=True
cnt=0
for i in range(1000):
    if dp[n][3][i]==True:cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
dp=[[[False for k in range(1000)] for j in range(4)] for i in range(n+1)]

dp[0][0][0]=True

for i in range(n):
    for j in range(4):
        for k in range(1000):
            if dp[i][j][k]==False:continue
            print(i,j,k)
            dp[i+1][j][k]=True
            print(i+1,j,k,i,j,k)
            if j<=2:
                dp[i+1][j+1][k*10+int(s[i])]=True
                print(i+1,j+1,k*10+int(s[i]),i,j,k)
cnt=0
for i in range(1000):
    if dp[n][3][i]==True:cnt+=1
print(cnt)
Problem p02885 (python)

Fixed submission:
A,B = map(int,input().split(" "))
print(max(A-B*2,0))

Buggy submission (verdict: Runtime Error):
import bisect
n=int(input())
L=[]*n
L=list(map(int,input().split()))
L.sort()
cnt=0
for i in range(n-2):
    for j in range(i+1,n-1):
        ab=L[i]+L[j]
        num=bisect.bisect_left(L[j+1:],ab)
        cnt+=num
print(cnt)
Problem p02886 (python)

Fixed submission:
import itertools
N = int(input())
D=[]*N
D=map(int,input().split(" "))
sum=0
for i,j in itertools.permutations(D,2):
    sum+=i*j

print(int(sum/2))

Buggy submission (verdict: Runtime Error):
N = input()
D=[]*N
D=map(int,input().split(" "))
sum=0
for i,di in enumerate(D):
    for j,jd in enumerate(D):
        if i!=j:
            sum+=jd*id
print(sum)
Problem p03006 (python)

Fixed submission:
from collections import defaultdict

n=int(input())
if n==1:
    print(1)
    exit()
x=[]
y=[]
for i in range(n):
    xx,yy=list(map(int,input().split()))
    x.append(xx)
    y.append(yy)

dif=defaultdict(int)

for i in range(n):
    for j in range(n):
        if i==j:continue
        p=x[j]-x[i]
        q=y[j]-y[i]
        dif[(p,q)]+=1

dif=sorted(dif.items(),key=lambda x:x[1],reverse=True)
ans=n-dif[0][1]

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

n=int(input())
x=[]
y=[]
for i in range(n):
    xx,yy=list(map(int,input().split()))
    x.append(xx)
    y.append(yy)

dif=defaultdict(int)

for i in range(n):
    for j in range(n):
        if i==j:continue
        p=x[j]-x[i]
        q=y[j]-y[i]
        dif[(p,q)]+=1

dif=sorted(dif.items(),key=lambda x:x[1],reverse=True)
ans=n-dif[0][1]

print(ans)
Problem p03241 (python)

Fixed submission:
# 解説AC

n,m=list(map(int,input().split()))

i=m//n

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors

lis=make_divisors(m)

for mm in lis:
    if mm<=i:
        ans=mm
        break

print(ans)

Buggy submission (verdict: Runtime Error):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors

lis=make_divisors(m)

for mm in lis:
    if mm<=i:
        ans=mm
        break

print(ans)
Problem p02609 (python)

Fixed submission:
def popcount(n):
    return str(bin(n)).count('1')
def f(n):
    if n==0:
        return 0
    else:
        return f(n%popcount(n))+1
N=int(input())
X=input()
K=X.count("1")
#k桁目がone,zeroのとき
ONE=0#K-1
ZERO=0#K+1
tmp1=1
tmp0=1
for i in range(N):
    if X[-i-1]=="1":
        if K>1:
            ONE+=tmp1
            ONE%=(K-1)
        ZERO+=tmp0
        ZERO%=(K+1)
    if K>1:
        tmp1*=2
        tmp1%=(K-1)
    tmp0*=2
    tmp0%=(K+1)
for i in range(N):
    nextnumber=-1
    if X[i]=="1":
        if K==1:
            print(0)
            continue
        else:
            nextnumber=(ONE-pow(2,N-i-1,K-1))%(K-1)
    else:
        nextnumber=(ZERO+pow(2,N-i-1,K+1))%(K+1)
    print(f(nextnumber)+1)

Buggy submission (verdict: Runtime Error):
def popcount(n):
    return str(bin(n)).count('1')
def f(n):
    if n==0:
        return 0
    else:
        return f(n%popcount(n))+1
N=int(input())
X=input()
K=X.count("1")
#k桁目がone,zeroのとき
ONE=0#K-1
ZERO=0#K+1
tmp1=1
tmp0=1
for i in range(N):
    if X[-i-1]=="1":
        ONE+=tmp1
        ONE%=(K-1)
        ZERO+=tmp0
        ZERO%=(K+1)
    tmp1*=2
    tmp1%=(K-1)
    tmp0*=2
    tmp0%=(K+1)
for i in range(N):
    nextnumber=-1
    if X[i]=="1":
        nextnumber=(ONE-pow(2,N-i-1,K-1))%(K-1)
    else:
        nextnumber=(ZERO+pow(2,N-i-1,K+1))%(K+1)
    print(f(nextnumber)+1)
Problem p02721 (python)

Fixed submission:
#差がC以下はダメ（Cもダメ）
N,K,C=map(int,input().split())
S=input()
X=[]
for i in range(N):
    if S[i]=="o":
        X.append(i+1)
M=len(X)
#例外処理（M=1のとき）
if M==1:
    #このときK==1
    print(X[0])
    exit()

#X[i]日に働くとき、その直前or直後で働ける最も近い日のindex
L=[-1 for i in range(M)]
R=[-1 for i in range(M)]
j=1
for i in range(M-1):
    while(j<M):
        if X[j]-X[i]>=C+1:
            R[i]=j
            break
        else:
            j+=1
j=M-2
for i in range(M-1,0,-1):
    while(j>=0):
        if X[i]-X[j]>=C+1:
            L[i]=j
            break
        else:
            j-=1
LD=[-1 for i in range(M)]
RD=[-1 for i in range(M)]
def Ldfs(i):
    if LD[i]!=-1:
        return LD[i]
    if L[i]==-1:
        LD[i]=1
        return 1
    else:
        LD[i]=Ldfs(L[i])+1
        return Ldfs(L[i])+1
def Rdfs(i):
    if RD[i]!=-1:
        return RD[i]
    if R[i]==-1:
        RD[i]=1
        return 1
    else:
        RD[i]=Rdfs(R[i])+1
        return Rdfs(R[i])+1
for i in range(M):
    Ldfs(i)
    Rdfs(M-1-i)
Y=[0 for i in range(M)]
Y[0]=RD[1]
Y[-1]=LD[-2]
for i in range(1,M-1):
    Y[i]=LD[i-1]+RD[i+1]
for i in range(M):
    if Y[i]<K:
        print(X[i])

Buggy submission (verdict: Runtime Error):
#差がC以下はダメ（Cもダメ）
N,K,C=map(int,input().split())
S=input()
X=[]
for i in range(N):
    if S[i]=="o":
        X.append(i+1)
M=len(X)
#例外処理（M=1のとき）
#ACしたので試験的にコメントアウト
'''
if M==1:
    #このときK==1
    print(X[0])
    exit()
'''
#X[i]日に働くとき、その直前or直後で働ける最も近い日のindex
L=[-1 for i in range(M)]
R=[-1 for i in range(M)]
j=1
for i in range(M-1):
    while(j<M):
        if X[j]-X[i]>=C+1:
            R[i]=j
            break
        else:
            j+=1
j=M-2
for i in range(M-1,0,-1):
    while(j>=0):
        if X[i]-X[j]>=C+1:
            L[i]=j
            break
        else:
            j-=1
LD=[-1 for i in range(M)]
RD=[-1 for i in range(M)]
def Ldfs(i):
    if LD[i]!=-1:
        return LD[i]
    if L[i]==-1:
        LD[i]=1
        return 1
    else:
        LD[i]=Ldfs(L[i])+1
        return Ldfs(L[i])+1
def Rdfs(i):
    if RD[i]!=-1:
        return RD[i]
    if R[i]==-1:
        RD[i]=1
        return 1
    else:
        RD[i]=Rdfs(R[i])+1
        return Rdfs(R[i])+1
for i in range(M):
    Ldfs(i)
    Rdfs(M-1-i)
Y=[0 for i in range(M)]
Y[0]=RD[1]
Y[-1]=LD[-2]
for i in range(1,M-1):
    Y[i]=LD[i-1]+RD[i+1]
for i in range(M):
    if Y[i]<K:
        print(X[i])
Problem p02744 (python)

Fixed submission:
from collections import deque
N=int(input())
if N==1:
    print("a")
    exit()
X=[chr(i+97) for i in range(N)]
#print(X)
Y=[]
q=deque(["a"])
while(len(q)>0):
    r=q.pop()
    k=len(set(r))
    for i in range(k+1):
        p=r+X[i]
        if len(p)==N:
            Y.append(p)
        else:
            q.append(p)
Y.sort()
for line in Y:
    print(line)

Buggy submission (verdict: Runtime Error):
from collections import deque
N=int(input())
X=[chr(i+97) for i in range(N)]
q=deque(["a"])
while(len(q)>0):
    r=q.popleft()
    k=len(set(r))
    for i in range(k+1):
        p=r+X[i]
        if len(p)==N:
            print(p)
        else:
            q.append(p)
Problem p02805 (python)

Fixed submission:
import math
N=int(input())
x=[0 for i in range(N)]
y=[0 for i in range(N)]
p=[]
for i in range(N):
    x[i],y[i]=map(int,input().split())
    p.append((x[i],y[i]))
def dist(p,q):
    a,b=p
    c,d=q
    return math.sqrt((a-c)**2+(b-d)**2)
def check(R):
    Q=[]
    for i in range(N):
        for j in range(i+1,N):
            d=dist(p[i],p[j])/2
            if R<d:
                return False
            h=math.sqrt(R*R-d*d)
            #print(d,h,R)
            nx,ny=(x[j]-x[i],y[j]-y[i])
            nr=math.sqrt(nx**2+ny**2)
            dx,dy=h*nx/nr,h*ny/nr
            mx,my=(x[i]+x[j])/2,(y[i]+y[j])/2
            #print(mx,my)
            #print(dx,dy)
            Q.append((mx+dy,my-dx))
            Q.append((mx-dy,my+dx))
    #print(Q,R)
    for pa in Q:
        flag=1
        for i in range(N):
            #print(pa,i,dist(pa,p[i]),R)
            if dist(pa,p[i])>R+9e-7:
                flag=0
                break
        if flag==1:
            return True
    return False

low=0
high=2000
for line in range(50):
    mid=(low+high)/2
    if check(mid):
        high=mid
    else:
        low=mid
print(mid)

Buggy submission (verdict: Runtime Error):
import math
N=int(input())
x=[0 for i in range(N)]
y=[0 for i in range(N)]
p=[]
for i in range(N):
    x[i],y[i]=map(int,input().split())
    p.append((x[i],y[i]))
X,Y,R=0,0,0
def dist(p,q):
    a,b=p
    c,d=q
    return math.sqrt((a-c)**2+(b-d)**2)
if N==2:
    print(dist(p[0],p[1])/2)
    exit()
a=dist(p[1],p[2])
b=dist(p[2],p[0])
c=dist(p[0],p[1])
aa=a*a*(b*b+c*c-a*a)
bb=b*b*(c*c+a*a-b*b)
cc=c*c*(a*a+b*b-c*c)

X=(aa*p[0][0]+bb*p[1][0]+cc*p[2][0])/(aa+bb+cc)
Y=(aa*p[0][1]+bb*p[1][1]+cc*p[2][1])/(aa+bb+cc)
R=dist((X,Y),p[0])
#print(dist((X,Y),p[0]))
#print(dist((X,Y),p[1]))
#print(dist((X,Y),p[2]))
for i in range(3,N):
    if dist((X,Y),p[i])<=R:
        continue
    d=dist((X,Y),p[i])
    nX=(X*(R+d)+p[i][0]*(d-R))/(2*d)
    nY=(Y*(R+d)+p[i][1]*(d-R))/(2*d)
    nR=(R+d)/2
    X,Y,R=nX,nY,nR
print(R)
Problem p02806 (python)

Fixed submission:
N=int(input())
s=["" for i in range(N)]
t=["" for i in range(N)]
for i in range(N):
    s[i],t[i]=input().split()
    t[i]=int(t[i])
X=input()
flag=0
ans=0
for i in range(N):
    if flag==1:
        ans+=t[i]
    else:
        if s[i]==X:
            flag=1
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
s=["" for i in range(N)]
t=["" for i in range(N)]
for i in range(N):
  s[i],t[i]=input().split()
  t[i]=int(t[i])
X=int(input())
flag=0
ans=0
for i in range(N):
  if flag==1:
    ans+=t[i]
  else:
    if s[i]==X:
      flag=1
print(ans)
Problem p02839 (python)

Fixed submission:
H,W=map(int,input().split())
A=[[int(i) for i in input().split()] for j in range(H)]
B=[[int(i) for i in input().split()] for j in range(H)]
dp=[[0 for j in range(W)] for i in range(H)]
M=161*161
dp[0][0]|=1<<(A[0][0]-B[0][0]+M)
dp[0][0]|=1<<(-A[0][0]+B[0][0]+M)

for i in range(H):
    for j in range(W):
        dij=abs(A[i][j]-B[i][j])
        if i>0:
            dp[i][j]|=dp[i-1][j]<<dij
            dp[i][j]|=dp[i-1][j]>>dij
        if j>0:
            dp[i][j]|=dp[i][j-1]>>dij
            dp[i][j]|=dp[i][j-1]<<dij
ans=[]
for k in range(2*M+1):
    if (1<<k)&dp[-1][-1]!=0:
        ans.append(abs(k-M))
print(min(ans))

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
A=[[int(i) for i in input().split()] for j in range(H)]
B=[[int(i) for i in input().split()] for j in range(H)]
dp=[[0 for j in range(W)] for i in range(H)]
M=161*161
dp[0][0]|=1<<(A[0][0]-B[0][0]+M)
dp[0][0]|=1<<(-A[0][0]+B[0][0]+M)

for i in range(H):
    for j in range(W):
        dij=abs(A[i][j]-B[i][j])
        if i>0:
            dp[i][j]|=dp[i-1][j]<<dij
            dp[i][j]|=dp[i-1][j]>>dij
        if j>0:
            dp[i][j]|=dp[i][j-1]>>dij
            dp[i][j]|=dp[i][j-1]<<dij
ans=[]
for i in range(M):
    if (1<<i)&dp[-1][-1]!=0:
        ans.append(abs(i-M))
print(min(ans))

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
A=[[int(i) for i in input().split()] for j in range(H)]
B=[[int(i) for i in input().split()] for j in range(H)]
dp=[[0 for j in range(W)] for i in range(H)]
M=80*80*2+1
dp[0][0]|=1<<(A[0][0]-B[0][0]+M)
dp[0][0]|=1<<(-A[0][0]+B[0][0]+M)

for i in range(H):
    for j in range(W):
        dij=abs(A[i][j]-B[i][j])
        if i>0:
            dp[i][j]|=dp[i-1][j]<<dij
            dp[i][j]|=dp[i-1][j]>>dij
        if j>0:
            dp[i][j]|=dp[i][j-1]>>dij
            dp[i][j]|=dp[i][j-1]<<dij
ans=[]
for i in range(M):
    if (1<<i)&dp[-1][-1]!=0:
        ans.append(abs(i-M))
print(min(ans))

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
A=[[int(i) for i in input().split()] for j in range(H)]
B=[[int(i) for i in input().split()] for j in range(H)]
dp=[[0 for j in range(W)] for i in range(H)]
M=80*80*2+1
dp[0][0]=1<<(abs(A[0][0]-B[0][0])+M)

for i in range(H):
    for j in range(W):
        dij=abs(A[i][j]-B[i][j])
        if i>0:
            dp[i][j]|=dp[i-1][j]<<dij
            dp[i][j]|=dp[i-1][j]>>dij
        if j>0:
            dp[i][j]|=dp[i][j-1]>>dij
            dp[i][j]|=dp[i][j-1]<<dij
ans=[]
for i in range(M):
    if (1<<i)&dp[-1][-1]!=0:
        ans.append(abs(i-M))
print(min(ans))
Problem p02868 (python)

Fixed submission:
class segtree():
    def segfunc(x,y):
        return min(x,y)
    #####単位元######
    ide_ele = -1
    n=1
    init_val=[0]*n
    #num:n以上の最小の2のべき乗
    num =2**(n-1).bit_length()
    seg=[ide_ele]*2*num
    
    def __init__(self,INIT_VAL,SEGFUNC,IDE_ELE):
        self.ide_ele=IDE_ELE
        self.init_val=[i for i in INIT_VAL]
        self.segfunc=SEGFUNC
        self.n=len(self.init_val)
        self.num =2**(self.n-1).bit_length()
        self.seg=[self.ide_ele]*2*self.num

        #set_val
        for i in range(self.n):
            self.seg[i+self.num-1]=self.init_val[i]    
        #built
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self,k,x):
        k += self.num-1
        self.seg[k] = x
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self,p,q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res
N,M=map(int,input().split())
Edge=[]
for i in range(M):
    l,r,c=map(int,input().split())
    Edge.append((l-1,r-1,c))
Edge.sort()
INF=10**15
dp=segtree([INF for i in range(N)],min,INF)
dp.update(0,0)
for i in range(M):
    l,r,c=Edge[i]
    dist=dp.query(l,r+1)
    tmp=dp.query(r,r+1)
    dp.update(r,min(tmp,dist+c))
ans=dp.query(N-1,N)
if ans==INF:
    ans=-1
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
X=sorted([(A[i],B[i]) for i in range(N)],key=lambda x:x[1])
A=[X[i][0] for i in range(N)]
B=[X[i][1] for i in range(N)]
C=sorted([(A[i],i) for i in range(N)],key=lambda x:x[0])
for i in range(N):
    if C[i][0]>B[i]:
        print("No")
        exit()
if len(set(A))<N:
    print("Yes")
    exit()
Y=[0 for i in range(N)]
j=0
for i in range(N):
    Y[j]=1
    j=C[j][1]
    
if sum(Y)==N:
    #A:C[i][0]
    #B:X[i][1]
    for i in range(N-1):
        if C[i+1][0]<=X[i][1]:
            print("Yes")
            exit()
    print("No")
else:
    print("Yes")
Problem p02992 (python)

Fixed submission:
N,K=map(int,input().split())
mod=10**9+7
Layer=[]
a=1
b=1
while(b<=N):
    a=b
    b=N//(N//a)+1
    Layer.append((a,b))
#print(Layer)
num=[x[1]-x[0] for x in Layer]
M=len(Layer)
#print(num)
dp=[[0 for j in range(M+1)] for i in range(K+1)]
dp[0][0]=1
sdp=[0 for i in range(M+2)]
for k in range(K):
    for j in range(M+1):
        sdp[j+1]=(dp[k][j]+sdp[j])%mod
    for j in range(M):
        dp[k+1][j]=(sdp[M-j]*num[j])%mod
ans=0
for j in range(M+1):
    ans+=dp[K][j]
    ans%=mod
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
mod=10**9+7
Layer=[]
a=1
b=1
while(b<N):
    a=b
    b=N//(N//a)+1
    Layer.append((a,b))
#print(Layer)
L=[N//x[0] for x in Layer]
num=[x[1]-x[0] for x in Layer]
M=len(Layer)
#print(num)
dp=[[0 for j in range(M)] for i in range(K+1)]
dp[0][0]=1
sdp=[0 for i in range(M+1)]
for i in range(K):
    for j in range(M):
        sdp[j+1]=(dp[i][j]+sdp[j])%mod
    for j in range(M):
        dp[i+1][j]=(sdp[M-j]*num[j])%mod
ans=0
for j in range(M):
    ans+=dp[K][j]
    ans%=mod
print(ans)
Problem p03128 (python)

Fixed submission:
N,M=map(int,input().split())
A=sorted([int(i) for i in input().split()],reverse=True)
num=[6,2,5,5,4,5,6,3,7,6]
INF=10**15
dp=[-INF for i in range(N+1)];dp[0]=0
for i in range(1,N+1):
    for j in range(M):
        if N>=i-num[A[j]]>=0:
            dp[i]=max(dp[i],dp[i-num[A[j]]]+1)
K=N
i=0
ans=""
while(K>0):
    if not(N>=K-num[A[i]]>=0):
        i+=1
        continue
    if dp[K-num[A[i]]]==dp[K]-1:
        ans=ans+str(A[i])
        K-=num[A[i]]
    else:
        i+=1
print(ans)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=sorted([int(i) for i in input().split()],reverse=True)
num=[6,2,5,5,4,5,6,3,7,6]
INF=10**15
dp=[-INF for i in range(N+1)];dp[0]=0
for i in range(1,N+1):
    for j in range(M):
        dp[i]=max(dp[i],dp[i-num[A[j]]]+1)
K=N
i=0
ans=""
while(K>0):
    if dp[K-num[A[i]]]==dp[K]-1:
        ans=ans+str(A[i])
        K-=num[A[i]]
    else:
        i+=1
print(ans)
Problem p03148 (python)

Fixed submission:
N,K=map(int,input().split())
t=[0 for i in range(N)]
d=[0 for i in range(N)]
for i in range(N):
    t[i],d[i]=map(int,input().split())
D=dict()
for i in range(N):
    if not(t[i] in D):
        D[t[i]]=[]
    D[t[i]].append((d[i],i))
E=[0 for i in range(N)]
for key in D:
    D[key].sort(reverse=True)
    E[D[key][0][1]]=1
A=[]
B=[]
for i in range(N):
    if E[i]==1:
        A.append(d[i])
    else:
        B.append(d[i])
A.sort(reverse=True)
B.sort(reverse=True)
X=len(A)
Y=len(B)
S=[0 for i in range(X+1)]
T=[0 for i in range(Y+1)]
for i in range(X):
    S[i+1]=A[i]+S[i]
for i in range(Y):
    T[i+1]=B[i]+T[i]
L=[]
for i in range(1,K+1):
    if i<=X and K-i<=Y:
        L.append(S[i]+T[K-i]+i*i)
print(max(L))

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
sushi=[]
for i in range(N):
    t,d=map(int,input().split())
    sushi.append((t,d))
sushi.sort(key=lambda x:(x[0],-x[1]))
#print(sushi)
X=[sushi[0][1]]
Y=[]
for i in range(1,N):
    if sushi[i-1][0]==sushi[i][0]:
        Y.append(sushi[i][1])
    else:
        X.append(sushi[i][1])
X.sort(reverse=True)
Y.sort(reverse=True)
SX=[0]
SY=[0]
for i in X:
    SX.append(SX[-1]+i)
for i in Y:
    SY.append(SY[-1]+i)
ans=0
#print(X)
#print(Y)
#1<=x<len(X)
#K-len(Y)<=x<=
for x in range(K-len(Y),min(len(SX),K+1)):
    ans=max(SX[x]+SY[K-x]+x*x,ans)
print(ans)
Problem p03165 (python)

Fixed submission:
S=input()
T=input()
a=[ord(i) for i in S]
b=[ord(i) for i in T]
N=len(a);M=len(b)
X=[[0 for j in range(M+1)] for i in range(N+1)]
Y=[[0 for j in range(M+1)] for i in range(N+1)]
for i in range(N):
    for j in range(M):
        if a[i]==b[j]:
            X[i+1][j+1]=X[i][j]+1
            Y[i+1][j+1]=0
        elif X[i+1][j]<X[i][j+1]:
            X[i+1][j+1]=X[i][j+1]
            Y[i+1][j+1]=+1
        else:
            X[i+1][j+1]=X[i+1][j]
            Y[i+1][j+1]=-1
c=[]
i=N;j=M
while(i>0 and j>0):
    if Y[i][j]>0:
        i-=1
    elif Y[i][j]<0:
        j-=1
    else:
        c.append(a[i-1])
        i-=1
        j-=1
print("".join([chr(i) for i in c[::-1]]))

Buggy submission (verdict: Runtime Error):
#出典
#http://d.hatena.ne.jp/mzp/20100623/lcs
#ここから完全にコピペしました
def maxBy(f, x, y):
    if f(x) > f(y):
        return x
    else:
        return y

table = { ("","") : "" }

def lcs(xs,ys):
    if (xs,ys) in table:
        return table[(xs,ys)]

    ret = ""
    if xs == "" or ys == "":
        ret = ""
    elif xs[-1] == ys[-1]:
        ret = lcs(xs[:-1],ys[:-1]) + xs[-1]
    else:
        ret = maxBy(len,
                    lcs(xs[:-1],ys),
                    lcs(xs,ys[:-1]))
    table[(xs,ys)] = ret
    return ret
S=input()
T=input()
print(lcs(S,T))
Problem p03219 (python)

Fixed submission:
X,Y=map(int,input().split())
print(X+Y//2)

Buggy submission (verdict: Runtime Error):
#include <iostream>
using namespace std;
int main(void){
    int X,Y;
    cin >> X >> Y;
    cout << X+Y/2 << endl;
    return 0;
}
Problem p03262 (python)

Fixed submission:
def gcd(a,b):
    x=max([a,b])
    y=min([a,b])
    if x%y==0:
        return y
    else:
        return gcd(y,x%y)
N,X=map(int,input().split())
x=[int(i) for i in input().split()]
y=[abs(x[i]-X) for i in range(N)]
if N==1:
    print(y[0])
    exit()
ans=gcd(y[0],y[1])
for i in range(2,N):
    ans=gcd(ans,y[i])
print(ans)

Buggy submission (verdict: Runtime Error):
def g(a,b):x=max([a,b]);y=min([a,b]);return g(y,x%y) if x%y else y
N,X=map(int,input().split());a=[abs(int(i)-X) for i in input().split()];ans=a[0]
for i in range(1,N):ans=g(ans,y[i])
print(ans)
Problem p03290 (python)

Fixed submission:
import itertools
D,G=map(int,input().split())
p=[0 for i in range(D)]
c=[0 for i in range(D)]
for i in range(D):
    p[i],c[i]=map(int,input().split())

S=list(itertools.product(range(2),repeat=D))
ans=sum(p)
for seq in S:
    score=0
    prove=0
    for i in range(D):
        if seq[i]==1:
            score+=(p[i]*100*(i+1)+c[i])
            prove+=p[i]
    if score>=G:
        if ans>prove:
            ans=prove
        continue
    j=-1
    for i in range(D):
        if seq[i]==0:
            j=i
    for k in range(p[j]):
        prove+=1
        score+=100*(j+1)
        if G<=score:
            break
    if G>score:
        continue
    if ans>prove:
        ans=prove
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
D,G=map(int,input().split())
p=[0 for i in range(D)]
c=[0 for i in range(D)]
for i in range(D):
    p[i],c[i]=map(int,input().split())

S=list(itertools.product(range(2),repeat=D))
ans=sum(p)
for seq in S:
    score=0
    prove=0
    for i in range(D):
        if seq[i]==1:
            score+=(p[i]*100*(i+1)+c[i])
            prove+=p[i]
    if score>G:
        continue
    j=-1
    for i in range(D):
        if seq[i]==0:
            j=i
    if (p[j]*100*(j+1)+c[j]+score<G):
        continue
    if (p[j]*100*(j+1)+score<G):
        continue
    k=(score-G)//(-(j+1)*100)
    prove+=k
    score+=k*100*(j+1)
    if ans>prove:
        ans=prove
print(ans)
Problem p03352 (python)

Fixed submission:
X=int(input())
L=[1]
for i in range(2,32):
  k=2
  while(True):
    if (i**k<=X):
      L.append(i**k)
    else:
      break
    k+=1
print(max(L))

Buggy submission (verdict: Runtime Error):
X=int(input())
L=[]
for i in range(2,32):
  k=2
  while(True):
    if (i**k<=X):
      L.append(i**k)
    else:
      break
    k+=1
print(max(L))