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

#include <iostream>

#include <cmath>

#include <cstring>

#include <sstream>

#include <algorithm>

#include <cstdlib>

#include <map>

#include <queue>

#include <utility>

#include <vector>

#include <set>

#include <memory.h>

#include <iomanip>

#include <bitset>

#include <list>

#include <stack>

#include <deque>

#include <numeric>

#include <complex>



using namespace std;



#define mod 1000000007



int main()

{

	int n;

	cin >> n;

	int a[100001] = {};

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

		cin >> a[i];

	}

	sort(a, a + n);



	if(n == 2){

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

		cout << a[1] << " " << a[0] << endl;

		return 0;

	}



	long long int suma[100001] = {};

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

		suma[i] = suma[i - 1] + a[i - 1];

	}

	long long int ans = -mod;

	int max_i = 0;

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

		long long int tmp = (suma[n] - suma[i]) - suma[i];

		if(tmp > ans){

			ans = tmp;

			max_i = i;

		}

	}

	// cout << max_i << endl;

	// 0 ... max_i - 1 まではマイナス

	// max_i, ... , n - 1 はプラス

	cout << ans << endl;

	if(max_i == n - 1){

		long long int now = a[n - 1];

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

			cout << now << " " << a[i] << endl;

			now -= a[i];

		}

		return 0;

	}

	cout << a[0] << " " << a[max_i] << endl;

	long long int now = a[0] - a[max_i];

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

		cout << now << " " << a[i] << endl;

		now -= a[i];

	}

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

	now = a[n - 1] - now;

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

		cout << now << " " << a[i] << endl;

		now -= a[i];

	}



}

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



#include <algorithm>

#include <bitset>

#include <cmath>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <deque>

#include <iomanip>

#include <iostream>

#include <list>

#include <map>

#include <numeric>

#include <queue>

#include <set>

#include <sstream>

#include <stack>

#include <utility>

#include <vector>



using namespace std;



#define MOD 1000000007

#define INIT -1



int main() {

	int n;

	cin >> n;

	int a[100000];

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

		cin >> a[i];

	}

	sort(a, a + n);

	int suma[100010] = {};

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

		suma[i] = suma[i - 1] + a[i - 1];

	}

	int ans = -MOD;

	int idx = -1;

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

		int tmp = suma[n] - suma[i] - suma[i];

		if (tmp > ans) {

			ans = tmp;

			idx = i;

		}

	}

	cout << ans << endl;

	int now = a[idx - 1];

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

		cout << now << " " << a[i] << endl;

		now -= a[i];

	}

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

	now = a[n - 1] - now;

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

		cout << now << " " << a[i] << endl;

		now -= a[i];

	}

}

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

#include <algorithm>

using namespace std;



int main()

{

    int n;

    int a[100010]={};

    cin>>n;

    long long ans=0;

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

    {

        cin>>a[i];

    }

    sort(a,a+n);

    ans-=a[0];

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

    {

        ans+=abs(a[i]);

    }

    ans+=a[n-1];

    cout<<ans<<endl;

    int cnt=0;

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

    {

        if(a[i]<0) cnt++;

        else

        {

            cout<<a[0]<<" "<<a[i]<<endl;

            a[0]-=a[i];

        }



    }



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

    a[n-1]-=a[0];



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

    {

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

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

    }

    return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <algorithm>

#include <cmath>



using namespace std;



const int maxn = 1e5+5 ;

int arr[maxn] ;

int main()

{

    int n ;

    cin >> n ;

    int l = 0 ;

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

        cin >> arr[i] ;

        if (arr[i]<0)  l++ ;

    }

    sort(arr,arr+n) ;

    int ans = 0 ;

    for(int i = 1 ; i < n-1 ; i++) ans += abs(arr[i]) ;

    ans-=arr[0] ;

    ans+=arr[n-1] ;

    cout << ans << endl ;

    if (l==0) l = 1 ;

    else if (l==n) l=n-1 ;

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

        cout << arr[0] << " "<< arr[i] <<endl;

        arr[0] -=arr[i] ;

    }

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

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

        arr[n-1] -=arr[i] ;

    }

    return 0;

}


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

#include<memory.h>

#include<stdio.h>

#include<algorithm>

using namespace std;



int n;

int a[100005];

int maxnum,minnum;

int ans1[100005];

int ans2[100005];



int main(){

    //cin>>n;

    scanf("%d",&n);

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

        //cin>>a[i];

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

    }

    sort(a,a+n);

    minnum=a[0];

    maxnum=a[n-1];

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

        if(a[i]<0){

            ans1[i]=maxnum;

            ans2[i]=a[i];

            maxnum-=a[i];

        }

        else{

            ans1[i]=minnum;

            ans2[i]=a[i];

            minnum-=a[i];

        }

    }

    cout<<maxnum-minnum<<endl;

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

        //cout<<ans1[i]<<" "<<ans2[i]<<endl;

        printf("%d %d\n",ans1[i],ans2[i]);

    }

    //cout<<maxnum<<" "<<minnum<<endl;

    printf("%d %d\n",maxnum,minnum);

    return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

#include <algorithm>

#define SIZE 100100

using namespace std;



long long rec[SIZE];



int main()

{

    int n,t,i;

    int tmp,pos;

    long long ans=0;

    scanf("%d",&n);

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

        scanf("%lld",rec+i);

    sort(rec,rec+n);

    if(rec[0]<0)

    {

        ans=rec[n-1];

        for(i=n-2;rec[i]>0;i--)

            ans+=rec[i];

        for(pos=i;i>=0;i--)

            ans-=rec[i];

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

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

        {

            printf("%lld %lld\n",rec[0],rec[i]);

            rec[0]-=rec[i];

        }

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

        {

            printf("%lld %lld\n",rec[n-1],rec[i]);

            rec[n-1]-=rec[i];

        }

    }

    else

    {

        if(n==1)

            ans=rec[0];

        else

            ans=-rec[0];

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

            ans+=rec[i];

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

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

        {

            printf("%lld %lld\n",rec[0],rec[i]);

            rec[0]-=rec[i];

        }

        if(n>1)

        printf("%lld %lld\n",rec[n-1],rec[0]);

    }



    return 0;

}


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

#include <algorithm>

#include <cmath>

#include <complex>

#include <vector>

#include <cstdio>

using namespace std;



typedef complex<double> P;



const double eps = 1.0e-7;

const double pi = acos(-1);



bool equals(double a, double b) { return abs(a-b) < eps; }

bool equals(P a, P b) {

  return equals(a.real(),b.real()) && equals(a.imag(),b.imag());

}



namespace std {

  bool operator < (const P& a, const P& b) {

    if(!equals(a.real(),b.real())) return a.real() < b.real();

    if(!equals(a.imag(),b.imag())) return a.imag() < b.imag();

    return false;

  }

}



P rotate(P p, double rad) {

  return P(cos(rad)*p.real() - sin(rad)*p.imag(),

	   sin(rad)*p.real() + cos(rad)*p.imag());

}



double solve(int N) {

  const static double r2 = 1.0/(2.0*(1.0-cos(pi*2.0/3.0)));

  vector<P> ps;

  vector<P> tri;

  tri.push_back(P(1.0,0.0));

  tri.push_back(rotate(P(1.0,0.0),pi*2.0/3.0));

  tri.push_back(rotate(P(1.0,0.0),-pi*2.0/3.0));

  double d = pi*2.0/(double)N;

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

    for(int j = 0; j < tri.size(); ++j) {

      ps.push_back(rotate(tri[j],pi*2.0*i/(double)N));

    }

  }



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

  int n = ps.size();

  for(int i = 1; i < ps.size(); ++i)

    n -= equals(ps[i-1],ps[i]);



  double rad = pi*2.0/(double)n;

  double rad2 = (pi*(n-2)/(double)n - pi/3.0)/2.0;

  double l2 = 2.0 * r2 * (1.0-cos(rad));

  return r2*pi - n*( (rad-sin(rad))*r2/2.0 + tan(rad2)*l2/4.0 );

}



int main() {

  int n;

  while(scanf("%d",&n) != EOF && n) printf("%.6f\n", solve(n));

  return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cmath>



using namespace std;



const double eps = 1.0e-7;

const double pi = acos(-1);



bool equals(double a, double b) { return abs(a-b) < eps; }



int main() {

  const static double rr = 1.0/(2.0*(1.0-cos(pi*2.0/3.0)));

  double N;

  while(scanf("%lf",&N) != EOF && N) {

    double n;

    for(n = 1; n < N && !equals(0,fmod(3*n,N)); n+=1);

    n *= 3;

    printf("%.6f\n",

	   rr*pi - n*( (pi*2/n-sin(pi*2/n))*rr/2.0

		       + tan((pi*(n-2)/n-pi/3.0)/2.0)*2*rr*(1-cos(pi*2/n))/4.0 ));

  }

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define S 100000

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

using namespace std;vector<int>E[S];int u[2*S],v[2*S],r[2*S],ans[2*S],d[S],cnt=1,b[2*S],ok[S]{1};queue<int>que;void bfs(int u, int t) {que.push(u); while (!que.empty()) {int p = que.front(); que.pop(); for (int v : E[p]) {if (t) {if (d[v] > d[p] && !ok[v]) {ok[v] = 1; cnt++; que.push(v);}}else if (!~d[v]) {d[v] = d[p] + 1; que.push(v);}}}}int main(){int n,m,q;scanf("%d%d%d",&n,&m,&q);rep(i, m){scanf("%d%d",&u[i],&v[i]);u[i]--;v[i]--;E[u[i]].push_back(v[i]);E[v[i]].push_back(u[i]);}memset(d,-1,sizeof(d));d[0]=0;bfs(0,0);rep(i,m){if(d[u[i]]>d[v[i]])swap(u[i],v[i]);}rep(i,n)E[i].clear();rep(i,q){scanf("%d",&r[i]);r[i]--;b[r[i]]=1;}rep(i,m){if(!b[i]){if(d[v[i]]>d[u[i]]){E[u[i]].push_back(v[i]);}}}bfs(0,1);for(int i=q-1;i>=0;i--){ans[i]=n-cnt;if(d[v[r[i]]]>d[u[r[i]]]&&!ok[v[r[i]]]){E[u[r[i]]].push_back(v[r[i]]);if(ok[u[r[i]]]){cnt++;ok[v[r[i]]]=1;bfs(v[r[i]],1);}}}rep(i,q)printf("%d\n",ans[i]);}

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

#include<vector>

#include<deque>

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

using namespace std;



void reader(int *x) {

	int k = getchar_unlocked(); *x = k - '0';

	while (true) {

		k = getchar_unlocked();

		if (k < '0') break;

		*x = ((*x) << 1) + ((*x) << 3) + k - '0';

	}

}

inline void writeln(int x) {

	int s = 0; char f[7];

	while (x) {

		f[s++] = x % 10;

		x /= 10;

	}

	if (!s) f[s++] = 0;

	while (s--) putchar_unlocked(f[s] + '0');

	putchar_unlocked('\n');

}



vector<int>E[100000];

int u[200000], v[200000], r[200000], ans[200000], d[100000]{ 1 }, cnt = 1;

char b[200000], ok[100000]{ 1 };

deque<int>que;



void bfs(int u, char t) {

	que.emplace_back(u);

	while (!que.empty()) {

		int p = que.front(); que.pop_front();

		for (int v : E[p]) {

			if (t) {

				if (d[v] > d[p] && !ok[v]) {

					ok[v] = 1; cnt++; que.emplace_back(v);

				}

			}

			else if (!d[v]) {

				d[v] = d[p] + 1; que.emplace_back(v);

			}

		}

	}

}

int main() {

	int n, m, q; reader(&n); reader(&m); reader(&q);

	rep(i, m) {

		reader(&u[i]); reader(&v[i]);

		u[i]--; v[i]--;

		E[u[i]].emplace_back(v[i]); E[v[i]].emplace_back(u[i]);

	}

	bfs(0, 0);

	rep(i, m) {

		if (d[u[i]] > d[v[i]])swap(u[i], v[i]);

	}

	rep(i, n)E[i].clear();

	rep(i, q) {

		reader(&r[i]); r[i]--;

		b[r[i]] = 1;

	}

	rep(i, m) {

		if (!b[i]) {

			if (d[v[i]] > d[u[i]]) {

				E[u[i]].emplace_back(v[i]);

			}

		}

	}

	bfs(0, 1);

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

		ans[i] = n - cnt;

		if (d[v[r[i]]] > d[u[r[i]]] && !ok[v[r[i]]]) {

			E[u[r[i]]].emplace_back(v[r[i]]);

			if (ok[u[r[i]]]) {

				cnt++; ok[v[r[i]]] = 1;

				bfs(v[r[i]], 1);

			}

		}

	}

	rep(i, q)writeln(ans[i]);

}

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

#include<queue>

using namespace std;

#pragma warning(disable:4996)

int n, m, q, dist[110000], mark[110000], u[210000], v[210000];

vector<pair<int, int>>x[110000], y[110000], z[110000]; bool used[210000];

bool isgood(int f) {

	for (int i = 0; i < z[f].size(); i++) {

		if (mark[z[f][i].first] == 0 && used[z[f][i].second] == false)return true;

	}

	return false;

}

int main() {

	scanf("%d%d%d", &n, &m, &q); queue<int>Q;

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

		int a, b; scanf("%d%d", &a, &b); u[i + 1] = a; v[i + 1] = b;

		x[a].push_back(make_pair(b, i + 1)); x[b].push_back(make_pair(a, i + 1));

	}

	Q.push(1); for (int i = 1; i <= n; i++)dist[i] = 999999; dist[1] = 0;

	while (!Q.empty()) {

		int a1 = Q.front(); Q.pop();

		for (int i = 0; i < x[a1].size(); i++) {

			if (dist[x[a1][i].first] > dist[a1] + 1) { dist[x[a1][i].first] = dist[a1] + 1; Q.push(x[a1][i].first); }

		}

	}

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

		for (int j = 0; j < x[i].size(); j++) {

			if (dist[i] < dist[x[i][j].first]) { y[i].push_back(x[i][j]); }

			if (dist[i] > dist[x[i][j].first]) { z[i].push_back(x[i][j]); }

		}

	}

	int cnt = 0;

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

		int a; scanf("%d", &a); used[a] = true;

		int E1 = u[a], E2 = v[a];

		if (dist[E1] == dist[E2]) { cnt += 0; }

		else {

			int a1 = 0; if (dist[E1] < dist[E2])a1 = E2; else a1 = E1;

			if (isgood(a1) == false && mark[a1] == 0) {

				queue<int>Q; Q.push(a1); cnt++; mark[a1] = 1;

				while (!Q.empty()) {

					int a2 = Q.front(); Q.pop();

					for (int j = 0; j < y[a2].size(); j++) {

						if (mark[y[a2][j].first] == 0 && isgood(y[a2][j].first) == false) {

							mark[y[a2][j].first] = 1; Q.push(y[a2][j].first); cnt++;

						}

					}

				}

			}

		}

		cout << cnt << endl;

	}

	return 0;

}

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

using namespace std;

int n,m,q,a[1<<18],b[1<<18],c,dist[1<<18],T[1<<18],cnt,U[1<<18];

vector<pair<int, int> >x[110000],y[110000];bool used[210000];

int main(){

	scanf("%d%d%d",&n,&m,&q);

	for(int i=0;i<m;i++){scanf("%d%d",&a[i],&b[i]);x[a[i]].push_back(make_pair(b[i],i));x[b[i]].push_back(make_pair(a[i],i));}

	fill(dist,dist+n+1,-1);dist[1]=0;queue<int>Q;Q.push(1);

	while(!Q.empty()){int a1=Q.front();Q.pop();for(pair<int,int>i:x[a1]){if(dist[i.first]==-1){dist[i.first]=dist[a1]+1;Q.push(i.first);}}}

	for(int i=1;i<=n;i++){for(pair<int,int>j:x[i]){if(dist[i]<dist[j.first]){y[i].push_back(j);T[j.first]++;}}}

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

		scanf("%d",&c);c--;queue<pair<int,int> >Q1; int ss=-1;

		if(dist[a[c]]<dist[b[c]])ss=b[c];

		if(dist[a[c]]>dist[b[c]])ss=a[c];

		if(ss>=1&&U[ss]==0&&used[c]==false){

			Q1.push(make_pair(ss,c));

			while(!Q1.empty()){

				int a1=Q1.front().first,a2=Q1.front().second;Q1.pop();

				if(U[a1]==1||used[a2]==true)continue;T[a1]--;used[a2]=true;if(T[a1]!=0)continue;cnt++;U[a1]=1;

				for(pair<int,int>j:y[a1]){if(U[j.first]==0)Q1.push(j);}

			}

		}

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

	}

}

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

#include<queue>

using namespace std;

#pragma warning(disable:4996)

int n, m, q, dist[110000], mark[110000], u[210000], v[210000];

vector<pair<int, int>>x[110000], y[110000], z[110000]; bool used[210000];

bool isgood(int f) {

	for (int i = 0; i < z[f].size(); i++) {

		if (mark[z[f][i].first] == 0 && used[z[f][i].second] == false)return true;

	}

	return false;

}

int main() {

	scanf("%d%d%d", &n, &m, &q); queue<int>Q;

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

		int a, b; scanf("%d%d", &a, &b); u[i + 1] = a; v[i + 1] = b;

		x[a].push_back(make_pair(b, i + 1)); x[b].push_back(make_pair(a, i + 1));

	}

	Q.push(1); for (int i = 1; i <= n; i++)dist[i] = 999999; dist[1] = 0;

	while (!Q.empty()) {

		int a1 = Q.front(); Q.pop();

		for (int i = 0; i < x[a1].size(); i++) {

			if (dist[x[a1][i].first] > dist[a1] + 1) { dist[x[a1][i].first] = dist[a1] + 1; Q.push(x[a1][i].first); }

		}

	}

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

		for (int j = 0; j < x[i].size(); j++) {

			if (dist[i] < dist[x[i][j].first]) { y[i].push_back(x[i][j]); }

			if (dist[i] > dist[x[i][j].first]) { z[i].push_back(x[i][j]); }

		}

	}

	int cnt = 0;

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

		int a; scanf("%d", &a); used[a] = true;

		int E1 = u[a], E2 = v[a];

		if (dist[E1] == dist[E2]) { cnt += 0; }

		else {

			int a1 = 0; if (dist[E1] < dist[E2])a1 = E2; else a1 = E1;

			if (isgood(a1) == false && mark[a1] == 0) {

				queue<int>Q; Q.push(a1); cnt++; mark[a1] = 1;

				while (!Q.empty()) {

					int a2 = Q.front(); Q.pop();

					for (int j = 0; j < y[a2].size(); j++) {

						if (mark[y[a2][j].first] == 0 && isgood(y[a2][j].first) == false) {

							mark[y[a2][j].first] = 1; Q.push(y[a2][j].first); cnt++;

						}

					}

				}

			}

		}

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

	}

	return 0;

}

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

using namespace std;

int n,m,q,a[1<<18],b[1<<18],c,dist[1<<18],T[1<<18],cnt,U[1<<18];

vector<pair<int, int> >x[110000],y[110000];bool used[210000];

int main(){

	scanf("%d%d%d",&n,&m,&q);

	for(int i=0;i<m;i++){scanf("%d%d",&a[i],&b[i]);x[a[i]].push_back(make_pair(b[i],i));x[b[i]].push_back(make_pair(a[i],i));}

	fill(dist,dist+n+1,-1);dist[1]=0;queue<int>Q;Q.push(1);

	while(!Q.empty()){int a1=Q.front();Q.pop();for(pair<int,int>i:x[a1]){if(dist[i.first]==-1){dist[i.first]=dist[a1]+1;Q.push(i.first);}}}

	for(int i=1;i<=n;i++){for(pair<int,int>j:x[i]){if(dist[i]<dist[j.first]){y[i].push_back(j);T[j.first]++;}}}

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

		scanf("%d",&c);c--;queue<pair<int,int> >Q1; int ss=-1;

		if(dist[a[c]]<dist[b[c]])ss=b[c];

		if(dist[a[c]]>dist[b[c]])ss=a[c];

		if(ss>=1&&U[ss]==0&&used[c]==false){

			Q1.push(make_pair(ss,c));

			while(!Q1.empty()){

				int a1=Q1.front().first,a2=Q1.front().second;Q1.pop();

				if(U[a1]==1||used[a2]==true)continue;T[a1]--;used[a2]=true;if(T[a1]!=0)continue;cnt++;U[a1]=1;

				for(pair<int,int>j:y[a1]){if(U[j.first]==0)Q1.push(j);}

			}

		}

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

	}

}

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

#include<algorithm>

#include<cstdio>

#include<cmath>

#include<stack>

#include<queue>

#include<map> 

#include<list>

#include<string>

#include<cstring>

#include<set>

#include<vector>

#define ll long long

#define memset(a,n) memset(a,n,sizeof(a))

#define mp make_pair 

#define pb push_back

using namespace std;

const int maxn = 2e5 + 100;





int main()

{

	int n;int a[maxn];ll p[maxn];scanf("%d",&n);

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

	p[1] = a[1];

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

		p[i] = p[i-2] + a[i];

	}

	ll dp[maxn] = {0};

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

		if(i & 1){

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

		}else{

			dp[i] = max(dp[i-2] + a[i],p[i-1]);

		}

	}

	printf("%lld\n",dp[n]);

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cmath>

#include<iostream>

#include<algorithm>

#include<cstring>

#include<cstdlib>

#include<queue>

#include<map>

#include<stack>

#include<set>

#include<vector>

#include<functional>

using namespace std;

typedef long long LL;

inline LL read()

{

	LL kk=0,f=1;

	char cc=getchar();

	while(cc<'0'||cc>'9'){if(cc=='-')f=-1;cc=getchar();}

	while(cc>='0'&&cc<='9'){kk=(kk<<1)+(kk<<3)+cc-'0';cc=getchar();}

	return kk*f;

}

LL a[2000222],dp[4],n,sum[2000222];

#define P(x) (x%3+3)%3

int main()

{

	n=read();

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

	{

		a[i]=read();

		sum[i]=sum[i-1];

		if(i&1)sum[i]+=a[i];

	}

	dp[1]=0;dp[2]=max(a[1],a[2]);

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

	{

		LL now,pre1,pre2;

		now=P(i);pre1=P(i-1);pre2=P(i-2);

		dp[now]=0;

		if(i&1)

		{

			dp[now]=max(dp[pre1],dp[pre2]+a[i]);

		}

		else

		{

			dp[now]=max(sum[i],dp[pre2]+a[i]);

		}

	}

	printf("%lld\n",dp[P(n)]);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#include<iostream>

#include<cstdio>

#include<string.h>

#include<cmath>

#include<algorithm>

#include<queue>

#include<stack>

using namespace std;

typedef unsigned long long ull;

typedef  long long ll;

#define INF  0x7f7f7f7f//7f7f7f7f

#define M 2000010

#define N 100010

const ll mod = 1e9 + 7;

ll a[M],dp[M],sum[M],n;

int main(void){

	scanf("%lld",&n);

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

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

		if(i%2)

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

		else

		sum[i] =sum[i-1];

	}

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

		if(i%2)

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

		else

		dp[i] =max(dp[i-2]+a[i],sum[i-1]);

	}

	printf("%lld\n",dp[n]);

	return 0;

}

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

#define N 200002

typedef long long LL;



int a[N];

LL s[N][2];



int read()

{

	char c, f = 0;

	while((c = getchar()) < 48 || c > 57){

		if(c == '-') f = 1;

	}

	int x;

	if(!f){

		x = c - 48;

		while((c = getchar()) > 47 && c < 58) x = x * 10 + (c - 48);

	}

	else{

		x = 48 - c;

		while((c = getchar()) > 47 && c < 58) x = x * 10 - (c - 48);

	}

	return x;

}



int main()

{		

	int n, i;

	LL s1 = 0, s2 = 0, t, x;

	

	scanf("%d", &n);

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

		a[i] = read();

	}

	if(n % 2 == 0){

		s[1][0] = (LL)a[1], s[2][0] = (LL)a[2];

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

			if(i & 1){

				s[i][0] = s[i - 2][0] + (LL)a[i];

			}

			else{

				t = s[i - 2][0];

				if((x = s[i - 3][0]) > t) t = x;

				s[i][0] = t + (LL)a[i];

			}

		}

		t = s[n][0];

		if((x = s[n - 1][0]) > t) t = x;

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

		return 0;

	}

	

	s[1][0] = (LL)a[1], s[2][0] = (LL)a[2];

	s[3][1] = (LL)a[3], s[3][0] = (LL)(a[1] + a[3]);

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

		if(i & 1){

			s[i][0] = s[i - 2][0] + (LL)a[i];

			t = s[i - 2][1];

			if((x = s[i - 3][0]) > t) t = x;

			if((x = s[i - 4][0]) > t) t = x;

			s[i][1] = t + (LL)a[i];

		}

		else{

			t = s[i - 2][0];

			if((x = s[i - 3][0]) > t) t = x;

			s[i][0] = t + (LL)a[i];

		}

	}

	t = s[n][1];

	if((x = s[n - 1][0]) > t) t = x;

	if((x = s[n - 2][0]) > t) t = x;

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

			

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define ll long long

#define inf 100000000000000000ll

using namespace std;

int n;

ll mem[200005][3], ara[200005];

bool vis[200005][3];

ll dp(int pos, int skip)

{

    if(pos>=n || (pos==n-1 && skip==2))return 0;

    if(vis[pos][skip])return mem[pos][skip];

    vis[pos][skip]= 1;

    mem[pos][skip]= -inf;

    if(skip)mem[pos][skip]= dp(pos+1, skip-1);

    mem[pos][skip]= max(mem[pos][skip], ara[pos]+dp(pos+2, skip));

    return mem[pos][skip];

}

int main()

{

    scanf("%d", &n);

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

    ll res= -inf;

    if(!(n&1))

    {

        memset(vis, 0, sizeof vis);

        res= max(res, ara[0]+dp(2, 1));

        memset(vis, 0, sizeof vis);

        res= max(res, ara[1]+dp(3, 0));

    }

    else

    {

        memset(vis, 0, sizeof vis);

        res= max(res, ara[0]+dp(2, 2));

        memset(vis, 0, sizeof vis);

        res= max(res, ara[1]+dp(3, 1));

        memset(vis, 0, sizeof vis);

        res= max(res, ara[2]+dp(4, 0));

    }

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

    return 0;

}


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

#define ll long long

#define inf 100000000000000000ll

using namespace std;

int n;

ll mem[200005][3], ara[200005];

bool vis[200005][3];

ll dp(int pos, int skip)

{

    if(pos>=n || (pos==n-1 && skip==2))return 0;

    if(vis[pos][skip])return mem[pos][skip];

    vis[pos][skip]= 1;

    mem[pos][skip]= -inf;

    if(skip)mem[pos][skip]= dp(pos+1, skip-1);

    mem[pos][skip]= max(mem[pos][skip], ara[pos]+dp(pos+2, skip));

    return mem[pos][skip];

}

int main()

{

    scanf("%d", &n);

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

    ll res= -inf;

    if(!(n&1))

    {

        //memset(vis, 0, sizeof vis);

        res= max(res, ara[0]+dp(2, 1));

        //memset(vis, 0, sizeof vis);

        res= max(res, ara[1]+dp(3, 0));

    }

    else

    {

        //memset(vis, 0, sizeof vis);

        res= max(res, ara[0]+dp(2, 2));

        //memset(vis, 0, sizeof vis);

        res= max(res, ara[1]+dp(3, 1));

        //memset(vis, 0, sizeof vis);

        res= max(res, ara[2]+dp(4, 0));

    }

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

    return 0;

}


// Fastest known solution for this problem: