function Main(input) {
	tmp = input.split("\n");

	var length = parseInt(tmp.shift(), 10);
  var max = 0;
	var next_max = 0;
	var max_index = 0;
	var value = 0;

  for (var i = 0; i < tmp.length; i++) {
    // 1つ目に大きい数字と、2つ目に大きい数字を見つける
    value = parseInt(tmp[i], 10);

    if (max < value) {
      next_max = max;
      max = value;
      max_index = i;
    }
  }

  // 配列の長さ分だけ、1つ目に大きい数字を詰める
  var answer = "";
  for (var j = 0; j < length; i++) {
    if (j = max_index) {
      answer += (next_max + "\n");
    } else {
      answer += (max + "\n");
    }
  }
	console.log('%s', answer.slice(0, -2));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"