using System;
using System.Linq;
public class Program
{
public static int solution(int[] A)
long minDiff = long.MaxValue; //set max possible value!
long rightSum = A.Sum(); //Total the array contents
long leftSum = 0L;
for (var i = 0; i < A.Length - 1; i++)
leftSum += A[i]; //add to left (0)
rightSum -= A[i]; //subtract from right (total)
long currentDiff = Math.Abs(rightSum - leftSum); //subtract, ensuring a positive number at all times
if (minDiff > currentDiff)
minDiff = currentDiff; //update with the smallest number
}
return (int)minDiff;
public static void Main()
Console.WriteLine(solution(new int[]
3, 1, 4, 7
));