#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double dinf = 1e300;
const long long INF = 1e18;
const int Mod = 1e9 + 7;
const int maxn = 5e5 + 10;
long long f[maxn];
int n, a[maxn];
char s[maxn];
int main() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; i++) {
    a[i] = s[i] - '0';
  }
  long long ans = 0, cur = 0;
  int l, r;
  for (int i = 1; i <= n; i++) {
    if (a[i]) {
      l = r = i;
      while (r < n && a[r + 1]) r++;
      for (int j = 1; j <= r - l + 1; j++) {
        cur += (l + j - 1) - f[j];
        f[j] = r - j + 1;
        ans += cur;
      }
      i = r;
    } else
      ans += cur;
  }
  printf("%lld\n", ans);
  return 0;
}
