import java.util.Scanner;

class Main {
  private static void solve(int n, int[] a) {
    Integer first = null;
    Integer second = null;
    int count = 0;
    for (int val : a) {
      if (first == null || first < val) {
        second = first;
        first = val;
        count = 1;
      } else if (first == val) {
        count += 1;
      } else if (second == null || second < val) {
        second = val;
      }
    }
    int[] result = new int[n];
    for (int i = 0; i < n; i++) {
      if (a[i] != first) {
        result[i] = first;
      } else if (count > 1) {
        result[i] = first;
      } else {
        result[i] = second;
      }
    }
    for (int val : result) {
      System.out.println(val);
    }
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine());
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = Integer.parseInt(sc.nextLine());
    }
    sc.close();
    solve(n, a);
  }
} import java.util.Scanner; Scanner java.util class Main {
  private static void solve(int n, int[] a) {
    Integer first = null;
    Integer second = null;
    int count = 0;
    for (int val : a) {
      if (first == null || first < val) {
        second = first;
        first = val;
        count = 1;
      } else if (first == val) {
        count += 1;
      } else if (second == null || second < val) {
        second = val;
      }
    }
    int[] result = new int[n];
    for (int i = 0; i < n; i++) {
      if (a[i] != first) {
        result[i] = first;
      } else if (count > 1) {
        result[i] = first;
      } else {
        result[i] = second;
      }
    }
    for (int val : result) {
      System.out.println(val);
    }
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine());
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = Integer.parseInt(sc.nextLine());
    }
    sc.close();
    solve(n, a);
  }
} Main private static void solve(int n, int[] a) {
    Integer first = null;
    Integer second = null;
    int count = 0;
    for (int val : a) {
      if (first == null || first < val) {
        second = first;
        first = val;
        count = 1;
      } else if (first == val) {
        count += 1;
      } else if (second == null || second < val) {
        second = val;
      }
    }
    int[] result = new int[n];
    for (int i = 0; i < n; i++) {
      if (a[i] != first) {
        result[i] = first;
      } else if (count > 1) {
        result[i] = first;
      } else {
        result[i] = second;
      }
    }
    for (int val : result) {
      System.out.println(val);
    }
  } solve {
    Integer first = null;
    Integer second = null;
    int count = 0;
    for (int val : a) {
      if (first == null || first < val) {
        second = first;
        first = val;
        count = 1;
      } else if (first == val) {
        count += 1;
      } else if (second == null || second < val) {
        second = val;
      }
    }
    int[] result = new int[n];
    for (int i = 0; i < n; i++) {
      if (a[i] != first) {
        result[i] = first;
      } else if (count > 1) {
        result[i] = first;
      } else {
        result[i] = second;
      }
    }
    for (int val : result) {
      System.out.println(val);
    }
  } Integer first = null; first null Integer second = null; second null int count = 0; count 0 for (int val : a) {
      if (first == null || first < val) {
        second = first;
        first = val;
        count = 1;
      } else if (first == val) {
        count += 1;
      } else if (second == null || second < val) {
        second = val;
      }
    } int val a {
      if (first == null || first < val) {
        second = first;
        first = val;
        count = 1;
      } else if (first == val) {
        count += 1;
      } else if (second == null || second < val) {
        second = val;
      }
    } {
      if (first == null || first < val) {
        second = first;
        first = val;
        count = 1;
      } else if (first == val) {
        count += 1;
      } else if (second == null || second < val) {
        second = val;
      }
    } if (first == null || first < val) {
        second = first;
        first = val;
        count = 1;
      } else if (first == val) {
        count += 1;
      } else if (second == null || second < val) {
        second = val;
      } first == null || first < val first == null first null first < val first val {
        second = first;
        first = val;
        count = 1;
      } second = first second first first = val first val count = 1 count 1 if (first == val) {
        count += 1;
      } else if (second == null || second < val) {
        second = val;
      } first == val first val {
        count += 1;
      } count += 1 count 1 if (second == null || second < val) {
        second = val;
      } second == null || second < val second == null second null second < val second val {
        second = val;
      } second = val second val int[] result = new int[n]; result new int[n] n for (int i = 0; i < n; i++) {
      if (a[i] != first) {
        result[i] = first;
      } else if (count > 1) {
        result[i] = first;
      } else {
        result[i] = second;
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      if (a[i] != first) {
        result[i] = first;
      } else if (count > 1) {
        result[i] = first;
      } else {
        result[i] = second;
      }
    } {
      if (a[i] != first) {
        result[i] = first;
      } else if (count > 1) {
        result[i] = first;
      } else {
        result[i] = second;
      }
    } if (a[i] != first) {
        result[i] = first;
      } else if (count > 1) {
        result[i] = first;
      } else {
        result[i] = second;
      } a[i] != first a[i] a i first {
        result[i] = first;
      } result[i] = first result[i] result i first if (count > 1) {
        result[i] = first;
      } else {
        result[i] = second;
      } count > 1 count 1 {
        result[i] = first;
      } result[i] = first result[i] result i first {
        result[i] = second;
      } result[i] = second result[i] result i second for (int val : result) {
      System.out.println(val);
    } int val result {
      System.out.println(val);
    } {
      System.out.println(val);
    } System.out.println(val) System.out.println System.out System System.out val int n n int[] a a public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine());
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = Integer.parseInt(sc.nextLine());
    }
    sc.close();
    solve(n, a);
  } main {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine());
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = Integer.parseInt(sc.nextLine());
    }
    sc.close();
    solve(n, a);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.nextLine()); n Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc int[] a = new int[n]; a new int[n] n for (int i = 0; i < n; i++) {
      a[i] = Integer.parseInt(sc.nextLine());
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      a[i] = Integer.parseInt(sc.nextLine());
    } {
      a[i] = Integer.parseInt(sc.nextLine());
    } a[i] = Integer.parseInt(sc.nextLine()) a[i] a i Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc sc.close() sc.close sc solve(n, a) solve n a String[] args args
import java.util.Scanner;

class Main {
  private static void solve(int n, int[] a) {
    Integer first = null;
    Integer second = null;
    int count = 0;
    for (int val : a) {
      if (first == null || first < val) {
        second = first;
        first = val;
        count = 1;
      } else if (first == val) {
        count += 1;
      } else if (second == null || second < val) {
        second = val;
      }
    }
    int[] result = new int[n];
    for (int i = 0; i < n; i++) {
      if (a[i] != first) {
        result[i] = first;
      } else if (count > 1) {
        result[i] = first;
      } else {
        result[i] = second;
      }
    }
    for (int val : result) {
      System.out.println(val);
    }
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine());
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = Integer.parseInt(sc.nextLine());
    }
    sc.close();
    solve(n, a);
  }
}