Problem list
Log in
#usaco0054 · USACO 2011-2012 US Open Gold

Balanced Cow Subsets

Platinum II 2.0 s 256 MB

Farmer John's owns N cows (2 <= N <= 20), where cow i produces M(i) units of milk each day (1 <= M(i) <= 100,000,000). FJ wants to streamline the process of milking his cows every day, so he installs a brand new milking machine in his barn. Unfortunately, the machine turns out to be far too sensitive: it only works properly if the cows on the left side of the barn have the exact same total milk output as the cows on the right side of the barn!

Let us call a subset of cows "balanced" if it can be partitioned into two groups having equal milk output. Since only a balanced subset of cows can make the milking machine work, FJ wonders how many subsets of his N cows are balanced. Please help him compute this quantity.

Input

  • Line 1: The integer N.
  • Lines 2..1+N: Line i+1 contains M(i).

Output

The number of balanced subsets of cows.

Example 1

Input
4
1
2
3
4
Output
3

Input details: There are 4 cows, with milk outputs 1, 2, 3, and 4.

Output details: There are three balanced subsets: {1,2,3} -> {1,2},{3}; {1,3,4} -> {1,3},{4}; {1,2,3,4} -> {1,4},{2,3}.

Source
USACO 2011-2012 US Open Gold
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code