#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  vector<int> B(N);
  for (int i = 0; i < N; i++) B[i] = A[i];
  sort(B.rbegin(), B.rend());
  for (int i = 0; i < B.size(); i++) cout << B[i] << " ";
  cout << endl;
  for (int i = 0; i < N; i++) {
    if (A[i] == B[0]) {
      cout << B[1];
    } else {
      cout << B[0];
    }
    cout << endl;
  }
  return 0;
}
