#include
#include
#include
#include
void funkcija(int * niza, int n) {
int prev_element = niza[0];
int nova_niza[n];
nova_niza[0] = niza[0];
int j = 1;
for(int i = 1; i < n; i++) {
if(prev_element <= niza[i]) {
nova_niza[j] = niza[i];
prev_element = niza[i];
j++;
}
}
for(int i = 0; i < j; i++) {
printf("%d ", nova_niza[i]);
}
}
int main(int argc, const char * argv[]) {
int n;
scanf("%d", &n);
int niza[n];
for(int i = 0; i < n; i++) {
scanf("%d", &niza[i]);
}
funkcija(niza, n);
return 0;
}
/*
8
1 2 -1 -2 4 3 15 7 2
*/