#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a == 0) {       return b;     }     return gcd(b % a, a);   }   int idx[200001] = {0};   vector<int> g[160];   int dp[160][100001] = {0};   int len[160][200001] = {0};   int nless(vector<int>& v, int val) {     if (!(int)v.size()) return 0;     if (v[0] > val) return 0;     int l = 0, r = (int)v.size() - 1;     while (r - l + 1 > 2) {       int x = (l + r) / 2;       if (v[x] > val) {         r = x;       } else {         l = x;       }     }     if (r - l + 1 == 2) {       if (v[r] <= val) {         return r + 1;       } else {         return l + 1;       }     }     if (r - l + 1 == 1) {       return l + 1;     }   }   void solve() {     int n;     cin >> n;     vector<int> v(n);     for (int j = 0; j < n; j++) cin >> v[j];     int num = 1;     vector<int> factors;     factors.push_back(1);     for (int j = 2; j <= sqrt(n); j++) {       if (n % j == 0) {         factors.push_back(j);         num++;         if (j * j != n) {           factors.push_back(n / j);           num++;         }       }     }     sort(factors.begin(), factors.end());     for (int j = 0; j < (int)factors.size(); j++) {       idx[factors[j]] = j;     }     for (int j = 1; j < n; j++) {       g[idx[gcd(j, n)]].push_back(j);     }     for (int j = n - 1; j >= 0; j--) {       for (int i = 0; i < num; i++) {         dp[i][j % factors[i]] = max(dp[i][j % factors[i]], v[j]);       }     }     for (int j = n - 1; j >= 0; j--) {       for (int i = 0; i < num; i++) {         len[i][j] = (v[j] == dp[i][j % factors[i]]) * (1 + len[i][j + 1]);       }     }     for (int j = n - 1; j >= 0; j--) {       for (int i = 0; i < num; i++) {         len[i][j] = min(             n - 1, (v[j] == dp[i][j % factors[i]]) * (1 + len[i][(j + 1) % n]));       }     }     long long int ans = 0;     for (int j = 0; j < n; j++) {       for (int i = 0; i < num; i++) {         int cnt = nless(g[i], len[i][j]);         ans += cnt;       }     }     cout << ans <<   n ;     return;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }   