CON - Vòng tròn số
Tác giả: ll931110
Ngôn ngữ: Pascal
Program MCON;
Const
input = '';
output = '';
maxn = 100000;
Var
a,b: array[1..maxn] of int64;
n: longint;
Procedure init;
Var
f: text;
i: longint;
Begin
Assign(f, input);
Reset(f);
Readln(f, n);
For i:= 1 to n do read(f, b[i]);
Close(f);
End;
Procedure solve;
Var
i,k: longint;
sum,sum1,sum2: int64;
Begin
sum:= 0;
For i:= 1 to n do sum:= sum + b[i];
sum:= sum div 3;
If n mod 3 = 0 then
Begin
a[1]:= 0;
a[2]:= 0;
For i:= 2 to n - 1 do
a[i + 1]:= b[i] - a[i] - a[i - 1];
End
else if n mod 3 = 1 then
Begin
sum1:= 0;
k:= 2;
While k <= n do
Begin
sum1:= sum1 + b[k];
k:= k + 3;
End;
a[n]:= sum - sum1;
sum2:= 0;
k:= 3;
While k <= n do
Begin
sum2:= sum2 + b[k];
k:= k + 3;
End;
a[1]:= sum - sum2;
a[2]:= b[1] - a[1] - a[n];
For i:= 2 to n - 2 do
a[i + 1]:= b[i] - a[i] - a[i - 1];
End
else
Begin
sum1:= 0;
k:= 4;
While k <= n do
Begin
sum1:= sum1 + b[k];
k:= k + 3;
End;
a[3]:= b[2] - (sum - sum1);
sum2:= 0;
k:= 3;
While k <= n do
Begin
sum2:= sum2 + b[k];
k:= k + 3;
End;
a[2]:= b[1] - (sum - sum2);
a[1]:= b[2] - a[3] - a[2];
For i:= 3 to n - 1 do
a[i + 1]:= b[i] - a[i] - a[i - 1];
End;
End;
Procedure printresult;
Var
f: text;
i: longint;
Begin
Assign(f, output);
Rewrite(f);
For i:= 1 to n do write(f, a[i], ' ');
Close(f);
End;
Begin
init;
solve;
printresult;
End.