Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# D
s = input()
length = len(s)
k = length
mid = length//2
max_k = None

while k>mid:
    overlap = s[length-k:k]
    pure = len(set(overlap)) == 1
    if pure:
        max_k = k
        print(max_k)
        break
    k -= 1

if not max_k:
    print(mid)

Fixed submission:
# D 3424320
S = input()
N = len(S)
center_i = N//2
center = S[center_i]

ans = N//2
l = r = center_i
if N%2==0:
    l -= 1
while l >= 0:
    if not (S[l] == center == S[r]):
        break
    l -= 1
    r += 1
    ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
length = len(s)
k = length
mid = length//2

while k>mid:
    overlap = s[length-k:k]
    pure = len(set(list(overlap))) == 1
    if pure:
        print(k)
        exit()
    k -= 1

print(mid)

Fixed submission:
# D 3424320
S = input()
N = len(S)
center_i = N//2
center = S[center_i]

ans = N//2
l = r = center_i
if N%2==0:
    l -= 1
while l >= 0:
    if not (S[l] == center == S[r]):
        break
    l -= 1
    r += 1
    ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
AList = list(map(int, input().split()))

count_list = []
for i in AList:
	count = 0
	odd_flag = True
	while odd_flag:
		i = i / 2
		count += 1
		if i % 2 == 1:
			odd_flag = False
	count_list.append(count)

print(min(count_list))

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

flag = True
count = 0
while flag:
	for i in range(N):
		if Alist[i] % 2 != 0:
			flag = False
			break

	if flag:
		for i in range(N):
			Alist[i] = Alist[i] / 2
		count += 1

print(count)

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

count = 0
roop = 0
while reduce(lambda x,y:x*y, AList) % 2 == 0:
	for i in range(N):
		AList[i] = AList[i] / 2
		if AList[i] % 2 == 0:
			break
		count += 1

roop = count // N
print(roop)

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

flag = True
count = 0
while flag:
	for i in range(N):
		if Alist[i] % 2 != 0:
			flag = False
			break

	if flag:
		for i in range(N):
			Alist[i] = Alist[i] / 2
		count += 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
AList = list(map(int, input().split()))

count = 0
roop = 0
while True:
	for i in range(N):
		AList[i] = AList[i] / 2
		if AList[i] % 2 == 0:
			break
		count += 1
roop = count // N
print(roop)

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

flag = True
count = 0
while flag:
	for i in range(N):
		if Alist[i] % 2 != 0:
			flag = False
			break

	if flag:
		for i in range(N):
			Alist[i] = Alist[i] / 2
		count += 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
AList = list(map(int, input().split()))

count = 0
roop = 0
while True:
	for i in range(N):
		if AList[i] % 2 == 0:
			AList[i] = AList[i] / 2
		else:
			break
		count += 1
	if count % N == 0:
		roop += 1
	else:
		break
print(roop)

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

flag = True
count = 0
while flag:
	for i in range(N):
		if Alist[i] % 2 != 0:
			flag = False
			break

	if flag:
		for i in range(N):
			Alist[i] = Alist[i] / 2
		count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
al = map(int, input().split())
bl = map(int, input().split())
cl = map(int, input().split())
al = sorted(al)
bl = sorted(bl)
cl = sorted(cl)

total = 0
for alnum in al:
    truebl = [blnum for blnum in bl if blnum > alnum]
    for blnum in truebl:
        total += sum(clnum>blnum for clnum in cl)
print(total)

Fixed submission:
# C
import bisect
n = int(input())
al = map(int, input().split())
bl = map(int, input().split())
cl = map(int, input().split())
al = sorted(al)
bl = sorted(bl)
cl = sorted(cl)

total = 0
for blnum in bl:
    alcnt = bisect.bisect_left(al, blnum)
    clcnt = n - bisect.bisect_right(cl, blnum)
    total += alcnt*clcnt
print(total)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
xs = []
ys = []
points = []
for _ in range(n):
    x, y = map(int, input().split())
    xs.append(x)
    ys.append(y)
    points.append((x, y))

                
min_ = float('inf')
for leftx in xs:
    for rightx in xs:
        if leftx >= rightx:
            continue
        for downy in ys:
            for upy in ys:
                if downy >= upy:
                    continue
                cnt = 0
                for tx, ty in points:
                    if (leftx <= tx <= rightx) and (downy <= ty <= upy):
                        cnt += 1
                
                if cnt >= k:
                    yoko = rightx - leftx
                    tate = upy - downy
                    men = yoko*tate
                    if men < min_:
                        min_ = men
print(min_)
                        

Fixed submission:
n, k = map(int,input().split())
ps = [tuple(map(int,input().split())) for i in range(n)]

sx = sorted(ps,key = lambda x: x[0]) # x座標でソート
nx = list(enumerate(sx)) # 頂点番号を付加
ans = 5e18

for f, (x1,y1) in nx[:n-k+1]: # 左辺の頂点
    for e, (x2,y2) in nx[f+k-1:]: # 右辺の頂点
        dx = x2 - x1 # 横
        sy = sorted(y for x,y in sx[f:e+1]) # 含まれる頂点をy座標でソート
        for y3,y4 in zip(sy,sy[k-1:]): # y3=下辺の頂点，y4=上辺の頂点
            if y3 <= y1 and y4 >= y2: # 左右辺の頂点を含むこと
                ans = min(ans, dx * (y4 - y3))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
b = deque(list())
n = int(input())
alist = list(map(int,input().split()))
for a in alist:
    b.append(a)
    b.reverse()
for i in b:
    print(i, end=' ')

Fixed submission:
from collections import deque
b = deque(list())
n = int(input())
alist = list(map(int,input().split()))
num = len(alist)

if num % 2 == 0:
    for i in range(num):
        if i % 2 == 0:
            b.append(alist[i])
        elif i % 2 == 1:
            b.appendleft(alist[i])

elif num % 2 == 1:
    for i in range(num):
        if i % 2 == 1:
            b.append(alist[i])
        elif i % 2 == 0:
            b.appendleft(alist[i])

for i in b:
    print(i, end=' ')
Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial
from collections import Counter
mod = 10**9 + 7

n = int(input())
length = n+1
li = list(map(int,input().split()))

counter = Counter(li)
dup = counter.most_common()[0][0]
be, af = [i for i, x in enumerate(li) if x==dup]
soto = be + length - af - 1

for k in range(1, n+2):
    if k == 1:
        print(n)
    elif k == n+1:
        print(1)
    else:
        zyouhukuari = factorial(length) // (factorial(k)*factorial(length-k))
        if soto-k+1 >= 0:
            zyouhuku = factorial(soto) // (factorial(k-1)*factorial(soto-k+1))
        else:
            zyouhuku = 0
        val = zyouhukuari - zyouhuku
        print(val%mod)

Fixed submission:
import collections

N = int(input())
a = list(map(int, input().split()))

c = collections.Counter(a)
dup = c.most_common()[0][0]

id = [i for i, x in enumerate(a) if x == dup]
L = id[0]
R = id[1]

MOD = 10**9 +7
factorial = [1]
inverse = [1]

for i in range(1, N+2):
    factorial.append(factorial[i-1] * i % MOD)
    inverse.append(pow(factorial[i], MOD-2, MOD))
    

def C(n, r):
    if n < r:
        return 0
    return (factorial[n] * inverse[r] * inverse[n-r]) % MOD

print(N)
for i in range(2, N+2):
    ans = (C(N+1, i) - C(L+(N-R), i-1)) % MOD
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial
from collections import Counter
mod = 10**9 + 7

n = int(input())
length = n+1
li = list(map(int,input().split()))

counter = Counter(li)
for k, v in counter.items():
    if v==2:
        dup = k
be, af = [i for i, x in enumerate(li) if x==dup]
soto = be + length - af - 1

for k in range(1, n+2):
    if k == 1:
        print(n)
    elif k == n+1:
        print(1)
    else:
        zyouhukuari = factorial(length) // (factorial(k)*factorial(length-k))
        if soto-k+1 >= 0:
            zyouhuku = factorial(soto) // (factorial(k-1)*factorial(soto-k+1))
        else:
            zyouhuku = 0
        val = zyouhukuari - zyouhuku
        print(val%mod)

Fixed submission:
import collections

N = int(input())
a = list(map(int, input().split()))

c = collections.Counter(a)
dup = c.most_common()[0][0]

id = [i for i, x in enumerate(a) if x == dup]
L = id[0]
R = id[1]

MOD = 10**9 +7
factorial = [1]
inverse = [1]

for i in range(1, N+2):
    factorial.append(factorial[i-1] * i % MOD)
    inverse.append(pow(factorial[i], MOD-2, MOD))
    

def C(n, r):
    if n < r:
        return 0
    return (factorial[n] * inverse[r] * inverse[n-r]) % MOD

print(N)
for i in range(2, N+2):
    ans = (C(N+1, i) - C(L+(N-R), i-1)) % MOD
    print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
alist = [int(input()) for _ in range(n)]
dis = max(alist) - min(alist)
print(dis)

Fixed submission:
n = int(input())
alist = list(map(int, input().split()))
dis = max(alist) - min(alist)
print(dis)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

left = 0
leftplus = 0
for i in range(len(s)):
    if s[i] == '(':
        left += 1
    else:
        if left == 0:
            leftplus += 1
        else:
            left -= 1

right = 0
rightplus = 0
r = s[::-1]
for i in range(len(reverse)):
    if r[i] == ')':
        right += 1
    else:
        if right == 0:
            rightplus += 1
        else:
            right -= 1
print('('*leftplus + s + ')'*rightplus)

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

left = 0
leftplus = 0
for i in range(len(s)):
    if s[i] == '(':
        left += 1
    else:
        if left == 0:
            leftplus += 1
        else:
            left -= 1

right = 0
rightplus = 0
r = s[::-1]
for i in range(len(r)):
    if r[i] == ')':
        right += 1
    else:
        if right == 0:
            rightplus += 1
        else:
            right -= 1
print('('*leftplus + s + ')'*rightplus)
Buggy python submission (verdict: Runtime Error):
n = int(input())
slist = [int(input()) for _ in range(n)]
slist = sorted(slist)

max_ = 0
for i in range(n+1):
    if i == 0:
        val = sum(slist)
        if val%10 != 0:
            max_ = val
            break
    else:
        for j in range(n-i):
            tmp = slist.copy()
            for k in range(j, j+i):
                tmp.pop(k)
            if (val > max_) and (val%10 != 0):
                max_ = val
            
print(max_)

Fixed submission:
n = int(input())
slist = [int(input()) for _ in range(n)]
total = sum(slist)

if total % 10 != 0:
    print(total)
    exit()
else:
    nonten = []
    for i in range(n):
        if slist[i] % 10 != 0:
            nonten.append(slist[i])
    if len(nonten) == 0:
        print(0)
    else:
        nonten = sorted(nonten)
        total -= nonten[0]
        print(total)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())

ans = float('inf')
for _ in range(2):
    for i in range(1, H):
        a = i*W

        b = ((H - i) // 2) * W
        c = ((H - i + 1)// 2) * W
        ans = min(ans, abs(max(a, b, c) - min(a, b, c)))

        b = (W // 2) * (H -i)
        c = ((W + 1) // 2) * (H - i)
        ans = min(ans, abs(max(a, b, c) - min(a, b, c)))
    H, W = W, H
return ans

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

ans = float('inf')
for _ in range(2):
    for i in range(1, H):
        a = i*W

        b = ((H - i) // 2) * W
        c = ((H - i + 1)// 2) * W
        ans = min(ans, abs(max(a, b, c) - min(a, b, c)))

        b = (W // 2) * (H -i)
        c = ((W + 1) // 2) * (H - i)
        ans = min(ans, abs(max(a, b, c) - min(a, b, c)))
    H, W = W, H
print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools
n, m = map(int, input().split())
adj_matrix = [[0] * n for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    adj_matrix[a-1][b-1] = 1
    adj_matrix[b-1][a-1] = 1

cnt = 0
for each in range(itertools.permutations(range(n))):
    if each[0] != 0:
        break
    flag = 1
    for i in range(n-1):
        flag *= adj_matrix[each[i]][each[i+1]]
    cnt += flag
print(cnt)

Fixed submission:
import itertools
n, m = map(int, input().split())
adj_matrix = [[0] * n for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    adj_matrix[a-1][b-1] = 1
    adj_matrix[b-1][a-1] = 1

cnt = 0
for each in itertools.permutations(range(n)):
    if each[0] != 0:
        break
    flag = 1
    for i in range(n-1):
        flag *= adj_matrix[each[i]][each[i+1]]
    cnt += flag
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):

import sys
sys.setrecursionlimit(10**9)

N = int(input())

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)

    # divisors.sort()
    return divisors

ds = set(make_divisors(N)) | set(make_divisors(N-1))

def check(n,k):
    if n<k:
        return n==1
    elif n%k==0:
        return check(n//k,k)
    else:
        return check(n-k,k)

ds.remove(1)
cnt = 0
for d in ds:
    # print(d)
    if check(N,d):
        cnt+=1
print(cnt)


Fixed submission:

import sys
sys.setrecursionlimit(10**9)

N = int(input())

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)

    # divisors.sort()
    return divisors

ds = set(make_divisors(N)) | set(make_divisors(N-1))

def check(n,k):
    if n<k:
        return n==1
    elif n%k==0:
        return check(n//k,k)
    else:
        return check(n%k,k)

ds.remove(1)
cnt = 0
for d in ds:
    # print(d)
    if check(N,d):
        cnt+=1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()

# N = 5*10**3
# S = "".join(["t" for n in range(N)])

dp = [{} for i in range(N+1)]

mx = 0

for i in range(N):
#   print(dp)
  for j in range(N):
    if i<j and S[i] == S[j]:
      dp[i+1][j+1] = 1

  for k in dp[i]:
    c_before = dp[i][k]
    if k<N and i+c_before<k and S[k]==S[i]:
      dp[i+1][k+1] = c_before+1
      mx = max(mx,c_before+1)

# print(dp)
print(mx)



Fixed submission:
N=int(input())
S=input()

# N = 5*10**3
# S = "".join(["t" for n in range(N)])

dp = [[0 for j in range(N+1)] for i in range(N+1)]

mx = 0

for i in range(N):
#   print(dp)
  for k in range(N):
    if i<k and S[i] == S[k]:
      dp[i+1][k+1] = 1
    c_before = dp[i][k]
    if k<N and i+c_before<k and S[k]==S[i]:
      dp[i+1][k+1] = c_before+1
      mx = max(mx,c_before+1)

# print(dp)
print(mx)
Buggy python submission (verdict: Time Limit Exceeded):

N=int(input())
A = []
for n in range(N):
    A.append(int(input()))

forward = [0 for n in range(N)]
forward[0] = A[0]
backward = [0 for n in range(N)]
backward[N-1] = A[N-1]
for n in range(1,N):
    forward[n] = max(forward[n-1], A[n])
for n in range(N-1)[::-1]:
    backward[n] = max(backward[n+1], A[n])

# print(forward)
# print(backward)

for n in range(N):
    # print("====")
    # print(forward[:n])
    # print(backward[n+1:])
    print(max(forward[:n]+backward[n+1:]))


Fixed submission:

N=int(input())
A = []
for n in range(N):
    A.append(int(input()))

forward = [0 for n in range(N)]
forward[0] = A[0]
backward = [0 for n in range(N)]
backward[N-1] = A[N-1]
for n in range(1,N):
    forward[n] = max(forward[n-1], A[n])
for n in range(N-1)[::-1]:
    backward[n] = max(backward[n+1], A[n])

# print(forward)
# print(backward)

print(backward[1])
for n in range(1,N-1):
    # print("====")
    # print(forward[n-1],backward[n+1])
    print(max(forward[n-1],backward[n+1]))
print(forward[N-2])
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)

N=int(input())
A = []
for n in range(N):
    A.append(int(input()))


# N = 2*10**3
# A = [0 for n in range(N)]

# print(A)

visited = [False for n in range(N)]

dp = {}
def search(n,d):
    if n in dp:
        return dp[n]
    maxd = d
    for i in range(n)[::-1]:
        if i in dp:
            maxd = max(dp[i], maxd)
        elif A[i] >= A[n]:
            maxd = max(search(i,d+1), maxd)
    dp[n] = maxd
    return dp[n]

ds = [0 for n in range(N)]
for n in range(N)[::-1]:
    if not n in dp:
        ds[n] = search(n,0)

# print(ds)

print(max(ds)+1)

Fixed submission:
import bisect
N=int(input())
a = []
for n in range(N):
    a.append(int(input()))

r = [-1]*N

mind = float("inf")
for n in range(N):
    ind = bisect.bisect_left(r, a[n])
    r[ind-1] = a[n]
    mind = min(mind, ind)

# print(r)
print(N-mind+1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100000)

N=int(input())
A = []
for n in range(N):
    A.append(int(input()))


# N = 2*10**3
# A = [0 for n in range(N)]

# print(A)

visited = [False for n in range(N)]

dp = {}
def search(n,d):
    if n in dp:
        return dp[n]
    maxd = d
    for i in range(n)[::-1]:
        if i in dp:
            maxd = max(dp[i], maxd)
        elif A[i] >= A[n]:
            maxd = max(search(i,d+1), maxd)
    dp[n] = maxd
    return dp[n]

ds = [0 for n in range(N)]
for n in range(N)[::-1]:
    if not n in dp:
        ds[n] = search(n,0)

# print(ds)

print(max(ds)+1)

Fixed submission:
import bisect
N=int(input())
a = []
for n in range(N):
    a.append(int(input()))

r = [-1]*N

mind = float("inf")
for n in range(N):
    ind = bisect.bisect_left(r, a[n])
    r[ind-1] = a[n]
    mind = min(mind, ind)

# print(r)
print(N-mind+1)
Buggy python submission (verdict: Runtime Error):
N,L = map(int,input().split())
a = [L+i for i in range(N)]
# print(a)

mn = 10*9
i = -1
for i in range(N):
  if mn > abs(a[i]):
    mn = abs(a[i])
    agmn = i
sm = 0
for i in range(N):
  if i!=agmn:
    sm += a[i]

# print(mn, agmn)
print(sm)

Fixed submission:
N,L = map(int,input().split())
a = [L+i for i in range(N)]
# print(a)

mn = 10**9
for i in range(N):
  if mn > abs(a[i]):
    mn = abs(a[i])
    agmn = i

sm = 0
for i in range(N):
  if i!=agmn:
    sm += a[i]

# print(mn, agmn)
print(sm)
Buggy python submission (verdict: Runtime Error):
import sys
N=int(input())
# N=50

p = []
for n in range(N):
    x,y = map(int,input().split())
    # x,y = n,n
    p.append( (x,y) )

#空のリストを用意
e = set()  #部分最小木
av = set()  #部分最小木に含まれる頂点
pv = set(p)  #その他の頂点

used = {}
for pp in p:
    used[pp] = 1
used[p[0]] += 1

#始点は任意
av.add(p[0])
pv.remove(p[0])

costs = 0
while 1:
    #比較のための初期値として十分大きい数を用意
    shortestlen = sys.float_info.max
    #部分最小木に追加する辺を為す2点の初期化
    kav = None  #部分最小木に含まれる頂点からの候補
    kpv = None  #その他の頂点からの候補
    for v1 in av:
        for v2 in pv:
            #重みの計算（ここでは距離）
            dist = 1 if (v1[0]==v2[0] or v1[1] == v2[1]) else 0
            # dist = math.sqrt(  (v1[0]-v2[0])**2 + ( v1[1]-v2[1] )**2 )
            if shortestlen > dist and used[v1] > 0:
                shortestlen = dist
                #候補の更新
                kav = v1
                kpv = v2
    if shortestlen >= 0:
        #部分最小木に追加
        costs += shortestlen
        e.add((kav , kpv))
        used[kav] -= 1
    #確定した頂点を移す
    av.add(kpv)
    pv.remove(kpv)
    #全頂点に対する判定を終えたら終了
    if len(pv) == 0:
        break

print(costs+1)
# print(e)

Fixed submission:
import sys
N=int(input())
# N=50

p = []
for n in range(N):
    x,y = map(int,input().split())
    # x,y = n,n
    p.append( (x,y) )

if N == 1:
    print(1)
    exit()

p = list(sorted(p))

diffs = {}
for i,pi in enumerate(p):
    for j,pj in enumerate(p):
        if i < j:
            diff = (pi[0]-pj[0], pi[1]-pj[1])
            if diff not in diffs:
                diffs[diff] = 0
            diffs[diff] += 1

mxdiff = 0
for k in diffs:
    mxdiff = max(mxdiff, diffs[k])
print(N-mxdiff)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
G = np.zeros((N,N),dtype = np.bool)

pairs = []

for i in range(N-1):
    a,b = map(int,input().split())
    pairs.append((a,b))
    G[a-1][b-1] = True
    G[b-1][a-1] = True

Cs = list(sorted(map(int,input().split())))


links = [0 for i in range(N)]

for i in range(N):
    links[i] = G[i,:].sum()

nodeval = np.array([0 for i in range(N)])

# print(links)

disabled = [False for i in range(N)]
while len(Cs) > 0:
    mx = 0
    for i,l in enumerate(links):
        if not disabled[i]:
            mx = max(l,mx)
    # print("mx",mx, "da", disabled)
    for i,l in enumerate(links):
        if not disabled[i] and l == mx:
            break
    disabled[i] = True
    # max connected node
    # print(i)
    nodeval[i] = Cs.pop(-1)

# print(nodeval)

sumval = 0
for p in pairs:
    sumval += min(nodeval[p[0]-1], nodeval[p[1]-1] )

print(sumval)
for i,l in enumerate(nodeval):
    print(l,end=" " if i!=N-1 else "\n")


Fixed submission:
import numpy as np 
N = int(input())
# N = 1000
# G = np.zeros((N,N),dtype = np.bool)

linked = [[] for i in range(N)]
pairs = []

for i in range(N-1):
    a,b = map(int,input().split())
    # a,b = 1,2
    pairs.append((a,b))
    linked[a-1].append(b-1)
    linked[b-1].append(a-1)

Cs = list(sorted(map(int,input().split()),reverse=True))
# Cs = [1 for i in range(N)]

# print(Cs)

links = np.array([0 for i in range(N)])

for i in range(N):
    links[i] = len(linked[i])

# minag = np.argmin(links)
nodeval = np.array([0 for i in range(N)])

stack = [1]

visited = [False for i in range(N)]

while(len(stack)>0):
    minag = stack.pop()
    nodeval[minag] = Cs.pop(0)
    for l in linked[minag]:
        if not visited[l]:
            stack.append(l)
    visited[minag] = True
    # print(nodeval)

sumval=0
for p in pairs:
    sumval += min(nodeval[p[0]-1], nodeval[p[1]-1] )

print(sumval)
for i,l in enumerate(nodeval):
    print(l,end=" " if i!=N-1 else "\n")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

d = [[float("inf") for i in range(n)] for i in range(n)] 

for i in range(n-1):
    u,v,w = map(int,input().split())
    d[u-1][v-1] = w
    d[v-1][u-1] = w
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    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])
    return d

d = warshall_floyd(d)

for i in range(n):
    print(d[0][i]%2)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
n = int(input())
# n = 10000
d = [set() for i in range(n)]
cost = {}
for i in range(n-1):
    u,v,w = map(int,input().split())
    # u,v,w = i,i+1,i
    d[u-1].add(v-1)
    d[v-1].add(u-1)
    cost[(u-1,v-1)] = w%2
    cost[(v-1,u-1)] = w%2

visited = [False for i in range(n)]
colors = [0 for i in range(n)]

stack = []
def dfs(v,c):
    visited[v] = True
    colors[v] = c%2
    for i in d[v]:
        if not visited[i]:
            dfs(i,c+cost[(v,i)])

dfs(0,0)

for i in range(n):
    print(colors[i])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np 

N,K = map(int,input().split())
s=input()

ll = []
for i in range(len(s)):
    pre = "1"
    cnt0 = 0
    for j in range(i,len(s)):
        if s[j] != pre and s[j]=="0":
            cnt0 +=1
        pre = s[j]
        if cnt0 > K:
            break
        ll.append(j-i+1)
print(max(ll))

Fixed submission:
import numpy as np 

N,K = map(int,input().split())
s=input()

li = []
ls = []
pre = "X"
for i in range(len(s)):
    if pre!=s[i]:
        li.append(i)
        ls.append(s[i])
    pre=s[i]
# print(li)
# print(ls)

for _ in range(K*2+1):
    li.append(N)

maxv = 0
for i in range(len(ls)):
    if ls[i] == "0":
        maxv = max(maxv, li[i+K*2]-li[i])
    else:
        maxv = max(maxv, li[i+K*2+1]-li[i])

print(maxv)