#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  long long sum = 0, mx = 0;
  for (long long i = 0; i < (long long)(n); i++) {
    cin >> a[i];
    mx = max(mx, a[i]);
    sum += mx;
  }
  cout << sum << endl;
  return 0;
}
