#include <bits/stdc++.h>
using namespace std;
long long all = 0, ans = 0;
long long f[1000100];
int n, now = 0;
char s[1000100];
int main() {
  int i;
  scanf("%d%s", &n, s + 1);
  for (i = 1; i <= n; i++) f[i] = n + 1;
  for (i = n; i >= 1; i--) {
    if (s[i] - '0' > 0)
      now++, all += f[now] - i;
    else {
      while (now) f[now] = i + now, now--;
    }
    ans += all;
  }
  cout << ans;
  return 0;
}
