#include<stdio.h>
#include <stdlib.h>
int cmp(constvoid* a,constvoid* b){return*(int*)a-*(int*)b;}
int main(){
int n,i,max=0,count=0,s[100001],t[100001],r[100001];scanf("%d",&n);for(i=0;i<n;i++){scanf("%d",&s[i]);
t[i]=s[i];}qsort(s,n,sizeof(int),cmp);for(i=0;i<n;i++){if(t[i]>t[max])max=i;if(t[i]==s[i]&&t[i]==t[max])r[count++]=t[i];}printf("%d\n",count);if(count!=0){for(i=0;i<count-1;i++)printf("%d ",r[i]);printf("%d",r[count-1]);}printf("\n");return0;}