stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

#define pb push_back

#define pf push_front

#define ff first

#define ss second

#define vll vector<ll>

#define pll pair<ll, ll>

#define vpll vector<pll>

#define endl "\n"

const ll maxn = 2*(1e5 + 5);

const ll mod = 1e9+7;



int main()

{

    ll i, j, k, t, n, m, a[maxn], maxi, mini, c=0;



    cin>>n>>k;



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

    {

        c+=i;

        a[i]=c;

    }

    ll ans=0;

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

    {

        maxi = a[n]-a[n-i];

        mini = a[i-1];



        ans+= (maxi-mini+1)%mod;

        ans%=mod;

    }

    cout<<(ans+1)%mod<<endl;





    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

#define pb push_back

#define pf push_front

#define ff first

#define ss second

#define vll vector<ll>

#define pll pair<ll, ll>

#define vpll vector<pll>

#define endl "\n"

const ll maxn = 2*(1e5 + 5);

const ll mod = 1e9+7;



int main()

{

    ll i, j=0, k=0, t, n, m, a=0, maxi, mini;



    cin>>n>>k;

    t=(((n+1)*n)%mod)/2;



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

    {

        maxi = (n*(n+1))/2 - ((n-i+1)*(n-i))/2;

        mini = (i*(i-1))/2;



        a+=(maxi-mini+1)%mod;

    }

    cout<<(a+1)%mod<<endl;

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

using namespace std;

long N,K;

const long mod=1e9+7;

main()

{

	cin>>N>>K;

	long ans=0;

	for(long k=K;k<=N+1;k++)

	{

		long L=k*(k-1)/2,R=N*k-k*(k-1)/2;

		ans+=(R-L+1)%mod;

	}

	cout<<ans%mod<<endl;

}


// Optimized solution to the same problem (faster):
#import<ios>

long n,k,a;main(){for(scanf("%d%d",&n,&k);k<n+2;)a+=1-(k+~n)*k++;printf("%d",a%=n=1e9+7);}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#import<iostream>

long n,k,a;main(){for(std::cin>>n>>k;k<n+2;k++)a+=1-k*(k+~n);std::cout<<a%(n=1e9+7);}

// Optimized solution to the same problem (faster):
#import<ios>

long n,k,a;main(){for(scanf("%d%d",&n,&k);k<n+2;)a+=1-(k+~n)*k++;printf("%d",a%=n=1e9+7);}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#import<iostream>

long n,k,a;main(){for(std::cin>>n>>k;k<n+2;)a+=1-(k+~n)*k++;std::cout<<a%(n=1e9+7);}

// Optimized solution to the same problem (faster):
#import<ios>

long n,k,a;main(){for(scanf("%d%d",&n,&k);k<n+2;)a+=1-(k+~n)*k++;printf("%d",a%=n=1e9+7);}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

		}

	}

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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();

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;



}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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]);

		}

	}

}


// Optimized solution to the same problem (faster):
#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;

	

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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]);

	}

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

	}

}

// Optimized solution to the same problem (faster):
#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]);

	}

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

	}

}

// Optimized solution to the same problem (faster):
#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++;

}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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++;

}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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++;

}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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();

}

// Optimized solution to the same problem (faster):
#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++;

}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

		}

	}

}

// Optimized solution to the same problem (faster):
#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++;

}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

	}

}

// Optimized solution to the same problem (faster):
#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++;

}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}




// Optimized solution to the same problem (faster):
#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++;

}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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';

}

// Optimized solution to the same problem (faster):
#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]));

    }

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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]);

    }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

		}

	}

}

// Optimized solution to the same problem (faster):
#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]);

    }

}


// Fastest known solution for this problem: