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

Fixed submission:
import itertools
mylist = [0, 1]
n = int(input().rstrip())

mise = [list(map(int, input().rstrip().split())) for i in range(n)]
mine = [list(map(int, input().rstrip().split())) for i in range(n)]

maxnum = - float('inf')
for i in itertools.product(mylist, repeat = 10):
    if sum(i) == 0:
        continue
    sell = 0
    for j, k in zip(mise, mine):
        temp = 0
        for l in range(10):
            if j[l] == i[l] and j[l] == 1:
                temp += 1
        sell += k[temp]
    maxnum = max(maxnum, sell)
print(maxnum)

Buggy submission (verdict: Runtime Error):
import itertools
import numpy as np
mylist = [0, 1]
n = int(input().rstrip())

mise = [list(map(int, input().rstrip().split())) for i in range(n)]
mine = [list(map(int, input().rstrip().split())) for i in range(n)]

maxnum = - float('inf')
for i in itertools.product(mylist, repeat = 10):
    if sum(i) == 0:
        continue
    sell = 0
    for j, k in zip(mise, mine):
        temp = 0
        for l in range(10):
            if j[l] == i[l] and j[l] == 1:
                temp += 1
        sell += k[temp]
    maxnum = max(maxnum, sell)
print(maxnum)
Problem p03557 (python)

Fixed submission:
#関数リスト
import sys
import bisect
input = sys.stdin.readline
def RD(): return input().rstrip()
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]

def main():
    N = I()
    A = LI()
    A.sort()
    B = LI()
    B.sort()
    B_len = len(B)
    C = LI()
    C.sort()
    C_len = len(C)
    result = 0
    A_init = A[0]
    index = 0
    next_i = index
    
    for i in B:
        tempA = bisect.bisect_left(A,i) 
        tempC = C_len - bisect.bisect_right(C,i)
        result += tempA*tempC
    print(result)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#関数リスト
import sys
from bisect import bisect
input = sys.stdin.readline
def RD(): return input().rstrip()
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]

def main():
    N = I()
    A = LI()
    A.sort()
    B = LI()
    B.sort()
    B_len = len(B)
    C = LI()
    C.sort()
    C_len = len(C)
    result = 0
    A_init = A[0]
    for i in A:
        index = bisect(B,i)
        if index == B_len:
            break
        for j in range(index, B_len):
            index2 = bisect(C,B[j]
            if index2 == C_len:
                break
            result += C_len - index2
    print(result)

if __name__ == "__main__":
    main()
Problem p02554 (python)

Fixed submission:
n = int(input())
mod = 10**9+7
a = 10**n-9**n-9**n+8**n
print(a%mod)

Buggy submission (verdict: Runtime Error):
N = int(input())
mod = 10**9+7
if N == 1:
  print(0)
elif N == 2:
  print(2)
else:
  ans = 10*8*6*(10**(3(N-3)))
  print((ans*2)%mod)

Buggy submission (verdict: Runtime Error):
N = int(input())
mod = 10**9+7
if N == 1:
  print(0)
elif N == 2:
  print(2)
else:
  ans = 10*8*6*10**(3(N-3))*2
  print(ans%mod)

Buggy submission (verdict: Runtime Error):
N = int(input())
mod = 10** + 7
if N == 1:
  print(0)
else:
  ans = N*10**(n-2)
  print(ans%mod)
Problem p02576 (python)

Fixed submission:
N,X,T = map(int,input().split())
count = 1
while N > X:
  N = N - X
  count += 1
print(T*count)

Buggy submission (verdict: Runtime Error):
N,X,T = map(int,input().split())
count=0
if N <=X:
  print(T)
  break
elif N > X:
  while N > X:
    N = N - X
    count+=1
  print(T*count)
Problem p02628 (python)

Fixed submission:
n,k = map(int,input().split())
p = sorted(list(map(int,input().split())))
total = 0
for i in range(k):
  total += p[i]
print(total)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
p = sorted([int(input()) for i in range(n)])
count=0
for i in range(k):
  count = count+p[i]
print(count)
Problem p02658 (python)

Fixed submission:
n = int(input())
cnt = 1
l = list(map(int, input().split()))
if 0 in l:
    print(0)
else:
    for i in l:
        cnt *= i
        if cnt > 10 ** 18:
            print(-1)
            exit()
        else:
            pass
    print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
if 0 in a:
  total = 0
else:
  total=1
  for i in a:
    total *= i
    if total > 10**8:
      total = -1
      break
print(total)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
if 0 in a:
  total = 0
  break
else:
  total=1
  for i in a:
    total *= i
    if total > 10**8:
      total = -1
      break
print(total)
Problem p02694 (python)

Fixed submission:
X = int(input())
year = 0
deposit = 100
while deposit < X:
    deposit = deposit*101//100
    year += 1
print(year)

Buggy submission (verdict: Runtime Error):
X = int(input())
deposit = 100
year = 0
while (deopsit<X):
  deposit = deposit*101//100
  year += 1
print(year)
Problem p02718 (python)

Fixed submission:
n,m = map(int,input().split())
a = sorted(list(map(int,input().split())),reverse=True)
b = sum(a)/(4*m)
c=[]
for i in a[:m]:
  if i >= b:
    c.append(i)

if len(c) == m:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = sorted(list(map(int,input().split())))
a_list=[]
for i in a[:m]:
  if sum(a)/(a*m) > i:
    print('No')
    exit()
  else:
    a_list.append(i)
print('Yes')
Problem p02772 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans=0
ans2=0
for i in a:
  if i % 2 == 0:
    ans +=1
    if i % 3 == 0 or i % 5 == 0:
      ans2 +=1
if ans == ans2:
  print('APPROVED')
else:
  print('DENIED')

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [i for i in map(int,input().split())]
Check = Fasle
check_list=[]
for s in range(n):
  if a[s]%2 == 0:
    check_list.append(a[s])
for t in range(len(check_list)):
  if check_list[t]%3 == 0 or check_list[t]%5==0:
    Check =True
if Check:
  print('APPROVED')
else:
  print('DENIED')
Problem p02886 (python)

Fixed submission:
N = int(input())
D = list(map(int,input().split()))
count=0
for i in range(N-1):
  for j in D[i+1:]:
    A = D[i]*j
    count+=A
print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
D = map(int,input().split())
count=0
for i in range(N):
  for j in D[i+1:]:
    A = D[i]*j
    count+=A
print(A)

Buggy submission (verdict: Runtime Error):
N = int(input())
D = list(map(int,input().split()))
count=0
for i in range(N):
  for j in d[i+1:]:
    A = d[i]*j
    count+=A
print(A)
Problem p02909 (python)

Fixed submission:
weather = ["Sunny","Cloudy","Rainy"]
S = input()
print(weather[(weather.index(S)+1)%3])

Buggy submission (verdict: Runtime Error):
weather = ["Sunny","Cloudy","Rainly"]
S = input()
print(weather[(weather.index(S)+1)%3])

Buggy submission (verdict: Runtime Error):
weather = ["Sunny","Cloudy","Rainly"]
S = input()
print(wether[(weather.index(S)+1)%3])
Problem p02922 (python)

Fixed submission:
import math
A,B = map(int,input().split())
print(1+math.ceil((B-A)/(A-1)))

Buggy submission (verdict: Runtime Error):
A, B = map(int,input().split())
con,out = 0,1
for out < B:
  out = out -1
  out = out + A
  con += 1
print(con)
Problem p02934 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
total=0
for i in a:
  total += 1/i
print(1/total)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
total=0
for i in a:
  total += 1/a
print(1/total)
Problem p02946 (python)

Fixed submission:
K,X = map(int,input().split())
for i in range(X-K+1,K+X):
  print(i,end=" ")

Buggy submission (verdict: Runtime Error):
K,X = map(int,input().split())
for i in range((K-X+1):(K+X)):
  print(i,end=" ")
Problem p02969 (python)

Fixed submission:
a = int(input())
print(3*a**2)

Buggy submission (verdict: Runtime Error):
print(3*((int(input())**2))
Problem p02994 (python)

Fixed submission:
n, l = map(int, input().split())
a = []
b = []
for i in range(1,n+1):
    a.append(l+i-1)
    b.append(abs(l+i-1))
x = b.index(min(b))
print(sum(a)-a[x])

Buggy submission (verdict: Runtime Error):
N,L = map(int,input().split())
l = []
ll = []
for i in range(1,N+1):
  l.append(L+i-1)
  ll.append(abs(L+i-1))
a = l.index(min(ll))
print(sum(l)-l[a])

Buggy submission (verdict: Runtime Error):
N,L = map(int,input().split())
l = []
ll = []
for i in range(1,N+1):
  l.append(L+i-1)
  ll.append(abs(L+i-1))
a = l.index(min(ll))
print(sum(l)-a)
Problem p03000 (python)

Fixed submission:
n,x = map(int,input().split())
l = list(map(int,input().split()))
d = 0
count=1
for i in range(n):
  d += l[i]
  if d<=x:
    count+=1
print(count)

Buggy submission (verdict: Runtime Error):
n,x = map(int,input().split())
l = list(map(int,input().split()))
d = 0
count=1
for i in range(n):
  d += n[i]
  if d<=x:
    count+=1
print(count)
Problem p03030 (python)

Fixed submission:
n = int(input())
L=[]
for i in range(n):
  s,p=input().split()
  L.append([s,-int(p),i+1])
list.sort(L)
for i in range(n):
  print(L[i][2])

Buggy submission (verdict: Runtime Error):
n = int(input())
L=[]
for i in range(n):
  s,p=input()
  L.append([s,int(p),i+1])
list.sort(L,reverse=True)
for i in range(n):
  print(L[i][2])
Problem p03105 (python)

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

Buggy submission (verdict: Runtime Error):
A,B,C = map(int,input().split())
print(min(B//A,C)
Problem p03136 (python)

Fixed submission:
input()
L = list(map(int, input().split()))
print("Yes" if sum(L) > 2*max(L) else "No")

Buggy submission (verdict: Runtime Error):
N = input()
L = [int(input()) for i in range(N)]
print("Yes" if sum(L) > 2*max(L) else "No")

Buggy submission (verdict: Runtime Error):
N = int(input())
L = [int(input()) for i in range(N)]
print('Yes' if sum(L)-max(L) > max(L) and sum(L) -max(L) == max(L) + 1 else 'No')

Buggy submission (verdict: Runtime Error):
N = int(input())
L = [int(input()) for i in range(N)]
print('Yes' if sum(L)-max(L) > max(L) else 'No')
Problem p03280 (python)

Fixed submission:
A,B = map(int,input().split())
print(A*B-(A+B-1))

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
print(A*B-(A+B-1))
Problem p03292 (python)

Fixed submission:
a,b,c = sorted(map(int,input().split()))
print(c-b + b-a)

Buggy submission (verdict: Runtime Error):
*a = map(int,input().split())
print(max(a)-min(a))
Problem p03408 (python)

Fixed submission:
n=[input() for _ in range(int(input()))]
m=[input() for _ in range(int(input()))]
l=list(set(n))
print(max(0,max(n.count(l[i])-m.count(l[i]) for i in range(len(l)))))

Buggy submission (verdict: Runtime Error):
n = [int(input()) for i in range(int(input()))]
m = [int(input()) for i in range(int(input()))]
l = list(set(n))
print(max(0,(n.count(l[i])-m.count(l[i])) for i in range(len(l))))

Buggy submission (verdict: Runtime Error):
n = [int(input()) for i in range(int(input()))]
m = [int(input()) for i in range(int(input()))]
print(max(len(set(n))-len(set(m)),0))

Buggy submission (verdict: Runtime Error):
n = [int(input()) for i in range(int(input()))]
m = [int(input()) for i in range(int(input()))]
print(min(len(set(n))-len(set(m)),0))
Problem p03469 (python)

Fixed submission:
S = input()
print('2018' + S[4:])

Buggy submission (verdict: Runtime Error):
S = input()
S[3:4] = '8'
print(S)
Problem p03470 (python)

Fixed submission:
print(len(set([int(input()) for _ in range(int(input()))])))

Buggy submission (verdict: Runtime Error):
N = int(input())
d = [int(input()) for i in N]
print(len(set(d)))

Buggy submission (verdict: Runtime Error):
N = int(input())
d = [int(input()) for i in N]
print(set(d))

Buggy submission (verdict: Runtime Error):
N = int(input())
d = list([int(input()) for i in range(N)])
print(d.count())
Problem p03485 (python)

Fixed submission:
import math
a,b = map(int,input().split())
print(math.ceil((a+b)/2))

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
import math
print(math.ceil((a+b)/2)
Problem p03543 (python)

Fixed submission:
a,b,c,d = input()
print('Yes' if a == b == c or b == c == d else 'No')

Buggy submission (verdict: Runtime Error):
a,b,c,d = input().split()
print('Yes' if a == b == c or b == c == d or a == b == d or a == c == d else 'No')
Problem p03545 (python)

Fixed submission:
A = input()
n = len(A)-1
for i in range(2**n):
  pn = ['-']*n
  for j in range(n):
    if ((i>>j)&1):
      pn[n-1-j] = '+'
  ans = A[0]+pn[0]+A[1]+pn[1]+A[2]+pn[2]+A[3]
  
  if eval(ans) == 7:
    print(ans+'=7')
    break

Buggy submission (verdict: Runtime Error):
a,b,c,d = input().split()
pm = '+-'
for i in pm:
  for j in pm:
    for k in pm:
      total = a+i+b+j+c+k+d
      if eval(total) == 7:
        print(total+'=7')
        exit()
Problem p03556 (python)

Fixed submission:
N = int(input())
x = int(N**(1/2))
print(x*x)

Buggy submission (verdict: Runtime Error):
N = int(input())
print(int(N**(0.5))
Problem p03605 (python)

Fixed submission:
N = input()
if "9" in N:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
if N in 9:
  print("Yes")
else:
  print("No")
Problem p03610 (python)

Fixed submission:
s = input()
print(s[::2])

Buggy submission (verdict: Runtime Error):
s = input()
a = int(len(s))
x = []
while i <= a:
  if i == 0:
    i = 1
    x.append(s[i])
  else:
    i += 2
    x.append(s[i])
print(x,end=',')
Problem p03635 (python)

Fixed submission:
n,m = map(int,input().split())
print((n-1)*(m-1))

Buggy submission (verdict: Runtime Error):
print((int(input())-1)*(int(input())-1))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
pritn(n+m-1)

Buggy submission (verdict: Runtime Error):
n = int(input())
m = int(input())
print(n+m-1)

Buggy submission (verdict: Runtime Error):
n = int(input())
m = int(input())
print(n*m - 1)
Problem p03636 (python)

Fixed submission:
a = input()
print(a[0]+str(len(a)-2)+a[-1])

Buggy submission (verdict: Runtime Error):
a,*b,c = input().split()
print(a+str(len(b))+c)

Buggy submission (verdict: Runtime Error):
a,*b,c = input().split()
print(a+len(b)+c)
Problem p03671 (python)

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

Buggy submission (verdict: Runtime Error):
abc=lint(map(int,input().split()))
print(sum(sorted(abc)[:2]))
Problem p03777 (python)

Fixed submission:
a,b = input().split()
print('H' if a==b else 'D')

Buggy submission (verdict: Runtime Error):
a,b == input().split()
print("H" if a == b else "D")
Problem p03860 (python)

Fixed submission:
print("A"+input()[8]+"C")

Buggy submission (verdict: Runtime Error):
a,b,c=map(input().split())
print(a[0]+b[0]+c[0])
Problem p04001 (python)

Fixed submission:
S = input()

res_list = []

for i in range(2**(len(S)-1)):
    temp_s = ''
    for j in range(len(S)):
        temp_s += S[j]
        if ((i >> j) & 1):
            temp_s += '+'
    # print(temp_s)
    res_list.append(temp_s)

temp_S_list = [eval(item) for item in res_list]

print(sum(temp_S_list))

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s-1)
total=0
for i in range(2**n):
  pl=['']*n
  ans=''
  for j in range(n):
    if ((i>>j)&1):
      pl[n-1-j] = '+'
  for k in range(n):
    ans += s[k]+pl[k]
  ans+=s[-1]
  total += eval(ans)

print(total)
Problem p04044 (python)

Fixed submission:
n,l = map(int,input().split())
s = sorted([input() for i in range(n)])
print(*s,sep='')

Buggy submission (verdict: Runtime Error):
n,l = map(int,input().ssplit())
s = sorted([input() for i in range(n)])
print(*s,sep="")

Buggy submission (verdict: Runtime Error):
n,l = map(int,input().ssplit())
s = sorted([int(input()) for i in range(n)])
print(*s,sep="")

Buggy submission (verdict: Runtime Error):
N,L = map(int,input().split())
s = sorted([int(innput()) for i in range(N)])
print(*s,sep="")
Problem p02658 (python)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]

abc=0

for i in range(n):
	if(a[i]==0):
		abc=1
		break
if(abc==1):
	print(0)
else:
	ans=1
	for i in range(n):
		ans*=a[i]
		if(ans>1000000000000000000):
			break

	if(ans>1000000000000000000):
		print(-1)
	else:
		print(ans)

Buggy submission (verdict: Runtime Error):
n = long(input())
a = [long(x) for x in input().split()]

ans=1
for i in range(n):
	ans*=a[i]
	if(ans>1000000000000000000):
		break;
	if(ans==0):
		break;

if(ans>1000000000000000000):
	print(-1)
else:
	print(ans)
Problem p02615 (python)

Fixed submission:
import sys
import math
import collections
import heapq

def set_debug(debug_mode=False):
    if debug_mode:
        fin = open('input.txt', 'r')
        sys.stdin = fin


def int_input():
    return list(map(int, input().split()))


if __name__ == '__main__':
    # set_debug(True)

    # t = int(input())
    t = 1

    for ti in range(1, t + 1):
        n = int(input())

        A = int_input()

        A.sort()

        res = A[-1]
        for i in range(len(A)-2):
            res += A[-(i//2)-2]
        print(res)

Buggy submission (verdict: Runtime Error):
import sys
import math
import collections
import heapq

def set_debug(debug_mode=False):
    if debug_mode:
        fin = open('input.txt', 'r')
        sys.stdin = fin


def int_input():
    return list(map(int, input().split()))


if __name__ == '__main__':
    set_debug(True)

    # t = int(input())
    t = 1

    for ti in range(1, t + 1):
        n = int(input())

        A = int_input()

        A.sort(reverse=True)

        res = sum(A[:-1])

        print(res)
Problem p02765 (python)

Fixed submission:
n, k = map(int, input().split())
if n >= 10:
  print(k)
else:
  print(k + 100 * (10-n))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
if n >= 10:
  return k
else:
  return n + 100 * (10-k)
Problem p02741 (python)

Fixed submission:
K=int(input())
list=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(list[K-1])

Buggy submission (verdict: Runtime Error):
import math
A=[float(a) for a in input().split()]
a=math.sqrt(A[0])
b=math.sqrt(A[1])
c=math.sqrt(A[2])
B=('%.1000f'%(a+b))
C=('%.1000f'%c)
if (B) < C:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import math
A=[float(a) for a in input().split()]
if round(math.sqrt(A[0],100))+round(math.sqrt(A[1],100))<round(math.sqrt(A[2],100)):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
A = [int(a) for a in input().split()]
masu=int((A[0]*A[1]/2)+0.5)
if A[1]==1 or A[0]==1:
    print(1)
else:
    print(masu)
Problem p02537 (python)

Fixed submission:
import sys
input = sys.stdin.readline

n,k = map(int, input().split())
As = [int(input()) for i in range(n)]

# N: 処理する区間の長さ

INF = 0

mx = 300001
LV = (mx-1).bit_length()
N0 = 2**LV
data = [INF]*(2*N0)
lazy = [None]*(2*N0)

# 伝搬対象の区間を求める
def gindex(l, r):
    L = (l + N0) >> 1; R = (r + N0) >> 1
    lc = 0 if l & 1 else (L & -L).bit_length()
    rc = 0 if r & 1 else (R & -R).bit_length()
    for i in range(LV):
        if rc <= i:
            yield R
        if L < R and lc <= i:
            yield L
        L >>= 1; R >>= 1

# 遅延伝搬処理
def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if v is None:
            continue
        lazy[2*i-1] = data[2*i-1] = lazy[2*i] = data[2*i] = v
        lazy[i-1] = None

# 区間[l, r)をxで更新
def update(l, r, x):
    *ids, = gindex(l, r)
    propagates(*ids)

    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] = data[R-1] = x
        if L & 1:
            lazy[L-1] = data[L-1] = x
            L += 1
        L >>= 1; R >>= 1
    for i in ids:
        data[i-1] = max(data[2*i-1], data[2*i])

# 区間[l, r)内の最小値を求める
def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r

    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R-1])
        if L & 1:
            s = max(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

update(As[0],As[0]+1,1)
for i, a in enumerate(As[1:]):
    l = max(0,a-k)
    r = min(mx,a+k)
    upd = query(l,r+1)
    if upd == -1:continue
    # print("i",i,"a",a,"upd",upd,"l",l,"r",r)
    update(a, a+1, upd+1)

ans = 0
for a in set(As):
    ans = max(ans,query(a,a+1))
print(ans)

Buggy submission (verdict: Runtime Error):
# セグメント木
# segment tree
import sys
input = sys.stdin.readline

class segmented_tree:
    X_unit = 0
    X_f = lambda self, a, b: max(a,b)
    def __init__(self, N):
        self.N = N
        self.X = [self.X_unit] * (2*N)
        
    def build(self, seq):
        for i, x in enumerate(seq, self.N):
            self.X[i] = x 
        # 後ろから入れていく
        for i in range(self.N-1, 0, -1):
            self.X[i] = self.X_f(self.X[i<<1], self.X[i<<1|1])

    # 1点更新
    def set_val(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.X_f(self.X[i<<1],self.X[i<<1|1])
    
    # 区間取得
    def fold(self, l, r):
        l += self.N
        r += self.N
        vl = self.X_unit
        vr = self.X_unit
        # 外から決めていく
        while l < r:
            # print(l,r)
            if l & 1:
                vl = self.X_f(vl, self.X[l])
                l += 1
            if r & 1:
                r -= 1
                vr = self.X_f(vr, self.X[r])
            l >>= 1
            r >>= 1
        return self.X_f(vl,vr)
n,k = map(int, input().split())
As = [int(input()) for i in range(n)]
mx = 300001
ans = 0
sg = segmented_tree(mx)

for i, a in enumerate(As):
    l = max(0,a-k)
    r = min(mx,a+k)
    upd = sg.fold(l,r+1)
    sg.set_val(a, upd+1)
    ans = max(ans, upd+1)
print(ans)
Problem p02579 (python)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
ch, cw = map(int, input().split())
dh_, dw_ = map(int, input().split())

fs = []
for i in range(H):
    r = list(input())
    fs.append(r)

walks = [(-1,0),(1,0),(0,1),(0,-1)]
magics = []
for i in range(-2,3):
    for j in range(-2,3):
        if i==j==0:continue
        if (i,j) not in walks:
            magics.append((i,j))

INF = 1 << 50
dps = [[INF]*W for i in range(H)]
dps[ch-1][cw-1] = 0
q = deque([])
q.appendleft((ch-1,cw-1,0))
while len(q)>0:
    h,w,cnt = q.popleft()
    if cnt > dps[h][w]:continue
    dps[h][w] = cnt
    for dh, dw in walks:
        hn = h + dh
        wn = w + dw
        if 0<=hn<H and 0<=wn<W:
            if dps[hn][wn] != INF:continue
            if fs[hn][wn] == ".":
                q.appendleft((hn, wn, cnt))
    for dh, dw in magics:
        hn = h + dh
        wn = w + dw
        if 0<=hn<H and 0<=wn<W:
            if dps[hn][wn] != INF:continue
            if fs[hn][wn] == ".":
                q.append((hn, wn, cnt+1))

ans = dps[dh_-1][dw_-1]
print(ans if ans != INF else -1)

Buggy submission (verdict: Runtime Error):
## dijkstraで解く

from collections import deque
import heapq

H, W = map(int, input().split())
ch, cw = map(int, input().split())
dh_, dw_ = map(int, input().split())

fs = []
for i in range(H):
    r = list(input())
    fs.append(r)

INF = 1 << 10
N = 10**4
dps = [[INF]*W for i in range(H)]
dps[ch-1][cw-1] = 0

heapq.heappush(q,(0, (ch-1)*N+(cw-1)))
while q:
    cnt, n  = heapq.heappop(q)
    h,w = divmod(n, N)
    if cnt > dps[h][w]:continue
    dps[h][w] = cnt
    # 歩いた
    for dh in range(-2,3):
        for dw in range(-2,3):            
            hn = h + dh
            wn = w + dw

            if not 0 <= wn < W: continue
            if not 0 <= hn < H: continue
            if fs[hn][wn] == "#": continue
            if dps[hn][wn] != INF:continue
            if abs(dh) + abs(dw) <= 1:
                heapq.heappush(q, (cnt, hn*N+wn))
            else:
                heapq.heappush(q, (cnt+1, hn*N+wn))

ans = dps[dh_-1][dw_-1]
print(ans if ans != INF else -1)