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

#BS0000152. Giấc mộng đêm hè (A mid-summer night’s dream)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Giấc mộng đêm hè (A mid-summer night’s dream)

A mid-summer night’s dream

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

A scientist dreams of nn nonnegative integers X1,X2,…,XnX_1,X_2,\ldots,X_n. He needs an integer AA minimizing the total absolute deviation:

S(A)=∑i=1n∣Xi−A∣.S(A)=\sum_{i=1}^{n}|X_i-A|.

Several integers may achieve the minimum. Find the smallest such AA, the number of input occurrences whose values are optimal choices for AA, and the number of distinct optimal integer values, including values absent from the input.

Input

  • The first line contains nn.
  • The next line contains exactly nn nonnegative integers X1,X2,…,XnX_1,X_2,\ldots,X_n.

Output

Print three space-separated integers: the smallest optimal AA, the number of input elements whose values are optimal, and the number of distinct optimal integer values.

Subtasks

  • Subtask 1 (20 points): 1≤n≤401\le n\le40; 0≤Xi≤1000\le X_i\le100 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤1041\le n\le10^4; 0≤Xi≤50000\le X_i\le5000 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤1061\le n\le10^6; 0≤Xi<655360\le X_i<65536 for every 1≤i≤n1\le i\le n.

Examples

Example 1

Input

4
1 3 5 8

Output

3 2 3

Explanation

Sorted numbers are 1,3,5,81,3,5,8 with central values 33 and 55. Every integer A∈[3,5]A\in[3,5] yields total distance 99, while going outside this interval increases it. The three valid integers are 3,4,53,4,5, but only 33 and 55 appear in the input, with two occurrences total. The smallest choice is 33; print 3 2 3.

Example 2

Input

2
10 10

Output

10 2 1

Explanation

Both numbers equal 1010. Choosing A=10A=10 gives zero total distance, which is minimal. Both input occurrences equal this optimal value, and no other integer produces a zero total. Hence print 10 2 1.