#K37962. Minimum Partition Difference

    ID: 26093 Type: Default 1000ms 256MiB

Minimum Partition Difference

Minimum Partition Difference

You are given an array of integers. Your task is to partition the array into two non-empty subsets such that the absolute difference between the sum of the elements in the two subsets is minimized. Formally, if the two subsets are denoted by S1 and S2, you need to minimize the value:

\( |\sum_{i \in S_1} a_i - \sum_{j \in S_2} a_j| \)

This is a classic partition problem that can be solved using dynamic programming. Note that the whole array must be partitioned into exactly two subsets and both subsets should be non-empty.

inputFormat

The first line of input consists of a single integer n (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 subsets.

## sample
4
1 6 11 5
1

</p>