#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int INF = 1000000007;
const double eps = 1e-10;
char s[maxn];
int S[maxn];
long long hist[maxn];
int main() {
  long long cur = 0, tot = 0;
  int n;
  scanf("%d", &n);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; i++) S[i] = s[i] - '0';
  for (int i = 1; i <= n; i++) {
    if (S[i] == 0)
      tot += cur;
    else {
      int l = i, r = i;
      while (r < n && S[r + 1] == 1) r++;
      for (int x = 1; x <= (r - l + 1); x++) {
        cur += (l - 1 + x) - hist[x];
        tot += cur;
        hist[x] = r - x + 1;
      }
      i = r;
    }
  }
  printf("%lld\n", tot);
  return 0;
}
