340C.md (2615B)
1 Source: https://codeforces.com/problemset/problem/340/C 2 3 C. Tourist Problem 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are *n* destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The *n* destinations are described by a non-negative integers sequence *a*1, *a*2, ..., *a**n*. The number *a**k* represents that the *k*th destination is at distance *a**k* kilometers from the starting point. No two destinations are located in the same place. 22 23 Iahub wants to visit each destination only once. Note that, crossing through a destination is not considered visiting, unless Iahub explicitly wants to visit it at that point. Also, after Iahub visits his last destination, he doesn't come back to kilometer 0, as he stops his trip at the last destination. 24 25 The distance between destination located at kilometer *x* and next destination, located at kilometer *y*, is |*x* - *y*| kilometers. We call a "route" an order of visiting the destinations. Iahub can visit destinations in any order he wants, as long as he visits all *n* destinations and he doesn't visit a destination more than once. 26 27 Iahub starts writing out on a paper all possible routes and for each of them, he notes the total distance he would walk. He's interested in the average number of kilometers he would walk by choosing a route. As he got bored of writing out all the routes, he asks you to help him. 28 29 Input 30 31 The first line contains integer *n* (2 ≤ *n* ≤ 105). Next line contains *n* distinct integers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 107). 32 33 Output 34 35 Output two integers — the numerator and denominator of a fraction which is equal to the wanted average number. The fraction must be irreducible. 36 37 Examples 38 39 Input 40 41 ``` 42 3 43 2 3 5 44 ``` 45 46 Output 47 48 ``` 49 22 3 50 ``` 51 52 Note 53 54 Consider 6 possible routes: 55 56 * [2, 3, 5]: total distance traveled: |2 – 0| + |3 – 2| + |5 – 3| = 5; 57 * [2, 5, 3]: |2 – 0| + |5 – 2| + |3 – 5| = 7; 58 * [3, 2, 5]: |3 – 0| + |2 – 3| + |5 – 2| = 7; 59 * [3, 5, 2]: |3 – 0| + |5 – 3| + |2 – 5| = 8; 60 * [5, 2, 3]: |5 – 0| + |2 – 5| + |3 – 2| = 9; 61 * [5, 3, 2]: |5 – 0| + |3 – 5| + |2 – 3| = 8. 62 63 The average travel distance is  =  = .