#include <bits/stdc++.h>
using namespace std;

const long long MOD = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    
    vector<int> p(n);
    vector<int> pos(n);  // pos[val] = where val is located
    
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        pos[p[i]] = i;
    }
    
    // Track min/max positions of first k values (0 to k-1)
    vector<int> mn(n + 1), mx(n + 1);
    int curMn = INT_MAX, curMx = -1;
    
    mn[0] = curMn;
    mx[0] = curMx;
    
    for (int k = 1; k <= n; k++) {
        int loc = pos[k - 1];  // Where is value (k-1)?
        curMn = min(curMn, loc);
        curMx = max(curMx, loc);
        mn[k] = curMn;
        mx[k] = curMx;
    }
    
    // Check if first k values are in same block
    auto ok = [&](int k, int sz) -> bool {
        if (k == 0) return true;
        return (mn[k] / sz) == (mx[k] / sz);
    };
    
    // Find all divisors of n
    vector<int> divs;
    for (int d = 1; d * d <= n; d++) {
        if (n % d == 0) {
            divs.push_back(d);
            if (d * d != n) {
                divs.push_back(n / d);
            }
        }
    }
    sort(divs.begin(), divs.end());
    
    long long ans = 0;
    
    // For each block size
    for (int sz : divs) {
        // Binary search: how many consecutive values fit in one block?
        int l = 0, r = n;
        
        while (l < r) {
            int m = (l + r + 1) / 2;
            
            if (ok(m, sz)) {
                l = m;
            } else {
                r = m - 1;
            }
        }
        
        // MEX is first missing value (capped at block size)
        long long mex = min((long long)sz, (long long)l);
        
        // Add to answer
        long long val = ((long long)sz % MOD) * (mex % MOD);
        ans = (ans + val) % MOD;
    }
    
    cout << ans << "\n";
    
    return 0;
}