#include <bits/stdc++.h>
using namespace std;
int main() {
  istream &is = cin;
  int N;
  cin >> N;
  vector<int> v(N);
  for (int n = 0; n < N; n++) cin >> v[n];
  int s, e;
  long long Sa, Sb, Sc, Sp, Ss;
  Sa = Sb = Sc = Sp = Ss = 0;
  for (int i = 0; i < v.size(); i++) {
    if (Ss + v[i] <= v[i]) {
      Sp = Sp + Ss;
      Ss = v[i];
    } else {
      Ss = Ss + v[i];
    }
    if (Sb >= Ss) {
      Sc = Sc + v[i];
    } else {
      Sa = Sp;
      Sb = Ss;
      Sc = 0;
    }
  }
  cout << Sb - Sa - Sc << endl;
  return 0;
}
