#K35257. Minimum Absolute Difference of Two Subarray Sums

    ID: 25491 Type: Default 1000ms 256MiB

Minimum Absolute Difference of Two Subarray Sums

Minimum Absolute Difference of Two Subarray Sums

You are given an array of n integers. Your task is to partition the array into two contiguous non-empty subarrays and find the minimum absolute difference between the sum of the first subarray and the sum of the second subarray.

Formally, let the array be \(a_1, a_2, \dots, a_n\) and let \(S = \sum_{i=1}^{n} a_i\). For a partition at index \(k\) (where \(1 \le k < n\)), define \(P = \sum_{i=1}^{k} a_i\). The absolute difference for this partition is \(|2P - S|\). You need to find the minimum value of \(|2P - S|\) over all possible partitions.

Note: Both subarrays must be non-empty.

inputFormat

The first line contains a single integer \(n\) which denotes the number of elements in the array.

The second line contains \(n\) space-separated integers representing the elements of the array.

outputFormat

Output a single integer which is the minimum absolute difference between the sums of the two subarrays.

## sample
6
1 3 2 7 9 5
1