using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace B_DDCC2020
{
    class MainClass
    {

        static int[] n;
        static long[] s;
        public static void Main(string[] args)
        {
            n = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            s = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);
            var sl = new List<long>();
            long a = 0;
            for (int i = 0; i < n[0]; i++)
            {
                a += s[i];
                sl.Add(a);
            }
            long sum = sl[n[0] - 1];
            long mid = sl[n[0] - 1] / 2;
            long ans = 0;
            //           WriteLine(idx);
            int idx = sl.BinarySearch(mid);
            //WriteLine(idx);
            int eod = (int)sum % 2;
            if (eod == 0)
            {
                if (idx >= 0)
                {
                    WriteLine(0);
                    return;

                }
                else
                {
                    idx = -idx;
                    idx--;
                    if (idx == 0)
                    {
                        ans = Abs(sum - sl[idx] - sl[idx]);
                        WriteLine(ans);
                        return;
                    }
                    else if (idx == n[0] - 1)
                    {
                        ans = Abs(sum - s[idx] - s[idx]);
                        WriteLine(ans);
                        return;
                    }
                    else
                    {
                        if (Abs(sl[idx] - mid) < Abs(sl[idx - 1] - mid))
                        {
                            ans = Abs(sum - sl[idx] - sl[idx]);
                            WriteLine(ans);
                            return;
                        }
                        else
                        {
                            idx = idx - 1;
                            ans = Abs(sum - sl[idx] - sl[idx]);
                            WriteLine(ans);
                            return;
                        }
                    }
                }
            }
            else
            {
                if (idx >= 0)
                {
                    WriteLine(1);
                    return;

                }
                else
                {
                    idx = -idx;
                    idx--;
                    if (idx == 0)
                    {
                        ans = Abs(sum - sl[idx] - sl[idx]);
                        WriteLine(ans);
                        return;
                    }
                    else if (idx == n[0] - 1)
                    {
                        ans = Abs(sum - s[idx] - s[idx]);
                        WriteLine(ans);
                        return;
                    }
                    else
                    {
                        if (Abs(sl[idx] - mid) <= Abs(sl[idx - 1] - mid))
                        {
                            ans = Abs(sum - sl[idx] - sl[idx]);
                            WriteLine(ans);
                            return;
                        }
                        else
                        {
                            idx = idx - 1;
                            ans = Abs(sum - sl[idx] - sl[idx]);
                            WriteLine(ans);
                            return;
                        }
                    }

                }
            }
        }
    }
}


Measured memory_bytes: 40912