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

#BS0000406. Trung bình và trung vị (Average and Median)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Trung bình và trung vị (Average and Median)

Average and Median

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Takahashi has nn cards in a row, with integer AiA_i on card ii. He chooses cards so that every adjacent pair contains at least one chosen card. Determine separately the greatest arithmetic mean and the greatest median of the chosen values. The two optima need not use the same selection. For mm chosen cards, the median is the value at position ⌈m/2⌉\lceil m/2\rceil after sorting in nondecreasing order.

Input

Line 1 contains integer nn. Line 2 contains nn integers A1,…,AnA_1,\ldots,A_n.

Output

Print two lines: the greatest mean, with absolute or relative error at most 10−310^{-3}, then the greatest median as an exact integer.

Subtasks

  • Subtask 1 (20 points): 2≤n≤162\le n\le 16; 1≤Ai≤1091\le A_i\le10^9 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 2≤n≤20002\le n\le 2000; 1≤Ai≤1091\le A_i\le10^9 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 2≤n≤1000002\le n\le 100000; 1≤Ai≤1091\le A_i\le10^9 for every 1≤i≤n1\le i\le n.

Examples

Input

6
2 1 2 1 1 10

Output

4
2

Explanation

Cards 2, 4 and 6 give mean 4. With m≥4m\ge4 cards, the sum is at most 10+2+2+(m−3)10+2+2+(m-3), giving a mean below 4. The four valid three-card choices are (1,3,5)(1,3,5), (2,3,5)(2,3,5), (2,4,5)(2,4,5) and (2,4,6)(2,4,6); only the last includes 10. Cards 1, 3, 5 and 6 yield sorted values 1,2,2,101,2,2,10 with median 2. A greater median is impossible because only one card exceeds 2 and at least three must be chosen.