stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
// #include {{{

#include <iostream>

#include <cassert>

#include <cstring>

#include <cstdlib>

#include <cstdio>

#include <cctype>

#include <cmath>

#include <ctime>

#include <queue>

#include <set>

#include <map>

#include <stack>

#include <string>

#include <bitset>

#include <vector>

#include <complex>

#include <algorithm>

using namespace std;

// }}}

// #define {{{

typedef long long ll;

typedef double db;

typedef pair<int,int> pii;

typedef vector<int> vi;

#define de(x) cout << #x << "=" << x << endl

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

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

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

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

#define mp make_pair

#define pb push_back

#define fi first

#define se second

// }}}





const int N = 1e5 + 10;

const ll inf = 1e18;

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

ll f[N][3];

char s[10];



int main(){

  scanf("%d",&n);

  rep(i,1,n+1) {

    if(i==1) op[i]=0;

    else {

      scanf("%s",s);

      op[i]=s[0]=='-';

    }

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

  }

  rep(i,0,n+1) rep(j,0,3) f[i][j]=-inf;

  f[0][0]=0;

  rep(i,0,n+1) per(j,0,3) {

    if(j) f[i][j-1]=max(f[i][j-1],f[i][j]);

    if(i!=n) {

      ll t=f[i][j]+a[i+1]*((j+op[i+1])&1?-1:1);

      f[i+1][j]=max(f[i+1][j],t);

      if(op[i+1]==1&&j!=2)

        f[i+1][j+1]=max(f[i+1][j+1],t);

    }

  }

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

  return 0;

}


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

#include<vector>

#include<cstring>

#include<algorithm>

using namespace std;

typedef double db;

typedef long long ll;

typedef vector<int> vi;

typedef pair<int, int> pii;

#define fi first

#define se second

#define mp make_pair

#define pb push_back

#define pw(x) (1ll << (x))

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

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

#define rep(i,l,r) for(i=(l);i<(r);++i)

#define per(i,l,r) for(i=(r)-1;i>=(l);--i)

#define dd(x) cout << #x << " = " << x << ", "

#define de(x) cout << #x << " = " << x << endl

//-----

const int N=100005;

ll pre[N],rpre[N];

int vec[N],sz=0;

ll qry(int l,int r) {

  return pre[r]-pre[l-1];

}

ll mymax(ll a,ll b) {

  return a>b?a:b;

}

int main() {

  int i;

  sz=0;

  int n,a;scanf("%d%d",&n,&a);pre[1]=rpre[1]=a;

  rep(i,2,n+1) {

    char s[5];

    int a;scanf("%s%d",s,&a);

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

    if(s[0]=='-') {

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

      vec[sz++]=i;

    }

    else rpre[i]=rpre[i-1]+a;

  }

  ll ans=rpre[n];

  rep(i,0,sz-1)ans=mymax(ans,rpre[vec[i]-1]-qry(vec[i],vec[i+1]-1)+qry(vec[i+1],n));

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

  return 0;

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

#include <cstring>

#include <algorithm>

#include <iostream>

#include <cmath>



using namespace std;



long long dp[100050][3];

char sign[100050];

int val[100050];

int sgn[100050];



int main()

{

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

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

	{

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

		if(i != n) scanf(" %c",&sign[i + 1]),sgn[i + 1] = sign[i + 1] == '-' ? -1 : 1;

	}

	sgn[0] = 1;

	memset(dp,-0x3f3f3f3f,sizeof(dp));

	dp[1][0] = val[1];

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

	{

		for(int j = 0;j <= 2; ++ j)

		{

			if(sgn[i] == -1)

			{

				if(j)

				{

					if(j == 2) 

						dp[i][j] = max(dp[i][j],dp[i - 1][j - 1] + val[i]);

					else

						dp[i][j] = max(dp[i][j],dp[i - 1][j - 1] - val[i]);

				}

				if(j % 2 == 0) dp[i][j] = max(dp[i][j],dp[i - 1][j] - val[i]);

				else dp[i][j] = max(dp[i][j],dp[i - 1][j] + val[i]);

				if(j != 2)

				{

					if(j == 1)

						dp[i][j] = max(dp[i][j],dp[i - 1][j + 1] - val[i]);

					else

						dp[i][j] = max(dp[i][j],dp[i - 1][j + 1] + val[i]);

				}

			}

			else

			{

				if(j % 2 == 0) dp[i][j] = max(dp[i][j],dp[i - 1][j] + val[i]);

				else dp[i][j] = max(dp[i][j],dp[i - 1][j] - val[i]);

				if(j != 2)

				{

					if(j == 1)

						dp[i][j] = max(dp[i][j],dp[i - 1][j + 1] + val[i]);

					else

						dp[i][j] = max(dp[i][j],dp[i - 1][j + 1] - val[i]);

				}

			}

		}

	}

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

}

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

using namespace std;

#define llong long long

const llong inf=0x3f3f3f3f3f3f3f3f;

int n;

char op[22];

int a;

llong dp[100100][3];

int main()

{

    scanf("%d",&n);

    scanf("%d",&a);

    dp[1][0]=a;

    dp[1][1]=dp[1][2]=-inf;

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

    {

        scanf("%s%d",op,&a);

        if(op[0]=='-')a=-a;

//        cout<<"i: "<<i<<" op: "<<op[0]<<" a: "<<a<<endl;

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

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

        dp[i][2]=dp[i-1][2]+a;

//        cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;cout<<endl;

        dp[i][0]+=a;

        dp[i][1]-=a;

        if(op[0]=='-')

        {

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

            dp[i][1]=max(dp[i][1],dp[i][0]);

        }

//        cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;cout<<endl;

    }

    printf("%lld\n",max(dp[n][0],max(dp[n][1],dp[n][2])));

    return 0;

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

#include <cstring>

#include <algorithm>

#include <iostream>

#include <cmath>



using namespace std;



long long dp[100050][3];

char sign[100050];

int val[100050];

int sgn[100050];



int main()

{

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

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

	{

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

		if(i != n) scanf(" %c",&sign[i + 1]),sgn[i + 1] = sign[i + 1] == '-' ? -1 : 1;

	}

	sgn[0] = 1;

	memset(dp,-0x3f3f3f3f,sizeof(dp));

	dp[1][0] = val[1];

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

	{

		for(int j = 0;j <= 2; ++ j)

		{

			if(sgn[i] == -1)

			{

				if(j)

				{

					if(j == 2) 

						dp[i][j] = max(dp[i][j],dp[i - 1][j - 1] + val[i]);

					else

						dp[i][j] = max(dp[i][j],dp[i - 1][j - 1] - val[i]);

				}

				if(j % 2 == 0) dp[i][j] = max(dp[i][j],dp[i - 1][j] - val[i]);

				else dp[i][j] = max(dp[i][j],dp[i - 1][j] + val[i]);

				if(j != 2)

				{

					if(j == 1)

						dp[i][j] = max(dp[i][j],dp[i - 1][j + 1] - val[i]);

					else

						dp[i][j] = max(dp[i][j],dp[i - 1][j + 1] + val[i]);

				}

			}

			else

			{

				if(j % 2 == 0) dp[i][j] = max(dp[i][j],dp[i - 1][j] + val[i]);

				else dp[i][j] = max(dp[i][j],dp[i - 1][j] - val[i]);

				if(j != 2)

				{

					if(j == 1)

						dp[i][j] = max(dp[i][j],dp[i - 1][j + 1] + val[i]);

					else

						dp[i][j] = max(dp[i][j],dp[i - 1][j + 1] - val[i]);

				}

			}

		}

	}

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

}

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

#include <iostream>

#include <cstdlib>

#include <cstring>

#include <cstdio>

#include <vector>

#include <cmath>

#include <ctime>

#include <queue>

#include <stack>

#include <map>

#include <set>

#define ll long long

using namespace std;

const long long N=1e5+10,M=3e5+30,LEN=50;

const int Mod=10007;

const long double EPS=1e-7;

const long long MAX=1e18;

int read() {

    int x = 0, f = 1;

    char c = getchar();

    while (c < '0' || c > '9') f = (c == '-') ? -1 : f, c = getchar();

    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();

    return x * f;

}

int n,a;

long long f[N][5];

int main(){

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

    //freopen("problem.ans","w",stdout);

    scanf("%d",&n);

    f[0][0]=0;

    f[0][1]=f[0][2]=-MAX;

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

    	a=read();

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

    	f[i][1]=max(f[i-1][1],f[i-1][2]);

    	f[i][2]=f[i-1][2];

    	f[i][0]+=a;

    	f[i][1]-=a;

    	f[i][2]+=a;

    	if(a<0){

    		f[i][2]=max(f[i][2],f[i][1]);

    		f[i][1]=max(f[i][1],f[i][0]);

    	}

    }

    printf("%lld\n",max(f[n][0],max(f[n][1],f[n][2])));

    return 0;

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

using namespace std;



typedef long long ll;

const int maxn = 1e5 + 5;



inline int gi()

{

	char c = getchar();

	while (c < '0' || c > '9') c = getchar();

	int sum = 0;

	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();

	return sum;

}



inline int gc()

{

	char c = getchar();

	while (c != '-' && c != '+') c = getchar();

	return c == '+' ? 1 : -1;

}



inline void chkmax(ll &a, ll b) {if (a < b) a = b;}



int n, a[maxn], b[maxn], pw[3];

ll f[maxn][3];



int main()

{

	n = gi();

	a[1] = gi(); b[1] = 1;

	for (int i = 2; i <= n; ++i) b[i] = gc(), a[i] = gi();



	memset(f, -63, sizeof(f));

	f[1][0] = a[1];

	pw[0] = pw[2] = 1; pw[1] = -1;

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

		for (int j = 0; j <= 2; ++j)

			if (f[i][j] > -1e18) {

				chkmax(f[i + 1][j], f[i][j] + a[i + 1] * b[i + 1] * pw[j]);

				if (j) chkmax(f[i + 1][j - 1], f[i][j] + a[i + 1] * b[i + 1] * pw[j - 1]);

				if (b[i + 1] < 0 && j < 2) chkmax(f[i + 1][j + 1], f[i][j] + a[i + 1] * b[i + 1] * pw[j]);

				if (b[i + 1] < 0 && j) chkmax(f[i + 1][j], f[i][j] + a[i + 1] * b[i + 1] * pw[j - 1]);

			}

	}



	printf("%lld\n", max(f[n][0], max(f[n][1], f[n][2])));

	

	return 0;

}


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

using namespace std;

#define lor(a,b,c) for(register int a=b;a<=c;++a)

#define ror(a,b,c) for(register int a=c;a>=b;--a)

typedef long long ll;



const int N=1e5+5;

int n,nxt[N]; ll a[N],sum[N],abssum[N],ans;



template <typename T> inline T read(){

	char tmp=getchar(); T sum=0; bool flag=false;

	while(tmp<'0'||tmp>'9'){

		if(tmp=='-') flag=true; tmp=getchar();

	}

	while(tmp>='0'&&tmp<='9'){

		sum=(sum<<1)+(sum<<3)+tmp-'0'; tmp=getchar();

	}

	return flag?-sum:sum;

}



int main(){

	n=read<int>(); lor(i,1,n) a[i]=read<ll>(),sum[i]=sum[i-1]+a[i],abssum[i]=abssum[i-1]+abs(a[i]); ans=sum[n];

	nxt[n+1]=n+1; sum[n+1]=sum[n]; abssum[n+1]=abssum[n]; ror(i,1,n) {if(a[i+1]<0) nxt[i]=i+1; else nxt[i]=nxt[i+1];}

	lor(i,1,n) if(a[i]<0){

		ans=max(ans,sum[i-1]+(abssum[n]-abssum[nxt[i]-1])-(abssum[nxt[i]-1]-abssum[i-1]));

	}

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



	return 0;

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

#define pa pair<int,int>

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

#define MP make_pair

#define fi first

#define se second

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef unsigned int ui;

typedef long double ld;

const int maxn=1e5+10;



inline char gc(){

	return getchar();

	static const int maxs=1<<16;static char buf[maxs],*p1=buf,*p2=buf;

    return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxs,stdin),p1==p2)?EOF:*p1++;

}

inline ll rd(){

    ll x=0;char c=gc();bool neg=0;

    while(c<'0'||c>'9'){if(c=='-') neg=1;c=gc();}

    while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=gc();

    return neg?(~x+1):x;

}



int N,a[maxn],op[maxn];

ll f[maxn][3];



inline void upd(ll &a,ll b){a=max(a,b);}



int main(){

    //freopen("","r",stdin);

    N=rd();

    a[1]=rd();op[1]=1;

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

        char s[5];scanf("%s",s);

        op[i]=(s[0]=='+')?1:-1;

        a[i]=rd();

    }

    CLR(f,-127);f[0][0]=0;

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

        upd(f[i][0],f[i-1][0]+op[i]*a[i]),upd(f[i][0],f[i-1][1]-op[i]*a[i]),upd(f[i][0],f[i-1][2]+op[i]*a[i]);

        upd(f[i][1],f[i-1][2]+op[i]*a[i]);

        if(op[i]==-1){

            upd(f[i][1],f[i-1][0]+op[i]*a[i]);

            upd(f[i][2],f[i-1][1]-op[i]*a[i]);

        }

        upd(f[i][1],f[i-1][1]-op[i]*a[i]);

        upd(f[i][2],f[i-1][2]+op[i]*a[i]);

        // printf("~%d %d %d %d\n",i,f[i][0],f[i][1],f[i][2]);

    }

    printf("%lld\n",f[N][0]);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.401146865067036x):
//Created Time:2019年12月02日 星期一 21时16分28秒

#include <iostream>

#include <cstdio>

#include <algorithm>

#include <cstring>

#define N 100005



using namespace std;



long long ans;

int a[N][2];

long long sum1[N], sum2[N];



int main(){

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

	scanf("%d", &a[1][0]); sum1[1] = sum2[1] = a[1][0];

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

		int x = 0; bool flag = false; char ch = getchar();

		for(; !isdigit(ch); ch = getchar()) flag |= (ch == '-');

		for(; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);

		a[i + 1][0] = x; a[i + 1][1] = flag; 

		sum1[i + 1] = sum1[i] + (flag ? -x : x);

		sum2[i + 1] = sum2[i] + x;

	}

	ans = sum1[n];

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

		if(a[i][1]){

			int pos = i + 1; long long tmp = 0;

			while(!a[pos][1] && pos <= n) tmp += a[pos++][0];

			ans = max(ans, sum1[i] - tmp + sum2[n] - sum2[pos - 1]);

			i = pos - 1;

		}

	cout << ans << endl;

	return 0;

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

#define pa pair<int,int>

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

#define MP make_pair

#define fi first

#define se second

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef unsigned int ui;

typedef long double ld;

const int maxn=1e5+10;



inline char gc(){

	return getchar();

	static const int maxs=1<<16;static char buf[maxs],*p1=buf,*p2=buf;

    return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxs,stdin),p1==p2)?EOF:*p1++;

}

inline ll rd(){

    ll x=0;char c=gc();bool neg=0;

    while(c<'0'||c>'9'){if(c=='-') neg=1;c=gc();}

    while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=gc();

    return neg?(~x+1):x;

}



int N,a[maxn],op[maxn];

ll f[maxn][3];



inline void upd(ll &a,ll b){a=max(a,b);}



int main(){

    //freopen("","r",stdin);

    N=rd();

    a[1]=rd();op[1]=1;

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

        char s[5];scanf("%s",s);

        op[i]=(s[0]=='+')?1:-1;

        a[i]=rd();

    }

    CLR(f,-127);f[0][0]=0;

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

        upd(f[i][0],f[i-1][0]+op[i]*a[i]),upd(f[i][0],f[i-1][1]-op[i]*a[i]),upd(f[i][0],f[i-1][2]+op[i]*a[i]);

        upd(f[i][1],f[i-1][2]+op[i]*a[i]);

        if(op[i]==-1){

            upd(f[i][1],f[i-1][0]+op[i]*a[i]);

            upd(f[i][2],f[i-1][1]-op[i]*a[i]);

        }

        upd(f[i][1],f[i-1][1]-op[i]*a[i]);

        upd(f[i][2],f[i-1][2]+op[i]*a[i]);

        // printf("~%d %d %d %d\n",i,f[i][0],f[i][1],f[i][2]);

    }

    printf("%lld\n",f[N][0]);

    return 0;

}

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

#define inf 100000000000000ll

using namespace std;



int read();



int n;

long long f[100005][3];

void chmax(long long &x, long long y) { x = x > y ? x : y; }



int main() {

    n = read();

    f[0][0] = 0, f[0][1] = f[0][2] = -inf;

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

        x = read();

        {

            f[i][0] = max(f[i - 1][0], f[i - 1][1]),

            f[i][1] = max(f[i - 1][1], f[i - 1][2]);

            f[i][2] = f[i - 1][2];

        }

        f[i][0] += x, f[i][1] -= x, f[i][2] += x;

        if (x < 0) chmax(f[i][2], f[i][1]), chmax(f[i][1], f[i][0]);

    }

    printf("%lld\n", max(f[n][0], max(f[n][1], f[n][2])));

    return 0;

}



int read() {

    int x = 0, f = 1;

    char c = getchar();

    while (c < '0' || c > '9') f = (c == '-') ? -1 : f, c = getchar();

    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();

    return x * f;

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

#include <cstring>

#include <iostream>

#include <algorithm>

using namespace std;

#define ll long long

#define N 100005

#define inf (1ll << 60)

int n, A[N], B[N];

ll ans, s[N], t[N], now, tot;

int main()

{

	scanf("%d", &n);

	scanf("%lld", &ans);

	t[0] = ans;

	char opt[5];

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

	{

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

		B[i] = opt[0] == '+' ? 1 : -1;

		ans += A[i] * B[i];

	}

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

		s[i] = A[i] + s[i + 1];

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

		t[i] = B[i] * A[i] + t[i - 1];

	now = -inf;

	tot = 0;

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

	{

		tot += A[i];

		if (B[i] == -1)

		{

			ans = max(ans, t[i - 1] - tot + now);

			now = s[i];

			tot = 0;

		}

	}

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

}


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

#include<algorithm>

using namespace std;

const int MAXN=int(1e5+5);

typedef long long LL;

#define INF LL(1e15)

LL s1,s2,as,n;

LL sz[MAXN],fh[MAXN];

char c[5];

int main()

{

	scanf("%lld",&n);

	scanf("%lld",&as);

	getchar();

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

		scanf("%s",c);

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

		fh[i]=c[0];

	}

	s1=s2=-INF;

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

		if(fh[i]=='-') {

			as-=sz[i];

			s2-=sz[i];

			s1+=sz[i];

			s2=max(s1,s2);

			s1=max(as,s1);

			as=max(s1,s2);

		}

		else {

			as+=sz[i];

			s2+=sz[i];

			s1-=sz[i];

			s1=max(s1,s2);

			as=max(s1,as);

		}

	}

	printf("%lld",as); 

}

/*

5

7 - 8 + 9 - 10 - 2*/
// Slower C++ solution:
#include <cstdio>

#include <cstring>

#include <iostream>

#include <algorithm>

using namespace std;

#define ll long long

#define N 100005

#define inf (1ll << 60)

int n, A[N], B[N];

ll ans, s[N], t[N], now, tot;

int main()

{

	scanf("%d", &n);

	scanf("%lld", &ans);

	t[0] = ans;

	char opt[5];

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

	{

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

		B[i] = opt[0] == '+' ? 1 : -1;

		ans += A[i] * B[i];

	}

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

		s[i] = A[i] + s[i + 1];

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

		t[i] = B[i] * A[i] + t[i - 1];

	now = -inf;

	tot = 0;

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

	{

		tot += A[i];

		if (B[i] == -1)

		{

			ans = max(ans, t[i - 1] - tot + now);

			now = s[i];

			tot = 0;

		}

	}

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

}


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



const int MAXN=100011;

const long long LONF=4567891012345678910LL;





int N;

int A[MAXN];

int O[MAXN];



long long F[MAXN][3];



int rO(){

	static char ch[2];

	scanf("%s", ch);

	return ch[0]=='+';

}



void relax(long long &f, long long v){

	if(f<v)	f=v;

}



int Calc(int t, int o, int a){

	if(t)	o=!o;

	return ((o<<1)-1)*a;

}



int main(){

	

	scanf("%d", &N);

	

	scanf("%d", &A[1]);

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

		O[i]=rO();

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

	}

	

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

		for(int j=0;j<=2;++j)

			F[i][j]=-LONF;

	

	F[1][0]=(long long)(A[1]);

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

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

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

				relax(F[i][k], F[i-1][j]+Calc(k&1, O[i], A[i]));

			}

			if(!O[i]){

				for(int k=0;k<=j && k<2;++k){

					relax(F[i][k+1], F[i-1][j]+Calc(k&1, O[i], A[i]));

				}

			}

		}

	}

	

	long long Ans=-LONF;

	for(int j=0;j<3;++j)

		relax(Ans, F[N][j]);

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

	

	return 0;

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

#include <cstring>

#include <iostream>

#include <algorithm>

using namespace std;

#define ll long long

#define N 100005

#define inf (1ll << 60)

int n, A[N], B[N];

ll ans, s[N], t[N], now, tot;

int main()

{

	scanf("%d", &n);

	scanf("%lld", &ans);

	t[0] = ans;

	char opt[5];

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

	{

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

		B[i] = opt[0] == '+' ? 1 : -1;

		ans += A[i] * B[i];

	}

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

		s[i] = A[i] + s[i + 1];

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

		t[i] = B[i] * A[i] + t[i - 1];

	now = -inf;

	tot = 0;

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

	{

		tot += A[i];

		if (B[i] == -1)

		{

			ans = max(ans, t[i - 1] - tot + now);

			now = s[i];

			tot = 0;

		}

	}

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

}


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

#include<cmath>

#include<cstring>

#include<string>

#include<algorithm>

#include<vector>



#define maxn 205

#define maxm 10000005



using namespace std;



inline int getint()

{

	int num=0,flag=1;char c;

	while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;

	while(c>='0'&&c<='9')num=num*10+c-48,c=getchar();

	return num*flag;

}



int n;

long long F[3];



int main()

{

	n=getint();F[1]=F[2]=-1ll<<60;

	while(n--)

	{

		int x=getint();

		F[0]+=x,F[1]-=x,F[2]+=x;

		if(x<0)F[2]=max(F[2],F[1]),F[1]=max(F[1],F[0]);

		F[1]=max(F[1],F[2]),F[0]=max(F[0],F[1]);

	}

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

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

using namespace std;

#define maxn 100010

template <typename T>inline T read()

{

    register T sum=0;

    register char cc=getchar();

    int sym=1;

    while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();

    if(cc=='-')sym=-1,cc=getchar();

    sum=sum*10+cc-'0';

    cc=getchar();

    while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();

    return sym*sum;

}

template <typename T>inline T read(T &a)

{

    a=read<T>();

    return a;

}

template <typename T,typename... Others> inline void read(T& a, Others&... b)

{

    a=read(a);

	read(b...);

}

int n,l=1,r,a[maxn],flg[maxn];

long long ans=-1e18,f[maxn],g[maxn];

int main()

{

	read(n);

	flg[1]=1;

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

	{

		read(a[i]);

		if(i<n)

		{

			char cc;

			scanf("%s",&cc);

			if(cc=='-')

				flg[i+1]=-1;

			else

				flg[i+1]=1;

		}

	}

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

		f[i]=f[i-1]+flg[i]*a[i];

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

		g[i]=g[i+1]+a[i];

	while(l<=n&&flg[l]==1)

		l+=1;

	for(;l<=n;l=r+1)

	{

		long long s=a[l];

		r=l;

		while(r<n&&flg[r+1]==1)

		{

			r+=1;

			s+=a[r];

		}

		ans=max(ans,f[l-1]+g[r+1]-s);

	}

	printf("%lld\n",max(ans,f[n]));

    return 0;

}


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

#include<cmath>

#include<cstring>

#include<string>

#include<algorithm>

#include<vector>



#define maxn 205

#define maxm 10000005



using namespace std;



inline int getint()

{

	int num=0,flag=1;char c;

	while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;

	while(c>='0'&&c<='9')num=num*10+c-48,c=getchar();

	return num*flag;

}



int n;

long long F[3];



int main()

{

	n=getint();F[1]=F[2]=-1ll<<60;

	while(n--)

	{

		int x=getint();

		F[0]+=x,F[1]-=x,F[2]+=x;

		if(x<0)F[2]=max(F[2],F[1]),F[1]=max(F[1],F[0]);

		F[1]=max(F[1],F[2]),F[0]=max(F[0],F[1]);

	}

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

}