Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,k = list(map(int, input().split()))
p = list(map(int, input().split()))

p = [(i+1)/2 for i in p]

ma = 0

for i in range(n-k+1):
    ma = max(ma, sum(p[i:k+i]))
    
print(ma)

Fixed submission:
n,k = list(map(int, input().split()))
p = list(map(int, input().split()))

from collections import deque

p = [(i+1)/2 for i in p]

d_front = deque(p[:k])
d_back = deque(p[k:])

sum_prev = sum(d_front)
ma = sum_prev

while d_back:
    ff = d_front.popleft()
    bf = d_back.popleft()
    sum_curr = sum_prev - ff + bf
    ma = max(ma, sum_curr)
    d_front.append(bf)
    sum_prev = sum_curr
    
print(ma)
Buggy python submission (verdict: Time Limit Exceeded):
"""
蟻本p37にスタート・ゴールの座標が決まっている場合のコードがある
この問題ではスタート・ゴールの座標が決まっていないので以下のように改変する
"""
h, w = list(map(int, input().split()))
field = [input() for _ in range(h)]

INF = 10**8
d = [[0]*w for i in range(h)] # 各点までの最短距離の配列
dx = [1,0,-1,0]; dy = [0,1,0,-1] # 移動4方向のベクトル

# (sx, sy)から(gx, gy)への最短距離を求める
# たどり着けないとINF
import queue

def bfs(sx, sy, gx, gy):
    que = queue.Queue()
    # 全ての点をINFで初期化
    for i in range(h):
        for j in range(w):
            d[i][j] = INF
    # スタート地点をキューに入れ、その点の距離を0にする
    que.put([sx, sy])
    d[sx][sy] = 0
    
    # キューが空になるまでループ
    while que.qsize():
        # キューの先頭を取り出す
        p = que.get()
        # 取り出してきた状態がゴールなら探索を辞める
        if p[0] == gx and p[1] == gy: break
        
        # 移動4方向をループ
        for i in range(4):
            # 移動した後の点を(nx, ny)とする
            nx = p[0] + dx[i]; ny = p[1] + dy[i]

            # 移動が可能かの判定と既に訪れたことがあるかの判定(d[nx][ny] != INF なら訪れたことあり)
            if 0 <= nx and nx < h and 0 <= ny and ny < w and field[nx][ny] != '#' and d[nx][ny] == INF:
                # 移動できるならキューに入れ、その点の距離をpからの距離+1で確定する
                que.put([nx, ny])
                d[nx][ny] = d[p[0]][p[1]] + 1
            
    return d[gx][gy]

# この問題ではスタート・ゴールの位置が決まっていないので取り得る位置の組み合わせを列挙する
from itertools import combinations

sg_candidates = []
for i in range(h):
    for j in range(w):
        if field[i][j] == '.':
            sg_candidates.append((i,j))
sg_pairs = combinations(sg_candidates, 2)

ans = 0
for s,g in sg_pairs:
    res = bfs(s[0],s[1],g[0],g[1])
    ans = max(res, ans)

print(ans)

Fixed submission:
h, w = list(map(int, input().split()))
s = [input() for _ in range(h)]

INF = 1001001001
di = [-1,0,1,0]
dj = [0,-1,0,1]
ans = 0

def update(i, j, x):
    if dist[i][j] != INF: return
    dist[i][j] = x
    que.put([i,j])

import queue

# スタートの座標全てのパターンについて距離を計算
for si in range(h):
    for sj in range(w):
        if s[si][sj] == '#': continue
        dist = [[INF]*w for i in range(h)]
        que = queue.Queue()
        update(si, sj, 0)
        while que.qsize():
            p = que.get()
            i = p[0]; j = p[1]
            for drc in range(4):
                ni = i+di[drc]; nj = j+dj[drc]
                if ni < 0 or ni >= h or nj < 0 or nj >= w: continue
                if s[ni][nj] == '#': continue
                update(ni, nj, dist[i][j]+1)
        # ゴールの座標全てのパターンについて距離を更新
        for i in range(h):
            for j in range(w):
                if dist[i][j] == INF: continue
                ans = max(ans, dist[i][j])

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

import itertools

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

C = list(itertools.permutations(a))

idxs = []

for i, c in enumerate(C):
    l = list(c)
    if l == p or l == q:
        idxs.append(i)

ans = idxs[1]-idxs[0]

print(ans)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

import itertools

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

C = list(itertools.permutations(a))

idxs = []

for i, c in enumerate(C):
    l = list(c)
    if l == p:
        idxs.append(i)
    if l == q:
        idxs.append(i)

ans = idxs[1]-idxs[0]

print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,k = list(map(int, input().split()))

if a =< k:
    k -= a
    a = 0
else:
    a -= k
    k = 0

if b =< k:
    b = 0
else:
    b -= k
    
print(a, b)

Fixed submission:
a,b,k = list(map(int, input().split()))

if a <= k:
    k -= a
    a = 0
else:
    a -= k
    k = 0

if b <= k:
    b = 0
else:
    b -= k
    
print(a, b)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

MOD = 10**9+7
ans = 0

for i in range(60):
    x = 0 # i桁目が1である数の個数
    for j in range(n):
        if a[j]>>i&1: # "a[j]のi桁目が1である"という意味
            x += 1
    now = x*(n-x)%MOD
    for j in range(i):
        now = now*2%MOD # 2**60をかけると容易にオーバーフローするので、安全に2をかけるごとにMODをとっている
    ans += now
    ans %= MOD
    
print(ans)

Fixed submission:
"""
ビット演算, XOR

XORは桁ごとに独立して計算できるので、桁ごとに計算する
XORが1になるのは0と1を足した時。2つの数を足す時、一方の数のi桁目が1でもう一方の数のi桁目が0であれば、2つの数を足した時のi桁目が1になる
全部で数がn個あるとき、i桁目が1の数がx個ある場合は、i桁目が0の数がn-x個あることになるので、x*(n-x)個の組み合わせでi桁目のXORが1になる
"""

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

MOD = 10**9+7
ans = 0

for i in range(60):
    x = 0 # i桁目が1である数の個数
    for j in range(n):
        if a[j]>>i&1: # "a[j]のi桁目が1である"という意味
            x += 1
    now = x*(n-x)%MOD
    for j in range(i):
        now = now*2%MOD # 2**60をかけると容易にオーバーフローするので、安全に2をかけるごとにMODをとっている
    ans += now
    ans %= MOD
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
"""
ビット演算, XOR

XORは桁ごとに独立して計算できるので、桁ごとに計算する
XORが1になるのは0と1を足した時。2つの数を足す時、一方の数のi桁目が1でもう一方の数のi桁目が0であれば、2つの数を足した時のi桁目が1になる
全部で数がn個あるとき、i桁目が1の数がx個ある場合は、i桁目が0の数がn-x個あることになるので、x*(n-x)個の組み合わせでi桁目のXORが1になる
"""

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

MOD = 10**9+7
ans = 0

for i in range(60):
    x = 0 # i桁目が1である数の個数
    for j in range(n):
        if a[j]>>i&1: # "a[j]のi桁目が1である"という意味
            x += 1
    now = x*(n-x)%MOD
    for j in range(i):
        now = now*2%MOD # 2**60をかけると容易にオーバーフローするので、安全に2をかけるごとにMODをとっている
    ans += now
    ans %= MOD
    
print(ans)

Fixed submission:
"""
ビット演算, XOR

XORは桁ごとに独立して計算できるので、桁ごとに計算する
XORが1になるのは0と1を足した時。2つの数を足す時、一方の数のi桁目が1でもう一方の数のi桁目が0であれば、2つの数を足した時のi桁目が1になる
全部で数がn個あるとき、i桁目が1の数がx個ある場合は、i桁目が0の数がn-x個あることになるので、x*(n-x)個の組み合わせでi桁目のXORが1になる
"""

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

MOD = 10**9+7
ans = 0

for i in range(60):
    x = 0 # i桁目が1である数の個数
    for j in range(n):
        if a[j]>>i&1: # "a[j]のi桁目が1である"という意味
            x += 1
    now = x*(n-x)%MOD
    for j in range(i):
        now = now*2%MOD # 2**60をかけると容易にオーバーフローするので、安全に2をかけるごとにMODをとっている
    ans += now
    ans %= MOD
    
print(ans)

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

from itertools import combinations

MOD = 10**9+7
ans = 0

for c in combinations(a, 2):
    tmp = c[0]^c[1]
    tmp %= MOD
    ans += c[0]^c[1]
    ans %= MOD

print(ans%MOD)

Fixed submission:
"""
ビット演算, XOR

XORは桁ごとに独立して計算できるので、桁ごとに計算する
XORが1になるのは0と1を足した時。2つの数を足す時、一方の数のi桁目が1でもう一方の数のi桁目が0であれば、2つの数を足した時のi桁目が1になる
全部で数がn個あるとき、i桁目が1の数がx個ある場合は、i桁目が0の数がn-x個あることになるので、x*(n-x)個の組み合わせでi桁目のXORが1になる
"""

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

MOD = 10**9+7
ans = 0

for i in range(60):
    x = 0 # i桁目が1である数の個数
    for j in range(n):
        if a[j]>>i&1: # "a[j]のi桁目が1である"という意味
            x += 1
    now = x*(n-x)%MOD
    for j in range(i):
        now = now*2%MOD # 2**60をかけると容易にオーバーフローするので、安全に2をかけるごとにMODをとっている
    ans += now
    ans %= MOD
    
print(ans)
Buggy python submission (verdict: Runtime Error):
"""bfs"""

import sys
sys.setrecursionlimit(10**6)

n = int(input())

to = [[] for _ in range(n)]
eid = [[] for _ in range(n)]
ans = [0]*(n-1)

for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1; b -= 1
    to[a].append(b); eid[a].append(i) # to:nodeの繋がり、eid:edgeの色
    to[b].append(a); eid[b].append(i)

import queue

q = queue.Queue()
used = [0]*n
q.put(0)
used[0] = 1
while not q.empty():
    v = q.get()
    p = pre[v]
    c = -1
    for i in range(len(to[v])):
        u = to[v]; ei = eid[v]
        if used[u]: c = ans[ei]
    k = 1
    for i in range(len(to[v])):
        u = to[v]; ei = eid[v]
        if used[u]: continue
        if k == c: k += 1
        ans[ei] = k
        k += 1
        q.put(u)
        used[u] = 1

mx = 0
for i in range(n):
    mx = max(mx, len(to[i]))
print(mx)
for i in range(n-1):
    print(ans[i])

Fixed submission:
"""dfs"""

n = int(input())
import sys
sys.setrecursionlimit(10**6)

to = [[] for _ in range(n)]
eid = [[] for _ in range(n)]
ans = [0]*n

def dfs(v, c=-1, p=-1):
    k = 1
    for i in range(len(to[v])):
        u = to[v][i]
        ei = eid[v][i]
        if u == p: continue
        if k == c: k += 1
        ans[ei] = k
        k += 1
        dfs(u,ans[ei],v)

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

dfs(0)
mx = 0
for i in range(n):
    mx = max(mx, len(to[i]))
print(mx)
for i in range(n-1):
    print(ans[i])

Buggy python submission (verdict: Runtime Error):
"""dfs"""

n = int(input())

to = [[] for _ in range(n)]
eid = [[] for _ in range(n)]
ans = [0]*n

def dfs(v, c=-1, p=-1):
    k = 1
    for i in range(len(to[v])):
        u = to[v][i]
        ei = eid[v][i]
        if u == p: continue
        if k == c: k += 1
        ans[ei] = k
        k += 1
        dfs(u,ans[ei],v)

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

dfs(0)
mx = 0
for i in range(n):
    mx = max(mx, len(to[i]))
print(mx)
for i in range(n-1):
    print(ans[i])

Fixed submission:
"""dfs"""

n = int(input())
import sys
sys.setrecursionlimit(10**6)

to = [[] for _ in range(n)]
eid = [[] for _ in range(n)]
ans = [0]*n

def dfs(v, c=-1, p=-1):
    k = 1
    for i in range(len(to[v])):
        u = to[v][i]
        ei = eid[v][i]
        if u == p: continue
        if k == c: k += 1
        ans[ei] = k
        k += 1
        dfs(u,ans[ei],v)

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

dfs(0)
mx = 0
for i in range(n):
    mx = max(mx, len(to[i]))
print(mx)
for i in range(n-1):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int, input().split())

#from math import gcd
from fractions import gcd

def get_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: # NNが平方数のときに√Nを2個出力しないようにする
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def get_primes(n):
    primes = set(range(2, n+1))
    for i in range(2, int(n**0.5+1)):
        primes.difference_update(range(i*2, n+1, i))
    primes = list(primes)
    
    return primes

g = gcd(a,b)
primes = get_primes(g)
ans = 1 # 1は素数ではないが答えには入る

for p in primes:
    if g % p == 0:
        ans += 1
        
print(ans)

Fixed submission:
a,b = map(int, input().split())

#from math import gcd
from fractions import gcd

g = gcd(a,b)

pf = {}

for i in range(2,int(g**0.5)+1):
    while g % i == 0:
        pf[i] = pf.get(i,0) + 1
        g //= i
if g > 1: pf[g] = 1

ans = 1 + len(pf.keys()) # 1は素数ではないが答えには入る

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

n,k = [int(i) for i in readline().split()]
s = input()
d = {'L':-1,'R':1}
l = [d[i] for i in s]

ans = 0

for _ in range(k):
  left = 0
  flag_left = 0
  right = n-1
  flag_right = 0
  while left < right and not (flag_left and flag_right):
    if l[left] != l[left+1] and not flag_left:
      left += 1
      flag_left = 1
    elif l[left] == l[left+1] and not flag_left:
      left += 1
    if l[right] != l[right-1] and not flag_right:
      right -= 1
      flag_right = 1
    elif l[right] == l[right-1] and not flag_right:
      right -= 1
  if flag_left == 0:
    left = 0
  if flag_right == 0:
    right = n-1
  if flag_left == flag_right == 1 and left > right:
    left = 0
  for i in range(left, right+1):
    l[i] *= -1

for i in range(n-1):
  if l[i] == l[i+1]:
    ans += 1

print(ans)

Fixed submission:
"""
1度の操作で最大+2できる
隣り合う箇所はN-1
LないしRが連続している箇所をグループとして見ると、求める数は
  N-1-隣り合うグループが異なっている場所の個数
= N-1-(グループの個数-1)
"""
import sys
sys.setrecursionlimit(10**6)
n, k = map(int, input().split())
s = input()

score = 0
for i in range(n-1):
    if s[i] == s[i+1]: score += 1

ans = min(score+2*k, n-1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n = int(input())

ans = sum([i for i in range(1,n)])

print(ans)

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

ans = int(n*(n-1)//2)

print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n = int(input())

l = list(range(1,n+1))

ans = 0
for i in range(n):
    ans += l[i] % l[i-n+1]

print(ans)

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

ans = int(n*(n-1)//2)

print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n = int(input())

l = list(range(1,n+1))
i = -1
ans = 0
while i > -n:
  tmp = 0
  for j in range(n):
    tmp += l[j+i] % l[j]
  ans = max(ans, tmp)
  i -= 1
print(ans)

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

ans = int(n*(n-1)//2)

print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n = int(input())

l = list(range(1,n+1))
i = -1
ans = 0
while i > -n:
  ltmp = l[-i:] + l[:-i]
  tmp = sum(i%j for i,j in zip(l,ltmp))
  ans = max(ans, tmp)
  i -= 1
print(ans)

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

ans = int(n*(n-1)//2)

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

MAXN = 1005
MAXV = MAXN*(MAXN-1)//2
to = [[] for _ in range(MAXV)] # 頂点間の辺の情報
id = [[[] for _ in range(MAXN)] for _ in range(MAXN)] # 試合のid=DAGの頂点番号
def toId(i,j): # 選手idから試合idを返す関数
    if i > j: # i,jが逆になっても試合idは同じ
        i,j = j,i
    return id[i][j]

visited = [False]*MAXV
calculated = [False]*MAXV
dp = [1]*MAXV # Vからスタートしたときの最長経路。頂点の個数ベースで経路の長さを数えるので、初期値は1

def dfs(v):
    if visited[v]:
        if not calculated[v]:
            return -1 # 計算が終わっていない頂点を2度訪れるのはループがあるということ
        return dp[v]
    visited[v] = True
    for u in to[v]: # 全ての辺をなめる
        res = dfs(u)
        if res == -1: return -1 # ループがあれば-1を返す
        dp[v] = max(dp[v], res+1)
    calculated[v] = True
    return dp[v]

def main():
    n = int(input())
    a = [[int(i) for i in readline().split()] for _ in range(n)]
    for i in range(n):
        for j in range(n-1):
            a[i][j] -= 1 # 選手idを0始まりに変換
    V = 0
    for i in range(n):
        for j in range(n):
            if i < j:
                id[i][j] = V
                V += 1 # 0から順に各試合にidを割り振る
    for i in range(n):
        for j in range(n-1):
            a[i][j] = toId(i,a[i][j]) # 選手idを試合id(頂点番号)に置き換える
        for j in range(n-2): # 頂点間の依存関係はn-2個
            to[a[i][j+1]].append(a[i][j])
    ans = 0
    for i in range(V):
        res = dfs(i)
        if res == -1:
            print('-1') # ループがあれば-1を返す（問題文の指示）
            return
        ans = max(ans, res)
    print(ans)
    return

if __name__ == '__main__':
    main()

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

MAXN = 1005
MAXV = MAXN*(MAXN-1)//2
to = [[] for _ in range(MAXV)] # 頂点間の辺の情報
id = [[[] for _ in range(MAXN)] for _ in range(MAXN)] # 試合のid=DAGの頂点番号
def toId(i,j): # 選手idから試合idを返す関数
    if i > j: # i,jが逆になっても試合idは同じ
        i,j = j,i
    return id[i][j]

visited = [False]*MAXV
calculated = [False]*MAXV
dp = [1]*MAXV # Vからスタートしたときの最長経路。頂点の個数ベースで経路の長さを数えるので、初期値は1

def dfs(v):
    if visited[v]:
        if not calculated[v]:
            return -1 # 計算が終わっていない頂点を2度訪れるのはループがあるということ
        return dp[v]
    visited[v] = True
    for u in to[v]: # 全ての辺をなめる
        res = dfs(u)
        if res == -1: return -1 # ループがあれば-1を返す
        dp[v] = max(dp[v], res+1)
    calculated[v] = True
    return dp[v]

def main():
    n = int(input())
    a = [[int(i) for i in readline().split()] for _ in range(n)]
    for i in range(n):
        for j in range(n-1):
            a[i][j] -= 1 # 選手idを0始まりに変換
    V = 0
    for i in range(n):
        for j in range(n):
            if i < j:
                id[i][j] = V
                V += 1 # 0から順に各試合にidを割り振る
    for i in range(n):
        for j in range(n-1):
            a[i][j] = toId(i,a[i][j]) # 選手idを試合id(頂点番号)に置き換える
        for j in range(n-2): # 頂点間の依存関係はn-2個
            to[a[i][j+1]].append(a[i][j])
    ans = 0
    for i in range(V):
        res = dfs(i)
        if res == -1:
            print('-1') # ループがあれば-1を返す（問題文の指示）
            return
        ans = max(ans, res)
    print(ans)
    return

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = []
for i in range(n):
    l.append(input())

ans = 0
i = 0
while i < len(l):
    ans += sum([sorted(l[i]) == sorted(l[n]) for n in range(i+1,n)])
    i += 1
print(ans)

Fixed submission:
n = int(input())
ans = 0
d = {}
for i in range(n):
    s = ''.join(sorted(input()))
    if s not in d.keys():
        d[s] = 1
    else:
        ans += d[s]
        d[s] += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = []
for i in range(n):
    d = {}
    for s in input():
        if s not in d.keys():
            d[s] = 1
        else:
            d[s] += 1
    l.append(d)

ans = 0
i = 0
while i < len(l):
    ans += sum([l[i] == l[n] for n in range(i+1,n)])
    i += 1
print(ans)

Fixed submission:
n = int(input())
ans = 0
d = {}
for i in range(n):
    s = ''.join(sorted(input()))
    if s not in d.keys():
        d[s] = 1
    else:
        ans += d[s]
        d[s] += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

s = input()

ans = [0]*len(s)

for _ in range(2):
    cnt = 0
    for i in range(n):
        if s[i] == 'R': cnt += 1
        else:
            ans[i] += cnt//2
            ans[i-1] += (cnt-1)//2
            cnt = 0
        
    ans.sort()
    s = s[::-1]
    for i in range(n):
        if s[i] == 'L': s[i] = 'R'
        else: s[i] = 'L'

print(*ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

s = input()

ans = [0]*len(s)

i = 0
len_left = 1
len_right = 0
intersec_left = 0
now_left = True

while i < len(s)-1:
    if s[i] == s[i+1] and now_left:
        len_left += 1
    elif s[i] != s[i+1] and now_left:
        len_right += 1
        intersec_left = i
        now_left = False
    elif s[i] == s[i+1]:
        len_right += 1
    else:
        if len_left%2 == 0:
            ans[intersec_left] += len_left//2
            ans[intersec_left+1] += len_left//2
        else:
            ans[intersec_left] += len_left//2+1
            ans[intersec_left+1] += len_left//2
        if len_right%2 == 0:
            ans[intersec_left] += len_right//2
            ans[intersec_left+1] += len_right//2
        else:
            ans[intersec_left] += len_right//2
            ans[intersec_left+1] += len_right//2+1
        len_left = 1
        len_right = 0
        intersec_left = i+1
        now_left = True
    i += 1
else:
    if len_left%2 == 0:
        ans[intersec_left] += len_left//2
        ans[intersec_left+1] += len_left//2
    else:
        ans[intersec_left] += len_left//2+1
        ans[intersec_left+1] += len_left//2
    if len_right%2 == 0:
        ans[intersec_left] += len_right//2
        ans[intersec_left+1] += len_right//2
    else:
        ans[intersec_left] += len_right//2
        ans[intersec_left+1] += len_right//2+1
    
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

n = int(input())
readline = sys.stdin.readline
a = [int(input()) for _ in range(n)]

from collections import deque
a = deque(a)

ans = []

for _ in range(n):
    tmp = a.popleft()
    ans.append(max(a))
    a.append(tmp)

print(*ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

n = int(input())
readline = sys.stdin.readline
A = [int(input()) for _ in range(n)]

import heapq

Q = [-a for a in A]
heapq.heapify(Q)

ans = []

for i in range(n):
    if -Q[0] == A[i]:
        tmp = heapq.heappop(Q)
        ans.append(-Q[0])
        heapq.heappush(Q, tmp)
    else:
        ans.append(-Q[0])

print(*ans)

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

n = int(input())
readline = sys.stdin.readline
a = [int(input()) for _ in range(n)]

ans = []

for _ in range(n):
    tmp = a.pop(0)
    ans.append(max(a))
    a.append(tmp)

print(*ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

n = int(input())
readline = sys.stdin.readline
A = [int(input()) for _ in range(n)]

import heapq

Q = [-a for a in A]
heapq.heapify(Q)

ans = []

for i in range(n):
    if -Q[0] == A[i]:
        tmp = heapq.heappop(Q)
        ans.append(-Q[0])
        heapq.heappush(Q, tmp)
    else:
        ans.append(-Q[0])

print(*ans)
Buggy python submission (verdict: Runtime Error):
3
1 0 0

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

n = int(input())
a = [0]
a += list(map(int, input().split()))

b = [0]*(n+1)

for i in range(n,0,-1):
    sum = 0
    for j in range(2*i, n+1, i):
        sum ^= b[j]
    b[i] = sum^a[i]
    
ans = []
for i in range(1,n+1):
    if b[i]: ans.append(i)

print(len(ans))
print(*ans)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

l, r = map(int, input().split())

MOD = 2019

#n = 2019
#pf = {}
#
#for i in range(2,int(n**0.5)+1):
#    while n % i == 0:
#        pf[i] = pf.get(i,0) + 1
#        n //= i
#if n > 1: pf[n] = 1
#print(pf)
## 2019=3*673

import itertools

l_mod = l%MOD
r_mod = r%MOD

if r-l > 2019:
    ans = 0
else:
    if l_mod < r_mod:
    	li = [i for i in range(l_mod, r_mod+1)]
    	ans = 2018
    	for v in itertools.combinations(li, 2):
      	ans = min(ans, v[0]*v[1]%MOD)        
    else:
        ans = 0

print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

l, r = map(int, input().split())

MOD = 2019

#n = 2019
#pf = {}
#
#for i in range(2,int(n**0.5)+1):
#    while n % i == 0:
#        pf[i] = pf.get(i,0) + 1
#        n //= i
#if n > 1: pf[n] = 1
#print(pf)
## 2019=3*673

import itertools

l_mod = l%MOD
r_mod = r%MOD

if r-l > 2019:
    ans = 0
else:
    if l_mod <= 3 <= r_mod and l_mod <= 673 <= r_mod:
        ans = 0
    elif l_mod < r_mod:
        li = [i for i in range(l_mod, r_mod+1)]
        ans = 2018
        for v in itertools.combinations(li, 2):
            ans = min(ans, v[0]*v[1]%MOD)        
    else:
        ans = 0

print(ans)