stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

	int a,b,c,d,e;

	cin >> a;

	c = 0;

	d = 0;

	for (int i = 1; i <= a; i++) {

		cin >> b;

		if (b > c) {

			d = c;

			c = b;

			e = i;

		} else if (b > d) {

			d = b;

		}

	}

	for (int j = 1; j <= a; j++) {

		if (j == e) {

			cout << d << endl;

		} else {

			cout << c << endl;

		}

	}

}


// Faster C++ solution for the same problem (measured speedup: 4.3426144222571885x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int main()

{

	int n,m,t;

	int a[200005],b[200005];

	while(~scanf("%d",&n)){

		for(int i=0;i<n;i++)

		{

			scanf("%d",&a[i]);

			b[i]=a[i];

		}

		sort(a,a+n);

		for(int j=0;j<n;j++)

		{

			if(b[j]==a[n-1])

			m=j;

			if(a[n-2]==b[j])

			t=j;

		}

		for(int i=0;i<n;i++)

		{

			if(i!=m)

			printf("%d\n",a[n-1]);

			else

			printf("%d\n",a[n-2]);

		}

	}

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MAXN=2e5+5;

const ll MOD=1e9+7;

const ll MOD1=13;

ll n,a[MAXN],max1,max2;

void solve()

{

    for(ll i=1;i<=n;i++)

    {

        if(a[i]>=max1)

        {



            max2=max1;

            max1=a[i];

        }

        else if(a[i]>max2)

        {

            max2=a[i];

        }

    }

    for(ll i=1;i<=n;i++)

    {

        if(a[i]==max1)

        {

            printf("%lld\n",max2);

        }

        else

        {

            printf("%lld\n",max1);

        }

    }

}

int main()

{

    scanf("%lld",&n);

    for(ll i=1;i<=n;i++)

    {

        scanf("%lld",&a[i]);

    }

    solve();

}


// Faster C++ solution for the same problem (measured speedup: 4.291221861126675x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int main()

{

	int n,m,t;

	int a[200005],b[200005];

	while(~scanf("%d",&n)){

		for(int i=0;i<n;i++)

		{

			scanf("%d",&a[i]);

			b[i]=a[i];

		}

		sort(a,a+n);

		for(int j=0;j<n;j++)

		{

			if(b[j]==a[n-1])

			m=j;

			if(a[n-2]==b[j])

			t=j;

		}

		for(int i=0;i<n;i++)

		{

			if(i!=m)

			printf("%d\n",a[n-1]);

			else

			printf("%d\n",a[n-2]);

		}

	}

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define ll long long



using namespace std;



bool compare(int i,int j)

{

    return i>j;

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



    int T;

    cin>>T;

    int arr[T], v[T];

    for (int j=0;j<T;j++)

    {

        cin>>arr[j];

        v[j] = arr[j];

    }

    sort(v, v+T);

    for (int i=0;i<T;i++)

    {

        if (arr[i]==v[T-1])

            cout<<v[T-2];

        else

            cout<<v[T-1];

        cout<<'\n';

    }







    return 0;



}


// Faster C++ solution for the same problem (measured speedup: 4.402038396669137x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int main()

{

	int n,m,t;

	int a[200005],b[200005];

	while(~scanf("%d",&n)){

		for(int i=0;i<n;i++)

		{

			scanf("%d",&a[i]);

			b[i]=a[i];

		}

		sort(a,a+n);

		for(int j=0;j<n;j++)

		{

			if(b[j]==a[n-1])

			m=j;

			if(a[n-2]==b[j])

			t=j;

		}

		for(int i=0;i<n;i++)

		{

			if(i!=m)

			printf("%d\n",a[n-1]);

			else

			printf("%d\n",a[n-2]);

		}

	}

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>



using namespace std;



int A[200000+100];

int f[200000+100];

int d[200000+100];



int main()

{

    int n;



    cin>>n;



    for(int i=1;i<=n;i++)

        cin>>A[i];



    f[n] = A[n];

    for(int i=n-1;i>0;i--)

        f[i] = max(f[i+1],A[i]);



    d[1] = A[1];

    for(int i=2;i<=n;i++)

        d[i] = max(d[i-1],A[i]);

    d[0] = 0;

    f[n+1] = 0;

    for(int i=1;i<=n;i++)

        cout<<max(d[i-1],f[i+1])<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 5.22017001322145x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int main()

{

	int n;

	scanf("%d",&n);

	int a[n],b[n];

	for(int i=0;i<n;i++)

	{

		scanf("%d",&a[i]);

		b[i]=a[i];

	}

	sort(a,a+n);

	for(int i=0;i<n;i++)

	{

		if(b[i]<a[n-1])

		printf("%d\n",a[n-1]);

		if(b[i]==a[n-1])

		printf("%d\n",a[n-2]);

	}

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

	int a,b,c,d,e;

	cin >> a;

	c = 0;

	d = 0;

	for (int i = 1; i <= a; i++) {

		cin >> b;

		if (b > c) {

			d = c;

			c = b;

			e = i;

		} else if (b > d) {

			d = b;

		}

	}

	for (int j = 1; j <= a; j++) {

		if (j == e) {

			cout << d << endl;

		} else {

			cout << c << endl;

		}

	}

}


// Faster C++ solution for the same problem (measured speedup: 5.219643574918978x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int main()

{

	int n;

	scanf("%d",&n);

	int a[n],b[n];

	for(int i=0;i<n;i++)

	{

		scanf("%d",&a[i]);

		b[i]=a[i];

	}

	sort(a,a+n);

	for(int i=0;i<n;i++)

	{

		if(b[i]<a[n-1])

		printf("%d\n",a[n-1]);

		if(b[i]==a[n-1])

		printf("%d\n",a[n-2]);

	}

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MAXN=2e5+5;

const ll MOD=1e9+7;

const ll MOD1=13;

ll n,a[MAXN],max1,max2;

void solve()

{

    for(ll i=1;i<=n;i++)

    {

        if(a[i]>=max1)

        {



            max2=max1;

            max1=a[i];

        }

        else if(a[i]>max2)

        {

            max2=a[i];

        }

    }

    for(ll i=1;i<=n;i++)

    {

        if(a[i]==max1)

        {

            printf("%lld\n",max2);

        }

        else

        {

            printf("%lld\n",max1);

        }

    }

}

int main()

{

    scanf("%lld",&n);

    for(ll i=1;i<=n;i++)

    {

        scanf("%lld",&a[i]);

    }

    solve();

}


// Faster C++ solution for the same problem (measured speedup: 5.157871834345223x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int main()

{

	int n;

	scanf("%d",&n);

	int a[n],b[n];

	for(int i=0;i<n;i++)

	{

		scanf("%d",&a[i]);

		b[i]=a[i];

	}

	sort(a,a+n);

	for(int i=0;i<n;i++)

	{

		if(b[i]<a[n-1])

		printf("%d\n",a[n-1]);

		if(b[i]==a[n-1])

		printf("%d\n",a[n-2]);

	}

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define ll long long



using namespace std;



bool compare(int i,int j)

{

    return i>j;

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



    int T;

    cin>>T;

    int arr[T], v[T];

    for (int j=0;j<T;j++)

    {

        cin>>arr[j];

        v[j] = arr[j];

    }

    sort(v, v+T);

    for (int i=0;i<T;i++)

    {

        if (arr[i]==v[T-1])

            cout<<v[T-2];

        else

            cout<<v[T-1];

        cout<<'\n';

    }







    return 0;



}


// Faster C++ solution for the same problem (measured speedup: 5.2910687432797125x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int main()

{

	int n;

	scanf("%d",&n);

	int a[n],b[n];

	for(int i=0;i<n;i++)

	{

		scanf("%d",&a[i]);

		b[i]=a[i];

	}

	sort(a,a+n);

	for(int i=0;i<n;i++)

	{

		if(b[i]<a[n-1])

		printf("%d\n",a[n-1]);

		if(b[i]==a[n-1])

		printf("%d\n",a[n-2]);

	}

	return 0;

}
// Slower C++ solution:
#include<stdio.h>

#include<algorithm>

using namespace std;

int main()

{

	int n,m,t;

	int a[200005],b[200005];

	while(~scanf("%d",&n)){

		for(int i=0;i<n;i++)

		{

			scanf("%d",&a[i]);

			b[i]=a[i];

		}

		sort(a,a+n);

		for(int j=0;j<n;j++)

		{

			if(b[j]==a[n-1])

			m=j;

			if(a[n-2]==b[j])

			t=j;

		}

		for(int i=0;i<n;i++)

		{

			if(i!=m)

			printf("%d\n",a[n-1]);

			else

			printf("%d\n",a[n-2]);

		}

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2019587896560087x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int main()

{

	int n;

	scanf("%d",&n);

	int a[n],b[n];

	for(int i=0;i<n;i++)

	{

		scanf("%d",&a[i]);

		b[i]=a[i];

	}

	sort(a,a+n);

	for(int i=0;i<n;i++)

	{

		if(b[i]<a[n-1])

		printf("%d\n",a[n-1]);

		if(b[i]==a[n-1])

		printf("%d\n",a[n-2]);

	}

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>



using namespace std;



int A[200000+100];

int f[200000+100];

int d[200000+100];



int main()

{

    int n;



    cin>>n;



    for(int i=1;i<=n;i++)

        cin>>A[i];



    f[n] = A[n];

    for(int i=n-1;i>0;i--)

        f[i] = max(f[i+1],A[i]);



    d[1] = A[1];

    for(int i=2;i<=n;i++)

        d[i] = max(d[i-1],A[i]);

    d[0] = 0;

    f[n+1] = 0;

    for(int i=1;i<=n;i++)

        cout<<max(d[i-1],f[i+1])<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 5.214619011922979x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int a[2000005];

int b[2000005];

int main()

{

	long long n;

	scanf("%lld",&n);

	for(int i=0;i<n;i++){

		scanf("%d",&a[i]);

		b[i]=a[i];

		}

		

		sort(a,a+n);

		

		for(int i=0;i<n;i++){

			if(b[i]!=a[n-1]){

				printf("%d\n",a[n-1]);

			}

			else{

				printf("%d\n",a[n-2]);

			}

		}

		

		return 0;

	

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

	int a,b,c,d,e;

	cin >> a;

	c = 0;

	d = 0;

	for (int i = 1; i <= a; i++) {

		cin >> b;

		if (b > c) {

			d = c;

			c = b;

			e = i;

		} else if (b > d) {

			d = b;

		}

	}

	for (int j = 1; j <= a; j++) {

		if (j == e) {

			cout << d << endl;

		} else {

			cout << c << endl;

		}

	}

}


// Faster C++ solution for the same problem (measured speedup: 5.21409313342214x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int a[2000005];

int b[2000005];

int main()

{

	long long n;

	scanf("%lld",&n);

	for(int i=0;i<n;i++){

		scanf("%d",&a[i]);

		b[i]=a[i];

		}

		

		sort(a,a+n);

		

		for(int i=0;i<n;i++){

			if(b[i]!=a[n-1]){

				printf("%d\n",a[n-1]);

			}

			else{

				printf("%d\n",a[n-2]);

			}

		}

		

		return 0;

	

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MAXN=2e5+5;

const ll MOD=1e9+7;

const ll MOD1=13;

ll n,a[MAXN],max1,max2;

void solve()

{

    for(ll i=1;i<=n;i++)

    {

        if(a[i]>=max1)

        {



            max2=max1;

            max1=a[i];

        }

        else if(a[i]>max2)

        {

            max2=a[i];

        }

    }

    for(ll i=1;i<=n;i++)

    {

        if(a[i]==max1)

        {

            printf("%lld\n",max2);

        }

        else

        {

            printf("%lld\n",max1);

        }

    }

}

int main()

{

    scanf("%lld",&n);

    for(ll i=1;i<=n;i++)

    {

        scanf("%lld",&a[i]);

    }

    solve();

}


// Faster C++ solution for the same problem (measured speedup: 5.152387079408644x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int a[2000005];

int b[2000005];

int main()

{

	long long n;

	scanf("%lld",&n);

	for(int i=0;i<n;i++){

		scanf("%d",&a[i]);

		b[i]=a[i];

		}

		

		sort(a,a+n);

		

		for(int i=0;i<n;i++){

			if(b[i]!=a[n-1]){

				printf("%d\n",a[n-1]);

			}

			else{

				printf("%d\n",a[n-2]);

			}

		}

		

		return 0;

	

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define ll long long



using namespace std;



bool compare(int i,int j)

{

    return i>j;

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



    int T;

    cin>>T;

    int arr[T], v[T];

    for (int j=0;j<T;j++)

    {

        cin>>arr[j];

        v[j] = arr[j];

    }

    sort(v, v+T);

    for (int i=0;i<T;i++)

    {

        if (arr[i]==v[T-1])

            cout<<v[T-2];

        else

            cout<<v[T-1];

        cout<<'\n';

    }







    return 0;



}


// Faster C++ solution for the same problem (measured speedup: 5.285442350003276x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int a[2000005];

int b[2000005];

int main()

{

	long long n;

	scanf("%lld",&n);

	for(int i=0;i<n;i++){

		scanf("%d",&a[i]);

		b[i]=a[i];

		}

		

		sort(a,a+n);

		

		for(int i=0;i<n;i++){

			if(b[i]!=a[n-1]){

				printf("%d\n",a[n-1]);

			}

			else{

				printf("%d\n",a[n-2]);

			}

		}

		

		return 0;

	

}
// Slower C++ solution:
#include<stdio.h>

#include<algorithm>

using namespace std;

int main()

{

	int n,m,t;

	int a[200005],b[200005];

	while(~scanf("%d",&n)){

		for(int i=0;i<n;i++)

		{

			scanf("%d",&a[i]);

			b[i]=a[i];

		}

		sort(a,a+n);

		for(int j=0;j<n;j++)

		{

			if(b[j]==a[n-1])

			m=j;

			if(a[n-2]==b[j])

			t=j;

		}

		for(int i=0;i<n;i++)

		{

			if(i!=m)

			printf("%d\n",a[n-1]);

			else

			printf("%d\n",a[n-2]);

		}

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2006806560348449x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int a[2000005];

int b[2000005];

int main()

{

	long long n;

	scanf("%lld",&n);

	for(int i=0;i<n;i++){

		scanf("%d",&a[i]);

		b[i]=a[i];

		}

		

		sort(a,a+n);

		

		for(int i=0;i<n;i++){

			if(b[i]!=a[n-1]){

				printf("%d\n",a[n-1]);

			}

			else{

				printf("%d\n",a[n-2]);

			}

		}

		

		return 0;

	

}
// Slower C++ solution:
#include<stdio.h>

#include<algorithm>

#include<string.h>

#include<queue>

using namespace std;

int main()

{

	int n;

	while(~scanf("%d",&n))

	{

		int z[200005]={0},y[200005]={0};

		int max=0;

		int s[20000];

 		int j=0;

 		int p=0;

		for(int i=0;i<n;i++)

		{

			scanf("%d",&z[i]);

			y[i]=z[i];

		}

		sort(z,z+n);

		for(int i=0;i<n;i++)

		{

			if(y[i]==z[n-1])

			printf("%d\n",z[n-2]);

			else

			printf("%d\n",z[n-1]);

		}

	}

}


// Faster C++ solution for the same problem (measured speedup: 9.449514673297982x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int a[2000005];

int b[2000005];

int main()

{

	long long n;

	scanf("%lld",&n);

	for(int i=0;i<n;i++){

		scanf("%d",&a[i]);

		b[i]=a[i];

		}

		

		sort(a,a+n);

		

		for(int i=0;i<n;i++){

			if(b[i]!=a[n-1]){

				printf("%d\n",a[n-1]);

			}

			else{

				printf("%d\n",a[n-2]);

			}

		}

		

		return 0;

	

}
// Slower C++ solution:
#include<stdio.h>

#include<algorithm>

#include<string.h>

#include<queue>

using namespace std;

int main()

{

	int n;

	while(~scanf("%d",&n))

	{

		int z[200005]={0},y[200005]={0};

		int max=0;

		int s[20000];

 		int j=0;

 		int p=0;

		for(int i=0;i<n;i++)

		{

			scanf("%d",&z[i]);

			y[i]=z[i];

		}

		sort(z,z+n);

		for(int i=0;i<n;i++)

		{

			if(y[i]==z[n-1])

			printf("%d\n",z[n-2]);

			else

			printf("%d\n",z[n-1]);

		}

	}

}


// Faster C++ solution for the same problem (measured speedup: 1.8054180279392882x):
#include <iostream>

#include <vector>

#include <map>

#include <iterator>



using namespace std;



int N, A;

vector<int> values;

map<int,int> numbers;

map<int,int>::iterator mayorA, mayorS;



int main()

{

  cin >> N;

  while(N--)

  {

    cin >> A;

    values.push_back(A);

    numbers[A]++;

  }

  mayorA = numbers.end();

  mayorA--;

  mayorS = mayorA;

  if(numbers.size()>1){mayorS--;}

  if((*mayorA).second > 1) { for(int v : values) {cout << (*mayorA).first << '\n';}}

  else 

  {

    for(int v : values)

    {

      if(v != (*mayorA).first) { cout << (*mayorA).first << '\n';}

      else { cout << (*mayorS).first << '\n';}

    }

  }

  return 0;

}
// Slower C++ solution:
#include<stdio.h>

#include<algorithm>

#include<string.h>

#include<queue>

using namespace std;

int main()

{

	int n;

	while(~scanf("%d",&n))

	{

		int z[200005]={0},y[200005]={0};

		int max=0;

		int s[20000];

 		int j=0;

 		int p=0;

		for(int i=0;i<n;i++)

		{

			scanf("%d",&z[i]);

			y[i]=z[i];

		}

		sort(z,z+n);

		for(int i=0;i<n;i++)

		{

			if(y[i]==z[n-1])

			printf("%d\n",z[n-2]);

			else

			printf("%d\n",z[n-1]);

		}

	}

}


// Faster C++ solution for the same problem (measured speedup: 1.7943787156485003x):
#include <bits/stdc++.h>

using namespace std;



int main() {

	long long max=0,max2=0,n,a;

	vector<int> v;

	cin>>n;

	for (int i=0;i<n;i++){

		cin>>a;

		if (a>max){

			max2=max;

			max=a;}

		else if (a>max2)

		  max2=a;

		v.push_back(a);}

	

	for (int i=0;i<n;i++){

		if (v[i]!=max)

		cout<<max<<endl;

		else

		cout<<max2<<endl;

	}

  return 0;

}
// Slower C++ solution:
#include<stdio.h>

#include<algorithm>

#include<string.h>

#include<queue>

using namespace std;

int main()

{

	int n;

	while(~scanf("%d",&n))

	{

		int z[200005]={0},y[200005]={0};

		int max=0;

		int s[20000];

 		int j=0;

 		int p=0;

		for(int i=0;i<n;i++)

		{

			scanf("%d",&z[i]);

			y[i]=z[i];

		}

		sort(z,z+n);

		for(int i=0;i<n;i++)

		{

			if(y[i]==z[n-1])

			printf("%d\n",z[n-2]);

			else

			printf("%d\n",z[n-1]);

		}

	}

}


// Faster C++ solution for the same problem (measured speedup: 1.8110032700824477x):
#include <iostream>

#include <sstream>

#include <vector>

#include <utility>

#include <map>

#include <algorithm>

#include <string>

#include <string.h>

#include <iomanip>

#include <cmath>

#define ll long long

#define PI 3.14159265358979323846

#define lp(i, n) for (int i = 0; i < n; i++)

#define rep(i, v) for (int i = 0; i < int(v.size()); i++)

using namespace std;

int main()

{

	int n;

	cin>>n;

	int arr[n],tmp[n];

	lp(i,n){

		cin>>arr[i];

		tmp[i]=arr[i];

	}

	sort(tmp,tmp+n);

	reverse(tmp,tmp+n);

	lp(i,n)

	{

		if(arr[i]==tmp[0])

			cout<<tmp[1];

		else

			cout<<tmp[0];

		cout<<endl;

	}

	return 0;

}
// Slower C++ solution:
#include<stdio.h>

#include<algorithm>

#include<string.h>

#include<queue>

using namespace std;

int main()

{

	int n;

	while(~scanf("%d",&n))

	{

		int z[200005]={0},y[200005]={0};

		int max=0;

		int s[20000];

 		int j=0;

 		int p=0;

		for(int i=0;i<n;i++)

		{

			scanf("%d",&z[i]);

			y[i]=z[i];

		}

		sort(z,z+n);

		for(int i=0;i<n;i++)

		{

			if(y[i]==z[n-1])

			printf("%d\n",z[n-2]);

			else

			printf("%d\n",z[n-1]);

		}

	}

}


// Faster C++ solution for the same problem (measured speedup: 1.7710923217244785x):
#include <bits/stdc++.h>

using namespace std;

#define endl              "\n"

#define pb              push_back

#define fir               first

#define sec               second

#define all(v)            ((v).begin()), ((v).end())

#define sz(v)            ((int)((v).size()))

#define ll              long long

#define ld              long double

#define lp(i, n)        for(int i = 0 ; (int)i<n ; i++)

#define loop(i, x, n)       for(int i=x ; (int)i<=n ; i++)

#define isPowerOfTwo(s) (!(s & (s-1)))

typedef vector<int> vi;

typedef deque<int> de;

void origi() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr), cout.tie(nullptr);

}

//vector<pair<int, pair<int , pair<int, int>>>>vec;

void tiranga() {

    int n;

    cin >> n;

    vector<int>orig;

    vector<int>arr;

    lp(i, n) {

        int x;

        cin >> x;

        orig.pb(x);

        arr.pb(x);

    }

    sort(arr.begin() , arr.end());

    int Max = arr[n - 1], pre = arr[n - 2];

    lp(i, n) {

        if (orig[i] == Max)

            cout << pre << endl;

        else

            cout << Max << endl;

    }

}

int main() {

#ifndef ONLINE_JUDGE.

    //freopen("input.txt", "r", stdin);

#else

#endif

    

    origi();

    tiranga();

    //cout << sumOfDig(123654);

   // genLarge(10, 10);

   // genSmall(10);



}
// Slower C++ solution:
#include<stdio.h>

#include<algorithm>

#include<string.h>

#include<queue>

using namespace std;

int main()

{

	int n;

	while(~scanf("%d",&n))

	{

		int z[200005]={0},y[200005]={0};

		int max=0;

		int s[20000];

 		int j=0;

 		int p=0;

		for(int i=0;i<n;i++)

		{

			scanf("%d",&z[i]);

			y[i]=z[i];

		}

		sort(z,z+n);

		for(int i=0;i<n;i++)

		{

			if(y[i]==z[n-1])

			printf("%d\n",z[n-2]);

			else

			printf("%d\n",z[n-1]);

		}

	}

}


// Faster C++ solution for the same problem (measured speedup: 1.8160501581520327x):
#include<bits/stdc++.h>

using namespace std;

int main () {

int N,i,j,maxint,index,maxint2;

vector<int> A;

cin>>N ;

A.reserve(N);

for(i=0;i<N;i++)

    { cin>>A[i];}



maxint=0;



for( j=0 ;j<N;j++) {

if (maxint<A[j] ) {

    maxint =A[j];

     index =j;

 }

}

maxint2=0;

for( j=0 ;j<N;j++){

        if ((maxint2<A[j] )&&(j!=index)){

                maxint2=A[j];}

    }

for( j=0 ;j<N;j++){if(j!=index){printf("%d\n",maxint);}

else {printf("%d\n",maxint2); }

}



}
// Slower C++ solution:
#include<stdio.h>

#include<algorithm>

#include<string.h>

#include<queue>

using namespace std;

int main()

{

	int n;

	while(~scanf("%d",&n))

	{

		int z[200005]={0},y[200005]={0};

		int max=0;

		int s[20000];

 		int j=0;

 		int p=0;

		for(int i=0;i<n;i++)

		{

			scanf("%d",&z[i]);

			y[i]=z[i];

		}

		sort(z,z+n);

		for(int i=0;i<n;i++)

		{

			if(y[i]==z[n-1])

			printf("%d\n",z[n-2]);

			else

			printf("%d\n",z[n-1]);

		}

	}

}


// Faster C++ solution for the same problem (measured speedup: 1.7721404565344492x):
#include <bits/stdc++.h>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)

#define REPR(i, n) for(int i = (int)(n); i > 0; i--)

#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); i++)

#define INF 2e9

#define ALL(v) (v).begin(), (v).end()

template <typename Iter> std::string join(Iter begin, Iter end, std::string const& separator){ std::ostringstream result; if (begin != end){ result << *begin++; }; while (begin != end){ result << separator << *begin++; }; return result.str(); }

using namespace std;

typedef long long ll;

void solve() {

  ll n;

  cin >> n;

  vector<ll> a(n);

  REP(i, n) {

    cin >> a[i];

  }

  ll first = *max_element(ALL(a));

  if(count(ALL(a), first) > 1) {

    REP(i, n) {

      cout << first << endl;

    }

  } else {

    ll second = min(a[0], a[1]);

    for(auto x: a) {

      if(x == first) continue;

      if(x > second) second = x;

    }

    for(auto x: a) {

      if(x == first) {

        cout << second << endl;

      } else {

        cout << first << endl;

      }

    }

  }

}

int main() {

  cin.tie(0);

  ios::sync_with_stdio(false);

  solve();

  return 0;

}
// Slower C++ solution:
#include<stdio.h>

#include<algorithm>

#include<string.h>

#include<queue>

using namespace std;

int main()

{

	int n;

	while(~scanf("%d",&n))

	{

		int z[200005]={0},y[200005]={0};

		int max=0;

		int s[20000];

 		int j=0;

 		int p=0;

		for(int i=0;i<n;i++)

		{

			scanf("%d",&z[i]);

			y[i]=z[i];

		}

		sort(z,z+n);

		for(int i=0;i<n;i++)

		{

			if(y[i]==z[n-1])

			printf("%d\n",z[n-2]);

			else

			printf("%d\n",z[n-1]);

		}

	}

}


// Faster C++ solution for the same problem (measured speedup: 1.8122055523238159x):
#include <bits/stdc++.h>

using namespace std;

 

#define ll long long

#define setp setprecision

#define fix fixed

#define db double

#define pb push_back

int main() {

	int n;

	cin>>n;

	int c[n+1];

	int p[n+1],s[n+2];

	p[0]=-1;

	s[n+1]=-1;

	for (int i=1;i<=n;i++) {

		cin>>c[i];

	}

	for (int i=1,j=n;i<=n;i++,j--) {

		p[i]=max(p[i-1],c[i]);

		s[j]=max(s[j+1],c[j]);

	}

	for (int i=1;i<=n;i++) {

		cout<<max(s[i+1],p[i-1])<<endl;

	}

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>



using namespace std;

const int maxn = 200000 + 10;



int a[maxn], b[maxn];

int n;



int main(int argc, char *argv[])

{

    cin >> n;

    for (int i = 0; i < n; ++i)

    {

        cin >> a[i];

        b[i] = a[i];

    }

    sort(a, a + n);

    

    for (int i = 0; i < n; ++i)

    {

        if (b[i] == a[n - 1])

        {

            cout << a[n - 2] << endl;

        }

        else

        {

            cout << a[n - 1] << endl;

        }

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.3480559347711285x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int main()

{

    int n,a[220000],i,acm,b[220000];

    while(~scanf("%d",&n))

    {

        acm=0;

        int sun=0;

        for(i=1;i<=n;i++)

        {

            scanf("%d",&a[i]);

            b[i]=a[i];

        }

        sort(b+1,b+n+1);

        acm=b[n];

        sun=b[n-1];

        for(i=1;i<=n;i++)

        {

            if(a[i]<acm)

                printf("%d\n",acm);

            else

                printf("%d\n",sun);

        }

    }

    return 0;

}