File size: 1,458 Bytes
c4b0eef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
  >>~~ UVa Online Judge ACM Problem Solution ~~<<

  ID: 10057
  Name: A mid-summer night's dream.
  Problem: https://onlinejudge.org/external/100/10057.pdf
  Language: C++

  Author: Arash Shakery
  Email: [email protected]
*/

#include <math.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define EPS 1e-9

inline int readchar() {
    const int N = 1048576;
    static char buf[N];
    static char *p = buf, *end = buf;
    if (p == end) {
        if ((end = buf + fread(buf, 1, N, stdin)) == buf)
            return EOF;
        p = buf;
    }
    return *p++;
}


bool isdigit(char ch) { return ch>='0' && ch<='9'; }
inline unsigned int readUInt() {
    char ch;
    unsigned int r=0;
    while (!isdigit(ch=readchar()))
        if (ch == EOF) return 0;
    r = ch-'0';
    while (isdigit(ch=readchar()))
        r = (r<<3) + (r<<1) + ch-'0';
    return r;
}

// ---------------------------------------------------------------

int n, X[1000017];
int main() {
    while ((n=readUInt())) {
        for (int i=0; i<n; ++i)
            X[i] = readUInt();

        int mid = (n-1)>>1;
        nth_element(X, X+mid  , X+n);
        int a1 = X[mid], a2 = a1;
        if (n%2 == 0) {
            nth_element(X, X+mid+1, X+n);
            a2 = X[mid+1];
        }

        int cnt = 0;
        for (int i=0; i<n; ++i)
            if (X[i]==a1 || X[i]==a2)
                ++cnt;

        printf("%d %d %d\n", a1, cnt, a2-a1+1);
    }
}