Pagini recente » Cod sursa (job #2481754) | Cod sursa (job #158217) | Cod sursa (job #1964927) | Cod sursa (job #2781345) | Cod sursa (job #2130929)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("numarare.in");
ofstream fout ("numarare.out");
const int Nmax = 100005;
queue < pair < int , int > > Q;
int a[Nmax] , n;
int main()
{
int x , y;
long long sol = 0;
fin >> n;
for(int i = 1 ; i <= n ; i++)
fin >> a[i];
for(int i = 1 ; i < n ; i++)
{
++sol;
Q . push({i , i + 1});
}
while(! Q . empty())
{
x = Q . front() . first;
y = Q . front() . second;
Q . pop();
if((x - 1) >= 1 && (y + 1) <= n && a[x - 1] + a[y + 1] == a[x] + a[y])
{
sol++;
Q . push({x - 1 , y + 1});
}
}
fout << sol << "\n";
fin.close();
fout.close();
return 0;
}