Polish version    English version  
  History of OI -> IX OI 2001/2002


 News
 About Olympic
 History of OI
XVII OI 2009/2010
XVI OI 2008/2009
XV OI 2007/2008
XIV OI 2006/2007
XIII OI 2005/2006
XII OI 2004/2005
XI OI 2003/2004
X OI 2002/2003
IX OI 2001/2002
Schedule
Problems
Stage III - results
Stage II - results
Stage I - results
Stage II
Rules
For contestants
Helpful resources
Stats
VIII OI 2000/2001
VII OI 1999/2000
VI OI 1998/1999
V OI 1997/1998
IV OI 1996/1997
III OI 1995/1996
II OI 1994/1995
I OI 1993/1994
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
IX Olimpiada Informatyczna 2001/2002

Task: wag
Author: Krzysztof Onak
Balance

III stage contest  

We have a balance at our disposal. The scales are in balance if and only if both pans are empty or the weights on each pan weigh the same in total. In the given set of weights one should find such two disjoint subsets that, after putting all the weights of one on one pan and all the weights of the other on the other pan, the scales are in balance. Moreover, we require to put on the scales the heaviest weight possible.

Task

Write a program which:
  • reads from the text file wag.in the weights of the available weights,
  • selects two disjoint sets of the weights meeting the conditions of the task,
  • writes the result to the text file wag.out.

Input

In the first line of the text file wag.in there is one integer n, 2<=n<=1 000, equal to the number available weights. In each of the following n lines there is one positive integer being the weight of one weight from the set of available weights. You may assume that all the weights weigh at most 50 000 in total.

Output

In the first line of the text file wag.out you should write two nonnegative integers p and q, separated by a single space, and denoting the numbers of weights in the first and the second set, respectively. In the second line there should be p integers separated by single spaces. They should be the weights of the weights from the first set. The third line should consist of q integers, separated by single spaces, equal to the weights of the weights from the second set.

Example

For the following input file wag.in:
4
1
1
2
7
a correct answer is in the following output file wag.out:
2 1
1 1
2

Announcement during the Contest

From all the arrangements of the weights, for which the scales keep balance, one should choose that one which contains the heaviest weight possible. In case of many such solutions only one is to be given.



Print friendly version