Pagini recente » Cod sursa (job #3138343) | Cod sursa (job #2061575) | Sandbox (cutiuţa cu năsip) | Cod sursa (job #1052761) | Cod sursa (job #1815371)
#include <bits/stdc++.h>
#define MMAX 500005
#define BMAX 5000
using namespace std;
typedef long long var;
ifstream fin ("reguli.in");
ofstream fout ("reguli.out");
var V[MMAX],P[MMAX],S[MMAX],e = BMAX - 1;
char buffer[BMAX + 1];
void parsare(var &x){
bool semn = 0;
while(!isdigit(buffer[e])){
if(buffer[e] == '-')
semn = 1;
if(++e == BMAX){
fin.read(buffer,BMAX);
e = 0;
}
}
x = 0;
while(isdigit(buffer[e])){
x = x * 10 + buffer[e] - '0';
if(++e == BMAX){
fin.read(buffer,BMAX);
e = 0;
}
}
if(semn == 1)
x = -x;
}
void prefix(int m){
int q = 0;
for(int i = 2; i <= m; i++){
while(q && V[i] != V[q + 1])
q = P[q];
if(V[i] == V[q + 1])
q++;
P[i] = q;
}
}
int main()
{
ios :: sync_with_stdio(false);
fin.tie(NULL);
int m;
fin >> m;
for(int i = 1; i <= m ; i++){
parsare(V[i]);
}
m--;
for(int i = 1; i <= m; i++)
V[i] = V[i + 1] - V[i];
prefix(m);
fout << m - P[m] << "\n";
for(int i = 1; i <= m - P[m]; i++)
fout << V[i] << "\n";
return 0;
}