#K57812. Minimum Difference in Game Preferences Partition

    ID: 30504 Type: Default 1000ms 256MiB

Minimum Difference in Game Preferences Partition

Minimum Difference in Game Preferences Partition

You are given n participants, where each participant has a list of game preferences. Your task is to divide the participants into two groups of equal size (if possible) such that the absolute difference between the total number of game preferences in one group and that in the other is minimized.

If n is odd, partitioning into two equal groups is impossible, and you should output Unbalanced. Otherwise, compute the sum of the counts of preferences for each participant and choose a subset of exactly n/2 participants. The answer is the minimum value of \( |2\times S - T| \), where \(S\) is the sum of counts in one group and \(T\) is the total number of game preferences across all participants.

Note: All formulas are expressed in \( \LaTeX \) format. For example, the difference is computed as \( |2\times S - T| \).

inputFormat

The first line contains an integer n, the number of participants. Each of the following n lines begins with an integer k representing the number of game preferences, followed by k space-separated integers representing the game preferences.

outputFormat

If n is even, output a single line containing the minimum absolute difference between the total game preferences of the two groups. If n is odd, output the string Unbalanced.

## sample
4
3 1 2 3
3 2 3 4
3 1 3 5
3 2 4 6
0