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. Win32汇编之其他指令

    汇编语言(assembly language)是一种用于电子计算机.微处理器.微控制器或其他可编程器件的低级语言,亦称为符号语言.在汇编语言中,用助记符(Mnemonics)代替机器指令的操作码,用地 ...

  2. Java 日志系统

    Java 日志系统 1. 创建日志记录器 private final Logger logger = LoggerFactory.getLogger(LoggerTest.class); 2. 打印日 ...

  3. Java反射理解(四)-- 获取成员变量构造函数信息

    Java反射理解(四)-- 获取成员变量构造函数信息 步骤 获取成员变量信息: obj.getClass() 获取类类型对象 成员变量也是对象,java.lang.reflect.Field 类中封装 ...

  4. the specified service is marked as deletion,can not find the file specified

    使用命令注册windows service sc create CCGSQueueService binpath= "D:\DKX4003\services\xxx.xx.xx\xxx.ex ...

  5. 修改mac系统的host文件 (一)

    hosts是本地预先配置的DNS数据,解析域名的时候首先试图从hosts文件获取,没有则从DNS服务器获取. 此文件的三个主要用途: 加快域名解析 方便局域网用户 一般局域网很少假设DNS服务器,访问 ...

  6. luogu题解P1032字串变换--BFS+STL:string骚操作

    题目链接 https://www.luogu.org/problemnew/show/P1032 分析 这题本来很裸的一个BFS,发现其中的字符串操作好烦啊.然后就翻大佬题解发现用STL中的strin ...

  7. 02 Go程序执行流程

    一.把源码编译成二进制后执行 .go代码源文件 => go build => 可执行文件(.exe文件或者linux二进制文件) => 运行结果 二.对源码直接运行 .go源代码文件 ...

  8. Java反射【一、概述】

    .net也使用过反射,不过用的比较浅显,用来记日志等.. Java基础课程学习已经过了一段时间了,接下来继续学习 本次学习包含以下内容 Java反射[一.概述] Java反射[二.Class类的使用] ...

  9. contextlib:上下文管理器工具

    介绍 contextlib模块包含的工具可以用于处理上下文管理器和with语句 上下文管理器API ''' 上下文管理器(context manager)负责管理一个代码块中的资源,会在进入代码块时创 ...

  10. 用Python+Aria2写一个自动选择最优下载方式的E站爬虫

    前言 E站爬虫在网上已经有很多了,但多数都只能以图片为单位下载,且偶尔会遇到图片加载失败的情况:熟悉E站的朋友们应该知道,E站许多资源都是有提供BT种子的,而且通常打包的是比默认看图模式更高清的文件: ...