Cod sursa(job #3277137)

Utilizator Andrei2454Andrei Hulubei Andrei2454 Data 15 februarie 2025 12:44:27
Problema Numarare Scor 50
Compilator cpp-64 Status done
Runda vs11_12_vine_oji_2025 Marime 0.62 kb
#include <bits/stdc++.h>
using namespace std;

ifstream fin("numarare.in");
ofstream fout("numarare.out");

int a[100005], d[100005], n;

int main()
{
    int i;
    long long cnt = 0;
    fin >> n;
    for(i = 1; i <= n; i++)
        fin >> a[i];
    if(n < 2)
    {
        fout << 0;
        return 0;
    }
    n--;
    for(i = 1; i <= n; i++)
        d[i] = a[i] - a[i+1];
    for(i = 1; i <= n; i++)
    {
        int l = i, r = i;
        while(l >= 1 && r <= n && d[l] == d[r])
        {
            cnt++;
            l--;
            r++;
        }
    }
    fout << cnt;
    return 0;
}