#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  int max = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] > A[i - 1]) max = A[i];
  }
  int maxcount = 0;
  for (int i = 0; i < N; i++)
    if (A[i] == max) maxcount++;
  cout << maxcount << endl;
  int submax = 0;
  int temp = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] == max)
      continue;
    else {
      if (A[i] > temp) {
        submax = A[i];
        temp = submax;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (A[i] == max && maxcount == 1)
      cout << submax << endl;
    else
      cout << max << endl;
  }
}
