#include <stdio.h>
#include <string.h>
//注意选择排序
// int minindex;int temp;
//i=0;i<n-1 j=i+1;j<n
int main()
{
int n;
scanf("%d", &n);
int s[n];
int sortflag; //1降序 0升序
for (int i = 0; i < n; i++)
scanf("%d", &s[i]);
scanf("%d", &sortflag);
//选择排序
int minindex;
int temp;
for (int i = 0; i < n - 1; i++)
{
minindex = i;
for (int j = i + 1; j < n; j++)
{
if (s[j] < s[minindex])
minindex = j;
}
temp = s[i];
s[i] = s[minindex];
s[minindex] = temp;
}
if (sortflag == 0)
{
for (int i = 0; i < n; i++)
printf("%d ", s[i]);
}
else if (sortflag == 1)
{
for (int i = n - 1; i >= 0; i--)
printf("%d ", s[i]);
}
return 0;
}