import java.util.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws IOException
{
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n,k;
String[] strNums;
n=Integer.parseInt(br.readLine());
if(n<=0 || n>=(10^5))
return;
int arr[]=new int[n];
strNums = br.readLine().split("\\s");
for(int i=0;i<n;i++)
{
arr[i]=Integer.parseInt(strNums[i]);
if(arr[i]<0 ||arr[i]>(10^6))
return;
}
k=Integer.parseInt(br.readLine());
if(k<1 || k>n)
return;
printMax(arr,n,k);
}
catch(Exception e)
{
e.printStackTrace();
}
}
static void printMax(int arr[],int n, int k)
{
Deque<Integer> Qi = new LinkedList<Integer>();
int i;
for(i = 0; i < k; ++i)
{
while(!Qi.isEmpty() && arr[i] >= arr[Qi.peekLast()])
{
Qi.removeLast(); // Remove from rear
}
Qi.addLast(i);
}
// Process rest of the elements, i.e., from arr[k] to arr[n-1]
for(;i < n; ++i)
{
System.out.print(arr[Qi.peek()] + " ");
if((!Qi.isEmpty())&&(Qi.peek()<= i-k))
{
// System.out.println("confusing while fulfilled,Qi.peek()="+Qi.peek()+" <= "+(i-k)+ " i-k");
Qi.removeFirst();
}
while((!Qi.isEmpty()) && arr[i] >= arr[Qi.peekLast()])
Qi.removeLast();
Qi.addLast(i);
}
System.out.print(arr[Qi.peek()]);
}
}