stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <algorithm>

using namespace std;

int a[200001]; 

int b[200001];

int main(){

	int n;

	cin>>n;

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

		cin>>a[i];

		b[i]=a[i];

	}

	sort(b,b+n);

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

		if(b[n-1]!=a[i])cout<<b[n-1]<<endl;

		else cout<<b[n-2]<<endl;

	}

}

// Faster C++ solution for the same problem (measured speedup: 4.34582043198687x):
#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;

}
// 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.3509327146668975x):
#include <stdio.h>

#include <algorithm>

using namespace std;

int main()

{int n,i,j,a[200100],b[200100];

scanf("%d",&n);

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

    {

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

    b[i]=a[i];}

    sort(a,a+n);

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

    if(b[j]!=a[n-1])printf("%d\n",a[n-1]);

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





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

#include <algorithm>

using namespace std;

int a[200001]; 

int b[200001];

int main(){

	int n;

	cin>>n;

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

		cin>>a[i];

		b[i]=a[i];

	}

	sort(b,b+n);

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

		if(b[n-1]!=a[i])cout<<b[n-1]<<endl;

		else cout<<b[n-2]<<endl;

	}

}

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

#include <algorithm>

using namespace std;

int main()

{int n,i,j,a[200100],b[200100];

scanf("%d",&n);

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

    {

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

    b[i]=a[i];}

    sort(a,a+n);

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

    if(b[j]!=a[n-1])printf("%d\n",a[n-1]);

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





}
// 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.352457036785552x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int main()

{

	int n,d,b[200005],a[200005],i;

	scanf("%d",&n);

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

	{

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

	b[i]=a[i];

	}

	sort(b,b+n);

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

	{if(a[i]!=b[n-1])printf("%d\n",b[n-1]);

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

	}

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

#include <algorithm>

using namespace std;

int a[200001]; 

int b[200001];

int main(){

	int n;

	cin>>n;

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

		cin>>a[i];

		b[i]=a[i];

	}

	sort(b,b+n);

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

		if(b[n-1]!=a[i])cout<<b[n-1]<<endl;

		else cout<<b[n-2]<<endl;

	}

}

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

#include<algorithm>

using namespace std;

int main()

{

	int n,d,b[200005],a[200005],i;

	scanf("%d",&n);

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

	{

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

	b[i]=a[i];

	}

	sort(b,b+n);

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

	{if(a[i]!=b[n-1])printf("%d\n",b[n-1]);

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

	}

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

using namespace std;



int main()

{

	const int MaxVal = 2000000;

	int n = 0;

	int A[MaxVal] = { 0 };

	cin >> n;

	int maxTemp =0;

	int nextTemp = 0;

	int topIndex = 0;

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

		cin >> A[i];

		if (maxTemp < A[i]) {

			nextTemp = maxTemp;

			maxTemp = A[i];

			topIndex = i;

		} else {

			if (nextTemp < A[i]) {

				nextTemp = A[i];

			}

		}

	}

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

		if (i == topIndex) {

			cout << nextTemp << endl;

		} else {

			cout << maxTemp << endl;

		}

	}



	return 0;

}

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

using namespace std;



int main()

{

	int n = 0;

	cin >> n;

	int maxTemp =0;

	int nextTemp = 0;

	int topIndex = 0;

	int temp = 0;

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

		cin >> temp;

		if (maxTemp < temp) {

			nextTemp = maxTemp;

			maxTemp = temp;

			topIndex = i;

		} else {

			if (nextTemp < temp) {

				nextTemp = temp;

			}

		}

	}

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

		if (i == topIndex) {

			cout << nextTemp << endl;

		} else {

			cout << maxTemp << endl;

		}

	}



	return 0;

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

using namespace std;

const int N=200001;

int n,d[N],maxn1=-1,maxid1=-1,maxn2=-1,maxid2=-1;

int main()

{

	scanf("%d",&n);

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

	{

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

		if(d[i]>maxn1)

		{

			maxn2=maxn1;

			maxid2=maxid1;

			maxn1=d[i];

			maxid1=i;

		}

		if(d[i]<maxn1 && d[i]>maxn2)

		{

			maxn2=d[i];

			maxid2=i;

		}

		if(d[i]==maxn1 && i!=maxid1)

		{

			maxn2=d[i];

			maxid2=i;

		}

	}

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

	{

		if(i!=maxid1)

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

		else

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

	}

	return 0;

}

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

#define N 200010

using namespace std;



int n, a[N], max1, max2, p;



int main() {

	scanf("%d", &n);

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

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

		if (a[i] >= max1)

			max2 = max1, max1 = a[i], p = i;

		else if (a[i] > max2)

			max2 = a[i];

	}

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

		printf("%d\n", i == p ? max2 : max1);

	return 0;

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

using namespace std;

const int N=200001;

int n,d[N],maxn1=-1,maxid1=-1,maxn2=-1,maxid2=-1;

int main()

{

	scanf("%d",&n);

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

	{

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

		if(d[i]>maxn1)

		{

			maxn2=maxn1;

			maxid2=maxid1;

			maxn1=d[i];

			maxid1=i;

		}

		if(d[i]<maxn1 && d[i]>maxn2)

		{

			maxn2=d[i];

			maxid2=i;

		}

		if(d[i]==maxn1 && i!=maxid1)

		{

			maxn2=d[i];

			maxid2=i;

		}

	}

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

	{

		if(i!=maxid1)

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

		else

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

	}

	return 0;

}

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

#include<cstring>

#include<algorithm>

using namespace std;

int main(){

	int a,b,c,d,e,i,j,l=1,max=0;

	int n[200005];

	int m[200005];

scanf("%d",&a);

e=a;c=a;

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

{

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

m[i]=n[i];	

}

sort(m+1,m+1+a);

l=1;

while(e--)

{

	if(m[a]==n[l])

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

	else

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

	l++;

}

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

using namespace std;

vector<int>mp;

vector<int>mps;

int arr[1000001];

int main(){

	int n;

	cin>>n;

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

		int a;

		cin>>a;

		mp.push_back(a);

		mps.push_back(a);

		arr[a]++;

	}

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

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

		int c=mps[mps.size()-1];

		if (mp[x]==c){

			if (arr[c]==1){

				cout<<mps[mps.size()-2]<<endl;

			}

			else cout<<c<<endl;

		}

		else cout<<c<<endl;

	}

}

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

#include<cstring>

#include<algorithm>

using namespace std;

int main(){

	int a,b,c,d,e,i,j,l=1,max=0;

	int n[200005];

	int m[200005];

scanf("%d",&a);

e=a;c=a;

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

{

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

m[i]=n[i];	

}

sort(m+1,m+1+a);

l=1;

while(e--)

{

	if(m[a]==n[l])

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

	else

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

	l++;

}

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

using namespace std;

#define int long long



signed main()

{

  int N; cin>>N;

  vector<int> a(N);

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

    cin>>a[i];

  }



  vector<int> L(N+1),R(N+1);

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

    L[i+1]=max(L[i],a[i]);

  }

  for(int i=N-1;i>=0;i--){

    R[i]=max(R[i+1],a[i]);

  }



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

    cout<<max(L[i],R[i+1])<<endl;

  }



  return 0;

}

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

#include<cstring>

#include<algorithm>

using namespace std;

int main(){

	int a,b,c,d,e,i,j,l=1,max=0;

	int n[200005];

	int m[200005];

scanf("%d",&a);

e=a;c=a;

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

{

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

m[i]=n[i];	

}

sort(m+1,m+1+a);

l=1;

while(e--)

{

	if(m[a]==n[l])

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

	else

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

	l++;

}

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

#include <algorithm>

using namespace std;

int n;

int a[200002],b[200002];



bool cmp(int x,int y){

	return x>y;

}



int main(){

	long long ans=0;

	cin>>n;

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

		cin>>a[i];

		b[i]=a[i];

	}

	sort(a,a+n,cmp);

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

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

			cout<<a[1]<<endl;

		}

		else cout<<a[0]<<endl;

	}

	return 0;

}

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

#include<cstring>

#include<algorithm>

using namespace std;

int main(){

	int a,b,c,d,e,i,j,l=1,max=0;

	int n[200005];

	int m[200005];

scanf("%d",&a);

e=a;c=a;

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

{

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

m[i]=n[i];	

}

sort(m+1,m+1+a);

l=1;

while(e--)

{

	if(m[a]==n[l])

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

	else

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

	l++;

}

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



#define lp(i,a,b) for(int i=a;i<b;i++)

#define ll long long

#define ff first

#define ss second



using namespace std;



void maxes(){

    int sMax = 0;

    int Max = 0;

    int iMax = -1;

    int n;

    cin >> n;

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

        int a;

        cin >> a;

        if (a >= Max){

            sMax = Max;

            Max = a;

            iMax = i;

        }

        else if (a > sMax)

            sMax = a;

    }

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

        cout << (i == iMax ? sMax : Max) << endl;

    }

}



int main() {

    maxes();

}

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

#include<cstring>

#include<algorithm>

using namespace std;

int main(){

	int a,b,c,d,e,i,j,l=1,max=0;

	int n[200005];

	int m[200005];

scanf("%d",&a);

e=a;c=a;

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

{

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

m[i]=n[i];	

}

sort(m+1,m+1+a);

l=1;

while(e--)

{

	if(m[a]==n[l])

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

	else

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

	l++;

}

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

using namespace std;



int n, x, max1, max2, a;



int main() {

	cin >> n;

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

		cin >> x;

		if (x>max1) {

			max2=max1;

			max1=x;

			a=i;

		}

		else {

			if (x>max2) {

				max2=x;

			}

		}

	}

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

		if (j==a) {

			cout << max2 << endl;

		}

		else {

			cout << max1 << endl;

		}

	}

}

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

#include<cstring>

#include<algorithm>

using namespace std;

int main(){

	int a,b,c,d,e,i,j,l=1,max=0;

	int n[200005];

	int m[200005];

scanf("%d",&a);

e=a;c=a;

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

{

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

m[i]=n[i];	

}

sort(m+1,m+1+a);

l=1;

while(e--)

{

	if(m[a]==n[l])

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

	else

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

	l++;

}

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

using namespace std;



int arr[1000001];

int c=0,terA,terB;



void swap(int &a,int &b) {

	int t=a;

	a=b;

	b=t;

}



void cek(int x) {

	if(c==0) {

		c++;

		terA=x;

		return;

	} else if(c==1) {

		c++;

		terB=x;

		if(terB>terA) swap(terA,terB);

		return;

	} else {

		if(x>terB) {

			terB=x;

			if(terB>terA) {

				swap(terA,terB);

			}

		}

	}

}



int main() {

	int a;

	cin>>a;

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

		cin>>arr[i];

		cek(arr[i]);

	}

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

		if(arr[i]!=terA) cout<<terA;

		else cout<<terB;

		cout<<endl;

	}

}

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

#include<cstring>

#include<algorithm>

using namespace std;

int main(){

	int a,b,c,d,e,i,j,l=1,max=0;

	int n[200005];

	int m[200005];

scanf("%d",&a);

e=a;c=a;

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

{

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

m[i]=n[i];	

}

sort(m+1,m+1+a);

l=1;

while(e--)

{

	if(m[a]==n[l])

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

	else

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

	l++;

}

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

using namespace std;

int C[1000000];

int main ()

{

    int n,d;

    cin >> n;

    int ans[n+10];

    pair<int,int> a[n+10];

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

            cin >> a[i].first;

            C[a[i].first]++;

            a[i].second=i;

    }

    sort(a,a+n);

    int mx = a[n-1].first;

    if(C[mx]>1)

    {

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

            cout<<mx<<"\n";

        }

        return 0;

    }

    int mx2 = a[n-2].first;

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

        if(a[i].first!=mx)

        ans[a[i].second]=mx;

        if(a[i].first==mx)

        ans[a[i].second]=mx2;

    }

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

            cout<<ans[i]<<"\n";

        }

    return 0;

}




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

#include<cstring>

#include<algorithm>

using namespace std;

int main(){

	int a,b,c,d,e,i,j,l=1,max=0;

	int n[200005];

	int m[200005];

scanf("%d",&a);

e=a;c=a;

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

{

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

m[i]=n[i];	

}

sort(m+1,m+1+a);

l=1;

while(e--)

{

	if(m[a]==n[l])

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

	else

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

	l++;

}

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



using namespace std;

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

#define vi vector<int>



int main(){

  int n; cin >> n;

  vi a(n); rep(i, n) cin >> a[i];



  //a[0], a[1], a[2]

  vi lm(n);// lm[i]; iより左にある者たちの中でのmax。 便宜上 lm[0]=0 としておく

  vi rm(n);// rm[i]; iより右にある者たちの中でのmax。 便宜上 rm[n-1] = 0

  // 求める値は max(lm[i],rm[i]) (i = 0,1,2,...,n-1) の最大値



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

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



  rep(i, n) cout << max(lm[i], rm[i]) << '\n';

}

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



int max(int a,int b){return a>b?a:b;}



int n;

int a[200050];



int main()

{

    scanf("%d",&n);

    for(int i=0;i<n;i++)scanf("%d",&a[i]);



    int left[200050];

    int right[200050];

    

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

    {

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

    }

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

    {

        right[i]=max(right[i+1],a[i+1]);

    }



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

    {

        printf("%d\n",max(left[i],right[i]));

    }

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

#define FOR(i, a, b) for (int i = a; i < b; i++)

#define mFOR(i, a, b) for (int i = a; i > b; i--)

#define MP make_pair

#define PB push_back

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

#define N 200007

#define INF 1000000007

using namespace std;



typedef long long ll;



ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }

int main()

{

   int n, a[N] = {}, mx1 = 0, mx2 = 0, ctr1 = 0, ctr2 = 0;

   cin >> n;

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

      cin >> a[i];



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

   {

      if (a[i] >= mx1)

      {

         mx2 = mx1;

         mx1 = a[i];

      }

      else if (a[i] >= mx2)

         mx2 = a[i];

   }

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

   {

      if (a[i] != mx1)

         cout << mx1 << endl;

      else

         cout << mx2 << endl;

   }

   return 0;

}


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

#define FOR(i, a, b) for (int i = a; i < b; i++)

#define mFOR(i, a, b) for (int i = a; i > b; i--)

#define MP make_pair

#define PB push_back

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

#define N 200007

#define INF 1000000007

using namespace std;



typedef long long ll;



ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }

int main()

{

   int n;

   cin >> n;

   vector<int> a(n + 2, 0), l(n + 2, 0), r(n + 2, 0);

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

      cin >> a[i];

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

   {

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

      r[n - i + 1] = max(a[n - i + 1], r[n - i + 2]);

   }

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

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

   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.211413292883288x):
#include <algorithm>

#include <cstdio>

using namespace std;

int n;

struct node{

	int sum,rank;

}	pool[200005];

bool cmp1(const node &a,const node &b){

	return a.sum<b.sum;

}

bool cmp2(const node &a,const node &b){

	return a.rank<b.rank;

}

int main(){

	scanf("%d",&n);

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

		int t;

		scanf("%d",&t);

		pool[i].rank=i;

		pool[i].sum=t;

	}

	sort(pool+1,pool+1+n,cmp1);

	int book=pool[n].rank,maxx=pool[n-1].sum;

	sort(pool+1,pool+1+n,cmp2);

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

		if(i!=book)	printf("%d\n",pool[book].sum);

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

	}

	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.219817010128422x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int cmp(int a,int b)

{

	return a>b;

}

int aa[200090];

int bb[200090];

main()

{

	int n,i;

	scanf("%d",&n);

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

	{

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

		bb[i]=aa[i];

	}

	sort(bb+1,bb+n+1,cmp);

	int m=1;

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

	{

		if(aa[i]!=bb[1])

		{

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

		}

		else

		{

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

		}

	}

	

}
// 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.220592642923298x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int cmp(int a,int b)

{

	return a>b;

}

int aa[200090];

int bb[200090];

main()

{

	int n,i;

	scanf("%d",&n);

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

	{

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

		bb[i]=aa[i];

	}

	sort(bb+1,bb+n+1,cmp);

	int m=1;

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

	{

		if(aa[i]!=bb[1])

		{

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

		}

		else

		{

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

		}

	}

	

}
// 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.297655584037902x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int cmp(int a,int b)

{

	return a>b;

}

int aa[200090];

int bb[200090];

main()

{

	int n,i;

	scanf("%d",&n);

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

	{

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

		bb[i]=aa[i];

	}

	sort(bb+1,bb+n+1,cmp);

	int m=1;

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

	{

		if(aa[i]!=bb[1])

		{

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

		}

		else

		{

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

		}

	}

	

}
// 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.2162099778150335x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int cmp(int a,int b)

{

	return a>b;

}

int aa[200090];

int bb[200090];

main()

{

	int n,i;

	scanf("%d",&n);

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

	{

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

		bb[i]=aa[i];

	}

	sort(bb+1,bb+n+1,cmp);

	int m=1;

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

	{

		if(aa[i]!=bb[1])

		{

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

		}

		else

		{

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

		}

	}

	

}
// 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.218775116385981x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int cmp(int a,int b)

{

	return a>b;

}

int aa[200090];

int bb[200090];

main()

{

	int n,i;

	scanf("%d",&n);

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

	{

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

		bb[i]=aa[i];

	}

	sort(bb+1,bb+n+1,cmp);

	int m=1;

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

	{

		if(aa[i]!=bb[1])

		{

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

		}

		else

		{

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

		}

	}

	

}