Under construction

Still being built. Things may change

Equal Subset Sums (Small)

Time limit5sMemory limit512 MB

Summary
For each set of 20 distinct numbers, print two different non-empty subsets with equal sum in code order, or Impossible.
Level

Medium5 of 10

Topics
Brute force, Hash map
Solved
No attempts yet

Problem

You are given a set SS of NN distinct positive integers. Find two non-empty subsets of SS that are different and whose elements add up to the same sum.

A subset is a set built only from elements of SS. Two subsets are different when they do not hold exactly the same elements. The two subsets may share elements.

Input

The first line holds the number of test cases TT. Each of the next TT lines holds one test case. A line starts with NN, the number of elements of SS, followed by the NN distinct positive integers of SS on the same line.

Limits

  • 1≤T≤101 \le T \le 10
  • NN is exactly 2020.
  • Every element of SS is a positive integer smaller than 10510^5.
  • No two elements of SS are equal.

Output

For each test case, first print one line holding "Case #x:", where x is the case number starting from 1.

If two different subsets with the same sum exist, print them on the next two lines, one subset per line. On each line print the elements of that subset in increasing order, separated by single spaces. If no such pair exists, print "Impossible" on a single line.

Several pairs can satisfy the condition, so exactly one pair counts as correct. Write the elements of SS in increasing order as s1<s2<⋯<s20s_1 < s_2 < \cdots < s_{20}, and give a non-empty subset AA the code code⁡(A)=∑si∈A2i−1\operatorname{code}(A) = \sum_{s_i \in A} 2^{i-1}. Among all pairs of different subsets with the same sum, take the pair whose larger code is smallest; if several pairs remain, take the one whose smaller code is smallest. Print the subset with the smaller code first.

Examples2

  1. Example 1

    Input
    2
    20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
    20 120 266 858 1243 1657 1771 2328 2490 2665 2894 3117 4210 4454 4943 5690 6170 7048 7125 9512 9600
    
    Expected output
    Case #1:
    1 2
    3
    Case #2:
    1243 1771
    120 2894
    
  2. Example 2

    Input
    1
    20 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71
    
    Expected output
    Case #1:
    2 3
    5