PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#QHD0000076. Tối ưu tích của hai tổng (Expression Again)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tối ưu tích của hai tổng (Expression Again)

Expression Again

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Consider the expression

(x1+x2+⋯+xN)⋅(y1+y2+⋯+yM).(x_1+x_2+\cdots+x_N)\cdot(y_1+y_2+\cdots+y_M).

You are given exactly N+MN+M integers, which may be negative, zero, or positive. Assign each occurrence to exactly one position: choose exactly NN numbers for the xx-sum and put the remaining exactly MM numbers in the yy-sum. Equal-valued occurrences are distinct and may be assigned separately.

For every permitted assignment, multiply the two group sums. Determine both the maximum and minimum product. The order within a group is irrelevant, but group sizes must be exact. Either group sum, and hence the product, may be negative.

Input

The first line contains positive integers N,MN,M. The second line contains N+MN+M integers, each in [−50,50][-50,50].

Output

Print the maximum product first, then the minimum product, separated by one space.

Subtasks

  • Subtask 1 (20 points): 1≤N,M≤501\le N,M\le50; N+M≤16N+M\le16; −10≤ai≤10-10\le a_i\le10; exactly NN numbers in the first group.

  • Subtask 2 (30 points): 1≤N,M≤501\le N,M\le50; N+M≤50N+M\le50; −30≤ai≤30-30\le a_i\le30; exactly NN numbers in the first group.

  • Subtask 3 (50 points): 1≤N,M≤501\le N,M\le50; N+M≤100N+M\le100; −50≤ai≤50-50\le a_i\le50; exactly NN numbers in the first group.

Examples

Example 1

Input

2 2
1 2 3 4

Output

25 21

Explanation

The total is 1010. Choosing 1,41,4 gives sums 55 and 55, product 2525 (maximum). Choosing 3,43,4 gives sums 77 and 33, product 2121 (minimum).

Example 2

Input

3 1
1 2 3 4

Output

24 9

Explanation

Choosing 1,2,31,2,3 yields 6⋅4=246\cdot4=24; choosing 2,3,42,3,4 yields 9⋅1=99\cdot1=9.

Example 3

Input

2 2
2 2 2 2

Output

16 16

Explanation

Every assignment yields sums 44 and 44, so both the maximum and minimum equal 1616.