fork download
  1. #include<cstdio>
  2. #include<cstdlib>
  3. #include<iostream>
  4. #include<algorithm>
  5. #include<vector>
  6. #include<cstring>
  7. #include<map>
  8. #include<set>
  9. #include<stack>
  10. #include<queue>
  11. #include<string>
  12. #include<iterator>
  13. #include<string>
  14. #include<sstream>
  15. #include<cassert>
  16. #include<ctime>
  17. #include<cmath>
  18.  
  19. #define MP make_pair
  20. #define PB push_back
  21. #define X first
  22. #define Y second
  23. #define oo 2000000000
  24. #define MOD 1000000007
  25. #define LL long long int
  26. #define PII pair<int,int>
  27. #define DEBUG 0
  28.  
  29. #define trace1(x) cerr << #x << ": " << x << endl;
  30. #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
  31. #define trace3(x, y, z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
  32. #define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
  33. #define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
  34. #define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
  35.  
  36. using namespace std;
  37. LL ar[100005];
  38. LL gcd(LL a,LL b){
  39. return b ? gcd(b,a%b) : a;
  40. }
  41. int main(){
  42. int n;
  43. scanf("%d",&n);
  44. for(int i=0;i<n;i++) scanf("%I64d",&ar[i]);
  45. sort(ar,ar+n);
  46. LL ss=0,ans=0;
  47. for(int i=0;i<n;i++){
  48. ans += ((ar[i]*i) - ss);
  49. ss += ar[i];
  50. }
  51. LL num = ss + 2*ans;
  52. LL den = n;
  53. LL g = gcd(num,den);
  54. cout << num/g << " " << den/g << endl;
  55.  
  56. return 0;
  57. }
Success #stdin #stdout 0s 4128KB
stdin
3
2 3 5
stdout
22 3