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

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

start=(M*pow(M-1,N-1,P))%P



if N>=2:
    fac=[0]*N
    finv=[0]*N
    inv=[0]*N
    fac[0]=1
    fac[1]=1
    finv[0]=1
    finv[1]=1
    inv[1]=1
    for i in range(2,N):
        fac[i]=(fac[i-1]*i)%P
        inv[i]=P-(inv[P%i]*(P//i))%P
        finv[i]=(finv[i-1]*inv[i])%P

    def comb(n,k):
        return fac[n]*(finv[k]*finv[n-k]%P)%P



    comp=0
    last=(N-1)-K #K=0ならthru
    for i in range(1,K+1):
        comp=(comp+comb(N-1,i)*pow(M-1,(N-1)-i,P))%P
    comp=(comp*M)%P

    print((start+comp)%P)

else:
    print(M%P)

Buggy submission (verdict: Runtime Error):
N,M,K=map(int,input().split())
P=998244353

start=(M*pow(M-1,N-1,P))%P

fac=[0]*N
finv=[0]*N
inv=[0]*N
fac[0]=1
fac[1]=1
finv[0]=1
finv[1]=1
inv[1]=1
for i in range(2,N):
    fac[i]=(fac[i-1]*i)%P
    inv[i]=P-(inv[P%i]*(P//i))%P
    finv[i]=(finv[i-1]*inv[i])%P

def comb(n,k):
    return fac[n]*(finv[k]*finv[n-k]%P)%P



comp=0
last=(N-1)-K #K=0ならthru
if K>=1:
    for i in range(1,K+1):
        comp=(comp+comb(N-1,i)*pow(M-1,(N-1)-i,P))%P
comp=(comp*M)%P

print((start+comp)%P)

Buggy submission (verdict: Runtime Error):
N,M,K=map(int,input().split())
P=998244353

start=(M*pow(M-1,N-1,P))%P

fac=[0]*N
finv=[0]*N
inv=[0]*N
fac[0]=1
fac[1]=1
finv[0]=1
finv[1]=1
inv[1]=1
for i in range(2,N):
    fac[i]=(fac[i-1]*i)%P
    inv[i]=P-(inv[P%i]*(P//i))%P
    finv[i]=(finv[i-1]*inv[i])%P

def comb(n,k):
    return fac[n]*(finv[k]*finv[n-k]%P)%P



comp=0
last=(N-1)-K #K=0ならthru
for i in range(1,K+1):
    comp=(comp+comb(N-1,i)*pow(M-1,(N-1)-i,P))%P
comp=(comp*M)%P

print((start+comp)%P)
Problem p02753 (python)

Fixed submission:
S=str(input())

if S=='AAA' or S=='BBB':
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
S=str(input())

if S=='AAA' or S='BBB':
    print('No')
else:
    print('Yes')
Problem p02762 (python)

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

N,M,K=map(int,input().split())


par=[index for index in range(N+1)]

def root(x):
    global par

    if x==par[x]:
        return x
    else:
        par[x]=root(par[x])
        return par[x]


def same(x,y):
    global par

    if root(x)==root(y):
        return True
    else:
        return False

def unite(x,y):
    global par

    if root(x)!=root(y):
        par[root(x)]=root(y)


friends=[[] for index1 in range(N+1)]
for index2 in range(M):
    a,b=map(int,input().split())
    unite(a,b)
    friends[a].append(b)
    friends[b].append(a)


block=[[] for index3 in range(N+1)]
for index4 in range(K):
    c,d=map(int,input().split())
    block[c].append(d)
    block[d].append(c)


relates=[0]*(N+1)
for i in range(1,N+1):
    relates[root(i)]+=1


Ans=[]
for j in range(1,N+1):
    ans=relates[root(j)]-1    #高速化可能   #1
    for k in friends[j]:
        if same(j,k):
            ans-=1
    for l in block[j]:
        if same(j,l):   #まとめられる
            ans-=1

    Ans.append(ans)

print(*Ans)

Buggy submission (verdict: Runtime Error):
N,M,K=map(int,input().split())


par=[index for index in range(N+1)]

def root(x):
    global par

    if x==par[x]:
        return x
    else:
        par[x]=root(par[x])
        return par[x]


def same(x,y):
    global par

    if root(x)==root(y):
        return True
    else:
        return False

def unite(x,y):
    global par

    if root(x)!=root(y):
        par[root(x)]=root(y)


friends=[[] for index1 in range(N+1)]
for index2 in range(M):
    a,b=map(int,input().split())
    unite(a,b)
    friends[a].append(b)
    friends[b].append(a)


block=[[] for index3 in range(N+1)]
for index4 in range(K):
    c,d=map(int,input().split())
    block[c].append(d)
    block[d].append(c)


relates=[0]*(N+1)
for i in range(1,N+1):
    relates[root(i)]+=1


Ans=[]
for j in range(1,N+1):
    ans=relates[root(j)]-1    #高速化可能   #1
    for k in friends[j]:
        if same(j,k):
            ans-=1
    for l in block[j]:
        if same(j,l):   #まとめられる
            ans-=1

    Ans.append(ans)

print(*Ans)
Problem p02771 (python)

Fixed submission:
A,B,C=map(int,input().split())

S={A,B,C}

if len(S)==2:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
A,B,C=map(int,input().split())

S=set(A,B,C)

if len(S)==2:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
A,B,C=map(int,input().split())

S=set{A,B,C}

if len(S)==2:
    print('Yes')
else:
    print('No')
Problem p02792 (python)

Fixed submission:
import copy

N=int(input())

def arrange(List,n=N):  #先頭がup末尾がdownの総数をList[up][down]に入れる;Listは10×10で0が入ってる
    for i in range(1,n+1):
        Len=len(str(i))
        up=int(str(i)[0])
        down=int(str(i)[Len-1])
        List[up][down]+=1
    return List

original=[]
component=[]
for x in range(10):
    component.append(0)
for y in range(10):
    original.append(copy.deepcopy(component))


L=arrange(original)

ans=0

for j in range(10):
    for k in range(10):
        ans+=L[j][k]*L[k][j]

print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())

def add(x):
    Len=len(str(x))
    up=int(str(x)[0])
    down=int(str(x)[Len-1])
    R=0
    if down!=0:
        if up<down:
            if Len>=3:
                R+=2*((10**(Len-2)-1)//9)
        elif up>down:
            R+=2*((10**(Len-1)-1)//9)
        else:
            R+=2*(((10**(Len-1)-1)//9)+1)-1
    return int(R)

def ans(y):
    if y==1:
        return 1
    else:
        return ans(y-1)+add(y)

#for i in range(1,N+1):
    #print(i,ans(i))

print(ans(N))
Problem p02820 (python)

Fixed submission:
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=str(input())

rec=[]
ans=0

def win(hand):
    if hand=='r':
        return ['p',P]
    elif hand=='s':
        return ['r',R]
    else:
        return ['s',S]

def gap(hand):
    if hand=='r':
        return 's'
    elif hand=='s':
        return 'p'
    else:
        return 'r'


for i in range(N):
    win_hand=win(T[i])[0]
    win_point=win(T[i])[1]
    same_hand=T[i]
    if 0<=i<=K-1:
        rec.append(win_hand)
        ans+=win_point
    else:
        if win_hand!=rec[i-K]:
            rec.append(win_hand)
            ans+=win_point
        else:
            if N-K-1<i<=N-1:
                rec.append(same_hand)#不要
            else:
                next_win_hand=win(T[i+K])[0]
                rec.append(gap(next_win_hand))

    #print(ans)

#print(rec)
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=str(input())

rec=[]
ans=0

def win(hand):
    if hand=='r':
        return ['p',P]
    elif hand=='s':
        return ['r',R]
    else:
        return ['s',S]

def gap(hand):
    if hand=='r':
        return 's'
    elif hand=='s':
        return 'p'
    else:
        return 'r'


for i in range(N):
    win_hand=win(T[i])[0]
    win_point=win(T[i])[1]
    same_hand=T[i]
    if 0<=i<=K-1:
        rec.append(win_hand)
        ans+=win_point
    else:
        if win_hand!=rec[i-K]:
            rec.append(win_hand)
            ans+=win_point
        else:
            if N-K<i<=N-1:
                rec.append(same_hand)#不要
            else:
                next_win_hand=win(T[i+K])[0]
                rec.append(gap(next_win_hand))

    #print(ans)

#print(rec)
print(ans)
Problem p02847 (python)

Fixed submission:
S=str(input())
L=['SUN','MON','TUE','WED','THU','FRI','SAT']
s=L.index(S)

print(7-s)

Buggy submission (verdict: Runtime Error):
S=str(input())
L=['SUN','MON','TUE','WED','THU','FRI','SAT']
s=L.index(L)

print(7-s)
Problem p02935 (python)

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

V_sorted=sorted(V)

now_value=(V_sorted[0]+V_sorted[1])/2
for i in range(2,N):
    now_value=(now_value+V_sorted[i])/2

print(now_value)

Buggy submission (verdict: Runtime Error):
N=int(input())
V=list(map(input().split()))

V_sorted=sorted(V)

now_value=(V_sorted[0]+V_sorted[1])/2
for i in range(2,N):
    now_value=(now_value+V_sorted[i])/2

print(now_value)

Buggy submission (verdict: Runtime Error):
N=int(input())
V=list(map(input().split()))

V_sorted=sorted(V)

now_value=(V_sorted[0]+V_sorted[1])/2
for i in range(2,N):
    now_value=(now_value+V_sorted[i])/2

print(now_value)

Buggy submission (verdict: Runtime Error):
N=int(input())
V=list(map(input().split()))

V_sorted=sorted(V)

now_value=(V_sorted[0]+V_sorted[1])/2
for i in range(2,N):
    now_value=(new_value+V_sorted[i])/2

print(now_value)
Problem p02951 (python)

Fixed submission:
A,B,C=map(int,input().split())

ans=0

if A-B<C:
    ans=C-(A-B)

print(ans)

Buggy submission (verdict: Runtime Error):
A,B,C=map（int,input().split())

ans=0

if A-B<C:
    ans=C-(A-B)

print(ans)
Problem p02954 (python)

Fixed submission:
#鈴木に教わった

S=str(input())
N=len(S)

ans=[]
for h in range(N):
    ans.append(0)
    
L=[]
count=0
for i in range(N-1):
    if S[i]==S[i+1]:
        count+=1
    else:
        L.append([S[i],count+1])
        count=0

L.append([S[N-1],count+1])

now=0
for j in range(len(L)):
    if L[j][0]=='R':
        now+=L[j][1]
        ans[now]+=L[j][1]//2
        ans[now-1]+=L[j][1]-L[j][1]//2
    else:
        ans[now-1]+=L[j][1]//2
        ans[now]+=L[j][1]-L[j][1]//2
        now+=L[j][1]

print(*ans)

Buggy submission (verdict: Runtime Error):
S=list(input())
N=len(S)
#print(S,N)

T=[0 for _ in range(N)]

for i in range(N):
    if S[i]=='R':
        j=i
        while S[j]=='R':
            j+=1
        if (j-i)%2==0:
            T[j]+=1
        elif (j-i)%==1:
            T[j-1]+=1
    else:
        j=i
        while S[j]=='L':
            j-=1
        if (i-j)%2==0:
            T[j]+=1
        elif (j-i)%2==1:
            T[j+1]+=1

print(T)
Problem p02970 (python)

Fixed submission:
import math

N,D=map(int,input().split())

if N%(2*D+1)==0:
    print(N//(2*D+1))
else:
    print((N//(2*D+1))+1)

Buggy submission (verdict: Runtime Error):
import math

N,D=int(input().split())

if N%(2*D+1)==0:
    print(N//(2*D+1))
else:
    print((N//(2*D+1))+1)
Problem p02990 (python)

Fixed submission:
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N,K=map(int,input().split())

for i in range(1,K+1):
    x=combinations_count(K-1,i-1)
    if N-K+1>=i:
        y=combinations_count(N-K+1,i)
        print((x*y)%1000000007)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N,K=map(int,input().split())

for i in range(1,K+1):
    x=combinations_count(K-1,i-1)
    y=combinations_count(N-K+1,i)
    print((x*y)%1000000007)
Problem p03805 (python)

Fixed submission:
N,M=map(int,input().split())
G=[[False]*(N+1) for _ in range(N+1)]
for i in range(M):
    a,b=map(int,input().split())
    G[a][b]=True
    G[b][a]=True

visited=[False]*(N+1)

visited[1]=True
def dfs(start):
    global N
    global visited
    all_visited=True
    sum=0

    for p in range(1,N+1):
        if not visited[p]:
            all_visited=False

    if all_visited:
        return 1
    else:
        for next in range(1,N+1):#N小より全探索
            if not G[start][next]:
                continue
            if visited[next]:
                continue
            visited[next]=True
            sum+=dfs(next)
            visited[next]=False   #backtrack

        return sum

print(dfs(1))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
G=[[False]*(M+1) for _ in range(N+1)]
for i in range(M):
    a,b=map(int,input().split())
    G[a][b]=True
    G[b][a]=True

visited=[False]*(N+1)

visited[1]=True
def dfs(start):
    global N
    global visited
    all_visited=True
    sum=0

    for p in range(1,N+1):
        if not visited[p]:
            all_visited=False

    if all_visited:
        return 1
    else:
        for next in range(1,N+1):#N小より全探索
            if not G[start][next]:
                continue
            if visited[next]:
                continue
            visited[next]=True
            sum+=dfs(next)
            visited[next]=False   #backtrack

        return sum

print(dfs(1))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
G=[[False]*(M+1) for _ in range(N+1)]
for i in range(M):
    a,b=map(int,input().split())
    G[a][b]=True
    G[b][a]=True

visited=[False]*(N+1)

visited[1]=True
def dfs(start):
    global N
    global visited
    all_visited=True
    sum=0

    for p in range(1,N+1):
        if not visited[p]:
            all_visited=False

    if all_visited:
        return 1
    else:
        for next in range(1,N+1):#N小より全探索
            if not G[start][next]:
                continue
            if visited[next]:
                continue
            visited[next]=True
            sum+=dfs(next)
            visited[next]=False   #backtrack

    return sum

print(dfs(1))
Problem p02659 (python)

Fixed submission:
from decimal import Decimal
a,b = input().split()
print(int(Decimal(a)*Decimal(b)))

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
print(int(a*b))
Problem p02679 (python)

Fixed submission:
from collections import Counter
import math
n = int(input())
pp = []
a0 = 0
b0 = 0
z = 0

for i in range(n):
  a,b = map(int,input().split())
  if a==0 and b==0:
    z += 1
  elif a==0:
    a0 += 1
  elif b==0:
    b0 += 1
  else:
    gomi = math.gcd(a,b)
    if a < 0:
      a *= -1
      b *= -1
    pp.append((a//gomi,b//gomi))
    
mod = 10**9+7
a0 %= mod
b0 %= mod
z %= mod
p = Counter(pp)
r = 1
s = set()

for i,j in p.keys():
  if (i,j) in s:
    continue
  ans = p[(i,j)]
  if j < 0:
    f = (-j,i)
  else:
    f = (j,-i)
  chk = p[f]
  r *= (pow(2,ans,mod)+pow(2,chk,mod)-1)%mod
  r %= mod
  s.add(f)
r *= (pow(2,a0,mod)+pow(2,b0,mod)-1)%mod
r %= mod
print((r+z-1)%mod)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
pp = []
a0 = 0
b0 = 0
z = 0
for i in range(n):
  a,b = map(int,input().split())
  if a==0 and b==0:
    z += 1
  elif a==0:
    a0 += 1
  elif b==0:
    b0 += 1
  else:
    pp.append(round(a/b,16))
    
mod = 10**9+7
a0 %= mod
b0 %= mod
z %= mod
p = Counter(pp)
r = 1
s = set()

for i in p.keys():
  if i in s:
    continue
  ans = p[i]
  f = round(-1/i,16)
  chk = p[f]
  r *= (pow(2,ans,mod)+pow(2,chk,mod)-1)%mod
  r %= mod
  s.add(f)
r *= (pow(2,a0,mod)+pow(2,b0,mod)-1)%mod
r %= mod
print((r+z-1)%mod)
Problem p02729 (python)

Fixed submission:
n,m = [int(i) for i in input().split()]
if n <= 1:
  a = 0
else:
  a = n*(n-1)/2
if m <= 1:
  b = 0
else:
  b = m*(m-1)/2
print(int(a+b))

Buggy submission (verdict: Runtime Error):
n,m = [int(i) for i in input().split()]
if n <= 1:
  a = 0
else:
  a = n*(n-1)/2
if m <= 1:
  b = 0
else:
  b = m*(m-1)/2
print(ab)
Problem p02735 (python)

Fixed submission:
h,w = [int(i) for i in input().split()]
s = []
for i in range(h):
  array = list(input())
  s.append(array)
d = [[float("inf")] * (w) for i in range(h)]
d[0][0]=0
if s[0][0]=='#':
  d[0][0]=1
for i in range(1,w):
  if s[0][i]!=s[0][i-1] and s[0][i]!=s[0][0]:
    d[0][i]=d[0][i-1]+1
  else:
    d[0][i]=d[0][i-1]
for i in range(1,h):
  for j in range(w):
    k=0
    u=0
    if j != 0 :
      if s[i][j]=="#" and s[i][j]!=s[i-1][j]:
        k=1
      if s[i][j]=="#" and s[i][j]!=s[i][j-1]:
        u=1
      d[i][j] = min(d[i-1][j]+k,d[i][j-1]+u)
    elif j == 0 :
      if s[i][0]=="#" and s[i][0]!=s[i-1][0]:
        k=1
      d[i][0] = d[i-1][0]+k

print(d[h-1][w-1])

Buggy submission (verdict: Runtime Error):
def main():
  import sys
  input = sys.stdin.readline
  n = int(input())
  a = list(map(int,input()))
  import copy
  for _ in range(n-1):
    b=[0]*(len(a)-1)
    for i in range(len(a)-1):
      b[i]=abs(a[i]-a[i+1])
      #print(b)
    a = copy.deepcopy(b)
    #print(a)

  print(b[0])
if __name__ == '__main__':
    main()
Problem p02757 (python)

Fixed submission:
import sys
input = sys.stdin.readline
n,p = [int(i) for i in input().split()]
s = input()
ans = 0

import math
def nCr(n, r):
  if n < r:
    return 0
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i + 1
    print(ans)
    exit()

else:
  chk = [0]*p
  chk[0] = 1
  m = 0
  for i in range(n)[::-1]:
    m = (int(s[i])*pow(10,n-1-i,p)+m)%p
    chk[m] += 1
  for i in chk:
    ans += nCr(i,2)
  print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,p = [int(i) for i in input().split()]
s = input()
ans = 0

if p == 2 or p == 5:
  s = list(s)
  for i,si in enumerate(s):
    if int(si)%p == 0:
      ans += i+1
  print(int(ans))
else:
  chk = [0]*p
  chk[0] = 1
  m = 0
  for i in range(n)[::-1]:
    m = (int(s[i])*pow(10,n-1-i)+m)%p
    chk[m] += 1
  for i in chk:
    ans += i*(i-1)/2
  print(int(ans))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,p = [int(i) for i in input().split()]
s = input()
ans = 0

if p == 2 or p == 5:
  s = list(s)
  for i,si in enumerate(s):
    if int(si)%p == 0:
      ans += i+1
  print(int(ans))

else:
  chk = [0]*p
  chk[0] = 1
  m = 0
  for i in range(n)[::-1]:
    m = (int(s[i])*(10**(n-1-i))+m)%p
    #print(i,m)
    chk[m] += 1
  for i in chk:
    ans += i*(i-1)/2
  print(int(ans))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,p = [int(i) for i in input().split()]
s = input()
ans = 0
if p == 2:
  s = list(s)
  for i,si in enumerate(s):
    if int(si)%2 == 0:
      ans += i+1
  print(int(ans))
  exit()

elif p == 5:
  s = list(s)
  for i,si in enumerate(s):
    if int(si)%5 == 0:
      ans += i+1
  print(int(ans))
  exit()

chk = [0]*p
chk[0] = 1

for i in range(1,n):
  m = s[:-i]
  k = int(int(m)%p)
  chk[k] += 1
r = int(int(s)%p)
chk[r] += 1
for i in chk:
  ans += i*(i-1)/2
print(int(ans))

Buggy submission (verdict: Runtime Error):
def main(): 
  import sys
  input = sys.stdin.readline
  n,p = [int(i) for i in input().split()]
  s = input()
  ans = 0
  if p == 2:
    s = list(s)
    for i,si in enumerate(s):
      if int(si)%2 == 0:
        ans += i+1
    print(ans)
    exit()

  elif p == 5:
    s = list(s)
    for i,si in enumerate(s):
      if int(si)%5 == 0:
        ans += i+1
    print(ans)
    exit()

  chk = [0]*p
  chk[0] = 1

  for i in range(1,n):
    m = s[:-i]
    k = int(int(m)%p)
    chk[k] += 1
  r = int(int(s)%p)
  chk[r] += 1
  for i in chk:
    ans += i*(i-1)/2
  print(int(ans))
if __name__ == '__main__':
    main()
Problem p02948 (python)

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
chk = []
for i in range(n):
  a,b =  map(int,input().split())
  if a <= m:
    chk.append((a,b))

from heapq import heappop, heappush
from operator import itemgetter
chk = sorted(chk,key=itemgetter(0),reverse=True)

q = []
ans = 0
for i in range(1, m + 1):
    while chk and chk[-1][0] <= i:
        a,b = chk.pop()
        heappush(q,-b)
    if q:
        ans -= heappop(q)
print(ans)

Buggy submission (verdict: Runtime Error):
from heapq import*
(n,m),*t=[map(int,s.split())for s in open(0)]
q=[0]*m
v=[[]for _ in q]
z=0
for a,b in t:v[a-1]+=[b]
for i in v:
	for j in i:heappush(q,-j)
	z-=heappop(q)
print(z)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
chk = []
for i in range(n):
  a,b =  map(int,input().split())
  if a <= m:
    chk.append((-b,a))

from heapq import heapify, heappop, heappush
from operator import itemgetter
chk = sorted(chk,key=itemgetter(1))

s = []
heapify(s)
ans = 0
if chk == []:
  print(0)
  exit()
  
cnt = 1
for i in chk:
  a,b = i
  if b == cnt:
    heappush(s,i)
  if b > cnt:
    if s != []:
      r,t = heappop(s)
      ans -= r
      heappush(s,i)
    cnt += 1

for i in range(m-cnt+1):
  r,t = heappop(s)
  ans -= r
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
chk = []
for i in range(n):
  a,b =  map(int,input().split())
  if a <= m:
    chk.append((-b,a))

from heapq import heapify, heappop, heappush
from operator import itemgetter
chk = sorted(chk,key=itemgetter(1))

s = []
heapify(s)
ans = 0
if chk == []:
  print(0)
  exit()
  
cnt = chk[0][1]
for i in chk:
  a,b = i
  if b == cnt:
    heappush(s,i)
  if b > cnt:
    r,t = heappop(s)
    ans -= r
    heappush(s,i)
    cnt = b
  
for i in range(m-cnt+1):
  r,t = heappop(s)
  ans -= r    
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
chk = []
for i in range(n):
  a,b =  map(int,input().split())
  if a <= m:
    chk.append((-b,a))

from heapq import heapify, heappop, heappush
from operator import itemgetter
chk = sorted(chk,key=itemgetter(1))
print(chk)
s = []
heapify(s)
ans = 0
cnt = chk[0][1]
for i in chk:
  a,b = i
  if b == cnt:
    heappush(s,i)
  if b > cnt:
    r,t = heappop(s)
    ans -= r
    heappush(s,i)
    cnt = b
    
r,t = heappop(s)
ans -= r    
print(ans)
Problem p02954 (python)

Fixed submission:
s = input()
if len(s) == 2:
  print(1,1)
  exit()
chk = [0]*len(s)
cntR = 1
r = 0
cntL = 0
for i in range(len(s)-1):
  if s[i] == 'R' and s[i+1] == 'L':
    r = i
    chk[r] += (cntR+1)//2
    chk[r+1] += (cntR)//2
    cntL = 1
  if s[i] == 'R' and s[i+1] == 'R':
    cntR += 1
  if s[i] == 'L' and s[i+1] == 'L':
    cntL += 1
  if s[i] == 'L' and s[i+1] == 'R':
    chk[r] += (cntL)//2
    chk[r+1] += (cntL+1)//2
    cntL = 0
    cntR = 1
chk[r] += (cntL)//2
chk[r+1] += (cntL+1)//2
chk = list(map(str,chk))
print(' '.join(chk))

Buggy submission (verdict: Runtime Error):
s = input().split()
if len(s) == 2:
  print(1,1)
  exit()
chk = [0]*len(s)
cntR = 1
r = 0
cntL = 0
for i in range(len(s)-1):
  if s[i] == 'R' and s[i+1] == 'L':
    r = i
    chk[r] += (cntR+1)//2
    chk[r+1] += (cntR)//2
    cntL = 1
  if s[i] == 'R' and s[i+1] == 'R':
    cntR += 1
  if s[i] == 'L' and s[i+1] == 'L':
    cntL += 1
  if s[i] == 'L' and s[i+1] == 'R':
    chk[r] += (cntL)//2
    chk[r+1] += (cntL+1)//2
    cntL = 0
    cntR = 1
chk[r] += (cntL)//2
chk[r+1] += (cntL+1)//2
chk = list(map(str,chk))
print(' '.join(chk))

Buggy submission (verdict: Runtime Error):
s = input().split()
if len(s) == 2:
  print(1,1)
  exit()
chk = [0]*len(s)
cntR = 1
r = 0
cntL = 0
for i in range(len(s)-1):
  if s[i] == 'R' and s[i+1] == 'L':
    r = i
    chk[r] += (cntR+1)//2
    chk[r+1] += (cntR)//2
    cntL = 1
  if s[i] == 'R' and s[i+1] == 'R':
    cntR += 1
  if s[i] == 'L' and s[i+1] == 'L':
    cntL += 1
  if s[i] == 'L' and s[i+1] == 'R':
    chk[r] += (cntL)//2
    chk[r+1] += (cntL+1)//2
    cntL = 0
    cntR = 1
chk[r] += (cntL)//2
chk[r+1] += (cntL+1)//2
chk = list(map(str,chk))
print(' '.join(chk))
Problem p03033 (python)

Fixed submission:
import sys
from bisect import bisect_left

n,q = map(int, input().split())
lines = sys.stdin.readlines()
c = []
for line in lines[:n]:
    s,t,x = map(int, line.split())
    c.append((x,s,t))
c.sort()
d = list(map(int,lines[n:]))

ans = [-1] * q
skip = [-1] * q
for x,s,t in c:
    ss = bisect_left(d,s-x)
    tt = bisect_left(d,t-x)
    while ss < tt:
        if skip[ss] == -1:
            ans[ss] = x
            skip[ss] = tt
            ss += 1
        else:
            ss = skip[ss]
print(*ans,sep='\n')

Buggy submission (verdict: Runtime Error):
import sys
from bisect import bisect_left

n, q = map(int, input().split())
lines = sys.stdin.readlines()
c = []
for line in lines[:n]:
    s, t, x = map(int, line.split())
    c.append((x, s, t))
kkk.sort()
d = list(map(int, lines[n:]))

ans = [-1] * q
skip = [-1] * q
for x, s, t in k:
    ss = bisect_left(d, s - x)
    tt = bisect_left(d, t - x)
    while ss < tt:
        if skip[ss] == -1:
            ans[ss] = x
            skip[ss] = tt
            ss += 1
        else:
            ss = skip[ss]
print(*ans,sep='\n')