#include <bits/stdc++.h>
using namespace std;
#define MAX_N 1000000
int gcd(int a, int b){
while(b){
int r = a%b;
a = b;
b = r;
}
return a;
}
int main() {
int N;
char S[MAX_N];
scanf("%d %s", &N, S+1);
int ans = 0;
for(int i=1; i<=N; i++){
if(S[i]=='b') continue;
char last = S[i]=='a' ? 'c' : 'a';
for(int q=1; q*q<=i; q++){
if(i%(q*q)!=0) continue;
for(int p=q+1; ; p++){
int j = i*p/q;
int k = j*p/q;
if(k>N)
break;
if(S[j]=='b' && S[k]==last && gcd(p, q)==1)
ans++;
}
}
}
printf("%d\n", ans);
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIE1BWF9OIDEwMDAwMDAKCmludCBnY2QoaW50IGEsIGludCBiKXsKCXdoaWxlKGIpewoJCWludCByID0gYSViOwoJCWEgPSBiOwoJCWIgPSByOwoJfQoJcmV0dXJuIGE7Cn0KCmludCBtYWluKCkgewogICAgaW50IE47CiAgICBjaGFyIFNbTUFYX05dOwogICAgc2NhbmYoIiVkICVzIiwgJk4sIFMrMSk7CiAgICAKICAgIGludCBhbnMgPSAwOwogICAgZm9yKGludCBpPTE7IGk8PU47IGkrKyl7CiAgICAgICAgaWYoU1tpXT09J2InKSBjb250aW51ZTsKICAgICAgICBjaGFyIGxhc3QgPSBTW2ldPT0nYScgPyAnYycgOiAnYSc7CgogICAgICAgIGZvcihpbnQgcT0xOyBxKnE8PWk7IHErKyl7CiAgICAgICAgICAgIGlmKGklKHEqcSkhPTApIGNvbnRpbnVlOwogICAgICAgICAgICAKICAgICAgICAgICAgZm9yKGludCBwPXErMTsgOyBwKyspewogICAgICAgICAgICAJCiAgICAgICAgICAgICAgICBpbnQgaiA9IGkqcC9xOwogICAgICAgICAgICAgICAgaW50IGsgPSBqKnAvcTsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgaWYoaz5OKQogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgaWYoU1tqXT09J2InICYmIFNba109PWxhc3QgJiYgZ2NkKHAsIHEpPT0xKQogICAgICAgICAgICAgICAgICAgIGFucysrOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgCiAgICBwcmludGYoIiVkXG4iLCBhbnMpOwogICAgCiAgICByZXR1cm4gMDsKfQo=