Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the i^{th} subject has c_{i} chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.

Let us say that his initial per chapter learning power of a subject is x hours. In other words he can learn a chapter of a particular subject in x hours.

Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour.

You can teach him the n subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy.

Please be careful that answer might not fit in 32 bit data type.


-----Input-----

The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 10^5). The next line will contain n space separated integers: c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^5).


-----Output-----

Output a single integer representing the answer to the problem.


-----Examples-----
Input
2 3
4 1

Output
11

Input
4 2
5 1 2 1

Output
10

Input
3 3
1 1 1

Output
6



-----Note-----

Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours.

Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours. Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours.

So overall, minimum of both the cases is 11 hours.

Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours.

Source: codeforces | Difficulty: EASY
Tags: Sorting

Implementation


Solutions:
(n, x) = map(int, input().split())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in l:
	ans += i * x
	x -= 1
	x = max(1, x)
print(ans)


(n, x) = map(int, input().split())
p = [int(x) for x in input().split()]
p = sorted(p)
s = 0
for i in range(0, n):
	s += x * p[i]
	if x > 1:
		x -= 1
print(s)


(n, x) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()

def min_hour(n, x, c):
	result = 0
	i = 0
	while i < n:
		if i == 0:
			time = x
		elif time != 1:
			time -= 1
		else:
			time = 1
		result += c[i] * time
		i += 1
	return result
print(min_hour(n, x, c))


(n, x) = map(int, input().split())
c = [int(i) for i in input().split()]
c.sort()
res = 0
for i in c:
	res += x * i
	if x > 1:
		x -= 1
print(res)


from sys import stdin
(n, x) = map(int, input().split())
a = sorted(list(map(int, stdin.readline().split())))
val = 0
for i in a:
	val += i * x
	x = max(x - 1, 1)
print(val)


(n, x) = input().split(' ')
l = input().split(' ')
x = int(x)
total = 0
for i in range(len(l)):
	l[i] = int(l[i])
l.sort()
for i in l:
	total += int(i) * x
	if x == 1:
		continue
	x -= 1
print(total)


n = input().split(' ')
c = input().split(' ')
for i in range(len(c)):
	c[i] = int(c[i])
c.sort()
sum = 0
for i in range(len(c)):
	sum += c[i] * int(n[1])
	if int(n[1]) > 1:
		n[1] = int(n[1]) - 1
print(sum)


(n, x) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
res = 0
learn_time = x
for i in range(n):
	res += c[i] * learn_time
	if learn_time > 1:
		learn_time -= 1
print(res)


(n, x) = list(map(int, input().split()))
cs = sorted(map(int, input().split()))
summa = 0
for c in cs:
	summa += x * c
	x = x - 1 if x - 1 >= 1 else 1
print(summa)


(n, x) = input().split()
(n, x) = (int(n), int(x))
lis = input().split()
for i in range(n):
	lis[i] = int(lis[i])
lis = sorted(lis)
s = 0
if n >= x:
	for i in range(x - 1):
		s += lis[i] * (x - i)
	for i in range(x - 1, n):
		s += lis[i]
else:
	for i in range(n):
		s += lis[i] * (x - i)
print(s)


(n, x) = map(int, input().split())
l = sorted(list(map(int, input().split())))
ans = 0
for i in range(n):
	ans += l[i] * x
	x -= 1
	if x <= 0:
		x = 1
print(ans)


(n, t) = map(int, input().split())
a = sorted(map(int, input().split()))
count = 0
for i in range(0, n):
	if t > 1:
		count += t * a[i]
		t -= 1
	else:
		count += a[i]
print(count)


def main():
	(n, x) = map(int, input().strip().split())
	cc = list(map(int, input().strip().split()))
	cc.sort()
	return sum((max(x - i, 1) * c for (i, c) in enumerate(cc)))
print(main())


(n, x) = map(int, list(input().split()))
c = list(map(int, list(input().split())))
c = sorted(c)
s = 0
for i in range(n):
	s += c[i] * x
	if x != 1:
		x -= 1
print(s)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, x) = map(int, input().split())
l = sorted(list(map(int, input().split())))
ans = 0
for i in l:
	ans += x * i
	if x > 1:
		x -= 1
print(ans)


(_, x) = map(int, input().split())
c = sorted(list(map(int, input().split())))
r = 0
for i in c:
	r += i * x
	x = max(1, x - 1)
print(r)


import sys

def ints_input():
	return [int(i) for i in sys.stdin.readline().strip('\n').split(' ')]

def print_list(arr):
	sys.stdout.writelines((str(x) + ' ' for x in arr))
	sys.stdout.write('\n')

def fast_input(type=str):
	return type(sys.stdin.readline().strip('\n'))
(n, x) = ints_input()
a = ints_input()
a.sort()
ans = 0
for i in range(n):
	ans += a[i] * x
	if x > 1:
		x -= 1
print(ans)


def main():
	(n, m) = map(int, input().split())
	tab = list(map(int, input().split()))
	tab.sort()
	co = tab[0] * m
	for x in range(1, n):
		if m - x >= 1:
			co += tab[x] * (m - x)
		else:
			co += tab[x]
	print(co)
main()


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
time = 0
i = 0
while i < n:
	if x > 1:
		time += x * a[i]
		x -= 1
	else:
		time += a[i]
	i += 1
print(time)


def DumpGuy(n, c):
	c.sort()
	result = 0
	for i in range(len(c)):
		result += c[i] * n[1]
		n[1] = n[1] - 1
		if n[1] < 1:
			n[1] = 1
	return result
n = [int(x) for x in input().split()]
c = [int(y) for y in input().split()]
print(DumpGuy(n, c))


(n, x) = map(int, input().split())
t = list(map(int, input().split()))
t.sort()
p = 0
for k in range(n):
	p += t[k] * x
	if x > 1:
		x -= 1
	else:
		x = 1
print(p)


(n, x) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
ans = 0
for val in arr:
	ans += val * (x if x > 0 else 1)
	x -= 1
print(ans)


(n, x) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
a.sort()
i = 0
res = 0
while i < n:
	res += a[i] * x
	if x > 1:
		x -= 1
	i += 1
print(res)


from sys import stdin
inFile = stdin
tokens = []
tokens_next = 0

def next_str():
	global tokens, tokens_next
	while tokens_next >= len(tokens):
		tokens = inFile.readline().split()
		tokens_next = 0
	tokens_next += 1
	return tokens[tokens_next - 1]

def nextInt():
	return int(next_str())
n = nextInt()
x = nextInt()
a = [nextInt() for i in range(n)]
a.sort()
print(sum((a[i] * max(x - i, 1) for i in range(len(a)))))


def inp():
	return map(int, input().split())

def arr_inp():
	return [int(x) for x in input().split()]
(n, x) = inp()
c = arr_inp()
c.sort()
ans = c[0] * x
for i in c[1:]:
	if x > 1:
		x -= 1
	ans += i * x
print(ans)


(n, t) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
t1 = 0
for i in range(n):
	if t > 1:
		t1 = t1 + a[i] * t
		t -= 1
	else:
		t1 = t1 + a[i]
print(t1)


(n, x) = map(int, input().split())
a = sorted(list(map(int, input().split())))
sum1 = 0
for i in range(0, len(a)):
	if x > 1:
		sum1 = sum1 + a[i] * x
		x = x - 1
	else:
		sum1 = sum1 + a[i]
print(sum1)


(n, x) = list(map(int, input().split()))
chapters = list(map(int, input().split()))
chapters.sort()
result = 0
for i in range(n):
	result += chapters[i] * x
	if x != 1:
		x -= 1
print(result)


(n, x) = map(int, input().split())
problems = sorted(list(map(int, input().split())))
res = 0
for p in problems:
	res += x * p
	if x != 1:
		x -= 1
	else:
		x = 1
print(res)


import sys
array1 = input()
array2 = input()
array1 = [int(x) for x in array1.split()]
array2 = [int(x) for x in array2.split()]
num_of_array = array1[0]
x = array1[1]
array2 = sorted(array2)
result = []
for i in range(num_of_array):
	hours = x - i
	if hours < 1:
		hours = 1
	result.append(array2[i] * hours)
print(sum(result))


(n, x) = map(int, input().split())
nums = list(map(int, input().split()))
nums.sort()
time = 0
for num in nums:
	time += num * x
	if x > 1:
		x -= 1
print(time)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a = list(sorted(a))
for i in range(n):
	a[i] *= k
	k -= 1
	k = max(k, 1)
print(sum(a))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
p = 0
for i in range(n):
	p += m * a[i]
	if m > 1:
		m -= 1
print(p)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
total = 0
for i in range(n):
	if m == 1:
		for j in range(i, n):
			total += l[j]
		break
	else:
		total += l[i] * m
		m -= 1
print(total)


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
ans = 0
(a, b) = (b, a)
for i in l:
	ans += i * a
	if a > 1:
		a -= 1
print(ans)


import sys
import io
import os
total = 0
failed = 0

def debug(*args):
	if 'LOCALTEST' in os.environ:
		print(*args, file=sys.stderr)

def run(test, res):
	x = io.StringIO()
	with io.StringIO(test) as sys.stdin:
		with x as sys.stdout:
			work()
			z = x.getvalue().strip()
	sys.stdout = sys.__stdout__
	print('Passed?', z == res)
	print('Expected: ', res)
	print('Actual  : ', z)
	global total, failed
	total += 1
	failed += 1 if z != res else 0

def work():
	(n, w) = map(int, input().split())
	f = list(map(int, input().split()))
	f.sort()
	s = 0
	for z in f:
		s += max(1, w) * z
		w -= 1
	print(s)

def test():
	run('2 3\n4 1', '11')
	run('4 2\n5 1 2 1', '10')
	run('3 3\n1 1 1', '6')
if 'LOCALTEST' in os.environ:
	test()
	print('\n Result: %s (%d total, %d failed)' % ('FAILED' if failed > 0 else 'PASSED', total, failed))
else:
	work()


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
(n, x) = mp()
arr = lmp()
arr.sort()
ans = 0
for i in arr:
	ans += i * x
	x = max(1, x - 1)
print(ans)


def main():
	rd = lambda : map(int, input().split())
	(n, x) = rd()
	arr = list(rd())
	arr.sort()
	cnt = 0
	for item in arr:
		cnt += x * item
		if x > 1:
			x -= 1
	print(cnt)
main()


(n, x) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
count = 0
for i in range(n):
	count += x * arr[i]
	if x >= 2:
		x = x - 1
print(count)


(n, p) = map(int, input().split())
ar = list(map(int, input().split()))
ar.sort()
ans = 0
for a in ar:
	ans += a * p
	if p > 1:
		p -= 1
print(ans)


(n, x) = map(int, input().split())
c = sorted(map(int, input().split()))
ans = 0
for i in range(n):
	if x == 0:
		x += 1
	ans += c[i] * x
	x -= 1
print(ans)


(number_of_subjects, learning_hour) = map(int, input().split())
chapters_each_subject = list(map(int, input().split()))
chapters_each_subject.sort()
total_time = 0
for subject in chapters_each_subject:
	total_time += subject * learning_hour
	learning_hour = max(1, learning_hour - 1)
print(total_time)


a = list(map(int, input().split(' ')))
subject = a[0]
hours = a[1]
chapters = list(map(int, input().split(' ')))
chapter = sorted(chapters)
s = 0
result = 0
while s < subject:
	result += chapter[s] * hours
	if hours > 1:
		hours -= 1
	else:
		hours = 1
	s += 1
print(result)


t = input().split()
n = int(t[0])
x = int(t[1])
t = [int(x) for x in input().split()]
t.sort()
slon = 0
for i in range(n):
	slon += t[i] * x
	x = x - 1 or 1
print(slon)


first_line = list(map(int, input().split()))
n = first_line[0]
x = first_line[1]
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in a:
	ans += i * x
	if x != 1:
		x -= 1
print(ans)


from collections import Counter
import string
import math
import sys

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(number_of_variables):
	if number_of_variables == 1:
		return int(sys.stdin.readline())
	if number_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
mod = 100000007
(n, x) = vary(2)
num = array_int()
num.sort()
ans = 0
for i in range(n):
	if x < 1:
		x = 1
	ans += num[i] * x
	x -= 1
print(ans)


INPUT = lambda : list(map(int, input().split()))
(n, x) = INPUT()
c = sorted(INPUT())
result = 0
for i in c:
	result += i * x
	x = max(x - 1, 1)
print(result)


(n, x) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
sum = 0
for i in c:
	sum += i * x
	if x > 1:
		x -= 1
print(sum)


(n, x) = [int(i) for i in input().split()]
arr = sorted([int(i) for i in input().split()])
ans = 0
for i in arr:
	if x > 1:
		ans += i * x
		x -= 1
	else:
		ans += i
print(ans)


n1 = input().split()
n2 = input().split()
(n, x) = (int(i) for i in n1)
arr = [int(i) for i in n2]
arr = sorted(arr)
res = 0
for i in range(n):
	res = res + arr[i] * x
	if x > 1:
		x -= 1
print(res)


nx = input().split()
(n, x) = (int(nx[0]), int(nx[1]))
arr = list(map(int, input().split()))
arr = sorted(arr)
h = 0
for i in range(n):
	h += arr[i] * x
	x = max(x - 1, 1)
print(h)


def selfLearning(subjects, x):
	subjects.sort()
	min_time = 0
	for subject in subjects:
		min_time += subject * x
		if x > 1:
			x -= 1
	return min_time
(n, x) = map(int, input().split())
subjects = list(map(int, input().split()))
result = selfLearning(subjects, x)
print(result)


(n, x) = map(int, input().split())
listsub = sorted(map(int, input().split()))
ketqua = 0
for i in listsub:
	ketqua += i * x
	x = max(x - 1, 1)
print(ketqua)


(n, x) = map(int, input().rstrip().split())
s = 0
arr = sorted(list(map(int, input().rstrip().split())))
for (i, e) in enumerate(arr):
	if x - i >= 1:
		s += (x - i) * e
	else:
		s += e
print(s)


(m, n) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
i = n
x = 0
for i in range(n):
	if i < m:
		x = x + a[i] * (n - i)
	else:
		break
if n < m:
	x = x + sum(a[n:m])
print(x)


(n, x) = map(int, input().split())
c = sorted(map(int, input().split()))
t = 0
for i in c:
	t += x * i
	if x > 1:
		x -= 1
print(t)


(n, x) = map(int, input().split())
Array = list(map(int, input().split()))
Array = sorted(Array, reverse=False)
time = 0
for item in Array:
	time += item * x
	if x > 1:
		x -= 1
print(time)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def abs(x):
	return x if x >= 0 else -x

def sumelem(x, start, end):
	sum = 0
	for i in range(start, end + 1):
		sum += x[i]
	return sum
cnt = set()
for t in range(1):
	(n, x) = list(map(int, input().split()))
	sub = list(map(int, input().split()))
	sub.sort()
	x += 1
	sumi = 0
	for i in sub:
		if x > 1:
			x -= 1
		sumi += x * i
	print(sumi)


(n, h) = map(int, input().split())
lec = list(map(int, input().split()))
lec = sorted(lec)
total = 0
for i in lec:
	total += i * h
	if h > 1:
		h -= 1
print(total)


k = list(map(int, input().split()))
n = k[0]
x = k[1]
a = list(map(int, input().split()))
sort = sorted(a)
total = 0
for value in sort:
	total += value * x
	if x > 1:
		x -= 1
print(total)


(n, x) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
ans = 0
for i in range(n):
	ans += x * c[i]
	if x > 1:
		x -= 1
	else:
		x = 1
print(ans)


(n, m) = map(int, input().strip().split(' '))
arr = list(map(int, input().strip().split(' ')))
arr.sort()
tota = 0
for i in arr:
	if m != 1:
		tota += i * m
		m -= 1
	else:
		tota += i
print(tota)


n = list(map(int, input().rstrip().split()))
chapters = list(map(int, input().rstrip().split()))
chapters.sort()
time = n[1]
ans = 0
for i in chapters:
	if time > 1:
		ans += time * i
		time -= 1
	else:
		ans += i
print(ans)


(n, x) = map(int, input().split())
nss = [int(i) for i in input().split()]
nss = sorted(nss)
hours = 0
i = 0
while i < len(nss):
	if x != 1:
		hours += nss[i] * x
		x -= 1
	else:
		break
	i += 1
print(hours + sum(nss[i:]))


(n, x) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
res = 0
for i in range(n):
	res += max(1, x - i) * a[i]
print(res)


sa = input().split(' ')
subjs = int(sa[0])
time = int(sa[1])
sa2 = input().split(' ')
sa3 = []
for item in sa2:
	sa3.append(int(item))
sa3.sort()
tot = 0
for thing in sa3:
	tot += thing * time
	if time != 1:
		time -= 1
print(tot)


import sys
(n, x) = map(int, sys.stdin.readline().split())
c = sorted(map(int, sys.stdin.readline().split()))
xl = [max(x - i, 1) for i in range(n)]
ans = sum([i * j for (i, j) in zip(c, xl)])
print(ans)


(n, x) = list(map(int, input().split()))
c = list(map(int, input().split()))
c.sort()
time = 0
for ci in c:
	time += x * ci
	x = max(x - 1, 1)
print(time)


(n, x) = map(int, input().split())
subj = list(map(int, input().split()))
subj = sorted(subj)
ans = 0
for s in subj:
	ans += x * s
	if x > 1:
		x -= 1
print(ans)


(n, k) = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
sum = 0
a.sort()
for i in range(n):
	sum += a[i] * k
	k = k - 1
	k = max(k, 1)
print(sum)


import sys
f = sys.stdin
(n, x) = map(int, f.readline().strip().split())
c = list(map(int, f.readline().strip().split()))
c.sort()
time = 0
for i in c:
	time += i * x
	x -= 1 if x > 1 else 0
print(time)


(n, x) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
s = 0
for i in range(n):
	s += x * l[i]
	if x > 1:
		x -= 1
print(s)


from collections import deque as de
import math
import re
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb
from fractions import Fraction as fr
from bisect import bisect_left as bl, bisect_right as br

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binarytodecimal(n):
	return int(n, 2)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def getProduct(n):
	product = 1
	while n != 0:
		product = product * (n % 10)
		n = n // 10
	return product

def dupconscount(nums):
	element = []
	freque = []
	if not nums:
		return element
	running_count = 1
	for i in range(len(nums) - 1):
		if nums[i] == nums[i + 1]:
			running_count += 1
		else:
			freque.append(running_count)
			element.append(nums[i])
			running_count = 1
	freque.append(running_count)
	element.append(nums[i + 1])
	return (element, freque)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def ceildiv(x, y):
	return (x + y - 1) // y

def di():
	return map(int, input().split())

def ii():
	return int(input())

def li():
	return sorted(list(map(int, input().split())))

def si():
	return list(map(str, input()))

def indic():
	dic = {}
	for (index, value) in enumerate(input().split()):
		dic[int(index) + 1] = int(value)
	return dic
(n, x) = di()
c = li()
ans = x * c[0]
for i in range(1, n):
	x -= 1
	if x < 1:
		x = 1
	ans += x * c[i]
print(ans)


(n, x) = map(int, input().split())
dis = list(map(int, input().split()))
dis.sort()
time = 0
for c in dis:
	time += c * x
	if x != 1:
		x -= 1
print(time)


(n, x) = map(int, input().split())
l = sorted(map(int, input().split()))
ans = 0
for i in range(n):
	ans += l[i] * max(x - i, 1)
print(ans)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math

def bin1(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = k ** mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin1(mid + 1, r, k, t, b, val, ans)
		else:
			return bin1(l, mid - 1, k, t, b, val, ans)

def bin2(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = t * k ** mid + b * mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin2(l, mid - 1, k, t, b, val, ans)
		else:
			return bin2(mid + 1, r, k, t, b, val, ans)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	l = []
	for i in range(2, n + 1):
		if prime[i]:
			l.append(i)
	return l

def bin(l, r, ll, val):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		if val >= ll[mid][0] and val <= ll[mid][1]:
			return mid
		elif val < ll[mid][0]:
			return bin(l, mid - 1, ll, val)
		else:
			return bin(mid + 1, r, ll, val)

def deci(n):
	s = ''
	while n != 0:
		if n % 2 == 0:
			n = n // 2
			s = '0' + s
		else:
			n = n // 2
			s = '1' + s
	return s

def diff(s1, s2):
	if len(s1) < len(s2):
		v = len(s1)
		while v != len(s2):
			s1 = '0' + s1
			v = v + 1
	else:
		v = len(s2)
		while v != len(s1):
			s2 = '0' + s2
			v = v + 1
	c = 0
	for i in range(len(s1)):
		if s1[i:i + 1] != s2[i:i + 1]:
			c = c + 1
	return c
from sys import stdin, stdout

def fac(a, b):
	v = a
	while a != b:
		v *= a - 1
		a = a - 1
	return v

def bino(l, r, n):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		val1 = math.log(n / mid + 1, 2)
		val2 = int(val1)
		if val1 == val2:
			return val1
		elif val1 < 1.0:
			return bino(l, mid - 1, n)
		else:
			return bino(mid + 1, r, n)

def binary(l, r, ll, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		if val % ll[mid] == 0:
			ans = ll[mid]
			return binary(l, mid - 1, ll, val, ans)
		else:
			return binary(l, mid - 1, ll, val, ans)

def odd(n, ans, s):
	if n % 2 != 0 or n in s:
		return ans
	else:
		s.add(n)
		return odd(n // 2, ans + 1, s)
(n, x) = map(int, stdin.readline().split(' '))
l = list(map(int, stdin.readline().split(' ')))
l.sort()
count = 0
for i in range(n):
	if x == 1:
		count += l[i]
	else:
		count += l[i] * x
		x -= 1
print(count)


a = input()
b = input()
(n, x) = [int(i) for i in a.split()]
subjects = [int(i) for i in b.split()]
subjects.sort()
time = 0
for i in subjects:
	time += x * i
	if x > 1:
		x -= 1
print(time)


(n, x) = map(int, input().split())
a = sorted(list(map(int, input().split())))
s = 0
for i in range(n):
	s += a[i] * max(1, x - i)
print(s)


def solve():
	(n, x) = map(int, input().split())
	c = []
	for c_ in input().split():
		c.append(int(c_))
	c.sort()
	total = 0
	for ch in c:
		total += ch * x
		x = x - 1 if x > 1 else x
	print(total)
solve()


from sys import stdin as cin, stdout as cout
from math import factorial as f
from itertools import combinations as comb
(n, x) = list(map(int, cin.readline().split()))
a = list(map(int, cin.readline().split()))
a.sort()
t = 0
for i in range(n):
	m = x - i
	if m < 1:
		m = 1
	t += m * a[i]
print(t)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
su = 0
for i in a:
	if x != 1:
		su += i * x
		x -= 1
	else:
		su += i
print(su)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
time = 0
for subject in a:
	time += subject * x
	x = max(1, x - 1)
print(time)


(n, x) = map(int, input().split())
clist = list(map(int, input().split()))
clist.sort()
time = 0
for i in clist:
	time = time + x * i
	if x > 1:
		x = x - 1
print(time)


def inp():
	return map(int, input().split())
(n, x) = inp()
c = list(inp())
c.sort()
total = 0
for i in range(n):
	total += c[i] * x
	if x > 1:
		x -= 1
print(total)


result = 0
subjects = []
(n, hour) = map(int, input().split())
subjects = list(map(int, input().split()))
subjects.sort()
for i in range(n):
	result += subjects[i] * hour
	if hour > 1:
		hour -= 1
print(result)


a = list(map(int, input().split()))[1]
b = sorted(map(int, input().split()))
b += [0] * (a - len(b))
print(sum(map(lambda x: b[x] * (a - x), range(a))) + sum(b[a:]))


import sys
(n, x) = map(int, sys.stdin.readline().split())
arr = list(map(int, sys.stdin.readline().split()))
arr.sort()
ans = 0
for i in range(n):
	ans += arr[i] * x
	x -= 1
	if x <= 1:
		x = 1
print(ans)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=False)
res = 0
for i in range(n):
	res += a[i] * x
	if x > 1:
		x -= 1
print(res)


(n, x) = [int(c) for c in input().split()]
disc = [int(c) for c in input().split()]
disc.sort()
res = 0
for i in range(len(disc)):
	res += disc[i] * x
	if x > 1:
		x -= 1
print(res)


(zzz, h) = map(int, input().split())
chapter = list(map(int, input().split()))
chapter.sort()
m = 0
for a in chapter:
	m += h * a
	if h > 1:
		h -= 1
print(m)


(n, x) = map(int, input().split())
y = sorted(list(map(int, input().split())))
mim = 0
for i in y:
	mim += i * x
	if x > 1:
		x = x - 1
print(mim)


(n, x) = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort()
ans = 0
for i in range(n):
	ans += x * a[i]
	if x > 1:
		x -= 1
print(ans)


(n, x) = map(int, input().split())
C = list(map(int, input().split()))
C.sort()
C.insert(0, 0)
res = 0
for i in range(1, n + 1):
	res = res + x * C[i]
	if x > 1:
		x -= 1
print(res)


(n, x) = map(int, input().split())
c = sorted(list(map(int, input().split())))
hours = 0
for d in range(len(c)):
	hours += c[d] * x
	x = max(x - 1, 1)
print(hours)


inp1 = [int(i) for i in input().split(' ')]
inp2 = sorted([int(i) for i in input().split(' ')])
result = 0
for i in inp2:
	if inp1[1] != 1:
		result += i * inp1[1]
		inp1[1] -= 1
	else:
		result += i * inp1[1]
print(result)


n = input()
n = n.split(' ')
c = int(n[1])
n = int(n[0])
soma = 0
v = 0
lista = []
v = input()
v = v.split(' ')
for i in v:
	val = int(i)
	lista.append(val)
lista.sort()
for i in lista:
	if c > 0:
		soma += i * c
		c -= 1
	else:
		soma += i
print(soma)


(n, x) = [int(j) for j in input().split()]
c = [int(j) for j in input().split()]
c.sort()
s = 0
for i in range(n):
	s += max(x, 1) * c[i]
	x -= 1
print(s)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
res = 0
for i in arr:
	res += i * k
	k -= 1
	k = max(k, 1)
print(res)


(n, x) = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
c = sorted(c)
s = 0
i = 0
while n > 0:
	n -= 1
	s += c[i] * x
	i += 1
	if x > 1:
		x -= 1
print(s)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
i = 0
t = 0
while i < n:
	t += a[i] * x
	x = max(1, x - 1)
	i += 1
print(t)


int_inp = lambda : int(input())
strng = lambda : input().strip()
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
import math
from collections import Counter, defaultdict
(a, b) = mul()
m = seq()
ans = 0
m.sort()
for i in range(0, a):
	if b == 1:
		ans = ans + sum(m[i:])
		break
	ans = ans + m[i] * b
	b -= 1
print(ans)


(n, x) = map(int, input().split())
s = sorted([int(i) for i in input().split()])
cnt = 0
for i in range(n):
	if x == 1:
		cnt += sum(s[i:n])
		break
	else:
		cnt += s[i] * x
		x -= 1
print(cnt)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
min_hours = 0
y = x
for i in range(n):
	min_hours = min_hours + a[i] * y
	if y > 1:
		y = y - 1
print(min_hours)


def solve():
	(n, x) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	arr.sort()
	sum_ = 0
	for i in range(n):
		sum_ += arr[i] * x
		if x > 1:
			x -= 1
	print(sum_)
solve()


(a, b) = map(int, input().split())
r = list(map(int, input().split()))
r.sort()
s = 0
for i in range(len(r)):
	s += r[i] * max(1, b - i)
print(s)


(n, k) = map(int, input().split())
t = map(int, input().split())
t = sorted(t)
s = 0
for i in t:
	s += i * k
	if k > 1:
		k -= 1
print(s)


(n, x) = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
c.sort()
m = 0
for i in range(n):
	m = m + c[i] * x
	if x > 1:
		x -= 1
print(m)


(n, x) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
i = 0
output = 0
while i < n:
	output += c[i] * x
	if x > 1:
		x -= 1
	i += 1
print(output)


(n, x) = map(int, input().split())
subjects = list(map(int, input().split()))
subjects.sort()
time = 0
for i in subjects:
	if x > 1:
		time += x * i
		x -= 1
	else:
		time += i
print(time)


(n, x) = map(int, input().split())
arr = list(map(int, input().split()))
total = 0
arr.sort()
for i in range(n):
	if x > 1:
		total = total + arr[i] * x
		x = x - 1
	else:
		total = total + arr[i]
print(total)


(n, x) = map(int, input().split())
ans = 0
arr = list(map(int, input().split()))
arr = sorted(arr)
for i in arr:
	ans += x * i
	if x != 1:
		x -= 1
print(ans)


class CodeforcesTask439BSolution:

	def __init__(self):
		self.result = ''
		self.n_x = []
		self.chapters = []

	def read_input(self):
		self.n_x = [int(x) for x in input().split(' ')]
		self.chapters = [int(x) for x in input().split(' ')]

	def process_task(self):
		self.chapters.sort()
		lp = self.n_x[1]
		tot_time = 0
		for topic in self.chapters:
			tot_time += lp * topic
			lp = max(1, lp - 1)
		self.result = str(tot_time)

	def get_result(self):
		return self.result
Solution = CodeforcesTask439BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(n, x) = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
c.sort(reverse=True)
ans = 0
while c:
	ans += x * c.pop()
	if x > 1:
		x -= 1
	else:
		ans += sum(c)
		break
print(ans)


(n, x) = map(int, input().split())
l_c = list(map(int, input().split()))
l_c.sort()
t = 0
for i in range(len(l_c)):
	t += max(1, x - i) * l_c[i]
print(t)


r = lambda : map(int, input().split())
(n, l) = r()
c = sorted(list(r()))
print(sum((x * max(l - i, 1) for (i, x) in enumerate(c))))


(n, x) = list(map(int, input().split()))
ci = list(map(int, input().split()))
ci = sorted(ci)
res = 0
for c in ci:
	res += c * x
	x = max(x - 1, 1)
print(res)


l = input().split()
n = int(l[0])
x = int(l[1])
l = input().split()
myList = []
for i in range(n):
	myList.append(int(l[i]))
myList.sort()
m = 0
for i in myList:
	m += i * x
	if x > 1:
		x -= 1
print(m)


(n, k) = map(int, input().split())
c = 0
ttl = 0
x = [int(x) for x in input().split()]
x.sort()
for i in x:
	ttl += i * (k - c)
	c += 1
	if c == k:
		c = k - 1
print(ttl)


p = input().rstrip().split(' ')
q = input().rstrip().split(' ')
q.sort(key=int)
l = []
w = []
S = []
D = []
F = 0
Y = int(p[1])
for i in range(0, len(q)):
	l.append(int(q[i]))
	w.append(Y)
	F += l[i] * w[i]
	if Y == 1:
		Y = 1
	else:
		Y -= 1
print(F)


(n, x) = input().split()
(n, x) = (int(n), int(x))
chapters = input().split()
chapters = sorted([int(i) for i in chapters])
ans = 0
for i in chapters:
	ans += x * i
	if x > 1:
		x -= 1
print(ans)


import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def main():
	(n, x) = invr()
	a = inlist()
	a = sorted(a)
	res = 0
	for i in a:
		h = max(1, x)
		res += i * h
		x -= 1
	print(res)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin
hat = stdin.readlines()
(n, x) = map(int, hat[0].split())
lst = [int(x) for x in hat[1].split()]
newlst = []
lst.sort()
halfway = int(0.5 * n)
houres = 0
for i in range(n):
	if x != 1:
		houres += x * lst[i]
		x -= 1
	else:
		houres += lst[i]
print(houres)


inp = lambda : map(int, input().split())
(n, k) = inp()
a = sorted(inp())
ans = 0
for i in range(n):
	ans += k * a[i]
	if k > 1:
		k -= 1
print(ans)


(n, x) = map(int, input().split())
subjects = list(map(int, input().split()))
hours = 0
if n == 0:
	print(0)
else:
	sortedSubjects = sorted(subjects)
	for i in range(0, len(sortedSubjects)):
		hours += sortedSubjects[i] * x
		if x > 1:
			x -= 1
	print(hours)


(n, x) = list(map(int, input().split()))
li = list(map(int, input().split()))
li = sorted(li)
res = 0
for value in li:
	res += value * x
	if x > 1:
		x -= 1
print(res)


(n, t) = map(int, input().split())
chapters = list(map(int, input().split()))
chapters.sort()
sum = 0
for sub in chapters:
	sum += sub * t
	if t > 1:
		t -= 1
print(sum)


from itertools import zip_longest
(n, x) = map(int, input().split())
(C, T) = (sorted(map(int, input().split())), reversed(range(1, x + 1)))
if n > x:
	print(sum((c * t for (c, t) in zip_longest(C, T, fillvalue=1))))
else:
	print(sum((c * t for (c, t) in zip(C, T))))


R = lambda : list(map(int, input().split()))
(n, x) = R()
a = R()
a = sorted(a)[::-1]
b = list(range(max(1, x - n + 1), x + 1))
if n - x > 0:
	b = [1] * (n - x) + b
ans = 0
for i in range(n):
	ans += a[i] * b[i]
print(ans)


(n, x) = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
s.sort()
k = 0
for i in range(n):
	k += s[i] * x
	if x > 1:
		x -= 1
print(k)


lista = []
(x, y) = map(int, input().split())
i = 0
entrada = input().split(' ')
while i < x:
	aux = int(entrada[i])
	lista += [aux]
	i += 1
lista.sort()
r = 0
for num in lista:
	r += y * num
	if y > 1:
		y -= 1
print(r)


(s, h) = [int(i) for i in input().split()]
sub = [int(i) for i in input().split()]
sub.sort()
result = 0
for i in sub:
	result += h * i
	if h > 1:
		h -= 1
print(result)


(n, x) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
c = 0
for i in l:
	c += i * x
	if x >= 2:
		x -= 1
print(c)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
k = m
ans = 0
for i in l:
	if k > 1:
		ans = ans + i * k
		k = k - 1
	else:
		ans = ans + i
print(ans)


import sys

def minp():
	return sys.stdin.readline().strip()
(n, x) = map(int, minp().split())
r = 0
for i in sorted(map(int, minp().split())):
	r += x * i
	x = max(1, x - 1)
print(r)


[n, x] = [int(i) for i in input().split()]
c = sorted([int(i) for i in input().split()])
time = 0
k = 0
while k < len(c):
	time += x * c[k]
	if x > 1:
		x -= 1
	k += 1
print(time)


(n, x) = (int(i) for i in input().split())
lst = sorted([int(i) for i in input().split()])
hour = 0
for i in lst:
	hour += i * x
	if x > 1:
		x -= 1
print(hour)


(n, x) = map(int, input().split())
a = sorted(list(map(int, input().split())))
s = 0
for t in a:
	s += t * x
	x = max(x - 1, 1)
print(s)


from sys import stdin, stdout
ZA = [int(a) for a in stdin.read().split()]
a = ZA[0]
b = ZA[1]
ZA = ZA[2:]
ZA.sort()
c = 0
d = 0
while c < a:
	d += ZA[c] * b
	if b > 1:
		b -= 1
	c += 1
print('%d' % d)


(n, x) = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
c.sort()
i = 0
sum = 0
while x > 1 and i < n:
	sum += c[i] * x
	x -= 1
	i += 1
while i < n:
	sum += c[i]
	i += 1
print(sum)


(n, x) = list(map(int, input().split()))
l = sorted(list(map(int, input().split())))
tong = 0
for i in range(n):
	tong += l[i] * x
	x = max(x - 1, 1)
print(tong)


(n, x) = map(int, input().split())
ls = map(int, input().split())
ls = sorted(ls)
ans = 0
for i in range(0, len(ls)):
	ans += ls[i] * x
	if x > 1:
		x -= 1
print(ans)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
b = []
for i in range(n):
	if x > 1:
		b.append(a[i] * x)
		x -= 1
	else:
		b.append(a[i])
print(sum(b))


(n, x) = map(int, input().split())
(a, s) = (sorted(map(int, input().split())), 0)
for i in a:
	s += i * x
	if x > 1:
		x -= 1
print(s)


def read(mode=2):
	inputs = input().strip()
	if mode == 0:
		return inputs
	if mode == 1:
		return inputs.split()
	if mode == 2:
		return [int(x) for x in inputs.split()]

def write(s='\n'):
	if isinstance(s, list):
		s = ' '.join(s)
	s = str(s)
	print(s, end='')
(n, x) = read()
c = read()
c.sort()
print(sum((max(x - i, 1) * c[i] for i in range(n))))


n = list(map(int, input().split(' ')))
t = list(map(int, input().split(' ')))
t.sort()
ans = 0
for f in t:
	ans += f * n[1]
	n[1] = max(n[1] - 1, 1)
print(ans)


(n, x) = map(int, input().split())
l = [x for x in map(int, input().split())]
l.sort()
hrs = 0
for i in range(n):
	if x == 1:
		hrs += sum(l) * x
		break
	else:
		hrs += x * l[0]
		del l[0]
		x -= 1
print(hrs)


(n, x) = map(int, input().split())
s = 0
for i in sorted(map(int, input().split())):
	s += i * x
	x = max(1, x - 1)
print(s)


(n, x) = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort()
s = 0
i = 0
while i < len(lst):
	if x == 1:
		break
	else:
		s += lst[i] * x
		x -= 1
		lst.remove(lst[i])
		i = -1
	i += 1
if len(lst) != 0:
	s += sum(lst)
print(s)


(n, x) = map(int, input().split())
arr = sorted(list(map(int, input().split())))
p = 0
for i in range(n):
	p += x * arr[i]
	if x != 1:
		x -= 1
print(p)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(a)
result = 0
for i in range(n):
	result = result + x * b[i]
	if x > 1:
		x = x - 1
print(result)


from typing import List

class Solution:

	@classmethod
	def solve(cls, n: int, x: int, chapters: List[int]):
		sorted_arr = sorted(chapters)
		total = 0
		for i in range(n):
			total += sorted_arr[i] * x
			if x > 1:
				x -= 1
		return total
(n, x) = input().split(' ')
(n, x) = (int(n), int(x))
chapters = list(map(lambda x: int(x), input().split(' ')))
result = Solution.solve(n, x, chapters)
print(result)


def dumb_guy(x, l):
	a = sorted(l)
	total = 0
	for i in range(len(a)):
		m = x - i
		if m < 1:
			m = 1
		total += m * a[i]
	print(total)
(n, x) = list(map(int, input().split()))
l = list(map(int, input().split()))
dumb_guy(x, l)


(n, x) = [int(x) for x in input().split()]
c = sorted([int(x) for x in input().split()])
time = 0
for i in c:
	if x > 1:
		time += i * x
		x -= 1
	else:
		time += i
print(time)


(subject, hours) = [int(x) for x in input().split()]
chapters = sorted([int(x) for x in input().split()])
needed = 0
for i in chapters:
	needed += hours * i
	hours = max(hours - 1, 1)
print(needed)


(n, x) = map(int, input().split())
a = sorted(list(map(int, input().split())))
s = 0
for i in range(n):
	if x > 1:
		s += a[i] * x
	else:
		s += sum(a[i:])
		print(s)
		exit()
	x -= 1
print(s)


(n, x) = map(int, input().split())
C = list(map(int, input().split()))
C.sort()
ans = 0
for i in range(n):
	ans += C[i] * x
	x = max(1, x - 1)
print(ans)


(n, t) = [int(n) for n in input().split()]
cs = [int(n) for n in input().split()]
cs = sorted(cs)
total = 0
for c in cs:
	total += t * c
	t = max(1, t - 1)
print(total)


(n, x) = map(int, input().split())
li = list(map(int, input().split()))
li.sort()
t = 0
for i in range(len(li)):
	t += li[i] * x
	if x > 1:
		x -= 1
	elif x == 0:
		x = 1
	elif x == 1:
		continue
print(t)


(n, x) = map(int, input().split(' '))
arr = [int(i) for i in input().split(' ')][:n]
arr.sort()
s = 0
i = 0
while x >= 1 and i < n:
	s += arr[i] * x
	if x <= 1:
		x = 1
	else:
		x -= 1
	i += 1
print(s)


(n, x) = map(int, input().split())
c = sorted(map(int, input().split()))
res = 0
for el in c:
	res += el * x
	if x > 1:
		x -= 1
print(res)


(n, x) = input('').split()
n = int(n)
x = int(x)
arr = list(map(int, input().split()))
arr.sort()
b = 0
for i in arr:
	b = b + x * i
	if x > 1:
		x = x - 1
print(b)


(n, x) = map(int, input().split())
ar = list(map(int, input().split()))
ar.sort()
ind = x
time = 0
for i in ar:
	time += i * ind
	if ind - 1 >= 1:
		ind -= 1
print(time)


(n, x) = map(int, input().split())
L = list(map(int, input().split()))
L.sort()
r = 0
for i in range(n):
	r += max(x - i, 1) * L[i]
print(r)


(n, x) = map(int, input().split())
ans = 0
chapters = list(map(int, input().split()))
chapters.sort()
for chap in chapters:
	if x > 0:
		v = chap * x
	else:
		v = chap
	ans += v
	x -= 1
print(ans)


from sys import stdin
firstline = stdin.readline().rstrip().split()
n = int(firstline[0])
x = int(firstline[1])
subjects = [int(x) for x in stdin.readline().rstrip().split()]
subjects.sort()
learning_time = 0
for subject_chapters in subjects:
	learning_time += x * subject_chapters
	x = max(1, x - 1)
print(learning_time)


from sys import stdin, stdout
input = stdin.readline
(n, x) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
ans = 0
for i in range(n):
	ans += max(x - i, 1) * c[i]
stdout.write(str(ans))


(x, y) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
a = 0
for i in range(x):
	if y >= 1:
		a = a + y * l[i]
		y = y - 1
	else:
		y = 1
		a = a + y * l[i]
print(a)


(n, x) = map(int, input().split(' '))
c = list(map(int, input().split(' ')))
sorted_c = sorted(c)
sum = 0
for i in range(n):
	tmp = max(1, x)
	sum += sorted_c[i] * tmp
	x = x - 1
print(sum)


stri = input().split()
n = int(stri[0])
x = int(stri[1])
stri = input().split()
chapters = []
for i in range(n):
	chapters.append(int(stri[i]))
chapters.sort()
answer = 0
for i in range(n):
	answer += chapters[i] * x
	if x > 1:
		x -= 1
print(answer)


(n, x) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
arr.sort()
time = 0
for i in arr:
	time += x * i
	if x > 1:
		x -= 1
print(time)


(n, x) = map(int, input().split())
books = [i for i in map(int, input().split())]
books = sorted(books)
sum = 0
for i in range(n):
	if x > 1:
		sum += books[i] * x
		x -= 1
	else:
		sum += books[i]
print(sum)


(subject_count, hour_count) = map(int, input().split())
chapters_list = map(int, input().split())
chapters_list = sorted(chapters_list)
total_hour = 0
for i in range(0, subject_count):
	total_hour += chapters_list[i] * hour_count
	hour_count -= 1
	if hour_count < 1:
		hour_count = 1
print(total_hour)


(size, maxCapacity) = map(int, input().split())
array = list(map(int, input().split()))
array = sorted(array)
counter = 0
for i in range(size):
	if maxCapacity != 1:
		counter += array[i] * maxCapacity
		maxCapacity -= 1
	else:
		counter += array[i]
print(counter)


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
int1 = lambda x: int(x) - 1
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))
ilelec = lambda : map(int1, input().split())
alelec = lambda : list(map(int1, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
(n, x) = ilele()
A = alele()
A.sort()
ans = 0
for i in A:
	ans += i * x
	x = max(1, x - 1)
print(ans)


pt = input().split()
num = pt[0]
x = int(pt[1])
cnt = 0
study = input().split()
for i in range(len(study)):
	study[i] = int(study[i])
study.sort()
for i in study:
	if x > 1:
		cnt += x * i
		x -= 1
	else:
		cnt += i
print(cnt)


(n, x) = map(int, input().split())
num_chap = sorted([int(x) for x in input().split()])
min_time = 0
for i in range(n):
	min_time += num_chap[i] * max(x - i, 1)
print(min_time)


(n, k) = map(int, input().split())
c = sorted([int(z) for z in input().split()]) + max(k - n, 0) * [0]
o = sum(c)
for i in range(k):
	o += (k - 1 - i) * c[i]
print(o)


X = list(map(int, input().split()))
Chapters = sorted(list(map(int, input().split())))
Sum = 0
for i in range(X[0]):
	Sum += Chapters[i] * X[1]
	X[1] = max(1, X[1] - 1)
print(Sum)


(n, x) = map(int, input().split())
subjects = list(map(int, input().split()))
subjects.sort()
print(sum([(x - o) * c for (o, c) in enumerate(subjects[:x - 1])]) + sum(subjects[x - 1:]))


s = input().split(' ')
n = int(s[0])
x = int(s[1])
sub = [int(i) for i in input().split(' ')]
sub = sorted(sub)
result = 0
for i in sub:
	result = result + i * x
	if x > 1:
		x = x - 1
print(result)


datain = True
if datain:
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
else:
	(n, x) = (2, 3)
	a = [4, 1]
a.sort()
sa = len(a)
time = x * a[0]
if sa == 1:
	print(time)
else:
	for i in range(1, sa):
		x = max(x - 1, 1)
		time += x * a[i]
	print(time)


(n, x) = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
i = 0
t = 0
while i < n:
	t = t + x * s[i]
	if x > 1:
		x = x - 1
	i = i + 1
print(t)


(n, x) = map(int, input().split())
c = list(map(int, input().split()))
cs = sorted(c)
i = 0
sum = 0
while i < n:
	sum += cs[i] * x
	if x != 1:
		x -= 1
	i += 1
print(sum)


(n, x) = [int(x) for x in input().split()]
l = sorted([int(x) for x in input().split()])
ans = 0
for c in l:
	ans += c * x
	x = max(1, x - 1)
print(ans)


import sys
input = sys.stdin.readline
from collections import deque
(n, x) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
ans = 0
for i in range(n):
	if x - i >= 1:
		chh = x - i
	else:
		chh = 1
	ans += chh * c[i]
print(ans)


mod = 10 ** 9 + 7
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, x) = f()
l = sorted(il())
sm = 0
for i in range(n):
	sm += max(1, x) * l[i]
	x -= 1
print(sm)


(n, x) = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
arr.sort()
hours = 0
for i in arr:
	hours += i * x
	x = max(1, x - 1)
print(hours)


import math
for _ in range(1):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	sum1 = 0
	for i in l:
		sum1 += i * x
		if x > 1:
			x = x - 1
		else:
			continue
	print(sum1)


def main():
	(n_subjects, x_learning_rate) = [int(i) for i in input().split()]
	subjects = [int(i) for i in input().split()]
	subjects.sort()
	hours = 0
	j = x_learning_rate
	for subject in subjects:
		if j < 1:
			j = 1
		hours += subject * j
		j -= 1
	print(hours)
main()


(n, x) = map(int, input().split())
c = sorted(map(int, input().split()))
p = x
result = 0
for ci in c:
	result += p * ci
	if p > 1:
		p -= 1
print(result)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l = sorted(l)
k = 0
for i in range(n):
	k = k + m * l[i]
	if m != 1:
		m = m - 1
print(k)


otv = 0
(n, m) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
for x in range(len(A)):
	otv += m * A[x]
	if m > 1:
		m -= 1
print(otv)


(n, x) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
ans = 0
i = 0
j = x
while i < n and j > 0:
	ans += c[i] * j
	i += 1
	j -= 1
	if j == 0:
		j = 1
print(ans)


def mi():
	return map(int, input().split())
(n, k) = mi()
a = list(mi())
a.sort()
s = 0
for i in a:
	s += i * k
	k -= 1
	k = max(k, 1)
print(s)


(n, x) = map(int, input().split())
l = [int(i) for i in input().split()]
l.sort()
sum = 0
for i in l:
	sum += x * i
	if x > 1:
		x -= 1
print(sum)


(n, c) = map(int, input().split())
L = sorted([k for k in map(int, input().split())])
resultado = 0
for k in L:
	if c == 0:
		c = 1
	resultado += k * c
	c -= 1
print(resultado)


nx = input().split()
for i in range(len(nx)):
	nx[i] = int(nx[i])
n = nx[0]
x = nx[1]
mas = input().split()
for i in range(len(mas)):
	mas[i] = int(mas[i])
mas.sort()
sum = 0
for i in mas:
	sum = sum + i * x
	if x > 1:
		x = x - 1
print(sum)


from sys import stdin, stdout
(n, x) = map(int, stdin.readline().split())
chapters = list(map(int, stdin.readline().split()))
chapters.sort()
minimum_hours = 0
for count in chapters:
	minimum_hours += count * x
	x -= 1
	if x == 0:
		x = 1
print(minimum_hours)


from math import *
from collections import deque
from copy import deepcopy
import sys

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def multi():
	return map(int, input().split())

def lis():
	return list(map(int, inp().split()))

def out(var):
	sys.stdout.write(str(var))

def printlist(a):
	print(' '.join((str(a[i]) for i in range(len(a)))))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
(n, x) = multi()
a = lis()
a.sort()
ans = 0
for i in a:
	ans += x * i
	if x > 1:
		x -= 1
print(ans)


def __init():
	num_input = input()
	num_input = num_input.split(' ')
	n = int(num_input[0])
	x = int(num_input[1])
	c = input()
	c = c.split(' ')
	for i in range(n):
		c[i] = int(c[i])
	return (n, x, c)

def timeStudy(n, x, c):
	c.append(0)
	c.sort()
	for i in range(1, n + 1):
		c[i] = c[i - 1] + c[i] * x
		if x > 1:
			x -= 1
	return c[n]
(n, x, c) = __init()
print(timeStudy(n, x, c))


from sys import stdin, stdout, setrecursionlimit
from gc import disable
gets = input
puts = print
input = stdin.readline
print = stdout.write

def main() -> int:
	disable()
	(n, x) = map(int, input().split())
	a = sorted(map(int, input().split()))
	i = 0
	count = 0
	while x != 1 and i < n:
		count += a[i] * x
		x -= 1
		i += 1
	count += sum(a[i:])
	print('%i' % count)
	return 0
main()


(n, m) = map(int, input().split())
mat = list(map(int, input().split()))
mat = sorted(mat)
result = 0
if m != 1:
	for j in range(n):
		result += mat[j] * m
		m -= 1
		if m == 1:
			break
	j += 1
	if j < n:
		result += sum(mat[j:])
else:
	result += sum(mat)
print(result)


(n, x) = [int(k) for k in input().split()]
c = [int(k) for k in input().split()]
c = sorted(c)
ans = 0
for i in c:
	ans += i * x
	x -= 1
	if x < 1:
		x = 1
print(ans)


(n, x) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
ans = 0
for val in c:
	ans += x * val
	if x > 1:
		x -= 1
print(ans)


(n, x) = str(input()).split()
n = int(n)
x = int(x)
line = str(input()).split()
line = [int(it) for it in line]
line.sort()
num = 0
if n > x:
	for i in range(x):
		num += line[i] * (x - i)
	num += sum(line[x:])
else:
	for i in range(n):
		num += line[i] * (x - i)
print(num)


(n, x) = map(int, input().split())
l = list(map(int, input().split()))
time = 0
l.sort()
for i in range(n):
	if x == 1:
		time = time + x * sum(l[i:n])
		break
	else:
		temp = l[i]
		time = time + x * temp
		x = x - 1
print(time)


def main():
	(N, X) = list(map(int, input().split()))
	C = list(map(int, input().split()))
	C.sort()
	s = 0
	for c in C:
		s += X * c
		X = max(X - 1, 1)
	print(s)
main()


x = [int(x) for x in input().split()]
y = [int(y) for y in input().split()]
y.sort()
summ = 0
z = len(y)
for i in y:
	summ += i * x[1]
	if x[1] > 1:
		x[1] -= 1
print(summ)


(n, m) = map(int, input().split())
B = input().split()
A = [int(x) for x in list(B)]
A = sorted(A)
dem = 0
for i in range(0, n):
	dem = dem + A[i] * m
	if m > 1:
		m -= 1
	else:
		m = 1
print(dem)


(n, x) = map(int, input().split())
arr = sorted(list(map(int, input().split())))
total = 0
for chapter in arr:
	total += chapter * x
	x = max(1, x - 1)
print(total)


s = input()
s = s.split(' ')
n = int(s[0])
hours = int(s[1])
s = input()
s = s.split(' ')
arr = []
for i in range(n):
	arr.append(int(s[i]))
arr = sorted(arr)
time = 0
for i in range(n):
	temp = hours * arr[i]
	time += temp
	hours -= 1
	if hours <= 1:
		hours = 1
print(time)


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
l = sorted(l)
c = int(b)
tot = 0
d = 0
for i in range(a):
	if c > 0:
		tot += l[i] * c
	elif c < 1:
		break
	c -= 1
if a <= b:
	print(tot)
else:
	d = l[b:]
	print(sum(d) + tot)


(n, x) = [int(e) for e in input().split()]
chapter_subjects = [int(e) for e in input().split()]
chapter_subjects.sort()
total = 0
for i in range(n):
	total += max(x - i, 1) * chapter_subjects[i]
print(total)


(n, x) = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
c.sort()
ans = 0
for item in c:
	ans += item * x
	if x > 1:
		x -= 1
print(ans)


(n, x) = map(int, input().split())
subjects = sorted(list(map(int, input().split())))
ans = 0
for s in subjects:
	ans += s * x
	x = max(1, x - 1)
print(ans)


(n, x) = map(int, input().split())
subjects = list(map(int, input().split()))
subjects.sort()
totaltime = 0
for subject in subjects:
	totaltime += subject * x
	if x != 1:
		x -= 1
print(totaltime)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
time = k
ans = 0
for i in a:
	ans += i * time
	if time > 1:
		time -= 1
print(ans)


(n, x) = map(int, input().split())
s = [int(i) for i in input().split()]
s.sort()
q = 0
for i in range(n):
	if i == 0:
		q = q + s[i] * x
		x = x - 1
	elif i > 0 and x >= 1:
		q = q + s[i] * x
		x = x - 1
	else:
		x = 1
		q = q + s[i] * x
print(q)


(n, x) = map(int, input().split(' '))
cs = list(map(int, input().split(' ')))
x_work = list(range(x, 0, -1)) + [1] * n
cs.sort()
answer = 0
for (i, item) in enumerate(cs):
	answer += x_work[i] * item
print(answer)


(n, x) = (int(x) for x in input().split())
val = 0
for c in sorted((int(x) for x in input().split())):
	val += c * x
	x = max(x - 1, 1)
print(val)


(a, x) = map(int, input().split(' '))
c = sorted(list(map(int, input().split(' '))))
timeToLearn = 0
for chapters in c:
	timeToLearn += x * chapters
	x = max(1, x - 1)
print(timeToLearn)


(n, x) = map(int, input().split())
l = list(sorted(map(int, input().split())))
total = 0
for i in l:
	if x == 0:
		x = 1
	total += x * i
	x -= 1
print(total)


buf = input().split(' ')
n = int(buf[0])
k = int(buf[1])
buf = input().split(' ')
for i in range(n):
	buf[i] = int(buf[i])
buf = sorted(buf)
wyn = 0
for i in range(n):
	wyn += buf[i] * k
	k = max(1, k - 1)
print(wyn)


(n, x) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
t1 = t2 = 0
i = 0
x_ = x
while i < n:
	t1 += c[i] * x
	if x > 1:
		x -= 1
	i += 1
while i != 0:
	i -= 1
	t2 += c[i] * x_
	if x_ > 1:
		x_ -= 1
print(min(t1, t2))


nx = input().split(' ')
n = int(nx[0])
x = int(nx[1])
c = input().split(' ')
a = []
for i in c:
	a.append(int(i))
a.sort()
ans = 0
for i in a:
	ans = ans + x * i
	if x >= 2:
		x = x - 1
print(ans)


inp = [int(i) for i in input().split()]
x = inp[1]
res = 0
parts = [int(i) for i in input().split()]
parts.sort()
for i in parts:
	res += i * x
	if x > 1:
		x -= 1
print(res)


a = input().split()
b = input().split()
l = []
for i in range(int(a[0])):
	l.append(int(b[i]))
l.sort()
x = int(a[1])
s = 0
time = 0
for i in range(int(a[0])):
	s = s + l[i] * x
	if x > 1:
		x = x - 1
print(s)


(n, x) = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
c.sort()
z = 0
for i in c:
	z += int(i) * x
	if x > 1:
		x -= 1
print(z)


(n, x) = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
a = 0
for i in s:
	a += i * x
	x -= [0, 1][x > 1]
print(a)


(n, x) = map(int, input().rstrip().split())
array = list(map(int, input().rstrip().split()))
sum = 0
array.sort()
for i in range(n):
	if x > 1:
		sum += array[i] * x
		x -= 1
	else:
		sum += array[i]
print(sum)


(n, h) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
res = 0
for i in l:
	res += i * h
	if h > 1:
		h -= 1
print(res)


string = input()
numbers = string.split()
n = int(numbers[1])
string = input()
numbers = [int(x) for x in string.split()]
numbers.sort()
hours = 0
for x in numbers:
	hours += n * x
	if n > 1:
		n -= 1
print(hours)


def minimumTime(n, x, c):
	c_sorted = sorted(c)
	ans = 0
	for i in range(n):
		ans += c_sorted[i] * max(1, x - i)
	return ans
(n, x) = map(int, input().split())
c = list(map(int, input().split()))
print(minimumTime(n, x, c))


(n, x) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
time = 0
for item in c:
	time += item * x
	x = x - 1 if x > 1 else 1
print(time)


(n, x) = [int(s) for s in input().split()]
mas = [int(s) for s in input().split()]
time = 0
mas.sort()
for val in mas:
	time += val * x
	if x > 1:
		x -= 1
print(time)


(n, x) = map(int, input().split())
subjects = [int(i) for i in input().split()]
subjects.sort()
count = res = 0
while count < n:
	res += subjects[count] * x
	if x > 1:
		x -= 1
	count += 1
print(res)


import sys
for line in sys.stdin:
	line = line.strip('\n').split(' ')
	(n, x) = (int(line[0]), int(line[1]))
	c = sys.stdin.readline()
	c = c.strip('\n').split(' ')
	c = [int(i) for i in c]
	c.sort()
	counter = 0
	for i in c:
		counter += i * x
		if x > 1:
			x -= 1
	print(counter)


def findMinHours(hours, chapters):
	total_time = 0
	for item in sorted(chapters):
		total_time += item * hours
		hours -= 1
		if hours < 1:
			hours = 1
	return total_time
(subjects, hours) = list(map(int, input().split()))
chapters = list(map(int, input().split()))
print(findMinHours(hours, chapters))


arra = list(map(int, input().split()))
chapters = list(map(int, input().split()))
time_learn_a_chapter = arra[1]
total_min_time = 0
chapters.sort()
for c in chapters:
	total_min_time = total_min_time + time_learn_a_chapter * c
	if time_learn_a_chapter <= 1:
		time_learn_a_chapter = 1
	else:
		time_learn_a_chapter = time_learn_a_chapter - 1
print(total_min_time)


(n, x) = map(int, input().split())
mas = list(map(int, input().split()))
sum = 0
mas.sort()
for i in mas:
	sum += i * x
	x = max(x - 1, 1)
print(sum)


(n, x) = map(int, input().split())
chap = [int(i) for i in input().split()]
chap.sort()
min_hours = 0
for i in chap:
	min_hours += i * x
	if x > 1:
		x -= 1
print(min_hours)


(n, x) = [int(a) for a in input().split()]
c = [int(a) for a in input().split()]
c.sort()
t = 0
for ci in c:
	t += ci * x
	if x > 1:
		x -= 1
print(t)


def solution():
	(n, x) = [int(x) for x in input().split(' ')]
	c = [int(x) for x in input().split(' ')]
	c.sort()
	ans = 0
	for i in range(n):
		ans += c[i] * x
		if x >= 2:
			x -= 1
	return ans
print(solution())


def main():
	(n, x) = map(int, input().split())
	mlist = [int(i) for i in input().split()]
	mlist.sort()
	ans = 0
	for c in mlist:
		ans += c * x
		if x > 1:
			x = x - 1
	print(ans)
main()


(n, l) = map(int, input().split())
d = list(map(int, input().split()))
a = 0
d.sort()
for i in range(len(d)):
	a = a + l * d[i]
	if l > 1:
		l = l - 1
print(a)


def main():
	(n, x) = map(int, input().split())
	chapter = list(map(int, input().split()))
	chapter.sort()
	total_time = 0
	for i in range(n):
		total_time += chapter[i] * x
		x -= 1
		if x < 1:
			x = 1
	print(total_time)
main()


(n, x) = map(int, input().split())
l = sorted([int(i) for i in input().split()])
ans = 0
for i in l:
	if x > 1:
		ans += x * i
		x -= 1
	else:
		ans += i * 1
print(ans)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
i = s = 0
b = sorted(a)
while i < n:
	s += b[i] * x
	if x > 1:
		x -= 1
	i += 1
print(s)


(n, x) = map(int, input().split())
subject = list(map(int, input().split()))
subject.sort()
sum_time = 0
for i in range(n):
	sum_time += subject[i] * x
	x = max(x - 1, 1)
print(sum_time)


(n, x) = map(int, input().split())
z = list(map(int, input().split()))
z.sort()
ans = 0
for i in z:
	ans += i * x
	x -= x - 1 >= 1
print(ans)


str1 = input()
l1 = str1.split()
n = l1[0]
x = int(l1[1])
str1 = input()
l2 = str1.split()
for i in range(len(l1)):
	l1[i] = int(int(l1[i]))
for i in range(len(l2)):
	l2[i] = int(int(l2[i]))
l2.sort()
sub = 0
for i in range(len(l2)):
	sub = sub + x * l2[i]
	if x > 1:
		x = x - 1
print(sub)


(N, K) = (int(num) for num in input().split())
A = [int(num) for num in input().split()]
A.sort()
i = 0
sum = 0
while i < N and K > 1:
	sum += A[i] * K
	K -= 1
	i += 1
while i < N:
	sum += A[i] * K
	i += 1
print(sum)


def find_min_hours(num_subjects, init_hour, chapters):
	chapters = sorted(chapters)
	study_hour = init_hour
	total_hours = 0
	for chapter in chapters:
		total_hours += chapter * study_hour
		if study_hour > 1:
			study_hour -= 1
	return total_hours
(num_subjects, init_hour) = list(map(int, input().split()))
chapters = list(map(int, input().split()))
print(find_min_hours(num_subjects, init_hour, chapters))


(n, x) = input().strip().split(' ')
n = int(n)
x = int(x)
ar = input().strip().split(' ')
for i in range(len(ar)):
	ar[i] = int(ar[i])
ar.sort()
count = 0
for i in range(len(ar)):
	if x == 1:
		count += ar[i] * x
	else:
		count += ar[i] * x
		x -= 1
print(count)


(n, x) = map(int, input().split())
ll = list(map(int, input().split()))
ll1 = [0] * 100001
for i in range(n):
	ll1[ll[i]] += 1
ans = 0
for i in range(100001):
	if ll1[i] != 0:
		for j in range(ll1[i]):
			ans = ans + x * i
			if x > 1:
				x -= 1
print(ans)


(n, x) = map(int, input().split())
data = sorted(map(int, input().split()))
print(sum([v * max(x - i, 1) for (i, v) in enumerate(data)]))


first = input('').split()
n = int(first[0])
x = int(first[1])
lst = list(map(int, input('').split()))
lst.sort()
total = 0
time = 0
for i in range(0, len(lst)):
	total = total + lst[i] * x
	if x > 1:
		x -= 1
	else:
		x = 1
print(total)


(n, x) = map(int, input().split())
lista = list(map(int, input().split()))
lista.sort()
somatorio = 0
for c in lista:
	somatorio += c * x
	x = max(1, x - 1)
print(somatorio)


(n, x) = list(map(int, input().split()))
l = list(map(int, input().split()))
l.sort()
t = 0
for i in l:
	t += i * x
	x = max(1, x - 1)
print(t)


(n, x) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
ans = 0
for i in range(len(arr)):
	ans += arr[i] * x
	if x > 1:
		x -= 1
print(ans)


n_and_x = input()
c1_to_cn = input()
(n, x) = (int(n_and_x.split()[0]), int(n_and_x.split()[1]))
chapter_list = []
for c in c1_to_cn.split():
	chapter_list.append(int(c))
chapter_list.sort()
ans = 0
for i in range(n):
	ans += int(chapter_list[i]) * x
	if x > 1:
		x -= 1
print(ans)


from sys import stdin
__author__ = 'artyom'

def read_next_line():
	return list(map(int, stdin.readline().strip().split()))
(_, x) = read_next_line()
hours = 0
for chapter in sorted(read_next_line()):
	hours += chapter * x
	x = max(1, x - 1)
print(hours)


(n, k) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
sum = 0
for i in range(n):
	sum = sum + k * c[i]
	if k > 1:
		k = k - 1
print(sum)


(n, x) = list(map(int, input().split()))
c = list(map(int, input().split()))
d = [0] * 100001
for ci in c:
	d[ci] += 1
time = 0
ci = 1
while ci < 100001:
	if d[ci] > 0:
		time += x * ci
		d[ci] -= 1
		x = max(1, x - 1)
	else:
		ci += 1
print(time)


import sys
import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list or type(n) is str:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return '\n'.join(map(str, arr))

def revn(n):
	return int(str(n)[::-1])

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True
(n, x) = mi()
c = sorted(li())
ans = 0
for i in range(n):
	ans += c[i] * max(x, 1)
	x -= 1
print(ans)


(n, x) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
min_time = 0
for chapters in c:
	min_time += chapters * x
	if x > 1:
		x -= 1
print(min_time)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
solve = 0
for i in range(n):
	solve += x * a[i]
	if x > 1:
		x -= 1
print(solve)


R = lambda : map(int, input().split())
(n, x) = R()
c = sorted(R())
s = 0
for k in c:
	s += x * k
	x = max(1, x - 1)
print(s)


(a, b) = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
tot = 0
for i in x:
	tot += i * b
	b = max(b - 1, 1)
print(tot)


(n, x) = map(int, input().split())
l = list(map(int, input().split()))
l = sorted(l)
c = 0
i = 0
while x > 1 and i < n:
	c += l[i] * x
	i += 1
	x = x - 1
if x == 1 and i < n:
	while i < n:
		c += l[i]
		i += 1
print(c)


(n, h) = list(map(int, input().split()))
c = list(map(int, input().split()))
count = 0
c.sort()
for i in range(n):
	count += c[i] * max(1, h)
	h = h - 1
print(count)


(n, x) = map(int, input().split())
w = sorted(list(map(int, input().split())))
(s, i) = (0, 0)
while True:
	s += w[i] * x
	if x > 1:
		x -= 1
	i += 1
	if i == n:
		break
print(s)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 10 ** 9 + 7

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	(n, x) = sep()
	a = lis()
	a = sorted(a)
	ans = 0
	for i in range(n):
		ans += a[i] * x
		if x > 1:
			x -= 1
	print(ans)
testcase(1)


(n, x) = map(int, input().split())
ps = sorted(map(int, input().split()))
t = 0
for p in ps:
	t += p * x
	x = max(1, x - 1)
print(t)


p = input().split()
i = 0
n = int(p[0])
x = int(p[1])
y = list(map(int, input().split()))
y.sort()
min = 0
while i < n:
	if x <= 1:
		x = 1
	min += y[i] * x
	x -= 1
	i += 1
print(min)


a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = sorted(b)
count = 0
d = a[1]
for i in range(0, len(c)):
	count = count + d * c[i]
	if d > 1:
		d = d - 1
	else:
		continue
print(count)


(n, x) = map(int, input().split())
c = list(map(int, input().split()))
s = sorted(c)

def decrease(a):
	if a > 1:
		return a - 1
	else:
		return 1
sum = 0
for e in s:
	sum += e * x
	x = decrease(x)
print(sum)


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]
spf_sieve()

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
(n, x) = int_array()
c = int_array()
ans = 0
c.sort()
for i in c:
	ans += i * max(1, x)
	x -= 1
print(ans)


(n, x) = map(int, input().split())
cs = list(map(int, input().split()))
cs.sort()
sol = 0
for c in cs:
	sol += c * x
	if x > 1:
		x -= 1
print(sol)


(n, x) = map(int, input().split())
a = sorted(list(map(int, input().split())))
print(sum([a[i] * max(x - i, 1) for i in range(len(a))]))


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, x) = value()
a = sorted(array())
hours = 0
for i in a:
	hours += max(1, x) * i
	x -= 1
print(hours)


(n, x) = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
l.sort()
t = 0
for i in range(n):
	t += l[i] * max(x, 1)
	x -= 1
print(t)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
res = 0
for i in a:
	res += x * i
	if x > 1:
		x -= 1
print(res)


inp = input().split(' ')
n = int(inp[0])
hrs = int(inp[1])
order = input().split(' ')
order = [int(x) for x in order]
order = sorted(order)
time = 0
for chapters in order:
	tps = chapters * hrs
	if hrs > 1:
		hrs -= 1
	time += tps
print(time)


(n, x) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
t = 0
for i in range(len(c)):
	t += x * c[i]
	if x != 1:
		x -= 1
print(t)


(n, x) = map(int, input().split())
c = [int(x) for x in input().split()]
c.sort()
ans = 0
for t in c:
	ans += t * x
	if x > 1:
		x -= 1
print(ans)


(n, x) = input().split()
n = int(n)
x = int(x)
c = list(map(int, input().split()))
c.sort()
d = 0
for t in c:
	d = d + t * x
	if x > 1:
		x -= 1
print(d)


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
k = []
for i in range(a):
	if b != 1:
		w = c[i] * b
		b = b - 1
		k.append(w)
	elif b == 1:
		k.append(c[i])
print(sum(k))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = 1
	rr = []
	for _ in range(t):
		(n, x) = LI()
		a = LI()
		a.sort()
		r = 0
		for c in a:
			r += c * x
			if x > 1:
				x -= 1
		rr.append(r)
	return JA(rr, '\n')
print(main())


(subject, hour) = map(int, input().split())
chapter = list(map(int, input().split()))
global sum
sum = 0
chapter.sort()
for i in range(subject):
	if hour == 1:
		sum += chapter[i]
	else:
		sum += chapter[i] * hour
		hour -= 1
print(sum)


n = input()
n = [int(i) for i in n.split()]
a = input()
a = [int(i) for i in a.split()]
a = sorted(a)
s = 0
for i in range(n[0]):
	s = s + a[i] * n[1]
	if n[1] > 1:
		n[1] -= 1
print(s)


def minimum_watering(n, x, c):
	c.sort()
	i = 0
	teaching_hour = 0
	for i in range(0, len(c)):
		teaching_hour += c[i] * x
		x = max(x - 1, 1)
	return teaching_hour

def read_input():
	(n, x) = [int(i) for i in input().split(' ')]
	c = [int(i) for i in input().split(' ')]
	return (n, x, c)

def main():
	(n, x, c) = read_input()
	print(minimum_watering(n, x, c))
main()


(n, d) = input('').split(' ')
(n, d) = (int(n), int(d))
nums = [int(x) for x in input('').split(' ')]
nums.sort()
sum = 0
for num in nums:
	sum += num * d
	if d != 1:
		d -= 1
print(sum)


(n, x) = map(int, input().split())
inputArr = list(map(int, input().split()))
current = x
sum = 0
inputArr.sort()
for i in range(0, n):
	sum += inputArr[i] * x
	x -= 1
	if x < 1:
		x = 1
print(sum)


(n, x) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
counter = 0
for i in a:
	counter += i * x
	if x > 1:
		x -= 1
print(counter)


(n, x) = map(int, input().split())
a = sorted([int(i) for i in input().split()])
k = 0
for i in a:
	if x > 1:
		k += x * i
		x -= 1
	else:
		k += i
print(k)


(n, m) = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
time = 0
arr = sorted(arr)
for i in range(n):
	time = time + arr[i] * m
	if m > 1:
		m = m - 1
print(time)


(n, x) = list(map(int, input().split()))
chapters_of_subject = list(map(int, input().split()))
sorted_chapters_of_subject = sorted(chapters_of_subject)
total = 0
for chapters in sorted_chapters_of_subject:
	total += chapters * x
	x -= 1
	if x < 1:
		x = 1
print(total)


(n, x) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
count = 0
for i in c:
	count += x * i
	x = max(1, x - 1)
print(count)


(n, x) = map(int, input().split())
m = list(map(int, input().split()))
m.sort()
cnt = 0
for i in range(n):
	cnt += x * m[i]
	if x > 1:
		x -= 1
print(cnt)


(n, x) = map(int, input().split())
c = sorted(list(map(int, input().split())))
ret = 0
for y in c:
	ret += x * y
	x = max(x - 1, 1)
print(ret)


(n, x) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
total_hours = 0
for i in range(n):
	total_hours += c[i] * max(x - i, 1)
print(total_hours)


import sys
(n, x) = sys.stdin.readline().split(' ')
c = sys.stdin.readline()
n = n.strip('\n')
x = x.strip('\n')
c = c.strip('\n')
n = int(n)
x = int(x)
c_char_list = c.split(' ')
c_list = []
for c in c_char_list:
	c_list.append(int(c))
c_list.sort()
r = 0
for cost in c_list:
	r += cost * x
	if x > 1:
		x -= 1
print(r)


(n, x) = map(int, input().split())
chaps = list(map(int, input().split()))
sorted = sorted(chaps)
time = 0
j = 0
for i in range(len(sorted)):
	time += (x - j) * sorted[i]
	if x - j >= 2:
		j += 1
print(time)


(n, m) = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
l = 0
for i in range(n):
	l += m * c[i]
	m = max(1, m - 1)
print(l)


def main():
	n = list(map(int, input().split(' ')))
	m = list(map(int, input().split(' ')))
	m.sort()
	result = 0
	for i in range(n[0]):
		result += n[1] * m[i]
		if n[1] > 1:
			n[1] -= 1
	print(result)
main()


import sys
(n, x) = [int(z) for z in sys.stdin.readline().split()]
ci = [int(z) for z in sys.stdin.readline().split()]
ci.sort()
result = 0
for i in range(n):
	result += ci[i] * x
	if x - 1 >= 1:
		x -= 1
print(result)


temp = input()
(n, x) = temp.split(' ')
n = int(n)
x = int(x)
temp = input()
c = list(temp.split(' '))
for i in range(0, len(c)):
	c[i] = int(c[i])
c.sort()
cost = 0
for i in range(0, len(c)):
	cost += c[i] * x
	if x > 1:
		x -= 1
print(cost)


(n, x) = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
c.sort()
time = 0
for i in c:
	time += i * x
	x = max(1, x - 1)
print(time)


(a, b) = map(int, input().split())
sum = 0
p = [int(i) for i in input().split()]
p.sort()
for i in range(len(p)):
	sum += p[i] * b
	if b > 1:
		b -= 1
print(sum)