#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  vector<int> a(n + 1), hist(n + 1);
  for (int i = 0; i < n; i++) {
    a[i + 1] = s[i] - '0';
  }
  long long tot = 0, res = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == 0) {
      res += tot;
    } else {
      int l = i, r = i;
      while (r < n and a[r + 1] == 1) {
        ++r;
      }
      for (int x = 1; x <= (r - l + 1); x++) {
        tot += (l - 1 + x) - hist[x];
        res += tot;
        hist[x] = r - x + 1;
      }
      i = r;
    }
  }
  cout << res;
}
