Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]

s_max = 0

p_sum = [sum(p[i:i+k]) for i in range(n-k+1)]

s_max = (max(p_sum) + k) / 2

print(s_max)

Fixed submission:
n, k = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]

sum_max = sum(p[0:k])
sum_temp = sum_max

for i in range(n-k):
     sum_temp = sum_temp - p[i] + p[i+k]
     if sum_temp > sum_max:
         sum_max = sum_temp

s_max = (sum_max + k) / 2

print(s_max)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]

s_max = 0

for i in range(n-k+1):
    temp = sum(p[i:i+k])
    if s_max < temp:
        s_max = temp

s_max = (s_max + k) / 2

print(s_max)

Fixed submission:
n, k = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]

sum_max = sum(p[0:k])
sum_temp = sum_max

for i in range(n-k):
     sum_temp = sum_temp - p[i] + p[i+k]
     if sum_temp > sum_max:
         sum_max = sum_temp

s_max = (sum_max + k) / 2

print(s_max)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]

s_max = 0

for i in range(n-k+1):
    temp = sum(p[i:i+k])
    if s_max < temp:
        s_max = temp

s_max = (s_max + k) / 2

print(s_max)

Fixed submission:
n, k = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]

sum_max = sum(p[0:k])
sum_temp = sum_max

for i in range(n-k):
     sum_temp = sum_temp - p[i] + p[i+k]
     if sum_temp > sum_max:
         sum_max = sum_temp

s_max = (sum_max + k) / 2

print(s_max)
Buggy python submission (verdict: Runtime Error):
import math

n = int(input())
k = int(input())

digit_num = math.floor(math.log10(n)) + 1
count = [0 for _ in range(n)]
# 1桁少ないとこまで
for i in range(digit_num-1):
    j = i + 1
    if j > k:
        temp = ((j*j + 3*j + 2) * 9^(j-2))  /2
        count[i] = temp

b = 0

for i in range(digit_num,k,-1):
    s = int(str(n)[i])
    if s > 1:
        temp = (s-1) * count[i+1]
        b = b + temp

ans = sum(count)+b

print(b)

Fixed submission:
# import bisect
from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = input()
    p = int(input())
    l = len(n)

    n_0 = int(str(n)[0])

    dp = [[[0] * 2 for _ in range(p + 2)] for __ in range(l)]
    dp[0][0][0] = 0
    dp[0][0][1] = 1
    dp[0][1][0] = 1
    dp[0][1][1] = (n_0 - 1)

    for i in range(l - 1):
        a = int(n[i + 1])
        if a != 0:
            for j in range(p + 1):
                dp[i + 1][j + 1][0] += dp[i][j][0]
                dp[i + 1][j + 1][1] += 9 * dp[i][j][1] + (a - 1) * dp[i][j][0]
                dp[i + 1][j][1] += dp[i][j][0] + dp[i][j][1]
        else:
            for j in range(p + 1):
                dp[i + 1][j + 1][1] += 9 * dp[i][j][1]
                dp[i + 1][j][0] += dp[i][j][0]
                dp[i + 1][j][1] += dp[i][j][1]

    print(dp[l - 1][p][0] + dp[l - 1][p][1])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, d, a = list(map(int, readline().split()))
    xh = [list(map(int, readline().split())) for _ in range(n)]

    from operator import itemgetter
    import bisect

    xh.sort(key=itemgetter(0))
    coordinate = [xh[i][0] for i in range(n)]
    hp = [xh[i][1] for i in range(n)]

    ans = 0

    for i in range(n):
        x = coordinate[i]
        h = hp[i]

        if h > 0:
            num = (h + a - 1) // a
            ans += num
            dmg = a * num
            range_left = x
            range_right = x + 2 * d
            index_left = bisect.bisect_left(coordinate, range_left)
            index_right = bisect.bisect_right(coordinate, range_right)
            for j in range(index_left, index_right):
               hp[j] -= dmg

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, d, a = list(map(int, readline().split()))
    xh = [list(map(int, readline().split())) for _ in range(n)]

    from operator import itemgetter, add
    import bisect

    xh.sort(key=itemgetter(0))
    coordinate = [xh[i][0] for i in range(n)]
    hp = [xh[i][1] for i in range(n)]

    ans = 0
    dmg_cur = 0
    dmg_cum = [0] * (n + 1)

    for i in range(n):
        x = coordinate[i]
        h = hp[i]

        dmg_cur += dmg_cum[i]
        h -= dmg_cur

        if h > 0:
            num = (h + a - 1) // a
            ans += num
            dmg = a * num
            dmg_cur += dmg
            range_left = x
            range_right = x + 2 * d
            index_right = bisect.bisect_right(coordinate, range_right)
            dmg_cum[index_right] -= dmg
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from fractions import gcd
from itertools import permutations, combinations, accumulate
from collections import deque
from heapq import heappush, heappop, heapify
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
MOD = 10**9 + 7

def main():
    c = ord(input())
    c += 1
    if c == 123:
        c = 97
    print(chr(c))

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    c = ord(input())
    c += 1
    if c == 123:
        c = 97
    print(chr(c))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
from fractions import gcd
from itertools import permutations, combinations, accumulate
from collections import deque
from heapq import heappush, heappop, heapify
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
MOD = 10**9 + 7

def main():
    c = ord(input())
    c += 1
    if c == 123:
        c = 97
    print(chr(c))

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    c = ord(input())
    c += 1
    if c == 123:
        c = 97
    print(chr(c))

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

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n0 = int(input())
    c0 = list(map(int, readline().split()))
    c0.sort(reverse=True)

    ans = 0
    mul = pow(2, n0 - 1, MOD)
    add = pow(2, n0 - 2, MOD)

    for i, cc in enumerate(c0, 1):
        ans += cc * mul
        ans %= MOD
        mul += add
        mul %= MOD

    ans *= pow(2, n0, MOD)
    ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n0 = int(input())
    c0 = list(map(int, readline().split()))
    c0.sort(reverse=True)

    ans = 0
    mul = pow(2, n0 - 1, MOD)
    add = pow(2, max(0, n0 - 2), MOD)

    for i, cc in enumerate(c0, 1):
        ans += cc * mul
        ans %= MOD
        mul += add
        mul %= MOD

    ans *= pow(2, n0, MOD)
    ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n0 = int(input())
    c0 = list(map(int, readline().split()))
    c0.sort(reverse=True)

    ans = 0
    mul = pow(2, n0 - 1, MOD)
    add = pow(2, n0 - 2, MOD)

    for i, cc in enumerate(c0, 1):
        ans += cc * mul
        ans %= MOD
        mul += add

    ans *= pow(2, n0, MOD)
    ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n0 = int(input())
    c0 = list(map(int, readline().split()))
    c0.sort(reverse=True)

    ans = 0
    mul = pow(2, n0 - 1, MOD)
    add = pow(2, max(0, n0 - 2), MOD)

    for i, cc in enumerate(c0, 1):
        ans += cc * mul
        ans %= MOD
        mul += add
        mul %= MOD

    ans *= pow(2, n0, MOD)
    ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def main():
    n = int(input())
    a = [int(_) for _ in input().split()]
    idx = -1
    ans = n

    for i in range(1, n+1):
        if i in a:
            idx = a.index(i)
            a = a[idx+1:]
            ans -= 1
        else:
            break

    if ans == n:
        ans = -1

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def main():
    n = int(input())
    a = [int(_) for _ in input().split()]
    seek = 1

    for i in range(n):
        if a[i] == seek:
            seek += 1

    if seek == 1:
        ans = -1
    else:
        ans = n + 1 - seek

    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def main():
    n = int(input())
    a = [int(_) for _ in input().split()]
    idx = -1
    ans = n

    for i in range(1, n+1):
        if i in a[idx + 1:]:
            idx = a.index(i,idx+1)
            ans -= 1
            if idx == n-1:
                break
        else:
            break

    if ans == n:
        ans = -1

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def main():
    n = int(input())
    a = [int(_) for _ in input().split()]
    seek = 1

    for i in range(n):
        if a[i] == seek:
            seek += 1

    if seek == 1:
        ans = -1
    else:
        ans = n + 1 - seek

    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#import math
#import bisect
#import numpy as np
#import itertools
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
INF = float('INF')
sys.setrecursionlimit(10**5)

def main():
    n = int(input())
    s = input()
    ans = 0
    pin = list(itertools.product(range(10), repeat=3))

    for cur in pin:
        a, b, c = map(str,cur)
        if a in s:
            aidx = s.index(a)
            if b in s[aidx+1:]:
                bidx = s[aidx+1:].index(b) + (aidx + 1)
                if c in s[bidx+1:]:
                    ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Fixed submission:
#import math
#import bisect
#import numpy as np
import itertools
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
INF = float('INF')
sys.setrecursionlimit(10**5)

def main():
    n = int(input())
    s = input()
    ans = 0
    pin = list(itertools.product(range(10), repeat=3))

    for cur in pin:
        a, b, c = map(str,cur)
        if a in s:
            aidx = s.index(a)
            if b in s[aidx+1:]:
                bidx = s[aidx+1:].index(b) + (aidx + 1)
                if c in s[bidx+1:]:
                    ans += 1

    print(ans)


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

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    a = list(map(int, readline().split()))

    cnt = [0] * 3
    ans = 1

    for x in a:
        p = cnt.count(x)
        ans *= p
        ans %= MOD
        cnt[cnt.index(x)] += 1

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    a = list(map(int, readline().split()))

    cnt = [0] * 3
    ans = 1

    for x in a:
        p = cnt.count(x)
        if p == 0:
            return print(0)
        ans *= p
        ans %= MOD
        cnt[cnt.index(x)] += 1

    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
a, b, x = [int(i) for i in input().split()]

i = 0

while True:
    #何桁円か確定させる
    price = a * (10**i) + b * (i+1)
    if price > x:
        break
    else:
        i += 1

x -= b * i
n = x//a

print(min(n,10**9))

Fixed submission:
s = input()

if s == 'SUN':
    n = 7
elif s == 'MON':
    n = 6
elif s == 'TUE':
    n = 5
elif s == 'WED':
    n = 4
elif s == 'THU':
    n = 3
elif s == 'FRI':
    n = 2
elif s == 'SAT':
    n = 1

print(n)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from fractions import gcd
from itertools import permutations, combinations, accumulate
from collections import deque
from heapq import heappush, heappop, heapify

input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def main():
    n = int(input())
    a= [0] * (n-1)
    b = [0] * (n-1)
    g = [[] for _ in range(n+1)]
    c = [[0]*(n+1) for _ in range(n+1)]
    cn = 0

    for i in range(n-1):
        a[i], b[i] = map(int, input().split())
        g[a[i]].append(b[i])

    for i in range(1, n+1):
        cc = [_ for _ in range(1, n) if _ not in c[i]]
        heapify(cc)
        for j in g[i]:
            c[i][j] = c[j][i] = heappop(cc)
            cn = max(cn, c[i][j])

    print(cn)
    for p, q in zip(a, b):
        print(c[p][q])



if __name__ == '__main__':
    main()

Fixed submission:
import sys
from fractions import gcd
from itertools import permutations, combinations, accumulate
from collections import deque
from heapq import heappush, heappop, heapify
from collections import deque

input = sys.stdin.readline
sys.setrecursionlimit(10**6)

class Edge:
    def __init__(self, first, second):
        self.color = 0
        self.first = first
        self.second = second

def main():
    def dfs(i, par, pcol):
        cc = 1
        for e in v[i]:
            if cc == pcol:
                cc += 1
            if e.color == 0:
                e.color = cc
                dfs(e.second, par, cc)
                cc += 1

    n = int(input())
    e = [[] for _ in range(n-1)]
    v = [[] for _ in range(n+1)]

    for i in range(n-1):
        a, b = list(map(int,input().split()))
        e[i] = Edge(a, b)
        v[a].append(e[i])

    dfs(1, -1, 0)

    m = 0
    for i in range(n-1):
        m = max(m,e[i].color)

    print(m)
    for i in range(n-1):
        print(e[i].color)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = map(int, readline().split())
    s = input()
    dp1 = [INF] * (n + 1)
    dp1[0] = 0

    for i in range(n):
        for j in range(1, m + 1):
            if i + j > n:
                break
            if s[i + j] == "0":
                dp1[i + j] = min(dp1[i + j], dp1[i] + 1)

    dp2 = [-INF] * (n + 1)
    dp2[0] = dp1[n]
    t = s[::-1]

    for i in range(n):
        for j in range(1, m + 1):
            if i + j > n:
                break
            if t[i + j] == "0":
                dp2[i + j] = max(dp2[i + j], dp2[i] - 1)
    dp2 = dp2[::-1]
    if dp1[n] != INF:
        res = []
        i = 0
        p = 0
        cnt = 0
        while i < n:
            i += 1
            if dp2[i] == cnt + 1:
                res.append(i-p)
                p = i
                cnt += 1
        print(*res)
    else:
        print(-1)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = map(int, readline().split())
    s = input()
    t = [0] * (n + 1)

    cur = n
    for i in range(n, -1, -1):
        if s[i] == "0":
            cur = i
            t[i] = cur
        else:
            t[i] = cur

    res = []

    i = n
    while i > 0:
        nx = max(0, i - m)
        if t[nx] == i:
            return print(-1)
        else:
            res.append(i - t[nx])
            i = t[nx]

    print(*res[::-1])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import collections
import itertools
from operator import mul

n = int(input())
k = n
ans = n -1
prime = []

while k != 1:
    for i in range(2,int(k**0.5)+1):
        if k % i == 0:
            prime.append(i)
            k /= i
            break
    else:
        prime.append(int(k))
        k = 1

div = list(itertools.accumulate(prime,mul))

for i in div:
    ans = min(ans,i + n//i -2)

print(ans)

Fixed submission:
import sys

n = int(input())

for i in range(int(n**0.5),0,-1):
    if n % i == 0:
        print(n//i + i - 2 )
        sys.exit()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = n -1
prime = []

while n != 1:
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            prime.append(i)
            n /= i
            break
    else:
        prime.append(int(n))
        n = 1

for bit in range(1 << len(prime)):
    a = 1
    b = 1

    for i in range(len(prime)):
        if bit >> i & 1:
            a *= prime[i]
        else:
            b *= prime[i]

    ans = min((a+b-2,ans))

print(ans)

Fixed submission:
import sys

n = int(input())

for i in range(int(n**0.5),0,-1):
    if n % i == 0:
        print(n//i + i - 2 )
        sys.exit()
Buggy python submission (verdict: Runtime Error):
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    w = {'Sunny': 'Cloudy', 'Cloudy': 'Rainy', 'Rainy': 'Sunny'}
    print(w[s])

if __name__ == '__main__':
    main()

Fixed submission:
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input().rstrip('\n')
    w = {'Sunny': 'Cloudy', 'Cloudy': 'Rainy', 'Rainy': 'Sunny'}
    print(w[s])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    s = input()
    x = 1

    sn = [ord(c) - 96 + x for c in s]

    lmax = n // 2
    m1 = 10 ** 9 + 7
    m2 = 2 ** 61 - 1

    ans = 0

    for l in range(1, lmax + 1):
        appeared = set()
        diff = pow(m1, l - 1, m2)

        h_init = 0
        for i in range(l):
            h_init += sn[i] * pow(m1, l - 1 - i, m2)

        hashlist = [0] * n
        hashlist[0] = h_init
        h = h_init

        for i in range(l, n):
            h -= sn[i-l] * diff
            h *= m1
            h += sn[i]
            h %= m2
            hashlist[i] = h
            if i - l >= 0:
                appeared.add(hashlist[i-l])
            if h in appeared:
                ans = l
                break

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    s = input()
    x = 1

    sn = [ord(c) - 96 + x for c in s]

    lmax = n // 2
    m1 = 10 ** 9 + 7
    m2 = 2 ** 61 - 1

    ans = 0

    ng = n + 1
    ok = 0

    while abs(ng - ok) > 1:
        l = (ng + ok) // 2
        found = False

        appeared = set()
        diff = pow(m1, l - 1, m2)

        h_init = 0

        for i in range(l):
            h_init += sn[i] * pow(m1, l - 1 - i, m2)
            h_init %= m2

        hashlist = [0] * n
        hashlist[l - 1] = h_init
        h = h_init

        for i in range(l, n):
            h -= sn[i - l] * diff
            h *= m1
            h += sn[i]
            h %= m2
            hashlist[i] = h
            if i - l >= 0:
                appeared.add(hashlist[i - l])
            if h in appeared:
                found = True
                break

        if found:
            ok = l
        else:
            ng = l

    print(ok)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

import bisect

# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd

import itertools

# from operator import attrgetter, itemgetter
import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k = list(map(int, readline().split()))
    stemp = input()
    s = "R"
    s += stemp
    s += "L"

    unhappy_edge = 0

    if s[1] == "L":
        unhappy_edge += 1
    if s[-2] == "R":
        unhappy_edge += 1

    unhappy_pair = 0
    prev = s[1]
    for i in range(2, n + 1):
        current = s[i]
        if prev == "R" and current == "L":
            unhappy_pair += 1
        prev = current

    while k > 0:
        if unhappy_pair > 0:
            unhappy_pair -= 1
            k -= 1
        elif unhappy_edge == 2:
            unhappy_edge -= 1
            break

    print(n - unhappy_pair * 2 - unhappy_edge)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

import bisect

# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd

import itertools

# from operator import attrgetter, itemgetter
import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k = list(map(int, readline().split()))
    stemp = input()
    s = "R"
    s += stemp
    s += "L"

    unhappy_edge = 0

    if s[1] == "L":
        unhappy_edge += 1
    if s[-2] == "R":
        unhappy_edge += 1

    unhappy_pair = 0
    prev = s[1]
    for i in range(2, n + 1):
        current = s[i]
        if prev == "R" and current == "L":
            unhappy_pair += 1
        prev = current

    temp = min(k, unhappy_pair)
    unhappy_pair -= temp
    k -= temp

    if k > 0:
        unhappy_edge = 1

    print(n - unhappy_pair * 2 - unhappy_edge)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

# import bisect
# from collections import Counter, deque

# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math


# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = [int(readline()) for _ in range(n)]

    c = [-1] * n
    ans = 1

    for number in a:
        for j in range(ans):
            if c[j] < number:
                c[j] = number
                break
        else:
            c[ans] = number
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

import bisect

# from collections import Counter, deque

# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math


# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = [-int(readline()) for _ in range(n)]

    c = [1] * n

    for number in a:
        idx = bisect.bisect_right(c, number)
        c[idx] = number

    ans = bisect.bisect_left(c, 1)
    print(ans)


if __name__ == '__main__':
    main()