#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  long long int rj = 0;
  long long int tr_rj = 0;
  int cnt = 0;
  vector<int> zad(n, -1);
  for (int i = 0; i < (n); i++) {
    if (s[i] == '0') {
      for (int j = 0; j < (cnt); j++) zad[j] = i - 1 - j;
      cnt = 0;
    } else {
      cnt++;
      tr_rj += (i - cnt - zad[cnt - 1]) + cnt;
    }
    rj += tr_rj;
  }
  cout << rj << "\n";
  return 0;
}
