Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = [int(i) for i in input().split()]

modDict = {}
B = 0
for i in range(N):
    B += A[i]
    if B%M in modDict:
        modDict[B%M] = modDict[B%M] + [i]
    else:
        modDict[B%M] = [i]

count = 0
for i in modDict:
    count += (len(modDict[i]) * (len(modDict[i]) -1))//2
    if i == 0:
        count += len(modDict[i])
print(count)

Fixed submission:
N, M = map(int, input().split())
A = [int(i) for i in input().split()]

modDict = {}
B = 0
for i in range(N):
    B += A[i]
    if B%M in modDict:
        modDict[B%M] = modDict[B%M] + 1
    else:
        modDict[B%M] = 1

count = (modDict[0] if 0 in modDict else 0)
for i in modDict:
    count += (modDict[i] * (modDict[i] -1))//2
print(count)
Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    if a % b == 0:
        return b
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return int(a * b / gcd(a, b))

N = int(input())
a = [int(i) for i in input().split()]

LCM = lcm(a[0], a[1])
for i in range(1, N-1):
    LCM = lcm(LCM, a[i+1])
LCM -= 1

modTotal = 0
for i in range(N):
    modTotal += LCM % a[i]
print(modTotal)

Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]

modTotal = 0
for i in range(N):
    modTotal += a[i]-1
print(modTotal)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

sleft = S[:N]
sright = S[2*N:N-1:-1]
ldict,rdict = {},{}
count = 0
for i in range(2**N):
    red = bin(i)[2:].zfill(N)
    leftred, rightred, leftblue, rightblue = "","","",""
    for j in range(len(red)):
        if red[j] == "1":
            leftred += sleft[j]
            rightred += sright[j]
        else:
            leftblue += sleft[j]
            rightblue += sright[j]
    ldict[red] = leftred + "-" + leftblue
    rdict[red] = rightred + "-" + rightblue

for i in range(N+1):
    lchoose = set(v for k, v in ldict.items() if k.count("1") == i)
    rchoose = set(v for k, v in rdict.items() if k.count("1") == i)
    sameset = list(lchoose & rchoose)
    for j in range(len(sameset)):
        lnum = len(list(k for k, v in ldict.items() if v == sameset[j]))
        rnum = len(list(k for k, v in rdict.items() if v == sameset[j]))
        count += lnum * rnum
print(count)

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

sleft = S[:N]
sright = S[2*N:N-1:-1]
ldict,rchoise = {},[]
count = 0
for i in range(2**N):
    red = bin(i)[2:].zfill(N)
    leftred, rightred, leftblue, rightblue = "","","",""
    for j in range(N):
        if red[j] == "1":
            leftred += sleft[j]
            rightred += sright[j]
        else:
            leftblue += sleft[j]
            rightblue += sright[j]
    if leftred + "-" + leftblue in ldict.keys():
        ldict[leftred + "-" + leftblue] += 1
    else:
        ldict[leftred + "-" + leftblue] = 1
    rchoise.append(rightred + "-" + rightblue)
    
for i in rchoise:
    count += ldict.get(i, 0)
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
cmin = []

for i in range(n):
	west = s[:i-1]
	east = s[i+1:]
	change = west.count("W") + east.count("E")
	cmin.append(change)

print(min(cmin))

Fixed submission:
import numpy as np
N = int(input())
S = list(input())

Wleft = np.zeros(N, dtype = int)
Eright = np.zeros(N, dtype = int)
Eright[0] = (S.count("E") if S[0] == "W" else S.count("E") - 1)
for i in range(N-1):
    if S[i] == "W":
        Wleft[i+1] = Wleft[i]+1
    else:
        Wleft[i+1] = Wleft[i]
    if S[i+1] == "E":
        Eright[i+1] = Eright[i] - 1
    else:
        Eright[i+1] = Eright[i]
total = Wleft + Eright
print(np.min(total))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [format(int(a), "b").zfill(20) for a in input().split()]

Sum = [0] * 20
start = 0
end = 1
Ans = N
for i in range(20):
    Sum[i] += int(A[0][i])
while end < N:
    for i in range(20):
        Sum[i] += int(A[end][i])
    if 2 in Sum:
        while 2 in Sum:
            Ans += end - start - 1
            for j in range(20):
                Sum[j] -= int(A[start][j])
            start += 1
    end += 1
while start < N and 2 in Sum:
    for j in range(20):
        Sum[j] -= int(A[start][j])
    start += 1
Ans += (N - start - 1) * (N - start) // 2
print(Ans)

Fixed submission:
N = int(input())
A = [format(int(a), "b").zfill(20) for a in input().split()]

Sum = [0] * 20
start = 0
end = 1
Ans = N
for i in range(20):
    Sum[i] += int(A[0][i])
while end < N:
    for i in range(20):
        Sum[i] += int(A[end][i])
    if 2 in Sum:
        while 2 in Sum:
            Ans += end - start - 1
            for j in range(20):
                Sum[j] -= int(A[start][j])
            start += 1
    end += 1
while start < N and 2 in Sum:
    for j in range(20):
        Sum[j] -= int(A[start][j])
    start += 1
Ans += (N - start - 1) * (N - start) // 2
print(Ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def solve():
    input = sys.stdin.readline
    s = input().strip("\n")
    K = int(input())
    substr = set()
    N = len(s)
    for i in range(N):
        for j in range(i+1, N + 1):
            substr |= {s[i:j]}
    sl = list(substr)
    sl.sort()
    print(sl[K-1])

    return 0

if __name__ == "__main__":
    solve()

Fixed submission:
import sys

def solve():
    input = sys.stdin.readline
    s = input().strip("\n")
    K = int(input())
    substr = set()
    N = len(s)
    for i in range(N):
        for j in range(1, min(6, N - i + 1)):
            substr |= {s[i:i+j]}
    sl = list(substr)
    sl.sort()
    print(sl[K-1])

    return 0

if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Runtime Error):
N = [int(a) for a in input().split()]
N.sort()
K = int(input())
print(A[0] + A[1] + A[2] * 2 ** K)

Fixed submission:
A = [int(a) for a in input().split()]
A.sort()
K = int(input())
print(A[0] + A[1] + A[2] * 2 ** K)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [input() for _ in range(N)]

Total = 0
for i in range(N):
    Synmmetry = True
    for a in range(N):
        for b in range(a, N):
            if S[a][(b + i) % N] != S[b][(a + i) % N]:
                Synmmetry = False
                break
        if not Synmmetry: break
    else: Total += 1
print(Total * N)

Fixed submission:
N = int(input())
S = [input() for _ in range(N)]

Total = 0
for i in range(N):
    Synmmetry = True
    for a in range(N):
        for b in range(a, N):
            if S[a][(b + i) % N] != S[b][(a + i) % N]:
                Synmmetry = False
                break
        if not Synmmetry: break
    else: Total += 1
print(Total * N)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [input() for _ in range(N)]

Total = 0
for i in range(N):
    Synmmetry = True
    for a in range(N):
        for b in range(N):
            if S[a][(b + i) % N] != S[b][(a + i) % N]:
                Synmmetry = False
                break
        if not Synmmetry: break
    else: Total += 1
print(Total * N)

Fixed submission:
N = int(input())
S = [input() for _ in range(N)]

Total = 0
for i in range(N):
    Synmmetry = True
    for a in range(N):
        for b in range(a, N):
            if S[a][(b + i) % N] != S[b][(a + i) % N]:
                Synmmetry = False
                break
        if not Synmmetry: break
    else: Total += 1
print(Total * N)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
sum_min = 0
use_min = 10000000
for i in range(X):
  m = int(input())
  sum_min += m
  use_min = min(use_min, m)
  
print(X + (N - sum_min) // use_min)

Fixed submission:
N, X = map(int, input().split())
sum_min = 0
use_min = 10000000
for i in range(N):
  m = int(input())
  sum_min += m
  use_min = min(use_min, m)
  
print(N + (X - sum_min) // use_min)
Buggy python submission (verdict: Time Limit Exceeded):
H, W, D = map(int, input().split())
C = {}
for i in range(H):
    A = [int(i) for i in input().split()]
    for j in range(W):
        C[A[j]] = (i, j)

memo = {}
Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    if (l, r) in memo:
        print(memo[(l, r)])
    else:
        MP, now = 0, l
        while now < r:
            nowx, nowy = C[now]
            nextx, nexty = C[now + D]
            MP += abs(nowx-nextx) + abs(nowy-nexty)
            now += D
        print(MP)
        memo[(l, r)] = MP

Fixed submission:
H, W, D = map(int, input().split())
C = {}
for i in range(H):
    A = [int(i) for i in input().split()]
    for j in range(W):
        C[A[j]] = (i, j)

MaxD = D * ((H*W)//D)
Cost = [[0] for i in range(D)]
for i in range(D):
    now = (D if i == 0 else i)
    nowx, nowy = C[now]
    while now + D <= H * W:
        nextx, nexty = C[now+D]
        MP = abs(nowx - nextx) + abs(nowy - nexty)
        Cost[i].append(Cost[i][-1] + MP)
        now += D
        nowx, nowy = nextx, nexty

Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    mod = l % D
    if mod == 0:
        print(Cost[mod][r//D - 1] - Cost[mod][l//D - 1])
    else:
        print(Cost[mod][r//D] - Cost[mod][l//D])
Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil
N = int(input())
A = [int(a) for a in input().split()]

DP = [[False for i in range(max(A) * N + 1)] for n in range(N)]
DP[0][0], DP[0][A[0]] = True, True
maxN = A[0]
for i in range(1, N):
    a = A[i]
    for j in range(maxN+1):
        if DP[i-1][j]:
            DP[i][j] = True
            DP[i][j + a] = True
    maxN += a

for i in range(ceil(sum(A)/2), max(A) * N + 1):
    if DP[N-1][i]:
        print(i)
        break


Fixed submission:
from math import ceil
N = int(input())
A = [int(a) for a in input().split()]

DP = 1
for a in A:
    DP |= DP << a

Shalf = ceil(sum(A)/2)
DP >>= Shalf
for i in range(N * max(A)):
    if DP & 1:
        print(Shalf + i)
        break
    DP >>= 1
Buggy python submission (verdict: Time Limit Exceeded):
import math
Primes = {2}
Sim = [0 for i in range(100002)]

for i in range(3, 100001):
    if i % 2 == 0:
        Sim[i] = Sim[i-1]
    else:
        for p in Primes:
            if i % p == 0:
                Sim[i] = Sim[i-1]
                break
        else:
            Primes |= {i}
            if (i+1)//2 in Primes:
                Sim[i] = Sim[i-1] + 1
            else:
                Sim[i] = Sim[i-1]

Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(Sim[r] - Sim[l-1])

Fixed submission:
Num = [int(i) for i in range(2, 100001)]
Primes = [True for i in range(100001)]
Sim = [0 for i in range(100001)]

for i in range(2, 100001):
    if Primes[i] == True:
        j = i * 2
        while j < 100001:
            Primes[j] = False
            j += i

for i in range(3, 100001):
    if Primes[i] and Primes[(i+1)//2]:
        Sim[i] = Sim[i-1] + 1
    else:
        Sim[i] = Sim[i-1]

Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(Sim[r] - Sim[l-1])
Buggy python submission (verdict: Runtime Error):
a, b = map(int, open(0)); print((a + b + 1) // 2)


Fixed submission:
a,b =map(int,input().split());print((a+b+1)//2)

Buggy python submission (verdict: Runtime Error):
a, b = map(int, open(0)); print((a + b) // 2 + (a + b) % 2)

Fixed submission:
a,b =map(int,input().split());print((a+b+1)//2)
Buggy python submission (verdict: Runtime Error):
s = input()
x, y = map(int, input().split())

MoveX, MoveY = [], []
dir = "X"
count = 0
for i in range(len(s)): 
    if s[i] == "T":
        if count:
            if dir == "X": MoveX.append(count)
            else: MoveY.append(count)
        count = 0
        dir = ("Y" if dir == "X" else "X")      
    else:
        count += 1
if s[-1] == "F":
    if dir == "X": MoveX.append(count)
    else: MoveY.append(count)

def DP(i, z, Move = list, memo = {}):
    if i == -1: 
        if z == 0: return True
        else: return False
    try:
        return memo[(i, z)]
    except KeyError:
        if DP(i-1, z-Move[i], Move, memo) or DP(i-1, z+Move[i], Move, memo): 
            memo[(i, z)] = True
            return True
        else: 
            memo[(i, z)] = False
            return False

memox, memoy = {}, {}
if DP(len(MoveX)-1, x, MoveX, memox) and DP(len(MoveY)-1, y, MoveY, memoy): print("Yes")
else: print("No")

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

MoveX, MoveY = [], []
dir = "X"
count = 0
for i in range(len(s)): 
    if s[i] == "T":
        if count:
            if dir == "X": MoveX.append(count)
            else: MoveY.append(count)
        count = 0
        dir = ("Y" if dir == "X" else "X")      
    else:
        count += 1
if s[-1] == "F":
    if dir == "X": MoveX.append(count)
    else: MoveY.append(count)

iniX = 0
if s[0] == "F":
    iniX = MoveX.pop(0)

def DP(i, z, ini, Move = list):
    canMove = set([ini])
    for j in range(i):
        temp = []
        for item in canMove:
            temp.append(item+Move[j])
            temp.append(item-Move[j])
        canMove = set(temp)
    return z in canMove

if DP(len(MoveX), x, iniX, MoveX) and DP(len(MoveY), y, 0, MoveY): print("Yes")
else: print("No")
Buggy python submission (verdict: Runtime Error):
R, G = map(int, input().split())
print(2 * G - R)

Fixed submission:
R = int(input())
G = int(input())
print(2 * G - R)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
T = [int(i) for i in input().split()]
L = [0]
for i in range(N):
    L.append(L[i] + T[i])
V = [int(i) for i in input().split()]

def VM(x, i): #x秒後に条件iがとり得る速度
    if 0 <= x <= L[i]:
        return V[i] + (L[i] - x)
    elif L[i] < x <= L[i+1]:
        return V[i]
    else:
        return V[i] + (x - L[i+1])

minV = [float("inf") for i in range(2*L[-1] + 1)]
for i in range(2*L[-1]+1):
    for j in range(N):
        minV[i] =min(minV[i], VM(i*0.5, j))
    minV[i] = min(minV[i], i*0.5, L[-1] - i*0.5)

Ans = 0
for i in range(2*L[-1]):
    Ans += (minV[i] + minV[i+1])/4
print(Ans)

Fixed submission:
N = int(input())
T = [int(i) for i in input().split()]
L = [0]
for i in range(N):
    L.append(L[i] + T[i])
V = [int(i) for i in input().split()]

def VM(x, i): #x秒後に条件iがとり得る速度
    if 0 <= x <= L[i]:
        return V[i] + (L[i] - x)
    elif L[i] < x <= L[i+1]:
        return V[i]
    else:
        return V[i] + (x - L[i+1])

Search = [[] for i in range(N)] #設定された最高速度よりも小さくなり得る条件を探索
for i in range(N):
    for j in range(N):
        if i < j and V[i] - V[j] > L[j] - L[i+1]:
            Search[i].append(j)
        elif i > j and V[i] - V[j] > L[i] - L[j+1]:
            Search[i].append(j)

maxV = [float("inf") for i in range(2*L[-1]+1)]
for i in range(N):
    for j in range(2 * L[i], 2 * L[i+1] + 1):
        maxV[j] = min(V[i], j * 0.5, L[-1] - j * 0.5) #初期化
        for s in Search[i]:
            maxV[j] = min(maxV[j], VM(j * 0.5, s))
Ans = 0
for i in range(2*L[-1]):
    Ans += (maxV[i] + maxV[i+1])/4
print(Ans)
Buggy python submission (verdict: Runtime Error):
S = list(input())
X, A = [], []
NX = ""

for i in range(len(S)):
    if S[i] == "x": X.append(i)
    else: 
        NX += S[i]
        A.append(i)
    
for i in range(len(NX)//2):
    if NX[i] != NX[-1-i]:
        print(-1)
        break
else:
    if NX == "": print(0)
    else:
        l, r = 0, len(S)-1
        midl = A[len(NX)//2]
        midr = (A[len(NX)//2] if len(NX)%2==1 else A[len(NX)//2 + 1])
        Add = 0
        while l < midl or r > midr:
            if S[l] == S[r] == "x":
                l += 1
                r -= 1
            elif S[l] == "x":
                l += 1
                Add += 1
            elif S[r] == "x":
                r -= 1
                Add += 1
            else:
                l += 1
                r -= 1
        print(Add)

Fixed submission:
S = list(input())
X, A = [], []
NX = ""

for i in range(len(S)):
    if S[i] == "x": X.append(i)
    else: 
        NX += S[i]
        A.append(i)
    
for i in range(len(NX)//2):
    if NX[i] != NX[-1-i]:
        print(-1)
        break
else:
    if NX == "": print(0)
    else:
        l, r = 0, len(S)-1
        midl = A[(len(NX)-1)//2]
        midr = (A[(len(NX)-1)//2] if len(NX)%2==1 else A[(len(NX)-1)//2 + 1])
        Add = 0
        while l < midl or r > midr:
            if S[l] == S[r] == "x":
                l += 1
                r -= 1
            elif S[l] == "x":
                l += 1
                Add += 1
            elif S[r] == "x":
                r -= 1
                Add += 1
            else:
                l += 1
                r -= 1
        print(Add)

Buggy python submission (verdict: Runtime Error):
S = list(input())
X = []
NX = ""

for i in range(len(S)):
    if S[i] == "x": X.append(i)
    else: NX += S[i]
    
NXr = ""
for i in reversed(range(len(NX))): NXr += NX[i]

if NXr != NX: print(-1)
else:
    mid = S.index(NX[(len(NX) - 1)//2])
    Xleft, Xright = set(), set()
    for x in X:
        if x < mid: Xleft |= {mid-x}
        else: Xright |= {x-mid}
    print(len(Xleft ^ Xright))

Fixed submission:
S = list(input())
X, A = [], []
NX = ""

for i in range(len(S)):
    if S[i] == "x": X.append(i)
    else: 
        NX += S[i]
        A.append(i)
    
for i in range(len(NX)//2):
    if NX[i] != NX[-1-i]:
        print(-1)
        break
else:
    if NX == "": print(0)
    else:
        l, r = 0, len(S)-1
        midl = A[(len(NX)-1)//2]
        midr = (A[(len(NX)-1)//2] if len(NX)%2==1 else A[(len(NX)-1)//2 + 1])
        Add = 0
        while l < midl or r > midr:
            if S[l] == S[r] == "x":
                l += 1
                r -= 1
            elif S[l] == "x":
                l += 1
                Add += 1
            elif S[r] == "x":
                r -= 1
                Add += 1
            else:
                l += 1
                r -= 1
        print(Add)
Buggy python submission (verdict: Runtime Error):
import sys
F = sys.stdin
N, M = map(int, F.readline().strip("\n").split())
Edge = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, F.readline().strip("\n").split())
    Edge[A-1].append(B-1)
    Edge[B-1].append(A-1)

Color = [0] * N


def dfs(v, c):
    Color[v] = c
    for next in Edge[v]:
        if Color[next] == c: return False
        if Color[next] == 0:
            if not dfs(next, -c): return False
    return True

Bipartite = dfs(0, 1)
if Bipartite:
    black = Color.count(1)
    print(black * (N-black) - M)
else:
    print(N * (N - 1)//2 - M)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
F = sys.stdin
N, M = map(int, F.readline().strip("\n").split())
Edge = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, F.readline().strip("\n").split())
    Edge[A-1].append(B-1)
    Edge[B-1].append(A-1)

Color = [0] * N


def dfs(v, c):
    Color[v] = c
    for next in Edge[v]:
        if Color[next] == c: return False
        if Color[next] == 0:
            if not dfs(next, -c): return False
    return True

Bipartite = dfs(0, 1)
if Bipartite:
    black = Color.count(1)
    print(black * (N-black) - M)
else:
    print(N * (N - 1)//2 - M)
Buggy python submission (verdict: Runtime Error):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    P = [int(p) for p in input().split()]
    swap = 0
    i = 0
    while i < N:
        if P[i] == i + 1:
            P[i], P[i+1] = P[i+1], P[i]
            swap += 1
        i += 1
    print(swap)
    return 0

if __name__ == "__main__":
    solve()

Fixed submission:
N = int(input())
P = [int(i) for i in input().split()]
i = 0
ans = 0
while i < N:
    if P[i] == i+1:
        ans += 1
        i += 2
    else:
        i += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

def solve():
    N = int(input())
    A = [int(a) for a in input().split()]
    lengthD = dict()
    for a in A:
        if a in lengthD: lengthD[a] += 1
        else: lengthD[a] = 1
    moreThanTwo = []
    count = 0
    for key in lengthD:
        if lengthD[key] > 1: 
            moreThanTwo.append(key)
            count += 1
    ans = 0
    moreThanTwo.sort()
    if lengthD[moreThanTwo[-1]] > 3: ans = moreThanTwo[-1] ** 2
    if count < 2: print(ans)
    else:
        ans = max(ans, moreThanTwo[-1] * moreThanTwo[-2])
        print(ans)

    return 0

if __name__ == "__main__":
    solve()

Fixed submission:
import sys

def solve():
    N = int(input())
    A = [int(a) for a in input().split()]
    lengthD = dict()
    for a in A:
        if a in lengthD: lengthD[a] += 1
        else: lengthD[a] = 1
    moreThanTwo = []
    count = 0
    for key in lengthD:
        if lengthD[key] > 1: 
            moreThanTwo.append(key)
            count += 1
    
    if count == 0: print(0)
    else:
        ans = 0
        moreThanTwo.sort()
        if lengthD[moreThanTwo[-1]] > 3: ans = moreThanTwo[-1] ** 2
        if count < 2: print(ans)
        else:
            ans = max(ans, moreThanTwo[-1] * moreThanTwo[-2])
            print(ans)

    return 0

if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Runtime Error):
def solve():
    N, K = map(int, input().split())
    L = [int(i) for i in input().split()]
    L.sort(reversed = True)
    print(sum(L[:K]))


if __name__ == "__main__":
    solve()

Fixed submission:
N, K = map(int, input().split())
L = [int(l) for l in input().split()]
L.sort(reverse = True)
print(sum(L[:K]))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"\
        , "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

ans = 0
i = 1
while i * 2 < len(s):
  if s[:i] == s[i:2 * i]: ans = i
print(ans)


Fixed submission:
s = input()
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"\
        , "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

ans = 0
i = 1
while i * 2 < len(s):
  if s[:i] == s[i:2 * i]: ans = i * 2
  i += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = [int(i) for i in input().split()]
b = str(A[0])

for i in range(1, n):
    if i % 2 == n % 2:
        b += " " + str(A[i])
    else:
        b = str(A[i]) + " " + b

print(b)

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

if n % 2 != 0:
    r = A[1::2]
    l = A[::2]
else:
    r = A[::2]
    l = A[1::2]
l.reverse()
print(" ".join(map(str, l + r)))

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

for i in range(n):
    if i % 2 == n % 2:
        b.append(A[i])
    else:
        b.insert(0, A[i])


print(" ".join(map(str, b)))

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

if n % 2 != 0:
    r = A[1::2]
    l = A[::2]
else:
    r = A[::2]
    l = A[1::2]
l.reverse()
print(" ".join(map(str, l + r)))

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

for i in range(n):
    if i % 2 != 0:
        b = [A[i]] + b
    else:
        b += [A[i]]

if n % 2 != 0:
    b = b[n-1: : -1]

print(" ".join(map(str, b)))

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

if n % 2 != 0:
    r = A[1::2]
    l = A[::2]
else:
    r = A[::2]
    l = A[1::2]
l.reverse()
print(" ".join(map(str, l + r)))