ZhenlongDai/ACPR huggingface dataset:
Problem: p03419
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction



mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]









n,m=l()
if(n<=2 and m<=2):
    print(0)
    exit()
if(n==2):
    print((m-2)*2)
    exit()
if(m==2):
    print((n-2)*2)
    exit()
print(max(1,n-2)*max(1,m-2))



Failing test case input:
124 0

Expected output:
-244


Actual output:
122


Fixed submission (verdict: Accepted):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction



mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]









n,m=l()
if(n>m):
    n,m=m,n
if(n==1 and m==1):
    print(1)
    exit()
if(n==1 and m!=1):
    print(m-2)
    exit()
print((n-2)*(m-2))
Problem: p03419
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction



mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]









n,m=l()
if(n<=2 and m<=2):
    print(0)
    exit()
if(n==2):
    print((m-2)*2)
    exit()
if(n==2):
    print((m-2)*2)
    exit()
print(max(1,n-2)*max(1,m-2))



Failing test case input:
115 0

Expected output:
-226


Actual output:
113


Fixed submission (verdict: Accepted):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction



mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]









n,m=l()
if(n>m):
    n,m=m,n
if(n==1 and m==1):
    print(1)
    exit()
if(n==1 and m!=1):
    print(m-2)
    exit()
print((n-2)*(m-2))

Problem: p03419
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split(" "))

if M > N:
    tmp = N
    M = N
    N = tmp

if N == 1 and M == 1: print(1)
elif M == 1: print(N-2)
else: print((N-2)*(M-2))

Failing test case input:
128 131

Expected output:
16254


Actual output:
15876


Fixed submission (verdict: Accepted):
N, M = map(int, input().split(" "))

if M > N:
    tmp = M
    M = N
    N = tmp

if N == 1 and M == 1: print(1)
elif M == 1: print(N-2)
else: print((N-2)*(M-2))
Problem: p03291
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s = input()

ans = 0

rc = [0]
rq = [0]
la = [0]
lq = [0]
q3 = [1]
t = 10**9+7

for i in range(len(s)-1):
    if s[len(s)-i-1]=='C':
        rc.append(rc[-1]+1)
        rq.append(rq[-1])
    elif s[len(s)-i-1]=='?':
        rc.append(rc[-1])
        rq.append(rq[-1]+1)
    else:
        rc.append(rc[-1])
        rq.append(rq[-1])
    if s[i]=='A':
        la.append(la[-1]+1)
        lq.append(lq[-1])
    elif s[i]=='?':
        la.append(la[-1])
        lq.append(lq[-1]+1)
    else:
        la.append(la[-1])
        lq.append(lq[-1])
    q3.append(q3[-1] * 3 % t)
rc.reverse()
rq.reverse()

for i in range(len(s)):
    if s[i]=='B' or s[i]=='?':
        l = q3[lq[i]-1]
        r = q3[rq[i]-1]
        ans += l*r*(3*la[i]+lq[i])*(3*rc[i]+rq[i]) % t

print(int(ans%t))


Failing test case input:
@<B@=>A>C?@B;@AA=???==A<?

Expected output:
1116


Actual output:
169180303


Fixed submission (verdict: Accepted):
s = input()

ans = 0

rc = [0]
rq = [0]
la = [0]
lq = [0]
q3 = [1]
t = 10**9+7

for i in range(len(s)-1):
    if s[len(s)-i-1]=='C':
        rc.append(rc[-1]+1)
        rq.append(rq[-1])
    elif s[len(s)-i-1]=='?':
        rc.append(rc[-1])
        rq.append(rq[-1]+1)
    else:
        rc.append(rc[-1])
        rq.append(rq[-1])
    if s[i]=='A':
        la.append(la[-1]+1)
        lq.append(lq[-1])
    elif s[i]=='?':
        la.append(la[-1])
        lq.append(lq[-1]+1)
    else:
        la.append(la[-1])
        lq.append(lq[-1])
    q3.append(q3[-1] * 3 % t)
rc.reverse()
rq.reverse()

q3.append(1/3)

for i in range(len(s)):
    if s[i]=='B' or s[i]=='?':
        l = q3[lq[i]-1]
        r = q3[rq[i]-1]
        ans += l*r*(3*la[i]+lq[i])*(3*rc[i]+rq[i]) % t

print(round(ans%t))

Problem: p03291
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def we_love_abc(S: str)->int:
    ABC = 'ABC'

    dp = [0, 0, 0, 0]
    dp[3] = 1

    for c in reversed(S):
        if c == '?':
            m, m1, m2 = 3, 3, 1
        else:
            m, m1, m2 = 1, 1, 0
        for j in range(3):
            
            
            if c == ABC[j]:
                m2 = 1
            dp[j] = m1 * dp[j] + m2 * dp[j+1]
        
        dp[3] = m * dp[3]

    return dp[0] % 1000000007


if __name__ == "__main__":
    S = input()
    ans = we_love_abc(S)
    print(ans)


Failing test case input:
?>????>??@??C;?>@B@?@=?>?

Expected output:
28579716


Actual output:
36551331


Fixed submission (verdict: Accepted):
def we_love_abc(S: str)->int:
    ABC = 'ABC'
    MOD = 1000000007

    dp = [0, 0, 0, 0]
    dp[3] = 1

    for c in reversed(S):
        for j in range(3):
            m1 = 3 if c == '?' else 1
            m2 = 1 if c == '?' or c == ABC[j] else 0
            dp[j] = (m1 * dp[j] + m2 * dp[j+1]) % MOD
        dp[3] = (3 if c == '?' else 1) * dp[3]
        dp[3] %= MOD

    return dp[0] % MOD


if __name__ == "__main__":
    S = input()
    ans = we_love_abc(S)
    print(ans)
Problem: p03291
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
N = len(S)
MOD = 10 ** 9 + 7

dp = [0, 0, 0, 0]
dp[0] = 1

for s in S:
    factor = 3 if s == '?' else 1
    for j, c in zip([2, 1, 0], 'CBA'):
        dp[j + 1] = dp[j + 1] * factor % MOD
        if s == c or s == '?':
            dp[j + 1] += dp[j]
    if s == '?':
        dp[0] = dp[0] % MOD

ans = dp[-1] % MOD

print(ans)

Failing test case input:
?D@@=?A?<>?B;?@B@>=A>=>9?

Expected output:
2808


Actual output:
830


Fixed submission (verdict: Accepted):
S = input()
N = len(S)
MOD = 10 ** 9 + 7

dp = [0, 0, 0, 0]
dp[0] = 1

for s in S:
    factor = 3 if s == '?' else 1
    for j, c in zip([2, 1, 0], 'CBA'):
        dp[j + 1] = dp[j + 1] * factor % MOD
        if s == c or s == '?':
            dp[j + 1] += dp[j]
    if s == '?':
        dp[0] = (dp[0] * 3) % MOD

ans = dp[-1] % MOD

print(ans)

Problem: p03291
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import accumulate as ac
s=input()
n=len(s)
mod=int(1e9)+7

*aca,=ac([0]+[1 if i=="A" else 0 for i in s])
*acc,=ac([0]+[1 if i=="C" else 0 for i in s])
*acq,=ac([0]+[1 if i=="?" else 0 for i in s])

v=0
for i in range(1,n-1):
  if s[i]=="B" or s[i]=="?":
    a=aca[i]
    l=acq[i]
    c=acc[n]-acc[i+1]
    r=acq[n]-acq[i+1]
    v+=(a*c*pow(3,l+r,mod))
    if l+r-1>=0:
      v+=(a*r*pow(3,l+r-1,mod))+(l*c*pow(3,l+r-1,mod))
    if l+r-2>=0:
      v+=(l*r*pow(3,l+r-2,mod))
    v%=mod

Failing test case input:
@>A>=???A?@>;@A=C@@<==@?>

Expected output:
954


Actual output:

Fixed submission (verdict: Accepted):
from itertools import accumulate as ac
s=input()
n=len(s)
mod=int(1e9)+7

*aca,=ac([0]+[1 if i=="A" else 0 for i in s])
*acc,=ac([0]+[1 if i=="C" else 0 for i in s])
*acq,=ac([0]+[1 if i=="?" else 0 for i in s])

v=0
for i in range(1,n-1):
  if s[i]=="B" or s[i]=="?":
    a=aca[i]
    l=acq[i]
    c=acc[n]-acc[i+1]
    r=acq[n]-acq[i+1]
    v+=(a*c*pow(3,l+r,mod))
    if l+r-1>=0:
      v+=(a*r*pow(3,l+r-1,mod))+(l*c*pow(3,l+r-1,mod))
    if l+r-2>=0:
      v+=(l*r*pow(3,l+r-2,mod))
    v%=mod
print(v)
Problem: p03291
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import sys
import itertools
import collections
import functools
import math
from queue import Queue
INF = float("inf")

MOD = 1000000007  

d = {}


def thpow(q):
    if q < 0:
        return 0
    if q == 0:
        return 1
    if q in d:
        return d[q]
    else:
        d[q] = (3*thpow(q-1)) % MOD
        return d[q]


def solve(S: str):
    dp = [0, 0, 0]
    q = 0
    for ch in S:
        
        a, b, c = dp
        if ch == "A":
            dp = [a+1, b, c]
        elif ch == "B":
            dp = [a, b+a, c]
        elif ch == "C":
            dp = [a, b, c+b]
        elif ch == "?":
            dp = [((a*3 % MOD)+thpow(q)) % MOD,
                  ((b*3) % MOD+a) % MOD,
                  ((c*3) % MOD+b) % MOD]
            q += 1
    
    print(dp[-1])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  
    solve(S)


if __name__ == '__main__':
    main()


Failing test case input:
>??@>????@?>B<?>@A@?@=???

Expected output:
6751269


Actual output:
6397029


Fixed submission (verdict: Accepted):

import sys
import itertools
import collections
import functools
import math
from queue import Queue
INF = float("inf")

MOD = 1000000007  

d = {}


def thpow(q):
    if q < 0:
        return 0
    if q == 0:
        return 1
    if q in d:
        return d[q]
    else:
        d[q] = (3*thpow(q-1)) % MOD
        return d[q]


def solve(S: str):
    dp = [0, 0, 0]
    q = 0
    for ch in S:
        a, b, c = dp
        if ch == "A":
            dp = [(a+thpow(q)) % MOD, b, c]
        elif ch == "B":
            dp = [a, (b+a) % MOD, c]
        elif ch == "C":
            dp = [a, b, (c+b) % MOD]
        elif ch == "?":
            dp = [((a*3 % MOD)+thpow(q)) % MOD,
                  ((b*3) % MOD+a) % MOD,
                  ((c*3)+b) % MOD]
            q += 1
        
    

    
    print(dp[2])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  
    solve(S)


if __name__ == '__main__':
    main()
Problem: p03291
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
MOD = 10 **9 + 7
s = input()

n = len(s)
a = [0] * (n+1)
b = [0] * (n+1)
c = [0] * (n+1)

for i in range(n):
    if s[i] == '?':
        a[i+1] = a[i] * 3 + 1
        b[i+1] = b[i] * 3 + a[i]
        c[i+1] = c[i] * 3 + b[i]
    else:
        a[i+1] = a[i]
        b[i+1] = b[i]
        c[i+1] = c[i]
        if s[i] == 'A':
            a[i+1] += 1
        if s[i] == 'B':
            b[i+1] += a[i]
        if s[i] == 'C':
            c[i+1] += b[i]
    a[i+1] = a[i+1] % MOD
    b[i+1] = b[i+1] % MOD
    c[i+1] = c[i+1] % MOD
print(c[n])

Failing test case input:
??>=>=?B;=@@C??@>@@??A???

Expected output:
498636


Actual output:
215884


Fixed submission (verdict: Accepted):
MOD = 10 **9 + 7
s = input()

n = len(s)
o = [1] * (n+1)
a = [0] * (n+1)
b = [0] * (n+1)
c = [0] * (n+1)

for i in range(n):
    if s[i] == '?':
        o[i+1] = o[i] * 3
        a[i+1] = a[i] * 3 + o[i]
        b[i+1] = b[i] * 3 + a[i]
        c[i+1] = c[i] * 3 + b[i]
    else:
        o[i+1] = o[i]
        a[i+1] = a[i]
        b[i+1] = b[i]
        c[i+1] = c[i]
        if s[i] == 'A':
            a[i+1] += o[i]
        if s[i] == 'B':
            b[i+1] += a[i]
        if s[i] == 'C':
            c[i+1] += b[i]
    o[i+1] = o[i+1] % MOD
    a[i+1] = a[i+1] % MOD
    b[i+1] = b[i+1] % MOD
    c[i+1] = c[i+1] % MOD
print(c[n])

Problem: p03291
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
table=[[0 for _ in range(4)] for _ in range(len(s)+1)]
abc='ABC'
for i in range(len(s)):
    table[i][0]=1
    for j in range(3):
        if s[i]=='?':
            table[i+1][j+1]=3*table[i][j+1]+table[i][j]
        elif s[i]==abc[j]:
            table[i+1][j+1]=table[i][j+1]+table[i][j]
        else:
            table[i+1][j+1]=table[i][j+1]

print(table[i+1][j+1]%(10*9+7))

Failing test case input:
?9>=>B=>@B??<B?><?A?=A?D?

Expected output:
37665


Actual output:
17


Fixed submission (verdict: Accepted):
s=input()
table=[[0 for _ in range(4)] for _ in range(len(s)+1)]
table[0][0]=1
abc='ABC'
for i in range(len(s)):
    for j in range(4):
        if s[i]=='?' and j!=0:
            table[i+1][j]=(3*table[i][j]+table[i][j-1])%(10**9+7)
        elif s[i]=='?':
            table[i+1][0]=3*table[i][0]%(10**9+7)
        elif s[i]==abc[j-1] and j!=0:
            table[i+1][j]=(table[i][j]+table[i][j-1])%(10**9+7)
        else:
            table[i+1][j]=table[i][j]%(10**9+7)

print(table[i+1][j]%(10**9+7))
Problem: p03291
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


 
modulo = 10 ** 9 + 7
 
S = input()
 
def nleft(S, c):
    
 
    
    n = [0 for c in S]
    for i in range(len(S)):
        n[i] = n[i-1] + (1 if S[i-1] == c else 0)

    q = 0      
    pow3q = 1  
    for i in range(len(n)):
        if q > 0:
            n[i] *= pow3q         
            n[i] += pow3q1 * q    
            n[i] %= modulo
        if S[i] == '?':
            q += 1
            pow3q1 = pow3q
            pow3q  = pow3q * 3 % modulo
    return n
 
def nright(S, c):
    
    n = [0 for c in S]
    for i in range(len(S) - 1, 0, -1):
        n[i-1] = n[i] + (1 if S[i] == c else 0)

    q = 0      
    pow3q = 1  
    for i in range(len(n) - 1, -1, -1):
        if q > 0:
            n[i] *= pow3q         
            n[i] += pow3q1 * q    
            n[i] %= modulo
        if S[i] == '?':
            q += 1
            pow3q1 = pow3q
            pow3q  = pow3q * 3 % modulo
    return n
 
 
left  = nleft (S, 'A')
right = nright(S, 'C')
 

abc = 0
for i in range(0, len(S)):
    if S[i] in 'B?':
        abc += left[i] * right[i]
 
abc = int(abc) % modulo
print(abc)


Failing test case input:
>?@===A@;=@@C>??@??@=>A>A

Expected output:
252


Actual output:
603


Fixed submission (verdict: Accepted):


 
modulo = 10 ** 9 + 7
 
S = input()
 
def nleft(S, c):
    
 
    
    n = [0 for c in S]
    for i in range(1, len(S)):
        n[i] = n[i-1] + (1 if S[i-1] == c else 0)
 
    q = 0      
    pow3q = 1  
    for i in range(len(n)):
        if q > 0:
            n[i] *= pow3q         
            n[i] += pow3q1 * q    
            n[i] %= modulo
        if S[i] == '?':
            q += 1
            pow3q1 = pow3q
            pow3q  = pow3q * 3 % modulo
    return n
 
def nright(S, c):
    
    n = [0 for c in S]
    for i in range(len(S) - 1, 0, -1):
        n[i-1] = n[i] + (1 if S[i] == c else 0)
 
    q = 0      
    pow3q = 1  
    for i in range(len(n) - 1, -1, -1):
        if q > 0:
            n[i] *= pow3q         
            n[i] += pow3q1 * q    
            n[i] %= modulo
        if S[i] == '?':
            q += 1
            pow3q1 = pow3q
            pow3q  = pow3q * 3 % modulo
    return n
 
 
left  = nleft (S, 'A')
right = nright(S, 'C')
 

abc = 0
for i in range(0, len(S)):
    if S[i] in 'B?':
        abc += left[i] * right[i]
 
abc = int(abc) % modulo
print(abc)
Problem: p03291
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = list(input())
mod = 10**9 + 7
abc = 0
bc = 0
c = 0
q = 0
print(s[::-1])
for i in s[::-1]:
  if i == "A":
    abc = (abc + bc) % mod
  if i == "B":
    bc = (bc + c) % mod
  if i == "C":
    c = (3**q+c) % mod
  if i == "?":
    abc = (abc*3 + bc) % mod
    bc = (bc*3 + c) % mod 
    c = (3**q + c*3) % mod
    q += 1
print(abc)

Failing test case input:
ABDBC

Expected output:
2


Actual output:
['C', 'B', 'D', 'B', 'A']
2


Fixed submission (verdict: Accepted):
s = input()
mod = 10**9 + 7
abc = 0
bc = 0
c = 0
q = 0
for i in s[::-1]:
  if i == "A":
    abc = (abc + bc) % mod
  if i == "B":
    bc = (bc + c) % mod
  if i == "C":
    c = (pow(3,q,mod) + c) % mod
  if i == "?":
    abc = (abc*3 + bc) % mod
    bc = (bc*3 + c) % mod 
    c = (pow(3,q,mod) + c*3) % mod
    q += 1
print(int(abc))

Problem: p03291
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
abc="ABCD"
n=len(s)
mod=10**9+7
dp=[[0]*4 for i in range(n+1)]
dp[n][3]=1
for i in range(n-1,-1,-1):
    for j in range(4):
        if s[i]=='?' :
            if j==3:
                dp[i][j]=3*dp[i+1][j]
            else :
                dp[i][j]=3*dp[i+1][j]+dp[i+1][j+1]
        elif s[i]==abc[j]:
            if j!=3:
                dp[i][j]=dp[i+1][j]+dp[i+1][j+1]
            else :
                dp[i][j]=dp[i+1][j]
        else :
            dp[i][j]=dp[i+1][j]
    dp[i][j]%=mod
print(dp[0][0])

Failing test case input:
>???=??>??@??????A@???@?B

Expected output:
338512341


Actual output:
3338512362


Fixed submission (verdict: Accepted):
s=input()
abc="ABCD"
n=len(s)
mod=10**9+7
dp=[[0]*4 for i in range(n+1)]
dp[n][3]=1
for i in range(n-1,-1,-1):
    for j in range(4):
        if s[i]=='?' :
            if j==3:
                dp[i][j]=3*dp[i+1][j]
            else :
                dp[i][j]=3*dp[i+1][j]+dp[i+1][j+1]
        elif s[i]==abc[j]:
            if j!=3:
                dp[i][j]=dp[i+1][j]+dp[i+1][j+1]
            else :
                dp[i][j]=dp[i+1][j]
        else :
            dp[i][j]=dp[i+1][j]
        dp[i][j]%=mod
print(dp[0][0])
Problem: p02843
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
x = int(input())
a = 0
i = 0
while a <= x:
  a += 100
  i += 1
y = x - 100*(a-1)
if y <= (i-1)*a:
  print("1")
else:
  print("0")

Failing test case input:
152

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
x = int(input())
a = 0
i = 0
while a <= x:
  a += 100
  i += 1
a -= 100
i -= 1
y = x - a
if y <= i*5:
  print("1")
else:
  print("0")

Problem: p02843
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
x = int(input())
l = int(x/105)
u = int(x/100)+1
flag = False
for n in range(l, u):
    for a in range(0, u):
        for b in range(n-a, u):
            for c in range(n-a-b, u):
                for d in range(n-a-b-c, u):
                    for e in range(n-a-b-c-d, u):
                        for f in range(n-a-b-c-d-e, u):
                            if 100*a + 101*b + 102*c + 103*d + 104*e + 105*f == x:
                                
                                flag = True
                                break
                            if flag == True: break
                        if flag == True: break
                    if flag == True: break
                if flag == True: break
            if flag == True: break
        if flag == True: break
    if flag == True: break

if flag:
    print('1')
else:
    print('0')

Failing test case input:
420

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
x = int(input())
l = int(x/105)
u = int(x/100)+1
flag = False
for n in range(l, u):
    for a in range(0, u):
        for b in range(0, u-a):
            for c in range(0, u-a-b):
                for d in range(0, u-a-b-c):
                    for e in range(0, u-a-b-c-d):
                        for f in range(0, u-a-b-c-d-e):
                            if 100*a + 101*b + 102*c + 103*d + 104*e + 105*f == x:
                                
                                flag = True
                                break
                            if flag == True: break
                        if flag == True: break
                    if flag == True: break
                if flag == True: break
            if flag == True: break
        if flag == True: break
    if flag == True: break

if flag:
    print('1')
else:
    print('0')

Problem: p02843
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input().strip())
valid = { 0: True }
for i in range(1, n+1):
  valid[i] = any(valid.get(i-j, False) for j in range(100, 106))
print (valid[n])

Failing test case input:
474

Expected output:
0


Actual output:
False


Fixed submission (verdict: Accepted):
n = int(input().strip())
valid = { 0: True }
for i in range(1, n+1):
  valid[i] = any(valid.get(i-j, False) for j in range(100, 106))
print (1 if valid[i] else 0)
Problem: p02843
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
X=int(input())

h_num=int(X/100)
x_s=int(X%100)

ans=int(x_s/5)+1

if ans<=h_num:
    print(1)
else:
    print(0)

Failing test case input:
420

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
X=int(input())

h_num=int(X/100)
x_s=int(X%100)

ans=int(x_s/5)+1

if X%105==0:
    print(1)
elif ans<=h_num:
    print(1)
else:
    print(0)

Problem: p02843
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
x = input()
x = '000'+x
z = x[:-2]
y = x[-2:]
s = 0
z = int(z)
y = int(y)
L = []
for i in range(1,15):
    s +=i
    if s>=y and z>=i:
        print(1)
        exit()
if z>=14:
    print(1)
    exit()
print(0)

Failing test case input:
420

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
x = input()
x = '000'+x
z = x[:-2]
y = x[-2:]
s = 0
z = int(z)
y = int(y)
L = []
for i in range(1,21):
    s +=5
    if s>=y and z>=i:
        print(1)
        exit()
if z>=20:
    print(1)
    exit()
print(0)

Problem: p02843
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
X = int(input())
if X >2000:
  print("1")
else:
  for i in range(1,20,1):
    if not (X in range(100*i,105*i +1)) == False:
      print("1")
      flag = True
      break
    else:
      print("0")

Failing test case input:
173

Expected output:
0


Actual output:
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0


Fixed submission (verdict: Accepted):
X = int(input())
if X >2000:
  print("1")
else:
  flag = False
  for i in range(1,20,1):
    if not (X in range(100*i,105*i +1)) == False:
      print("1")
      flag = True
      break
  if flag ==False:
    print("0")

Problem: p02843
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import permutations, combinations,combinations_with_replacement,product

X =int(input())

s =str(X/100)

s_list =s.split('.')

A =[0,1,2,3,4,5]

for h in range(1,int(s_list[0])+1):
    for i in combinations_with_replacement(A,h):
        if sum(i) == int(s_list[1]):
            print(i)
            
            

print("0")


Failing test case input:
420

Expected output:
1


Actual output:
(2,)
(0, 2)
(1, 1)
(0, 0, 2)
(0, 1, 1)
(0, 0, 0, 2)
(0, 0, 1, 1)
0


Fixed submission (verdict: Accepted):
from itertools import permutations, combinations,combinations_with_replacement,product

X =int(input())

s =str(X/100)

s_list =s.split('.')

A =[0,1,2,3,4,5]

for h in range(1,int(s_list[0])+1):
    for i in combinations_with_replacement(A,h):
        if sum(i) == int(s_list[1]):
            
            print("1")
            exit()

print("0")

Problem: p02843
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools
n = input()
if len(n) <= 2:
    print(0)
    exit()
n = int(str(n)[0:3])

k = int(str(n)[0])
l = int(str(n)[1:3])

if l < 5*k:
    print(1)
else:
    print(0)


Failing test case input:
420

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import itertools
n = input()
if len(n) <= 2:
    print(0)
    exit()


k = int(n[:len(n)-2])
l = int(n[len(n)-2:])

if l <= 5*k:
    print(1)
else:
    print(0)
Problem: p02843
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
X = int(input())
a = [100, 101, 102, 103, 104, 105]
dp = [[False]*100010 for _ in range(10)]
dp[0][0] = True
for i in range(6):
    for j in range(100001):
        dp[i+1][j] |= dp[i][j]
        if j >= a[i]:
            dp[i+1][j] |= dp[i][j-a[i]]

if dp[6][X]:
    print(1)
else:
    print(0)

Failing test case input:
622

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
X = int(input())
a = [100, 101, 102, 103, 104, 105]
dp = [[False]*100010 for _ in range(10)]
dp[0][0] = True

for j in range(X+1):
    for i in range(6):
        dp[i+1][j] |= dp[i][j]
        if j >= a[i]:
            dp[i+1][j] |= dp[i][j-a[i]]
            dp[i+1][j] |= dp[i+1][j-a[i]]
if dp[6][X]:
    print(1)
else:
    print(0)

Problem: p02843
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
left = n
n = n%100
pay = 0
chance = 0
for i in range(5, 0,-1):
	pay+=n
	chance+=(n%i)
	n=n/i

if pay<left:
	print(1)
else:
	print(0)

Failing test case input:
299

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
r = n
left = n
n = n%100
pay = 0
chance = 0
for i in range(5, 0,-1):
	pay+=(n
	chance+=(n%i)
	n=n%i
if pay<=left:
	print(1)
else:
	print(0)
Problem: p02537
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n,k=map(int,input().split())
a=[int(input()) for _ in range(n)]
l=[[] for i in range(n)]

l[0].append(a[0])
ans=0
for ai in a[1:]:
  for i in reversed(range(ans+1)): 
    for li in l[i]:
      if -k<=(li-ai)<=k:
        ans=max(ans,i+1)
        l[ans].append(ai)
        break
    else:
      continue
    break
  else:
    l[0].append(ai)

print(ans+1)

Failing test case input:
10 3
1
5
2
0
6
6
9
5
4
1

Expected output:
6


Actual output:
7


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
a=[int(input()) for _ in range(n)]
l=[[] for i in range(n)]

l[0].append(a[0])
ans=0
for ai in a[1:]:
  for i in reversed(range(ans+1)): 
    for li in l[i]:
      if -k<=(li-ai)<=k:
        ans=max(ans,i+1)
        l[i+1].append(ai)
        break
    else:
      continue
    break
  else:
    l[0].append(ai)

print(ans+1)
Problem: p02537
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
class SegTree:
	
	def __init__(self,size,func,init_val,undef):
		self.specSize = size
		self.datSize = 1
		self.compareFunc = func		
		self.INIT_VAL = init_val	
		self.UNDEFINED_VAL = undef	
		
		self.datSize = 2**size.bit_length()

		
		
		self.datTree = [self.INIT_VAL for _ in range(2*self.datSize+1)]

	def update(self, i, val ):
		
		
		
		i += self.datSize
		self.datTree[i] = val
		while 1 < i:
			i >>= 1
			self.datTree[i] = self.compareFunc( self.datTree[i<<1|0], self.datTree[i<<1|1] )

	def query(self,a,b):
		return self.query_(a,b,1,0,self.datSize)

	def query_(self,a,b,i,l,r):
		
		ret = self.UNDEFINED_VAL

		a += self.datSize
		b += self.datSize
		while a < b:
			if b & 1:
				b -= 1
				ret = self.compareFunc(ret, self.datTree[b])

			if a & 1:
				ret = self.compareFunc(ret, self.datTree[a])
				a += 1

			a >>= 1; b >>= 1

		return ret

	def printTree(self):
		print(self.datTree)


def LongestSeaquence(A,K):
	N = len(A)
	lis = 0

	
	MAX_A = max(A)
	tree = SegTree(MAX_A+1,max,0,-1e18)
	

	for n in range(N):
		x = A[n]
		l = max(1,x-K)
		r = min(MAX_A,x+K)
		tree.update( x, tree.query(l,r+1)+1 )

	
	lis = tree.query(1,MAX_A)

	return lis

def main():
	N,K = map(int,input().split())
	A = [ int(input()) for _ in range(N)]

	print(LongestSeaquence(A,K))



if __name__ == "__main__":
	main()

Failing test case input:
10 3
0
1
4
3
6
6
9
7
4
4

Expected output:
10


Actual output:
9


Fixed submission (verdict: Accepted):
class SegTree:
	
	def __init__(self,size,func,init_val,undef):
		self.specSize = size
		self.datSize = 1
		self.compareFunc = func		
		self.INIT_VAL = init_val	
		self.UNDEFINED_VAL = undef	
		
		self.datSize = 2**size.bit_length()

		
		
		self.datTree = [self.INIT_VAL for _ in range(2*self.datSize+1)]

	def update(self, i, val ):
		
		
		
		i += self.datSize
		self.datTree[i] = val
		while 1 < i:
			i >>= 1
			self.datTree[i] = self.compareFunc( self.datTree[i<<1|0], self.datTree[i<<1|1] )

	def query(self,a,b):
		return self.query_(a,b,0,0,self.datSize)

	def query_(self,a,b,i,l,r):
		
		ret = self.UNDEFINED_VAL

		a += self.datSize
		b += self.datSize
		while a < b:
			if b & 1:
				b -= 1
				ret = self.compareFunc(ret, self.datTree[b])

			if a & 1:
				ret = self.compareFunc(ret, self.datTree[a])
				a += 1

			a >>= 1; b >>= 1

		return ret

	def printTree(self):
		print(self.datTree)


def LongestSeaquence(A,K):
	N = len(A)
	lis = 0

	
	MAX_A = max(A)
	tree = SegTree(MAX_A+1,max,0,-1e18)
	

	for n in range(N):
		x = A[n]
		l = max(0,x-K)
		r = min(MAX_A,x+K)
		tmp = tree.query(l,r+1)+1
		tree.update( x, tmp )
		lis = max(lis, tmp)

	return lis

def main():
	N,K = map(int,input().split())
	A = [ int(input()) for _ in range(N)]

	print(LongestSeaquence(A,K))



if __name__ == "__main__":
	main()
Problem: p02537
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):









def segfunc(x, y):
    return max(x, y)

 

ide_ele = -1

 
class SegTree:
    
    def __init__(self, init_val, segfunc, ide_ele):
        
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
 
    def update(self, k, x):
        
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1
 
    def query(self, l, r):
        
        res = self.ide_ele
 
        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res




N, K = map(int, input().split())
tree = [0 for _ in range(400000)]
tree = SegTree(tree, segfunc, ide_ele)
for k in range(N):
  A = int(input())
  A -= 1
  n = tree.query(max(0, A-K), min(400000, A+K+1))
  tree.update(A, n+1)
print(tree.query(0, 400000))








Failing test case input:
10 3
1
5
2
0
1
6
9
8
4
2

Expected output:
6


Actual output:
5


Fixed submission (verdict: Accepted):









def segfunc(x, y):
    return max(x, y)

 

ide_ele = -1

 
class SegTree:
    
    def __init__(self, init_val, segfunc, ide_ele):
        
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
 
    def update(self, k, x):
        
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1
 
    def query(self, l, r):
        
        res = self.ide_ele
 
        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res




N, K = map(int, input().split())
tree = [0 for _ in range(400000)]
tree = SegTree(tree, segfunc, ide_ele)
for k in range(N):
  A = int(input())
  n = tree.query(max(0, A-K), min(400000, A+K+1))
  tree.update(A, n+1)
print(tree.query(0, 400000))
Problem: p02537
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):

def segfunc(x, y):
    return max(x, y)



ide_ele = 0



class SegTree:
    
    def __init__(self, init_val, segfunc, ide_ele):
        
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

n, k = map(int, input().split())
st = SegTree([0] * 300001, segfunc, ide_ele)
for _ in range(n):
    a = int(input())
    v = st.query(a - 3, a + 4) + 1
    st.update(a, v)
print(st.query(0, 300001))


Failing test case input:
10 1
1
8
0
3
8
11
9
7
6
1

Expected output:
4


Actual output:
6


Fixed submission (verdict: Accepted):

def segfunc(x, y):
    return max(x, y)



ide_ele = 0



class SegTree:
    
    def __init__(self, init_val, segfunc, ide_ele):
        
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

n, k = map(int, input().split())
st = SegTree([0] * 300001, segfunc, ide_ele)
for _ in range(n):
    a = int(input())
    v = st.query(max(0, a - k), min(300001, a + k + 1)) + 1
    st.update(a, v)
print(st.query(0, 300001))
Problem: p02537
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):


def segfunc(x, y):
    return max(x,y)



ide_ele = 0




class SegTree:
    
    def __init__(self, init_val, segfunc, ide_ele):
        
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res



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

T=[0 for i in range(300000+1)]
T=SegTree(T,segfunc,ide_ele)

for num in A:
    now=T.query(max(0,num-k),min(num+k+1,n))
    
    T.update(num,now+1)

print(T.query(0,n+1))



Failing test case input:
10 3
0
5
4
3
8
11
9
7
6
2

Expected output:
6


Actual output:
5


Fixed submission (verdict: Accepted):


def segfunc(x, y):
    return max(x,y)



ide_ele = 0




class SegTree:
    
    def __init__(self, init_val, segfunc, ide_ele):
        
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res



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

T=[0 for i in range(300000+1)]
T=SegTree(T,segfunc,ide_ele)

for num in A:
    now=T.query(max(0,num-k),min(num+k+1,300002))
    
    T.update(num,now+1)

print(T.query(0,300001))
Problem: p02537
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys, math
import io, os

from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var): sys.stdout.write('\n'.join(map(str, var)) + '\n')
def out(var): sys.stdout.write(str(var) + '\n')
from decimal import Decimal


mod = 998244353
INF=float('inf')


def construct_sum(segtree,a,n,func=max):
    for i in range(n):
        segtree[n + i] = a[i]
    for i in range(n - 1, 0, -1):
        segtree[i] = func(segtree[2 * i], segtree[2 * i + 1])

def update(pos, x, func=max):
    pos += n-1
    segtree[pos] = x
    while (pos>1):
        pos>>=1
        segtree[pos] = func(segtree[2 * pos], segtree[2 * pos + 1])

def get(l, r, func=max):
    l += n-1
    r += n-1
    s = 0
    while (l <= r):
        if l & 1:
            s = func(segtree[l],s)
            l+=1
        if (r+1) & 1:
            s = func(segtree[r],s)
            r-=1
        l >>= 1
        r >>= 1
    return s

n,k=mdata()
a=[int(data()) for i in range(n)]
n=max(a)+1
segtree = [0]*(2*n)
construct_sum(segtree,[0]*n,n)
ans=0
for i in a:
    a1=get(max(i-k,0),min(i+k,n))+1
    update(i,a1)
    ans=max(ans,a1)
out(ans)








Failing test case input:
10 3
0
1
3
0
5
9
9
7
4
4

Expected output:
7


Actual output:
9


Fixed submission (verdict: Accepted):
import sys, math
import io, os

from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var): sys.stdout.write('\n'.join(map(str, var)) + '\n')
def out(var): sys.stdout.write(str(var) + '\n')
from decimal import Decimal


mod = 998244353
INF=float('inf')


def construct_sum(segtree,a,n,func=max):
    for i in range(n):
        segtree[n + i] = a[i]
    for i in range(n - 1, 0, -1):
        segtree[i] = func(segtree[2 * i], segtree[2 * i + 1])

def update(pos, x, func=max):
    pos += n-1
    segtree[pos] = x
    while (pos>1):
        pos>>=1
        segtree[pos] = func(segtree[2 * pos], segtree[2 * pos + 1])

def get(l, r, func=max):
    l += n-1
    r += n-1
    s = 0
    while (l <= r):
        if l & 1:
            s = func(segtree[l],s)
            l+=1
        if (r+1) & 1:
            s = func(segtree[r],s)
            r-=1
        l >>= 1
        r >>= 1
    return s

n,k=mdata()
a=[int(data()) for i in range(n)]
n=max(a)+1
segtree = [0]*(2*n)
construct_sum(segtree,[0]*n,n)
ans=0
for i in a:
    a1=get(max(i-k+1,1),min(i+k+1,n))+1
    update(i+1,a1)
    ans=max(ans,a1)
out(ans)
Problem: p02537
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()

def segfunc(x, y):
    return max(x, y)

ide_ele = 0

class SegTree:
    
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

size = 10**5*3+10
seg = SegTree([0]*size, segfunc, ide_ele)
for _ in range(N):
    a = int(input())
    maxi = seg.query(max(0, a-K-1), min(size, a+K))
    seg.update(a-1, maxi+1)
print(seg.query(0, size))

Failing test case input:
10 4
0
1
4
3
3
12
9
7
4
4

Expected output:
8


Actual output:
7


Fixed submission (verdict: Accepted):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()

def segfunc(x, y):
    return max(x, y)

ide_ele = 0

class SegTree:
    
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

size = 10**5*3+10
seg = SegTree([0]*size, segfunc, ide_ele)
for _ in range(N):
    a = int(input())
    maxi = seg.query(max(0, a-K), min(size, a+K+1))
    seg.update(a, maxi+1)
print(seg.query(0, size))
Problem: p02537
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys


class SegmentTree:
    

    def __init__(self, size, f=lambda x, y: max(x, y), default=0):
        self.size = 2 ** (size - 1).bit_length()
        self.default = default
        self.dat = [default] * (self.size * 2)
        self.f = f

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i * 2], self.dat[i * 2 + 1])

    def query(self, l, r):
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres)
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res


input = sys.stdin.buffer.readline

N, K = map(int, input().split())
MAX = 300010
B = SegmentTree(MAX)

for _ in range(N):
    a = int(input())
    m = B.query(max(1, a - K), min(MAX, a + K + 1))
    B.update(a, m + 1)
print(B.query(1, MAX))


Failing test case input:
10 3
1
5
2
0
6
0
9
8
4
2

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
import sys


class SegmentTree:
    

    def __init__(self, size, f=lambda x, y: max(x, y), default=0):
        self.size = 2 ** (size - 1).bit_length()
        self.default = default
        self.dat = [default] * (self.size * 2)
        self.f = f

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i * 2], self.dat[i * 2 + 1])

    def query(self, l, r):
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres)
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res


input = sys.stdin.buffer.readline

N, K = map(int, input().split())
MAX = 300010
B = SegmentTree(MAX)
for _ in range(N):
    a = int(input()) + 1
    m = B.query(max(1, a - K), min(MAX, a + K + 1))
    B.update(a, m + 1)
print(B.query(1, MAX))