##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
There are numbers written around a circle. You want to divide the circle into two non-empty contiguous parts, so that the absolute difference between the sums of the two parts is as small as possible.
More formally, you are given an array . The array is circular, so is adjacent to . A contiguous part on the circle is a non-empty sequence of consecutive elements while moving around the circle. For example, form one contiguous part.
Choose two different gaps between adjacent elements and cut the circle at those gaps. This creates two contiguous parts. Both parts must be non-empty.
Find the minimum possible absolute difference between the sums of the two parts.
The only possible division puts index in one part and index in the other part. Their sums are and , so the answer is .
Cut the circle so that indices are in one part and indices are in the other part. The two sums are and , so the answer is .
Cut the circle so that indices are in one part and indices are in the other part. The two sums are and , so the difference is . It is impossible to make the difference smaller.