Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def main():
  import sys
  input = sys.stdin.readline
  import bisect

  N, K = [int(x) for x in input().split()]
  A = [int(x) for x in input().split()]

  A_m = [abs(int(x)) for x in A if x < 0]
  A_m.sort()
  N_m = len(A_m)

  A_p = [int(x) for x in A if x > 0]
  A_p.sort()
  N_p = len(A_p)

  M = N_m * N_p
  P = (1 / 2) * (N_m) * (N_m - 1) + (1 / 2) * (N_p) * (N_p - 1)
  Z = (1 / 2) * N * (N - 1) - (M + P)

  if M < K <= M + Z:
      print(0)
      sys.exit()

  def cnt_M(x):
      cnt = 0
      for i in A_m:
          cnt += bisect.bisect_right(A_p, x // i)
      return cnt >= (M - K + 1)

  if K <= M:
      left = -1 - 10**18
      right = 1 + 10**18 
      while right - left > 1:
          mid = (left + right) // 2
          if cnt_M(mid):
              right = mid
          else:
              left = mid
      print(-right)
      sys.exit()
  K -= (M + Z)
  def cnt_P(x):
      cnt = 0
      ng = 0
      for i in A_m:
          cnt += bisect.bisect_right(A_m, x // i)
          if i ** 2 <= x:
              ng += 1
      for j in A_p:
          cnt += bisect.bisect_right(A_p, x // j)
          if j ** 2 <= x:
              ng += 1
      return (cnt - ng) // 2 >= K

  left = -1 - 10**18
  right = 1 + 10**18
  while right - left > 1:
      mid = (left + right) // 2
      if cnt_P(mid):
         right = mid
      else:
          left = mid

  print(right)
main()

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

A = [int(x) for x in input().split()]

from collections import Counter

c = Counter(A)

for i in c.values():
    if i == 2:
        print("Yes")
        sys.exit()
print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N = [int(x) for x in input().rstrip()][::-1] + [0]
L = len(N)

dp = [[10 ** 18, 10 ** 18] for _ in range(L)]
dp[0] = [N[0], 10 - N[0]]

for i in range(1, L):
    n = N[i]
    dp[i][0] = min(dp[i - 1][0] + n, dp[i - 1][1] + (n + 1))
    dp[i][1] = min(dp[i - 1][0] + (10 - n), dp[i - 1][1] + (10 - (n + 1)))

print(dp[-1][0])

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

N = [int(x) for x in input().rstrip()][::-1] + [0]
L = len(N)

dp = [[10 ** 18, 10 ** 18] for _ in range(L + 1)]
dp[0] = [0, 0]
dp[1] = [N[0], 10 - N[0]]

for i in range(2, L + 1):
    n = N[i - 1]
    dp[i][0] = min(dp[i - 1][0] + n, dp[i - 1][1] + (n + 1))
    dp[i][1] = min(dp[i - 1][0] + (10 - n), dp[i - 1][1] + (10 - (n + 1)))

print(dp[-1][0])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N = int(input())
P = [int(x) for x in input().split()]

cnt = 0
for i in range(N):
    if P[i] <= min(P[:i+1]):
        cnt += 1
print(cnt)

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
P = [int(x) for x in input().split()]
cnt = 1
minP = P[0]
for i in range(1, N):
    if minP >= P[i]:
        cnt += 1
        minP = P[i]

print(cnt)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N = int(input())
XL = []
import numpy as np
for _ in range(N):
    XL.append([int(x) for x in input().split()])
XL = np.array(sorted(XL))
XL_max = []
XL_min = []
for i in XL:
    XL_max.append(i[0] + i[1])
    XL_min.append(i[0] - i[1])
A = [0] * N
for i in range(N):
    cnt = 0
    left = sorted(XL_max[:i])
    right = sorted(XL_min[i+1:])
    cnt += i - np.searchsorted(left, XL_min[i], side = "right") 
    cnt += np.searchsorted(right, XL_max[i], side = "left")
    A[i] = cnt
cnt = np.array(sorted(A, reverse=True), np.int64)
cnt = np.cumsum(cnt)
if cnt[-1] == 0:
    print(n)
else:
    print(N - (np.searchsorted(cnt, cnt[-1] // 2) + 1))



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

N = int(input())
XL = []
for _ in range(N):
    tmp = [int(x) for x in input().split()]
    XL.append(tmp)
LR = []
for i in XL:
    LR.append([i[0] - i[1], i[0] + i[1]])
LR.sort()
ans = N
last = LR[0][1]
for i in range(1, N):
    if last > LR[i][0]:
        if last > LR[i][1]:
            last = LR[i][1]
        ans -= 1
    else:
        last = LR[i][1]
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N = int(input())
X = []
L = []
XL = []
for _ in range(N):
    XL.append([int(x) for x in input().split()])
XL = sorted(XL)
for i in XL:
    X.append(i[0])
    L.append(i[1])
import numpy as np
X = np.array(X, np.int64)
L = np.array(L, np.int64)
XL_max = X + L
XL_min = X - L
A = [0] * N
for i in range(N):
    cnt = 0
    left = sorted(XL_max[:i])
    right = sorted(XL_min[i+1:])
    cnt += i - np.searchsorted(left, XL_min[i], side = "right") 
    cnt += np.searchsorted(right, XL_max[i], side = "left")
    A[i] = cnt
cnt = np.array(sorted(A, reverse=True), np.int64)
cnt = np.cumsum(cnt)
if cnt[-1] == 0:
    print(n)
else:
    print(N - (np.searchsorted(cnt, cnt[-1] // 2) + 1))



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

N = int(input())
XL = []
for _ in range(N):
    tmp = [int(x) for x in input().split()]
    XL.append(tmp)
LR = []
for i in XL:
    LR.append([i[0] - i[1], i[0] + i[1]])
LR.sort()
ans = N
last = LR[0][1]
for i in range(1, N):
    if last > LR[i][0]:
        if last > LR[i][1]:
            last = LR[i][1]
        ans -= 1
    else:
        last = LR[i][1]
print(ans)
Buggy python submission (verdict: Runtime Error):
def cmb(n, k, mod, fac, ifac):
    """
    nCkを計算する
    """
    k = min(k, n-k)
    return fac[n] * ifac[k] * ifac[n-k] % mod


def make_tables(mod, n):
    """
    階乗テーブル、逆元の階乗テーブルを作成する
    """
    fac = [1, 1] # 階乗テーブル・・・(1)
    ifac = [1, 1] #逆元の階乗テーブル・・・(2)
    inverse = [0, 1] #逆元テーブル・・・(3)

    for i in range(2, n+1):
        fac.append((fac[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        ifac.append((ifac[-1] * inverse[-1]) % mod)
    return fac, ifac
    
n,k=map(int,input().split())
a=sorted(list(map(int, input().split())))
MOD=10**9+7

fac, ifac=make_tables(MOD,n)

s=0
for i in range(k-1,n):
	s+=(a[i]-a[n-i-1])*cmb(i,k-1,MOD,fac,ifac)
	s%=10**9+7
print(s)



Fixed submission:
import sys
input = sys.stdin.readline
C = input().rstrip()
al = [chr(i) for i in range(97, 97+26)]
alpha2num = lambda c: ord(c) - ord("a")
print(al[alpha2num(C) + 1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import numpy as np
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A = np.sort(np.array(A))
def shake_hands(x):
    cnt = 0
    for i in A:
        X = np.searchsorted(A, x - i, side="left")
        cnt += N - X
    if cnt >= M:
        return 1
    return 0
left = 2
right = 10 ** 6
while True:
    m = (right + left) // 2
    if shake_hands(m) == 1 and shake_hands(m+1) == 0:
        maximum = m
        break
    elif shake_hands(m) == 0 and shake_hands(m-1) == 1:
        maximum = m - 1
        break
    elif shake_hands(m) == 1:
        left = m + 1
    else:
        right = m - 1
A_cumsum = np.array(np.cumsum(A))
ans = 0
cnt = 0
for i in A:
    a = np.searchsorted(A, (maximum + 1) - i, side="left")
    if a != 0:
        ans += A_cumsum[-1] - A_cumsum[a-1] 
        ans += (N - a) * i
        cnt += N - a
    else:
        ans += A_cumsum[-1]
        cnt += N
        ans += N * i
ans += maximum * (M - cnt)
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
import numpy as np
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A = np.sort(np.array(A))
def shake_hands(x):
    cnt = 0
    X = np.searchsorted(A, x - A, side="left")
    cnt += N * N - X.sum()
    if cnt >= M:
        return 1
    return 0
left = 0
right = 10 ** 6
while True:
    m = (right + left) // 2
    if shake_hands(m) == 1 and shake_hands(m+1) == 0:
        maximum = m
        break
    elif shake_hands(m) == 0 and shake_hands(m-1) == 1:
        maximum = m - 1
        break
    elif shake_hands(m) == 1:
        left = m + 1
    else:
        right = m - 1
X = np.searchsorted(A,maximum+1-A) # 行わない人数
Acum = np.zeros(N+1,np.int64) # 人数 -> 累積和
Acum[1:] = np.cumsum(A)

shake = N * N - X.sum()
happy = (Acum[-1] - Acum[X]).sum() + (A * (N - X)).sum()

happy += (M - shake) * (maximum)
print(happy)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, M, V, P = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A = sorted(A)
kakutei = A[-P]
kakutei_idx = A.index(kakutei)
ans = N - kakutei_idx
V -= (ans - 1)
A = A[:kakutei_idx]
A = sorted(A, reverse=True)
N = len(A)
kakutei_muri = A[-(V - 1)]
kakutei_muri_idx = A.index(kakutei_muri)
ans += (kakutei_muri_idx)
print(ans)



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

n, m, v, p = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
a = a[::-1]

ans = p

b = a[p:]
b_cumsum = [a[p - 1]]
for i in b:
    b_cumsum.append(b_cumsum[-1] + i)

for i in range(len(b)):
    vote_cnt = max(0, (v - p - (len(b) - (i + 1))))
    if b_cumsum[i] + m * vote_cnt <= (b[i] + m) * (i + 1) and a[p - 1] <= b[i] + m:
        ans += 1
    else:
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n = int(input())

from collections import defaultdict
d = defaultdict(list)

for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = [int(x) for x in input().split()]
        d[i].append((x - 1, y))
ans = 0
for k in range(2**n):
    res = 0
    j = bin(k)[2:].zfill(n)
    for i in range(n):
        if j[i] == "0":
            continue
        flag = 1
        for x, y in d[i]:
            if int(j[x]) != int(y):
                flag = 0
                break
        res += 1
    if flag:
        ans = max(ans, res)
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
S = [[] for _ in range(N)]
for i in range(N):
    A = int(input())
    temp = []
    for _ in range(A):
        temp.append([str(x) for x in input().split()])
        S[i] = temp
ans = 0
for i in range(2 ** N - 1, -1,-1):
    biti = list(bin(i)[2:].zfill(N))
    flag = 0
    for j in range(N):
        if biti[j] == "1":
            for k in S[j]:
                if biti[int(k[0])-1] != k[1]:
                    flag = 1
                    break
        if flag:
            break
    if not flag:    
        biti = np.array(biti)
        ans = max(ans, np.count_nonzero(biti == "1"))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np
N = int(readline())
A = [int(x) for x in readline().rstrip().split()]
B = [0] * 60
ans = 0
for i in range(N):
    i_bin = np.array(list(bin(A[i])))
    i_bin = i_bin[2:]
    i_bin = i_bin[::-1]
    k = 0
    for j in i_bin:
        if j == "1":
            B[k] += 1
        k += 1

for q in range(60):
    temp = B[q] * (N - B[q])
    ans += (temp % (7 + 10 ** 9)) * ((2 ** q) % (7 + 10 ** 9))
    ans %= 7 + 10 ** 9
print(ans)    

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = [int(x) for x in readline().rstrip().split()]
B = [0] * 60
ans = 0
for i in range(N):
    i_bin = list(bin(A[i]))
    i_bin = i_bin[2:]
    i_bin = i_bin[::-1]
    k = 0
    for j in i_bin:
        if j == "1":
            B[k] += 1
        k += 1

for q in range(60):
    temp = B[q] * (N - B[q])
    ans += (temp % (7 + 10 ** 9)) * ((2 ** q) % (7 + 10 ** 9))
    ans %= 7 + 10 ** 9
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
A = [int(x) for x in readline().rstrip().split()]
B = [0] * 60
ans = 0
for i in range(N):
    i_bin = list(bin(A[i]))
    i_bin = i_bin[2:]
    i_bin = i_bin[::-1]
    k = 0
    for j in i_bin:
        if j == "1":
            B[k] += 1
        k += 1
B = np.array(B)

for q in range(60):
    temp = B[q] * (N - B[q])
    ans += (temp % (7 + 10 ** 9)) * ((2 ** q) % (7 + 10 ** 9))
    ans %= 7 + 10 ** 9
print(ans)    

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = [int(x) for x in readline().rstrip().split()]
B = [0] * 60
ans = 0
for i in range(N):
    i_bin = list(bin(A[i]))
    i_bin = i_bin[2:]
    i_bin = i_bin[::-1]
    k = 0
    for j in i_bin:
        if j == "1":
            B[k] += 1
        k += 1

for q in range(60):
    temp = B[q] * (N - B[q])
    ans += (temp % (7 + 10 ** 9)) * ((2 ** q) % (7 + 10 ** 9))
    ans %= 7 + 10 ** 9
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

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

mean = sum(a) / n

ans = [200, 200]

for i in range(n):
    if abs(mean - a[i]) < ans[1]:
        ans = [i, abs(mean - a[i])]

print(ans[0])


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

x, y = [int(x) for x in input().split()]
ans = 0

for i in [x, y]:
    if i == 1:
        ans += 300000
    elif i == 2:
        ans += 200000
    elif i == 3:
        ans += 100000
    
if x == 1 and y == 1:
    ans += 400000

print(ans)
Buggy python submission (verdict: Runtime Error):
import math
X,Y = list(map(int,input().split()))
if X%3!=0 or Y%3!=0:
    print(0)
else:
    n = (2*Y - X)//3
    m = (2*X - Y)//3

a = math.factorial(n+m)
b = math.factorial(m)
c = math.factorial(n)
print((a//(b*c))%(7+10**9))

Fixed submission:
X,Y = list(map(int,input().split()))
def nCk(n, k, mod=10 ** 9 + 7):
    if n < k:
        return 0
    k = min(k, n - k)
    numer = 1
    for x in range(n - k + 1, n + 1):
        numer = (numer * x) % mod
    denom = 1
    for x in range(1, k + 1):
        denom = (denom * x) % mod
    return numer * pow(denom, mod - 2, mod) % mod
if (X+Y)%3!=0:
    print(0)
else:
    n = (2*Y - X)//3
    m = (2*X - Y)//3
    if n<0 or m<0:
        print(0)
    else:
        print(nCk(n+m, m)%(7+10**9))
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect
N = int(input())
L = list(map(int,input().split()))
L.sort()
cnt = 0

for i in range(N-1,1,-1):
    for j in range(i-1,0,-1):
        temp = L[i] - L[j]
        l = bisect(L,temp,lo=0,hi=j)
        cnt += j - l
print(cnt)


Fixed submission:
def main():
    from bisect import bisect
    N = int(input())
    L = list(map(int,input().split()))
    L.sort()
    cnt = 0

    for i in range(N-1,1,-1):
        for j in range(i-1,0,-1):
            temp = L[i] - L[j]
            l = bisect(L,temp,lo=0,hi=j)
            cnt += j - l
    print(cnt)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int,input().split()))
L.sort()
cnt = 0
for i in range(N-1,1,-1):
    for j in range(i-1,0,-1):
        temp = L[i] - L[j]
        k = j-1
        while L[k] > temp and k >= 0:
            cnt += 1
            k -= 1
print(cnt)


Fixed submission:
def main():
    from bisect import bisect
    N = int(input())
    L = list(map(int,input().split()))
    L.sort()
    cnt = 0

    for i in range(N-1,1,-1):
        for j in range(i-1,0,-1):
            temp = L[i] - L[j]
            l = bisect(L,temp,lo=0,hi=j)
            cnt += j - l
    print(cnt)
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    a = list(map(int,input().split()))
    ans = []
    for i in range(1,N+1):
        ans.append(a.index(i)+1)
    print(*ans)


if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    ans = [0]*N
    a = list(map(int,input().split()))
    for i in range(N):
        ans[a[i]-1] = i+1
    print(*ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    A,B = map(int,input().split())
    import math
    C = math.gcd(A,B)
    cnt = 0
    def make_divisors(n):
        divisors = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n//i)
        return divisors
    def is_prime(n):
        if n == 1:
            return True
        for i in range(2,int(n**0.5)+1):
            if n % i == 0:
                return False
        return True
    
    C_2 = make_divisors(C)
    
    for i in C_2:
        if is_prime(i):
            cnt += 1
    print(cnt)
    
    


    
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    A,B = map(int,input().split())
    import fractions
    C = fractions.gcd(A,B)
    cnt = 0
    def make_divisors(n):
        divisors = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n//i)
        return divisors
    def is_prime(n):
        if n == 1:
            return True
        for i in range(2,int(n**0.5)+1):
            if n % i == 0:
                return False
        return True
    
    C_2 = make_divisors(C)
    
    for i in C_2:
        if is_prime(i):
            cnt += 1
    print(cnt)
    
    


    
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
S=input()
N = len(S)
ans=0
for i in range(N+1):
    if i%2==0:
        if S[i]=='L':
            print('No')
        else:
            ans+=1
    else:
        if S[i]=='R':
            print('No')
        else:
            ans+=1
if ans==2:
    print('Yes')

Fixed submission:
S=input()
N = len(S)
S_o=[]
S_e=[]
for i in range(N):
    if i%2==0:
        S_o.append(S[i])
    else:
        S_e.append(S[i])
if 'L' in S_o or 'R' in S_e:
    print('No')
else:
    print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    import heapq
    input=sys.stdin.readline
    N,M=map(int,input().split())
    A=list(map(lambda x:-1*int(x),input().split()))
    for i in range(M):
        heapq.heapify(A)
        if i==0:
            temp = -(heapq.heappop(A))//2
        else:
            heapq.heappush(A,-temp)
            temp = -(heapq.heappop(A))//2
    print(-sum(A)+temp)
    
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    import heapq
    input=sys.stdin.readline
    N,M=map(int,input().split())
    A=list(map(lambda x:-1*int(x),input().split()))
    heapq.heapify(A)
    for i in range(M):
        if i==0:
            temp = -(heapq.heappop(A))//2
        else:
            heapq.heappush(A,-temp)
            temp = -(heapq.heappop(A))//2
    print(-sum(A)+temp)
    
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    import heapq
    input=sys.stdin.readline
    N,M=map(int,input().split())
    A=list(map(int,input().split()))
    A=[-x for x in A]
    for i in range(M):
        heapq.heapify(A)
        if i==0:
            temp = -(heapq.heappop(A))//2
        else:
            heapq.heappush(A,-temp)
            temp = -(heapq.heappop(A))//2
    print(-sum(A)+temp)
    
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    import heapq
    input=sys.stdin.readline
    N,M=map(int,input().split())
    A=list(map(lambda x:-1*int(x),input().split()))
    heapq.heapify(A)
    for i in range(M):
        if i==0:
            temp = -(heapq.heappop(A))//2
        else:
            heapq.heappush(A,-temp)
            temp = -(heapq.heappop(A))//2
    print(-sum(A)+temp)
    
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n = int(input())
s = input().rstrip()

strings = [[] for _ in range(n // 2 + 1)]

for i in range(n):
    string = [s[i]]
    strings[1].append(s[i])
    for j in range(i + 1, n):
        string.append(s[j])
        if j - i + 1 < 1 + n // 2:
            strings[j - i + 1].append("".join(string))

ans = 0

for i in range(n // 2, 0, -1):
    check = strings[i]
    for j in range(len(check)):
        check_set = set(check[j + i:])
        if check[j] in check_set:
            print(i)
            sys.exit()

print(ans)


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

n = int(input())
s = input().rstrip()

def z_algo(S):
    N = len(S)
    A = [0]*N
    i = 1; j = 0
    A[0] = l = len(S)
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A

ans = 0

for i in range(n):
    s_ = s[i:]
    z_s = z_algo(s_)
    for j in range(len(z_s)):
        ans = max(ans, min(j, z_s[j]))

print(ans)

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

n = int(input())
s = input().rstrip()

strings = [[] for _ in range(n // 2 + 1)]

for i in range(n):
    string = [s[i]]
    strings[1].append(s[i])
    for j in range(i + 1, n):
        string.append(s[j])
        if j - i + 1 < 1 + n // 2:
            strings[j - i + 1].append("".join(string))

ans = 0

for i in range(n // 2, 0, -1):
    check = strings[i]
    for j in range(len(check)):
        if check[j] in check[j + i:]:
            print(i)
            sys.exit()

print(ans)


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

n = int(input())
s = input().rstrip()

def z_algo(S):
    N = len(S)
    A = [0]*N
    i = 1; j = 0
    A[0] = l = len(S)
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A

ans = 0

for i in range(n):
    s_ = s[i:]
    z_s = z_algo(s_)
    for j in range(len(z_s)):
        ans = max(ans, min(j, z_s[j]))

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque
N,K = list(map(int,input().split()))
S = list(input())
S = deque(S)
i = 0
ans = 0
S_2 = [S.popleft()]
while len(S) > 0:
    if S[0] == S_2[-1]:
        ans += 1
        S.popleft()
    else:
        S_2.append(S.popleft())
cnt = 0

for i in range(1,len(S_2)-1):
    if S_2[i] != S_2[i-1] and S_2[i] != S_2[i+1]:
        ans += 2
        K -= 1
        S_2[i] = S_2[i-1]
        if K ==0:
            break
if K > 0:
    if len(S_2) == 1:
        print(ans)
    elif len(S_2) == 2 and S_2[0] != S_2[1]:
        print(ans + 1)
    else:
        if (S[0] != S[1] or S[-1] != S[-2]) and K == 1:
            print(ans + 1)
        elif K > 1 and (S[0] != S[1] and S[-1] != S[-2]):
            print(ans + 2)
        elif K > 1 and (S[0] != S[1] and S[-1] == S[-2]) or (S[0] == S[1] or S[-1] != S[-2]):
            print(ans + 1)
        else:
            print(ans)
else:
    print(ans)

Fixed submission:
from collections import deque
N,K = list(map(int,input().split()))
S = list(input())
S = deque(S)
ans = 0
S_2 = [S.popleft()]
while len(S) > 0:
    if S[0] == S_2[-1]:
        ans += 1
        S.popleft()
    else:
        S_2.append(S.popleft())
cnt = 0

for i in range(1,len(S_2)-1):
    if S_2[i] != S_2[i-1] and S_2[i] != S_2[i+1]:
        ans += 2
        K -= 1
        S_2[i] = S_2[i-1]
        if K ==0:
            break
if len(S_2) == 1:
    print(ans) 
elif len(S_2) == 2:
    if S_2[0] == S_2[1] or K == 0:
        print(ans)
    else:
        print(ans + 1)
else:
    if S_2[0] != S_2[1] and S_2[-1] != S_2[-2] and K > 1:
        print(ans + 2)
    elif K == 0 or (S_2[0] == S_2[1] and S_2[-1] == S_2[-2]):
        print(ans)
    else:
        print(ans + 1)