#include <iostream>
#include <string>
using namespace std;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int n;
    cin >> n;
    string s;
    cin >> s;
 
    // Count winning substrings that are entirely '0' (length >= 2).
    long long ans = 0;
    long long cnt = 0;
    for (int i = 0; i < n; i++){
        if (s[i] == '0')
            cnt++;
        else {
            if (cnt > 0){
                ans += cnt * (cnt - 1LL) / 2; // Each maximal block of zeros contributes L*(L-1)/2.
                cnt = 0;
            }
        }
    }
    if (cnt > 0)
        ans += cnt * (cnt - 1LL) / 2;
 
    // Count substrings of length 3 that are winning due to circular adjacency.
    // These substrings have exactly two zeros (so that even if they aren't consecutive linearly,
    // the zeros are adjacent in the circular view).
    for (int i = 0; i <= n - 3; i++){
        int zeros = 0;
        zeros += (s[i] == '0');
        zeros += (s[i+1] == '0');
        zeros += (s[i+2] == '0');
        if (zeros == 2)
            ans++;
    }
 
    cout << ans << "\n";
    return 0;
}