Problem:
Score : 400 points

Problem Statement

There are N mountains in a circle, called Mountain 1, Mountain 2, ..., Mountain N in clockwise order. N is an odd number.

Between these mountains, there are N dams, called Dam 1, Dam 2, ..., Dam N. Dam i (1 \leq i \leq N) is located between Mountain i and i+1 (Mountain N+1 is Mountain 1).

When Mountain i (1 \leq i \leq N) receives 2x liters of rain, Dam i-1 and Dam i each accumulates x liters of water (Dam 0 is Dam N).

One day, each of the mountains received a non-negative even number of liters of rain.

As a result, Dam i (1 \leq i \leq N) accumulated a total of A_i liters of water.

Find the amount of rain each of the mountains received. We can prove that the solution is unique under the constraints of this problem.

Constraints

All values in input are integers.

3 \leq N \leq 10^5-1

N is an odd number.

0 \leq A_i \leq 10^9

The situation represented by input can occur when each of the mountains receives a non-negative even number of liters of rain.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print N integers representing the number of liters of rain Mountain 1, Mountain 2, ..., Mountain N received, in this order.

Sample Input 1

3
2 2 4

Sample Output 1

4 0 4

If we assume Mountain 1, 2, and 3 received 4, 0, and 4 liters of rain, respectively, it is consistent with this input, as follows:

Dam 1 should have accumulated \frac{4}{2} + \frac{0}{2} = 2 liters of water.

Dam 2 should have accumulated \frac{0}{2} + \frac{4}{2} = 2 liters of water.

Dam 3 should have accumulated \frac{4}{2} + \frac{4}{2} = 4 liters of water.

Sample Input 2

5
3 8 7 5 5

Sample Output 2

2 4 12 2 8

Sample Input 3

3
1000000000 1000000000 0

Sample Output 3

0 2000000000 0

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

// ReSharper disable ArrangeTypeMemberModifiers
// ReSharper disable ConvertIfStatementToSwitchStatement
// ReSharper disable FunctionRecursiveOnAllPaths
// ReSharper disable InconsistentNaming
// ReSharper disable InlineOutVariableDeclaration
// ReSharper disable InvertIf
// ReSharper disable JoinDeclarationAndInitializer
// ReSharper disable MemberCanBeMadeStatic.Global
// ReSharper disable MemberCanBeMadeStatic.Local
// ReSharper disable NonReadonlyMemberInGetHashCode
// ReSharper disable PossibleNullReferenceException
// ReSharper disable RedundantUsingDirective
// ReSharper disable SuggestVarOrType_BuiltInTypes
// ReSharper disable SuggestVarOrType_Elsewhere
// ReSharper disable TailRecursiveCall
// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedMember.Local
// ReSharper disable UseObjectOrCollectionInitializert

#if true && UTAKA_LOCAL

//#if false
#define UTAKA_DEBUG
#endif

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Numerics;
using System.Runtime.InteropServices;

namespace UtakaApp
{
    public partial class Program
    {
        //=========================================================================================
        // Answer
        //=========================================================================================

        public const string SiteName    = "AtCoder";
        public const string ContestName = "abc133";
        public const string ProblemName = "D";

        public void Solve()
        {
            int N = cin.ReadInt;

            long[] A = cin.ReadLongArray(N);

            long[][] table = new long[N][];
            for (int i = 0; i < N; i++)
            {
                table[i] = new long[N];
            }

            for (int i = 0; i < N; i++)
            {
                table[i][i]           = 1;
                table[i][(i + 1) % N] = 1;
            }

            long[] b = new long[N];
            for (int i = 0; i < N; i++)
            {
                b[i] = 2 * A[i];
            }

            long[] result;
            int    rank = GaussJordanMod.LinearEquation(table, b, out result);

            if (rank < 0)
            {
                throw new InvalidOperationException($"解が見つからなかった");
            }

            for (int i = 0; i < N; i++)
            {
                if (i != 0)
                {
                    cou.Write(" ");
                }

                cou.Write(b[i]);
            }

            cou.WriteLine();
        }


        /// mod p (pは素数)の掃き出し法
        public static class GaussJordanMod
        {
            /// 掃き出す
            /// rankを返す
            public static int Calc(long[][] A, int mod = 1000000007, bool isExtended = false)
            {
                int m = A.Length;
                int n = A[0].Length;

                // まずAの全要素を0以上mod未満にする
                for (int row = 0; row < m; row++)
                {
                    for (int col = 0; col < n; col++)
                    {
                        A[row][col] = (A[row][col] % mod + mod) % mod;
                    }
                }

                int rank = 0;

                for (int col = 0; col < n; col++)
                {
                    // 拡大係数行列の場合は最後の列は掃き出ししない
                    if (isExtended && col == n - 1) break;

                    // ピボットを探す
                    int pivot = -1;

                    for (int row = rank; row < m; row++)
                    {
                        if (A[row][col] != 0)
                        {
                            pivot = row;
                            break;
                        }
                    }

                    // ピボットがなかったら次の列へ
                    if (pivot == -1) continue;

                    // 行をswap
                    Swap(ref A[pivot], ref A[rank]);

                    // ピボットの値を1にする
                    long inv = ModInv(A[rank][col], mod);

                    for (int col2 = 0; col2 < n; col2++)
                    {
                        A[rank][col2] = (int)(A[rank][col2] * inv % mod);
                    }

                    // ピボットのある列の値がすべて0になるように掃き出す
                    for (int row = 0; row < m; row++)
                    {
                        if (row != rank && A[row][col] > 0)
                        {
                            long fac = A[row][col];

                            for (int col2 = 0; col2 < n; col2++)
                            {
                                A[row][col2] -= A[rank][col2] * fac % mod;

                                if (A[row][col2] < 0) A[row][col2] += mod;
                            }
                        }
                    }

                    rank++;
                }

                return rank;
            }

            public static int LinearEquation(long[][] inputA, long[] b, out long[] result, int mod = 100000007)
            {
                int m = inputA.Length;
                int n = inputA[0].Length;

                // 拡張する
                long[][] A = new long[m][];

                for (int row = 0; row < m; row++)
                {
                    long[] newRow = new long[n + 1];
                    A[row] = newRow;

                    long[] inputRow = inputA[row];

                    for (int col = 0; col < n; col++)
                    {
                        newRow[col] = inputRow[col];
                    }

                    newRow[n] = b[row];
                }

                // out引数に値を入れておく
                result = new long[m];

                // 解があるか求める
                int rank = Calc(A, mod, true);

                for (int row = rank; row < m; row++)
                {
                    if (A[row][n] > 0) return -1;
                }

                // 解を求める
                for (int row = 0; row < rank; row++)
                {
                    result[row] = A[row][n];
                }

                return rank;
            }


            /// <summary>
            /// mod.m での a の逆元 a^{-1} を求める
            /// </summary>
            public static long ModInv(long a, long m)
            {
                long b = m;
                long u = 1;
                long v = 0;

                while (b > 0)
                {
                    long t = a / b;
                    a -= t * b;
                    Swap(ref a, ref b);
                    u -= t * v;
                    Swap(ref u, ref v);
                }

                u %= m;
                if (u < 0) u += m;
                return u;
            }

            public static void Swap<T>(ref T a, ref T b)
            {
                T c = a;
                a = b;
                b = c;
            }
        }
    }


//=========================================================================================
// Library
//=========================================================================================


//=========================================================================================
// Debug IO
//=========================================================================================

    public partial class Program
    {
        //=========================================================================================
        // Main
        //=========================================================================================

        private readonly ConsoleInput cin;
        private readonly IConsole     cou;

        public Program(ConsoleInput cin, IConsole cou)
        {
            this.cin = cin;
            this.cou = cou;
        }

        public static void Main(string[] args)
        {
#if UTAKA_LOCAL
//#if false
            new TestCaseCheckerForAtCoder().TestProblems();
#else
            var cin = new ConsoleInput(System.Console.In);
            var console = new MyConsole();
            new Program(cin, console).Solve();
            console.Flush();
#endif
        }
    }

    public class ConsoleInput
    {
        private readonly char          _separator = ' ';
        private readonly TextReader    _stream;
        private readonly Queue<string> inputStream;

        public ConsoleInput(TextReader stream, char separator = ' ')
        {
            _separator  = separator;
            _stream     = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0)
                {
                    return inputStream.Dequeue();
                }

                var tmp = _stream.ReadLine().Split(_separator);
                for (var i = 0; i < tmp.Length; ++i)
                {
                    inputStream.Enqueue(tmp[i]);
                }

                return inputStream.Dequeue();
            }
        }

        public string ReadLine   => _stream.ReadLine();
        public int    ReadInt    => int.Parse(Read);
        public long   ReadLong   => long.Parse(Read);
        public double ReadDouble => double.Parse(Read);

        public string[] ReadStrArray(long N)
        {
            var ret = new string[N];
            for (long i = 0; i < N; ++i)
            {
                ret[i] = Read;
            }

            return ret;
        }

        public int[] ReadIntArray(long N)
        {
            var ret = new int[N];
            for (long i = 0; i < N; ++i)
            {
                ret[i] = ReadInt;
            }

            return ret;
        }

        public long[] ReadLongArray(long N)
        {
            var ret = new long[N];
            for (long i = 0; i < N; ++i)
            {
                ret[i] = ReadLong;
            }

            return ret;
        }
    }

    public interface IConsole
    {
        void Flush();
        void Write(object obj);
        void Write(string str);
        void WriteLine(object obj);
        void WriteLine(string str);
        void WriteLine();
    }

    public class MyConsole : IConsole
    {
        public MyConsole()
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            Console.SetOut(sw);
        }

        public void Flush()
        {
            Console.Out.Flush();
        }

        public void Write(object obj)
        {
            Write(obj.ToString());
        }

        public void Write(string str)
        {
            Console.Write(str);
        }

        public void WriteLine(object obj)
        {
            WriteLine(obj.ToString());
        }

        public void WriteLine(string str)
        {
            Console.WriteLine(str);
        }

        public void WriteLine()
        {
            Console.WriteLine();
        }
    }

#if UTAKA_LOCAL

    public class DebugConsole : IConsole
    {
        private readonly StringBuilder mSb;

        public DebugConsole()
        {
            mSb = new StringBuilder();
        }

        public void Flush()
        {
            // 何もしない
        }

        public void Write(object obj)
        {
            Write(obj.ToString());
        }

        public void Write(string str)
        {
            mSb.Append(str);
        }

        public void WriteLine(object obj)
        {
            WriteLine(obj.ToString());
        }

        public void WriteLine(string str)
        {
            mSb.AppendLine(str);
        }

        public void WriteLine()
        {
            mSb.AppendLine();
        }

        public string GetAllOutput()
        {
            return mSb.ToString();
        }
    }

#endif

#if UTAKA_LOCAL

    public class TestCaseCheckerForAtCoder
    {
        private string GetDirectoryPath()
        {
            var problemPart = string.IsNullOrEmpty(Program.ProblemName)
                ? ""
                : $"/{Program.ProblemName}";

            return
                $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}";
        }

        private string GetInputFilePath(int testCaseNumber)
        {
            return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in";
        }

        private string GetOutputFilePath(int testCaseNumber)
        {
            return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out";
        }

        public bool TestProblem(int testCaseNumber)
        {
            var inputFilePath  = GetInputFilePath(testCaseNumber);
            var outputFilePath = GetOutputFilePath(testCaseNumber);

            TextReader inputStream = new StreamReader(inputFilePath);
            var        cin         = new ConsoleInput(inputStream);

            var debugConsoleWriter = new DebugConsole();

            new Program(cin, debugConsoleWriter).Solve();

            var output = debugConsoleWriter.GetAllOutput();

            TextReader outputStream = new StreamReader(outputFilePath);
            var        outputAnswer = outputStream.ReadToEnd();

            Dbg.WriteLine(output);
            Dbg.WriteLine(outputAnswer);

            var isCorrect = output == outputAnswer;

            return isCorrect;
        }

        public void TestProblems(int targetTestCaseNumber = -1)
        {
            if (targetTestCaseNumber >= 0)
            {
                Console.WriteLine($"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!");
            }

            bool isSuccessAll = true;

            int testCaseNumber = 0;
            while (true)
            {
                testCaseNumber++;

                if (targetTestCaseNumber >= 0 && targetTestCaseNumber != testCaseNumber)
                {
                    continue;
                }

                var inputFileName = GetInputFilePath(testCaseNumber);
                if (!File.Exists(inputFileName))
                {
                    break;
                }

                Console.WriteLine($"TestCase {testCaseNumber} =====================================================");

                var result = TestProblem(testCaseNumber);

                if (result)
                {
                    Console.WriteLine("Success");
                }
                else
                {
                    isSuccessAll = false;
                    Console.WriteLine("Failure *****");
                }
            }

            if (isSuccessAll)
            {
                Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!");
            }
        }
    }

#endif

#if UTAKA_LOCAL

    public static class Dbg
    {
        public static void WriteLine(string str)
        {
            Console.WriteLine(str);
        }

        public static void Write(string str)
        {
            Console.Write(str);
        }
    }
#else
    public static class Dbg
    {
        public static void WriteLine(string str)
        {
        }

        public static void Write(string str)
        {
        }
    }

#endif
}