Candies

Time limit1sMemory limit128 MB

Summary
Given N bags of candies, choose which bag's count to replace with a new positive value so the number of distinct subset sums is maximized, breaking ties by smallest P then smallest Q.
Level

Medium6 of 10

Topics
Dynamic programming, Brute force, Array
Solved
No attempts yet

Problem

Kristian runs a shop that sells candy in prepackaged bags. He has NN bags, and bag ii holds BiB_i candies. When a customer asks for exactly KK candies, Kristian must hand over a set of whole bags whose candy counts add up to exactly KK; if no set of bags sums to KK, he cannot serve that request.

Call a positive integer KK servable if some non-empty subset of the bags sums to KK. The number of distinct options Kristian can offer is the number of distinct servable values KK.

To please more customers, Kristian opens exactly one bag and changes how many candies it holds. If he opens a bag that currently holds PP candies, he may refill it with any positive integer QQ of candies. He wants to choose the bag (identified by its current count PP) and the new amount QQ so that the number of distinct options afterwards is as large as possible.

Input

The first line contains one integer NN (2≤N≤1002 \le N \le 100).

The second line contains NN integers B1,B2,…,BNB_1, B_2, \dots, B_N (1≤Bi≤70001 \le B_i \le 7000) separated by single spaces — the number of candies in each bag.

Output

Print two integers PP and QQ separated by a single space: Kristian should take a bag that currently holds PP candies and change its contents to QQ candies. PP must be equal to one of the BiB_i, and QQ must be a positive integer.

If several choices reach the maximum possible number of distinct options, print the one with the smallest PP; if a tie still remains, print the smallest QQ. It is guaranteed that at least one such change strictly increases the number of distinct options.

Examples3

  1. Example 1

    Input
    4
    1 3 4 4
    
    Expected output
    4 9
    
  2. Example 2

    Input
    5
    3 3 3 3 3
    
    Expected output
    3 1
    
  3. Example 3

    Input
    3
    2 2 2
    
    Expected output
    2 1