Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, M=input().split()
if N == M:
  print(AC)
else:
  print(WA)

Fixed submission:
N, M=input().split()
if N == M:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
x = input()
print chr(ord(x) + 1)

Fixed submission:
x = input()
print(chr(ord(x) + 1))

Buggy python submission (verdict: Runtime Error):
c =input()
c=c.upper()
c=chr(ord(c) + 1)
print(x)
 

Fixed submission:
x = input()
print(chr(ord(x) + 1))
Buggy python submission (verdict: Runtime Error):
S,T = map(int,input().split())
print(T+S)

Fixed submission:
S,T = map(str,input().split())
print(T+S)
Buggy python submission (verdict: Runtime Error):
A,B,K = map(int,input().split())
T = A - K
O = 0
if T >= 0:
	print(T, 0)
	else:
      print(0,O-T)

Fixed submission:
A,B,K = map(int,input().split())
T = A - K
O = B

if T >= 0:
    print(T, O)
elif O+T >=0:
    print(0,O+T)
else:
    print(0,0)
Buggy python submission (verdict: Runtime Error):
def main():
    n = input('Find the next prime number greater great than: ')
    print find_next_prime(n+1)

def find_next_prime(n):
    return find_prime_in_range(n, 2*n)

def find_prime_in_range(a, b):
    for p in range(a, b):
        for i in range(2, p):
            if p % i == 0:
                break
        else:
            return p
    return None

if __name__ == '__main__':
    main()

Fixed submission:
import math 
def isPrime(n):
    if n == 1:
        return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True
def nextPrime(N):
    if N <= 1:
        return 2
    prime = N
    found = False
    while(not found): 
        prime = prime + 1
        if(isPrime(prime) == True): 
            found = True
    return prime 
A = int(input())
N = A-1
print(nextPrime(N))
Buggy python submission (verdict: Runtime Error):
def make_divisors(n):
    divisors = []
    for i in range(1, n):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
 
    # divisors.sort()
    return divisors
A, B, K=map(int,input().split())
dA = make_divisors(A)
dB = make_divisors(B)
D = list(set(dA)&set(dB))
print(D[-K])

Fixed submission:
a,b,k=map(int,input().split())
check=0
m=min(a,b)
for i in range(m,0,-1):
    if a%i==0 and b%i==0:
        check+=1
        if check==k:
            print(i)
            break

Buggy python submission (verdict: Runtime Error):
def cf(x1,x2):
    cf=[]
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf
A, B, K=map(int,input().split())
D = cf(A,B)
print(D[-K])


Fixed submission:
a,b,k=map(int,input().split())
check=0
m=min(a,b)
for i in range(m,0,-1):
    if a%i==0 and b%i==0:
        check+=1
        if check==k:
            print(i)
            break
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
counter = False
#for n in range (0,100):
  for i in range (math.ceil((n+1) / 4) ):
    for j in range (math.ceil((n+1) / 7) ):
      #print(n, i,j)
      if i*4 + j*7 == n:
        counter = True
  if counter == True:
    print("Yes")
  else:
    print("No")

Fixed submission:
import math
n = int(input())
counter = False
#for n in range (0,100):
for i in range (math.ceil((n+1) / 4) ):
  for j in range (math.ceil((n+1) / 7) ):
    #print(n, i,j)
    if i*4 + j*7 == n:
      counter = True
if counter == True:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
counter = False
#for n in range (0,100):
  for i in range (math.ceil((n+1) / 4) ):
    for j in range (math.ceil((n+1) / 7) ):
      #print(n, i,j)
      if i*4 + j*7 == n:
        counter = True
  if counter == True:
    print("Yes")
  else:
   	print("No")

Fixed submission:
import math
n = int(input())
counter = False
#for n in range (0,100):
for i in range (math.ceil((n+1) / 4) ):
  for j in range (math.ceil((n+1) / 7) ):
    #print(n, i,j)
    if i*4 + j*7 == n:
      counter = True
if counter == True:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
D = int(input())
N = int(input())
if D == 2:
  print(N*10000)
elif D == 1:
  print(N*100)
else:
  print(N)
  

Fixed submission:
D, N = map(int,input().split())
if D == 2:
  if N < 100:
    print(N*10000)
  else:
    print(1010000)
elif D == 1:
  if N < 100:
    print(N*100)
  else:
    print(10100)
else:
  if N < 100:
    print(N)
  else:
    print(101)
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
n = N
amari = 0
for i in range (len(str(N))):
  amari += n % 10
  n = math.floor(n / 10)
if amari = 1:
  print(10)
else:
  print(amari)

Fixed submission:
import math
N = int(input())
n = N
amari = 0
for i in range (len(str(N))):
  amari += n % 10
  n = math.floor(n / 10)
if amari == 1:
  print(10)
else:
  print(amari)
Buggy python submission (verdict: Runtime Error):
a = int(input())
count = 0
for i in range (3):
  if str(a)[i] == '1':
    count += 1
  else:
    pass
print(count)

Fixed submission:
a = int(input())
count = 0
for i in range (len(str(a))):
  if str(a)[i] == '1':
    count += 1
  else:
    pass
print(count)
Buggy python submission (verdict: Runtime Error):
N, A, B = map(int, input()split()) 
if B >= A*N:
  print(A*N)
else:
  print(B)

Fixed submission:
N, A, B = map(int, input().split()) 
if B >= A*N:
  print(A*N)
else:
  print(B)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

cnt = 1
for i in range(1,N):
    for j in range(0,i):
        if A[i] > A[j]:
            break
    else:
        cnt += 1
print(cnt)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))

cnt = 0
# for i in range(1,N):
#     for j in range(0,i):
#         if A[i] > A[j]:
#             break
#     else:
#         cnt += 1
min_value = A[0]
for i in range(N):
    if min_value >= A[i]:
        cnt += 1
        min_value = A[i]

print(cnt)
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = ["0"] * 2N

S, T = input().split()
for i in range(N):
  ans[2*i] = S[i]
  ans[2*i+1] = T[i]

print("".join(ans))

Fixed submission:
N = int(input())
ans = ["0"] * 2 * N
 
S, T = input().split()
for i in range(N):
  ans[2*i] = S[i]
  ans[2*i+1] = T[i] 
print("".join(ans))
Buggy python submission (verdict: Runtime Error):
"""
最大公約数を求める
最大公約数の約数を列挙
素数かどうかを判定
"""

import functools
import math

def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

def is_prime(n):
    """素数判定関数

    Arguments:
        n {[type]} -- [description]

    Returns:
        [type] -- [description]
    """
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return True

A, B = map(int,input().split())

gcd = functools.reduce(math.gcd, [A,B])
#print(gcd)
numbers = divisor(int(gcd))
#print(numbers)
ans = 0
for i in numbers:
    if is_prime(i):
        ans += 1
print(ans)



Fixed submission:
"""
最大公約数を求める
最大公約数の約数を列挙
素数かどうかを判定
"""

import math

def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

def max_yakusu(a, b):
    while b:
        a, b = b, a % b
    return a

def is_prime(n):
    """素数判定関数

    Arguments:
        n {[type]} -- [description]

    Returns:
        [type] -- [description]
    """
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return True

A, B = map(int,input().split())

gcd = max_yakusu(B,A)
numbers = divisor(int(gcd))
ans = 0
for i in numbers:
    if is_prime(i):
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
H = list(map(int,input().split()))

max_cnt = 0
for i in range(N-1):
    value = H[i]
    cnt = 0
    for j in range(i+1,N):
        if H[j] > value:
            break
        value = H[j]
        cnt += 1
    if cnt > max_cnt:
        max_cnt = cnt
    
print(max_cnt)

Fixed submission:
N = int(input())
H = list(map(int,input().split()))

max_cnt = 0
cnt_list = [0]
for i in range(N-2,-1,-1):
    value = H[i]
    cnt = 0
    cnt_list.append(cnt_list[-1]+1) if H[i] >= H[i+1] else cnt_list.append(0)
    #print(cnt_list)
print(max(cnt_list))
Buggy python submission (verdict: Runtime Error):
L, R = map(int,input().split())
l , r = L//2019, R//2019
if R - L >= 2019:
    print(0)
else:
    flag=0
    Amari=[]
    for i in range(L,R-1):
        amari = i % 2019
        if i %3 == 0:
            flag = True
        Amari.append(amari)
    if 673 in Amari and flag:
        print(0)
    else:
        print(min(Amari)*(min(Amari)+1))


Fixed submission:
L, R = map(int,input().split())
l , r = L//2019, R//2019
if R - L >= 2019:
    print(0)
elif R-L == 1:
    print(R*L%2019)
else:
    Amari=[]
    for i in range(L,R-1):
        for j in range(i+1,R+1):
            k = i*j
            Amari.append(k%2019)
    print(min(Amari))
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(map(int,input().split()))

# for i in range(m):
#     a = sorted(a)
#     b,c = map(int,input().split())
#     for j in range(b):
#         if a[j] >= c:
#             break
#         else:
#             a[j] = c
# print(sum(a))
d = []
for i in range(m):
    b,c = map(int,input().split()) # b 交換できる枚数 c:カードの値
    d.append((b,c))

# dを降順にsorted
d = sorted(d,key=lambda x: x[1], reverse=True)

for i in range(m):
    b,c = d[i]
    a.extend([c]*b)
    if len(a) > 2*N:
        break

print(sum(sorted(a)[-n:]))

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

# for i in range(m):
#     a = sorted(a)
#     b,c = map(int,input().split())
#     for j in range(b):
#         if a[j] >= c:
#             break
#         else:
#             a[j] = c
# print(sum(a))
d = []
for i in range(m):
    b,c = map(int,input().split()) # b 交換できる枚数 c:カードの値
    d.append((b,c))

# dを降順にsorted
d = sorted(d,key=lambda x: x[1], reverse=True)

for i in range(m):
    b,c = d[i]
    a.extend([c]*b)
    if len(a) > 2*n:
        break

print(sum(sorted(a)[-n:]))

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = list(map(int,input().split()))

# for i in range(m):
#     a = sorted(a)
#     b,c = map(int,input().split())
#     for j in range(b):
#         if a[j] >= c:
#             break
#         else:
#             a[j] = c
# print(sum(a))

for i in range(m):
    b,c = map(int,input().split())
    a.extend([c]*b)
    a = sorted(a)[-n:]
print(sum(a))

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

# for i in range(m):
#     a = sorted(a)
#     b,c = map(int,input().split())
#     for j in range(b):
#         if a[j] >= c:
#             break
#         else:
#             a[j] = c
# print(sum(a))
d = []
for i in range(m):
    b,c = map(int,input().split()) # b 交換できる枚数 c:カードの値
    d.append((b,c))

# dを降順にsorted
d = sorted(d,key=lambda x: x[1], reverse=True)

for i in range(m):
    b,c = d[i]
    a.extend([c]*b)
    if len(a) > 2*n:
        break

print(sum(sorted(a)[-n:]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = map(int,input().split())
B = map(int,input().split())
C = map(int,input().split())

A = sorted(A,reverse=True)
B = sorted(B,reverse=True)
C = sorted(C,reverse=True)

count = 0
for i in range(N):
    a = A[i]
    for j in range(N):
        b = B[j]
        if a >= b:
            #flag = True
            break
        for k in range(N):
            c = C[k]
            if b >= c:
                break
            #print(a,b,c)
            count += 1
print(count)


Fixed submission:
def bs_left(A, target):
    low, high = 0, len(A)
    while low<high:
        mid = (low+high)//2
        if A[mid]<target:
            low = mid+1
        else:
            high = mid
    return low

def bs_right(C, target):
    low, high = 0, len(C)
    while low<high:
        mid = (low+high)//2
        if target<C[mid]:
            high = mid
        else:
            low = mid+1
    return low
if __name__ == '__main__':
    N = int(input())

    A = map(int,input().split())
    B = map(int,input().split())
    C = map(int,input().split())
    A = sorted(A)
    B = sorted(B)
    C = sorted(C)

    count = 0
    for i in range(N):
        b = B[i]
        count = count + bs_left(A,b) * (N - bs_right(C,b))
    print(count)
Buggy python submission (verdict: Runtime Error):
k,s=[int(i) for i in input().split()]
count = 0
for y in range(k+1):
 if i < s - k * 2 or s - i < 0:
  continue
 for x in range(k+1):
   if s - x - y >= 0 and s - x - y <= k:
      count = count+1
print(count)

Fixed submission:
k,s=[int(i) for i in input().split()]
count = 0
for y in range(k+1):
 if y < s - k * 2 or s - y < 0:
  continue
 for x in range(k+1):
   if s - x - y >= 0 and s - x - y <= k:
      count = count+1
print(count)
Buggy python submission (verdict: Runtime Error):
import sys
import collections
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 998244353
N = int(input())
D = list(map(int, input().split()))
mD = max(D)

c = collections.Counter(D)
c = dict(c)

ans = 1
tmp = 1
for i in range(mD+1):
    if not(i in c.keys()):
        ans = 0
        break
    elif i == 0:
        if c[0] > 1:
            ans = 0
            break
    elif i == 1:
        tmp = c[i]
    else:
        ans = (ans * tmp**c[i])%MOD
        tmp = c[i]

if N == 1:
    if D[0] == 0:
        print(1)
    else:
        print(0)
elif N < 5:
    print(D[100])
else:
    print(ans)

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

MOD = 998244353
N = int(input())
D = list(map(int, input().split()))
mD = max(D)

c = collections.Counter(D)
c = dict(c)

ans = 1
tmp = 1
for i in range(mD+1):
    if not(i in c.keys()):
        ans = 0
        break
    elif i == 0:
        if c[0] > 1:
            ans = 0
            break
    elif i == 1:
        tmp = c[i]
    else:
        ans = (ans * tmp**c[i])%MOD
        tmp = c[i]

if D[0] != 0:
    print(0)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import heapq
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

INF = 10**100
N, M = map(int, input().split())
G = [[]for i in range(N)]
for i in range(1, N):
    G[i].append([i-1, 0])

for i in range(M):
    L, R, C = map(int, input().split())
    G[L-1].append([R-1, C])

S = 0

def dijkstra(N, S):
    d = [INF for i in range(N)]

    que = []
    d[S] = 0
    heapq.heappush(que, [0, S])

    while not(len(que) == 0):
        q = heapq.heappop(que)
        ver = q[1] # ノード
        dis = q[0] # 過去に更新された最短距離

        # vまで2番目に短い距離（最新）　＜　過去最短距離　の時、
        # キューから取り出した過去のものを無視する
        if d[ver] < dis:
            continue

        # 隣接リストに対してループ
        for i in range(len(G[ver])):
            e = G[ver][i]
            if d[e[0]] > d[ver] + e[1]:
                d[e[0]] = d[ver] + e[1]
                heapq.heappush(que, [d[e[0]], e[0]])

    return d[N-1]

ans = dijkstra(N, S)
if ans == INF:
    print(-1)
else:
    print(dijkstra(N, S))

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

N, M = map(int, input().split())
E = []
for i in range(M):
    L, R, C = map(int, input().split())
    E.append([L-1, R-1, C])

E = sorted(E, key=lambda X: X[1])

# N_はN以上の2べき数
N_ = 2**(len(bin(N))-2)
INF = 10**15 # 10**10 
seg = [INF] * (2*N_-1)

# k番目(0index)をaに更新
def update(k, a):
    k += N_-1
    seg[k] = a

    while k > 0:
        k = (k-1)//2
        seg[k] = min(seg[k*2+1], seg[k*2+2])

# 開区間！！！[a, b)の最小値を求める
def query(a, b, k, l, r):
    if r <= a or b <= l:
        return INF
    if a <= l and r <= b:
        return seg[k]
    else:
        vl = query(a, b, k*2+1, l, (l+r)//2)
        vr = query(a, b, k*2+2, (l+r)//2, r)
        return min(vl, vr)



# 初期化
update(0, 0)

for i in range(M):
    new = query(E[i][0], E[i][1], 0, 0, N_) + E[i][2]
    if new < seg[E[i][1] + N_-1]:
        update(E[i][1], new)

if seg[N-1+N_-1] == INF:
    print(-1)
else:
    print(seg[N-1+N_-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import heapq

N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A = sorted(A)
F = sorted(F, reverse= True)
S = [(-A[i]*F[i], i) for i in range(N)]

heapq.heapify(S)

for i in range(K):
    ma = heapq.heappop(S)
    A[ma[1]] -= 1
    heapq.heappush(S, (-A[ma[1]]*F[ma[1]], ma[1]))

print(-heapq.heappop(S)[0])


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

N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A = sorted(A)
F = sorted(F, reverse= True)
S = [(-A[i]*F[i], i) for i in range(N)]


def judge(s):
    global N, K
    ksum = 0
    for i in range(N):
        ksum += max(0, -(-(A[i] * F[i] - s) // F[i]))
    if ksum <= K:
        return True
    else:
        return False

lb = -1
ub = 10**13
while lb + 1 < ub:
    mid = (lb + ub) // 2
    if judge(mid):
        ub = mid
    else:
        lb = mid

print(ub)

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

N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A = sorted(A)
F = sorted(F, reverse= True)
S = [(-A[i]*F[i], i) for i in range(N)]

heapq.heapify(S)

for i in range(K):
    ma = heapq.heappop(S)
    A[ma[1]] -= 1
    heapq.heappush(S, (-A[ma[1]]*F[ma[1]], ma[1]))

print(-heapq.heappop(S)[0])


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

N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A = sorted(A)
F = sorted(F, reverse= True)
S = [(-A[i]*F[i], i) for i in range(N)]


def judge(s):
    global N, K
    ksum = 0
    for i in range(N):
        ksum += max(0, -(-(A[i] * F[i] - s) // F[i]))
    if ksum <= K:
        return True
    else:
        return False

lb = -1
ub = 10**13
while lb + 1 < ub:
    mid = (lb + ub) // 2
    if judge(mid):
        ub = mid
    else:
        lb = mid

print(ub)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
S = []
for i in range(N):
    s = list(input().strip())
    s_list = [int(k) for k in s]
    S.append(s_list)

count_max = 0
for i in range(N):
    flag = [-1]*N
    q = deque([i])
    flag[i] = 0
    count = 0
    while(q):
        count += 1
        for k in range(len(q)):
            v = q.popleft()
            for j in range(len(S[v])):
                if S[v][j] == 1 and flag[j] == -1:
                    flag[j] = count
                    q.append(j)
                elif S[v][j] == 1:
                    if flag[j]%2 != count%2:
                        print(-1)
                        sys.exit()
    count_max = max(count, count_max)
print(count_max)
        


Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
S = []
for i in range(N):
    s = list(input().strip())
    s_list = [int(k) for k in s]
    S.append(s_list)

count_max = 0
for i in range(N):
    flag = [-1]*N
    q = deque([i])
    flag[i] = 0
    count = 0
    while(q):
        count += 1
        for k in range(len(q)):
            v = q.popleft()
            for j in range(len(S[v])):
                if S[v][j] == 1 and flag[j] == -1:
                    flag[j] = count
                    q.append(j)
                elif S[v][j] == 1:
                    if flag[j]%2 != count%2:
                        print(-1)
                        sys.exit()
    count_max = max(count, count_max)
print(count_max)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
S = list(input().strip())

dp = [0] * N
max_leng = 0

for i in range(0, N):
    leng = 0
    idx_i = i
    sta_j = -1

    j = i - 1
    while j > -1:
        if sta_j == idx_i:
            leng = 0
            idx_i = i
            j = sta_j-1
            sta_j = -1
            continue

        if S[idx_i] == S[j]:
            if leng == 0:
                sta_j = j
            leng += 1
            idx_i -= 1
            max_leng = max(leng, max_leng)
        else:
            j += leng
            leng = 0
            idx_i = i
        j -= 1
print(max_leng)

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

N = int(input())
S = list(input().strip())

dp = [[0] * N for i in range(N)]
max_leng2 = 0 
for i in range(0, N):
    leng2 = 0

    j = i - 1
    while j > -1:
        if S[i] == S[j]:
            sta_j = j
            if j != 0:
                leng2 = dp[i-1][sta_j-1] + 1
            else: 
                leng2 = 1
            
            if i - sta_j < leng2:
                leng2 = i - sta_j
                
            dp[i][sta_j] = leng2
            max_leng2 = max(max_leng2, leng2)
        j -= 1
print(max_leng2)

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

N = int(input())
S = list(input().strip())

dp = [0] * N
max_leng = 0

for i in range(1, N):
    leng = 0
    idx_i = i
    sta_j = -1

    j = i - 1
    while j > -1:
        if sta_j == idx_i:
            leng = 0
            idx_i = i
            j = sta_j-1
            sta_j = -1
            continue

        if S[idx_i] == S[j]:
            if leng == 0:
                sta_j = j
            leng += 1
            idx_i -= 1
            max_leng = max(leng, max_leng)
        else:
            leng = 0
            idx_i = i
        j -= 1
print(max_leng)

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

N = int(input())
S = list(input().strip())

dp = [[0] * N for i in range(N)]
max_leng2 = 0 
for i in range(0, N):
    leng2 = 0

    j = i - 1
    while j > -1:
        if S[i] == S[j]:
            sta_j = j
            if j != 0:
                leng2 = dp[i-1][sta_j-1] + 1
            else: 
                leng2 = 1
            
            if i - sta_j < leng2:
                leng2 = i - sta_j
                
            dp[i][sta_j] = leng2
            max_leng2 = max(max_leng2, leng2)
        j -= 1
print(max_leng2)
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())

A = []
for i in range(N):
    A.append(list(map(int, input().split())))

B = []
for i in range(N):
    tmp = [0] * N
    for j in range(N-1):
        tmp[A[i][j]-1] = j+1
    B.append(tmp)


ans = N-1
ans_tmp = 0
ans_tmp1 = 0
for i in range(N):
    ans_tmp = 0
    tmp = 0
    for j in A[i]:
        if B[j-1][i] > tmp:
            tmp = B[j-1][i]
        elif B[j-1][i] == tmp:
            ans_tmp += 1
        else:
            print(-1)
            sys.exit()
    ans_tmp1 = max(ans_tmp1, ans_tmp+tmp)

print(ans_tmp1)


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

S = list(input().strip())
T = list(input().strip())

ans = 0
for i in range(len(S)):
    if S[i] == T[i]:
        ans += 1

print(ans)