시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB55752090168738.728%

문제

수직선에 n개의 점이 찍혀 있다. 각각의 점의 x좌표가 주어졌을 때, n2개의 모든 쌍에 대해서 거리를 더한 값을 구하는 프로그램을 작성하시오.

즉, 모든 i, j에 대해서 |x[i] - x[j]|의 합을 구하는 것이다.

입력

첫째 줄에 n(1 ≤ n ≤ 10,000)이 주어진다. 다음 줄에는 x[1], x[2], x[3], …, x[n]이 주어진다. 각각은 0 이상 1,000,000,000 이하의 정수이다.

출력

첫째 줄에 답을 출력한다.

예제 입력 1

5
1 5 3 2 4

예제 출력 1

40
W3sicHJvYmxlbV9pZCI6IjIzOTkiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWFjNzBcdWI5YWNcdWM3NTggXHVkNTY5IiwiZGVzY3JpcHRpb24iOiI8cD5cdWMyMThcdWM5YzFcdWMxMjBcdWM1ZDAgblx1YWMxY1x1Yzc1OCBcdWM4MTBcdWM3NzQgXHVjYzBkXHVkNjAwIFx1Yzc4OFx1YjJlNC4gXHVhYzAxXHVhYzAxXHVjNzU4IFx1YzgxMFx1Yzc1OCB4XHVjODhjXHVkNDVjXHVhYzAwIFx1YzhmY1x1YzViNFx1Yzg0Y1x1Yzc0NCBcdWI1NGMsIG48c3VwPjI8XC9zdXA+XHVhYzFjXHVjNzU4IFx1YmFhOFx1YjRlMCBcdWMzMGRcdWM1ZDAgXHViMzAwXHVkNTc0XHVjMTFjIFx1YWM3MFx1YjlhY1x1Yjk3YyBcdWIzNTRcdWQ1NWMgXHVhYzEyXHVjNzQ0IFx1YWQ2Y1x1ZDU1OFx1YjI5NCBcdWQ1MDRcdWI4NWNcdWFkZjhcdWI3YThcdWM3NDQgXHVjNzkxXHVjMTMxXHVkNTU4XHVjMmRjXHVjNjI0LjxcL3A+XHJcblxyXG48cD5cdWM5ODksIFx1YmFhOFx1YjRlMCBpLCBqXHVjNWQwIFx1YjMwMFx1ZDU3NFx1YzExYyB8e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PaW5nIHNlc3Npb25zLjxcL3A+XHJcbiIsImhpbnQiOiIiLCJvcmlnaW5hbCI6IjEiLCJodG1sX3RpdGxlIjoiMCIsInByb2JsZW1fbGFuZ190Y29kZSI6IkVuZ2xpc2gifV0=

출처

Olympiad > USA Computing Olympiad > 2004-2005 Season > USACO January 2005 Contest > Silver 3번

  • 문제의 오타를 찾은 사람: gojib2002