// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { N: number, A: number[] } => {
  const N = +lines[0]
  const A = lines.slice(1, 1 + N).map(line => +line)
  const obj = { N, A }
  debug(obj)
  return obj
}

// solver
export const solve = (lines: string[]): string => {
  const { N, A } = parseLines(lines)
  const max = Math.max(...A)
  const maxRemoved = A.filter(num => num !== max)
  const semiMax = maxRemoved.length === 0 ? max : Math.max(...A.filter(num => num !== max))

  const answer = []
  for (let i = 0; i < N; i++) {
    if (A[i] === max) {
      answer.push(semiMax)
    } else {
      answer.push(max)
    }
  }
  return `${answer.join('\n')}`
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}
