using System;
using System.Collections.Generic;

public class CSharp{
    public static void Main(){
        Kyopuro chokudai = new Kyopuro();
	    chokudai.AtCoder();
	}
}

public class Kyopuro{
    
    int n;
    int[] a;
    List<long> b;
    long ans;
    
    public void AtCoder(){
        n = int.Parse(Console.ReadLine());
        a = new int[n];
        string[] s = Console.ReadLine().Split(' ');
        ans = long.Parse(s[0]);
        int sign;
        for(int i=1; i<n; i++){
            sign = 1;
            if(s[i*2-1] == "-") sign = -1;
            a[i] = int.Parse(s[i*2]) * sign;
        }
        
        long tmp;
        b = new List<long>();
        int c = 1;
        while(c<n && a[c]>0) ans += a[c++];
        if(c<n) ans += a[c++];
        while(c<n){
            tmp = 0;
            if(a[c]<0){
                while(c<n && a[c]<0) tmp -= a[c++];
                while(c<n && a[c]>0) tmp += a[c++];
                ans += tmp;
                b.Add(0);
            } else {
                while(c<n && a[c]>0) tmp += a[c++];
                b.Add(tmp);
            }
            if(c<n) b.Add(a[c++]);
            else b.Add(0);
        }
        
        c = 0;
        while(c + 1 < b.Count){
            tmp = 0;
            tmp += b[c++];
            tmp += b[c++];
            ans += Math.Abs(tmp);
        }
        Console.WriteLine(ans);
    }
    
    public static void DebugWL(object x){ System.Diagnostics.Debug.WriteLine(x); }
}