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

def left_rot(node):
    s = node['right'].copy()
    node['right'] = s['left']#.copy()
    s['left'] = node
    return s

def right_rot(node):
    s = node['left'].copy()
    node['left'] = s['right']#.copy()
    s['right'] = node
    return s

def insert(node,k,p):
    if(node is None):
        child = {
            'left' : None,
            'right' : None,
            'key' : k,
            'priority' : p}
        return child
    if(k == node['key']):
        return node
    # Left side
    if(k < node['key']):
        node['left'] = insert(node['left'],k,p)
        #追加したらあとは優先度による回転を行う
        if(node['priority'] < node['left']['priority']):
            node = right_rot(node)
    # Right side
    else:
        node['right'] = insert(node['right'],k,p)
        #追加したらあとは以下略
        if(node['priority'] < node['right']['priority']):
            node = left_rot(node)

    return node

def find(node,k):
    if(node is None):
        return k
    if(node['key'][0] < k):
        k = node['key'][0]
    min_left = find(node['left'],k)
    min_right = find(node['right'],k)
    return min(min_left,min_right)

def delete(node, k):
    if(node is None):
        return None

    if(node['key'] == k):
        if(node['left'] is None and node['right'] is None):
            return None
        elif(node['left'] is None):
            node = left_rot(node)
        elif(node['right'] is None):
            node = right_rot(node)
        else:
            if(node['left']['priority'] > node['right']['priority']):
                node = right_rot(node)
            else:
                node = left_rot(node)
        return delete(node, k)
    if(k < node['key']):
        node['left'] = delete(node['left'], k)
    else:
        node['right'] = delete(node['right'], k)

    return node

N,k = map(int, input().split())
arr = list(map(int,input().split()))
node = None
priorities = list(range(N))
shuffle(priorities)
for i in range(k):
    #p = priorities.pop(0)
    node = insert(node, (arr[i],i), priorities[i])
    #priorities.append(p)
ans = []
INT_MAX = 10**9
for i in range(N-k):
    ans.append(find(node,INT_MAX))
    #p = priorities.pop(0)
    node = delete(node, (arr[i],i))
    node = insert(node, (arr[i+k],i+k), priorities[i+k])
    #priorities.append(p)

ans.append(find(node,INT_MAX))
print(" ".join([str(r) for r in ans]))



Fixed submission:
INTMAX = (1<<31) - 1

def ans():
    for i in range(k):
        x = i + OFS
        A[x] = arr[i]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r#min(tree[left],tree[right])
    res = []
    c = 0
    for i in range(_N-k):
        res.append(A[0])
        x = c + OFS
        A[x] = arr[i+k]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r
        c += 1
        if(c == k):
            c = 0
    res.append(A[0])
    print(*res)

_N,k = map(int, input().split())
*arr, = map(int,input().split())
if(k==1):
    print(*arr)
else:
    N = 2**(_N-1).bit_length()
    A = [INTMAX]*(2*N)
    OFS = N - 1
    ans()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import math
sys.setrecursionlimit(20000)
def update(tree,x,y,N):
    # offset
    #x += int(N/2)
    x += N - 1
    tree[x] = y
    # segment tree no update suru
    while True:
        if(x <= 0):
            break
        x = math.floor((x - 1)/2)
        left = x*2+1
        right = x*2+2
        tree[x] = min(tree[left],tree[right])

def find(tree,x,y,k,l,r):

    if (r <= x or y <= l):
        return 2**31 - 1
    # sita wo mite itte mitukatta toki (intersect)
    if ( x <= l and r <= y):
        return tree[k]
    # sita ni sagaru
    v_left = find(tree, x, y, k*2 + 1, l, int((l+r)/2))
    v_right = find(tree, x, y, k*2 + 2, int((l+r)/2), r)
    return min(v_left, v_right)

if __name__ == '__main__':
    _N,k = map(int, input().split())
    arr = list(map(int,input().split()))
    INT_MAX = 2**31 - 1
    N = 1
    res = []
    while True:
        if(N >= _N):
            break
        N *= 2
    #N = 2*N - 1 - 1
    if not (N == 1):
        A_bin_tree = [INT_MAX]*(2*N - 1)
    else:
        A_bin_tree = [INT_MAX]
    for i in range(_N):
        update(A_bin_tree,i,arr[i],N)

    for i in range(_N-k+1):
        z = find(A_bin_tree,i,i+k,0,0,N)
        res.append(z)

    print(" ".join([str(r) for r in res]))



Fixed submission:
INTMAX = (1<<31) - 1

def ans():
    for i in range(k):
        x = i + OFS
        A[x] = arr[i]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r#min(tree[left],tree[right])
    res = []
    c = 0
    for i in range(_N-k):
        res.append(A[0])
        x = c + OFS
        A[x] = arr[i+k]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r
        c += 1
        if(c == k):
            c = 0
    res.append(A[0])
    print(*res)

_N,k = map(int, input().split())
*arr, = map(int,input().split())
if(k==1):
    print(*arr)
else:
    N = 2**(_N-1).bit_length()
    A = [INTMAX]*(2*N)
    OFS = N - 1
    ans()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import math
sys.setrecursionlimit(20000)
INT_MAX = 2**31 - 1
def update(tree,x,y,N):
    # offset
    #x += int(N/2)
    x += N - 1
    tree[x] = y
    # segment tree no update suru
    while True:
        if(x <= 0):
            break
        x = math.floor((x - 1)/2)
        left = x*2+1
        right = x*2+2
        tree[x] = min(tree[left],tree[right])

def find(tree,x,y,k,l,r):

    if (r <= x or y <= l):
        return INT_MAX - 1
    # sita wo mite itte mitukatta toki (intersect)
    if ( x <= l and r <= y):
        return tree[k]
    # sita ni sagaru
    v_left = find(tree, x, y, k*2 + 1, l, int((l+r)/2))
    v_right = find(tree, x, y, k*2 + 2, int((l+r)/2), r)
    return min(v_left, v_right)

if __name__ == '__main__':
    _N,k = map(int, input().split())
    arr = list(map(int,input().split()))
    N = 1
    res = []
    while True:
        if(N >= _N):
            break
        N *= 2
    #N = 2*N - 1 - 1
    if not (N == 1):
        A_bin_tree = [INT_MAX]*(2*N - 1)
    else:
        A_bin_tree = [INT_MAX]
    for i in range(k):
        update(A_bin_tree,i,arr[i],N)

    for i in range(_N-k):
        res.append(find(A_bin_tree,i,i+k,0,0,N))
        update(A_bin_tree,i+k,arr[i+k],N)

    res.append(find(A_bin_tree,_N-k,_N,0,0,N))
    print(" ".join([str(r) for r in res]))



Fixed submission:
INTMAX = (1<<31) - 1

def ans():
    for i in range(k):
        x = i + OFS
        A[x] = arr[i]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r#min(tree[left],tree[right])
    res = []
    c = 0
    for i in range(_N-k):
        res.append(A[0])
        x = c + OFS
        A[x] = arr[i+k]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r
        c += 1
        if(c == k):
            c = 0
    res.append(A[0])
    print(*res)

_N,k = map(int, input().split())
*arr, = map(int,input().split())
if(k==1):
    print(*arr)
else:
    N = 2**(_N-1).bit_length()
    A = [INTMAX]*(2*N)
    OFS = N - 1
    ans()

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

def left_rot(node):
    s = node['right'].copy()
    node['right'] = s['left']#.copy()
    s['left'] = node
    return s

def right_rot(node):
    s = node['left'].copy()
    node['left'] = s['right']#.copy()
    s['right'] = node
    return s

def insert(node,k,p):
    if(node is None):
        child = {
            'left' : None,
            'right' : None,
            'key' : k,
            'priority' : p}
        return child
    if(k == node['key']):
        return node
    # Left side
    if(k < node['key']):
        node['left'] = insert(node['left'],k,p)
        #追加したらあとは優先度による回転を行う
        if(node['priority'] < node['left']['priority']):
            node = right_rot(node)
    # Right side
    else:
        node['right'] = insert(node['right'],k,p)
        #追加したらあとは以下略
        if(node['priority'] < node['right']['priority']):
            node = left_rot(node)

    return node

def find(node,k):
    if(node is None):
        return k
    if(node['key'][0] < k):
        k = node['key'][0]
    min_left = find(node['left'],k)
    min_right = find(node['right'],k)
    return min(min_left,min_right)

def delete(node, k):
    if(node is None):
        return None

    if(node['key'] == k):
        if(node['left'] is None and node['right'] is None):
            return None
        elif(node['left'] is None):
            node = left_rot(node)
        elif(node['right'] is None):
            node = right_rot(node)
        else:
            if(node['left']['priority'] > node['right']['priority']):
                node = right_rot(node)
            else:
                node = left_rot(node)
        return delete(node, k)
    if(k < node['key']):
        node['left'] = delete(node['left'], k)
    else:
        node['right'] = delete(node['right'], k)

    return node

N,k = map(int, input().split())
*arr, = map(int,input().split())
node = None
priorities = list(range(N))
shuffle(priorities)
for i in range(k):
    #p = priorities.pop(0)
    node = insert(node, (arr[i],i), priorities[i])
    #priorities.append(p)
ans = []
INT_MAX = 10**9
for i in range(N-k):
    ans.append(find(node,INT_MAX))
    #p = priorities.pop(0)
    node = delete(node, (arr[i],i))
    node = insert(node, (arr[i+k],i+k), priorities[i+k])
    #priorities.append(p)

ans.append(find(node,INT_MAX))
print(*ans)



Fixed submission:
INTMAX = (1<<31) - 1

def ans():
    for i in range(k):
        x = i + OFS
        A[x] = arr[i]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r#min(tree[left],tree[right])
    res = []
    c = 0
    for i in range(_N-k):
        res.append(A[0])
        x = c + OFS
        A[x] = arr[i+k]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r
        c += 1
        if(c == k):
            c = 0
    res.append(A[0])
    print(*res)

_N,k = map(int, input().split())
*arr, = map(int,input().split())
if(k==1):
    print(*arr)
else:
    N = 2**(_N-1).bit_length()
    A = [INTMAX]*(2*N)
    OFS = N - 1
    ans()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import math
INT_MAX = 2**31 - 1
def update(tree,x,y,N):
    x += N - 1
    tree[x] = y
    while True:
        if(x <= 0):
            break
        x = math.floor((x - 1)/2)
        left = x*2+1
        right = x*2+2
        tree[x] = min(tree[left],tree[right])

def find(tree,x,y,k,l,r):

    if (r <= x or y <= l):
        return INT_MAX - 1
    if ( x <= l and r <= y):
        return tree[k]
    v_left = find(tree, x, y, k*2 + 1, l, int((l+r)/2))
    v_right = find(tree, x, y, k*2 + 2, int((l+r)/2), r)
    return min(v_left, v_right)

_N,k = map(int, input().split())
*arr, = map(int,input().split())
N = 1
res = []
while True:
    if(N >= _N):
        break
    N *= 2
if not (N == 1):
    A_bin_tree = [INT_MAX]*(2*N - 1)
else:
    A_bin_tree = [INT_MAX]
for i in range(_N):
    update(A_bin_tree,i,arr[i],N)

for i in range(_N-k+1):
    z = find(A_bin_tree,i,i+k,0,0,N)
    res.append(z)

print(*res)



Fixed submission:
INTMAX = (1<<31) - 1

def ans():
    for i in range(k):
        x = i + OFS
        A[x] = arr[i]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r#min(tree[left],tree[right])
    res = []
    c = 0
    for i in range(_N-k):
        res.append(A[0])
        x = c + OFS
        A[x] = arr[i+k]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r
        c += 1
        if(c == k):
            c = 0
    res.append(A[0])
    print(*res)

_N,k = map(int, input().split())
*arr, = map(int,input().split())
if(k==1):
    print(*arr)
else:
    N = 2**(_N-1).bit_length()
    A = [INTMAX]*(2*N)
    OFS = N - 1
    ans()

Buggy python submission (verdict: Time Limit Exceeded):
INT_MAX = 2**31 - 1
def update():
    for i in range(_N):
        x = i + N - 1
        A_bin_tree[x] = arr[i]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            left = x*2+1
            right = x*2+2
            A_bin_tree[x] = min(A_bin_tree[left],A_bin_tree[right])

def find(x,y,k,l,r):

    if (r <= x or y <= l):
        return INT_MAX
    if ( x <= l and r <= y):
        return A_bin_tree[k]
    v_left = find(x, y, k*2 + 1, l, int((l+r)/2))
    v_right = find(x, y, k*2 + 2, int((l+r)/2), r)
    return min(v_left, v_right)

_N,k = map(int, input().split())
*arr, = map(int,input().split())
N = 1
res = []
while True:
    if(N >= _N):
        break
    N *= 2
if not (N == 1):
    A_bin_tree = [INT_MAX]*(2*N - 1)
else:
    A_bin_tree = [INT_MAX]
update()

for i in range(_N-k+1):
    z = find(i,i+k,0,0,N)
    res.append(z)

print(*res)



Fixed submission:
INTMAX = (1<<31) - 1

def ans():
    for i in range(k):
        x = i + OFS
        A[x] = arr[i]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r#min(tree[left],tree[right])
    res = []
    c = 0
    for i in range(_N-k):
        res.append(A[0])
        x = c + OFS
        A[x] = arr[i+k]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r
        c += 1
        if(c == k):
            c = 0
    res.append(A[0])
    print(*res)

_N,k = map(int, input().split())
*arr, = map(int,input().split())
if(k==1):
    print(*arr)
else:
    N = 2**(_N-1).bit_length()
    A = [INTMAX]*(2*N)
    OFS = N - 1
    ans()

Buggy python submission (verdict: Time Limit Exceeded):
INT_MAX = (1<<31) - 1

def update():
    for i in range(_N):
        x = i+N-1
        A_bin_tree[x] = arr[i]
        while x > 1:
            x >>= 1
            l, r = A_bin_tree[x<<1], A_bin_tree[(x<<1)+1]
            A_bin_tree[x] = min(l,r)#l if l < r else r

def find(x,y):
    l = x+N-1
    r = y+N-1
    z = INT_MAX
    while l < r:
        if l & 1:
            if(A_bin_tree[l] < z):
                z = A_bin_tree[l]
            l += 1
        if r & 1:
            r -= 1
            if(A_bin_tree[r] < z):
                z = A_bin_tree[r]
        l >>= 1
        r >>= 1
    return z

import sys
input = sys.stdin.readline
_N,k = map(int,input().split())
*arr, = map(int,input().split())
N = 1
while True:
    if(N >= _N):
        break
    N = N << 1
A_bin_tree = [INT_MAX]*(2*N)

update()
res = [find(i,i+k) for i in range(_N-k+1)]
print(*res)



Fixed submission:
INTMAX = (1<<31) - 1

def ans():
    for i in range(k):
        x = i + OFS
        A[x] = arr[i]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r#min(tree[left],tree[right])
    res = []
    c = 0
    for i in range(_N-k):
        res.append(A[0])
        x = c + OFS
        A[x] = arr[i+k]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r
        c += 1
        if(c == k):
            c = 0
    res.append(A[0])
    print(*res)

_N,k = map(int, input().split())
*arr, = map(int,input().split())
if(k==1):
    print(*arr)
else:
    N = 2**(_N-1).bit_length()
    A = [INTMAX]*(2*N)
    OFS = N - 1
    ans()

Buggy python submission (verdict: Time Limit Exceeded):
INT_MAX = (1<<31) - 1
def update():
    for i in range(_N):
        x = i+N-1
        A_bin_tree[x] = arr[i]
        while x > 1:
            x >>= 1
            y = x<<1
            l = A_bin_tree[y]
            r = A_bin_tree[y+1]
            A_bin_tree[x] = l if l < r else r#min(l,r)

def find(x,y):
    l = x+N-1
    r = y+N-1
    z = INT_MAX
    while l < r:
        if l & 1:
            if(A_bin_tree[l] < z):
                z = A_bin_tree[l]
            l += 1
        if r & 1:
            r -= 1
            if(A_bin_tree[r] < z):
                z = A_bin_tree[r]
        l >>= 1
        r >>= 1
    return z

import sys
input = sys.stdin.readline
_N,k = map(int,input().split())
*arr, = map(int,input().split())
N = 1
N = 2**(_N-1).bit_length()
A_bin_tree = [INT_MAX]*(N<<1)
update()
res = [find(i,i+k) for i in range(_N-k+1)]
print(*res)


Fixed submission:
INTMAX = (1<<31) - 1

def ans():
    for i in range(k):
        x = i + OFS
        A[x] = arr[i]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r#min(tree[left],tree[right])
    res = []
    c = 0
    for i in range(_N-k):
        res.append(A[0])
        x = c + OFS
        A[x] = arr[i+k]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r
        c += 1
        if(c == k):
            c = 0
    res.append(A[0])
    print(*res)

_N,k = map(int, input().split())
*arr, = map(int,input().split())
if(k==1):
    print(*arr)
else:
    N = 2**(_N-1).bit_length()
    A = [INTMAX]*(2*N)
    OFS = N - 1
    ans()

Buggy python submission (verdict: Time Limit Exceeded):
INTMAX = (1<<31) - 1

def update():
    for i in range(_N):
        x = i+N-1
        A[x] = arr[i]
        while x > 1:
            x >>= 1
            y = x<<1
            l = A[y]
            r = A[y+1]
            A[x] = l if l < r else r#min(l,r)

def find():
    res = [0]*(_N-k+1)
    for i in range(_N-k+1):
        l = i+N-1
        r = i+k+N-1
        z = INTMAX
        while l < r:
            if l & 1:
                if(A[l] < z):
                    z = A[l]
                l += 1
            if r & 1:
                r -= 1
                if(A[r] < z):
                    z = A[r]
            l >>= 1
            r >>= 1
        res[i] = z
    print(*res)

_N,k = map(int,input().split())
*arr, = map(int,input().split())
N = 1
N = 2**(_N-1).bit_length()
A = [INTMAX]*(N<<1)
update()
find()



Fixed submission:
INTMAX = (1<<31) - 1

def ans():
    for i in range(k):
        x = i + OFS
        A[x] = arr[i]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r#min(tree[left],tree[right])
    res = []
    c = 0
    for i in range(_N-k):
        res.append(A[0])
        x = c + OFS
        A[x] = arr[i+k]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r
        c += 1
        if(c == k):
            c = 0
    res.append(A[0])
    print(*res)

_N,k = map(int, input().split())
*arr, = map(int,input().split())
if(k==1):
    print(*arr)
else:
    N = 2**(_N-1).bit_length()
    A = [INTMAX]*(2*N)
    OFS = N - 1
    ans()

Buggy python submission (verdict: Time Limit Exceeded):
INTMAX = (1<<31) - 1

def ans():
    for i in range(_N):
        x = i+OFS#N-1
        A[x] = arr[i]
        while x > 1:
            x >>= 1
            y = x<<1
            l = A[y]
            r = A[y+1]
            A[x] = l if l < r else r#min(l,r)

    res = [0]*(_N-k+1)
    for i in range(_N-k+1):
        l = i+OFS#N-1
        r = i+k+OFS#N-1
        z = INTMAX
        while l < r:
            if l & 1:
                p = A[l]
                z = p if p < z else z
                l += 1
            if r & 1:
                r -= 1
                p = A[r]
                z = p if p < z else z
            l >>= 1
            r >>= 1
        res[i] = z
    print(*res)

_N,k = map(int,input().split())
*arr, = map(int,input().split())
N = 1
N = 2**(_N-1).bit_length()
OFS = N - 1
A = [INTMAX]*(N<<1)
ans()



Fixed submission:
INTMAX = (1<<31) - 1

def ans():
    for i in range(k):
        x = i + OFS
        A[x] = arr[i]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r#min(tree[left],tree[right])
    res = []
    c = 0
    for i in range(_N-k):
        res.append(A[0])
        x = c + OFS
        A[x] = arr[i+k]
        while True:
            if(x <= 0):
                break
            x = (x - 1)//2
            l = A[x*2+1]
            r = A[x*2+2]
            A[x] = l if l < r else r
        c += 1
        if(c == k):
            c = 0
    res.append(A[0])
    print(*res)

_N,k = map(int, input().split())
*arr, = map(int,input().split())
if(k==1):
    print(*arr)
else:
    N = 2**(_N-1).bit_length()
    A = [INTMAX]*(2*N)
    OFS = N - 1
    ans()