Pagini recente » Cod sursa (job #2605246) | Cod sursa (job #2786389) | Cod sursa (job #3188033) | Cod sursa (job #3202978)
// #include <iostream>
#include <fstream>
#include <climits>
using namespace std;
ifstream cin("reguli.in");
ofstream cout("reguli.out");
long long a[500002],n,m;
long long lps[500002];
int main()
{
cin >> n;
long long x, y;
cin >> x;
for (int i = 1; i < n; i++)
{
cin >> y;
a[m++] = y - x;
x = y;
}
long long q = 0;
long long l = 0;
for (int i = 2; i <= m; i++)
{
while (q && a[q] != a[i - 1])
q=lps[q-1];
if (a[q] == a[i - 1])
q++;
lps[i] = q;
}
cout << m-1-lps[m-1] << '\n';
for (int i = 0; i < m - 1 - lps[m - 1]; i++)
cout << a[i] << '\n';
return 0;
}