import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner (System.in);

    while (in.hasNext()) {
      int N = in.nextInt();
      int[] A = new int[N];
      int max = 0;
      int maxIdx = -1;

      for (int i = 0; i < A.length; ++i) {
        A[i] = in.nextInt();

        if (A[i] > max) {
          max = A[i];
          maxIdx = i;
        }
      }

      int sndMax = 0;      
      int sndMaxIdx = -1;
      for (int i = 0; i < A.length; ++i) {
        if (A[i] > sndMax && i != maxIdx) {
          sndMax = A[i];
          sndMaxIdx = i;
        }
      }

      for (int i = 0; i < A.length; ++i) {
        if (i != maxIdx) {
          System.out.println(max);
        } else {
          System.out.println(sndMax);
        }
      }
    }
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner (System.in);

    while (in.hasNext()) {
      int N = in.nextInt();
      int[] A = new int[N];
      int max = 0;
      int maxIdx = -1;

      for (int i = 0; i < A.length; ++i) {
        A[i] = in.nextInt();

        if (A[i] > max) {
          max = A[i];
          maxIdx = i;
        }
      }

      int sndMax = 0;      
      int sndMaxIdx = -1;
      for (int i = 0; i < A.length; ++i) {
        if (A[i] > sndMax && i != maxIdx) {
          sndMax = A[i];
          sndMaxIdx = i;
        }
      }

      for (int i = 0; i < A.length; ++i) {
        if (i != maxIdx) {
          System.out.println(max);
        } else {
          System.out.println(sndMax);
        }
      }
    }
  }
} Main public static void main (String[] args) {
    Scanner in = new Scanner (System.in);

    while (in.hasNext()) {
      int N = in.nextInt();
      int[] A = new int[N];
      int max = 0;
      int maxIdx = -1;

      for (int i = 0; i < A.length; ++i) {
        A[i] = in.nextInt();

        if (A[i] > max) {
          max = A[i];
          maxIdx = i;
        }
      }

      int sndMax = 0;      
      int sndMaxIdx = -1;
      for (int i = 0; i < A.length; ++i) {
        if (A[i] > sndMax && i != maxIdx) {
          sndMax = A[i];
          sndMaxIdx = i;
        }
      }

      for (int i = 0; i < A.length; ++i) {
        if (i != maxIdx) {
          System.out.println(max);
        } else {
          System.out.println(sndMax);
        }
      }
    }
  } main {
    Scanner in = new Scanner (System.in);

    while (in.hasNext()) {
      int N = in.nextInt();
      int[] A = new int[N];
      int max = 0;
      int maxIdx = -1;

      for (int i = 0; i < A.length; ++i) {
        A[i] = in.nextInt();

        if (A[i] > max) {
          max = A[i];
          maxIdx = i;
        }
      }

      int sndMax = 0;      
      int sndMaxIdx = -1;
      for (int i = 0; i < A.length; ++i) {
        if (A[i] > sndMax && i != maxIdx) {
          sndMax = A[i];
          sndMaxIdx = i;
        }
      }

      for (int i = 0; i < A.length; ++i) {
        if (i != maxIdx) {
          System.out.println(max);
        } else {
          System.out.println(sndMax);
        }
      }
    }
  } Scanner in = new Scanner (System.in); in new Scanner (System.in) while (in.hasNext()) {
      int N = in.nextInt();
      int[] A = new int[N];
      int max = 0;
      int maxIdx = -1;

      for (int i = 0; i < A.length; ++i) {
        A[i] = in.nextInt();

        if (A[i] > max) {
          max = A[i];
          maxIdx = i;
        }
      }

      int sndMax = 0;      
      int sndMaxIdx = -1;
      for (int i = 0; i < A.length; ++i) {
        if (A[i] > sndMax && i != maxIdx) {
          sndMax = A[i];
          sndMaxIdx = i;
        }
      }

      for (int i = 0; i < A.length; ++i) {
        if (i != maxIdx) {
          System.out.println(max);
        } else {
          System.out.println(sndMax);
        }
      }
    } in.hasNext() in.hasNext in {
      int N = in.nextInt();
      int[] A = new int[N];
      int max = 0;
      int maxIdx = -1;

      for (int i = 0; i < A.length; ++i) {
        A[i] = in.nextInt();

        if (A[i] > max) {
          max = A[i];
          maxIdx = i;
        }
      }

      int sndMax = 0;      
      int sndMaxIdx = -1;
      for (int i = 0; i < A.length; ++i) {
        if (A[i] > sndMax && i != maxIdx) {
          sndMax = A[i];
          sndMaxIdx = i;
        }
      }

      for (int i = 0; i < A.length; ++i) {
        if (i != maxIdx) {
          System.out.println(max);
        } else {
          System.out.println(sndMax);
        }
      }
    } int N = in.nextInt(); N in.nextInt() in.nextInt in int[] A = new int[N]; A new int[N] N int max = 0; max 0 int maxIdx = -1; maxIdx -1 1 for (int i = 0; i < A.length; ++i) {
        A[i] = in.nextInt();

        if (A[i] > max) {
          max = A[i];
          maxIdx = i;
        }
      } int i = 0; int i = 0; i 0 i < A.length i A.length A A.length ++i ++i i {
        A[i] = in.nextInt();

        if (A[i] > max) {
          max = A[i];
          maxIdx = i;
        }
      } {
        A[i] = in.nextInt();

        if (A[i] > max) {
          max = A[i];
          maxIdx = i;
        }
      } A[i] = in.nextInt() A[i] A i in.nextInt() in.nextInt in if (A[i] > max) {
          max = A[i];
          maxIdx = i;
        } A[i] > max A[i] A i max {
          max = A[i];
          maxIdx = i;
        } max = A[i] max A[i] A i maxIdx = i maxIdx i int sndMax = 0; sndMax 0 int sndMaxIdx = -1; sndMaxIdx -1 1 for (int i = 0; i < A.length; ++i) {
        if (A[i] > sndMax && i != maxIdx) {
          sndMax = A[i];
          sndMaxIdx = i;
        }
      } int i = 0; int i = 0; i 0 i < A.length i A.length A A.length ++i ++i i {
        if (A[i] > sndMax && i != maxIdx) {
          sndMax = A[i];
          sndMaxIdx = i;
        }
      } {
        if (A[i] > sndMax && i != maxIdx) {
          sndMax = A[i];
          sndMaxIdx = i;
        }
      } if (A[i] > sndMax && i != maxIdx) {
          sndMax = A[i];
          sndMaxIdx = i;
        } A[i] > sndMax && i != maxIdx A[i] > sndMax A[i] A i sndMax i != maxIdx i maxIdx {
          sndMax = A[i];
          sndMaxIdx = i;
        } sndMax = A[i] sndMax A[i] A i sndMaxIdx = i sndMaxIdx i for (int i = 0; i < A.length; ++i) {
        if (i != maxIdx) {
          System.out.println(max);
        } else {
          System.out.println(sndMax);
        }
      } int i = 0; int i = 0; i 0 i < A.length i A.length A A.length ++i ++i i {
        if (i != maxIdx) {
          System.out.println(max);
        } else {
          System.out.println(sndMax);
        }
      } {
        if (i != maxIdx) {
          System.out.println(max);
        } else {
          System.out.println(sndMax);
        }
      } if (i != maxIdx) {
          System.out.println(max);
        } else {
          System.out.println(sndMax);
        } i != maxIdx i maxIdx {
          System.out.println(max);
        } System.out.println(max) System.out.println System.out System System.out max {
          System.out.println(sndMax);
        } System.out.println(sndMax) System.out.println System.out System System.out sndMax String[] args args public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner (System.in);

    while (in.hasNext()) {
      int N = in.nextInt();
      int[] A = new int[N];
      int max = 0;
      int maxIdx = -1;

      for (int i = 0; i < A.length; ++i) {
        A[i] = in.nextInt();

        if (A[i] > max) {
          max = A[i];
          maxIdx = i;
        }
      }

      int sndMax = 0;      
      int sndMaxIdx = -1;
      for (int i = 0; i < A.length; ++i) {
        if (A[i] > sndMax && i != maxIdx) {
          sndMax = A[i];
          sndMaxIdx = i;
        }
      }

      for (int i = 0; i < A.length; ++i) {
        if (i != maxIdx) {
          System.out.println(max);
        } else {
          System.out.println(sndMax);
        }
      }
    }
  }
} public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner (System.in);

    while (in.hasNext()) {
      int N = in.nextInt();
      int[] A = new int[N];
      int max = 0;
      int maxIdx = -1;

      for (int i = 0; i < A.length; ++i) {
        A[i] = in.nextInt();

        if (A[i] > max) {
          max = A[i];
          maxIdx = i;
        }
      }

      int sndMax = 0;      
      int sndMaxIdx = -1;
      for (int i = 0; i < A.length; ++i) {
        if (A[i] > sndMax && i != maxIdx) {
          sndMax = A[i];
          sndMaxIdx = i;
        }
      }

      for (int i = 0; i < A.length; ++i) {
        if (i != maxIdx) {
          System.out.println(max);
        } else {
          System.out.println(sndMax);
        }
      }
    }
  }
} Main
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner (System.in);

    while (in.hasNext()) {
      int N = in.nextInt();
      int[] A = new int[N];
      int max = 0;
      int maxIdx = -1;

      for (int i = 0; i < A.length; ++i) {
        A[i] = in.nextInt();

        if (A[i] > max) {
          max = A[i];
          maxIdx = i;
        }
      }

      int sndMax = 0;      
      int sndMaxIdx = -1;
      for (int i = 0; i < A.length; ++i) {
        if (A[i] > sndMax && i != maxIdx) {
          sndMax = A[i];
          sndMaxIdx = i;
        }
      }

      for (int i = 0; i < A.length; ++i) {
        if (i != maxIdx) {
          System.out.println(max);
        } else {
          System.out.println(sndMax);
        }
      }
    }
  }
}