Pagini recente » Cod sursa (job #3256657) | Cod sursa (job #2849142) | Cod sursa (job #1895097) | Cod sursa (job #3160060) | Cod sursa (job #3277351)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("numarare.in");
ofstream fout("numarare.out");
int n, a[100005], s[100005], cnt[100005];
long long sol;
int main()
{
int i, j, st, dr, l, r;
fin >> n;
for(i = 1;i <= n;i++)
fin >> a[i];
for(i = 2;i <= n;i++)
s[i - 1] = a[i] - a[i - 1];
n--;
l = r = 1;
s[0] = 2e9;s[n + 1] = -2e9;
for(i = 1;i <= n;i++)
{
cnt[i] = max(0, min(r - i, cnt[l + (r - i)]));
while(s[i - cnt[i]] == s[i + cnt[i]])
cnt[i]++;
if(i + cnt[i] > r)
{
l = i - cnt[i];
r = i + cnt[i];
}
}
for(i = 1;i <= n;i++)
sol += cnt[i];
fout << sol << "\n";
fout.close();
return 0;
}