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

using namespace std;

int n;

int a[200000+10],b[200000+10];

int mmax,mmax2,mmax_i,mmax2_i;

int main()

{

    cin>>n;

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

    {

        cin>>a[i];

        b[i]=a[i];

    }

    sort(b,b+n);

    mmax=b[n-1];

    mmax2=b[n-2];

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

    {

        if(a[i]==mmax)  cout<<mmax2<<endl;

        else    cout<<mmax<<endl;

    }

    return 0;

}

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

#include<algorithm>

using namespace std;

int main()

{

	int n;

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

	{

	int i,j;

	int a[200010],b[200010];

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

	   {

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

	    b[i]=a[i];

	   }

	sort(b,b+n);

	if(b[n-1]==b[n-2])

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

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

	else

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

	    {

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

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

	      else

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

	    }

    }

	return 0;

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

#include<algorithm>

using namespace std;

int n,a[200005],b[200005],o;

bool cmp(int x,int y){

	return x>y;

}

int main(){

	cin>>n;

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

		cin>>a[i];

		b[i]=a[i];

	}

	sort(b,b+n,cmp);

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

		if(a[i]<b[0]){

			cout<<b[0]<<endl;

		}

		else{

			cout<<b[1]<<endl;

		}

	}

}

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

#include<algorithm>

using namespace std;

int main()

{

	int n;

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

	{

	int i,j;

	int a[200010],b[200010];

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

	   {

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

	    b[i]=a[i];

	   }

	sort(b,b+n);

	if(b[n-1]==b[n-2])

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

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

	else

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

	    {

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

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

	      else

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

	    }

    }

	return 0;

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



using namespace std;



int main(){

    

    int x, arr[200005], max1 = 0, max2 = 0, imax=0;

    cin >> x;

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

        cin >> arr[i];

        if(arr[i]>max1){

            max1=arr[i];

            imax = i;

        }

    }

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

        if(arr[i]>max2 && imax!=i)

        max2=arr[i];

    }

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

        if(arr[i]==max1){

            cout << max2 << endl;

        }

        else{

            cout << max1 << endl;

        }

    }

    return 0;

}

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

#include<algorithm>

using namespace std;

int main()

{

	int n;

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

	{

	int i,j;

	int a[200010],b[200010];

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

	   {

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

	    b[i]=a[i];

	   }

	sort(b,b+n);

	if(b[n-1]==b[n-2])

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

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

	else

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

	    {

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

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

	      else

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

	    }

    }

	return 0;

}
// Slower C++ solution:
/*

 Shahadat Hossain

 I.C.T Department

 Comilla University

 Session: 2013-2014

 */



#include<iostream>

#include<map>

#include<queue>

#include<vector>

#include<string>

#include<cstring>



using namespace std;



int const N = 1e6 + 5;

int const MOD = 1e9 + 7;



int ar[N];

int l[N], r[N];



int main(){

    

    int n;

    cin >> n;

    

    int mx = 0;

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

        cin >> ar[i];

        mx = max(ar[i], mx);

        l[i] = mx;

    }

    

    mx = 0;

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

        mx = max(ar[i], mx);

        r[i] = mx;

    }

    

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

        cout << max(l[i - 1], r[i + 1]) << endl;

    }

    

}


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

#include<algorithm>

using namespace std;

int main()

{

	int n;

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

	{

	int i,j;

	int a[200010],b[200010];

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

	   {

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

	    b[i]=a[i];

	   }

	sort(b,b+n);

	if(b[n-1]==b[n-2])

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

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

	else

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

	    {

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

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

	      else

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

	    }

    }

	return 0;

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

#include<cstdio>

#include<algorithm>

using namespace std;



int main()

{

    int n,i,j,p,x;

    cin>>n;

    int a[n],b[n];



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

    {

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

        b[i] = a[i];

    }

    sort(a,a+n,greater<int>());

    p=a[0];x=a[1];

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

    {

        if(p== b[i]) printf("%d\n",x);

        else printf("%d\n",p);

    }





    return 0;

}


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

#include<algorithm>

using namespace std;

int main()

{

	int n;

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

	{

	int i,j;

	int a[200010],b[200010];

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

	   {

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

	    b[i]=a[i];

	   }

	sort(b,b+n);

	if(b[n-1]==b[n-2])

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

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

	else

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

	    {

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

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

	      else

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

	    }

    }

	return 0;

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

using namespace std;

int n;

int a[200000+10],b[200000+10];

int mmax,mmax2,mmax_i,mmax2_i;

int main()

{

    cin>>n;

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

    {

        cin>>a[i];

        b[i]=a[i];

    }

    sort(b,b+n);

    mmax=b[n-1];

    mmax2=b[n-2];

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

    {

        if(a[i]==mmax)  cout<<mmax2<<endl;

        else    cout<<mmax<<endl;

    }

    return 0;

}

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

#include<algorithm>

using namespace std;

int a[300008],b[2000008];

int main(){

    int n;

    scanf("%d",&n);

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

        scanf("%d",a+i),b[i]=a[i];

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

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

        if(a[i]==b[n]){

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

        }

        else

            printf("%d\n",b[n]);

    }

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

#include<algorithm>

using namespace std;

int n,a[200005],b[200005],o;

bool cmp(int x,int y){

	return x>y;

}

int main(){

	cin>>n;

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

		cin>>a[i];

		b[i]=a[i];

	}

	sort(b,b+n,cmp);

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

		if(a[i]<b[0]){

			cout<<b[0]<<endl;

		}

		else{

			cout<<b[1]<<endl;

		}

	}

}

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

#include<algorithm>

using namespace std;

int a[300008],b[2000008];

int main(){

    int n;

    scanf("%d",&n);

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

        scanf("%d",a+i),b[i]=a[i];

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

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

        if(a[i]==b[n]){

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

        }

        else

            printf("%d\n",b[n]);

    }

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



using namespace std;



int main(){

    

    int x, arr[200005], max1 = 0, max2 = 0, imax=0;

    cin >> x;

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

        cin >> arr[i];

        if(arr[i]>max1){

            max1=arr[i];

            imax = i;

        }

    }

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

        if(arr[i]>max2 && imax!=i)

        max2=arr[i];

    }

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

        if(arr[i]==max1){

            cout << max2 << endl;

        }

        else{

            cout << max1 << endl;

        }

    }

    return 0;

}

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

#include<algorithm>

using namespace std;

int a[300008],b[2000008];

int main(){

    int n;

    scanf("%d",&n);

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

        scanf("%d",a+i),b[i]=a[i];

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

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

        if(a[i]==b[n]){

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

        }

        else

            printf("%d\n",b[n]);

    }

}
// Slower C++ solution:
/*

 Shahadat Hossain

 I.C.T Department

 Comilla University

 Session: 2013-2014

 */



#include<iostream>

#include<map>

#include<queue>

#include<vector>

#include<string>

#include<cstring>



using namespace std;



int const N = 1e6 + 5;

int const MOD = 1e9 + 7;



int ar[N];

int l[N], r[N];



int main(){

    

    int n;

    cin >> n;

    

    int mx = 0;

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

        cin >> ar[i];

        mx = max(ar[i], mx);

        l[i] = mx;

    }

    

    mx = 0;

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

        mx = max(ar[i], mx);

        r[i] = mx;

    }

    

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

        cout << max(l[i - 1], r[i + 1]) << endl;

    }

    

}


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

#include<algorithm>

using namespace std;

int a[300008],b[2000008];

int main(){

    int n;

    scanf("%d",&n);

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

        scanf("%d",a+i),b[i]=a[i];

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

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

        if(a[i]==b[n]){

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

        }

        else

            printf("%d\n",b[n]);

    }

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

#include<cstdio>

#include<algorithm>

using namespace std;



int main()

{

    int n,i,j,p,x;

    cin>>n;

    int a[n],b[n];



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

    {

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

        b[i] = a[i];

    }

    sort(a,a+n,greater<int>());

    p=a[0];x=a[1];

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

    {

        if(p== b[i]) printf("%d\n",x);

        else printf("%d\n",p);

    }





    return 0;

}


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

#include<algorithm>

using namespace std;

int a[300008],b[2000008];

int main(){

    int n;

    scanf("%d",&n);

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

        scanf("%d",a+i),b[i]=a[i];

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

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

        if(a[i]==b[n]){

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

        }

        else

            printf("%d\n",b[n]);

    }

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

#include<algorithm>

using namespace std;

int main()

{

	int n;

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

	{

	int i,j;

	int a[200010],b[200010];

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

	   {

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

	    b[i]=a[i];

	   }

	sort(b,b+n);

	if(b[n-1]==b[n-2])

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

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

	else

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

	    {

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

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

	      else

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

	    }

    }

	return 0;

}

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

#include<algorithm>

using namespace std;

int a[300008],b[2000008];

int main(){

    int n;

    scanf("%d",&n);

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

        scanf("%d",a+i),b[i]=a[i];

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

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

        if(a[i]==b[n]){

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

        }

        else

            printf("%d\n",b[n]);

    }

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

using namespace std;

int n;

int a[200000+10],b[200000+10];

int mmax,mmax2,mmax_i,mmax2_i;

int main()

{

    cin>>n;

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

    {

        cin>>a[i];

        b[i]=a[i];

    }

    sort(b,b+n);

    mmax=b[n-1];

    mmax2=b[n-2];

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

    {

        if(a[i]==mmax)  cout<<mmax2<<endl;

        else    cout<<mmax<<endl;

    }

    return 0;

}

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

#define sz 200009

typedef long long ll;

int ar[sz],br[sz];

int i,j,n,r,max=0;

int main()

{

	

	scanf("%d",&n);

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

	{

		scanf("%d",&r);

		if (r>max) max=r;

		br[i]=r;

		ar[r]++;

	}

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

	{

		for (j=max; ; j-- )

		{

			if (ar[j]>0)

			{

				if (j==br[i]){

			if (br[i]==max && ar[max]==1) continue;}

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

	         break;

			}

		}

	}

	return 0;

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

#include<algorithm>

using namespace std;

int n,a[200005],b[200005],o;

bool cmp(int x,int y){

	return x>y;

}

int main(){

	cin>>n;

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

		cin>>a[i];

		b[i]=a[i];

	}

	sort(b,b+n,cmp);

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

		if(a[i]<b[0]){

			cout<<b[0]<<endl;

		}

		else{

			cout<<b[1]<<endl;

		}

	}

}

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

#define sz 200009

typedef long long ll;

int ar[sz],br[sz];

int i,j,n,r,max=0;

int main()

{

	

	scanf("%d",&n);

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

	{

		scanf("%d",&r);

		if (r>max) max=r;

		br[i]=r;

		ar[r]++;

	}

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

	{

		for (j=max; ; j-- )

		{

			if (ar[j]>0)

			{

				if (j==br[i]){

			if (br[i]==max && ar[max]==1) continue;}

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

	         break;

			}

		}

	}

	return 0;

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



using namespace std;



int main(){

    

    int x, arr[200005], max1 = 0, max2 = 0, imax=0;

    cin >> x;

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

        cin >> arr[i];

        if(arr[i]>max1){

            max1=arr[i];

            imax = i;

        }

    }

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

        if(arr[i]>max2 && imax!=i)

        max2=arr[i];

    }

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

        if(arr[i]==max1){

            cout << max2 << endl;

        }

        else{

            cout << max1 << endl;

        }

    }

    return 0;

}

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

#define sz 200009

typedef long long ll;

int ar[sz],br[sz];

int i,j,n,r,max=0;

int main()

{

	

	scanf("%d",&n);

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

	{

		scanf("%d",&r);

		if (r>max) max=r;

		br[i]=r;

		ar[r]++;

	}

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

	{

		for (j=max; ; j-- )

		{

			if (ar[j]>0)

			{

				if (j==br[i]){

			if (br[i]==max && ar[max]==1) continue;}

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

	         break;

			}

		}

	}

	return 0;

}
// Slower C++ solution:
/*

 Shahadat Hossain

 I.C.T Department

 Comilla University

 Session: 2013-2014

 */



#include<iostream>

#include<map>

#include<queue>

#include<vector>

#include<string>

#include<cstring>



using namespace std;



int const N = 1e6 + 5;

int const MOD = 1e9 + 7;



int ar[N];

int l[N], r[N];



int main(){

    

    int n;

    cin >> n;

    

    int mx = 0;

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

        cin >> ar[i];

        mx = max(ar[i], mx);

        l[i] = mx;

    }

    

    mx = 0;

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

        mx = max(ar[i], mx);

        r[i] = mx;

    }

    

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

        cout << max(l[i - 1], r[i + 1]) << endl;

    }

    

}


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

#define sz 200009

typedef long long ll;

int ar[sz],br[sz];

int i,j,n,r,max=0;

int main()

{

	

	scanf("%d",&n);

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

	{

		scanf("%d",&r);

		if (r>max) max=r;

		br[i]=r;

		ar[r]++;

	}

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

	{

		for (j=max; ; j-- )

		{

			if (ar[j]>0)

			{

				if (j==br[i]){

			if (br[i]==max && ar[max]==1) continue;}

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

	         break;

			}

		}

	}

	return 0;

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

#include<cstdio>

#include<algorithm>

using namespace std;



int main()

{

    int n,i,j,p,x;

    cin>>n;

    int a[n],b[n];



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

    {

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

        b[i] = a[i];

    }

    sort(a,a+n,greater<int>());

    p=a[0];x=a[1];

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

    {

        if(p== b[i]) printf("%d\n",x);

        else printf("%d\n",p);

    }





    return 0;

}


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

#define sz 200009

typedef long long ll;

int ar[sz],br[sz];

int i,j,n,r,max=0;

int main()

{

	

	scanf("%d",&n);

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

	{

		scanf("%d",&r);

		if (r>max) max=r;

		br[i]=r;

		ar[r]++;

	}

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

	{

		for (j=max; ; j-- )

		{

			if (ar[j]>0)

			{

				if (j==br[i]){

			if (br[i]==max && ar[max]==1) continue;}

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

	         break;

			}

		}

	}

	return 0;

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

#include<algorithm>

using namespace std;

int main()

{

	int n;

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

	{

	int i,j;

	int a[200010],b[200010];

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

	   {

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

	    b[i]=a[i];

	   }

	sort(b,b+n);

	if(b[n-1]==b[n-2])

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

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

	else

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

	    {

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

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

	      else

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

	    }

    }

	return 0;

}

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

#define sz 200009

typedef long long ll;

int ar[sz],br[sz];

int i,j,n,r,max=0;

int main()

{

	

	scanf("%d",&n);

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

	{

		scanf("%d",&r);

		if (r>max) max=r;

		br[i]=r;

		ar[r]++;

	}

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

	{

		for (j=max; ; j-- )

		{

			if (ar[j]>0)

			{

				if (j==br[i]){

			if (br[i]==max && ar[max]==1) continue;}

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

	         break;

			}

		}

	}

	return 0;

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



using namespace std;

const int N = 200005;

int arr[N];



int main() {

    //  freopen("in.txt", "rt", stdin);

    int n;

    scanf("%d", &n);

    multiset<int> st;

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

        scanf("%d", arr + i);

        st.insert(arr[i]);

    }

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

        st.erase(st.find(arr[i]));

        printf("%d\n", *st.rbegin());

        st.insert(arr[i]);

    }

}

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

#define sz 200009

typedef long long ll;

int ar[sz],br[sz];

int i,j,n,r,max=0;

int main()

{

	

	scanf("%d",&n);

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

	{

		scanf("%d",&r);

		if (r>max) max=r;

		br[i]=r;

		ar[r]++;

	}

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

	{

		for (j=max; ; j-- )

		{

			if (ar[j]>0)

			{

				if (j==br[i]){

			if (br[i]==max && ar[max]==1) continue;}

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

	         break;

			}

		}

	}

	return 0;

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



using namespace std;

#define ll long long

const int N=2e5+5;

int a[N];

bool ball[N];

int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);cout.tie(0);

    multiset<int>st;

    int n;

    cin>>n;

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

        cin>>a[i],st.insert(a[i]);

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

    {

       st.erase(st.find(a[i]));

       cout<<*st.rbegin()<<'\n';

       st.insert(a[i]);

    }

    return 0;

}


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

#define sz 200009

typedef long long ll;

int ar[sz],br[sz];

int i,j,n,r,max=0;

int main()

{

	

	scanf("%d",&n);

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

	{

		scanf("%d",&r);

		if (r>max) max=r;

		br[i]=r;

		ar[r]++;

	}

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

	{

		for (j=max; ; j-- )

		{

			if (ar[j]>0)

			{

				if (j==br[i]){

			if (br[i]==max && ar[max]==1) continue;}

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

	         break;

			}

		}

	}

	return 0;

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

using namespace std;



const int max_n = 2e5;



int main()

{

    int n;

    cin >> n;

    pair<int, int> a[max_n];

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

    {

        int x;

        cin >> x;

        a[i] = make_pair(x, i);

    }



    sort(a, a + n, greater<pair<int, int>>());

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

    {

        if(a[0].second == i)

        {

            cout << a[1].first << endl;

        } else

        {

            cout << a[0].first << endl;

        }

    }

}

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

using namespace std;

using ll = long long;

using pint = pair<int, int>;

ll N;

vector<ll> A;

vector<ll> B;

const ll INF = 1e12;



int main()

{

    cin >> N;

    A.resize(N);

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

        cin >> A[i];

    B = A;

    sort(B.begin(), B.end(), greater<ll>());

    for (ll a : A)

    {

        if (B[0] == a)

        {

            cout << B[1] << endl;

        }

        else

        {

            cout << B[0] << endl;

        }

    }

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

#define me(a,x) memset(a,x,sizeof(a))

#define sc scanf

#define itn int

using namespace std;

const int N=1e6;

const long long mod=1e9+7;

const int oo=0x7fffffff;

const int sup=0x80000000;

typedef long long ll;

typedef unsigned long long ull;

template <typename it>void db(it *begin,it *end){while(begin!=end)cout<<(*begin++)<<" ";puts("");}

template <typename it>

string to_str(it n){string s="";while(n)s+=n%10+'0',n/=10;reverse(s.begin(),s.end());return s;}

template <typename it>int o(it a){cout<<a<<endl;return 0;}

ll mul(ll a,ll b,ll c){ll ans=0;for(;b;b>>=1,a=(a+a)%c)if(b&1)ans=(ans+a)%c;return ans;}

ll ksm(ll a,ll b,ll c){ll ans=1;for(;b;b>>=1,a=mul(a,a,c))if(b&1)ans=mul(ans,a,c);return ans;}

int n;

int a[N];

int pre[N]={0},suf[N]={0};

int main(){

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

	cin>>n;

	for(itn i=1;i<=n;i++)cin>>a[i];

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

		pre[i]=max(pre[i-1],a[i]);

	}

	for(int i=n;i>=1;i--)suf[i]=max(suf[i+1],a[i]);

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

		o(max(pre[i-1],suf[i+1]));

	}

}

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

#include <cstdlib>

#include <algorithm>

using namespace std;

const int N=200010;

inline char get()

{

    static char buf[1024];

    static int pos=0,size=0;

    if(pos==size)

    {

        size=fread(buf,1,1024,stdin);

        pos=0;

        if(!size) return EOF;

        else return buf[pos++];

    }

    else return buf[pos++];     

}

int read()

{

    int sum=0,fh=1;

    char ch=get();

    while(!(ch>='0' && ch<='9'))

    {

        if(ch=='-') fh=-1;

        ch=get();

    }

    while(ch>='0' && ch<='9' && ch!=EOF) sum=sum*10+ch-48,ch=get();

    return sum*fh;

}

int n,d[N],ma[N][2];

int main()

{

	n=read();

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

	{

		d[i]=read();

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

	}

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

		ma[i][1]=max(ma[i+1][1],d[i]);

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

		printf("%d\n",max(ma[i-1][0],ma[i+1][1]));

	return 0;

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

#include <algorithm>

#include <iostream>

using namespace std;



const int N = 200003;



int n, a[N], b[N];

int maxx=-1, maxi;

signed main(void)

{

	cin >> n;

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

	{



	cin >> a[i];b[i]=a[i];

	if(maxx < a[i])

	{

		maxx = a[i];

		maxi=i;

	 } 

}

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

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

{

	if(i != maxi)printf("%d\n", b[n]);

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

}

	



	return 0;

}

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

#include <cstdlib>

#include <algorithm>

using namespace std;

const int N=200010;

inline char get()

{

    static char buf[1024];

    static int pos=0,size=0;

    if(pos==size)

    {

        size=fread(buf,1,1024,stdin);

        pos=0;

        if(!size) return EOF;

        else return buf[pos++];

    }

    else return buf[pos++];     

}

int read()

{

    int sum=0,fh=1;

    char ch=get();

    while(!(ch>='0' && ch<='9'))

    {

        if(ch=='-') fh=-1;

        ch=get();

    }

    while(ch>='0' && ch<='9' && ch!=EOF) sum=sum*10+ch-48,ch=get();

    return sum*fh;

}

int n,d[N],ma[N][2];

int main()

{

	n=read();

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

	{

		d[i]=read();

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

	}

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

		ma[i][1]=max(ma[i+1][1],d[i]);

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

		printf("%d\n",max(ma[i-1][0],ma[i+1][1]));

	return 0;

}