Tourist Problem

CodeForces - 340C

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 a1a2, ..., an. The number ak represents that the kth destination is at distance ak kilometers from the starting point. No two destinations are located in the same place.

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.

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.

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.

Input

The first line contains integer n (2 ≤ n ≤ 105). Next line contains n distinct integers a1a2, ..., an (1 ≤ ai ≤ 107).

Output

Output two integers — the numerator and denominator of a fraction which is equal to the wanted average number. The fraction must be irreducible.

Examples

Input
3
2 3 5
Output
22 3

Note

Consider 6 possible routes:

  • [2, 3, 5]: total distance traveled: |2 – 0| + |3 – 2| + |5 – 3| = 5;
  • [2, 5, 3]: |2 – 0| + |5 – 2| + |3 – 5| = 7;
  • [3, 2, 5]: |3 – 0| + |2 – 3| + |5 – 2| = 7;
  • [3, 5, 2]: |3 – 0| + |5 – 3| + |2 – 5| = 8;
  • [5, 2, 3]: |5 – 0| + |2 – 5| + |3 – 2| = 9;
  • [5, 3, 2]: |5 – 0| + |3 – 5| + |2 – 3| = 8.

The average travel distance is  =  = .

sol:小学奥数题.

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n;
ll a[N],ans=;
ll Jiec[N],Invj[N];
inline ll gcd(ll a,ll b)
{
return (b==)?a:(gcd(b,a%b));
}
int main()
{
int i;
ll S=,GG;
R(n);
for(i=;i<=n;i++) R(a[i]);
sort(a+,a+n+);
for(i=;i<=n;i++)
{
S+=a[i-];
ans+=1ll*(i-)*a[i]-S;
}
S+=a[n];
ans=1ll*(ans*2ll+S);
GG=gcd(ans,n);
W(ans/GG); Wl(n/GG);
return ;
}
/*
Input
3
2 3 5
Output
22 3 Input
4
1 5 77 2
Output
547 4 Input
40
8995197 7520501 942559 8012058 3749344 3471059 9817796 3187774 4735591 6477783 7024598 3155420 6039802 2879311 2738670 5930138 4604402 7772492 6089337 317953 4598621 6924769 455347 4360383 1441848 9189601 1838826 5027295 9248947 7562916 8341568 4690450 6877041 507074 2390889 8405736 4562116 2755285 3032168 7770391
Output
644565018 5
*/

codeforces340C的更多相关文章

随机推荐

  1. Web前端开发JQuery框架

    JQuery 是一个兼容多浏览器支持的JavaScript库,其核心理念是write less,do more(写得更少,做得更多),它是轻量级的js库,兼容CSS3还兼容各种浏览器,需要注意的是后续 ...

  2. 【其他】BootCDN

    BootCDN 稳定.快速.免费的前端开源项目 CDN 加速服务 是 Bootstrap 中文网支持并维护的前端开源项目免费 CDN 服务,致力于为 Bootstrap.jQuery.Angular. ...

  3. JS基础_质数练习,用到了标记flag

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. linux mint ubuntu 安装qq

    git clone https://gitee.com/wszqkzqk/deepin-wine-for-ubuntu.gitcd deepin-wine-for-ubuntu./install.sh ...

  5. postman传数组参数,二维数组,多维数组

    一维数组: 传递: 接收: 二维数组: 传递: 接收: 依此类推,

  6. 帝国cms 权限操作

    <? if ($classid==5 || $classid==6 || $classid==7 || $classid==8 || $classid==9 || $classid==10 || ...

  7. HTML5之动画优化(requestAnimationFrame)

    定时器setInterval实现的匀速动画为什么不是匀速? window.requestAnimationFrame() 一.定时器setInterval实现的匀速动画为什么不是匀速? 以上提问并非通 ...

  8. vue.js项目开发实战笔记001——准备工作

    1,Vue.js 是一套构建用户界面的渐进式框架. 2,Vue.js 是由尤雨溪开发出的,最早发布于2014年2月. 3,引用vue.js地址一CDN: <script src="ht ...

  9. Winfrom 简单的进度条小程序

    使用Winform空间编写简单的进度条小程序: 所需控件:Lable 标签  TextBox  文本框  progressBar  进度条控件  timer 定时器 下面是源码及效果图: /// &l ...

  10. 把json1赋值给json2,修改json2的属性,json1的属性也一起变化

    let json1 = { a: 1}let json2 = json1json2.a = 5 console.log(json1.a) // 5 console.log(json2.a) // 5 ...