Pagini recente » Cod sursa (job #2393188) | Utilizatori inregistrati la Junior Challenge 2023 Runda 1 | Cod sursa (job #2169091) | Cod sursa (job #1253999) | Cod sursa (job #1913665)
#include <cstdio>
using namespace std;
long long n, v[500001], pi[500001], k, sol;
int main()
{
freopen("reguli.in","r",stdin);
freopen("reguli.out","w",stdout);
long long i;
scanf("%lld", &n);
for(i = 0; i < n; ++i)
{
scanf("%lld", &v[i]);
}
for(i = n - 1; i > 0; --i)
{
v[i] -= v[i - 1];
}
for(i = 2; i < n; ++i)
{
while(k > 0 && v[k + 1] != v[i])
{
k = pi[k];
}
if(v[k + 1] == v[i])
{
++k;
}
pi[i] = k;
}
sol = n - 1 - pi[n - 1];
printf("%lld\n",sol);
for(i = 1; i <= sol; ++i)
{
printf("%lld\n", v[i]);
}
return 0;
}