Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import  math
a,b,c=map(double,input().split())
tmp=math.sqrt(a*b)
if a+b+2*tmp<c:
    print("Yes")
else:
    print("No")

Fixed submission:
a,b,c=map(int,input().split())

d=c-a-b
if d>0 and d*d>4*a*b:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
s=input()

if "h" in s:
    flag = False
    for i in range(len(s)-1):
        if s[i]=="h":
            if s[i+1]=="i":
                flag=True
            else:
                flag=False

if flag:
    print("Yes")
else:
    print("No")

Fixed submission:
s=input()
if s=="hi" or s=="hihi" or s=="hihihi" or s=="hihihihi" or s=="hihihihihi":
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
s=input()

if "h" in s:
    flag = True
    for i in range(len(s)-1):
        if s[i]=="h":
            if s[i+1]!="i":
                flag=False

if flag:
    print("Yes")
else:
    print("No")

Fixed submission:
s=input()
if s=="hi" or s=="hihi" or s=="hihihi" or s=="hihihihi" or s=="hihihihihi":
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s=input()
q=int(input())
sd=deque()
for i in range(len(s)):
    sd.append(s[i])

for i in range(q):
    que=list(map(str,input().split()))
    if int(que[0])==1:
        sd=deque(reversed(sd))
    else:
        if int(que[1])==1:
            sd.appendleft(str(que[2]))
        else:
            sd.append(str(que[2]))

ans=''.join(sd)
print(ans)

Fixed submission:
from collections import deque
s=input()
q=int(input())
sd=deque()
for i in range(len(s)):
    sd.append(s[i])
count=0
for i in range(q):
    que=list(map(str,input().split()))
    if int(que[0])==1:
        count+=1
    else:
        if int(que[1])==1:
            if count%2==0:
                sd.appendleft(str(que[2]))
            else:
                sd.append(str(que[2]))
        else:
            if count%2==0:
                sd.append(str(que[2]))
            else:
                sd.appendleft(str(que[2]))
if count%2!=0:
    sd.reverse()

ans=''.join(sd)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s=input()
q=int(input())
sd=deque()
for i in range(len(s)):
    sd.append(s[i])
    
for i in range(q):
    que=list(map(str,input().split()))
    if int(que[0])==1:
        sd.reverse()
    else:
        if int(que[1])==1:
            sd.appendleft(str(que[2]))
        else:
            sd.append(str(que[2]))

ans=''.join(sd)
print(ans)

Fixed submission:
from collections import deque
s=input()
q=int(input())
sd=deque()
for i in range(len(s)):
    sd.append(s[i])
count=0
for i in range(q):
    que=list(map(str,input().split()))
    if int(que[0])==1:
        count+=1
    else:
        if int(que[1])==1:
            if count%2==0:
                sd.appendleft(str(que[2]))
            else:
                sd.append(str(que[2]))
        else:
            if count%2==0:
                sd.append(str(que[2]))
            else:
                sd.appendleft(str(que[2]))
if count%2!=0:
    sd.reverse()

ans=''.join(sd)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
for i in range(q):
    que=list(map(str,input().split()))
    if int(que[0])==1:
        s=s[::-1]
    else:
        if int(que[1])==1:
            s=str(que[2])+s
        else:
            s=s+str(que[2])

print(s)

Fixed submission:
from collections import deque
s=input()
q=int(input())
sd=deque()
for i in range(len(s)):
    sd.append(s[i])
count=0
for i in range(q):
    que=list(map(str,input().split()))
    if int(que[0])==1:
        count+=1
    else:
        if int(que[1])==1:
            if count%2==0:
                sd.appendleft(str(que[2]))
            else:
                sd.append(str(que[2]))
        else:
            if count%2==0:
                sd.append(str(que[2]))
            else:
                sd.appendleft(str(que[2]))
if count%2!=0:
    sd.reverse()

ans=''.join(sd)
print(ans)
Buggy python submission (verdict: Runtime Error):
from scipy.special import comb
n,a,b=map(int,input().split())
MOD=10**9+7
def pos(x, n, m):
    if n == 0:
        return 1
    res = pos(x*x%m, n//2, m)
    if n%2 == 1:
        res = res*x%m
    return res

def comb(n,k):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    k=min(n-k,k)
    ans=1
    inv=[1]*(k+1)
    if k>=1:
        ans*=(n-k+1)%MOD
    for i in range(2,k+1):
        inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
        ans=ans*(n-k+i)*inv[i]%MOD
    return ans

na=comb(n,a)
nb=comb(n,b)

ans=(pos(2,n,MOD)-na-nb-1)%MOD

print(ans)

Fixed submission:

n,a,b=map(int,input().split())
MOD=10**9+7
def pos(x, n, m):
    if n == 0:
        return 1
    res = pos(x*x%m, n//2, m)
    if n%2 == 1:
        res = res*x%m
    return res

def comb(n,k):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    k=min(n-k,k)
    ans=1
    inv=[1]*(k+1)
    if k>=1:
        ans*=(n-k+1)%MOD
    for i in range(2,k+1):
        inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
        ans=ans*(n-k+i)*inv[i]%MOD
    return ans

na=comb(n,a)
nb=comb(n,b)

ans=(pos(2,n,MOD)-na-nb-1)%MOD

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=input()[::-1]
n+="0"
lt=len(n)
dp=[[float('inf') for _ in range(2)] for j in range(lt+1)]
dp[0][0]=0

for i in range(0,lt):
    for j in range(2):
        x=int(n[i])
        x+=j #繰り上がり処理，あとに+11でもOK
        for num in range(0,10):
            ni = i + 1
            nj = 0
            b=num-x
            if b<0:
                b+=10
                nj=1
            dp[ni][nj]=min(dp[ni][nj],dp[i][j]+num+b)

print(dp[lt][0])

Fixed submission:
n=input()[::-1]
n+="0"
lt=len(n)
dp=[[float('inf') for _ in range(2)] for j in range(lt+1)]
dp[0][0]=0

for i in range(0,lt):
    for j in range(2):
        x=int(n[i])
        x+=j #繰り上がり処理，あとに+11でもOK
        for num in range(0,10):
            ni = i + 1
            nj = 0
            b=num-x
            if b<0:
                b+=10
                nj=1
            dp[ni][nj]=min(dp[ni][nj],dp[i][j]+num+b)

print(dp[lt][0])
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a%b==0:
    print(a//b)
else:
    print(a//b+1)a,b=map(int,input().split())
if a%b==0:
    print(a//b)
else:
    print(a//b+1)

Fixed submission:
a,b=map(int,input().split())
if a%b==0:
    print(a//b)
else:
    print(a//b+1)
Buggy python submission (verdict: Time Limit Exceeded):
h,n=map(int,input().split())
a=[]
b=[]
for i in range(n):
    x,y=map(int,input().split())
    a.append(x)
    b.append(y)

cost=[float("inf")]*(h+1)
cost[0]=0
for i in range(1,h+1):
    for j in range(0,n):
        cost[i]=min(cost[i],cost[max(i-a[j],0)]+b[j])

print(cost[-1])

Fixed submission:
h,n=map(int,input().split())
a=[]
b=[]
for i in range(n):
    x,y=map(int,input().split())
    a.append(x)
    b.append(y)

cost=[float("inf")]*(h+1)
cost[0]=0
for i in range(1,h+1):
    for j in range(0,n):
        cost[i]=min(cost[i],cost[max(i-a[j],0)]+b[j])

print(cost[-1])
Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
S=[]
for i in range(H):
    S.append(input())
from collections import deque

def dfs(field, s):
    MOVE = [(0, 1), (1, 0), (0, -1), (-1, 0)]
    q = deque([(0, s)])
    dist = [[-1] * w for _ in range(h)]

    d, i, j = -1, -1, -1
    while q:
        d, (i, j) = q.popleft()
        if dist[i][j] != -1:
            continue
        dist[i][j] = d
        for di, dj in MOVE:
            ni, nj = i + di, j + dj
            if not 0 <= ni < h or not 0 <= nj < w:
                continue
            if field[ni][nj] == '#':
                continue
            if dist[ni][nj] != -1:
                continue
            q.append((d + 1, (ni, nj)))
    return d, i, j

ans=0
for i in range(H):
    for j in range(W):
        if S[i][j]==".":
            d,i,j=dfs(S,(i,j))
            ans=max(ans,d)

print(ans)

Fixed submission:

from collections import deque

def dfs(field, s):
    MOVE = [(0, 1), (1, 0), (0, -1), (-1, 0)]
    q = deque([(0, s)])
    dist = [[-1] * w for _ in range(h)]

    d, i, j = -1, -1, -1
    while q:
        d, (i, j) = q.popleft()
        if dist[i][j] != -1:
            continue
        dist[i][j] = d
        for di, dj in MOVE:
            ni, nj = i + di, j + dj
            if not 0 <= ni < h or not 0 <= nj < w:
                continue
            if field[ni][nj] == '#':
                continue
            if dist[ni][nj] != -1:
                continue
            q.append((d + 1, (ni, nj)))
    return d, i, j

h,w=map(int,input().split())
S=[]
for i in range(h):
    S.append(input())

ans=0
for i in range(h):
    for j in range(w):
        if S[i][j]==".":
            d,i,j=dfs(S,(i,j))
            ans=max(ans,d)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))

ans=0
MOD=10**9+7

for k in range(60):
    x0=0
    x1=0
    for i in range(n):
        cnt=(a[i]>>k)&1
        if cnt==0:
            x0+=1
        else:
            x1+=1

    tmp=1
    for j in range(k):
        tmp*=2
        tmp%=MOD

    su=(x0*x1)*tmp%MOD
    ans+=su
    ans%=MOD

print(ans)

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

ans=0
MOD=10**9+7

for k in range(60):
    x0=0
    x1=0
    for i in range(n):
        cnt=(a[i]>>k)&1
        if cnt==0:
            x0+=1
        else:
            x1+=1

    tmp=1
    for j in range(k):
        tmp*=2
        tmp%=MOD

    su=(x0*x1)*tmp%MOD
    ans+=su
    ans%=MOD

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())

a=list(map(int,input().split()))
f=list(map(int,input().split()))
cnt=[]
a.sort()
f.sort(reverse=True)
for i in range(n):
    cv=a[i]*f[i]
    cnt.append(cv)

def judge(s):
    tmp=k
    for i in range(n):
        if cnt[i]>s:
            if (cnt[i]-s)%f[i]==0:
                vv=(cnt[i]-s)//f[i]
            else:
                vv=1+(cnt[i]-s)//f[i]
            tmp-=vv
    if tmp<0:
        return False
    return True

left=-1
right=10**18

while left+1<right:
    mid=(left+right)//2
    if judge(mid):
        right=mid
    else:
        left=mid

print(right)

Fixed submission:
# tempt
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N,K = map(int,readline().split())
A = np.array(readline().split(),np.int64)
F = np.array(readline().split(),np.int64)

A.sort(); F.sort(); F=F[::-1]

Asum = A.sum()

def test(x):
    # 全員がx秒以下に収めるための必要コストがK以下である
    return Asum - np.minimum(A,x//F).sum() <= K

left = -1 # 不可能目標
right = 10**13 # 可能目標
while left+1 < right:
    mid = (left+right)//2
    if test(mid):
        right = mid
    else:
        left = mid

answer = right
print(answer)
Buggy python submission (verdict: Runtime Error):
import  numpy as np
N=int(input())
A=list(map(int,input().split()))

B=np.argsort(A)+1

print(' '.join(map(str,B)))


Fixed submission:
import numpy as np
N=int(input())
A=list(map(int,input().split()))

B=np.argsort(A)+1

print(' '.join(map(str,B)))

Buggy python submission (verdict: Runtime Error):
import  numpy as np
N=int(input())
A=list(map(int,input().split()))

B=np.argsort(A)

print(' '.join(map(str,B+1)))

Fixed submission:
import numpy as np
N=int(input())
A=list(map(int,input().split()))

B=np.argsort(A)+1

print(' '.join(map(str,B)))
Buggy python submission (verdict: Runtime Error):
import  fractions
import  math
A, B = map(int, input().split())

c=fractions.gcd(A,B)

Cnt=[]

def prime_decomposition(n):
  i = 2
  table = set([])
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.add(int(i))
    i += 1
  if n > 1:
    table.add(int(n))
  return table

Cnt=prime_decomposition(c)

def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1

ans=1


for i in range(0,len(Cnt)):
    if is_prime(int(Cnt[i])):
        ans+=1

print(ans)

Fixed submission:
import  fractions
import  math
A, B = map(int, input().split())

c=fractions.gcd(A,B)

Cnt=[]

def prime_decomposition(n):
  i = 2
  table = set([])
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.add(int(i))
    i += 1
  if n > 1:
    table.add(int(n))
  return table

Cnt=prime_decomposition(c)
Cnt=list(Cnt)
def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1

ans=1


for i in range(0,len(Cnt)):
    if is_prime(int(Cnt[i])):
        ans+=1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
up=float('inf')
dp=[[up]*(1<<n) for i in range(m)]

dp[0][0]=0
buy=[]
a=[]
b=[]
for cnt in range(m):
    x,y=map(int,input().split())
    a.append(x)
    b.append(y)
    c=list(map(int,input().split()))
    tmp=0
    for w in c:
        tmp+=1<<(w-1)
    buy.append(tmp)

for i in range(m-1):
    for j in range(1<<n):
        dp[i+1][j]=min(dp[i+1][j],dp[i][j])
        dp[i+1][j|buy[i]]=min(dp[i][j]+a[i],dp[i+1][j|buy[i]])

if dp[m-1][-1]==float('inf'):
    print(-1)
else:
    print(dp[m-1][-1])

Fixed submission:
n,m=map(int,input().split())
up=float('inf')
dp=[[up]*(1<<n) for i in range(m)]

dp[0][0]=0
buy=[]
a=[]
b=[]
for cnt in range(m):
    x,y=map(int,input().split())
    a.append(x)
    b.append(y)
    c=list(map(int,input().split()))
    tmp=0
    for w in c:
        tmp+=1<<(w-1)
    buy.append(tmp)

for i in range(m-1):
    for j in range(1<<n):
        dp[i+1][j]=min(dp[i+1][j],dp[i][j])
        dp[i+1][j|buy[i]]=min(dp[i][j]+a[i],dp[i+1][j|buy[i]])

if dp[m-1][-1]==float('inf'):
    print(-1)
else:
    print(dp[m-1][-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
A=list(map(int,input().split()))

ans=0
def cheap(x,y):
    x=int(x/(2**y))
    return x

i=0
while(i<M):
    A.sort(reverse=True)
    A[0]=cheap(A[0],1)
    i+=1

for i in range(0,N):
    ans+=A[i]

print(ans)



Fixed submission:
import heapq

N,M=map(int,input().split())
A=list(map(int,input().split()))
for i in range (0,len(A)):
    A[i]*=-1

heapq.heapify(A)

ans=0
def cheap(x,y):
    x=int(x/(2**y))
    return x

i=0
while(i<M):
    tmp=heapq.heappop(A)
    tmp=cheap(tmp,1)
    heapq.heappush(A,tmp)
    i+=1

for i in range(0,N):
    ans+=A[i]

print(ans*(-1))
Buggy python submission (verdict: Runtime Error):
import heapq
from heapq import _heappop_max, _heapify_max
n,m=map(int,input().split())
task=[[0] for _ in range(m+1)]

for i in range(n):
    a,b=map(int,input().split())
    if a<=m:
        task[a].append(b)

task=task[::-1]

tmp=[]
heapq.heapify(tmp)
ans=0

for i in range(m,-1,-1):
    cnt=0
    for j in task[i]:
        heapq.heappush(tmp,-j)
    cnt=heapq.heappop(tmp)
    ans-=cnt
print(ans)


Fixed submission:
import heapq

n,m=map(int,input().split())
task=[[0] for _ in range(m+1)]

for i in range(n):
    a,b=map(int,input().split())
    if a<=m:
        task[a].append(b)

task=task[::-1]

tmp=[]
heapq.heapify(tmp)
ans=0

for i in range(m,-1,-1):
    cnt=0
    for j in task[i]:
        heapq.heappush(tmp,-j)
    cnt=heapq.heappop(tmp)
    ans-=cnt
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
dp=[list(0 for i in range(13)) for j in range(n)]
MOD=10**9+7
if s[0]=="?":
    for k in range(0,10):
        dp[0][k]+=1
else:
    dp[0][int(s[0])]+=1
for i in range(0,n-1):
    for k in range(13):
        if s[i+1]=="?":
            for j in range(10):
                ct=(k*10+j)%13
                dp[i+1][ct]+=dp[i][k]
                dp[i+1][ct]%=MOD
        elif s[i+1]!="?":
            tmp=(int(s[i+1])+k*10)%13
            dp[i+1][tmp]+=dp[i][k]
            dp[i+1][tmp]%=MOD
print(dp[n-1][5])



Fixed submission:
s=input()
n=len(s)
dp=[list(0 for i in range(13)) for j in range(n)]
MOD=10**9+7
if s[0]=="?":
    for k in range(0,10):
        dp[0][k]+=1
else:
    dp[0][int(s[0])]+=1
for i in range(0,n-1):
    for k in range(13):
        if s[i+1]=="?":
            for j in range(10):
                ct=(k*10+j)%13
                dp[i+1][ct]+=dp[i][k]
                dp[i+1][ct]%=MOD
        elif s[i+1]!="?":
            tmp=(int(s[i+1])+k*10)%13
            dp[i+1][tmp]+=dp[i][k]
            dp[i+1][tmp]%=MOD
print(dp[n-1][5])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
cnt=[]
def divis(n):
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            a[i-1]^=1
            if i != n // i :
                ij=n//i
                a[ij-1]^=1
for i in reversed(range(n)):
    if a[i]==1:
        cnt.append(i+1)
        divis(i+1)
if len(cnt)>0:
    print(len(cnt))
    print(*cnt)
else:
    print(0)



Fixed submission:
n=int(input())
a=list(map(int,input().split()))
cnt=[]
def divis(n):
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            a[i-1]^=1
            if i != n // i :
                ij=n//i
                a[ij-1]^=1
for i in reversed(range(n)):
    if a[i]==1:
        cnt.append(i+1)
        divis(i+1)
if len(cnt)>0:
    print(len(cnt))
    print(*cnt)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
n,a,b,c,d=map(int,input().split())
s=input()
flag=True
for i in range(len(s)-1):
    if s[i]=="#" and s[i+1]=="#":
        flag=False
        break

if c<d:
    if flag:
        print("Yes")
    else:
        print("No")
elif c>d:
    flag=False
    for i in range(b,d+1):
        if s[i-1]=="." and s[i]=="." and s[i+1]==".":
            flag=True
            break
    if flag:
        print("Yes")
    else:
        print("No")


Fixed submission:
N,A,B,C,D=map(int,input().split())
S=input()
A-=1
B-=1
C-=1
D-=1
if "##" in S[A:C+1] or "##" in S[B:D+1]:
    print('No')
else:
    if C<D:
        print('Yes')
    else:
        if "..." in S[B-1:D+2]:
            print('Yes')
        else:
            print('No')
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
ans=0
while(1):
    for i in range(1,len(s)-1):
        if s[i-1]=="A" and s[i]=="B" and s[i+1]=="C":
            ans+=1
            s=s[:i-1]+"BCA"+s[i+2:]
    if not "ABC" in s:
        print(ans)
        exit()

Fixed submission:
s=input().replace("BC","X")
ans=0
acc=0
for i in range(len(s)):
    if s[i]=="B" or s[i]=="C":
        acc=0

    elif s[i]=="A":
        acc+=1
    elif s[i]=="X":
        ans+=acc


print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
ans=0
while(1):
    for i in range(1,len(s)-1):
        if s[i-1]=="A" and s[i]=="B" and s[i+1]=="C":
            ans+=1
            s=s[:i-1]+"BCA"+s[i+2:]

    if not "ABC" in s:
        print(ans)
        exit()

Fixed submission:
s=input().replace("BC","X")
ans=0
acc=0
for i in range(len(s)):
    if s[i]=="B" or s[i]=="C":
        acc=0

    elif s[i]=="A":
        acc+=1
    elif s[i]=="X":
        ans+=acc


print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
tmp=[]
change=[]
for i in range(m):
    q,r=map(int,input().split())
    tmp.append([r,q])
tmp.sort(reverse=True)

for i in range(0,m):
    t=0
    cnt=0
    while t<tmp[i][1]:
        change.append(tmp[i][0])
        t+=1
        cnt+=1
    i+=cnt

for i in range(0,min(n,len(change))):
    a[i]=max(a[i],change[i])

print(sum(a))


Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
rep=[]
for i in range(m):
    b,c=map(int,input().split())
    rep.append([c,b])
rep.sort(reverse=True)
Card=[0]*n
cnt=0
fg=0
while fg<n and cnt<m:
    tt=0
    while tt<rep[cnt][1] and fg+tt <n :
        Card[fg+tt]=rep[cnt][0]
        tt+=1
    fg+=tt
    cnt+=1

a.sort()
ans=[]
for i in range(n):
    ans.append(max(a[i],Card[i]))

print(sum(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
tmp=[]
change=[]
for i in range(m):
    q,r=map(int,input().split())
    tmp.append([r,q])
tmp.sort(reverse=True)

for i in range(0,m):
    t=0
    cnt=0
    while t<tmp[i][1]:
        change.append(tmp[i][0])
        t+=1
        cnt+=1
    i+=cnt

if len(change)<n:
    while len(change)<=n:
        change.append(0)

for i in range(0,n):
    a[i]=max(a[i],change[i])

print(sum(a))


Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
rep=[]
for i in range(m):
    b,c=map(int,input().split())
    rep.append([c,b])
rep.sort(reverse=True)
Card=[0]*n
cnt=0
fg=0
while fg<n and cnt<m:
    tt=0
    while tt<rep[cnt][1] and fg+tt <n :
        Card[fg+tt]=rep[cnt][0]
        tt+=1
    fg+=tt
    cnt+=1

a.sort()
ans=[]
for i in range(n):
    ans.append(max(a[i],Card[i]))

print(sum(ans))
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np
# inputを高速化する。
input = sys.stdin.readline

n,k=map(int,input().split())
h=list(map(int,input().split()))
INF=10**10
cost=[INF]*(n+1)
cost[0]=0

for i in range(0,n):
    for j in range(1,min(k+1,n-i)):
        cost[i+j]=min(cost[i+j],cost[i]+abs(h[i+j]-h[i]))

print(cost[n-1])

Fixed submission:
import sys
# inputを高速化する。
input = sys.stdin.readline

n,k=map(int,input().split())
h=list(map(int,input().split()))
INF=10**10
cost=[INF]*(n+1)
cost[0]=0

for i in range(0,n):
    for j in range(1,min(k+1,n-i)):
        cost[i+j]=min(cost[i+j],cost[i]+abs(h[i+j]-h[i]))

print(cost[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))
INF=10**10
cost=[INF]*(n+1)
cost[0]=0
for i in range(0,n):
    for j in range(1,min(k+1,n-i)):
        cost[i+j]=min(cost[i+j],cost[i]+abs(h[i+j]-h[i]))
print(cost[n-1])

Fixed submission:
import sys
# inputを高速化する。
input = sys.stdin.readline

n,k=map(int,input().split())
h=list(map(int,input().split()))
INF=10**10
cost=[INF]*(n+1)
cost[0]=0

for i in range(0,n):
    for j in range(1,min(k+1,n-i)):
        cost[i+j]=min(cost[i+j],cost[i]+abs(h[i+j]-h[i]))

print(cost[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,W=map(int,input().split())
w=[]
v=[]
for i in range(N):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
V=sum(v)

dp=[[float("inf") for i in range(V+1)] for _ in range(110)]
dp[0][0]=0

for i in range(0,N):
    for j in range(V+1):
        if j-v[i]>=0:
            dp[i+1][j]=min(dp[i+1][j],dp[i][j-v[i]]+w[i])

        dp[i+1][j]=min(dp[i+1][j],dp[i][j])


ans=0

for j in range(V+1):
    if dp[N][j]<=W:
        ans=j

print(ans)


Fixed submission:
N,W=map(int,input().split())
w=[0]*N
v=[0]*N
for i in range(N):
    w[i],v[i]=map(int,input().split())
V=sum(v)

dp=[[float("inf") ]*(V+1) for _ in range(110)]
dp[0][0]=0

for i in range(0,N):
    for j in range(V+1):
        if j-v[i]>=0:
            dp[i+1][j]=min(dp[i+1][j],dp[i][j-v[i]]+w[i])
        dp[i+1][j]=min(dp[i+1][j],dp[i][j])
ans=0
for j in range(V+1):
    if dp[N][j]<=W:
        ans=j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,W=map(int,input().split())
w=[]
v=[]
for i in range(N):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
V=sum(v)

dp=[[float("inf") for i in range(V+1)] for _ in range(110)]
dp[0][0]=0

for i in range(0,N):
    for j in range(V+1):
        if j-v[i]>=0:
            dp[i+1][j]=min(dp[i+1][j],dp[i][j-v[i]]+w[i])

        dp[i+1][j]=min(dp[i+1][j],dp[i][j])


ans=0

for j in range(V+1):
    if dp[N][j]<=W:
        ans=j

print(ans)


Fixed submission:
N,W=map(int,input().split())
w=[0]*N
v=[0]*N
for i in range(N):
    w[i],v[i]=map(int,input().split())
V=sum(v)

dp=[[float("inf") ]*(V+1) for _ in range(110)]
dp[0][0]=0

for i in range(0,N):
    for j in range(V+1):
        if j-v[i]>=0:
            dp[i+1][j]=min(dp[i+1][j],dp[i][j-v[i]]+w[i])
        dp[i+1][j]=min(dp[i+1][j],dp[i][j])
ans=0
for j in range(V+1):
    if dp[N][j]<=W:
        ans=j
print(ans)