#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int *x = new int [n];
for ( int i = 0; i < n; i++ ) cin >> x [i];
int min = 100;
int max = -100;
for ( int i = 0; i < n; i++ ) {
if ( x [i] > max ) max = x [i];
if ( x [i] < min ) min = x [i];
}
for ( int i = 0; i < n; i++ ) {
if ( x [i] == max ) x [i] = min;
else if ( x [i] == min ) x [i] = max;
}
for ( int i = 0; i < n; i++ ) cout << x [i] << " ";
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCmludCBtYWluKCkgewoJaW50IG47CgljaW4gPj4gbjsKCWludCAqeCA9IG5ldyBpbnQgW25dOwoJZm9yICggaW50IGkgPSAwOyBpIDwgbjsgaSsrICkgY2luID4+IHggW2ldOwoJaW50IG1pbiA9IDEwMDsKCWludCBtYXggPSAtMTAwOwoJZm9yICggaW50IGkgPSAwOyBpIDwgbjsgaSsrICkgewoJCWlmICggeCBbaV0gPiBtYXggKSBtYXggPSB4IFtpXTsKCQlpZiAoIHggW2ldIDwgbWluICkgbWluID0geCBbaV07Cgl9Cglmb3IgKCBpbnQgaSA9IDA7IGkgPCBuOyBpKysgKSB7CgkJaWYgKCB4IFtpXSA9PSBtYXggKSB4IFtpXSA9IG1pbjsKCQllbHNlIGlmICggeCBbaV0gPT0gbWluICkgeCBbaV0gPSBtYXg7Cgl9Cglmb3IgKCBpbnQgaSA9IDA7IGkgPCBuOyBpKysgKSBjb3V0IDw8IHggW2ldIDw8ICIgIjsKCXJldHVybiAwOwp9