Problem: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $L$, find the minimum of each possible sub-arrays with size $L$ and print them from the beginning. For example, for an array $\\{1, 7, 7, 4, 8, 1, 6\\}$ and $L = 3$, the possible sub-arrays with size $L = 3$ includes $\\{1, 7, 7\\}$, $\\{7, 7, 4\\}$, $\\{7, 4, 8\\}$, $\\{4, 8, 1\\}$, $\\{8, 1, 6\\}$ and the minimum of each sub-array is 1, 4, 4, 1, 1 respectively.

Constraints

* $1 \leq N \leq 10^6$
* $1 \leq L \leq 10^6$
* $1 \leq a_i \leq 10^9$
* $L \leq N$

Input

The input is given in the following format.

$N$ $L$
$a_1$ $a_2$ ... $a_N$

Output

Print a sequence of the minimum in a line. Print a space character between adjacent elements.

Example

Input

7 3
1 7 7 4 8 1 6


Output

1 4 4 1 1

Solution (in CPP):

Solution:
#include <iostream>
#include <vector>

using namespace std;

const int INIVAL = (1<<31) - 1;

class SegmentTree{
public:
    int n; //array size
    vector<int> D; //minimum values for the range represented by node i of the segment tree
    //
    void initRMQ(int n_);
    void update(int k, int x);
    int findMin(int a, int b);
    int query(int node, int start, int end_, int l, int r);
    //
    void printTree();
};

void getin();

int main()
{
    getin();
    return 0;
}

void getin(){
    SegmentTree ist;
    int N, L, a;
    //
    cin >> N >> L;
    ist.initRMQ(N);
    vector<int> out(N-L+1);
    // get the whole array
    for (int i = 0; i < N; i++) {
        cin >> a;
        ist.update(i,a);
    }
    // calculate output
    for (int i = 0; i < N-L; i++) {
        cout << ist.findMin(i, i+L-1) << " ";
    }
    cout << ist.findMin(N-L, N-1);
    cout << endl;
}

void SegmentTree::initRMQ(int n_) {
    n = 1;
    while (n<n_) {n *= 2;}
    D = vector<int>(2*n-1, INIVAL);
}

void SegmentTree::printTree() {
    cout << "segtree: " << endl;
    for (int i = 0; i < D.size(); i++) {
        cout << fixed << this->D[i] << "\t";
    }
    cout << endl;
}

void SegmentTree::update(int k, int x) {
    k += n - 1;
    D[k] = x;
    while (k > 0) {
        k = (k-1)/2;
        D[k] = min(D[k*2+1], D[k*2+2]);
    }
}

int SegmentTree::findMin(int a, int b) {
    return query(0, 0, n-1, a, b);
}

// given searching range a[l], ... a[r]
int SegmentTree::query(int node, int start, int end_, int l, int r) {
    if ((r < start) || (end_ < l)) {
        // the range presented by the current node is completely outside the given (searching) range
        return INIVAL;
    }
    else if ((l <= start) && (end_ <= r)) {
        // completely inside the given range
        return D[node];
    }
    else { // partly inside and partly outside
        int mid = (start+end_)/2;
        int vl = query(2*node+1, start, mid, l, r);
        int vr = query(2*node+2, mid+1, end_, l, r);
        return min(vl, vr);
    }
}