#include <bits/stdc++.h>
using namespace std;
long long l[500005], n;
int32_t main() {
  cin >> n;
  string s;
  cin >> s;
  long long nr = 0;
  long long sol = 0, ans = 0;
  for (long long i = 0; i < n; ++i) {
    if (s[i] == '1') {
      nr++;
      sol += i + 1 - l[nr];
    } else {
      for (long long j = 1; j <= nr; ++j) l[j] = i + 1 - j;
      nr = 0;
    }
    ans += sol;
  }
  cout << ans << "\n";
  return 0;
}
