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

#include<algorithm>

#include<cstdlib>

#include<iostream>

using namespace std;

int n,ans=1,m[100066];

int main(){

	cin>>n;

	bool jia=false,jian=false,flag=false;

	for(int i=1;i<=n;i++)cin>>m[i];

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

		if(jia==false&&jian==false&&m[i]!=m[i+1]){

			if(m[i+1]>m[i])jia=true;

			else if(m[i+1]<m[i])jian=true;

		}

		if(i!=1) {

			if(m[i]==m[i-1])continue;

			else if(m[i]>m[i-1]){

				if(jia==false&&jian==true){

					ans++;jian=false;

				}

			}

			else if(m[i]<m[i-1]){

				if(jian==false&&jia==true){

					ans++;jia=false;

				}

			}

		}

		if(jia==false&&jian==false&&m[i]!=m[i+1]){

			if(m[i+1]>m[i])jia=true;

			else if(m[i+1]<m[i])jian=true;

		}

	}

	cout<<ans;

	return 0;

}

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

int n, a[100010];

int main() {

	scanf("%d", &n);

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

	int ans = 1, pre = a[1], how = 0;

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

		if (a[i] == pre) {

			continue ;

		}

		if (a[i] < pre) {

			if (how == 1) {

				++ ans;

				pre = a[i];

				how = 0;

			} else {

				how = -1;

				pre = a[i];

			}

		}

		if (a[i] > pre) {

			if (how == -1) {

				++ ans;

				pre = a[i];

				how = 0;

			} else {

				how = 1;

				pre = a[i];

			}

		}

	}

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

	return 0;

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

#include <cstring>

using namespace std;

int pd[100010],arr[100010];

int main()

{

    int n,m,ans=0,T=0;

    memset(pd,0,sizeof(pd));

    cin>>n;

    

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

    {

        cin>>arr[i];

    }



    T=arr[2]-arr[1];

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

        if(T==0)T=arr[i]-arr[i-1];

        if(1LL* T * (arr[i]-arr[i-1])<0){

            ans++;

            T=0;

        }

    }

    

    cout<<ans+1<<endl;

}

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

#include <ext/pb_ds/assoc_container.hpp> // Common file

#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#include <ext/pb_ds/detail/standard_policies.hpp>



using namespace std;

using namespace __gnu_pbds;



typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,

		tree_order_statistics_node_update> ordered_set;



#define el				'\n'

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

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

#define clr(v, d)		memset(v, d, sizeof(v))



double const EPS = 1e-8, PI = acos(-1);

const int N = 1e5 + 9, M = 1e5 + 9, OO = (int) 2e9 + 1;

const long long MOD = 1e9 + 7, INF = 1e18 + 9;



typedef long long ll;



void OUTPUT() {

	cout << fixed << setprecision(0);

	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

}



void INPUT() {

#ifndef ONLINE_JUDGE

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

//	freopen("output.txt", "w", stdout);

#endif

}



int n, arr[N];



int main() {

//	INPUT();

	OUTPUT();

	cin >> n;

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

		cin >> arr[i];

	}

	if (n < 3) {

		cout << 1;

		return 0;



	}



	ll ans = 1, incc = 0, decc = 0;

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

		if (arr[i] > arr[i + 1]) {

			if (decc) {

				decc = 0;

				ans++;

			} else {

				incc++;

			}

		} else if (arr[i] < arr[i + 1]) {

			if (incc) {

				incc = 0;

				ans++;

			} else {

				decc++;

			}

		}

	}

	cout << ans;

	return 0;



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

#include <cstring>

using namespace std;

int pd[100010],arr[100010];

int main()

{

    int n,m,ans=0,T=0;

    memset(pd,0,sizeof(pd));

    cin>>n;

    

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

    {

        cin>>arr[i];

    }



    T=arr[2]-arr[1];

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

        if(T==0)T=arr[i]-arr[i-1];

        if(1LL* T * (arr[i]-arr[i-1])<0){

            ans++;

            T=0;

        }

    }

    

    cout<<ans+1<<endl;

}

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

#define ll long long

using namespace std;



int main() {

      int N;

      cin >> N;

      ll A[N];



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

            cin >> A[i];

      }



      int count = 1;        // given N>=1, there will at least be 1 subarray

      int order = 0;        // 0 - reset (partition);     1 - ascending;       2 - descending



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

            if((order == 1 && A[i]<A[i-1]) || (order == 2 && A[i]>A[i-1])) {  // set partition

                  order = 0;

                  count++;

            }     

            else if(A[i] > A[i-1]) order = 1;

            else if(A[i] < A[i-1]) order = 2;

      }

      

      cout << count << endl;

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

#include <cstring>

using namespace std;

int pd[100010],arr[100010];

int main()

{

    int n,m,ans=0,T=0;

    memset(pd,0,sizeof(pd));

    cin>>n;

    

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

    {

        cin>>arr[i];

    }



    T=arr[2]-arr[1];

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

        if(T==0)T=arr[i]-arr[i-1];

        if(1LL* T * (arr[i]-arr[i-1])<0){

            ans++;

            T=0;

        }

    }

    

    cout<<ans+1<<endl;

}

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

# include <map>

using namespace std;



const int NEUTRAL = 0;

const int ASCENDING = -1;

const int DESCENDING = 1;



int main(){

  int N, numbers[100005];

  cin >> N;

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

    cin >> numbers[i];

  }

  

  int flag = NEUTRAL;

  int ans = 1;

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

    if((flag == ASCENDING && numbers[i] > numbers[i+1]) || 

       (flag == DESCENDING && numbers[i] < numbers[i+1])) {

          ans++;

          flag = NEUTRAL;

       }

    else if(numbers[i] < numbers[i+1]) flag = ASCENDING;

    else if(numbers[i] > numbers[i+1]) flag = DESCENDING;

  }

  

  cout << ans << endl;

  

  return 0;

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

#include <cstring>

using namespace std;

int pd[100010],arr[100010];

int main()

{

    int n,m,ans=0,T=0;

    memset(pd,0,sizeof(pd));

    cin>>n;

    

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

    {

        cin>>arr[i];

    }



    T=arr[2]-arr[1];

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

        if(T==0)T=arr[i]-arr[i-1];

        if(1LL* T * (arr[i]-arr[i-1])<0){

            ans++;

            T=0;

        }

    }

    

    cout<<ans+1<<endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.3856960385953685x):
/* Author : Aaryan Srivastava ^__^ */ 

#include <bits/stdc++.h>

#include <random>

#include <chrono>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp> 

#define pb push_back

#define mp make_pair

#define ff first

#define ss second   

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

#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)

#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)

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

#define rall(c) (c).rbegin(),(c).rend()

#define setval(a,val) memset(a,val,sizeof(a))

#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())

#define trav(x , a) for(auto &x : a)

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

typedef long long ll ; 



#define int ll



using namespace std;



const int N = 3e5 +5 ;

const int mod = 1e9 + 7 ;

const ll inf = 1e18 ;

const int SZ = 101 ;

const double eps = 1e-9 ;

using namespace __gnu_pbds;

using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;



typedef pair<int, int> pii; 

typedef pair<int , pii> ipii ;

typedef pair<pii , int> piii ; 

typedef unsigned long long ull ;

typedef long double ld;



ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}



void solve()

{

    int n ;

    cin >> n ;

    int a[n];

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

    int cur = 1 , g = 0;

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

        if(a[i] == a[i-1]) continue ;

        int ng = (a[i] > a[i-1] ? 1 : -1);

        if(g == 0) g = ng ;

        if(ng == g) continue ;

        else cur++ , g = 0 ;

    }

    cout << cur ;

}   



     

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

{

    ios::sync_with_stdio(0);    

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

    int TC = 1, t = 0;

    //cin >> TC ;

    while(t++ < TC)

    {

        //cout << "Case #" << t << ": " ;

        solve();

        cout << "\n" ;

    }

    return 0;

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

#include<cstdio>

#include<algorithm>

#include<cmath>

#include<cstring>

using namespace std;

struct node{

    int x,note=0x3f;//x代表数字，note表示状态，是上升还是下降

    //note=0，下降序列；note=1，上升序列；note=2，起点 或 起点后不明上下的点 

}a[100005]; //声明一个数组 

int main(){//主函数 

    int n,ans=1;//n个数，ans统计答案 

    cin>>n;//输入个数 

    for(int i=1;i<=n;i++){//挨个输入 

        cin>>a[i].x;//把数输入 

    }

    a[1].note=2;//第一个数必然是起点，打好状态标记 

    for(int i=2;i<=n;i++){//从第二个数开始找状态 

        if(a[i-1].note==0){//前一个数状态为0（下降） 

            if(a[i].x>a[i-1].x) a[i].note=2,ans++;//如果不下降了，这个数就是下一个序列的起点，序列数++ 

            else a[i].note=0;//下降，标记成0 

        }else if(a[i-1].note==1){//前一个数状态为1（上升） 

            if(a[i].x>=a[i-1].x) a[i].note=1;//继续上升，标记成1 

            else a[i].note=2,ans++;//不上升了，标记成起点，序列数++ 

        }else if(a[i-1].note==2){//是起点或起点后的不明点（统一当起点即可） 

            if(a[i].x<a[i-1].x) a[i].note=0;//比前一个数小，证明是下降序列，标为0 

            else if(a[i].x==a[i-1].x) a[i].note=2;//相等，这个点是不明上升/下降的点 

            else a[i].note=1;//上升，标成1 

        }

    }

    cout<<ans<<endl;//输出（换行） 

    return 0;

}

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

#include <cstdio>

using namespace std;

typedef long long ll;

ll x=0,n,last,sum=1;

inline void f(ll k){

	if(x==0){

		if(k>last)x=1;

		else if(k<last)x=2;

	}

	else{

		if(k>last&&x==2)sum++,x=0;

		else if(k<last&&x==1)sum++,x=0;

	}

}

int main(){

	register int i,j;

	scanf("%lld",&n);

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

		ll k;

		scanf("%lld",&k);

		if(i>1)f(k);

		last=k;

	}

	cout<<max(sum,(ll)1)<<endl;

	return 0;

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

using namespace std;



const int MAXN = 100005;



int A[MAXN];



int N, Ans;



int main() {

	ios::sync_with_stdio(false);



	cin >> N;

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

		cin >> A[i];



	{

		int i = 0;



		for(; i <= N;) {

			bool isu = true, isd = true;

			for(i += 2; i <= N; i++) {

				if(A[i-1] == A[i]) continue;

				if(A[i-1] < A[i]) {

					isd = false;

				} else {

					isu = false;

				}

				if(!isd && !isu) { i--; break; }

			}

			if(N < i) break;

			Ans++;

		}

	}



	cout << (Ans+1) << endl;

	return 0;

}

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

int a[121212];

int main() {

	int n, i, j, k, ans = 0; scanf("%d", &n);

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

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

		for (j = i + 1; j < n&&a[j - 1] <= a[j]; j++);

		for (k = i + 1; k < n&&a[k - 1] >= a[k]; k++);

		i = (j > k ? j : k);

		ans++;

	}

	printf("%d", ans);

	return 0;

}
// Slower C++ solution:
#include <iostream> // cin, cout, cerr

#include <algorithm> // minmax, sort, swap

#include <numeric> // iota

#include <cstdio> // printf, scanf

#include <string> // string, stoi, to_string

#include <vector> // vector

#include <queue> // queue, priority_queue

#include <deque> // deque

#include <map> // key-value pairs sorted by keys

#include <set> // set

#include <iomanip> // cout<<setprecision(n)

#include <functional> // function<void(int)>

#include <cmath>

#include <cassert>

#include <bitset>



#ifdef DEBUG

#include "debug.hpp"

#else

#define debug(...)

#endif



#define int long long // at least int64 > 9*10^18

#define EL '\n'

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

#define print(i) std::cout << (i) << '\n'

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

using Graph = std::vector<std::vector<int> >;

const int INF = 1e17;

/* libraries */



constexpr int MOD = 1e9+7;

struct mint

{

	int v;

	mint():v(0){}

	mint(int v):v((v+MOD)%MOD){}

	mint operator-()const{ return mint(0) - *this; }

	mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this; }

	mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this; }

	mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this; }

	mint& operator/=(const mint& a){ (*this) *= a.inv(); return *this; }

	mint operator+(const mint& a)const{ return mint(*this) += a; }

	mint operator-(const mint& a)const{ return mint(*this) -= a; }

	mint operator*(const mint& a)const{ return mint(*this) *= a; }

	mint operator/(const mint& a)const{ return mint(*this) /= a; }

	bool operator<(const mint& a)const{ return v < a.v; }

	bool operator==(const mint& a)const{ return v == a.v; }

	mint pow(int k)const{ mint r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }

	mint inv()const{ return pow(MOD-2); }

	static mint comb(int n, int k) {

		if(n-k<k) k=n-k;

		mint num(1), dom(1);

		for(int i=0;i<k;i++) { num*=n-i; dom*=i+1; }

		return num/dom;

	}

};

std::istream& operator>>(std::istream&i,mint&a){ int t; i>>t; a=mint(t); return i; }

std::ostream& operator<<(std::ostream&o,const mint&a){ o<<a.v; return o; }





signed main() {

	int n,k;

	std::cin >> n >> k;

	mint ans=0;

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

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

		ans+=x;

	}

	print(ans);

	return 0;

}


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

using namespace std;

typedef long long ll;

typedef string str;

typedef vector<ll> vel;

typedef vector<str> ves;

#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)

#define rep(i, b) REP(i, 0, b)

const ll cd = 1000000007;

const double pi = 3.14159265358979;



int main() {

  	constexpr ll MOD=1e9+7;

    ll N, K;

    cin >> N >> K;

    ll count = 0;

    vel sum(N + 2);

    sum[0] = 0;

    rep(i, N+1) {

        sum[i+1] = sum[i] + i;

    }

    REP(i, K, N+2) {

        ll max, min;

        max = sum[N+1] - sum[N+1-i];

        min = sum[i] - sum[0];

        count += (max - min + 1)%MOD;

      	count%=MOD;

    }

    cout << count << endl;

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

#define m 1000000007

int main()

{

    int n,k;

    scanf("%d%d",&n,&k);

    unsigned long long a[200003]={},i,j,s=0;

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

        a[i]=1+i*(n+1-i);

        a[i]=a[i]%m;

    }

    for(j=k;j<=n+1;j++) {

        s+=a[j];

    }

    printf("%llu\n",s%m);

    



    return 0;

}

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

#define ll long long 

using namespace std;

ll M=(ll)1e9+7;



ll sum(ll n){

	return n*(n+1LL)/2LL;

}



int main(){

	// freopen("Input.txt","r",stdin); freopen("Output.txt","w",stdout);

	ll n,k,ans=0;cin>>n>>k;

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

		ll l=sum(i-1);

		ll r=sum(n)-sum(n-i);

		ans+=(r-l+1);

	}

	ans++;

	ans=ans%M;

	cout<<ans<<"\n";

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

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

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

using namespace std;

const long long MOD = 1e9 + 7;

const long long INF = 1e12;

const int inf = 1e9;

typedef long long ll;

typedef pair<ll,int> P;

typedef set<int> S;

int main(){

    int n,k;

    cin>>n>>k;

    set<ll> sll;

    vector<ll> v(200010,0);

    rep(i,200010){

        v[i+1]=v[i]+i+1;

    }

    //ll left = MOD+1;

    //ll right = 0;

    ll ans = 0;

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

        ll ans1=0,ans2=0;

        ans1 = v[i-1];

        ans2 = v[n]-v[n-i];

        /*cout<<i<<endl;

        cout<<v[i-1]<<" "<<v[n]<<" "<<v[n-i]<<endl;

        cout<<ans1<<" "<<ans2<<endl;*/

        ans=(ans+ans2-ans1+1)%MOD;

        //cout<<ans<<endl<<endl;

    }

    cout<<ans+1<<endl;

    return 0;

}

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

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

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

using namespace std;

const long long MOD = 1e9 + 7;

const long long INF = 1e12;

const int inf = 1e9;

const int mod = 1e9+7;

typedef long long ll;

typedef pair<ll,int> P;

typedef set<int> S;

int main(){

	cout << fixed << setprecision(10);

	ll ans = 0;

	ll n,k;

	cin >> n >> k;

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

		ll left = i*(0+i-1)/2;

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

		ans += right - left + 1;

		ans %= mod;

	}

	cout << ans << endl;

	return 0;

}
// Slower C++ solution:
#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;

}

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

}
// Slower C++ solution:
#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;

}


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

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

// Faster C++ solution for the same problem (measured speedup: 4.951589019520203x):
#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);}
// 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.218143523707193x):
#include<stdio.h>

#include<algorithm>

using namespace std;

int a[200010];

int c[200010];

int main()

{

	int n,m,s,i,j;

	scanf("%d",&n);

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

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

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

		c[j]=a[j];

		sort(c,c+n);

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

	{

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

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

	    else 

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

	}

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

#include<algorithm>

using namespace std;

int a[200010];

int c[200010];

int main()

{

	int n,m,s,i,j;

	scanf("%d",&n);

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

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

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

		c[j]=a[j];

		sort(c,c+n);

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

	{

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

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

	    else 

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

	}

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

#include<algorithm>

using namespace std;

int a[200010];

int c[200010];

int main()

{

	int n,m,s,i,j;

	scanf("%d",&n);

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

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

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

		c[j]=a[j];

		sort(c,c+n);

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

	{

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

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

	    else 

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

	}

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

#include<algorithm>

using namespace std;

int a[200010];

int c[200010];

int main()

{

	int n,m,s,i,j;

	scanf("%d",&n);

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

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

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

		c[j]=a[j];

		sort(c,c+n);

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

	{

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

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

	    else 

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

	}

}
// 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: 4.34305240591104x):
#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;

}