#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int N = 1<<19;
const int TREE_SIZE = N<<2;
struct tree_node {
int *a,n;
tree_node(): n(0) {}
tree_node(int k) {
n=k;
a=(int*)malloc((sizeof(int)*k));
}
};
struct merge_max {
pair < int, int > operator ()(const pair < int, int > &a, const pair < int, int > &b) const {
return max(a,b);
}
};
template < class T, class MERGE >
struct sparse_table {
MERGE merge;
int n,offset;
T **st;
int *log;
template < class CONTAINER >
void initialize(CONTAINER arr, int k, int base=1) {
int current_log=0,i,j;
offset=(base^1);
n=k;
log=(int*)malloc((sizeof(int)*(n+1)));
st=(T**)malloc((sizeof(T*)*(n+1)));
for(i=0;i<=n;i++) {
while((1<<(1+current_log))<=i) ++current_log;
log[i]=current_log;
}
for(i=1;i<=n;i++) st[i]=(T*)malloc((sizeof(T)*(log[n]+1)));
for(i=1;i<=n;i++) st[i][0]=arr[i-offset];
for(j=1;(1<<j)<=n;j++) for(i=1;i+(1<<j)-1<=n;i++) st[i][j]=merge(st[i][j-1],st[i+(1<<(j-1))][j-1]);
}
T query(int l, int r) {
l+=offset;
r+=offset;
int k=log[r-l+1];
return merge(st[l][k],st[r-(1<<k)+1][k]);
}
};
int tests,current_case;
int n,arr[N];
tree_node tree[TREE_SIZE];
long long ans;
sparse_table < pair < int, int >, merge_max > rmq;
pair < int, int > a[N];
void message(int current_case) {
fprintf(stderr, "Case %d solved!\n", current_case);
}
inline tree_node merge_them(tree_node a, tree_node b) {
tree_node ans(a.n+b.n);
int i=0,j=0,idx=0;
while(i<a.n && j<b.n) {
if(a.a[i]<=b.a[j]) ans.a[idx++]=a.a[i++];
else ans.a[idx++]=b.a[j++];
}
while(i<a.n) ans.a[idx++]=a.a[i++];
while(j<b.n) ans.a[idx++]=b.a[j++];
return ans;
}
inline void build_tree(int a, int b, int node) {
if(a>b) return;
if(a==b) {
tree[node]=tree_node(1);
tree[node].a[0]=arr[a];
return;
}
build_tree(a,(a+b)>>1,node<<1);
build_tree(((a+b)>>1)+1,b,(node<<1)|1);
tree[node]=merge_them(tree[node<<1],tree[(node<<1)|1]);
}
inline int query_tree(int a, int b, int i, int j, int node, int value) {
if(a>b || a>j || b<i) return 0;
if(a>=i && b<=j) {
//if(value>=tree[node].a[tree[node].n-1]) return 0;
int left,right,middle;
left=-1;
right=tree[node].n;
while(right-left>1) {
middle=(left+right)>>1;
if(value<tree[node].a[middle]) right=middle;
else left=middle;
}
return tree[node].n-right;
}
return query_tree(a,(a+b)>>1,i,j,node<<1,value)+query_tree(((a+b)>>1)+1,b,i,j,(node<<1)|1,value);
}
int query(int l, int r, int k) {
if(l>r) return 0;
return r-l+1-query_tree(1,n,l,r,1,k);
}
void solve(int from, int to) {
if(from>=to) return;
pair < int, int > curr=rmq.query(from,to);
int i,left=curr.second-from,right=to-curr.second;
if(left<right) {
for(i=from;i<=curr.second;i++) {
ans+=query(curr.second+1,to,curr.first/arr[i]);
}
for(i=from;i<curr.second;i++) if(arr[i]==1) ++ans;
}
else {
for(i=curr.second;i<=to;i++) {
ans+=query(from,curr.second-1,curr.first/arr[i]);
}
for(i=curr.second+1;i<=to;i++) if(arr[i]==1) ++ans;
}
solve(from,curr.second-1);
solve(curr.second+1,to);
}
int main() {
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
int i;
tests=1;
//scanf("%d", &tests);
for(current_case=1;current_case<=tests;current_case++) {
scanf("%d", &n);
for(i=1;i<=n;i++) scanf("%d", &arr[i]),a[i]=make_pair(arr[i],i);
rmq.initialize(a,i);
ans=0;
build_tree(1,n,1);
solve(1,n);
printf("%lld\n", ans);
message(current_case);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZW5kbCAnXG4nCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE4gPSAxPDwxOTsKY29uc3QgaW50IFRSRUVfU0laRSA9IE48PDI7CgpzdHJ1Y3QgdHJlZV9ub2RlIHsKICAgIGludCAqYSxuOwogICAgdHJlZV9ub2RlKCk6IG4oMCkge30KICAgIHRyZWVfbm9kZShpbnQgaykgewogICAgICAgIG49azsKICAgICAgICBhPShpbnQqKW1hbGxvYygoc2l6ZW9mKGludCkqaykpOwogICAgfQp9OwoKc3RydWN0IG1lcmdlX21heCB7CiAgICBwYWlyIDwgaW50LCBpbnQgPiBvcGVyYXRvciAoKShjb25zdCBwYWlyIDwgaW50LCBpbnQgPiAmYSwgY29uc3QgcGFpciA8IGludCwgaW50ID4gJmIpIGNvbnN0IHsKICAgICAgICByZXR1cm4gbWF4KGEsYik7CiAgICB9Cn07Cgp0ZW1wbGF0ZSA8IGNsYXNzIFQsIGNsYXNzIE1FUkdFID4Kc3RydWN0IHNwYXJzZV90YWJsZSB7CiAgICAgICAgTUVSR0UgbWVyZ2U7CiAgICAgICAgaW50IG4sb2Zmc2V0OwogICAgICAgIFQgKipzdDsKICAgICAgICBpbnQgKmxvZzsKICAgICAgICB0ZW1wbGF0ZSA8IGNsYXNzIENPTlRBSU5FUiA+CiAgICAgICAgdm9pZCBpbml0aWFsaXplKENPTlRBSU5FUiBhcnIsIGludCBrLCBpbnQgYmFzZT0xKSB7CiAgICAgICAgICAgIGludCBjdXJyZW50X2xvZz0wLGksajsKICAgICAgICAgICAgb2Zmc2V0PShiYXNlXjEpOwogICAgICAgICAgICBuPWs7CiAgICAgICAgICAgIGxvZz0oaW50KiltYWxsb2MoKHNpemVvZihpbnQpKihuKzEpKSk7CiAgICAgICAgICAgIHN0PShUKiopbWFsbG9jKChzaXplb2YoVCopKihuKzEpKSk7CiAgICAgICAgICAgIGZvcihpPTA7aTw9bjtpKyspIHsKICAgICAgICAgICAgICAgIHdoaWxlKCgxPDwoMStjdXJyZW50X2xvZykpPD1pKSArK2N1cnJlbnRfbG9nOwogICAgICAgICAgICAgICAgbG9nW2ldPWN1cnJlbnRfbG9nOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGZvcihpPTE7aTw9bjtpKyspIHN0W2ldPShUKiltYWxsb2MoKHNp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ZGRsZTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRyZWVbbm9kZV0ubi1yaWdodDsKICAgIH0KICAgIHJldHVybiBxdWVyeV90cmVlKGEsKGErYik+PjEsaSxqLG5vZGU8PDEsdmFsdWUpK3F1ZXJ5X3RyZWUoKChhK2IpPj4xKSsxLGIsaSxqLChub2RlPDwxKXwxLHZhbHVlKTsKfQoKaW50IHF1ZXJ5KGludCBsLCBpbnQgciwgaW50IGspIHsKICAgIGlmKGw+cikgcmV0dXJuIDA7CiAgICByZXR1cm4gci1sKzEtcXVlcnlfdHJlZSgxLG4sbCxyLDEsayk7Cn0KCnZvaWQgc29sdmUoaW50IGZyb20sIGludCB0bykgewogICAgaWYoZnJvbT49dG8pIHJldHVybjsKICAgIHBhaXIgPCBpbnQsIGludCA+IGN1cnI9cm1xLnF1ZXJ5KGZyb20sdG8pOwogICAgaW50IGksbGVmdD1jdXJyLnNlY29uZC1mcm9tLHJpZ2h0PXRvLWN1cnIuc2Vjb25kOwogICAgaWYobGVmdDxyaWdodCkgewogICAgICAgIGZvcihpPWZyb207aTw9Y3Vyci5zZWNvbmQ7aSsrKSB7CiAgICAgICAgICAgIGFucys9cXVlcnkoY3Vyci5zZWNvbmQrMSx0byxjdXJyLmZpcnN0L2FycltpXSk7CiAgICAgICAgfQogICAgICAgIGZvcihpPWZyb207aTxjdXJyLnNlY29uZDtpKyspIGlmKGFycltpXT09MSkgKythbnM7CiAgICB9CiAgICBlbHNlIHsKICAgICAgICBmb3IoaT1jdXJyLnNlY29uZDtpPD10bztpKyspIHsKICAgICAgICAgICAgYW5zKz1xdWVyeShmcm9tLGN1cnIuc2Vjb25kLTEsY3Vyci5maXJzdC9hcnJbaV0pOwogICAgICAgIH0KICAgICAgICBmb3IoaT1jdXJyLnNlY29uZCsxO2k8PXRvO2krKykgaWYoYXJyW2ldPT0xKSArK2FuczsKICAgIH0KICAgIHNvbHZlKGZyb20sY3Vyci5zZWNvbmQtMSk7CiAgICBzb2x2ZShjdXJyLnNlY29uZCsxLHRvKTsKfQoKaW50IG1haW4oKSB7CiAgICAvL2lvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgLy9jaW4udGllKE5VTEwpOwogICAgaW50IGk7CgogICAgdGVzdHM9MTsKICAgIC8vc2NhbmYoIiVkIiwgJnRlc3RzKTsKICAgIGZvcihjdXJyZW50X2Nhc2U9MTtjdXJyZW50X2Nhc2U8PXRlc3RzO2N1cnJlbnRfY2FzZSsrKSB7CiAgICAgICAgc2NhbmYoIiVkIiwgJm4pOwogICAgICAgIGZvcihpPTE7aTw9bjtpKyspIHNjYW5mKCIlZCIsICZhcnJbaV0pLGFbaV09bWFrZV9wYWlyKGFycltpXSxpKTsKICAgICAgICBybXEuaW5pdGlhbGl6ZShhLGkpOwogICAgICAgIGFucz0wOwogICAgICAgIGJ1aWxkX3RyZWUoMSxuLDEpOwogICAgICAgIHNvbHZlKDEsbik7CiAgICAgICAgcHJpbnRmKCIlbGxkXG4iLCBhbnMpOwogICAgICAgIG1lc3NhZ2UoY3VycmVudF9jYXNlKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=