Pagini recente » Cod sursa (job #3184457) | Cod sursa (job #2935422) | pla | Cod sursa (job #468969) | Cod sursa (job #2539662)
#include <fstream>
using namespace std;
ifstream cin("numarare.in");
ofstream cout("numarare.out");
int main(){
int n;
cin>>n;
int l1[n], d[n];
for(int x = 0;x<n;x++)
cin>>l1[x];
for(int x = 0, l = 0, r = -1;x<n;x++){
int k;
if(x > r){
k = 0;
}else k = min(d[l + r - x + 1], r - x + 1);
while((x - k) && ((x + k) < n) && ((l1[x - k - 1] + l1[x + k]) == (l1[x - 1] + l1[x])))
k++;
d[x] = k--;
if((x + k) > r){
l = x - k - 1;
r = x + k;
}
}
long long int res = 0;
for(int x = 0;x<n;x++)
res += d[x];
cout<<res<<endl;
return 0;
}