Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,m,l = map(int,input().split())
d = [[float("inf")]*n for _ in [0]*n]
for i in range(m):
    a,b,c = map(int,input().split())
    if l >= c:
        d[a-1][b-1] = d[b-1][a-1] = c
for i in range(n):
    d[i][i] = 0

for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j] = min(d[i][j],d[i][k] + d[k][j])

edge = [[float("inf")]*n for _ in [0]*n]
for i in range(n):
    for j in range(n):
        if d[i][j] <= l:
            edge[i][j] = 1

for k in range(n):
    for i in range(n):
        for j in range(n):
            edge[i][j] = min(edge[i][j],edge[i][k] + edge[k][j])

q = int(input())
for _ in [0]*q:
    s,t = map(int,input().split())
    if edge[s-1][t-1] == float("inf"):
        print(-1)
    else:
        print(edge[s-1][t-1]-1)

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    n,m,l = map(int,input().split())
    d = [[10**12]*n for _ in [0]*n]
    for i in range(m):
        a,b,c = map(int,input().split())
        if l >= c:
            d[a-1][b-1] = d[b-1][a-1] = c
    for i in range(n):
        d[i][i] = 0

    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])

    edge = [[10**12]*n for _ in [0]*n]
    for i in range(n):
        for j in range(n):
            if d[i][j] <= l:
                edge[i][j] = 1

    for k in range(n):
        for i in range(n):
            for j in range(n):
                edge[i][j] = min(edge[i][j],edge[i][k] + edge[k][j])

    q = int(input())
    for _ in [0]*q:
        s,t = map(int,input().split())
        if edge[s-1][t-1] >= 10**12:
            print(-1)
        else:
            print(edge[s-1][t-1]-1)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import random

n = int(input())
s = list(input())

#s[i:j]のハッシュ値:(hash1[j]-hash1[i]*power1[j-i]%mod1)%mod1,hash_key2 = (hash2[j]-hash2[i]*power2[j-i]%mod2)%mod2
#長さnの文字列s
base1 = 1007
mod1 = 1000000007
base2 = 2009
mod2 = 1000000009

"""
modTank1 = [8570647,8570659,8570671,8570677,8570687,8570701,8570719,8570761,8570797,8571799]
mod1 = modTank1[random.randint(0,10)]
modTank2 = [7777709,7777727,7777753,7777769,7777801,7777811,7777813,7777843,7777849,7777853]
mod2 = modTank2[random.randint(0,10)]
"""

modTank1 = [8570647,8570659,8570671,8570677,8570687,8570701,8570719,8570761,8570797,8571799]
mod1 = modTank1[random.randint(0,10)]

hash1 = [0]*(n+1)
power1 = [1]*(n+1)


for i,e in enumerate(s):
    hash1[i+1] = (hash1[i]*base1 + ord(e))%mod1
    power1[i+1] = (power1[i]*base1)%mod1

res = 0
for i in range(n):
    for j in range(i+1,n):
        ng = min(j-i+1,n-j+1)
        ok = 0
        while ng-ok > 1:
            mid = (ok+ng)//2
            if (hash1[i+mid]-hash1[i]*power1[mid]%mod1)%mod1 != (hash1[j+mid]-hash1[j]*power1[mid]%mod1)%mod1:
                ng = mid
            else:
                ok = mid
        res = max(res,mid)
print(res)

Fixed submission:
n = int(input())
s = list(input())

res = 0

for k in range(1,n):
    d = [0]*n
    for i in range(n-k):
        if i+k <= n-1 and s[i] == s[i+k]:
            d[i] = min(k,d[i-1]+1)
            res = max(res,d[i])
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())

res = 0

for k in range(1,n//2+1):
    d = [0]*n
    for i in range(n):
        if i+k <= n-1 and s[i] == s[i+k]:
            d[i] = min(k,d[i-1]+1)
            res = max(res,d[i])
print(res)

Fixed submission:
n = int(input())
s = list(input())

res = 0

for k in range(1,n):
    d = [0]*n
    for i in range(n-k):
        if i+k <= n-1 and s[i] == s[i+k]:
            d[i] = min(k,d[i-1]+1)
            res = max(res,d[i])
print(res)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s =list(map(int,input().split()))

s.sort()

p = 0
for e in s:
    p = p^e

res = 0

q = 0
for e in s:
    q = q^e
    res = max(res,(p^q)+q)


q = 0
for i in range(n):
    q = q^s[n-1-i]
    res = max(res,(p^q)+q)
print(res)

Fixed submission:
n = int(input())
s = list(input())

res = 0

for k in range(1,n):
    d = [0]*n
    for i in range(n-k):
        if i+k <= n-1 and s[i] == s[i+k]:
            d[i] = min(k,d[i-1]+1)
            res = max(res,d[i])
print(res)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s =list(map(int,input().split()))

s.sort()

p = 0
for e in s:
    p = p^e

res = 0

q = 0
for e in s:
    q = q^e
    res = max(res,(p^q)+q)


q = 0
for i in range(n):
    q = q^s[n-1-i]
    res = max(res,(p^q)+q)
print(res)

Fixed submission:
n = int(input())
s = list(input())

res = 0

for k in range(1,n):
    d = [0]*n
    for i in range(n-k):
        if i+k <= n-1 and s[i] == s[i+k]:
            d[i] = min(k,d[i-1]+1)
            res = max(res,d[i])
print(res)
Buggy python submission (verdict: Runtime Error):
import bisect
n,k = map(int,input().split())
a = list(map(int,input().split()))

# i が与えられたとき a1~aiまでの和を計算する( O(log n) )
def bitsum(bit,i):
    s = 0
    while i > 0:
        s += bit[i]
        i -= i&(-i)
    return s
    
# i と x が与えられたとき ai += x とする ( O(log n) )
def bitadd(bit,i,x):
    while i <= n:
        bit[i] += x
        i += i&(-i)
    return bit
    
#################################
import math

#bitの構築
n_ = int(math.log2(n)) + 1
bit = [0] * (2**n_)
bit.append(0)

################################
ass = 0
for j in range(n):
    ass += j-bitsum(bit,a[j])
    #bitsum(bit,a[j]): j-1番目までの中でa[j]以下のもの
    bit = bitadd(bit,a[j],1)

res = 0
b = sorted(a)

for e in b:
    kw = bisect.bisect_right(b,e)
    res += n-kw

mod = 10**9+7

print((k*ass%mod+res*k*(k-1)//2%mod)%mod)

Fixed submission:
import bisect

n,k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9+7

ass = 0
for i in range(n):
    for j in range(i):
        if a[i] < a[j]:
            ass += 1

res = 0
b = sorted(a)
for e in b:
    kw = bisect.bisect_right(b,e)
    res += n-kw

print((k*ass%mod+( (k*(k-1)//2)%mod )*res%mod)%mod)

Buggy python submission (verdict: Runtime Error):
import bisect
n,k = map(int,input().split())
a = list(map(int,input().split()))

# i が与えられたとき a1~aiまでの和を計算する( O(log n) )
def bitsum(bit,i):
    s = 0
    while i > 0:
        s += bit[i]
        i -= i&(-i)
    return s
    
# i と x が与えられたとき ai += x とする ( O(log n) )
def bitadd(bit,i,x):
    while i <= n:
        bit[i] += x
        i += i&(-i)
    return bit
    
#################################
import math

#bitの構築
n_ = int(math.log2(n)) + 1
bit = [0] * (2**n_)
bit.append(0)

################################
ass = 0
for j in range(n):
    ass += j-bitsum(bit,a[j])
    #bitsum(bit,a[j]): j-1番目までの中でa[j]以下のもの
    bit = bitadd(bit,a[j],1)

res = 0
b = sorted(a)

for e in b:
    kw = bisect.bisect_right(b,e)
    res += n-kw

mod = 10**9+7

print((k*ass%mod+res*k*(k-1)//2%mod)%mod)

Fixed submission:
import bisect

n,k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9+7

ass = 0
for i in range(n):
    for j in range(i):
        if a[i] < a[j]:
            ass += 1

res = 0
b = sorted(a)
for e in b:
    kw = bisect.bisect_right(b,e)
    res += n-kw

print((k*ass%mod+( (k*(k-1)//2)%mod )*res%mod)%mod)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input.split())

print(max(a+b,a-b,a*b))


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

print(max(a+b,a-b,a*b))

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

print(max(a+b,a-b,a＊b))


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

print(max(a+b,a-b,a*b))
Buggy python submission (verdict: Time Limit Exceeded):
def shortest_path(s,n,w,es):
    #s→iの最短距離
    # s:始点, n:頂点数, w:辺の数, es[i]: [辺の始点,辺の終点,辺のコスト]
    d = [float("inf")] * n
    #d[i] : s→iの最短距離
    d[s] = 0
    for _ in range(n*w+1):
        updata = False
        for p,q,r in es:
            # e: 辺iについて [from,to,cost]
            if d[p] != float("inf") and d[q] > d[p] + r:
                d[q] = d[p] + r
                updata = True
        if not updata:
            break
    return d

def main():
    import sys
    input = sys.stdin.readline
    n,m,p = map(int,input().split())
    es = []
    for _ in range(m):
        a,b,c = map(int,input().split())
        es.append([a-1,b-1,p-c])

    d = shortest_path(0,n,m,es)

    kouho = d[-1]

    for _ in range(5):
        updata = True
        for i in range(m):
            e = es[i]
            # e: 辺iについて [from,to,cost]
            if d[e[0]] != float("inf") and d[e[1]] > d[e[0]] + e[2]:
                d[e[1]] = d[e[0]] + e[2]
                updata = True
        if not updata:
            break

    res = d[-1]

    if kouho == res:
        print(max(0,-res))
    else:
        print(-1)

if __name__ == '__main__':
    main()

Fixed submission:
def shortest_path(s,n,w,es):
    #s→iの最短距離
    # s:始点, n:頂点数, w:辺の数, es[i]: [辺の始点,辺の終点,辺のコスト]
    d = [float("inf")] * n
    #d[i] : s→iの最短距離
    d[s] = 0
    for _ in [0]*n:
        update = False
        for p,q,r in es:
            # e: 辺iについて [from,to,cost]
            if d[p] != float("inf") and d[q] > d[p] + r:
                d[q] = d[p] + r
                update = True
        if not update:
            break
    return d

def main():
    import sys
    input = sys.stdin.readline
    n,m,p = map(int,input().split())
    es = []
    edge = [[] for _ in range(n)]

    for _ in range(m):
        a,b,c = map(int,input().split())
        es.append([a-1,b-1,p-c])
        edge[b-1].append(a-1)
    
    ren = [False]*n
    tank = [n-1]
    while len(tank) != 0:
        new = []
        for elt in tank:
            for go in edge[elt]:
                if ren[go]:
                    continue
                ren[go] = True
                new.append(go)
        tank = new

    d = shortest_path(0,n,m,es)

    for p,q,r in es:
        # e: 辺iについて [from,to,cost]
        if d[p] != float("inf") and d[q] > d[p] + r:
            d[q] = d[p] + r
            if ren[q]:
                print(-1)
                exit()

    print(max(-d[-1],0))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))

s = sum(a)
p = 0
for i in range(n):
    if i%2 == 1:
        p += a[i]*2

q = s-p
for i in range(n):
    print(q)
    q = a[i]*2-q

Fixed submission:
mod = 2019
l,r = map(int,input().split())

cnt = 0
tank = []
for i in range(l,r+1):
    tank.append(i%mod)
    cnt += 1
    if cnt >= 2020:
        break

res = 2019

n = len(tank)
for i in range(n):
    for j in range(i+1,n):
        res = min(res,tank[i]*tank[j]%mod)
print(res)
Buggy python submission (verdict: Runtime Error):
mod = 2019
l,r = map(int,input().split())

cnt = 0
tank = []
for i in range(l,r+1):
    tank.append(i%mod)
    cnt += 1
    if cnt >= 2020:
        break

res = 2019

n = len(tank)
for i in range(n):
    for j in range(i+1,n):
        res = min(res,tank[i]*tank[j]%mod)
print(res)

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

s = sum(a)
p = 0
for i in range(n):
    if i%2 == 1:
        p += a[i]*2

q = s-p
for i in range(n):
    print(q)
    q = a[i]*2-q
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
mod = 10**9+7

dp = [[0]*n for i in range(k+1)]
dp[0][0] = 1

for i in range(1,k+1):
    for j in range(1,i+1):
        dp[i][j] = ((dp[i-1][j]*(i+j-1)+dp[i-1][j-1]*(n-k-j+2))//i)%mod

for i in range(1,k+1):
    print(dp[-1][i])

Fixed submission:
n,k = map(int,input().split())
mod = 10**9+7

dp = [[0]*(k+1) for i in range(k+1)]
dp[0][0] = 1

for i in range(1,k+1):
    for j in range(1,i+1):
        dp[i][j] = (dp[i-1][j]*(i+j-1)+dp[i-1][j-1]*(n-k-j+2))//i

for i in range(1,k+1):
    print(dp[-1][i]%mod)
Buggy python submission (verdict: Runtime Error):
x,a = map(int(input()).split())
if x<a:
  print(0)
else:
  print(10)

Fixed submission:
x,a = map(int,input().split())
if x<a:
  print(0)
else:
  print(10)
Buggy python submission (verdict: Runtime Error):
w,h,x,y = map(input().split())

if w/2.0 == float(x) and h/2.0 == float(y):
    print(w*h/2.0,1)
else:
    print(w*h/2.0,0)

Fixed submission:
w,h,x,y = map(int,input().split())

if w/2.0 == float(x) and h/2.0 == float(y):
    print(w*h/2.0,1)
else:
    print(w*h/2.0,0)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))

    num = 0
    ab = []
    ba = []
    for i in range(3):
        if a[i]-b[i] < 0:
            ab.append([a[i],b[i]])  
        elif a[i]-b[i] > 0:
            ba.append([a[i],b[i]])

    dp = [i for i in range(n+1)]
    if len(ab) > 0:
        for i in range(n+1):
            for x,y in ab:
                if i >= x:
                    dp[i] = max(dp[i],dp[i-x]+y)
    p = max(n,dp[n])

    dp2 = [i for i in range(p+1)]
    if len(ba) > 0:
        for i in range(p+1):
            for y,x in ba:
                if i >= x:
                    dp2[i] = max(dp2[i],dp2[i-x]+y)
    print(dp2[-1])
if __name__ == '__main__':
    main()

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

    ab = []
    ba = []
    for i in range(3):
        if a[i]-b[i] < 0:
            ab.append((a[i],b[i]))
        elif a[i]-b[i] > 0:
            ba.append((a[i],b[i]))

    dp = [0]*(n+1)
    if len(ab) > 0:
        for i in range(n+1):
            dp[i] = i
            for x,y in ab:
                if i >= x:
                    dp[i] = max(dp[i],dp[i-x]+y)
    p = max(n,dp[n])

    dp2 = [0]*(p+1)

    if len(ba) > 0:
        for i in range(p+1):
            dp2[i] = i
            for y,x in ba:
                if i >= x:
                    dp2[i] = max(dp2[i],dp2[i-x]+y)
    print(max(p,dp2[-1]))
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
L = int(input(),2)

mod = 10**9+7

res = 0
bi = 1

thr = [1]
for i in range(1000002):
    thr.append(thr[-1]*3%mod)

for i in range(1000001,0,-1):
    if ((L>>i)&1) == 1:
        res = (res+(thr[i]*bi))%mod
        bi = bi*2
if (L&1) == 1:
    res += 3*bi
else:
    res += bi
print(res%mod)


Fixed submission:
L = int(input(),2)

mod = 10**9+7

res = 0
bi = 1

thr = [1]
for i in range(1000002):
    thr.append(thr[-1]*3%mod)

for i in range(1000001,0,-1):
    if ((L>>i)&1) == 1:
        res = (res+(thr[i]*bi)%mod)%mod
        bi = bi*2%mod
if (L&1) == 1:
    res += 3*bi
else:
    res += bi
print(res%mod)

Buggy python submission (verdict: Time Limit Exceeded):
L = int(input(),2)

mod = 10**9+7

res = 0
bi = 1


for i in range(1000001,0,-1):
    if ((L>>i)&1) == 1:
        res = (res+(pow(3,i,mod))*bi)%mod
        bi = bi*2
if (L&1) == 1:
    res += 3*bi
else:
    res += bi
print(res%mod)


Fixed submission:
L = int(input(),2)

mod = 10**9+7

res = 0
bi = 1

thr = [1]
for i in range(1000002):
    thr.append(thr[-1]*3%mod)

for i in range(1000001,0,-1):
    if ((L>>i)&1) == 1:
        res = (res+(thr[i]*bi)%mod)%mod
        bi = bi*2%mod
if (L&1) == 1:
    res += 3*bi
else:
    res += bi
print(res%mod)

Buggy python submission (verdict: Time Limit Exceeded):
L = int(input(),2)

mod = 10**9+7


res = 0
bi = 1

judge = True

for i in range(1000001,0,-1):
    if ((L>>i)&1) == 1:
        res = (res+(pow(3,i,mod))*bi)%mod
        bi = bi*2
if (L&1) == 1:
    res += 3*bi
else:
    res += bi
print(res%mod)


Fixed submission:
L = int(input(),2)

mod = 10**9+7

res = 0
bi = 1

thr = [1]
for i in range(1000002):
    thr.append(thr[-1]*3%mod)

for i in range(1000001,0,-1):
    if ((L>>i)&1) == 1:
        res = (res+(thr[i]*bi)%mod)%mod
        bi = bi*2%mod
if (L&1) == 1:
    res += 3*bi
else:
    res += bi
print(res%mod)
Buggy python submission (verdict: Runtime Error):
m,k = map(int,input().split())

if m == 0:
    if k == 0:
        print(0,0)
    else:
        print(-1)
    exit()
if m == 1:
    if k == 0:
        print(0,0,1,1)
    else:
        print(-1)
    exit()
if k >= 2**m:
    print(-1)

res = []
used = [True]*(pow(2**m))

tank = []

for i in range(2**m):
    if used[i]:
        tank.append((i,i^k))
        used[i] = used[i^k] = False
for i in range(len(tank)):
    if i % 2 == 1:
        continue
    a = tank[i][0]
    b = tank[i][1]
    c = tank[i+1][0]
    d = tank[i+1][1]
    res += [c,a,b,c,d,b,a,d]

for e in res:
    print(e,end=' ')

Fixed submission:
m,k = map(int,input().split())

if m == 0:
    if k == 0:
        print(0,0)
    else:
        print(-1)
    exit()
if m == 1:
    if k == 0:
        print(0,0,1,1)
    else:
        print(-1)
    exit()
if k >= 2**m:
    print(-1)
    exit()
if k == 0:
    for i in range(2**m):
        print(i,i,end = ' ')
    exit()
res = []
used = [True]*(2**m)

tank = []

for i in range(2**m):
    if used[i]:
        tank.append((i,i^k))
        used[i] = used[i^k] = False
for i in range(len(tank)):
    if i % 2 == 1:
        continue
    a = tank[i][0]
    b = tank[i][1]
    c = tank[i+1][0]
    d = tank[i+1][1]
    res += [c,a,b,c,d,b,a,d]

for e in res:
    print(e,end=' ')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n = int(input())
a = [int(input()) for i in range(n)]
w = sum(a)
mod =998244353

dp = [[0]*(w+1) for i in range(n)]

cnt = a[0]
dp[0][a[0]] = 1
dp[0][0] = 2
for i in range(1,n):
    cnt += a[i]
    for j in range(cnt+1):
        dp[i][j] = dp[i-1][j]*2
        if j >= a[i]:
            dp[i][j] += dp[i-1][j-a[i]]
        


#sより大きいのはブー
s = w//2+1
if w %2 == 0:
    d = [[0]*(s+1) for i in range(n)]
    d[0][0] = 1
    d[0][a[0]] = 1
    cnt = a[0]

    for i in range(1,n):
        cnt += a[i]
        for j in range(min(cnt+1,s+1)):
            d[i][j] = d[i-1][j]
            if j >= a[i]:
                d[i][j] += d[i-1][j-a[i]]
            d[i][j] = d[i][j]%mod
    mns = d[-1][w//2]
if w%2 == 0:
    s -= 1
cnt = 0
for i in range(s,w+1):
    cnt += dp[-1][i]
    cnt = cnt%mod

res = (pow(3,n,mod)-cnt*3)%mod

if w % 2 == 0:
    res = (res+mns*3)%mod
print(res)

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

n = int(input())
a = [int(input()) for i in range(n)]
w = sum(a)
mod =998244353

dp = [[0]*(w+1) for i in range(n)]

cnt = a[0]
dp[0][a[0]] = 1
dp[0][0] = 2
for i in range(1,n):
    cnt += a[i]
    for j in range(cnt+1):
        dp[i][j] = dp[i-1][j]*2
        if j >= a[i]:
            dp[i][j] += dp[i-1][j-a[i]]
        
        dp[i][j] = dp[i][j]%mod

#sより大きいのはブー
s = w//2+1
if w %2 == 0:
    d = [[0]*(s+1) for i in range(n)]
    d[0][0] = 1
    d[0][a[0]] = 1
    cnt = a[0]

    for i in range(1,n):
        cnt += a[i]
        for j in range(min(cnt+1,s+1)):
            d[i][j] = d[i-1][j]
            if j >= a[i]:
                d[i][j] += d[i-1][j-a[i]]
            d[i][j] = d[i][j]%mod
    mns = d[-1][w//2]
if w%2 == 0:
    s -= 1
cnt = 0
for i in range(s,w+1):
    cnt += dp[-1][i]
    cnt = cnt%mod

res = (pow(3,n,mod)-cnt*3)%mod

if w % 2 == 0:
    res = (res+mns*3)%mod
print(res)
Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())
s = list(input())
p = []
for i in range(q):
    t,d = map(str,input().split())
    p.append([t,d])

res = 0
cnt = 0
end = True
bef = ''
judge = s[0]
for i in range(q-1,-1,-1):
    if p[i][0] == bef and p[i][1] == 'R':
        end = False
        judge = bef
        cnt -= 1
        if cnt == 0:
            bef = ''
        else:
            bef = s[cnt-1]
    elif p[i][0] == judge and p[i][1] == 'L':
        if cnt+1>=res:
            end = True
        res = max(cnt+1,res)
        cnt += 1
        if res == n:
            break
        while judge==s[cnt] and cnt <= n-1:
            cnt += 1
            res += 1
        bef = judge
        judge = s[cnt]
if not end:
    res -= 1
res = max(0,res)

bef = ''
cnt = 0
end = True
res2 = 0
judge = s[n-1]
for i in range(q-1,-1,-1):
    if p[i][0] == bef and p[i][1] == 'L':
        end = False
        judge = bef
        cnt -= 1
        if cnt == 0:
            bef = ''
        else:
            bef = s[n-1-cnt+1]
    elif p[i][0] == judge and p[i][1] == 'R':
        if cnt+1 >= res2:
            end = True
        res2 = max(cnt+1,res2)
        cnt += 1
        if res2 == n:
            break
        while judge == s[n-1-cnt] and cnt <= n-1:
            res2 += 1
            cnt += 1
        bef = judge
        judge = s[max(0,n-1-cnt)]
if not end:
    res2 -= 1
res2 = max(0,res2)

print(max(min(n,n-res-res2),0))


Fixed submission:
n,q = map(int,input().split())
s = list(input())
p = [tuple(map(str,input().split())) for i in range(q)]

#s[x]が左へ抜けるか O(q)
def judge_left(x):
    for i in range(q):
        if p[i][0] == s[x]:
            if p[i][1] == 'L':
                x -= 1
            else:
                x += 1
        if x == -1:
            return True
        if x == n:
            return False
    return False

#s[x]が右へ抜けるか O(q)
def judge_right(x):
    for i in range(q):
        if p[i][0] == s[x]:
            if p[i][1] == 'L':
                x -= 1
            else:
                x += 1
        if x == -1:
            return False
        if x == n:
            return True
    return False

#どこまで左で抜けるか
ok = -1
ng = n
while ng-ok > 1:
    mid = (ng+ok)//2
    if judge_left(mid):
        ok = mid
    else:
        ng = mid
left = ok+1

#どこまで右で抜けるか
ok = n
ng = -1
while ok-ng >1:
    mid = (ok+ng)//2
    if judge_right(mid):
        ok = mid
    else:
        ng = mid
right = n-ok

print(max(n-left-right,0))
Buggy python submission (verdict: Runtime Error):
#落ち着くのんな
import sys
input = sys.stdin.readline

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


used = [True]*n
res = [0]*n
for i in range(1,n+1):
    
    for j in range(n-1,-1,-1):
        if b[j] == i:
            res[tank] = i
            tank = cnt + 1
            cnt = 0
        else:
            cnt += 1



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

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

res = [-1]*n
#今考えている数列のindex、ないなら-1
ind = [i for i in range(1,n+1)]
#決定した数
cnt = 0
while cnt != n:
    #judge:変化があるか
    judge = False
    for i in range(n-1,-1,-1):
        if ind[i] == b[i]:
            ind[i] = -1
            res[n-1-cnt] = b[i]
            cnt += 1
            judge = True
            break
        else:
            ind[i] -= 1
    if not judge:
        print(-1)
        exit()
for e in res:
    print(e)