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

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <algorithm>

#include <assert.h>

#define IOS ios::sync_with_stdio(false)

using namespace std;

#define inf (0x3f3f3f3f)

typedef long long int LL;





#include <iostream>

#include <sstream>

#include <vector>

#include <set>

#include <map>

#include <queue>

#include <string>

#include <bitset>

const int maxn = 1e5 + 20;

LL perfixSum[maxn], absSum[maxn];

vector<int>pos;

void cut(LL &val, int pos1, int pos2) {

    if (pos1 > pos2) return;

    val -= absSum[pos2] - absSum[pos1 - 1];

}

void work() {

    int n;

    scanf("%d", &n);

    int val;

    scanf("%d", &val);

    perfixSum[1] = val;

    absSum[1] = val;

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

        int val;

        char op;

        cin >> op;

        scanf("%d", &val);

        if (op == '+') {

            perfixSum[i] = perfixSum[i - 1] + val;

        } else {

            perfixSum[i] = perfixSum[i - 1] - val;

            pos.push_back(i);

        }

        absSum[i] = absSum[i - 1] + val;

    }

    LL ans = perfixSum[n];

    for (int i = 0; i <= (int)pos.size() - 2; ++i) {

        int p1 = pos[i], p2 = pos[i + 1];

        LL tans = absSum[n] - absSum[p2 - 1];

        tans += perfixSum[p1];

        cut(tans, p1 + 1, p2 - 1);

        ans = max(ans, tans);

    }

    cout << ans << endl;

}



int main() {

#ifdef local

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

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

#endif

//    int val;

//    scanf("%d", &val);

//    cout << val << endl;

    work();

    return 0;

}

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

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;



const int MAXN=100005;

const int INF=0x3f3f3f3f;



ll sum[MAXN];

ll tot,ans=-INF;

int n,a[MAXN];

bool flag[MAXN];

char s[5];



int main(){

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

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

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

        if(s[0]=='-') flag[i]=1;

    }

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

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

    int last=1;

    while(flag[last]==0&&last<=n){

        tot+=a[last];

        last++;

    }

    while(last<=n){

        int last1=last+1;

        ll tot1=0;

        while(flag[last1]==0&&last1<=n){

            tot1+=a[last1];

            last1++;

        }

        if(last1<=n)

            ans=max(ans,tot-tot1-a[last]+sum[last1]);

        tot-=a[last];

        last=last1;

        tot+=tot1;

    }

    ans=max(ans,tot);

    printf("%lld",ans);

}


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

using namespace std;



static const int Maxn = 100005;



int n, st, ed;

char op[Maxn];

long long a[Maxn];

long long dp[Maxn][3];



int main() {

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

  scanf("%lld ", a + 1), op[1] = '+';

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

    scanf("%c %lld ", op + i, a + i);

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

  dp[0][0] = 0;

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

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

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

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

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

    }

    else {

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

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

    }

  }

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

  return 0;

}

// Optimized solution to the same problem (faster):
//I love Nanami Chiaki

#include<bits/stdc++.h>

using namespace std;

#define ll long long

inline int read(){

	int re=0;char c=getchar();

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

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

	return re;

}

inline int readc(){

	char c=getchar();

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

	if (c=='+') return 1;

	return -1;

}

int n;

ll ans=0;

int main(){

	int n=read();

	ans+=read();

	int op,a;

	ll hve=0,add=-1,pre=-1;

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

		op=readc();a=read();

		ans+=a;

		if (op==-1){

			if (pre==-1){

				pre=a;

				hve=0;

				continue;

			}

			if (add==-1) add=pre+hve;

			else add=min(add,pre+hve);

			pre+=a;

			hve=0;

		}

		else{

			hve+=a;

		}

	}

	if (pre==-1){

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

		return 0;

	}

	else if (add==-1) ans-=2*pre;

	else ans-=2*add;

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

	return 0;

}

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



using namespace std;



typedef long long ll;

typedef pair<int, int> PII;



const int MM = 1e9 + 7;

const double eps = 1e-8;

const int MAXN = 2e6 + 10;

const ll INF = 1ll << 60;



int n, m;



ll f[MAXN][2];



int a[MAXN];



void prework(){



}



int b[MAXN];



void read(){

	scanf("%d", &n);

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

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

		char s[10];

		if (i < n){

			scanf("%s", s);

			if (s[0] == '+')

				b[i + 1] = 1;

			else

				b[i + 1] = -1;

		}

	}

	b[0] = b[1] = 1;

	f[0][0] = 0;

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

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

		if (b[i] == 1){

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

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

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

		}

		else{

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

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

			f[i][1] = f[i][0];

		}

		//cout<<f[i][0]<<' '<<f[i][1]<<endl;

	}

	cout<<max(f[n][1],max(f[n][0], f[n][2]))<<endl;

}



void solve(int casi){



}



void printans(){



}





int main(){

	prework();

	int T = 1;

//	cin>>T;

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

		read();

		solve(i);

		printans();

	}

	return 0;

}






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

#define N (100010)

typedef long long LL;

int a[N];

char b[N][2];

int n;

int main(){

	scanf("%d",&n);

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

		scanf("%d%s",a+i,b[i]);

	}

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

	LL ans1=a[1];

	for (int i=1;i<n;i++) ans1+=b[i][0]=='+'?a[i+1]:-a[i+1];

	LL temp=ans1;

	LL cur=a[n],tot=0;

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

		if (b[i][0]=='-'){

			temp=temp+a[i+1];

			if (temp-cur+tot>ans1) ans1=temp-cur+tot;

			tot+=cur;

			cur=0;

		}

		else {

			temp=temp-a[i+1];

		}

		cur+=a[i];

	}

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

}


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



using namespace std;



typedef long long LL;



const int N = 1e5 + 10;

int a[N], ri[N];

char b[N];

LL sum[N];



int main() {

    int n;

    scanf("%d", &n);

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

    for (int i = 2; i <= n; i++) scanf(" %c %d", b + i, a + i);

    for (int i = 1; i <= n; i++) sum[i] = sum[i-1] + a[i];

    ri[n + 1] = n + 1;

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

        ri[i] = ri[i+1];

        if (b[i+1] == '-') ri[i] = i + 1;

    }

    LL ans = -1e18;

    LL tmp = a[1];

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

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

            LL ans1 = tmp - a[i] - (sum[ri[i]-1]-sum[i]) + (sum[n] - sum[ri[i]-1]);

            ans = max(ans1, ans);

        }

        if (b[i] == '-') tmp -= a[i];

        else tmp += a[i];

    }

    ans = max(ans, tmp);

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

    return 0;

}


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

#define N (100010)

typedef long long LL;

int a[N];

char b[N][2];

int n;

int main(){

	scanf("%d",&n);

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

		scanf("%d%s",a+i,b[i]);

	}

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

	LL ans1=a[1];

	for (int i=1;i<n;i++) ans1+=b[i][0]=='+'?a[i+1]:-a[i+1];

	LL temp=ans1;

	LL cur=a[n],tot=0;

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

		if (b[i][0]=='-'){

			temp=temp+a[i+1];

			if (temp-cur+tot>ans1) ans1=temp-cur+tot;

			tot+=cur;

			cur=0;

		}

		else {

			temp=temp-a[i+1];

		}

		cur+=a[i];

	}

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

}


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

using namespace std;

const int maxn=1e5+10;

long long dp[maxn][3];

int n;

int val[maxn],pos[maxn];

char op[3];

int main()

{

	scanf("%d",&n);

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

	{

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

		if(i!=n)

		{

			scanf("%s",op+1);

			if(op[1]=='+')pos[i+1]=0;

			else pos[i+1]=1;		

		}

	}

	memset(dp,128,sizeof(dp));

	dp[0][0]=0;

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

	{

		if(pos[i])

		{

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

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

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

		}

		else 

		{

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

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

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

		}

	}

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

}

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

using namespace std;

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

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

#define mp(x,y) make_pair((x),(y))

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

#define pb push_back

typedef long long ll;

typedef pair<int,int> pii;

inline int read(){

    register int x=0,f=1;register char ch=getchar();

    while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}

    while(isdigit(ch)){x=x*10+(ch^'0');ch=getchar();}

    return f?x:-x;

}



int n;

ll f[100005][3];

inline void chkmax(ll& x,ll y){x=x>y?x:y;}



int main(){

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

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

	n=read();

	REP(i,1,n){

		int 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)chkmax(f[i][2],f[i][1]),chkmax(f[i][1],f[i][0]);

	}

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

	return 0;

}


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



using namespace std;

#define int long long

const int N = 1e5 + 5, M = 5, inf = 1e15;

int dp[N][M], a[N];

char op[N];



int Sign(int x) {

    if (x % 2) return -1;

    return 1;

}



int32_t main() {

    for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) dp[i][j] = -inf;

    int n; cin >> n >> a[0];

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

    dp[0][0] = a[0];

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

        if (op[i] == '+') dp[i][j] = dp[i - 1][j] + a[i] * Sign(j);

        else if (j) dp[i][j] = dp[i - 1][j - 1] + a[i] * Sign(j);

        if (j + 1 < M) dp[i][j] = max(dp[i][j], dp[i][j + 1]);

    }

    cout << dp[n-1][0] << "\n";

}


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



using namespace std;

#define int long long

const int N = 1e5 + 5, M = 3, inf = 1e15;

int dp[N][M], a[N];

char op[N];



int Sign(int x) {

    if (x % 2) return -1;

    return 1;

}



int32_t main() {

    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.tie(0);

    for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) dp[i][j] = -inf;

    int n; cin >> n >> a[0];

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

    dp[0][0] = a[0];

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

        if (op[i] == '+') dp[i][j] = dp[i - 1][j] + a[i] * Sign(j);

        else if (j) dp[i][j] = dp[i - 1][j - 1] + a[i] * Sign(j);

        if (j + 1 < M) dp[i][j] = max(dp[i][j], dp[i][j + 1]);

    }

    cout << dp[n-1][0] << "\n";

}


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

using namespace std;

const int maxn=1e5+10;

long long dp[maxn][3];

int n;

int val[maxn],pos[maxn];

char op[3];

int main()

{

	scanf("%d",&n);

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

	{

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

		if(i!=n)

		{

			scanf("%s",op+1);

			if(op[1]=='+')pos[i+1]=0;

			else pos[i+1]=1;		

		}

	}

	memset(dp,128,sizeof(dp));

	dp[0][0]=0;

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

	{

		if(pos[i])

		{

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

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

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

		}

		else 

		{

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

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

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

		}

	}

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

}

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

#define inf 100000000000000ll

using namespace std;



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;

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)

      f[i][2] = max(f[i][2], f[i][1]), f[i][1] = max(f[i][1], f[i][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;

}


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

using namespace std;

const int N = 100010;

typedef long long LL;

int op[N], num[N]; LL dp[N][3]; char s[5];

int main() {

	int n; scanf("%d%d", &n, &num[1]), op[1] = 1;

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

		scanf("%s%d", s + 1, &num[i]);

		if (s[1] == '-') op[i] = -1; else op[i] = 1;

	}

	memset(dp, -0x3f, sizeof(dp)), dp[1][0] = num[1];

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

		dp[i][1] = dp[i - 1][1] - op[i] * num[i];

		dp[i][0] = dp[i - 1][0] + op[i] * num[i];

		dp[i][2] = dp[i - 1][2] + op[i] * num[i];

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

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

			dp[i][2] = max(dp[i][2], dp[i - 1][1] + op[i] * num[i]);

		}

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

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

	}

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

}

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

#define inf 100000000000000ll

using namespace std;



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;

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)

      f[i][2] = max(f[i][2], f[i][1]), f[i][1] = max(f[i][1], f[i][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;

}


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

}


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

}


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

}

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

}

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

}


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

}

// Fastest known solution for this problem: