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: Accepted)

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using static Sample.Settings;
using static System.Math;

namespace Sample
{
    public sealed class Program : BaseProgram
    {
        public static void Main(string[] args)
        {
            using (var sc = new SetConsole()) { Solve(); }
        }
        public static void Solve()
        {
            var n = GetNumber<int>();
            var a = GetArray(d => d.ToLong() * 2);

            long sum = 0;
            var sign = 1;
            for (int i = 0; i < n - 1; i++)
            {
                sum += a[i] * sign;
                sign *= -1;
            }

            var result = new long[n];
            result[0] = (sum + a[n - 1]) / 2;
            for (int i = 1; i < n; i++)
            {
                result[i] = a[i - 1] - result[i - 1];
            }

            Write(string.Join(" ", result));
        }
    }

    public class BaseProgram
    {
        protected static void Write<T>(T str) => Console.WriteLine(str);
        protected static string GetString() => Console.ReadLine();
        protected static T GetNumber<T>() where T : IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable
        {
            var str = GetString();
            if (str == null) { throw new NullReferenceException("標準入力がnullです Solveメソッド内の解答コードが間違っています"); }

            var t = typeof(T);
            if ((t == typeof(byte)))
            {
                return (T)(object)str.ToByte();
            }
            else if (t == typeof(int))
            {
                return (T)(object)str.ToInt();
            }
            else if (t == typeof(long))
            {
                return (T)(object)str.ToLong();
            }
            else if (t == typeof(double))
            {
                return (T)(object)str.ToDouble();
            }
            throw new NotSupportedException();
        }
        protected static T[] GetArray<T>() where T : IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable
        {
            var str = GetString();
            if (str == null) { throw new NullReferenceException("標準入力がnullです Solveメソッド内の解答コードが間違っています"); }
            return str.ToArray<T>();
        }
        protected static TResult[] GetArray<TResult>(Func<string, TResult> selector)
        {
            var str = GetString();
            if (str == null) { throw new NullReferenceException("標準入力がnullです Solveメソッド内の解答コードが間違っています"); }
            return (TResult[])(object)str.Split().Select(selector).ToArray();
        }
        protected static void Swap<T>(ref T item1, ref T item2)
        {
            var tmp = item1;
            item1 = item2;
            item2 = tmp;
        }
        protected class SetConsole : IDisposable
        {
            readonly StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
            public SetConsole()
            {
                sw.AutoFlush = false;
                Console.SetOut(sw);
            }
            public void Dispose()
            {
                Console.Out.Flush();
                sw.AutoFlush = true;
                Console.SetOut(sw);
            }
        }
    }
    static class ExtentionsLibrary
    {
        public static List<T> CopyList<T>(this IReadOnlyList<T> list) => CopyArray(list.ToArray()).ToList();
        public static T[] CopyArray<T>(this T[] array)
        {
            var newArray = new T[array.Length];
            Array.Copy(array, newArray, array.Length);
            return newArray;
        }
        public static T[,] CopyArray<T>(this T[,] array)
        {
            var firstDimentionLength = array.GetLength(0);
            var secondDimentionLength = array.GetLength(1);
            var newDArray = new T[firstDimentionLength, secondDimentionLength];
            Array.Copy(array, newDArray, firstDimentionLength * secondDimentionLength);
            return newDArray;
        }
        public static T[] ToArray<T>(this string str) where T : IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable
        {
            if (typeof(T) == typeof(string)) { return (T[])(object)str.Split(); }

            return str.ConvertEnumerator<T>().ToArray();
        }
        public static IEnumerable<T> ConvertEnumerator<T>(this string str) where T : IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable
        {
            var t = typeof(T);
            if (t == typeof(byte))
            {
                return (IEnumerable<T>)str.Split().Select(byte.Parse);
            }
            if (t == typeof(int))
            {
                return (IEnumerable<T>)str.Split().Select(int.Parse);
            }
            if (t == typeof(long))
            {
                return (IEnumerable<T>)str.Split().Select(long.Parse);
            }
            if (t == typeof(double))
            {
                return (IEnumerable<T>)str.Split().Select(double.Parse);
            }
            if (t == typeof(BigInteger))
            {
                return (IEnumerable<T>)str.Split().Select(BigInteger.Parse);
            }
            throw new NotSupportedException();
        }
        public static byte ToByte(this string str) => byte.Parse(str);
        public static byte ToByte(this char chr) => byte.Parse(chr.ToString());
        public static int ToInt(this string str) => int.Parse(str);
        public static int ToInt(this char chr) => int.Parse(chr.ToString());
        public static long ToLong(this string str) => long.Parse(str);
        public static double ToDouble(this string str) => double.Parse(str);
        public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
        public static DateTime ToDateTime(this string str) => DateTime.Parse(str);
        public static string StringJoin(this object[] array, string separator) => string.Join(separator, array);
        public static string StringJoin<T>(this IEnumerable<T> collection, string separator) => string.Join(separator, collection.Select(c => c.ToString()));
    }
    public class PriorityQueue<T> : IEnumerable<T> where T : IComparable<T>
    {
        private readonly Priority priority;
        private List<T> heap = new List<T> { default(T) };

        private PriorityQueue() { }
        public PriorityQueue(Priority p)
        {
            priority = p;
        }
        public int Count() => heap.Count - 1;
        public T Peek()
        {
            if (Count() <= 0) { throw new Exception("要素が空です"); }
            return heap[1];
        }
        public T Dequeue()
        {
            if (Count() <= 0) { throw new Exception("要素が空です"); }

            var max = heap[1];
            heap[1] = heap[heap.Count - 1];
            heap.RemoveAt(heap.Count - 1);
            MaxHeapify(1);
            return max;
        }
        public void Enqueue(T key)
        {
            HeapIncreaseKey(key);
        }
        public void EnqueueRange(IEnumerable<T> keys)
        {
            foreach (var key in keys) { HeapIncreaseKey(key); }
        }
        public void Clear()
        {
            heap = new List<T>() { default(T) };
        }
        private void MaxHeapify(int i)
        {
            int largest;
            int l = Left(i);
            int r = Right(i);

            if (l <= heap.Count - 1 && Compare(heap[i], heap[l]) < 0)
            {
                largest = l;
            }
            else
            {
                largest = i;
            }
            if (r <= heap.Count - 1 && Compare(heap[r] ,heap[largest]) > 0)
            {
                largest = r;
            }

            if (largest != i)
            {
                var temp = heap[i];
                heap[i] = heap[largest];
                heap[largest] = temp;
                MaxHeapify(largest);
            }
        }
        private void HeapIncreaseKey(T key)
        {
            heap.Add(key);
            int lastIndex = heap.Count - 1;
            while (lastIndex > 1 && Compare(heap[Parent(lastIndex)], heap[lastIndex]) < 0)
            {
                var temp = heap[lastIndex];
                heap[lastIndex] = heap[Parent(lastIndex)];
                heap[Parent(lastIndex)] = temp;
                lastIndex = Parent(lastIndex);
            }
        }
        private static int Parent(int i) => i / 2;
        private static int Left(int i) => i * 2;
        private static int Right(int i) => i * 2 + 1;
        private int Compare(T x, T y) => priority == Priority.Larger ? x.CompareTo(y) : y.CompareTo(x);
        IEnumerator<T> IEnumerable<T>.GetEnumerator() => heap.Skip(1).GetEnumerator();
        public IEnumerator GetEnumerator()
        {
            return heap.Skip(1).GetEnumerator();
        }
    }
    public class Settings
    {
        public enum Priority : byte
        {
            Smaller = 0,
            Larger = 1
        }
    }
}