#include <bits/stdc++.h>
using namespace std;
const int maxn = 500005;
int n;
int lst[maxn];
long long ans;
long long sum[maxn];
string s;
int main() {
  scanf("%d", &n);
  cin >> s, s = " " + s;
  for (int i = 1; i <= n; i++) {
    if (s[i] == '0') sum[i] = sum[i - 1];
    if (s[i] == '1') {
      int j = i;
      while (s[j + 1] == '1') j++;
      for (int k = i; k <= j; k++) sum[k] = sum[k - 1] + k - lst[k - i + 1];
      for (int k = i; k <= j; k++) lst[j - k + 1] = k;
      i = j;
    }
  }
  for (int i = 1; i <= n; i++) ans += sum[i];
  printf("%lld\n", ans);
  return 0;
}
