Recently Vasya decided to improve his pistol shooting skills. Today his coach offered him the following exercise. He placed $n$ cans in a row on a table. Cans are numbered from left to right from $1$ to $n$. Vasya has to knock down each can exactly once to finish the exercise. He is allowed to choose the order in which he will knock the cans down.

Vasya knows that the durability of the $i$-th can is $a_i$. It means that if Vasya has already knocked $x$ cans down and is now about to start shooting the $i$-th one, he will need $(a_i \cdot x + 1)$ shots to knock it down. You can assume that if Vasya starts shooting the $i$-th can, he will be shooting it until he knocks it down.

Your task is to choose such an order of shooting so that the number of shots required to knock each of the $n$ given cans down exactly once is minimum possible.


-----Input-----

The first line of the input contains one integer $n$ $(2 \le n \le 1\,000)$ — the number of cans.

The second line of the input contains the sequence $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 1\,000)$, where $a_i$ is the durability of the $i$-th can.


-----Output-----

In the first line print the minimum number of shots required to knock each of the $n$ given cans down exactly once.

In the second line print the sequence consisting of $n$ distinct integers from $1$ to $n$ — the order of indices of cans that minimizes the number of shots required. If there are several answers, you can print any of them.


-----Examples-----
Input
3
20 10 20

Output
43
1 3 2 

Input
4
10 10 10 10

Output
64
2 1 4 3 

Input
6
5 4 5 4 4 5

Output
69
6 1 3 5 2 4 

Input
2
1 4

Output
3
2 1 



-----Note-----

In the first example Vasya can start shooting from the first can. He knocks it down with the first shot because he haven't knocked any other cans down before. After that he has to shoot the third can. To knock it down he shoots $20 \cdot 1 + 1 = 21$ times. After that only second can remains. To knock it down Vasya shoots $10 \cdot 2 + 1 = 21$ times. So the total number of shots is $1 + 21 + 21 = 43$.

In the second example the order of shooting does not matter because all cans have the same durability.

Difficulty: EASY
Tags: Sorting

Implementation

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
from collections import defaultdict
n = int(input())
rec = defaultdict(list)
origi = list(map(int, input().split()))
for i in range(n):
	rec[origi[i]].append(i + 1)
a = sorted(origi, reverse=True)
l = 0
ans = []
for i in range(n):
	l += a[i] * i + 1
	ans.append(rec[a[i]].pop())
print(l)
for i in ans:
	print(i, end=' ')
print('')


n = int(input())
s = list(map(int, input().split()))
ct = []
for (i, v) in enumerate(s):
	ct.append((v, i + 1))
ct.sort(reverse=True)
ans = 0
p = []
for (i, v) in enumerate(ct):
	ans += i * v[0] + 1
	p.append(v[1])
print(ans)
print(' '.join(map(str, p)))


def main():
	n = int(input())
	aa = [int(a) for a in input().split()]
	aae = list(enumerate(aa))
	aae.sort(reverse=True, key=lambda x: x[1])
	sum = 0
	(seq, aa) = zip(*aae)
	for (i, a) in enumerate(aa):
		sum += a * i + 1
	print(sum)
	print(' '.join(map(str, map(lambda x: x + 1, seq))))
main()


n = int(input())
a = [int(i) for i in input().split()]
a = [(a[i], i) for i in range(len(a))]
a.sort(reverse=True)
s = 0
order = []
for i in range(len(a)):
	s += a[i][0] * i + 1
	order.append(a[i][1])
print(s)
print(' '.join([str(i + 1) for i in order]))


n = int(input())
temp = list(map(int, input().split()))
a = []
for i in range(len(temp)):
	a.append((temp[i], i + 1))
a.sort(key=lambda s: s[0], reverse=True)
result = 0
order = []
for i in range(len(a)):
	result += a[i][0] * i + 1
	order.append(a[i][1])
print(result)
print(*order)


a = int(input())
z = list(map(int, input().split()))
ans = []
for i in range(len(z)):
	ans.append([-z[i], i])
ans.sort()
total = 0
x = 0
for i in range(len(ans)):
	total += abs(ans[i][0]) * x + 1
	x += 1
print(total)
for i in range(len(ans)):
	print(ans[i][1] + 1, end=' ')


n = int(input())
a = [int(x) for x in input().split(' ')]
count = 0
pos = dict()
pos_index = dict()
for i in range(n):
	var = a[i]
	if var in pos:
		pos[var].append(i + 1)
	else:
		pos[var] = [i + 1]
for var in pos:
	pos_index[var] = len(pos[var])
a.sort()
ord = []
x = 0
for i in range(n - 1, -1, -1):
	var = a[i]
	count += x * var + 1
	x += 1
	pos_index[var] -= 1
	ord.append(pos[var][pos_index[var]])
print(count)
print(*ord)


def shooting(n, arr):
	temp = arr.copy()
	shots = 0
	count = 0
	seen = []
	arr.sort()
	for i in range(n - 1, -1, -1):
		if shots == 0:
			shots += 1
			count += 1
			seen.append(temp.index(arr[i]) + 1)
			ind = temp.index(arr[i])
			temp[ind] = 0
		elif shots > 0:
			shots += count * arr[i] + 1
			count += 1
			ind = temp.index(arr[i])
			seen.append(temp.index(arr[i]) + 1)
			temp[ind] = 0
	print(shots)
	for c in seen:
		print(c, end=' ')
no_of_cans = int(input())
seq = list(map(int, input().split()))
shooting(no_of_cans, seq)


n = int(input())
_ = list(map(int, input().split()))
s = []
for (i, x) in enumerate(_, 1):
	s.append((i, x))
a = sorted(s, key=lambda x: x[1], reverse=True)
r = 0
n = 0
for (_, x) in a:
	r += x * n + 1
	n += 1
print(r)
for (i, _) in a:
	print(i, end=' ')


n = int(input())
a = [[p + 1, int(i)] for (p, i) in enumerate(input().split())]
a.sort(key=lambda x: x[1], reverse=True)
res = 0
p = []
for i in range(n):
	res += a[i][1] * i + 1
	p.append(a[i][0])
print(res)
print(' '.join((str(i) for i in p)))


def arr():
	return list(map(int, input().split()))
n = int(input())
a = arr()
l = [0] * (n + 1)
x = []
b = a.copy()
ans = 0
b.sort(reverse=True)
for i in a:
	x.append([i, 0])
for i in range(n):
	x[x.index([b[i], 0])] = [b[i], i + 1]
c = []
for i in x:
	c.append(i[1])
for i in range(n):
	ans += x[i][0] * (x[i][1] - 1) + 1
print(ans)
for i in range(n):
	l[x[i][1]] = i + 1
print(' '.join(map(str, l[1:])))


n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
	b.append([a[i], i])
b.sort()
b.reverse()
c = 0
for i in range(n):
	c += b[i][0] * i + 1
print(c)
print(' '.join(map(lambda x: str(x[1] + 1), b)))


import sys
can_num = int(sys.stdin.readline())
durability = sys.stdin.readline().split()
order = [None] * can_num
for i in range(can_num):
	durability[i] = int(durability[i])
res = 0
can_count = 0
while True:
	max_val = 0
	index_val = 0
	for j in range(0, can_num):
		if durability[j] > max_val:
			max_val = durability[j]
			index_val = j
	if max_val == 0:
		break
	order[can_count] = index_val + 1
	res += can_count * max_val + 1
	can_count += 1
	durability[index_val] = 0
print(res)
print(' '.join((str(y) for y in order)))


n = int(input())
a = list(map(int, input().split()))
v = []
for i in range(n):
	v.append([a[i], i])
v.sort(reverse=True)
(x, ans) = (0, 0)
res = []
for i in v:
	ans += i[0] * x + 1
	res.append(i[1] + 1)
	x += 1
print(ans)
print(*res)


n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
	b.append([a[i], i + 1])
b.sort(reverse=True)
ans = 0
x = 0
for i in b:
	ans += x * i[0] + 1
	x += 1
print(ans)
for i in b:
	print(i[1], end=' ')


n = int(input())
a = list(map(int, input().split()))
r = []
ans = 0
for i in range(n):
	pos = -1
	for j in range(n):
		if pos == -1 or a[j] > a[pos]:
			pos = j
	r.append(pos + 1)
	ans += i * a[pos] + 1
	a[pos] = 0
print(ans)
print(*r)


n = int(input())
ar = list(map(int, input().split()))
ar1 = []
for i in range(n):
	ar1.append([ar[i], i])
ar1.sort(reverse=True)
ans_ar = []
fin = 0
for j in range(n):
	ans_ar.append(ar1[j][1] + 1)
	fin += ar1[j][0] * j + 1
print(fin)
print(*ans_ar)


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


n = int(input())
l = sorted(zip(map(int, input().split()), range(n)), reverse=True)
print(sum((l[i][0] * i + 1 for i in range(n))))
print(*[i + 1 for (_, i) in l])


input()
a = list(map(int, input().split()))
s = 0
z = 0
f = []
n = max(a) + 2
for i in sorted(a, reverse=True):
	s += i * z + 1
	z += 1
	f += [a.index(i) + 1]
	a[a.index(i)] = n
print(s, '\n', *f)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = [a[i], i]
	a.sort(reverse=True)
	ans = 0
	for i in range(n):
		ans += i * a[i][0] + 1
	print(ans)
	b = [k[1] + 1 for k in a]
	print(*b)
	return
main()


n = int(input())
a = input().split()
for i in range(n):
	a[i] = (int(a[i]), i)
a.sort(reverse=True)
ans = 0
for i in range(n):
	ans += a[i][0] * i + 1
print(ans)
for i in a:
	print(i[1] + 1, end=' ')


n = int(input())
cans = input().split()
cans = list(enumerate(map(int, cans)))
cans.sort(key=lambda x: x[1], reverse=True)
ans = 0
ord = []
for (i, v) in enumerate(cans):
	ord.append(v[0])
	ans += i * v[1] + 1
print(ans)
for i in ord:
	print('%d ' % (i + 1), end='')


from collections import deque
import sys

def inp():
	return sys.stdin.readline().strip()
n = int(inp())
a = list(map(int, inp().split()))
b = [(a[i], i + 1) for i in range(n)]
b.sort(reverse=True)
ans = 0
for i in range(len(b)):
	ans += i * b[i][0] + 1
print(ans)
res = [i[1] for i in b]
print(*res)


n = int(input())
arr = list(map(int, input().split()))
x = list(range(n))
x = sorted(x, key=lambda i: arr[i], reverse=True)
seq = []
i = ans = 0
for j in x:
	ans += arr[j] * i + 1
	i += 1
	seq.append(j + 1)
print(ans)
print(*seq)


import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
from heapq import heappush as hpush
from heapq import heappop as hpop
mod = 10 ** 9 + 7

def ri(flag=0):
	if flag == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
n = ri(1)
a = ri()
b = sorted(a, reverse=True)
c = [i + 1 for i in range(n)]
c.sort(key=lambda x: a[x - 1])
c = c[::-1]
ans = 0
x = 0
for i in range(n):
	ans += b[i] * x + 1
	x += 1
print(ans)
print(*c)


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


n = int(input())
lis = list(map(int, input().split()))
mat = [(lis[i], i) for i in range(n)]
mat.sort(reverse=True)
ans = 0
aa = []
for i in range(n):
	ans += mat[i][0] * i + 1
	aa.append(mat[i][1] + 1)
print(ans)
print(*aa)


(x, y) = ([], [])
n = int(input())
l = list(map(int, input().split()))
for i in range(n):
	x.append(l[i])
	x.append(i + 1)
	y.append(x)
	x = []
y.sort()
y.reverse()
l.sort()
l.reverse()
ans = 0
for i in range(len(l)):
	ans += l[i] * i + 1
print(ans)
for i in range(len(y)):
	print(y[i][1], end=' ')


x = int(input())
y = input()
y_ = y.split()
z = [int(d) for d in y_]
b = []
unique = []
for num in z:
	if num not in unique:
		unique.append(num)
unique.sort(reverse=True)
for num in unique:
	for j in range(len(z)):
		if z[j] == num:
			b.append(j + 1)
z.sort(reverse=True)
i = 0
ans = 0
while i < len(z):
	ans = ans + z[i] * i + 1
	i = i + 1
print(ans)
print(*b)


n = int(input())
cans = [int(i) for i in input().split()]
order = {}
for i in range(len(cans)):
	order[i + 1] = cans[i]
order = dict(sorted(order.items(), key=lambda x: x[1], reverse=True))
cost = 0
cans = list(order.values())
for i in range(len(cans)):
	cost += i * cans[i] + 1
print(cost)
print(*list(order.keys()))


n = int(input())
k = list(map(int, input().strip().split()[:n]))
a = s = 0
k1 = k.copy()
k1.sort()
k1.reverse()
for x in k1:
	s = s + (x * a + 1)
	a += 1
print(s)
for x in k1:
	print(k.index(x) + 1, end=' ')
	k[k.index(x)] = '#@%@%'


def getKey(item):
	return item[0]
n = int(input())
cans = [int(i) for i in input().split()]
cans = [(cans[i], i + 1) for i in range(0, n)]
cans = sorted(cans, key=getKey, reverse=True)
sequence = []
counter = 1
total = 1
sequence.append(cans[0][1])
for i in range(1, n):
	total += cans[i][0] * counter + 1
	sequence.append(cans[i][1])
	counter += 1
print(total)
for i in sequence:
	print(i, end=' ')


elem = int(input())
ar = []
for t in input().split(' '):
	ar.append(int(t))
copy_ar = ar.copy()
sor = [i[0] for i in sorted(enumerate(ar), key=lambda x: x[1])]
x = 0
count = 0
for a in reversed(sor):
	count = count + x * ar[a] + 1
	x = x + 1
print(count)
sor = [x + 1 for x in sor]
print(*reversed(sor))


n = int(input())
s = input()
l = [int(nm) for nm in s.split(' ')]
l2 = sorted(((v, i) for (i, v) in enumerate(l)), reverse=True)
ct = 0
for i in range(n):
	ct += l2[i][0] * i + 1
print(ct)
l3 = []
for i in range(n):
	l3.append(l2[i][1] + 1)
print(*l3)


import math
alph = 'abcdefghijklmnopqrstuvwxyz'
n = int(input())
a = list(map(int, input().split()))
b = a * 1
b.sort(reverse=True)
E = 0
c = []
for i in range(n):
	E += 1 + b[i] * i
	c.append(1 + a.index(b[i]))
	a[a.index(b[i])] = -1
print(E)
for i in range(n):
	print(c[i], end=' ')


n = int(input())
s = list(map(int, input().split()))
a = []
for (i, j) in enumerate(s):
	a.append((j, i + 1))
a.sort(key=lambda x: x[0], reverse=True)
k = 0
total = 0
shot = []
for i in a:
	total += i[0] * k + 1
	k += 1
	shot.append(i[1])
print(total)
print(*shot)


n = int(input())
arr = [i for i in map(int, input().split())]
copy = sorted(arr)
copy = copy[::-1]
k = 1
sum = 0
for i in range(1, len(copy)):
	sum += k * copy[i] + 1
	k += 1
sum += 1
ans = list()
for i in range(len(copy)):
	for j in range(len(arr)):
		if copy[i] == arr[j]:
			ans.append(str(j + 1))
			copy[i] = '$'
			arr[j] = '#'
			break
print(sum)
print(' '.join(ans))


N = int(input())
(*A,) = map(int, input().split())
(*I,) = range(N)
I.sort(key=A.__getitem__, reverse=1)
ans = 0
for i in range(N):
	a = A[I[i]]
	ans += i * a + 1
print(ans)
I = [i + 1 for i in I]
print(*I)


n = int(input())
a = list(map(int, input().split()))
ans = 0
x = 0
l = []
temp = sorted(a, reverse=True)
for i in range(n):
	ans += temp[i] * x + 1
	x += 1
	l.append(a.index(temp[i]) + 1)
	a[a.index(temp[i])] += 1000
print(ans)
print(*l)


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


n = int(input())
proch = [int(i) for i in input().split()]
posl = []
summa = 0
for i in range(n):
	posl.append(str(proch.index(max(proch)) + 1))
	summa += max(proch) * i + 1
	proch[proch.index(max(proch))] = 0
proch.sort(reverse=True)
print(summa)
print(*posl)


index = 0

def lol(x):
	global index
	index += 1
	return (int(x), index)
n = int(input())
cans = sorted(list(map(lol, input().split())), reverse=True)
ans = 0
for i in range(n):
	ans += cans[i][0] * i + 1
print(ans)
for i in range(n):
	print(cans[i][1], end=' ')


n = int(input())
l = [int(x) for x in input().split()]
g = sorted(l, reverse=True)
(st, e) = (1, 0)
k = []
for i in g:
	c = l.index(i)
	k.append(c + 1)
	l[c] = 0
	if e != 0:
		st += i * e + 1
	e += 1
print(st)
print(*k)


n = int(input())
l = [int(i) for i in input().split()]
k1 = sorted(set(l), reverse=True)
c = 0
l1 = []
for i in k1:
	for j in range(n):
		if i == l[j]:
			c += len(l1) * l[j] + 1
			l1.append(j + 1)
print(c)
print(*l1)


n = int(input())
arr = list(map(int, input().split()))
arr1 = [[0, 0] for i in range(n)]
for i in range(1, n + 1):
	arr1[i - 1][0] = arr[i - 1]
	arr1[i - 1][1] = i
arr1.sort(reverse=True)
count = 0
ans = ''
for i in range(n):
	count += arr1[i][0] * i + 1
	ans += str(arr1[i][1]) + ' '
print(count)
print(ans)


def main():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	newarr = []
	for i in range(n):
		newarr.append([arr[i], i])
	newarr.sort(reverse=True)
	shots = 0
	pos = []
	for i in range(n):
		shots += newarr[i][0] * i + 1
		pos.append(newarr[i][1] + 1)
	print(shots)
	for i in range(0, len(pos) - 1):
		print(pos[i], end=' ')
	print(pos[-1])
main()


n = int(input())
A = list(map(int, input().split()))
B = list(A)
B.sort()
B = B[::-1]
P = list()
M = [0] * n
ans = 0
for i in range(0, n):
	ans += i * B[i] + 1
for i in range(0, n):
	for j in range(0, n):
		if B[i] == A[j] and M[j] == 0:
			M[j] = 1
			P.append(j + 1)
print(ans)
print(' '.join(map(str, P)))


def ele(x):
	return x[1]
n = int(input())
arr = list(map(int, input().split()))
arr1 = []
for i in range(n):
	arr1.append([i + 1, arr[i]])
arr1.sort(reverse=True, key=ele)
tot = 0
cou = 0
for i in arr1:
	tot += i[1] * cou + 1
	cou += 1
print(tot)
for i in arr1:
	print(i[0], end=' ')


n = int(input())
a = [(int(el), i + 1) for (i, el) in enumerate(input().split())]
a = sorted(a, reverse=True)
shots = 0
for (i, (el, _)) in enumerate(a):
	shots += i * el + 1
print(shots)
print(*(i for (_, i) in a))


n = int(input())
a = list(map(int, input().split(' ')))
s = sorted(a, reverse=True)
ind = []
ans = []
for i in range(len(s)):
	ind.append(a.index(s[i]) + 1)
	ans.append(i * s[i] + 1)
	a[a.index(s[i])] = '*'
print(sum(ans))
print(*ind)


n = int(input())
a = list(map(int, input().split()))
k = []
for i in range(len(a)):
	k.append([a[i], i + 1])
k.sort(reverse=True)
x = 0
s = 0
y = []
for i in range(len(k)):
	s = s + k[i][0] * x + 1
	x = x + 1
	y.append(k[i][1])
print(s)
print(*y)


n = int(input())
a = list(map(int, input().split()))
b = sorted(list(enumerate(a)), key=lambda x: x[1], reverse=True)
ans = 0
for i in range(n):
	ans += i * b[i][1] + 1
b = list(map(lambda x: x[0] + 1, b))
print(ans)
print(' '.join(list(map(str, b))))


ii = lambda : int(input())
kk = lambda : map(int, input().split())
ll = lambda : list(kk())
(n, ls, c) = (ii(), sorted(((l, i) for (i, l) in enumerate(kk())), reverse=True), 0)
ans = [0] * n
for i in range(n):
	ans[i] = ls[i][1] + 1
	c += ls[i][0] * i + 1
print(c)
print(*ans)


import math
t = 1
while t:
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for i in range(n):
		if d.get(l[i], -1) == -1:
			d[l[i]] = []
		d[l[i]].append(i)
	l.sort(reverse=True)
	ans = 0
	j = 0
	for i in range(n):
		ans += j * l[i] + 1
		j += 1
	print(ans)
	k = 0
	i = 0
	while i < n:
		k = i
		for j in range(len(d[l[k]])):
			print(d[l[k]][j] + 1, end=' ')
			i += 1
	t -= 1


n = int(input())
arr = [int(x) for x in input().split()]
arrtwo = []
i = 1
for j in range(n):
	arrtwo.append([arr[j], i])
	i += 1
arrtwo.sort(reverse=True)
i = 0
ans = 0
for j in range(len(arrtwo)):
	ans = ans + (arrtwo[j][0] * i + 1)
	i += 1
print(ans)
for j in range(len(arrtwo)):
	print(arrtwo[j][1], end=' ')


n = int(input())
m = [int(i) for i in input().split()]
d = []
for i in range(n):
	d.append((m[i], i + 1))
d.sort(reverse=True)
k = 0
for i in range(n):
	k += d[i][0] * i + 1
print(k)
for i in d:
	print(i[1], end=' ')


def solve(n, ar):
	track = ar
	best = 0
	best_index = 0
	shot = 0
	x = 0
	trace = []
	while ar.count(-1) != n:
		best = max(ar)
		best_index = ar.index(best)
		shot += ar[best_index] * x + 1
		x += 1
		trace.append(best_index + 1)
		ar[best_index] = -1
	print(shot)
	print(' '.join(map(str, trace)))
n = int(input())
ar = list(map(int, input().split()))
solve(n, ar)


def bubb(x, a):
	fl = False
	n = len(x)
	while not fl:
		fl = True
		for i in range(n - 1):
			if x[i] < x[i + 1]:
				(x[i], x[i + 1]) = (x[i + 1], x[i])
				(a[i], a[i + 1]) = (a[i + 1], a[i])
				fl = False
	return (x, a)
n = int(input())
c = [int(x) for x in input().split()]
c1 = [int(x) for x in range(n)]
s = 0
(c, c1) = bubb(c, c1)
for i in range(n):
	s += i * c[i] + 1
print(s)
for i in range(n):
	print(c1[i] + 1, end=' ')


def f(seq):
	return [i for (v, i) in sorted(((v, i) for (i, v) in enumerate(seq)))]
n = int(input())
in_arr = list(map(int, input().split()))
for i in range(n):
	in_arr[i] = -in_arr[i]
out_arr = f(in_arr)
s = 0
for i in range(n):
	s += -in_arr[out_arr[i]] * i + 1
print(s)
for i in range(n):
	print(out_arr[i] + 1, end=' ')


n = int(input())
s = list(map(int, input().split()))
x = 0
p = []
for i in range(n):
	p.append((s[i], i + 1))
p.sort()
p.reverse()
count = 0
p1 = []
for i in range(n):
	count += p[i][0] * x + 1
	p1.append(p[i][-1])
	x += 1
print(count)
print(*p1)


n = int(input())
it = 0

def func():
	global it
	it += 1
	return it
a = map(lambda x: (func(), int(x)), input().split())
a = list(a)
a.sort(key=lambda x: x[1], reverse=True)
ans = 0
for (x, el) in enumerate(a):
	ans += x * el[1] + 1
print(ans)
for i in a:
	print(i[0], end=' ')


n = int(input())
l = list(map(int, input().split()))
m = l + []
m.sort()
o = []
m.reverse()
for i in range(n):
	p = l.index(m[i])
	o.append(p + 1)
	l[p] = -100
x = 0
c = 0
for i in range(n):
	c += m[i] * x + 1
	x += 1
print(c)
for i in range(n):
	print(o[i], end=' ')


import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
from collections import Counter
Y = lambda : list(map(int, input().split()))
N = lambda : int(input())
n = N()
a = Y()
r = 0
a = [(-a[k], k % len(a) + 1) for k in range(n)]
a.sort()
for i in range(n):
	r += -a[i][0] * i + 1
print('{0}\n{1}'.format(r, ' '.join(map(str, [x[1] for x in a]))))


n = int(input())
arr = list(map(int, input().split()))
s = 0
ans = []
for i in range(n):
	s = s + max(arr) * i + 1
	ans.append(arr.index(max(arr)))
	arr.remove(max(arr))
	arr.insert(ans[len(ans) - 1], 0)
print(s)
for i in ans:
	print(i + 1, end=' ')


n = int(input())
l = list(map(int, input().split()))
ul = sorted(zip(l, range(1, n + 1)), reverse=True)
c = 0
for i in range(n):
	c += i * ul[i][0] + 1
print(c)
for i in ul:
	print(i[1], end=' ')


n = int(input())
f = list(map(int, input().split()))
ast = f.copy()
ast.sort()
ast.reverse()
ct = 0
ans = []
for i in range(n):
	ty = f.index(ast[i])
	ans.append(ty)
	f[ty] = -1
	ct += ast[i] * i + 1
print(ct)
for i in range(n):
	print(ans[i] + 1, end=' ')


import sys

def rint():
	return map(int, sys.stdin.readline().split())
n = int(input())
a = list(rint())
ai = []
for i in range(n):
	ai.append(i)
ai.sort(key=lambda e: a[e] * -1)
x = 0
tot = 0
for i in range(n):
	aa = a[ai[i]]
	shot = aa * x + 1
	x += 1
	tot += shot
print(tot)
for i in range(n):
	ai[i] += 1
print(*ai)


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


n = int(input())
a = list(map(int, input().split()))
index = []
for i in range(n):
	index.append(i + 1)
for i in range(n):
	for j in range(n - i - 1):
		if a[j] < a[j + 1]:
			tmp = a[j + 1]
			a[j + 1] = a[j]
			a[j] = tmp
			tmp = index[j + 1]
			index[j + 1] = index[j]
			index[j] = tmp
ans = 0
for i in range(n):
	ans = ans + a[i] * i + 1
print(ans)
for i in range(n):
	print(index[i], end=' ')


from collections import defaultdict
n = int(input())
arr = list(map(int, input().split()))
mapp = defaultdict(int)
for i in range(n):
	mapp[i] = arr[i]
result = []
summ = 0
for (i, el) in enumerate(sorted(mapp.items(), key=lambda el: el[1], reverse=True)):
	result.append(el[0] + 1)
	summ += el[1] * i + 1
print(summ)
print(' '.join(list(map(str, result))))


def get_key(d, value):
	for (k, v) in d.items():
		if v == value:
			return k
n = int(input())
p = list(map(int, input().split()))
d = dict()
c = 1
for i in p:
	d[c] = i
	c += 1
p.sort(reverse=True)
sum = 0
i = 0
for a in p:
	sum += a * i + 1
	i += 1
print(sum)
for i in p:
	print(get_key(d, i), end=' ')
	d.pop(get_key(d, i))


_ = input()
canstr = [(int(x), i) for (i, x) in enumerate(input().split())]
canstr.sort(reverse=True)
cost = 0
for (i, pair) in enumerate(canstr):
	cost += 1 + i * pair[0]
print(cost)
print(' '.join([str(x[1] + 1) for x in canstr]))


I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
lr = l.copy()
temp = [[l[i], i] for i in range(n)]
temp.sort(key=lambda x: x[0], reverse=True)
lr.sort(reverse=True)
ans = 0
for i in range(n):
	ans += lr[i] * i + 1
print(ans)
for i in range(n):
	print(temp[i][1] + 1, end=' ')


n = int(input())
ls = [int(a) for a in input().split()][:n]
ls1 = [int(a) for a in ls]
ls.sort(reverse=True)
sm = 0
ans = list()
ans2 = list()
ans3 = list()
for i in range(len(ls1)):
	ans.append(i)
for i in range(len(ls)):
	sm = sm + ls[i] * i + 1
for i in range(len(ls1)):
	if ls[i] in ls1:
		x = ls1.index(ls[i])
		ans2.append(x)
		ls1.remove(ls[i])
		ls1.insert(x, 0)
print(sm)
for a in ans2:
	a = a + 1
	print(a, end=' ')


(n, a) = (int(input()), list(map(int, input().split())))
b = a.copy()
b.sort(reverse=True)
l = []
s = 0
for i in range(n):
	s += b[i] * i + 1
	for j in range(n):
		if a[j] == b[i]:
			l.append(j + 1)
			a[j] = -1
			break
print(s)
for i in l:
	print(i, end=' ')


n = int(input())
arr = [int(x) for x in input().split()]
narr = []
for (index, item) in enumerate(arr, 1):
	narr.append([item, index])
narr.sort(key=lambda x: x[0], reverse=True)
sum = 0
for i in range(0, n):
	sum += narr[i][0] * i + 1
print(sum)
for i in narr:
	print(i[1], end=' ')


n = int(input())
L = list(map(int, input().split()))
L1 = sorted(L, reverse=True)
c = 0
s = 0
L2 = []
for i in range(len(L1)):
	s = s + L1[i] * c + 1
	j = 0
	flag = True
	while j < len(L) and flag:
		if L[j] == L1[i]:
			if j + 1 not in L2:
				flag = False
				L2.append(j + 1)
		j += 1
	c += 1
print(s)
for i in range(len(L2)):
	print(L2[i], end=' ')


n = range(int(input()))
a = sorted(zip(map(int, input().split()), n))[::-1]
print(sum((i * a[i][0] + 1 for i in n)))
print(*(i + 1 for (_, i) in a))


p = int(input())
y = input().split()
for x in range(p):
	y[x] = (int(y[x]), x + 1)
y.sort()
y.reverse()
b = 0
o = []
for x in range(p):
	b = b + x * y[x][0] + 1
print(b)
for x in range(p):
	print(y[x][1], end=' ')


n = int(input())
numbers = input().split()
num = []
b = {}
for i in numbers:
	b[i] = []
for i in range(len(numbers)):
	num.append(int(numbers[i]))
	b[numbers[i]].append(i)
num.sort()
summed = 0
index = ''
for i in range(len(num) - 1, -1, -1):
	summed += (len(num) - i - 1) * num[i] + 1
	k = b[str(num[i])]
	index += str(k[0] + 1) + ' '
	b[str(num[i])] = k[1:len(k)]
print(summed)
print(index)


n = int(input())
lista = list(map(int, input().split()))
listaP = [i for i in lista]
lista.sort(reverse=True)
result = 1
listaResult = []
listaResult.append(listaP.index(lista[0]) + 1)
listaP[listaP.index(lista[0])] = 0
for i in range(1, n, 1):
	result += lista[i] * i + 1
	listaResult.append(listaP.index(lista[i]) + 1)
	listaP[listaP.index(lista[i])] = 0
print(result)
for i in listaResult:
	print(str(i) + ' ', end='')


n = int(input())
banki = list(map(int, input().split()))
sortirovanie_BANKI = sorted(zip(banki, range(n)), key=lambda x: x[0], reverse=True)
pistols = 0
killed = 0
for i in sortirovanie_BANKI:
	pistols += i[0] * killed + 1
	killed += 1
print(pistols)
print(' '.join(map(lambda x: str(x[1] + 1), sortirovanie_BANKI)))


def main():
	n = int(input())
	a = [int(p) for p in input().split()]
	pairs = []
	for (i, v) in enumerate(a):
		pair = (v, i + 1)
		pairs.append(pair)
	pairs = sorted(pairs, reverse=True, key=lambda p: p[0])
	score = 0
	for i in range(n):
		score += pairs[i][0] * i + 1
	print(score)
	for (v, i) in pairs:
		print(i, end=' ')
main()


n = int(input())
a = input().split()
sum = 0
for i in range(1, n + 1):
	a[i - 1] = [int(a[i - 1]), i]
a.sort()
a = a[::-1]
for i in range(n):
	sum += a[i][0] * i + 1
print(sum)
b = []
for i in a:
	print(str(i[1]) + ' ', end='')


n = int(input())
l = list(map(int, input().split()))
k = sorted(l)
k.reverse()
s = list(set(k))
s.sort()
s.reverse()
c = 0
for i in range(n):
	c += 1 + k[i] * i
print(c)
for x in range(len(s)):
	for y in range(n):
		if s[x] == l[y]:
			print(y + 1, end=' ')


import itertools
input()
nums = [int(i) for i in str.split(input(), ' ')]
nums = list(zip(nums, itertools.count(1)))
nums = sorted(nums, key=lambda x: -x[0])
res = 0
for i in range(len(nums)):
	res += nums[i][0] * i + 1
print(res)
print(' '.join([str(r[1]) for r in nums]))


t = int(input())
e = list(map(int, input().split()))
a = []
sum = 0
for i in range(t):
	c = e.index(max(e))
	a.append(c + 1)
	sum = 1 + sum + i * e[c]
	e[c] = 0
print(sum)
print(*a)


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


import sys
n = int(input())
a = input().split()
for x in range(n):
	a[x] = (int(a[x]), x + 1)
a.sort()
a.reverse()
c = 0
o = []
for x in range(n):
	c = c + x * a[x][0] + 1
print(c)
for x in range(n):
	print(a[x][1], end=' ')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
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 = I()
		a = LI()
		t = sorted([(a[i], i) for i in range(n)], reverse=True)
		r = 0
		for (i, (ai, _)) in enumerate(t):
			r += i * ai + 1
		rr.append(r)
		rr.append(JA(map(lambda x: x[1] + 1, t), ' '))
	return JA(rr, '\n')
print(main())


n = int(input())
a = list(map(int, input().split()))
(b, counter) = ([], 0)
for j in sorted(set(a), reverse=True):
	for i in range(n):
		if j == a[i]:
			counter += len(b) * a[i] + 1
			b.append(i + 1)
print(counter, *b)


(n, a) = (int(input()), list(sorted(enumerate(map(int, input().split())), reverse=True, key=lambda x: x[1])))
print(sum([i * a[i][1] + 1 for i in range(n)]))
print(*[a[i][0] + 1 for i in range(n)])


def main():
	n = int(input())
	data = [int(v) for v in input().split()]
	data = [(v, i) for (i, v) in enumerate(data)]
	data.sort(reverse=True)
	s = 0
	for (i, v) in enumerate(data):
		s += v[0] * i + 1
	print(s)
	print(' '.join([str(v[1] + 1) for v in data]))
main()


n = int(input())
b = []
l = list(map(int, input().strip().split()))[:n]
b = l[:]
b.sort(reverse=True)
hits = 0
k = 0
for i in range(n):
	hits = hits + (k * b[i] + 1)
	k = k + 1
print(hits)
for i in range(n):
	for j in range(n):
		if b[i] == l[j]:
			l[j] = -100
			print(j + 1, end=' ')
			break


n = int(input())
a = list(map(int, input().split()))
b = sorted(a, reverse=True)
(m, y) = (1, 1)
p = a.index(b[0])
a[p] = 0
x = [p + 1]
for i in range(1, n):
	m += b[i] * y + 1
	y += 1
	z = a.index(b[i])
	a[z] = 0
	x.append(z + 1)
print(m)
print(*x)


n = int(input())
a = list(map(int, input().split()))
l = []
sum1 = 0
k = []
for i in range(n):
	l.append((a[i], i + 1))
l.sort(reverse=True)
for i in range(n):
	sum1 = sum1 + l[i][0] * i + 1
	k.append(l[i][1])
print(sum1)
print(*k)


n = int(input())
l = list(map(int, input().split()))
cost = 0
ind = []
for i in range(n):
	ind.append(i)
for i in range(n):
	for j in range(i + 1, n):
		if l[i] < l[j]:
			t = l[i]
			l[i] = l[j]
			l[j] = t
			t = ind[i]
			ind[i] = ind[j]
			ind[j] = t
for i in range(n):
	cost += i * l[i] + 1
print(cost)
for i in range(n):
	print(ind[i] + 1, end=' ')


numcans = int(input())
cans = input().split()
total = 0
newcans = []
two = []
answer = ''
for can in range(numcans):
	cans[can] = int(cans[can])
for zero in range(numcans):
	newcans.append(0)
for can in range(len(cans)):
	counter = 0
	for can2 in range(len(cans)):
		if cans[can2] > cans[can]:
			counter = counter + 1
	while 0 == 0:
		if newcans[counter] == 0:
			newcans[counter] = cans[can]
			break
		else:
			counter = counter + 1
for can in range(numcans):
	total = total + newcans[can] * can + 1
print(total)
for can in range(numcans):
	for can2 in range(numcans):
		if newcans[can] == cans[can2]:
			two.append(can2 + 1)
			cans[can2] = 0
			break
for num in range(numcans):
	print(two[num], end=' ')


n = int(input())
a = list(map(int, input().split()))
l = a.copy()
l.sort()
l.reverse()
c = 0
for i in range(n):
	c += l[i] * i + 1
print(c)
for i in l:
	print(a.index(i) + 1, end=' ')
	a[a.index(i)] = -1


n = int(input())
x = list(map(int, input().split()))
y = []
for i in range(n):
	y.append([x[i], i + 1])
y = sorted(y)
s = 0
temp = []
y = list(reversed(y))
for i in range(n):
	s = s + (y[i][0] * i + 1)
	temp.append(y[i][1])
print(s)
for a in temp:
	print(a, end=' ')


n = int(input())
a = list(map(int, input().split()))[:]
c = s = 0
b = []
for i in range(n):
	m = max(a[:])
	s += m * c + 1
	c += 1
	b.append(a.index(m) + 1)
	a[a.index(m)] = -1
print(s)
print(*b)


n = int(input())
s = list(map(int, input().strip().split()))
d = {}
for (i, j) in enumerate(s):
	if j in d:
		d[j].append(i)
	else:
		d[j] = [i]
for i in d:
	d[i].sort()
dur = sorted(d.keys(), reverse=True)
x = 0
shots = 0
ans = []
for i in dur:
	for j in range(len(d[i])):
		shots += i * x + 1
		x += 1
	for i in d[i]:
		ans.append(str(i + 1))
print(shots)
print(' '.join(ans))


n = int(input())
l = list(map(int, input().split()))
temp = l.copy()
temp.sort(reverse=True)
ans = 0
j = 0
answer = []
for i in temp:
	ans = ans + i * j + 1
	j = j + 1
	x = l.index(i)
	answer.append(x + 1)
	l[x] = 0
print(ans)
print(*answer)


n = int(input())
s = input().split(' ')
s_list = [[int(s[i]), i] for i in range(len(s))]
s_list.sort()
s_list.reverse()
print(sum([s_list[i][0] * i + 1 for i in range(len(s_list))]))
print(' '.join([str(i) for i in [j[1] + 1 for j in s_list]]))


from typing import List
from math import ceil, sqrt, floor, sqrt
from collections import defaultdict, Counter, deque
from collections import defaultdict, deque
n = int(input())
A = list(((v, i + 1) for (i, v) in enumerate(map(int, input().split()))))
A.sort(reverse=True)
res = 0
res_index = []
for i in range(n):
	res += i * A[i][0] + 1
	res_index.append(A[i][1])
print(res)
print(' '.join((str(i) for i in res_index)))


from operator import itemgetter
N = int(input())
A = list(map(int, input().split()))
B = []
for (i, a) in enumerate(A):
	B.append((i, a))
B.sort(reverse=True, key=itemgetter(1))
score = 0
for (n, (i, b)) in enumerate(B):
	score += b * n + 1
print(score)
for (i, _) in B:
	print(i + 1, end=' ')
print()


n = int(input())
l = list(map(int, input().split()))
d = sorted(l, reverse=True)
s = 0
x = []
for i in range(n):
	s = s + d[i] * i + 1
for i in range(n):
	x.append([l[i], i + 1])
x.sort(reverse=True)
y = []
for i in range(n):
	y.append(x[i][1])
print(s)
print(*y)


n = int(input())
a = [int(i) for i in input().split()]
ans = 0
b = []
for i in range(n):
	maxi = 0
	for j in range(n):
		if a[j] >= a[maxi]:
			maxi = j
	ans += i * a[maxi] + 1
	a[maxi] = 0
	b.append(maxi + 1)
print(ans)
print(' '.join((str(i) for i in b)))


n = int(input())
c = [int(x) for x in input().split()]
cs = sorted(range(len(c)), key=lambda k: c[k])
sum = 0
times = 0
for i in reversed(range(n)):
	sum += c[cs[i]] * times + 1
	times += 1
print(sum)
s = ''
cs = [str(x + 1) for x in reversed(cs)]
print(' '.join(cs))


n = int(input())
l = list(map(int, input().split()))
l1 = [i for i in range(1, n + 1)]
for i in range(n):
	min1 = i
	for j in range(i + 1, n):
		if l[j] > l[min1]:
			min1 = j
	(l[i], l[min1]) = (l[min1], l[i])
	(l1[i], l1[min1]) = (l1[min1], l1[i])
count = 0
for i in range(n):
	count += l[i] * i + 1
print(count)
print(*l1)


n = int(input())
kq = 0
out = []
x = 0
a = input()
a = a.split()
for i in range(0, n):
	a[i] = eval(a[i])
while x < n and max(a) != -1:
	c = max(a)
	d = a.index(max(a))
	kq = c * x + 1 + kq
	x = x + 1
	out.append(d + 1)
	a[d] = -1
print(kq)
ou = ' '.join((str(x) for x in out))
print(ou)


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

def num():
	return int(input())
from operator import itemgetter as ig
n = num()
a = sorted(enumerate(line()), key=ig(1))[::-1]
q = sum((v * x for (x, (i, v)) in enumerate(a))) + n
print(q)
print(' '.join(map(str, (i + 1 for (i, v) in a))))


T = int(input())
L = list(map(int, input().split()))
rt = 0
order = ''
l = 0
while l < len(L):
	c = -1
	x = 0
	while x < len(L):
		if c == -1 or L[x] > L[c]:
			c = x
		x += 1
	order += str(c + 1) + ' '
	rt += l * L[c] + 1
	L[c] = 0
	l += 1
print(rt)
print(order)


n = int(input())
a = [int(x) for x in input().split()]
b = []
c = 0
l = []
for x in a:
	b.append(x)
b.sort()
b.reverse()
for x in range(n):
	c += x * b[x] + 1
	l.append(a.index(b[x]) + 1)
	a[a.index(b[x])] = 0
print(c)
for x in l:
	print(x, end=' ')


def main():
	T = int(input().strip())
	s = map(int, input().strip().split())
	s = list(s)
	index = sorted(range(len(s)), key=lambda k: s[k])
	s = sorted(s)
	ans = 0
	for i in range(T):
		ans += s[-(i + 1)] * i + 1
	print(ans)
	index.reverse()
	print(' '.join(('%s' % (num + 1) for num in index)))
main()


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


n = int(input())
v = list(map(int, input().split(' ')))
d = {i: v[i] for i in range(n)}
sorted_dict = {k: d[k] for k in sorted(d, key=d.get, reverse=True)}
L = list(sorted_dict.values())
M = [i + 1 for i in sorted_dict.keys()]
M = list(map(str, M))
minNumber = sum([L[i] * i + 1 for i in range(n)])
print(minNumber)
print(' '.join(M))


n = int(input())
(temp, a, cnt) = (list(map(int, input().split())), [], 0)
for i in range(n):
	a.append((temp[i], i + 1))
a.sort(reverse=True)
temp = []
for i in range(n):
	cnt += a[i][0] * i + 1
	temp.append(a[i][1])
print(cnt)
print(*temp)


(n, a) = (int(input()), list(map(int, input().split())))
b = []
o = 0
for i in range(n):
	pos = -1
	for j in range(n):
		if pos == -1 or a[j] > a[pos]:
			pos = j
	b.append(pos + 1)
	o += i * a[pos] + 1
	a[pos] = 0
print(o)
for i in range(n):
	print(b[i], end=' ')


N = int(input())
L = list(map(int, input().split()))
L2 = []
risultato = 0
for n in range(0, N):
	L2.append([L[n], n + 1])
L2.sort(reverse=True)
for n in range(N):
	risultato = risultato + (n * L2[n][0] + 1)
print(risultato)
for n in range(N):
	print(L2[n][1], end=' ')


n = int(input())
a = list(map(int, input().split()))

def argsort(seq):
	return [x for (x, y) in sorted(enumerate(seq), key=lambda x: x[1], reverse=True)]

def sort(seq):
	return [y for (x, y) in sorted(enumerate(seq), key=lambda x: x[1], reverse=True)]
indexes = argsort(a)
a = sort(a)
s = 0
for i in range(n):
	s += i * a[i] + 1
print(s)
for i in range(n):
	print(indexes[i] + 1, end=' ')


n = int(input())
a = input().split()
b = []
for i in range(n):
	a[i] = int(a[i])
	b.append([a[i], i])
b.sort(reverse=True)
c = []
ans = n
for i in range(n):
	ans += b[i][0] * i
	c.append(b[i][1] + 1)
print(ans)
print(' '.join((str(x) for x in c)))


n = int(input())
l = list(map(int, input().rstrip().split()))
p = sorted(l)
k = []
sum1 = 0
for i in range(n):
	sum1 = sum1 + (p[n - 1 - i] * i + 1)
	j = l.index(p[n - 1 - i])
	k.append(j + 1)
	l[j] = 'a'
print(sum1)
for i in k:
	print(i, end=' ')


n = int(input())
arr = list(map(int, input().split()))
arr1 = [[arr[i], i + 1] for i in range(n)]
arr1.sort(reverse=True)
summ = 0
for i in range(len(arr1)):
	summ += i * arr1[i][0] + 1
print(summ)
for i in arr1:
	print(i[1], end=' ')


n = int(input())
l = [int(x) for x in input().split()]
q = []
for i in range(n):
	q.append([l[i], i + 1])
q.sort()
l = q[::-1]
count = 0
s = str(l[0][1]) + ' '
for i in range(1, len(l)):
	count += i * l[i][0] + 1
	s += str(l[i][1]) + ' '
print(count + 1)
print(s)


from collections import defaultdict as df
n = int(input())
d = df(list)
a = list(map(int, input().rstrip().split()))
for i in range(n):
	d[a[i]].append(i + 1)
a.sort(reverse=True)
a = list(set(a))
a.sort(reverse=True)
sum1 = 0
ans = []
counter = 0
for i in range(len(a)):
	for j in d[a[i]]:
		sum1 += a[i] * counter + 1
		counter += 1
		ans.append(j)
print(sum1)
print(*ans)


n = int(input())
a = list(map(int, input().split()))
x = max(a)
y = a.copy()
y.sort(reverse=True)
sum = 1
l = []
l.append(a.index(y[0]))
i = 1
while i < len(y):
	if a.index(y[i]) not in l:
		sum = sum + i * y[i] + 1
		l.append(a.index(y[i]))
		i += 1
	else:
		g = [j for (j, value) in enumerate(a) if value == y[i]]
		for k in range(1, len(g)):
			l.append(g[k])
			sum = sum + i * y[i] + 1
			i += 1
print(sum)
for i in l:
	print(i + 1, end=' ')


n = int(input())
inputlist = list(map(int, input().split()))
outputlist = list(reversed(sorted(inputlist)))
shootcount = 0
x = 0
for j in outputlist:
	shootcount += j * x + 1
	x += 1
print(shootcount)
elementlist = []
countlist = []
for i in outputlist:
	if i not in elementlist:
		elementlist.append(i)
for i in elementlist:
	count = 0
	for j in outputlist:
		if i == j:
			count += 1
		else:
			continue
	countlist.append(count)
indexlist = []
index = 0
indexmain = 0
for i in countlist:
	if indexmain >= len(elementlist):
		break
	count = 0
	for j in inputlist:
		if count == i:
			break
		if j == elementlist[indexmain]:
			count += 1
			indexlist.append(index)
			index += 1
		else:
			index += 1
			continue
	indexmain += 1
	index = 0
string = ''
for j in indexlist:
	string += str(j + 1) + ' '
print(string[:len(string) - 1])


n = int(input())
a = sorted(zip(map(int, input().split()), range(1, n + 1)), reverse=True)
ans = 0
for i in range(n):
	ans += a[i][0] * i + 1
print(ans)
print(*(x for (_, x) in a))


n = int(input())
arr = map(int, input().split())
lst = []
for (i, n) in enumerate(arr, start=1):
	lst.append((n, i))
sor = sorted(lst, key=lambda x: x[0], reverse=True)
ans = [i[1] for i in sor]
tot = 0
step = 0
for i in sor:
	tot += i[0] * step + 1
	step += 1
print(tot)
print(*ans)


n = int(input())
a = list(map(int, input().split()))
b = []
for (i, j) in enumerate(a):
	b.append((j, i))
b.sort(reverse=True)
ans = 0
for (j, i) in enumerate(b):
	ans += i[0] * j + 1
print(ans)
for (i, j) in b:
	print(j + 1, end=' ')


n = int(input())
arr = list(map(int, input().split()))
temp = [(c, i) for (i, c) in enumerate(arr)]
temp.sort(reverse=True)
score = 0
order = []
for (i, can) in enumerate(temp):
	score += can[0] * i + 1
	order.append(can[1] + 1)
print(score)
print(*order)


n = int(input())
a = list(enumerate(map(int, input().split())))
res = 1
a.sort(reverse=True, key=lambda x: x[1])
ans = [a[0]]
for i in range(1, len(a)):
	res += a[i][1] * i + 1
	ans.append(a[i])
print(res)
for l in ans:
	print(l[0] + 1, end=' ')


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
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 = 1000000007

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 p in range(t):
		solve()

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

def solve():
	n = int(inp())
	ar = lis()
	temp = []
	for i in range(n):
		temp.append((ar[i], i + 1))
	temp.sort(reverse=True)
	ans = 0
	answer = []
	for i in range(n):
		ans += temp[i][0] * i + 1
		answer.append(temp[i][1])
	print(ans)
	printlist(answer)
solve()


n = int(input())
arr = list(map(int, input().strip().split(' ')))
ar = []
for i in range(n):
	ar.append([arr[i], i + 1])
ar.sort(reverse=True)
shots = 0
for i in range(n):
	shots += ar[i][0] * i + 1
print(shots)
for i in range(n):
	print(ar[i][1], end=' ')


import sys
import math
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
ans = list()
for i in range(n):
	ans.append([arr[i], i + 1])
ans.sort(reverse=True)
d = 0
for i in range(n):
	d += ans[i][0] * i + 1
print(d)
for i in range(n):
	print(ans[i][1], end=' ')
print()


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

def si():
	return input()

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

def li():
	return list(mi())
import math
n = ii()
a = li()
l = sorted(a, reverse=True)
ans = 0
for i in range(n):
	ans += l[i] * i + 1
b = [i[0] for i in sorted(enumerate(a), key=lambda x: x[1])]
print(ans)
b = b[::-1]
for i in range(n):
	b[i] += 1
print(*b)


line1 = input()
arr = list(enumerate(map(int, str(input()).split(' '))))
arr.sort(key=lambda x: x[1], reverse=True)
res = 0
x = 0
for (i, a) in arr:
	res += x * a + 1
	x += 1
print(res)
print(' '.join((str(x + 1) for (x, _) in arr)))


a = int(input())
b = list(map(int, input().split()))
k = -10000
l = h = 0
p = []
for i in range(a):
	for j in range(a):
		if b[j] > k:
			k = b[j]
			l = j
	h += k * i + 1
	p.append(l + 1)
	b[l] = 0
	l = 0
	k = -1000
print(h)
print(*p)


import math
n = int(input())
shots = 1
a = list(map(int, input().split()))
mat = []
for i in range(n):
	mat.append([i + 1, a[i]])
mat.sort(key=lambda x: x[1], reverse=True)
for i in range(1, n):
	shots += mat[i][1] * i + 1
print(shots)
for i in range(n):
	if i < n - 1:
		print(mat[i][0], end=' ')
	else:
		print(mat[i][0])


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = list()
for i in range(n):
	b.append([a[i], i + 1])
b = sorted(b, reverse=True)
x = 0
res = list()
ans = 0
for i in range(n):
	ans += b[i][0] * x + 1
	res.append(b[i][1])
	x += 1
print(ans)
print(*res)


n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
	b.append([a[i], i])
b.sort(key=lambda x: x[0], reverse=True)
cnt = 0
s = 0
res = []
for i in range(n):
	s += cnt * b[i][0] + 1
	cnt += 1
	res.append(str(b[i][1] + 1))
print(s)
print(' '.join(res))


n = int(input())
a = list(map(int, input().split()))
res = 0
kn = 0
b = list(range(1, n + 1))
b = [str(x) for (_, x) in sorted(zip(a, b), reverse=True)]
for x in b:
	res += a[int(x) - 1] * kn + 1
	kn += 1
print(res)
print(' '.join(b))


n = int(input())
a = list(map(int, input().split()))
b = [(v, i + 1) for (i, v) in enumerate(a)]
b.sort(reverse=True)
res = 0
c = 0
for (v, i) in b:
	res += c * v + 1
	c += 1
print(res)
for i in range(n - 1):
	print(b[i][1], end=' ')
print(b[n - 1][1])


n = int(input())
ar = list(map(int, input().split()))
ls = []
for i in range(n):
	ls.append([ar[i], i + 1])
ls.sort(reverse=True)
cnt = 0
s = ''
for i in range(n):
	cnt += ls[i][0] * i + 1
	s += f'{ls[i][1]} '
print(cnt)
print(s)


n = int(input())
a = list(map(int, input().split()))
d = {}
res = []
(c, j) = (0, 0)
for i in range(len(a)):
	d[i + 1] = a[i]
for i in sorted(a, reverse=True):
	c += i * j + 1
	j += 1
d = sorted(d.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)
for i in d:
	res.append(i[0])
print(c)
print(' '.join(list(map(str, res))))


n = int(input())
A = list(map(int, input().split()))
for i in range(n):
	A[i] = [A[i], i]
A.sort(reverse=True)
B = []
result = 0
for i in range(n):
	(x, ind) = A[i]
	result += x * i + 1
	B.append(ind + 1)
print(result)
for i in B:
	print(i, end=' ')


n = int(input())
c = list(map(int, input().split()))
d = sorted(c, reverse=True)
e = sorted(list(set(d)), reverse=True)
index = []
i = 0
cnt = 0
for j in e:
	for k in range(len(c)):
		if j == c[k]:
			index.append(k + 1)
for j in d:
	cnt += j * i + 1
	i += 1
print(cnt)
print(*index)


from sys import stdin
n = int(stdin.readline())
cans = list(map(int, stdin.readline().split()))
cans = [(cans[idx], idx + 1) for idx in range(n)]
cans = sorted(cans, key=lambda x: x[0], reverse=True)
times = 0
for idx in range(n):
	times += cans[idx][0] * idx + 1
print(times)
for can in cans:
	print(can[1], end=' ')


x = eval(input())
y = input().split(' ')
y = list(map(int, y))
c = 0
z = []
for i in range(len(y)):
	y[i] = (y[i], i + 1)
y = sorted(y)
for i in range(len(y)):
	c += y[len(y) - 1 - i][0] * i + 1
	z += [str(y[len(y) - 1 - i][1])]
print(c)
print(' '.join(z))


n = int(input())
nums = list(map(int, input().split()))
li = [[i, nums[i]] for i in range(len(nums))]
li = sorted(li, key=lambda l: l[1], reverse=True)
s = 0
for i in range(len(nums)):
	s += i * nums[li[i][0]] + 1
print(s)
for i in range(len(nums)):
	print(li[i][0] + 1, end=' ')
print()


n = int(input())
s = list(map(int, input().split()))
a = sorted(list(zip(*[s, list(range(1, n + 1))])), reverse=True)
b = 0
c = ''
for (i, k) in enumerate(a):
	b += i * k[0] + 1
	c += str(k[1]) + ' '
print(b)
print(c)


n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(n):
	d[i + 1] = a[i]
c = 0
b = []
res = 0
for (k, v) in sorted(d.items(), key=lambda x: (x[1], x[0]), reverse=True):
	res += v * c + 1
	c += 1
	b.append(str(k))
print(res)
print(' '.join(b))


n = int(input())
nums = list(map(int, input().split()))
temp = [(nums[i], i) for i in range(len(nums))]
temp = sorted(temp, reverse=True)
ans = 0
for i in range(len(nums)):
	ans += temp[i][0] * i + 1
print(ans)
for i in range(len(nums)):
	print(temp[i][1] + 1, end=' ')


n = int(input())
a = list(map(int, input().split()))
b = []
for (x, y) in enumerate(a):
	b.append((y, x))
b.sort()
b.reverse()
c = 0
r = []
for (i, (x, y)) in enumerate(b):
	c += i * x + 1
	r.append(str(y + 1))
print(c)
print(' '.join(r))


n = int(input())
l = list(map(int, input().split()))
t = []
j = [0] * n
t = sorted(l)
s = 0
t.reverse()
for i in range(n):
	s += t[i] * i + 1
	for x in range(n):
		if t[i] == l[x]:
			j[i] = x + 1
			l[x] = 0
			break
print(s)
print(*j)


import os

def f(arr):
	i_a_arr = [(i + 1, a) for (i, a) in enumerate(arr)]
	i_a_arr.sort(key=lambda x: -x[1])
	result = 0
	for i in range(len(i_a_arr)):
		result += i_a_arr[i][1] * i + 1
	return f"{result}\n{''.join((str(i) + ' ' for (i, a) in i_a_arr))}"
if os.environ.get('DEBUG', False):
	print(f'{f([20, 10, 20])} = 43 [1 3 2]')
	print(f'{f([10, 10, 10, 10])} = 64 [2 1 4 3]')
	print(f'{f([5, 4, 5, 4, 4, 5])} = 69 [6 1 3 5 2 4]')
	print(f'{f([1, 4])} = 3 [2 1]')
else:
	input()
	arr = list(map(int, input().split()))
	print(f(arr))


n = int(input())
a = sorted(enumerate(map(int, input().split())), key=lambda x: x[1], reverse=True)
shots = 0
output = [0] * n
for i in range(n):
	shots += a[i][1] * i + 1
	output[i] = a[i][0] + 1
print(shots)
print(*output)


import sys
import os
from io import IOBase, BytesIO
import math
import collections
mod = 10 ** 9 + 7
pie = 3.1415926536

def modinv(n, p):
	return pow(n, p - 2, p)

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def ain():
	return list(map(int, sin().split()))

def sin():
	return input().strip()

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def read2DIntArray(row, col):
	arr = []
	for i in range(0, row):
		temp = list(map(int, sin().split()))
		arr.append(temp)
	return arr

def read2DCharArray(row, col):
	arr = []
	for i in range(0, row):
		temp = str(sin())
		arr.append(temp)
	return arr

def smallestNumber(n):
	lst = list(str(n))
	lst.sort()
	tmp = ''
	for (i, n) in enumerate(lst):
		if n != '0':
			tmp = lst.pop(i)
			break
	return str(tmp) + ''.join(lst)

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 * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	lst = []
	for p in range(n + 1):
		if prime[p]:
			lst.append(p)
	return lst

def nCr(n, r):
	a = 1
	b = 1
	c = 1
	for i in range(1, n + 1):
		c *= i
	for i in range(1, r + 1):
		b *= i
	for i in range(1, n - r + 1):
		a *= i
	return c // (a * b)

def sieveOfEratosthenes1(N, s):
	prime = [False] * (N + 1)
	for i in range(2, N + 1, 2):
		s[i] = 2
	for i in range(3, N + 1, 2):
		if prime[i] == False:
			s[i] = i
			for j in range(i, int(N / i) + 1, 2):
				if prime[i * j] == False:
					prime[i * j] = True
					s[i * j] = i

def generatePrimeFactors(N):
	s = [0] * (N + 1)
	sieveOfEratosthenes1(N, s)
	curr = s[N]
	cnt = 1
	factors = []
	power = []
	while N > 1:
		N //= s[N]
		if curr == s[N]:
			cnt += 1
			continue
		factors.append(curr)
		power.append(cnt)
		curr = s[N]
		cnt = 1
	return (factors, power)

def main():
	n = int(sin())
	a = ain()
	lst = []
	for i in range(n):
		lst.append((a[i], i + 1))
	lst = sorted(lst, key=lambda x: x[0], reverse=True)
	ans = 0
	for i in range(n):
		idx = lst[i][1] - 1
		ans += a[idx] * i + 1
	print(ans)
	for i in range(n):
		print(lst[i][1], end=' ')
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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()


def shooting(n, array):
	arridx = []
	arrsort = []
	sum = 0
	locs = []
	for i in range(n):
		ele = array.index(array[i])
		arridx.append(ele + 1)
	for i in range(n):
		arrsort.append(array[i])
	arrsort.sort(reverse=True)
	for i in range(n):
		sum += arrsort[i] * i + 1
	locs = [i[0] for i in sorted(enumerate(array), reverse=True, key=lambda x: x[1])]
	print(sum)
	for i in range(n):
		print(locs[i] + 1, end=' ')
n = int(input())
arr = [int(x) for x in input().split()]
shooting(n, arr)


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


n = int(input())
l = list(map(int, input().split()))
k = sorted(l, reverse=True)
total = 0
for i in range(len(k)):
	total = total + (i * k[i] + 1)
print(total)
for i in range(len(l)):
	print(l.index(k[i]) + 1, end=' ')
	l[l.index(k[i])] = -1


n = int(input())
a = [int(i) for i in input().split()]
posl = []
x = 0
amount = 0
m = max(a)
while m:
	amount += m * x + 1
	x += 1
	ind = a.index(m)
	posl.append(ind + 1)
	a[ind] = 0
	m = max(a)
print(amount)
print(*posl)


n = int(input())
A = [int(_) for _ in input().split()]
B = sorted(A, reverse=True)
c = 0
for _ in range(n):
	c += B[_] * _ + 1
print(c)
for _ in B:
	x = A.index(_)
	A[x] = 0
	print(x + 1, end=' ')


n = input()
liste = input().split(' ')
liste = [int(element) for element in liste]
liste = sorted(enumerate(liste), key=lambda x: x[1], reverse=True)
shots = 0
order = ''
for i in range(len(liste)):
	shots += 1 + liste[i][1] * i
	order += str(liste[i][0] + 1) + ' '
print(str(shots) + '\n' + order[:-1])


n = int(input())
a = []
d = []
x = 0
t = 0
m = 0
a = list(map(int, input().split()))
for j in range(n):
	m = max(a)
	dex = a.index(m)
	d.append(dex + 1)
	t += m * x + 1
	x += 1
	a[dex] = -1
print(t)
print(*d)


from operator import itemgetter
n = int(input())
l = list(map(int, input().split()))
l = [(i + 1, v) for (i, v) in enumerate(l)]
l = sorted(l, key=itemgetter(1), reverse=True)
shot = 0
result = []
for i in range(n):
	result.append(l[i][0])
	shot += l[i][1] * i + 1
print(shot)
print(*result)


n = int(input())
a = list(map(int, input().split()))
indx = [i[0] for i in sorted(enumerate(a), reverse=True, key=lambda x: x[1])]
a = sorted(a, reverse=True)
count = 0
for i in range(len(a)):
	count += a[i] * i + 1
print(count)
for i in indx:
	print(i + 1, end=' ')
print()


n = int(input())
a = [*map(int, input().split())]
A = []
for i in range(n):
	A.append((a[i], i))
A.sort(reverse=True)
x = 0
res = 0
l = []
for i in A:
	res += i[0] * x + 1
	x += 1
	l.append(i[1])
print(res)
for i in l:
	print(i + 1, end=' ')


n = int(input())
s = list(map(int, input().split()))
a = s[:]
s.sort(reverse=True)
c = 0
for i in range(n):
	c += i * s[i] + 1
print(c)
for i in range(n):
	for j in range(n):
		if a[j] == s[i]:
			print(j + 1, end=' ')
			a[j] = -1
			break
print()


from itertools import count
n = int(input())
counter = count(1)

def tuples(*args):
	for arg in args:
		return (int(arg), next(counter))
a = list(map(tuples, input().split()))
a.sort(reverse=True)
result = 0
for (index, (val, org_index)) in enumerate(a):
	result += val * index + 1
print(result)
for (val, index) in a:
	print(index, end=' ')


n = int(input())
aa = list(map(int, input().split()))
a = [[0] * 2 for i in range(n)]
for i in range(n):
	a[i][0] = aa[i]
	a[i][1] = i + 1
a.sort(key=lambda x: x[0])
k = 0
x = 0
for i in range(n - 1, -1, -1):
	k += a[i][0] * x + 1
	x += 1
print(k)
for i in range(n - 1, -1, -1):
	print(a[i][1], end=' ')


(n, inp) = (int(input()), input().split())
a = [(int(inp[i]), i) for i in range(n)]
a.sort(key=lambda x: x[0], reverse=True)
ttl = 0
for i in range(n):
	ttl = ttl + a[i][0] * i + 1
print(ttl)
for ai in a:
	print(ai[1] + 1, end=' ')
print()


t = int(input())
lst = list(map(int, input().split()))
x1 = []
for i in range(len(lst)):
	a = [lst[i], i + 1]
	x1.append(a)
x1.sort(key=lambda x: x[0])
ans = []
s = 0
x = 0
for i in range(len(x1) - 1, -1, -1):
	ans.append(x1[i][1])
	s += x1[i][0] * x + 1
	x += 1
print(s)
print(*ans)


n = int(input())
l = list(map(int, input().split()))
L = []
colpi_sparati = 0
ordine = ''
for x in range(len(l)):
	temp = [l[x], x + 1]
	L.append(temp)
L.sort(reverse=True)
for x in range(len(l)):
	colpi_sparati = colpi_sparati + (x * L[x][0] + 1)
	ordine = ordine + str(L[x][1]) + ' '
print(colpi_sparati)
print(ordine)


n = int(input())
l = [int(l) for l in input().split()]
(c, x) = (0, 0)
l1 = []
for i in range(n):
	m = max(l)
	c += m * x + 1
	x += 1
	l1.append(l.index(m) + 1)
	l[l.index(m)] = 0
print(c)
for i in l1:
	print(i, end=' ')


N = int(input())
a = input().split()
for x in range(N):
	a[x] = (int(a[x]), x + 1)
a.sort()
a.reverse()
b = 0
o = []
for x in range(N):
	b = b + x * a[x][0] + 1
print(b)
for x in range(N):
	print(a[x][1], end=' ')


n = int(input())
a = [int(x) for x in input().split(' ')]
b = sorted(list(enumerate(a)), key=lambda x: x[1], reverse=True)
ans = [x[0] + 1 for x in b]
a.sort(reverse=True)
cnt = 0
for i in range(n):
	cnt += a[i] * i + 1
print(cnt)
print(*ans)


from __future__ import division, print_function
from sys import stdin, stdout
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from fractions import Fraction
import math

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

def si():
	return str(input())

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

def li():
	return list(mi())

def fii():
	return int(stdin.readline())

def fsi():
	return str(stdin.readline())

def fmi():
	return map(int, stdin.readline().split())

def fli():
	return list(fmi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

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

def ntl(n):
	return [int(i) for i in str(n)]

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

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)
from collections import defaultdict

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y, z) = mi()
		if x not in d:
			d[x] = [[z, y]]
		else:
			d[x].append([z, y])
		if y not in d:
			d[y] = [[z, x]]
		else:
			d[y].append([z, x])
	return d

def gr2(n):
	d = defaultdict(list)
	for i in range(n):
		(x, y) = mi()
		d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)

def SieveOfEratosthenes(n, isPrime):
	isPrime[0] = isPrime[1] = False
	for i in range(2, n + 1):
		isPrime[i] = True
	p = 2
	while p * p <= n:
		if isPrime[p] == True:
			i = p * p
			while i <= n:
				isPrime[i] = False
				i += p
		p += 1
	return isPrime
n = ii()
l = li()
s = []
for i in range(n):
	s.append([l[i], i + 1])
s = sorted(s)[::-1]
x = str(s[0][1])
s = s[1:]
count = 1
out = [x]
for i in range(1, n):
	count += s[i - 1][0] * i + 1
	out.append(str(s[i - 1][1]))
print(count)
print(' '.join(out))


from sys import stdin, stdout
(n, sumy) = (int(input()), 1)
l = list(map(int, input().split()))
shan = sorted(l, reverse=True)
siri = []
for e in shan:
	j = l.index(e)
	l[j] = 0
	siri.append(j + 1)
for i in range(1, n):
	sumy += shan[i] * i + 1
print(sumy)
print(*siri)


n = int(input())
a = list(map(int, input().split()))
ans = 0
ans_i = [-1] * n
max_a = max(a)
ind_a = a.index(max_a)
for i in range(n):
	ans_i[i] = ind_a + 1
	ans += a[ind_a] * i + 1
	a[ind_a] = -1
	max_a = max(a)
	ind_a = a.index(max_a)
print(ans)
for i in range(n):
	print(ans_i[i], end=' ')


(n, a) = (int(input()), list(map(int, input().split())))
res = []
ans = 0
for i in range(n):
	pos = -1
	for j in range(n):
		if pos == -1 or a[j] > a[pos]:
			pos = j
	res.append(pos + 1)
	ans += i * a[pos] + 1
	a[pos] = 0
print(ans)
print(' '.join([str(x) for x in res]))


n = int(input())
s = list(map(int, input().split()))
q = sorted(range(len(s)), key=lambda k: s[k])
q = q[::-1]
res = ''
c = 0
for i in range(n):
	m = s[q[i]]
	c += m * i + 1
	res += str(q[i] + 1) + ' '
print(c)
print(res)


n = int(input())
a = list(map(int, input().split()))
li = []
for i in range(n):
	li.append([a[i], i + 1])
b = sorted(li, key=lambda x: x[0], reverse=True)
shots = 0
for i in range(n):
	shots += b[i][0] * i + 1
print(shots)
for i in b:
	print(i[1], end=' ')


n = int(input())
l = [int(i) for i in input().split()][:n]
temp1 = []
count = 0
s = len(l)
while s > 0:
	x = max(l)
	if x != -1:
		i = l.index(x)
	val = l.pop(i)
	l.insert(i, -1)
	temp1.append(list([val, i]))
	s -= 1
temp2 = []
for i in range(len(temp1)):
	temp2.append(list([temp1[i][0], temp1[i][1] + 1]))
temp3 = sorted(temp2, reverse=True)
sum = 0
count = 0
for i in range(len(temp3)):
	sum = sum + (temp3[i][0] * count + 1)
	count += 1
print(sum)
for i in range(len(temp3)):
	print(temp3[i][1], end=' ')


n = int(input())
l = [int(i) for i in input().split()]
l1 = [[l[i], i] for i in range(n)]
l1.sort(key=lambda x: -x[0])
sm = 0
cnt = 0
for i in range(n):
	sm += cnt * l1[i][0] + 1
	cnt += 1
print(sm)
print(' '.join((str(l1[i][1] + 1) for i in range(n))))


n = int(input())
arr = list(map(int, input().split()))
data = []
for i in range(n):
	data.append([arr[i], i])
shots = 0
ans = 0
data.sort(key=lambda x: x[0], reverse=True)
for i in range(n):
	ans += shots * data[i][0] + 1
	shots += 1
print(ans)
for i in data:
	print(i[1] + 1, end=' ')


cans = int(input())
durability = input().split()
indexed_dur = []
for (index, value) in enumerate(durability):
	indexed_dur.append([index, int(value)])
indexed_dur.sort(key=lambda x: x[1], reverse=True)
cost = 0
order = []
for i in range(0, len(indexed_dur)):
	cost += indexed_dur[i][1] * i + 1
	order.append(str(indexed_dur[i][0] + 1))
print(cost)
print(' '.join(order))


import sys
input = sys.stdin.readline
cf = lambda a, x: a * x + 1
n = int(input())
cans = list(map(int, input().split()))
c_i = [(c, i) for (i, c) in enumerate(cans, start=1)]
c_i.sort(reverse=True)
index = []
cost = 0
for (pre, (c, i)) in enumerate(c_i):
	cost += cf(c, pre)
	index.append(i)
print(cost)
print(*index)


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 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 ' '.join(map(str, arr))

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

def revn(n):
	m = 0
	while n > 0:
		m = m * 10 + n % 10
		n = n // 10
	return m
n = ii()
a = li()
b = []
for i in range(n):
	b.append([a[i], i])
b.sort(reverse=True)
ans = 0
for i in range(n):
	ans += b[i][0] * i + 1
pos = []
for i in range(n):
	pos.append(b[i][1] + 1)
print(ans)
print(wr(pos))


def shooting():
	total = int(input())
	cans = input().split()
	checker = [False for i in range(len(cans))]
	output = 0
	output2 = ''
	for i in range(len(cans)):
		maximum = 0
		position = 0
		for j in range(len(cans)):
			if not checker[j]:
				if int(cans[j]) > maximum:
					maximum = int(cans[j])
					position = j
		checker[position] = True
		output += maximum * i + 1
		output2 += str(position + 1) + ' '
	print(output)
	print(output2)
shooting()


from sys import stdin, stdout
n = int(input())
D = list(map(int, input().split()))
for i in range(n):
	D[i] = [D[i], i]
D.sort(reverse=True)
ans = 0
for (i, d) in enumerate(D):
	ans += d[0] * i + 1
print(ans)
for d in D:
	print(d[1] + 1, end=' ')


import sys
input = lambda : sys.stdin.readline().strip()
n = int(input())
ls = list(map(int, input().split()))
ls = [(i, ls[i - 1]) for i in range(1, n + 1)]
ls.sort(key=lambda x: x[1])
ls.reverse()
cnt = 0
for i in range(n):
	cnt += i * ls[i][1] + 1
print(cnt)
for i in range(n):
	print(ls[i][0], end=' ')
print()


n = int(input())
a = [int(t) for t in input().split(' ')]
res = []
total = 0
i = 0
for (idx, d) in sorted(enumerate(a), reverse=True, key=lambda a: a[1]):
	total += d * i + 1
	res.append(idx)
	i += 1
print(total)
print(' '.join([str(t + 1) for t in res]))


n = int(input())
l = list(map(int, input().split()))
l1 = []
for i in range(n):
	l1.append([l[i], i + 1])
c = 0
x = 0
s = ''
l1.sort(reverse=True)
for i in range(n):
	c += l1[i][0] * x + 1
	x += 1
	s += str(l1[i][1]) + ' '
print(c)
print(s)


n = int(input())
numbers = [int(k) for k in input().split(' ')]
dic = {}
for i in range(n):
	dic[str(i + 1)] = numbers[i]
x = [sorted(dic.values(), reverse=True), sorted(dic, key=dic.get, reverse=True)]
sum = 0
st = ''
for i in range(len(x[0])):
	numb = x[0][i]
	sum += 1 + numb * i
	st += str(x[1][i]) + ' '
print(sum)
print(st.strip())


n = int(input())
a = list(map(int, input().split()))
c = []
for i in range(n):
	c.append([i + 1, a[i]])
c.sort(key=lambda x: x[1], reverse=True)
res = 0
for i in range(n):
	res += c[i][1] * i + 1
print(res)
for i in range(n):
	print(c[i][0], end=' ')


n = int(input())
array = list(map(int, input().split()))
array = [[array[i], i] for i in range(n)]
array.sort(reverse=True)
count = 0
x = 0
for el in array:
	count += el[0] * x + 1
	x += 1
array = [array[i][1] + 1 for i in range(n)]
print(count)
print(*array)


ll = lambda : list(map(int, input().split()))
testcases = 1
for _ in range(testcases):
	[n] = ll()
	a = ll()
	d = []
	for i in range(n):
		d.append([a[i], i + 1])
	d.sort(reverse=True)
	ans = 0
	for i in range(0, n):
		ans += d[i][0] * i + 1
	print(ans)
	for x in range(n):
		print(d[x][1], end=' ')


N = int(input())
a = list(map(int, input().split()))
b = []
for i in range(N):
	b.append([a[i], i])
b.sort()
b.reverse()
ans = 0
for i in range(N):
	ans += b[i][0] * i + 1
print(ans)
for i in range(N):
	if i == N - 1:
		print(b[i][1] + 1)
	else:
		print(b[i][1] + 1, end=' ')


n = int(input())
arr = [int(i) for i in input().split()]
Dict = []
for i in range(n):
	Dict.append([arr[i], i])
Dict.sort(reverse=True)
count = 0
for i in range(n):
	count += Dict[i][0] * i + 1
print(count)
for i in range(n - 1):
	print(Dict[i][1] + 1, end=' ')
print(Dict[-1][1] + 1)


n = int(input())
c = list(map(int, input().split()))
su = 0
d = {}
for i in range(n):
	if c[i] not in d:
		d[c[i]] = [i + 1]
	else:
		d[c[i]].append(i + 1)
f = []
c = sorted(c, reverse=True)
for i in range(n):
	su = su + i * c[i] + 1
	f.append(d[c[i]][0])
	d[c[i]].pop(0)
print(su)
print(*f, sep=' ')


n = int(input())
ls = list(map(int, input().split()))
ds = dict()
for i in range(len(ls)):
	ds[i] = ls[i]
import operator
sorted_d = sorted(ds.items(), key=operator.itemgetter(1), reverse=True)
ans = 0
for (i, j) in enumerate(sorted_d):
	ans += i * j[1] + 1
print(ans)
for i in sorted_d:
	print(i[0] + 1, end=' ')


n = int(input())
s = list(map(int, input().split()))
l = sorted(s, reverse=True)
ans = 0
c = 0
for i in l:
	ans += i * c + 1
	c += 1
print(ans)
for i in l:
	u = s.index(i)
	print(u + 1, end=' ')
	s[u] = -1
print()


n = int(input())
s = [*map(int, input().split())]
ls = dict()
for i in range(n):
	ls[i + 1] = s[i]
ls = dict(reversed(sorted(ls.items(), key=lambda kv: kv[1])))
x = 0
shot = 0
for (k, v) in ls.items():
	shot += v * x + 1
	x += 1
print(shot)
for k in ls.keys():
	print(k, end=' ')


def arr_enu():
	return [[i + 1, int(x)] for (i, x) in enumerate(input().split())]

def print_arr(arr):
	print(*arr, sep=' ')

def get_col(arr, i):
	return [row[i] for row in arr]
(n, a, out) = (int(input()), arr_enu(), 1)
a.sort(reverse=True, key=lambda x: x[1])
for i in range(1, n):
	out += a[i][1] * i + 1
print(out)
print_arr(get_col(a, 0))


n = int(input())
s = input()
arr = list(map(int, s.split(' ')))
x = 0
shot = 0
new = []
used = set()
for i in range(len(arr)):
	ind = arr.index(max(arr))
	new.append(str(ind + 1))
	shot += arr[ind] * x + 1
	x += 1
	arr[ind] = -1
	used.add(ind)
print(shot)
print(' '.join(new))


n = int(input())
inp = input()
inp_arr = inp.split(' ')
inp_arr_int = [int(i) for i in inp_arr]
arr1 = [(inp_arr_int[i], i) for i in range(n)]
arr1.sort(reverse=True)
out_arr = [str(arr1[i][1] + 1) for i in range(n)]
shots = 0
for i in range(n):
	shots += arr1[i][0] * i + 1
out = ' '.join(out_arr)
print(shots)
print(out)


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

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 list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
A = [(a, i + 1) for (i, a) in enumerate(A)]
A.sort(reverse=1)
cnt = 0
for (i, (a, _)) in enumerate(A):
	cnt += a * i + 1
(_, idxs) = zip(*A)
print(cnt)
print(*idxs)


def main():
	input()
	arr = [(int(x), i + 1) for (i, x) in enumerate(input().split(' '))]
	res = 0
	sor_arr = sorted(arr)[::-1]
	for (cnt, (x, i)) in enumerate(sor_arr):
		res += cnt * x + 1
	print(res)
	print(' '.join((str(i) for (_, i) in sor_arr)))
main()


n = int(input())
a = [int(n) for n in input().split()]
d = dict()
for i in range(n):
	d[i] = a[i]
l1 = list(d.keys())
l2 = list(d.values())
l3 = zip(l1, l2)
l3 = sorted(l3, key=lambda x: x[1])
l3.reverse()
su = 0
for i in range(n):
	su += l3[i][1] * i
su += n
print(su)
for i in range(n):
	print(l3[i][0] + 1, end=' ')


n = int(input())
g = []
l = [int(j) for j in input().split()]
for i in range(n):
	g.append([l[i], i + 1])
g.sort(reverse=True)
s = 0
for i in range(n):
	s += g[i][0] * i + 1
print(s)
for i in range(n):
	print(g[i][1], end=' ')


import operator
import collections
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
	b.append([a[i], i])
b.sort(key=lambda x: x[0], reverse=True)
s = 0
c = []
for i in range(n):
	s += b[i][0] * i + 1
	c.append(b[i][1] + 1)
print(s)
print(*c)


from sys import stdin, stdout
n = int(stdin.readline())
arr = [int(x) for x in stdin.readline().split()]
new_arr = sorted(arr, reverse=True)
cost = 0
new_pos = []
for (i, val) in enumerate(new_arr):
	cost += val * i + 1
	indexes = arr.index(val)
	new_pos.append(indexes)
	arr[indexes] = -1
stdout.write(str(cost) + '\n')
for cos in new_pos:
	stdout.write(str(cos + 1) + ' ')


n = map(int, input().split())
A = list(map(int, input().split()))
la = []
ind = 1
for a in A:
	la.append((a, ind))
	ind += 1
la.sort(key=lambda x: x[0], reverse=True)
x = 0
sm = 0
li = []
for tp in la:
	a = tp[0]
	sm += a * x + 1
	x += 1
	li.append(tp[1])
print(sm)
print(' '.join((str(i) for i in li)))


n = int(input())
s = map(int, input().split())
s = list(s)
ss = []
c = 0
for i in range(n):
	c = c + (max(s) * i + 1)
	ss.append(s.index(max(s)) + 1)
	s[s.index(max(s))] = 0
print(c)
print(' '.join(map(str, ss)))


from sys import stdin
n = int(stdin.readline().strip())
s1 = list(map(int, stdin.readline().strip().split()))
s = []
for i in range(n):
	s.append([s1[i], i])
s.sort()
ans = 0
c = 0
res = []
for i in range(n - 1, -1, -1):
	ans += c * s[i][0] + 1
	res.append(s[i][1] + 1)
	c += 1
print(ans)
print(*res)


n = int(input())
a = list(map(int, input().split()))
o = sorted(range(n), key=lambda k: a[k])[::-1]
o = [x + 1 for x in o]
a = sorted(a)[::-1]
ans = 0
for i in range(n):
	ans += a[i] * i + 1
print(ans)
print(' '.join(list(map(str, o))))


n = int(input())
a = list(map(int, input().split()))
b = []
ans = 0
mm = max(a)
for i in range(n):
	m = max(a)
	ans += m * i + 1
	b.append(a.index(m) + 1)
	a[a.index(m)] = -1
print(ans)
print(*b)


from itertools import count
n = int(input())
targets = sorted(map(lambda x: (x[0], int(x[1])), zip(count(), input().split(' '))), key=lambda x: x[1], reverse=True)
result = 0
for (c, (_, strength)) in zip(count(), targets):
	result = result + 1 + c * strength
print(result)
print(' '.join(map(lambda x: str(x[0] + 1), targets)))


n = int(input())
a = list(map(int, input().split()))
b = list(a)
b.sort()
b.reverse()
count = 0
for i in range(n):
	count += b[i] * i + 1
print(count)
for i in b:
	print(a.index(i) + 1, end=' ')
	a[a.index(i)] = '#'


n = int(input())
nums = list(map(int, input().strip().split()))
sore = sorted(nums, reverse=True)
alist = []
count = 0
for (shin, i) in enumerate(sore):
	ind = nums.index(i)
	count += shin * nums[ind] + 1
	nums[ind] = None
	alist.append(str(ind + 1))
print(count)
print(' '.join(alist))


s = int(input())
li = list(map(int, input().split(' ')))
sortedOrder = [str(i[0] + 1) for i in sorted(enumerate(li), key=lambda x: x[1], reverse=True)]
lik = sorted(li, reverse=True)
cnt = 0
ans = 0
for i in lik:
	ans += i * cnt + 1
	cnt += 1
print(ans)
print(' '.join(sortedOrder))


n = int(input())
a = list(map(int, input().split()))
b = sorted([(a[i], i) for i in range(n)], reverse=True)
ans = 0
t = 0
for (x, y) in b:
	ans += x * t + 1
	t += 1
print(ans)
print(*[b[i][1] + 1 for i in range(n)])


n = int(input())
a = [*map(int, input().split())]
(c, x) = (0, 0)
b = list(zip(range(1, n + 1), a))
b.sort(key=lambda x: x[1], reverse=True)
for i in b:
	c += i[1] * x + 1
	x += 1
print(c)
print(*list(zip(*b))[0], sep=' ')


(n, a) = (int(input()), list(map(int, input().split())))
r = []
answer = 0
for i in range(n):
	p = -1
	for j in range(n):
		if p == -1 or a[j] > a[p]:
			p = j
	r.append(p + 1)
	answer += i * a[p] + 1
	a[p] = 0
print(answer)
print(' '.join([str(i) for i in r]))


n = int(input())
s = list(map(int, input().split()))
x = 0
aa = 0
ans = ''
while x < n:
	m = max(s)
	aa = aa + (m * x + 1)
	t = s.index(m)
	ans = ans + str(t + 1) + ' '
	s[t] = -1
	x = x + 1
print(aa)
print(ans)


t = int(input())
v = list(map(int, input().split()))
a = []
index = 1
for j in v:
	a.append((j, index))
	index += 1
a = sorted(a, reverse=True)
total = 0
ans = []
for i in range(t):
	total += a[i][0] * i + 1
	ans.append(a[i][1])
print(total)
print(*ans)


def f():
	n = int(input())
	li = list(map(int, input().split()))
	arr = sorted(li, reverse=True)
	bullet = 0
	fk = 0
	for i in arr:
		bullet += i * fk + 1
		fk += 1
	print(bullet)
	output = []
	for a in arr:
		ind = li.index(a)
		li[ind] = 9999
		output.append(ind + 1)
	print(*output)
f()


def sol(l, s):
	cnt = 0
	order = []
	ss = []
	for i in range(l):
		ss.append([s[i], i + 1])
	ss.sort(reverse=True)
	for i in range(l):
		cnt = cnt + i * ss[i][0] + 1
		order.append(ss[i][1])
	return (cnt, order)
l = int(input())
s = list(map(int, input().split(' ')))
(a, b) = sol(l, s)
print(a)
st = ''
for i in b:
	st = st + str(i) + ' '
print(st)


n = int(input())
li = list(map(int, input().split()))
d = {}
b = []
for i in range(1, n + 1):
	k = li[i - 1]
	try:
		d[k].append(i)
	except KeyError:
		d[k] = [i]
		b.append(k)
b.sort(reverse=True)
ans1 = []
ans = 0
l = 0
for i in b:
	for j in d[i]:
		ans1.append(j)
		ans += l * i + 1
		l += 1
print(ans)
print(*ans1)


n = int(input())
(r, k, a) = (0, 0, [0] * n)
for (i, x) in sorted(enumerate(map(int, input().split())), key=lambda x: x[1])[::-1]:
	r += x * k + 1
	a[k] = i + 1
	k += 1
print(r)
print(*a)


n = int(input())
a = [int(_) for _ in input().split()]
l1 = a[:]
l1.sort(reverse=True)
l2 = []
ans = 0
for i in l1:
	shit = a.index(i)
	a[shit] = '_'
	ans += i * len(l2) + 1
	l2.append(shit)
print(ans)
for i in l2:
	print(i + 1, end=' ')


n = int(input())
arr = list(map(int, input().split()))
d = {}
count = 1
for i in arr:
	if i in d:
		d[i].append(count)
	else:
		d[i] = [count]
	count += 1
uni = list(set(arr))
uni.sort()
uni = uni[-1::-1]
ans = 0
f = []
cans = 0
for i in uni:
	cur = i
	f += d[i]
	for j in range(len(d[i])):
		ans += cur * cans + 1
		cans += 1
print(ans)
print(*f)


def constcal(ai, x):
	icost = ai * x + 1
	return icost

def shootcans(cans, n):
	cost = 0
	x = 0
	res = list()
	while x != n:
		canno = cans.index(max(cans))
		res.append(canno + 1)
		c = constcal(cans[canno], x)
		cost = cost + c
		x = x + 1
		cans[canno] = -1
	print(cost)
	for i in res:
		print(i, end=' ')
n = int(input())
cans = [int(x) for x in input().split()]
shootcans(cans, n)


n = int(input())
l = [int(y) for y in input().split()]
k = []
for i in range(n):
	k.append([l[i], i + 1])
k.sort(key=lambda x: x[0], reverse=True)
ans = 0
a = []
for i in range(n):
	a.append(k[i][1])
	ans = ans + (k[i][0] * i + 1)
print(ans)
for i in a:
	print(i, end=' ')
print()


n = int(input())
arr = list(map(int, input().split()))
temp = arr.copy()
arr.sort(reverse=True)
idx = []
for i in range(n):
	idx1 = temp.index(arr[i])
	temp[idx1] = -1
	idx.append(idx1)
(x, summ) = (0, 0)
for i in range(n):
	summ += arr[i] * x + 1
	x += 1
print(summ)
for i in range(n):
	print(idx[i] + 1, end=' ')
print('')


n = int(input())
a = list(map(int, input().split()))
(v, s, w) = ([], '', 0)
for (x, y) in list(enumerate(a)):
	v.append([y, x])
v.sort(reverse=True)
for i in range(len(v)):
	w += i * v[i][0] + 1
	s += str(v[i][1] + 1) + ' '
print(w)
print(s)


import collections, heapq, bisect, math

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

def solve(A):
	A = [(a, i) for (i, a) in enumerate(A)]
	A.sort(reverse=True)
	out = 0
	for i in range(len(A)):
		out += i * A[i][0] + 1
	print(out)
	print(' '.join((str(i + 1) for (_, i) in A)))
q = 1
tests = []
for test in range(1):
	n = input()
	tests.append([int(p) for p in input().split(' ')])
for test in tests:
	solve(test)


n = int(input())
a = list(map(int, input().split()))
dict = {}
for i in range(n):
	dict[i] = a[i]
list_of_tup = sorted(dict.items(), reverse=True, key=lambda x: x[1])
count = 0
order = []
sum = 0
for i in range(n):
	sum += list_of_tup[i][1] * len(order) + 1
	order.append(list_of_tup[i][0])
print(sum)
for i in range(len(order)):
	print(order[i] + 1, end=' ')


n = int(input())
l = list(map(int, input().split()))
x = 0
v = []
count = 0
for i in range(n):
	index = -1
	for j in range(n):
		if index == -1 or l[j] > l[index]:
			index = j
	v.append(index + 1)
	count += i * l[index] + 1
	l[index] = 0
print(count)
for i in v:
	print(i, end=' ')


n = int(input())
durability = list(map(int, input().split()))
sortedList = []
for i in range(n):
	sortedList.append((i + 1, durability[i]))
sortedList.sort(key=lambda x: x[1], reverse=True)
count = 0
total = 0
for (i, j) in sortedList:
	total += j * count + 1
	count += 1
print(total)
for (i, j) in sortedList:
	print(i, end=' ')


n = int(input())
alist = list(map(int, input().split()))
blist = alist.copy()
blist.sort(reverse=True)
count = 0
for i in range(len(blist)):
	count = count + 1 + i * blist[i]
print(count)
clist = []
for i in blist:
	a = alist.index(i) + 1
	clist.append(a)
	alist[a - 1] = '#'
for i in range(len(clist)):
	clist[i] = str(clist[i])
b = ' '.join(clist)
print(b)


n = int(input())
a = list(map(int, input().split()))
li = []
for (i, j) in enumerate(a, 1):
	li.append([j, i])
li.sort(reverse=True, key=lambda x: x[0])
ans = 0
x = 0
res = []
for i in range(n):
	t = li[i][0] * x + 1
	ans += t
	x += 1
	res.append(li[i][1])
print(ans)
print(*res)


import os
import heapq
import sys
import bisect
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inar():
	return [int(k) for k in input().split()]

def main():
	n = int(input())
	arr = inar()
	dic = defaultdict(list)
	for i in range(n):
		dic[arr[i]].append(i)
	cnt = 0
	ans = 0
	lis = []
	arr.sort(reverse=True)
	for i in range(n):
		ans += arr[i] * cnt + 1
		lis.append(dic[arr[i]][-1] + 1)
		dic[arr[i]].pop(-1)
		cnt += 1
	print(ans)
	print(*lis)
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')
main()


n = int(input())
a = [int(i) for i in input().split()]
b = sorted(a, reverse=True)
d = 0
sum = 0
for i in range(0, len(b)):
	sum = sum + (b[i] * d + 1)
	d = d + 1
l = []
while len(l) < len(a):
	for j in range(0, len(b)):
		for k in range(0, len(a)):
			if b[j] == a[k] and k + 1 not in l:
				l.append(k + 1)
print(sum)
print(*l)


n = int(input())
ar = list(map(int, input().split()))[:n]
d = ar.copy()
c = []
d.sort(reverse=True)
s = 0
for i in range(n):
	s = s + d[i] * i + 1
for i in range(n):
	c.append([ar[i], i + 1])
c.sort(reverse=True)
print(s)
for i in range(n):
	print(c[i][1], end=' ')


cancount = int(input())
durabilities = [[int(x), 0] for x in input().split(' ')]
for i in range(cancount):
	durabilities[i][1] = i + 1
durabilities.sort()
res = cancount
sequence = ''
for i in range(cancount - 1, -1, -1):
	res += durabilities[i][0] * (cancount - i - 1)
	sequence += str(durabilities[i][1]) + ' '
print(res)
print(sequence)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	clon = [i for i in a]
	a.sort(reverse=True)
	v = 0
	ans = []
	for x in range(n):
		v += a[x] * x + 1
		ans.append(clon.index(a[x]) + 1)
		clon[clon.index(a[x])] = None
	print(v)
	print(' '.join(map(str, ans)))
main()


n = int(input())
lis = list(map(int, input().split()))
s = 0
l = []
k = []
for i in lis:
	k.append(i)
x = 0
for i in range(n):
	m = max(lis)
	for j in range(n):
		if k[j] == m:
			if j + 1 not in l:
				l.append(j + 1)
				break
	s = s + m * x + 1
	x += 1
	lis.remove(m)
print(s)
z = ' '.join((str(v) for v in l))
print(z)


n = int(input())
a = list(map(int, input().split(' ')))
b = a.copy()
b = sorted(b)[::-1]
summ = 0
ans = []
for i in range(n):
	summ += b[i] * i + 1
	ans.append(a.index(b[i]) + 1)
	a[a.index(b[i])] = 0
print(summ)
for i in ans:
	print(i, end=' ')


n = int(input())
l = list(map(int, input().split()))
l = [(v, i) for (i, v) in enumerate(l)]
l.sort()
l.reverse()
(s, x) = (0, 0)
for (v, i) in l:
	s += v * x + 1
	x += 1
print(s)
for (v, i) in l:
	print(i + 1)


n = int(input())
x = [int(q) for q in input().split()]
y = sorted(x)
y = y[::-1]
ans = 0
l = []
for i in range(n):
	ans += i * y[i] + 1
	l.append(1 + x.index(y[i]))
	x[x.index(y[i])] = 0
print(ans)
print(*l)


n = int(input())
l = list(map(int, input().split(' ')))
in_list = []
for i in range(1, n + 1):
	in_list.append(i)
for i in range(n):
	for j in range(n - i - 1):
		if l[j] > l[j + 1]:
			temp = l[j]
			l[j] = l[j + 1]
			l[j + 1] = temp
			temp = in_list[j]
			in_list[j] = in_list[j + 1]
			in_list[j + 1] = temp
count = 0
res = 0
for i in range(n - 1, -1, -1):
	res += l[i] * count + 1
	count += 1
print(res)
for i in range(n - 1, -1, -1):
	print(in_list[i], end=' ')


n = int(input())
a = list(map(int, input().split()))
c = []
for i in range(len(a)):
	c.append([a[i], i])
c = sorted(c)
c.reverse()
l = 0
for i in range(len(c)):
	l += c[i][0] * i + 1
print(l)
for i in range(len(c)):
	print(c[i][1] + 1, end=' ')


n = int(input())
a = list(map(int, input().split()))
a1 = list()
k = 1
for i in a:
	a1.append([i, k])
	k = k + 1
a1.sort(reverse=1)
result = 0
k = 0
for i in a1:
	result = result + (i[0] * k + 1)
	k = k + 1
print(result)
for i in a1:
	print(i[1], end=' ')


from sys import stdin, stdout
import math
n = int(stdin.readline())
arr = [int(i) for i in stdin.readline().split()]
idx = {}
for i in range(n):
	idx.update({i + 1: arr[i]})
arr = sorted(arr, reverse=True)
idx = sorted(idx.items(), key=lambda x: (x[1], x[0]), reverse=True)
order = [y[0] for y in idx]
x = 0
shots = 0
for i in arr:
	shots += x * i + 1
	x += 1
print(shots)
for i in order:
	print(i, end=' ')


n = int(input())
a = list(map(int, input().split()))
c = a.copy()
a.sort()
a.reverse()
s = 0
b = []
for i in range(n):
	s = s + a[i] * i + 1
	b.append(c.index(a[i]) + 1)
	c[c.index(a[i])] = -1
print(s)
print(*b)


size = input()
cans = input()
cans = [int(s) for s in cans.split()]
x = 0
shots = 0
ordering = []
while max(cans) > 0:
	largest = max(cans)
	pos = cans.index(largest)
	shots += largest * x + 1
	cans[pos] = -1
	ordering.append(pos + 1)
	x += 1
print(shots)
print(' '.join(map(str, ordering)))


n = int(input())
a = input().split()
l = []
c = []
for i in a:
	l.append(int(i))
l.sort()
l.reverse()
k = 0
t = 0
for i in l:
	t += i * k + 1
	k += 1
for i in l:
	c.append(a.index(str(i)) + 1)
	a[a.index(str(i))] = '@'
print(t)
for i in c:
	print(i, end=' ')


n = int(input())
a = list(map(int, input().split()))
l = []
for i in range(n):
	l.append((a[i], i + 1))
l.sort(reverse=True)
order = []
cnt = 0
for i in range(n):
	cnt += l[i][0] * i + 1
	order.append(l[i][1])
print(cnt)
print(' '.join(map(str, order)))


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	a = []
	for i in range(len(arr)):
		a.append([arr[i], i])
	a.sort(reverse=True)
	cnt = 0
	ans = 0
	for i in range(n):
		ans += cnt * a[i][0] + 1
		cnt += 1
	print(ans)
	for i in range(n):
		print(a[i][1] + 1, end=' ')
	return
main()


input()
seq = [(v, i) for (i, v) in enumerate(map(int, input().split()))]
seq_sort = sorted(seq, reverse=True)
print(sum([i * v[0] + 1 for (i, v) in enumerate(seq_sort)]))
print(*[i[1] + 1 for i in seq_sort])


n = int(input())
a = list(map(int, input().split()))
d = {}
for i in set(a):
	d[i] = []
for i in range(n):
	d[a[i]].append(i + 1)
x = sorted(a, reverse=True)
(ans, ini) = (0, 0)
(arr, s) = ([], set())
for i in range(n):
	tmp = x[i] * ini + 1
	ans += tmp
	ini += 1
	if x[i] not in s:
		for j in d[x[i]]:
			arr.append(j)
		s.add(x[i])
print(ans)
print(*arr)


n = int(input())
a = list(map(int, input().split()))
for i in range(len(a)):
	a[i] = [a[i], i + 1]
a.sort(reverse=True)
x = 0
ans = 0
for i in a:
	ans += x * i[0] + 1
	x += 1
print(ans)
print(' '.join([str(i[1]) for i in a]))


n = int(input())
l = [int(i) for i in input().split()]
b = l[:]
b.sort(reverse=True)
s = 1
for i in range(1, n):
	s = s + 1 + b[i] * i
print(s)
for i in range(n):
	print(l.index(b[i]) + 1, end=' ')
	l[l.index(b[i])] = -1


from collections import defaultdict
n = int(input())
arr = list(map(int, input().split()))
y = defaultdict(list)
for (i, e) in enumerate(arr):
	y[e].append(i + 1)
u = sorted(arr, reverse=True)
tot = 0
for (i, e) in enumerate(u):
	tot += e * i + 1
print(tot)
for h in sorted(list(set(arr)), reverse=True):
	print(*y[h], end=' ')


def Shooting(n, a):
	sortedIndices = sorting(n, a)
	totalShots = 0
	i = n - 1
	j = 0
	resultSeq = ''
	while i >= 0:
		totalShots += a[i] * j + 1
		resultSeq += str(sortedIndices[i] + 1)
		resultSeq += ' '
		i -= 1
		j += 1
	return (totalShots, resultSeq[:len(resultSeq) - 1])

def sorting(n, a):
	sortdIndex = [i for i in range(n)]
	i = 0
	while i < n - 1:
		j = i + 1
		while j < n:
			if a[j] < a[i]:
				sortedIndex = swap(i, j, sortdIndex)
				a = swap(i, j, a)
			j += 1
		i += 1
	return sortdIndex

def swap(a, b, seq):
	temp = seq[a]
	seq[a] = seq[b]
	seq[b] = temp
	return seq
n = int(input())
a = [int(x) for x in input().split()]
(totalShots, seq) = Shooting(n, a)
print(totalShots)
print(seq)


n = int(input())
l = [int(i) for i in input().split()]
f = [(l[i], i + 1) for i in range(0, n)]
f.sort(reverse=True)
c = 0
o = ''
for i in range(n):
	c += f[i][0] * i + 1
	o += str(f[i][1]) + ' '
print(c)
print(o[0:-1])


n = int(input())
sp = list(map(int, input().split()))
count = 0
undexs = []
t = sp.copy()
sp.sort(reverse=True)
for i in range(len(sp)):
	count += sp[i] * i + 1
for i in range(len(t)):
	undexs.append(t.index(max(t)))
	t[undexs[i]] = 0
print(count)
for i in undexs:
	print(i + 1, end=' ')


n = int(input())
cans = list(map(int, input().split()))
ansCans = []
cansD = 0
ans = 0
sortcans = sorted(cans, reverse=True)
for i in sortcans:
	ans += i * cansD + 1
	cansD += 1
	ansCans.append(cans.index(i) + 1)
	cans[cans.index(i)] = 1001
print(ans)
print(' '.join(map(str, ansCans)))


from sys import stdin, stdout
get = stdin.readline
put = stdout.write
n = int(get())
a = list(map(int, get().split()))
b = sorted(a, reverse=True)
p = 0
d = {}
for i in range(n):
	if a[i] not in d:
		d[a[i]] = [i + 1]
	else:
		d[a[i]].append(i + 1)
	p = p + b[i] * i + 1
put(str(p) + '\n')
for i in sorted(list(set(b)), reverse=True):
	print(*d[i], end=' ')


n = int(input())
a = list(map(int, input().split(' ')))
flag = []
for i in a:
	flag.append(0)
temp = []
count = 0
result = 0
while count < n:
	max_ = -1
	counter = -1
	for i in range(n):
		if a[i] > max_ and flag[i] != 1:
			max_ = a[i]
			counter = i
	flag[counter] = 1
	result += count * max_ + 1
	count += 1
	temp.append(counter + 1)
print(result)
for i in temp:
	print(i, end=' ')


n = int(input())
l = [int(i) for i in input().split(' ')]
d = dict()
for i in range(len(l)):
	if l[i] in d.keys():
		d[l[i]].append(i + 1)
	else:
		d[l[i]] = [i + 1]
res = []
c = 0
val = 0
for i in sorted(d, reverse=True):
	for j in d[i]:
		res.append(j)
		val += i * c + 1
		c += 1
print(val)
for i in res:
	print(i, end=' ')


n = int(input())
cans = list(map(int, input().split()))
solution = [i for i in sorted(enumerate(cans), key=lambda x: x[1], reverse=True)]
total = 0
for i in range(n):
	total += i * solution[i][1] + 1
print(total)
for x in solution:
	print(x[0] + 1, end=' ')
print()


(b, n) = (int(input()), list(map(int, input().split())))
k = sorted(n, reverse=True)
resb = []
res = 0
for i in range(len(k)):
	res += i * k[i] + 1
	resb.append(str(n.index(k[i]) + 1))
	n[n.index(k[i])] = -1
print('{}\n{}'.format(res, ' '.join(resb)))


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
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))
mod = 1000000007

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 graph(vertex):
	return [[] for i in range(0, vertex + 1)]

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

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

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

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

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

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

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 bs(a, l, h, x):
	while l < h:
		mid = (l + h) // 2
		if a[mid] == x:
			return mid
		if a[mid] < x:
			l = mid + 1
		else:
			h = mid
	return l

def sieve(a):
	for i in range(3, 10 ** 6 + 1, 2):
		a[i] = 1
	for i in range(3, 10 ** 6 + 1, 2):
		for j in range(i * i, 10 ** 6 + 1, i):
			a[j] = 0
	a[2] = 1
	return a

def bfs(g, st):
	visited = [0] * len(g)
	visited[st] = 1
	queue = []
	queue.append(st)
	new = []
	while len(queue) != 0:
		s = queue.pop()
		new.append(s)
		for i in g[s]:
			if visited[i] == 0:
				visited[i] = 1
				queue.append(i)
	return new

def solve():
	n = int(inp())
	a = lis()
	h = []
	for i in range(0, n):
		heappush(h, [-a[i], i + 1])
	ans = 0
	cnt = 0
	order = []
	for i in range(0, n):
		elem = heappop(h)
		ans += -elem[0] * cnt + 1
		cnt += 1
		order.append(elem[1])
	print(ans)
	print(*order)
testcase(1)


n = int(input())
a = list(map(int, input().split()))
sum = 0
sorted_indices = sorted(range(1, len(a) + 1), key=lambda k: a[k - 1], reverse=True)
for (c, i) in enumerate(sorted_indices):
	sum += a[i - 1] * c + 1
print(sum)
print(*sorted_indices)


n = int(input())
cans = input()
cans = map(int, cans.split())
order = list(enumerate(cans))
order = sorted(order, key=lambda x: x[1], reverse=1)
times = 0
for i in range(n):
	times += order[i][1] * i + 1
print(times)
[print(x[0] + 1, end=' ') for x in order]


n = int(input())
a = [int(o) for o in input().split()]
b = [None] * n
for i in range(n):
	b[i] = [a[i], i + 1]
b.sort()
b = b[::-1]
c = 0
x = 0
for i in range(n):
	c += b[i][0] * i + 1
print(c)
for i in range(n):
	print(b[i][1], end=' ')


from collections import defaultdict
n = int(input())
arr = list(map(int, input().split()))
d = defaultdict(list)
for i in range(n):
	if arr[i] in d.keys():
		d[arr[i]].append(i + 1)
	else:
		d[arr[i]].append(i + 1)
arr.sort()
arr.reverse()
ans = 0
s = ''
for i in range(n):
	ans += i * arr[i] + 1
	s += str(d[arr[i]][0]) + ' '
	d[arr[i]].pop(0)
print(ans)
print(s)


import os
import sys
from io import BytesIO, IOBase

def solution(n, arr):
	arr_i = [(arr[i], i + 1) for i in range(n)]
	arr_i.sort(reverse=True)
	(res, factor) = (0, 0)
	for (x, i) in arr_i:
		res += x * factor + 1
		factor += 1
	write(res)
	write(*(i for (x, i) in arr_i))

def main():
	n = r_int()
	arr = r_array()
	solution(n, arr)
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')

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


def f(mas):
	n = len(mas)
	masInd = [i for i in range(n)]
	for i in range(n):
		maxInd = i
		for j in range(i, n):
			if mas[masInd[maxInd]] < mas[masInd[j]]:
				maxInd = j
		(masInd[maxInd], masInd[i]) = (masInd[i], masInd[maxInd])
	return masInd
input()
x = 0
Sum = 0
inp_data = list(map(int, input().split()))
mas = f(inp_data)
for i in mas:
	Sum += x * inp_data[i] + 1
	x += 1
print(Sum)
print(*[x + 1 for x in mas], sep=' ')


n = int(input())
a = list(map(int, input().split()))
l = []
ans = 0
for i in range(0, n):
	l.append([a[i], i + 1])
l.sort(reverse=True)
for j in range(0, n):
	ans = ans + l[j][0] * j + 1
print(ans)
for k in range(0, n):
	print(l[k][1], end=' ')
print()


n = int(input())
s = list(map(int, input().split()))
b = sorted(range(len(s)), key=lambda k: s[k])
ans = 0
s.sort(reverse=True)
for i in range(len(s)):
	ans += b[i] * s[b[i]] + 1
b = [i + 1 for i in b]
c = []
for i in range(n):
	c.append(b[n - 1 - i])
print(ans)
print(*c)


n = int(input())
a = enumerate(list(map(int, input().split())))
a = sorted(a, key=lambda x: x[1], reverse=True)
ans = 0
l = []
x = 0
for i in a:
	ans += i[1] * x + 1
	l.append(i[0] + 1)
	x += 1
print(ans)
print(*l)


import sys
input = sys.stdin.readline
t = 1
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	for i in range(n):
		a[i] = (a[i], i)
	a.sort(reverse=True)
	ans = [0] * n
	res = 0
	for i in range(n):
		res += a[i][0] * i + 1
		ans[i] = a[i][1] + 1
	print(res)
	print(*ans)


n = int(input())
s = list(map(lambda x: (int(x[1]), x[0]), enumerate(input().split())))
s.sort(reverse=True)
ans = 0
for i in range(n):
	ans += s[i][0] * i + 1
print(ans)
print(*map(lambda x: x[1] + 1, s))


n = int(input())
c = 0
s = list(map(int, input().split()))
s = sorted([(s[i], i) for i in range(n)], key=lambda x: -x[0])
p = []
for i in range(n):
	c += s[i][0] * i + 1
	p.append(str(s[i][1] + 1))
print(c)
print(' '.join(p))


n = int(input())
a = list(map(int, input().split()))
b = []
c = []
ans = 0
for i in range(n):
	c.append(a[i])
for i in range(n):
	maximum = a[0]
	max_index = 0
	for j in range(len(c)):
		if c[j] > maximum:
			maximum = c[j]
			max_index = j
	ans += i * c[max_index] + 1
	del c[max_index]
	b.append(a.index(maximum) + 1)
	a[a.index(maximum)] = -123456
print(ans)
for i in range(len(b)):
	print(b[i], end=' ')


n = int(input())
t = list(map(int, input().split()))
s = 0
p = []
for k in range(n):
	a = max(t)
	l = t.index(a)
	s += a * k + 1
	t[l] = 0
	p.append(l + 1)
print(s)
print(*p)


import math
import sys
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		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 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)
n = ii()
d = li()
t = []
for i in range(n):
	t.append([d[i], i + 1])
t.sort(reverse=True)
x = 0
res = 0
ra = []
for i in t:
	res += x * i[0] + 1
	x += 1
	ra.append(i[1])
print(res)
print(' '.join(map(str, ra)))


n = int(input())
arr = list(map(int, input().split(' ')))
for i in range(n):
	arr[i] = [arr[i], i + 1]

def firstItem(value):
	return value[0]
arr.sort(key=firstItem, reverse=True)
answer = []
cost = 0
index = 0
for can in arr:
	(currCost, canIndex) = can
	cost += currCost * index + 1
	index += 1
	answer.append(str(canIndex))
print(cost)
print(' '.join(answer))


n = int(input())
cst = list(map(int, input().split()))
cans = []
for i in range(n):
	cans.append([])
	cans[i].append(cst[i])
	cans[i].append(i + 1)
cans = sorted(cans, reverse=True)
ans = []
shoots = 0
for i in range(n):
	shoots += cans[i][0] * i + 1
	ans.append(str(cans[i][1]))
print(shoots)
print(' '.join(ans))


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


n = int(input())
line = input().split()
arr = []
for i in range(n):
	arr.append([int(line[i]), i + 1])
arr.sort(key=lambda x: x[0], reverse=True)
ans = 0
count = 0
for i in range(n):
	ans += count * arr[i][0] + 1
	count += 1
print(ans)
for i in range(n):
	print(arr[i][1], end=' ')


import sys
n = int(sys.stdin.readline())
a = [int(i) for i in sys.stdin.readline().split()]
arr = []
for i in range(n):
	arr.append([a[i], i + 1])
arr.sort(reverse=True)
shots = 0
for i in range(n):
	shots += arr[i][0] * i + 1
print(shots)
ans_arr = []
for g in range(n):
	ans_arr.append(str(arr[g][1]))
print(' '.join(ans_arr))


n = int(input())
x = [int(x) for x in input().split()]
y = x.copy()
x = sorted(x, reverse=True)
s = 0
for i in range(0, n):
	s += x[i] * i + 1
print(s)
y = sorted(range(len(y)), reverse=True, key=lambda k: y[k])
y = list((i + 1 for i in y))
for i in y:
	print(i, end=' ')


n = int(input())
c = list(map(int, input().split()))
c = [[c, ind] for (ind, c) in enumerate(c, start=1)]
c.sort(key=lambda x: -x[0])
result = 0
for i in range(n):
	result += c[i][0] * i + 1
print(result)
for i in range(n):
	print(f'{c[i][1]}', end=' ')


n = int(input())
m = list(map(int, input().split()))
l = []
p = []
for i in range(n):
	l.append([m[i], i + 1])
	l.sort(reverse=True)
a = 0
for j in range(n):
	p.append(l[j][1])
	a += l[j][0] * j + 1
s = [str(k) for k in p]
t = ' '.join(s)
print(a)
print(t)


n = int(input())
x = input()
xx = x.split()
for i in range(0, n):
	xx[i] = int(xx[i])
a = xx[:]
xx.sort()
xx.reverse()
g = 0
for i in range(0, n):
	g = g + xx[i] * i + 1
s = []
for i in xx:
	for j in range(0, n):
		if i == a[j] and j + 1 not in s:
			s.append(j + 1)
			break
print(g)
for i in s:
	print(i, end=' ')


n = int(input())
b = list(map(int, input().split()))
a = dict()
for i in range(len(b)):
	a[i] = b[i]
a = [k + 1 for k in sorted(a, key=a.get, reverse=True)]
shootlist = sorted(b, reverse=True)
shots = 0
x = 0
for banka in shootlist:
	shots += banka * x + 1
	x += 1
print(shots)
print(*a)


n = int(input())
s = list(map(int, input().split()))
arr = [[s[i], i + 1] for i in range(n)]
arr = sorted(arr, reverse=True)
start = 0
ans = 0
a = []
for (v, i) in arr:
	ans += v * start + 1
	start += 1
	a.append(i)
print(ans)
print(*a)


import sys
r = sys.stdin.readline
n = int(r())
l = list(map(int, r().split()))
d = {}
for c in range(len(l)):
	if l[c] in d:
		d[l[c]].append(c + 1)
	else:
		d[l[c]] = [c + 1]
k = [d[max(l)].pop()]
l.pop(l.index(max(l)))
(t, s) = (1, 1)
for i in range(len(l)):
	t += max(l) * s + 1
	s += 1
	k.append(d[max(l)].pop())
	l.pop(l.index(max(l)))
print(t)
for i in k:
	print(i, end=' ')


n = int(input())
l = list(map(int, input().split()))
curr_sum = 0
l1 = list()
count = 0
i = 0
while max(l) != 0:
	curr_sum = curr_sum + (max(l) * count + 1)
	count += 1
	i = l.index(max(l)) + 1
	l1.append(i)
	l[i - 1] = 0
print(curr_sum)
print(*l1)


n = int(input())
a = list(map(int, input().split()))
arr = []
for i in range(n):
	arr.append((a[i], i + 1))
arr.sort(reverse=True)
count = 0
for i in range(n):
	count += i * arr[i][0] + 1
print(count)
for i in range(n):
	print(arr[i][1], end=' ')


n = int(input())
l = list(map(int, input().split()))
k = [[l[i], i + 1] for i in range(n)]
k.sort()
k.reverse()
sumka = 0
for i in range(n):
	sumka += k[i][0] * i + 1
print(sumka)
for i in range(n):
	print(k[i][1], end=' ')


n = int(input())
l = list(map(int, input().split()))
x = 0
hits = 0
new_list = []
for i in range(n):
	largest_num_index = l.index(max(l))
	new_list.append([largest_num_index + 1, l[largest_num_index]])
	l[largest_num_index] = -9999999999999999999999999999999999
for i in range(n):
	hits += new_list[i][1] * i + 1
print(hits)
for i in range(n):
	print(new_list[i][0], end=' ')


n = int(input())
x = [int(x) for x in input().split()]
l = []
for i in range(n):
	l.append([x[i], i + 1])
l.sort(reverse=True)
shot = 0
j = 0
for i in l:
	shot += i[0] * j + 1
	j += 1
print(shot)
for i in l:
	print(i[1], end=' ')


n = int(input())
a = list(map(int, input().split()))
shots = 0
result = []
for i in range(n):
	pos = 0
	for j in range(1, n):
		if a[pos] < a[j]:
			pos = j
	result.append(pos + 1)
	shots += i * a[pos] + 1
	a[pos] = 0
print(shots)
print(*result)


n = int(input())
a = list(map(int, input().strip().split()))
b = []
for i in range(n):
	b.append([a[i], i + 1])
b.sort(reverse=True)
c = []
s = 0
for i in range(n):
	c.append(b[i][1])
	s = s + (b[i][0] * i + 1)
print(s)
print(*c)


n = int(input())
l = list(map(int, input().split()))
In = sorted(range(len(l)), key=l.__getitem__, reverse=True)
s = 0
for i in range(len(In)):
	s += i * l[In[i]] + 1
print(s)
for i in range(len(In)):
	In[i] += 1
print(*In)


n = int(input())
A = sorted([(int(x), i) for (i, x) in enumerate(input().split())])[::-1]
result = 0
x = 0
B = []
for (a, i) in A:
	result += a * x + 1
	x += 1
	B += [i + 1]
print(result)
print(' '.join(map(str, B)))


n = int(input())
x = list(map(int, input().strip().split()))
y = x.copy()
m = []
x.sort()
x.reverse()
k = 0
l = 0
for i in x:
	l = i * k + 1 + l
	k = k + 1
	j = y.index(i)
	m.append(j + 1)
	y[j] = 'a'
print(l)
for i in m:
	print(i, end=' ')


n = int(input())
a = list(map(int, input().split()))
indexes = sorted(range(len(a)), key=lambda i: a[i], reverse=True)
shots = 0
for i in range(len(a)):
	shots += a[indexes[i]] * i + 1
print(shots)
print(' '.join([str(i + 1) for i in indexes]))


N = int(input())
arr = list(map(int, input().split()))
d = dict()
for i in range(len(arr)):
	d[i + 1] = arr[i]
d = sorted(d.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)
suma = 0
rs = []
for i in range(len(d)):
	suma = suma + (d[i][1] * i + 1)
	rs.append(d[i][0])
print(suma)
for e in rs:
	print(e, end=' ')


n = int(input())
a = [int(_) for _ in input().split()]
m = [(a[i], i + 1) for i in range(n)]
m.sort(reverse=True)
t = 1
ans = [m[0][1]]
for i in range(n - 1):
	t += m[i + 1][0] * (i + 1) + 1
	ans.append(m[i + 1][1])
print(t)
print(*ans)


n = int(input())
cans = list(map(int, input().strip().split()))
original = cans[:]
cans.sort(reverse=True)
x = 0
ans = 0
seq = []
for d in cans:
	ans += d * x + 1
	x += 1
	l = original.index(d) + 1
	seq.append(str(l))
	original[l - 1] = 'X'
print(ans)
print(' '.join(seq))


n = int(input())
A = input().split()
A = sorted([(-int(a), i) for (i, a) in enumerate(A)])
tot = n + sum((-j * a for (j, (a, i)) in enumerate(A)))
print(tot)
print(' '.join((str(j + 1) for (_, j) in A)))


n = int(input())
a = list(map(int, input().split()))
l = a + []
l.sort(reverse=True)
s = 0
x = 0
for i in range(len(l)):
	s += l[i] * x + 1
	x += 1
print(s)
for i in range(len(l)):
	print(a.index(l[i]) + 1, end=' ')
	a[a.index(l[i])] = 0


n = int(input())
a = [(i, int(b)) for (i, b) in enumerate(input().split(), start=1)]
a.sort(reverse=True, key=lambda x: x[1])
countr = 0
bs = 0
s = ''
for (i, b) in a:
	s += str(i) + ' '
	countr += bs * b + 1
	bs += 1
print(countr)
print(s)


n = int(input())
b = []
x = 0
c = 0
a = list(map(int, input().split()))
for i in range(n):
	b.append(a.index(max(a)) + 1)
	c = c + (a[a.index(max(a))] * x + 1)
	x += 1
	a[a.index(max(a))] = 0
print(c)
print(' '.join(map(str, b)))


n = int(input())
a = [int(i) for i in input().split()]
sl = list(set(a))
sl.sort()
sl.reverse()
res = []
x = 0
ans = 0
for i in range(len(sl)):
	for j in range(n):
		if a[j] == sl[i]:
			ans += a[j] * x + 1
			x += 1
			res.append(j + 1)
print(ans)
for i in range(n):
	print(res[i], end=' ')


q = int(input())
l = list(map(int, input().split(' ')))
cnt = 0
d = []
sum1 = 0
c = []
for i in range(q):
	d.append((l[i], i))
d.sort()
d = d[::-1]
for i in range(len(d)):
	c.append(d[i][1] + 1)
	sum1 = sum1 + d[i][0] * cnt + 1
	cnt = cnt + 1
print(sum1)
for i in c:
	print(i, end=' ')
print()


def solve(n, arr):
	count = 1
	ans = 1
	ans_arr = sorted(range(len(arr)), key=arr.__getitem__, reverse=True)
	arr.sort(reverse=True)
	for i in range(1, n):
		ans += arr[i] * count + 1
		count += 1
	print(ans)
	for i in ans_arr:
		print(i + 1, end=' ')
n = int(input())
arr = list(map(int, input().split()))
solve(n, arr)


x = int(input())
s = list(map(int, input().split()))
z = sorted(s)
z = z[::-1]
a = b = 0
v = []
for n in range(x):
	k = s.index(z[n])
	s[k] = -n
	v.append(k + 1)
	a += z[n] * b + 1
	b += 1
print(a)
print(*v)


n = int(input())
c = list(map(int, input().split()))
d = c.copy()
k = 0
e = [0] * n
sum1 = 0
d.sort(reverse=True)
for i in range(n):
	sum1 += d[i] * i + 1
print(sum1)
while k < n:
	if k > 0 and d[k] == d[k - 1]:
		temp = i + 1
	else:
		temp = 0
	for i in range(temp, n):
		if c[i] == d[k]:
			e[k] = i + 1
			break
	k += 1
for i in range(n):
	print(e[i], end=' ')


n = int(input())
a = list(map(int, input().split(' ')))
idxs = list(range(1, n + 1))
idxs = [x for (_, x) in sorted(zip(a, idxs), reverse=True)]
a = sorted(a, reverse=True)
res = 0
for i in range(n):
	res += a[i] * i + 1
print(res)
print(*idxs)


n = int(input())
list1 = [int(i) for i in input().split()]
list2 = []
for i in range(0, len(list1)):
	list2.append([list1[i], i + 1])
l2 = sorted(list2, reverse=True)
count = 0
for i in range(0, len(l2)):
	count = count + l2[i][0] * i + 1
print(count)
for i in range(len(l2)):
	print(l2[i][1], end=' ')


N = int(input())
d = list(map(int, input().split()))
for i in range(N):
	d[i] = (d[i], i + 1)
d.sort(key=lambda x: x[0], reverse=True)
c = 0
for i in range(N):
	c = c + d[i][0] * i + 1
print(c)
for i in range(N):
	print(d[i][1], end=' ')


import sys
import os
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
import random
import re
import heapq
n = int(input())
s = list(map(int, input().split()))
s = sorted([(s[i], i + 1) for i in range(len(s))], reverse=True)
multi = 0
res = 0
for c in s:
	res += multi * c[0] + 1
	multi += 1
print(res)
res = [str(s[i][1]) for i in range(len(s))]
print(' '.join(res))


n = int(input())
l = list(map(int, input().split()))
for i in range(0, n):
	l[i] = (l[i], i + 1)
l.sort(reverse=True)
b = 0
s = 0
for i in range(0, n):
	s += l[i][0] * b + 1
	b += 1
print(s)
for i in range(0, n):
	print(l[i][1], end=' ')


(n, arr) = (int(input()), list(map(int, input().split())))
newarr = [(arr[i], i + 1) for i in range(len(arr))]
newarr = sorted(newarr, key=lambda x: x[0], reverse=True)
cost = 0
x = 0
for i in range(len(newarr)):
	cost += newarr[i][0] * x + 1
	x += 1
print(cost)
print(*[x[1] for x in newarr])


sumo = 0
num = int(input())
x = input()
x = x.split()
x = [int(i) for i in x]
y = [_ + 1 for _ in range(num)]
zz = []
for i in range(num):
	zz.append((x[i], y[i]))
zz.sort(reverse=True)
outo = []
for i in range(num):
	outo.append(str(zz[i][1]))
	sumo += i * zz[i][0] + 1
print(sumo)
print(' '.join(outo))


a = int(input())
l = list(map(int, input().split()))
g = l[:]
k = []
foo = 0
g.sort()
g.reverse()
for i in range(a):
	k.append(l.index(g[i]) + 1)
	l[l.index(g[i])] = -1
	foo += g[i] * i + 1
print(foo)
print(*k)


n = int(input())
lis = list(map(int, input().split()))
res = []
x = 0
c = 0
for i in range(n):
	a = max(lis)
	c += x * a + 1
	x += 1
	a = lis.index(a)
	res.append(a + 1)
	lis[a] = -1
print(c)
for i in res:
	print(i, end=' ')
print()


n = int(input())
l1 = [int(a) for a in input().split()]
l2 = []
for i in range(n):
	l2.append(i)
arr = l1
for i in range(1, len(arr)):
	key = arr[i]
	key1 = l2[i]
	j = i - 1
	while j >= 0 and key < arr[j]:
		arr[j + 1] = arr[j]
		l2[j + 1] = l2[j]
		j -= 1
	arr[j + 1] = key
	l2[j + 1] = key1
x = 0
c = 0
for i in range(n - 1, -1, -1):
	c += arr[i] * x + 1
	x += 1
print(c)
for i in range(n - 1, -1, -1):
	print(l2[i] + 1, end=' ')


import sys
import math
import functools

def compare(s, t):
	if s[0] > t[0]:
		return 1
	elif s[0] == t[0]:
		if s[1] < t[1]:
			return 1
	return 0
while True:
	try:
		n = int(input())
	except EOFError:
		break
	line = list(map(int, input().split()))
	paired = [(line[x], x) for x in range(n)]
	paired.sort()
	paired.reverse()
	cnt = 0
	total = 0
	res = []
	for x in paired:
		total += x[0] * cnt + 1
		cnt += 1
		res.append(x[1])
	print(total)
	for x in res:
		print(x + 1, end=' ')
	print('')
pass


n = int(input())
l = list(map(int, input().split()))
s = [(x, i) for (i, x) in enumerate(l)]
s = reversed(sorted(s))
ans = 0
count = 0
l = []
for (i, x) in s:
	ans += count * i + 1
	l.append(x + 1)
	count += 1
print(ans)
for i in l:
	print(i, end=' ')


from collections import defaultdict
n = int(input())
arr = list(map(int, input().split()))
idx = defaultdict(list)
for i in range(n):
	idx[arr[i]].append(i + 1)
arr.sort(reverse=True)
ans = 0
amount = 0
for i in range(n):
	ans += arr[i] * amount + 1
	amount += 1
print(ans)
for i in range(n):
	print(idx[arr[i]].pop(), end=' ')


from collections import Counter
import string
import math
import sys
from fractions import Fraction

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

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

def makedict(var):
	return dict(Counter(var))
testcases = 1
for _ in range(testcases):
	n = vary(1)
	num = array_int()
	val = []
	for i in range(n):
		val.append([num[i], i + 1])
	val.sort(reverse=True)
	x = 0
	ans = 0
	for i in range(n):
		ans += val[i][0] * x + 1
		x += 1
	print(ans)
	for i in range(n):
		print(val[i][1], end=' ')
	print()


T = int(input())
array = list(map(int, input().split(' ')))
array1 = sorted(array, reverse=True)
sum1 = 0
a = []
for i in range(T):
	sum1 = sum1 + array1[i] * i + 1
	b = array.index(array1[i])
	a.append(b + 1)
	array.remove(array1[i])
	array.insert(b, 0)
print(sum1)
print(*a)


n = int(input())
ais = list(map(int, input().split()))
kys = ais
ais = list(reversed(sorted(ais)))
x = 0
s = 0
indices = []
for i in ais:
	indices.append(kys.index(i) + 1)
	kys[kys.index(i)] = -1
for i in ais:
	s = s + i * x + 1
	x += 1
print(s)
for i in indices:
	print(i, end=' ')


from bisect import bisect_left
n = int(input())
b = [int(x) for x in input().split()]
a = [0] * n
for i in range(n):
	a[i] = b[i]
b.sort()
bullets = 0
seq = 0
S = ''
used = [False] * n
for j in range(n - 1, -1, -1):
	x = b[j]
	i = 0
	while not a[i] == x or used[i]:
		i += 1
	used[i] = True
	S = S + str(i + 1) + ' '
	bullets += a[i] * seq + 1
	seq += 1
print(bullets)
print(S)


from sys import stdin, stdout
for _ in range(1):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	l = []
	for i in range(n):
		l += [[a[i], i + 1]]
	l.sort(key=lambda x: -x[0])
	ans = 1
	for i in range(1, n):
		ans += i * l[i][0] + 1
	print(ans)
	for (v, ind) in l:
		stdout.write(str(ind) + ' ')


import array
n = int(input())
st = input().split(' ')
a = [i for i in range(n)]
for i in range(n):
	a[i] = int(st[i])
b = [i + 1 for i in range(n)]
swapped = True
while swapped:
	swapped = False
	for i in range(0, n - 1):
		if a[i] < a[i + 1]:
			swapped = True
			swap = a[i]
			swap2 = b[i]
			a[i] = a[i + 1]
			b[i] = b[i + 1]
			a[i + 1] = swap
			b[i + 1] = swap2
s = 0
x = 0
for i in range(n):
	s = s + (a[i] * x + 1)
	x = x + 1
print(s)
for i in range(n):
	print(b[i], end=' ')


from collections import defaultdict, deque
n = int(input())
a = list(map(int, input().split()))
pos = defaultdict(deque)
for (i, x) in enumerate(a):
	pos[x].append(i)
b = sorted(a, reverse=True)
ans = []
shoots = 0
for (i, x) in enumerate(b):
	j = pos[x].popleft()
	ans.append(j + 1)
	shoots += i * x + 1
print(shoots)
print(' '.join(map(str, ans)))


import copy
n = int(input())
a = [int(x) for x in input().split()]
b = copy.deepcopy(a)
d = []
f = [[] for i in range(1002)]
for i in range(n):
	f[a[i]].append(i)
a.sort(reverse=True)
for i in a:
	d.append(f[i][0] + 1)
	f[i].remove(f[i][0])
count = n
for i in range(1, n):
	count += i * a[i]
print(count)
for i in d:
	print(i, end=' ')
print()


n = int(input())
values = input().split(' ')
proc = []
for i in range(len(values)):
	proc.append((int(values[i]), i))
proc.sort()
result = [1, 1, [str(proc[len(proc) - 1][1] + 1)]]
for i in range(len(proc) - 2, -1, -1):
	result[0] += proc[i][0] * result[1] + 1
	result[1] += 1
	result[2].append(str(proc[i][1] + 1))
print('{}\n{}'.format(result[0], ' '.join(result[2])))


n = int(input())
a = list(map(int, input().split()))
l = [(i, a[i - 1]) for i in range(1, n + 1)]
l.sort(key=lambda x: -x[1])
s = 0
for (ind, (i, k)) in enumerate(l):
	s += k * ind + 1
print(s)
for (i, k) in l:
	print(i, end=' ')


q = int(input())
s = list(map(int, input().split(' ')))
index_sort = sorted(range(len(s)), key=lambda k: s[k])
for i in range(len(index_sort)):
	index_sort[i] = index_sort[i] + 1
s.sort(reverse=True)
sum = 0
for i in range(len(s)):
	sum = sum + s[i] * i + 1
print(sum)
for i in range(len(s)):
	print(index_sort[len(s) - i - 1], end=' ')


n = int(input())
a = list(map(int, input().split()))
a = [[a[i], i] for i in range(n)]
a = sorted(a, reverse=True)
ans = 0
for i in range(n):
	ans += a[i][0] * i + 1
print(ans)
for i in range(n):
	print(a[i][1] + 1, end=' ')


n = int(input())
l = list(map(int, input().split()))
b = []
for i in range(n):
	b.append([l[i], i])
b.sort(reverse=True)
order = []
ans = 0
for i in range(n):
	order.append(b[i][1] + 1)
	ans += b[i][0] * i + 1
print(ans)
print(*order)


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 = Int()
a = array()
b = sorted(set(a), reverse=True)
d = defaultdict(list)
for i in range(n):
	d[a[i]].append(i + 1)
tot = 0
x = 0
ans = []
for i in b:
	for j in d[i]:
		tot += a[j - 1] * x + 1
		ans.append(j)
		x += 1
print(tot)
print(*ans)


L = int(input())
c = list(map(int, input().split(' ')))
Nc = []
for (i, v) in enumerate(c):
	Nc.append([v, i])

def d(v):
	return v[0]
Nc.sort(key=d, reverse=True)
counter = 0
x = 0
ans = ''
for i in Nc:
	n = i[0]
	counter += n * x + 1
	ans += str(i[1] + 1) + ' '
	x += 1
print(counter)
print(ans[:-1])


n = int(input())
a = list(map(int, input().split()))
b = dict()
for i in range(len(a)):
	if a[i] in b:
		b[a[i]].append(i + 1)
	else:
		b[a[i]] = [i + 1]
a = sorted(a, reverse=True)
ans = 0
c = []
for i in range(len(a)):
	ans += i * a[i] + 1
	c.append(b[a[i]].pop())
print(ans)
print(*c)


n = int(input())
l = list(map(int, input().split()))
d = {}
for i in range(len(l)):
	if l[i] not in d:
		d[l[i]] = [i]
	else:
		d[l[i]].append(i)
d1 = sorted(d.keys(), reverse=True)
x = 0
result = []
sum1 = 0
for i in range(len(d1)):
	a = d[d1[i]]
	for j in range(len(a)):
		sum1 += d1[i] * x + 1
		x += 1
		result.append(a[j] + 1)
print(sum1)
for i in range(len(result)):
	print(result[i], end=' ')


nb = int(input())
ar = [int(x) for x in input().split()]
al = sorted([(v, i) for (i, v) in enumerate(ar)], reverse=True)
an = []
mu = 0
su = 0
for (x, y) in al:
	an.append(y + 1)
	su += x * mu + 1
	mu += 1
print(su)
print(*an)


n = int(input())
lst = list(map(int, input().split()))
num = []
for i in range(1, n + 1):
	num.append(i)
Fin = []
for i in range(n):
	t = []
	t.append(lst[i])
	t.append(num[i])
	Fin.append(t)
Fin = sorted(Fin)[::-1]
c = 0
for i in range(n):
	c += i * Fin[i][0] + 1
print(c)
for i in range(n):
	print(Fin[i][1], end=' ')


n = int(input())
nums = sorted(enumerate(map(int, input().split(' '))), key=lambda x: -x[1])
out = n
junban = [-1 for _ in range(n)]
for (i, (moto_i, num)) in enumerate(nums):
	out += i * num
	junban[i] = moto_i + 1
print(out)
out_txt = ' '.join([str(elm) for elm in junban])
print(out_txt)


n = int(input())
arr = list(map(int, input().split()))
op = []
for i in range(n):
	op.append((arr[i], i + 1))
op.sort(reverse=True)
cost = 0
knocks = 0
for (x, y) in op:
	cost += x * knocks + 1
	knocks += 1
print(cost)
for (x, y) in op:
	print(y, end=' ')


n = int(input())
l = list(map(int, input().split()))
visited = [False] * n
r = 0

def max1(l, visited):
	max1 = float('-inf')
	for i in range(len(l)):
		if visited[i] == False:
			if l[i] >= max1:
				max1 = l[i]
				max1i = i
	return max1i
r = 0
shots = 0
k = []
while r < n:
	t = max1(l, visited)
	visited[t] = True
	k.append(t + 1)
	shots = shots + r * l[t] + 1
	r = r + 1
print(shots)
print(*k)


n = int(input())
l = list(map(int, input().split()))
for i in range(n):
	l[i] = [l[i], i]
res = 0
l.sort()
l = l[::-1]
for i2 in range(n):
	res += i2 * l[i2][0] + 1
print(res)
for i3 in range(n):
	print(l[i3][1] + 1, end=' ')


n = int(input())
dur = list(map(int, input().split()))
dur_dict = dict()
total = 0
for i in range(n):
	dur[i] = (dur[i], i + 1)
dur.sort(reverse=True)
for i in range(n):
	total += dur[i][0] * i + 1
	dur[i] = dur[i][1]
print(total)
print(' '.join(map(str, dur)))


a = int(input())
b = []
cnt = 1
a = map(int, input().split())
for i in a:
	b.append((i, cnt))
	cnt += 1
b.sort()
b = b[::-1]
ans = 0
cnt = 0
for i in b:
	ans += i[0] * cnt + 1
	cnt += 1
print(ans)
for i in b:
	print(i[1], end=' ')


a = int(input())
b = input().split(' ')
l = []
for x in range(a):
	l.append([int(b[x]), x])
l.sort()
l.reverse()
total = 0
count = 0
for x in l:
	total += x[0] * count + 1
	count += 1
print(total)
out = ''
for x in l:
	out += str(x[1] + 1) + ' '
print(out[:-1])


n = int(input())
a = []
for (i, j) in enumerate([*map(int, input().split())]):
	a.append([j, i + 1])
a.sort(key=lambda x: -x[0])
ans = [i[1] for i in a]
res = 0
for i in range(n):
	res += a[i][0] * i + 1
print(res)
print(*ans)


n = int(input())
a = list(map(int, input().split()))
B = list()
for i in range(n):
	B.append([a[i], i + 1])
B.sort(reverse=True)
Omg = list()
ans = 0
for i in range(n):
	ans += i * B[i][0] + 1
	Omg.append(B[i][1])
print(ans)
print(*Omg)


n = int(input())
l = list(map(int, input().split()))
l = sorted([(v, i) for (i, v) in enumerate(l)], reverse=True)
j = 0
s = 0
a = []
for (v, i) in l:
	a.append(i + 1)
	s += v * j + 1
	j += 1
print(s)
print(' '.join(map(str, a)))


n = int(input())
l1 = [[int(x), 0] for x in input().split()]
for x in range(n):
	l1[x][1] += x
l1.sort(reverse=True)
ans = 0
l2 = []
for x in range(n):
	ans += l1[x][0] * x + 1
	l2.append(l1[x][1] + 1)
print(ans)
print(*l2)


MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import *
(n,) = I()
l = I()
for i in range(n):
	l[i] = [l[i], i]
l.sort(reverse=True)
ans = 0
k = []
for i in range(n):
	ans += i * l[i][0] + 1
print(ans)
print(*[i + 1 for (j, i) in l])


def main():
	n = int(input())
	cans = enumerate(map(int, input().split()))
	cans = sorted(cans, key=lambda x: x[1], reverse=True)
	calc_shots = lambda x, a: x * a + 1
	total_shots_required = 0
	for x in range(n):
		a = cans[x][1]
		total_shots_required += calc_shots(x, a)
	print(total_shots_required)
	for (i, c) in cans:
		print(i + 1, end=' ')
main()


import sys

def val(x):
	return x[1]

def ind(x):
	return x[0]
A = [(ind(v), i * val(v) + 1) for (i, v) in enumerate(sorted(list(zip(range(1, int(input()) + 1), map(int, input().split()))), key=val, reverse=True))]
print(sum(map(val, A)))
sys.stdout.write(' '.join(map(str, map(ind, A))))


n = int(input())
A = list(map(int, input().split()))
B = sorted(A)
B.reverse()
K = []
s = 0
for i in range(n):
	s += B[i] * i + 1
print(s)
for i in B:
	for j in range(n):
		if A[j] == i:
			K.append(j + 1)
			A[j] = 1000000000000000
			break
print(*K)


a = int(input())
l = list(map(int, input().split()))
(p, j, c) = ([], 0, [])
for i in l:
	p.append((i, j + 1))
	j += 1
s = 0
p = sorted(p)[::-1]
for i in range(a):
	s += p[i][0] * i + 1
	c.append(p[i][1])
print(s)
print(*c)


t = int(input())
arr = list(map(int, input().split()))
cnt = 0
result = []
sum = 0
for i in range(t):
	max = 0
	m_index = 0
	for j in range(t):
		if arr[j] > max:
			max = arr[j]
			m_index = j
	sum = max * cnt + 1 + sum
	result.append(m_index + 1)
	arr[m_index] = -1
	cnt += 1
print(sum)
print(*result)


def fun(x):
	return x[0]
n = int(input())
a = list(map(int, input().strip().split()))
for i in range(n):
	a[i] = [a[i], i + 1]
a.sort(key=fun, reverse=True)
op = 0
op2 = ''
for i in range(n):
	op2 += str(a[i][1]) + ' '
	op += a[i][0] * i + 1
print(op)
print(op2)


x = int(input())
y = [int(i) for i in input().split()]
z = y[:]
z.sort(reverse=True)
a = 0
for i in range(x):
	a += z[i] * i + 1
print(a)
a = set(y)
b = [i for i in a]
b.sort()
for i in b[::-1]:
	for j in range(len(y)):
		if y[j] == i:
			print(j + 1, end=' ')


def ans(l, n):
	sum = 0
	for i in range(n):
		sum = sum + l[i] * i + 1
	return sum
n = int(input())
l = list(map(int, input().split()))
print(ans(sorted(l, reverse=True), n))
for m in range(n):
	print(l.index(max(l)) + 1)
	temp = l.index(max(l))
	l.pop(l.index(max(l)))
	l.insert(temp, -99999)


input()
a = enumerate([int(x) for x in input().split()])
a = sorted(a, reverse=True, key=lambda x: x[1])
s = 0
for (i, (k, v)) in enumerate(a):
	s += v * i + 1
print(s)
print(' '.join([str(x[0] + 1) for x in a]))


n = int(input())
da = [int(i) for i in input().split()]
data = [(da[i], i + 1) for i in range(n)]
data.sort(reverse=True)
ans2 = [i[1] for i in data]
ans = 0
for i in range(n):
	ans += data[i][0] * i + 1
print(ans)
print(*ans2)


n = int(input())
l = [int(x) for x in input().split(' ')]
shots = 0
dropped = 0
total = 0
order = []
for i in range(n):
	m = max(l)
	index = l.index(m)
	shots = dropped * m + 1
	total += shots
	order.append(index + 1)
	l[index] = 0
	dropped += 1
print(total)
for i in order:
	print(i, end=' ')


arr = list()
count_bank = 0
count_bullet = 0
n = input()
x = list(map(int, input().split()))
for i in range(len(x)):
	pr = list()
	pr.append(x[i])
	pr.append(i + 1)
	arr.append(pr)
rigi = list()
arr.sort(reverse=1)
for i in arr:
	rigi.append(i[1])
	count_bullet += count_bank * i[0] + 1
	count_bank += 1
print(count_bullet)
for i in rigi:
	print(i)


n = int(input())
durability = list(map(int, input().split()))
sorted_durability = sorted(durability, reverse=True)
ans = []
ans_e = []
for e in sorted_durability:
	cnt = ans_e.count(e)
	ind = [i for i in range(n) if durability[i] == e]
	ans.append(ind[cnt] + 1)
	ans_e.append(e)
x = 0
cnt = 0
for i in range(n):
	cnt += sorted_durability[i] * x + 1
	x += 1
print(cnt)
print(*ans)


n = int(input())
c = list(map(int, input().split()))
idxSet = dict()
countSet = dict()
totWays = 0
for i in range(0, n):
	if c[i] not in idxSet:
		idxSet[c[i]] = str(i + 1)
	else:
		idxSet[c[i]] = idxSet[c[i]] + ' ' + str(i + 1)
sortedC = []
for key in idxSet:
	sortedC.append(key)
sortedC.sort(reverse=True)
ans = ''
for i in sortedC:
	ans += idxSet[i] + ' '
countList = ans.split(' ')
for i in range(0, len(countList) - 1):
	totWays += c[int(countList[i]) - 1] * i + 1
print(totWays)
print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
ans = []
b = a.copy()
ans1 = 0
x = 0
for i in range(n):
	ans1 += x * max(a) + 1
	x += 1
	ans.append(b.index(max(a)) + 1)
	b[b.index(max(a))] = -1
	del a[a.index(max(a))]
print(ans1)
print(*ans)


import sys
n = int(sys.stdin.readline())
cans = list(map(int, sys.stdin.readline().split()))
for i in range(n):
	cans[i] = [cans[i], i + 1]
cans = sorted(cans, key=lambda ele: -ele[0])
res1 = 0
res2 = []
for j in range(n):
	res1 += j * cans[j][0] + 1
	res2.append(cans[j][1])
print(res1)
for k in res2:
	print(k, end=' ')


nc = int(input())
cl = [int(x) for x in input().split()]
fl = []
cost = 0
j = 0
for i in sorted(cl, reverse=True):
	cost += j * i + 1
	fl.append(cl.index(i) + 1)
	cl[cl.index(i)] = float('inf')
	j += 1
print(cost)
print(*fl)


n = int(input())
dur = sorted(list(zip(map(int, input().split()), range(1, n + 1))))[::-1]
shoot = 0
order = []
for i in range(n):
	order.append(dur[i][1])
	shoot += dur[i][0] * i + 1
print(shoot)
print(*order)


from math import *
from sys import *
from heapq import *
from collections import defaultdict
import os, sys
from io import IOBase, BytesIO
M = 10 ** 9 + 7

def pow(a, b):
	res = 1
	while b > 0:
		if b & 1:
			res *= a
		a *= a
		b >>= 1
	return res

def powmod(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a *= a
		b >>= 1
	return res

def inv(a, m):
	return powmod(a, m - 2, m)

def alldivisors(n):
	list = []
	arr = []
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				arr += [i]
			else:
				arr += [i]
				list.append(n // i)
	arr += list[::-1]
	return arr

def primefactorisation(n):
	potentional_p = 3
	itog_list = defaultdict(int)
	if n % 2 == 0:
		itog_list[2] = 0
	while n % 2 == 0:
		n = n // 2
		itog_list[2] += 1
	while n - 1:
		if potentional_p > n ** 0.5:
			itog_list[n] += 1
			return itog_list
		while n % potentional_p == 0:
			n = n // potentional_p
			itog_list[potentional_p] += 1
		potentional_p += 2
	return itog_list

def main():
	n = int(input())
	a = list(map(int, input().split()))
	lst = []
	for i in range(n):
		lst.append([a[i], i])
	lst.sort(reverse=True)
	val = n
	c = 0
	for x in lst:
		val += x[0] * c
		c += 1
	print(val)
	for x in lst:
		print(x[1] + 1, end=' ')
	print()
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.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')
main()


n = int(input())
l = list(map(int, input().split()))
l2 = l.copy()
l.sort(reverse=True)
l1 = [True for i in range(n + 1)]
ans = 1
for i in range(1, n):
	ans += l[i] * i + 1
print(ans)
for i in range(n):
	a = l[i]
	b = l2.index(l[i])
	while l1[b] == False:
		l2[b] = float('inf')
		b = l2.index(l[i])
	l1[b] = False
	print(b + 1, end=' ')
print()


n = int(input())
li = list(map(int, input().split()))
li = [(li[i], i + 1) for i in range(n)]
li = sorted(li, key=lambda x: x[0], reverse=True)
sol = 0
for i in range(n):
	sol += li[i][0] * i + 1
print(sol)
for i in li:
	print(i[1], end=' ')
print()


n = int(input())
arr = list(map(int, input().split()))
ans = []
for i in range(1, n + 1):
	ans.append((arr[i - 1], i))
ans.sort(reverse=True)
res = 0
cnt = 0
act = []
for i in ans:
	res += i[0] * cnt + 1
	cnt += 1
	act.append(i[1])
print(res)
print(*act)


R = lambda : map(int, input().split())
n = int(input())
L = list(R())
s = sorted(L, reverse=True)
d = {}
for i in range(n):
	if L[i] not in d:
		d[L[i]] = []
	d[L[i]].append(i + 1)
x = 0
res = 0
for i in s:
	res += i * x + 1
	x += 1
print(res)
s = sorted(set(s), reverse=True)
for i in range(len(s)):
	print(*d[s[i]], end=' ')


n = int(input())
arr = counter = 0
a = sorted(zip([int(x) for x in input().split()], range(1, n + 1)), reverse=True)
for item in a:
	arr += counter * item[0] + 1
	counter += 1
print(arr)
for item in a:
	print(item[1], end=' ')


n = int(input())
l = list(map(int, input().split()))
l1 = []
for i in range(n):
	l1.append([l[i], i + 1])
l1.sort()
l1.reverse()
l2 = []
for i in range(n):
	l2.append(l1[i][1])
c = 0
for i in range(n):
	c += i * l1[i][0] + 1
print(c)
for i in l2:
	print(i, end=' ')


n = int(input())
stro = list(map(int, input().split()))
stroka = stro.copy()
stroka.sort()
stroka.reverse()
res = 0
result = []
x_banok = 0
for x in stroka:
	res += x * x_banok + 1
	x_banok += 1
print(res)
i = 0
for x in stroka:
	result.append(stro.index(x) + 1)
	stro[stro.index(x)] = -1
print(*result)


n = int(input())
lst = list(map(int, input().split()))
d = {}
for (i, x) in enumerate(lst):
	if d.get(x) == None:
		d[x] = []
	d[x].append(i + 1)
lst.sort()
key = list(d.keys())
key.sort()
key.reverse()
(res, x, result) = ([], 0, 0)
for (i, a) in enumerate(key):
	for (j, y) in enumerate(d[a]):
		res.append(y)
		result += a * x + 1
		x += 1
print(result)
print(*res)


n = int(input())
arr = sorted([(int(x), i) for (i, x) in enumerate(input().split())])[::-1]
total = 0
x = 0
for (a, i) in arr:
	total += a * x + 1
	x += 1
print(total)
for (a, i) in arr:
	print(i + 1, end=' ')


n = int(input())
l = list(map(int, input().split()))
ans = []
yo = 0
count = 0
for i in range(n):
	ans.append([l[i], i + 1])
final = []
ans.sort(reverse=True)
for (a, b) in ans:
	count += yo * a + 1
	final.append(b)
	yo += 1
print(count)
print(*final)


n = int(input())
a = list(map(int, input().split()))
a_sorted = list(zip(a, range(n)))
a_sorted.sort(reverse=True)
sm = 0
x = 0
output = list()
for item in a_sorted:
	sm += item[0] * x + 1
	x += 1
	output.append(item[1] + 1)
print(sm)
print(*output)


input()
a = sorted(((b, a) for (a, b) in enumerate(map(int, input().split()))))[::-1]
print(sum((ai * x + 1 for (x, (ai, n)) in enumerate(a))))
print(' '.join((str(n + 1) for (v, n) in a)))


def process(A, n):
	C = A.copy()
	for i in range(len(A)):
		A[i] = [A[i], i]
	A.sort(key=lambda x: x[0], reverse=True)
	B = [None] * len(A)
	for i in range(len(A)):
		B[i] = A[i][1] + 1
	res = 1
	for i in range(1, len(B)):
		res += i * C[B[i] - 1] + 1
	return (res, B)
n = int(input())
A = [int(x) for x in input().split()]
(res, B) = process(A, n)
print(res)
for i in B:
	print(i, end=' ')


mod = 10 ** 9 + 7
from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
import collections
import math
import heapq
from random import randint as rn

def modinv(n, p):
	return pow(n, p - 2, p)

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def main():
	n = inin()
	a = ain()
	b = []
	for i in range(n):
		b.append([a[i], i])
	b.sort(reverse=True)
	x = y = 0
	c = []
	for i in b:
		y += i[0] * x + 1
		x += 1
		c.append(i[1] + 1)
	print(y)
	print(*c)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
main()


n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
c = [0] * n
b.reverse()
x = 0
sum = 0
count = 0
for i in b:
	sum = sum + i * x + 1
	x = x + 1
print(sum)
for i in b:
	if count == 0:
		count = a.count(i)
		for j in range(0, n):
			if a[j] == i:
				c = 1 + j
				print(c, end=' ')
	count = count - 1


n = int(input())
a = list(map(int, input().split(' ')))
cans = 0
shots = 0
choice = []
for i in range(0, len(a)):
	indx = a.index(max(a))
	choice.append(indx + 1)
	shots += a[indx] * cans + 1
	a[indx] = -1
	cans += 1
print(shots)
for i in choice:
	print(i, end=' ')


try:
	from string_source import string_source
	source = string_source('2\n1 4')
except ImportError:
	source = input
durs = [20, 10, 20]

def cans(durs):
	g = ((d, idx + 1) for (idx, d) in enumerate(durs))
	(sorted_durs, idxes) = zip(*sorted(g, key=lambda x: (-x[0], x[1])))
	shots = sum((idx * s + 1 for (idx, s) in enumerate(sorted_durs)))
	return (shots, idxes)
source()
(shots, idxes) = cans(list(map(int, source().split())))
print(shots)
print(' '.join(map(str, idxes)))


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


i = 0

def read(a):
	global i
	i += 1
	return (int(a), i)

def k(a):
	return a[0]
input()
banks = sorted(map(read, input().split()), reverse=True, key=k)
b = 0
s = 0
for i in banks:
	s += i[0] * b + 1
	b += 1
print(s)
for i in banks:
	print(i[1], end=' ')


a = int(input())
b = input().split()
for i in range(len(b)):
	b[i] = int(b[i])
d = dict()
c = 0
s = ''
for i in range(len(b)):
	if not b[i] in d.keys():
		d[b[i]] = [i]
	else:
		d[b[i]] += [i]
b = sorted(b, reverse=True)
for i in range(len(b)):
	c += b[i] * i + 1
	s += str(d[b[i]][0] + 1) + ' '
	if len(d[b[i]]) > 1:
		d[b[i]] = d[b[i]][1:]
print(c)
print(s)


n = int(input())
a = [int(x) for x in input().split()]
ans = 0
k = 0
b = []
for i in range(n):
	b.append((a[i], i + 1))
b.sort(reverse=True)
for i in range(len(b)):
	ans += b[i][0] * k + 1
	k += 1
print(ans)
for i in b:
	print(i[1], end=' ')


n = int(input())
a = [int(i) for i in input().split()]
b = sorted(a, reverse=True)
c = []
m = 0
for i in range(n):
	m += b[i] * i + 1
	c.append(a.index(b[i]) + 1)
	a[a.index(b[i])] = 0
print(m)
for i in c:
	print(i, end=' ')


input()
s = []
for i in input().split(' '):
	s.append(int(i))
o = []
c = 0
t = 0
for i in reversed(range(max(s) + 1)):
	for j in range(len(s)):
		if s[j] == i:
			t += c * i + 1
			c += 1
			o.append(j)
print(t)
for i in o:
	print(i + 1, end=' ')


from sys import setcheckinterval, stdin, setrecursionlimit
setcheckinterval(1000)
setrecursionlimit(10 ** 7)

def iin():
	return int(stdin.readline())

def lin():
	return list(map(int, stdin.readline().split()))
n = iin()
a = lin()
sa = [[a[i], i] for i in range(n)]
sa.sort(reverse=True)
ans = 0
ch = -1
sol = []
for (i, j) in sa:
	ch += 1
	ans += i * ch + 1
	sol.append(j + 1)
print(ans)
print(*sol)


n = int(input())
a = list(zip(map(int, input().split()), range(n)))
a.sort(reverse=True)
ans = sum((x * y + 1 for (x, (y, _)) in zip(range(n), a)))
print(ans)
print(*(y + 1 for (_, y) in a))


def x(m):
	return m[1]
N = int(input())
arr = list(map(int, input().split()))
arr = list(enumerate(arr, 1))
arr.sort(key=x, reverse=True)
cost = 0
broke = 0
for i in range(N):
	cost += arr[i][1] * broke + 1
	broke += 1
print(cost)
print(' '.join([str(x[0]) for x in arr]))


from sys import stdin
input = stdin.readline
n = int(input())
a = list(map(int, input().split()))
l = []
for i in range(n):
	t = (a[i], i + 1)
	l.append(t)
l.sort(reverse=True)
c = 0
out = []
for i in range(n):
	c += l[i][0] * i + 1
	out.append(str(l[i][1]))
print(c)
print(' '.join(out))


n = int(input())
l = list(map(int, input().split()))
list2 = []
for i in range(0, len(l)):
	list2.append([l[i], i + 1])
list2.sort(reverse=True)
sum1 = 0
for i in range(0, len(list2)):
	sum1 += list2[i][0] * i + 1
print(sum1)
for i in range(0, len(list2)):
	print(list2[i][1], end=' ')


n = int(input())
lst = [int(s) for s in input().split()]
d = {}
for (i, x) in enumerate(lst):
	if d.get(x) is None:
		d[x] = []
	d[x].append(i + 1)
lst.sort()
key = list(d.keys())
key.sort()
key.reverse()
(b, x, result) = ([], 0, 0)
for (i, a) in enumerate(key):
	for (j, y) in enumerate(d[a]):
		b.append(y)
		result += a * x + 1
		x += 1
print(result)
print(*b)


n = int(input())
l1 = list(map(int, input().split()))
temp = []
for i in range(n):
	temp.append((-l1[i], i + 1))
temp.sort()
answer = 0
result = []
for i in range(n):
	answer -= i * temp[i][0] - 1
	result.append(temp[i][1])
print(answer)
print(*result, sep=' ')


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


n = input()
arr = list(sorted(enumerate(map(int, input().strip().split())), key=lambda x: x[1]))
(count, sum, order) = (0, 0, [])
for (k, v) in arr[::-1]:
	sum += count * v + 1
	order.append(str(k + 1))
	count += 1
print(sum)
print(' '.join(order))


n = int(input())
a = list(map(int, input().split()))
b = [0 for j in range(n)]
l = len(a)
x = 0
summ = 0
for i in range(l):
	maxx = max(a)
	ind = a.index(maxx)
	summ = summ + maxx * x + 1
	b[i] = ind + 1
	a[ind] = -1
	x += 1
print(summ)
for k in range(l):
	print(b[k], '', end='')


n = int(input())
alist = map(int, input().split())
ans = []
for (idx, val) in enumerate(alist):
	ans.append((idx, val))
ans.sort(key=lambda x: (-x[1], x[0]))
sum = 0
j = 0
idx = []
for i in ans:
	sum += j * i[1] + 1
	idx.append(i[0])
	j += 1
print(sum)
for i in idx:
	print(i + 1, end=' ')


n = int(input())
l1 = list(map(int, input().split()))
d = {}
for i in range(1002):
	d[i] = []
for i in range(len(l1)):
	d[l1[i]].append(i)
l2 = sorted(l1, reverse=1)
ans = 0
for i in range(len(l1)):
	ans += l2[i] * i + 1
print(ans)
for i in range(len(l1)):
	print(d[l2[i]].pop() + 1, end=' ')


n = int(input())
a = [(int(x), i) for (i, x) in enumerate(input().split(), start=1)]
a.sort(reverse=True, key=lambda x: x[0])
r = 0
n = []
for (i, aa) in enumerate(a):
	r += i * aa[0] + 1
	n.append(aa[1])
print(r)
print(*n)


n = int(input())
h = list(map(int, input().split()))
s = 0
c = []
i = 0
while i < n:
	c.append(h.index(max(h)) + 1)
	s += max(h) * i + 1
	h[h.index(max(h))] = -100
	i += 1
print(s)
i = 0
while i < len(c):
	print(c[i], end=' ')
	i += 1


n = int(input())
a = [int(s) for s in input().split()]
b = []
for i in range(n):
	b.append((a[i], i))
b.sort(reverse=True)
count = 0
for i in range(n):
	count += b[i][0] * i + 1
print(count)
for i in b:
	print(i[1] + 1, end=' ')


import math
import sys
import itertools
import itertools

def sa(Type=int):
	return [Type(x) for x in input().split()]

def solve(t):
	n = int(input())
	arr = sa()
	arr = list(enumerate(arr))
	arr.sort(key=lambda x: x[1], reverse=True)
	cc = 0
	x = 0
	for (i, c) in arr:
		cc += x * c + 1
		x += 1
	print(cc)
	print(' '.join(map(lambda x: str(x[0] + 1), arr)))
solve(1)


import sys
sin = sys.stdin
n = int(sin.readline())
a = sin.readline().split()
a = [int(x) for x in a]
a = [(a[i], i) for i in range(len(a))]

def first(tup):
	return tup[0]
a.sort(key=first, reverse=True)
shots = 0
x = 0
order = []
for i in a:
	shots += i[0] * x + 1
	x += 1
	order.append(i[1] + 1)
print(shots)
print(' '.join([str(x) for x in order]))


length = int(input())
cans = list(map(int, input().split(' ')))
cansOrder = sorted(cans, reverse=True)
knockedDown = 0
knockOrder = []
shots = 0
for shot in cansOrder:
	shots += shot * knockedDown + 1
	knockedDown += 1
	knockOrder.append(cans.index(shot) + 1)
	cans[cans.index(shot)] = 0
print(shots)
for orderNumber in knockOrder:
	print(orderNumber, end=' ')


def ain():
	return map(int, input().split())
n = int(input())
l = list(ain())
ind = []
for i in range(1, n + 1):
	ind += [i]
z = [x for (_, x) in sorted(zip(l, ind))]
z.reverse()
o = []
sum = 0
for i in range(n):
	x = z[i]
	o += [x]
	sum += l[x - 1] * i + 1
print(sum)
for x in o:
	print(x, end=' ')


import sys
r = lambda : sys.stdin.readline().rstrip()
n = int(r())
scores = list(map(int, r().split()))
scores = list(enumerate(scores))
scores.sort(key=lambda x: x[1])
ans = 0
answer = []
for i in range(n):
	curr = scores.pop()
	ans += i * curr[1] + 1
	answer.append(curr[0])
print(ans)
for i in answer:
	print(i + 1, end=' ')


n = map(int, input())
arr = list(map(int, input().split()))
dict = {}
for (k, v) in enumerate(arr):
	dict[k] = v
l = sorted(dict.items(), key=lambda x: x[1], reverse=True)
i = 0
val = 0
ra = []
for (k, v) in l:
	val += i * v + 1
	i += 1
	ra.append(k + 1)
print(val)
print(' '.join(list(map(str, ra))))


n = int(input())
a = list(map(int, input().split()))
c = 0
l = [[a[0], 1]]
for i in range(1, n):
	l.append([a[i], i + 1])
l.sort(reverse=True)
s = 0
for i in range(n):
	k = l[i][0] * i
	k = k + 1
	s = s + k
print(s)
for i in range(n):
	print(l[i][1], end=' ')
print()


import sys

def main():

	def input():
		return sys.stdin.readline()[:-1]
	n = int(input())
	a = list(map(int, input().split()))
	l = [[a[k], k] for k in range(n)]
	l = sorted(l, key=lambda x: -x[0])
	A = []
	ans = 1
	A.append(l[0][1] + 1)
	for k in range(1, n):
		ans += k * l[k][0] + 1
		A.append(l[k][1] + 1)
	print(ans)
	print(*A, sep=' ')
main()


x = int(input())
p = list(map(int, input().split()))
y = sorted(p, reverse=True)
k = list()
(l, t) = (0, 0)
for i in range(x):
	t += l * y[i] + 1
	l += 1
	for j in range(x):
		if y[i] == p[j]:
			k.append(j + 1)
			p[j] = -1
print(t)
print(*k, sep=' ')


n = int(input())
s = list(map(int, input().split()))
s = [[s[i], i + 1] for i in range(n)]
s.sort()
s.reverse()
j = 0
ans = 0
for i in s:
	ans += i[0] * j + 1
	j += 1
print(ans)
print(*[s[i][1] for i in range(n)])


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


n = int(input())
l = list(map(int, input().split()))
l2 = l
l3 = sorted(l)
l3 = l3[::-1]
c = 0
su = 0
for i in range(n):
	su = su + (l3[i] * c + 1)
	c = c + 1
ix = [0] * n
for i in range(n):
	for j in range(n):
		if l3[i] == l2[j] and l2[j] != -1:
			ix[i] = j + 1
			l2[j] = -1
			break
print(su)
print(*ix)


n = int(input())
a = list(map(int, input().split()))
b = sorted([[-a[i], i] for i in range(n)])
print(sum([-b[i][0] * i + 1 for i in range(n)]))
print(' '.join(map(lambda x: str(x[1] + 1), b)))


def c(w, x):
	return w * x + 1
n = int(input())
if not (2 <= n and n <= 1000):
	raise Exception('invalid input')
b = input().split()
a = [[i, int(b[i])] for i in range(n)]
if all((1 <= x[1] and x[1] <= 1000 for x in a)):
	pass
else:
	raise Exception('invalid input')
a.sort(reverse=True, key=lambda x: x[1])
ans = 0
time = 0
for x in a:
	ans += c(x[1], time)
	time += 1
print(ans)
for x in a:
	print(x[0] + 1, end=' ')


n = int(input())
s = input().split()
a_s = []
for a in s:
	a_s.append(int(a))
a = sorted(a_s, reverse=True)
l = ''
count = 0
c = 0
for i in a:
	count += i * c + 1
	l += str(s.index(str(i)) + 1) + ' '
	s[s.index(str(i))] = -1
	c += 1
print(count)
print(l)


n = int(input())
dat = list(map(int, input().split()))
dat_a = []
for i in range(n):
	dat_a.append((dat[i], i + 1))
dat_a.sort(reverse=True, key=lambda x: x[0])
x = 0
res = 0
res_dat = []
for i in range(n):
	res += 1 + x * dat_a[i][0]
	res_dat.append(str(dat_a[i][1]))
	x += 1
print(res)
print(' '.join(res_dat))


import operator
n = int(input())
a = list(map(int, input().split()))
dic = {}
ans = []
fact = 0
sums = 0
for i in range(1, len(a) + 1):
	dic[i] = a[i - 1]
sorted_x = sorted(dic.items(), key=operator.itemgetter(1))
for i in sorted_x[::-1]:
	ans.append(i[0])
	sums += i[1] * fact + 1
	fact += 1
print(sums)
print(*ans)


n = int(input())
al = input().split()
alll = n
a = []
k = {}
for (i, j) in enumerate(al):
	if int(j) not in k.keys():
		k[int(j)] = [i + 1]
	else:
		k[int(j)].append(i + 1)
	a.append(int(j))
al = []
for i in sorted(a)[::-1]:
	alll += i * len(al)
	al.append(str(k[i][0]))
	del k[i][0]
print(alll)
print(' '.join(al))


def func(n):
	global i
	i += 1
	return (int(n), i)
i = 0
cans = [input(), sorted(map(func, input().split()), key=lambda x: x[0], reverse=True)][1]
res = sum((cans[i][0] * i + 1 for i in range(len(cans))))
print(res, ' '.join((str(a[1]) for a in cans)), sep='\n')


import os
import sys
from io import BytesIO, IOBase
import math
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 = int(input())
l = list(map(int, input().split()))
ll = sorted(l)
c = 0
sum = n
ll.sort(reverse=True)
for i in range(n):
	sum += ll[i] * c
	c += 1
print(sum)
na = []
for i in range(n):
	var = ll[i]
	for j in range(n):
		if var == l[j]:
			na.append(j + 1)
			l[j] = -1
			break
print(*na, end=' ')


n = int(input())
a = list(map(int, input().split()))
ia = [(i, a[i]) for i in range(n)]
ia.sort(key=lambda t: t[1], reverse=True)
ans1 = 0
ans2 = []
c = 0
for (i, ai) in ia:
	ans1 += c * ai + 1
	ans2.append(i + 1)
	c += 1
print(ans1)
print(*ans2)


n = int(input())
arr = list(map(int, input().split()))
arr4 = arr.copy()
arr2 = sorted(arr, reverse=True)
arr3 = []
count = 0
result = 0
for k in arr2:
	z = arr.index(k)
	arr3.append(z + 1)
	arr.remove(k)
	arr.insert(z, '@')
	result += k * count + 1
	count += 1
print(result)
for kk in arr3:
	print(kk, end=' ')


n = int(input())
a = list(map(int, input().split()))
a = [(i, x) for (i, x) in enumerate(a)]
a = sorted(a, key=lambda x: x[1], reverse=True)
total = [i * y + 1 for (i, (x, y)) in enumerate(a)]
print(sum(total))
print(*[x + 1 for (x, y) in a])


from copy import copy
count = int(input())
cans = list(map(int, input().split()))
sorted_cans = copy(cans)
sorted_cans.sort()
sorted_cans.reverse()
out = []
cost = 0
for (ind, val) in enumerate(sorted_cans):
	cost += ind * val + 1
	index = cans.index(val)
	out.append(index + 1)
	cans[index] = -1
print(cost)
print(' '.join((str(i) for i in out)))


n = int(input())
a = [int(x) for x in input().split()]
b = a.copy()
c = []
b.sort(reverse=True)
j = 0
sum = 0
for i in range(0, n):
	sum = sum + b[i] * j + 1
	j += 1
	for k in range(0, n):
		if b[i] == a[k]:
			c.append(k + 1)
			a[k] = -1
			break
print(sum)
for i in c:
	print(i, end=' ')


n = int(input())
l = list(map(int, input().split()))
cnt = 0
for i in range(len(l)):
	l[i] = (l[i], i)
l.sort(reverse=True)
for (i, e) in enumerate(l):
	cnt += e[0] * i + 1
print(cnt)
for i in l:
	print(i[1] + 1, end=' ')


n = int(input())
a = list(map(int, input().split()))
b = []
total = 0
for i in range(len(a)):
	k = a.index(max(a))
	total += a[k] * i + 1
	b.append(k + 1)
	a[k] = -1
print(total)
print(*b)


n = int(input())
numbers = list(map(int, input().split(' ')))
out_list = [0 for _ in numbers]
out = 0
i = 0
while any(numbers):
	out += i * max(numbers) + 1
	out_list[i] = numbers.index(max(numbers)) + 1
	numbers[out_list[i] - 1] = 0
	i += 1
print(out)
print(' '.join(list(map(str, out_list))))


n = int(input())
A = list(map(int, input().split()))
B = [(A[i], i + 1) for i in range(n)]
B.sort(reverse=True)
fin = [0] * n
c = 0
for i in range(n):
	c += i * B[i][0] + 1
	fin[i] = B[i][1]
print(c)
print(' '.join([str(i) for i in fin]))


n = int(input())
arr = [int(i) for i in input().split()]
d = {i + 1: arr[i] for i in range(len(arr))}
shots = 0
c = 0
ind = []
for (key, val) in sorted(d.items(), key=lambda x: x[1], reverse=True):
	shots += val * c + 1
	ind.append(key)
	del d[key]
	c += 1
print(shots)
print(*ind)


n = int(input())
arr = list(map(int, input().split()))
arr1 = sorted(arr, reverse=True)
cost = 0
indices = []
for i in range(n):
	cost += arr1[i] * i + 1
	indices.append(arr.index(arr1[i]) + 1)
	arr[arr.index(arr1[i])] = -1
print(cost)
print(' '.join([str(i) for i in indices]))


n = int(input())
l = list(map(int, input().split(' ')))
copy = l.copy()
l.sort(reverse=True)
sum = 0
for i in range(0, n):
	sum = sum + (l[i] * i + 1)
print(sum)
s = list(set(l))
s.sort(reverse=True)
for i in s:
	for (count, ele) in enumerate(copy):
		if i == ele:
			print(count + 1, end=' ')


n = int(input())
durabilities = [(int(d), i + 1) for (i, d) in enumerate(input().split(' '))]
sorted_by_d = sorted(durabilities, reverse=True)
shots = 0
cans = 0
for (d, i) in sorted_by_d:
	shots += d * cans + 1
	cans += 1
sequence = ' '.join([str(i) for (d, i) in sorted_by_d])
print(shots)
print(sequence)


def main():
	n = int(input())
	lista = list(map(int, input().split()))
	order = sorted(lista, reverse=True)
	soma = sum([order[i] * i for i in range(n)])
	seq = ''
	for i in order:
		index = lista.index(i)
		seq += ' ' + str(index + 1)
		lista[index] = -1
	print(soma + n)
	print(seq.strip())
main()


n = int(input())
a = list(map(int, input().split()))
li = []
l = []
for i in a:
	l.append(i)
a.sort(reverse=True)
c = 0
r = 0
for i in range(len(a)):
	r += a[i] * c + 1
	c += 1
for i in a:
	li.append(l.index(i) + 1)
	l[l.index(i)] = -1
print(r)
for i in li:
	print(i, end=' ')


input()
cans = list(map(int, input().split(' ')))
candict = dict(zip(range(1, len(cans) + 1), cans))
candict = sorted(candict.items(), key=lambda item: item[1], reverse=True)
cost = 1
FACTOR = 1
result = ''
result += str(candict[0][0])
for i in range(1, len(candict)):
	cost += candict[i][1] * FACTOR + 1
	result += ' ' + str(candict[i][0])
	FACTOR += 1
print(cost)
print(result)


n = int(input())
a = list(map(int, input().split()))
b = [[a[i], i + 1] for i in range(n)]
b.sort()
b = sorted(b, reverse=True)
k = 0
f = ''
for i in range(n):
	k += b[i][0] * i + 1
	f += str(b[i][1]) + ' '
print(k)
print(f)


n = int(input())
a = list(map(int, input().split()))
l = []
o = []
for _ in range(len(a)):
	i = -1
	m = 0
	for x in range(len(a)):
		if a[x] > m:
			m = a[x]
			i = x
	a[i] = 0
	o.append(i + 1)
	l.append(m)
print(sum((l[x] * x + 1 for x in range(len(l)))))
print(*o)


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	temp = []
	a = list(map(int, input().split(' ')))
	for x in range(n):
		temp.append([a[x], x + 1])
	temp.sort(reverse=True)
	ans = 0
	for x in range(n):
		ans += x * temp[x][0] + 1
	print(ans)
	print(*list(map(lambda x: x[1], temp)))
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')
main()


n = int(input())
X = [int(x) for x in input().split(' ')]
c = 0
j = 0
ans = []
while set(X) != {0}:
	temp = max(X)
	for i in range(len(X)):
		if X[i] == temp:
			c = c + X[i] * j + 1
			X[i] = 0
			j = j + 1
			ans.append(i + 1)
			break
print(c)
print(' '.join((str(v) for v in ans)))


n = int(input())
t = []
x = 0
a = list(map(int, input().split()))
b = list(zip(a, range(n)))
b = sorted(b, reverse=True)
for i in range(n):
	x += b[i][0] * i + 1
	t.append(b[i][1] + 1)
print(x)
print(*t)


from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 10 ** 6 + 1
MOD = 10 ** 9 + 7
spf = [i for i in range(MAXN)]

def sieve():
	for i in range(2, MAXN, 2):
		spf[i] = 2
	for i in range(3, int(MAXN ** 0.5) + 1):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def mhd(a, b):
	return abs(a[0] - b[0]) + abs(b[1] - a[1])

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def eld(x, y):
	a = y[0] - x[0]
	b = x[1] - y[1]
	return (a * a + b * b) ** 0.5

def lgcd(a):
	g = a[0]
	for i in range(1, len(a)):
		g = math.gcd(g, a[i])
	return g

def ms(a):
	msf = -MAX
	meh = 0
	st = en = be = 0
	for i in range(len(a)):
		meh += a[i]
		if msf < meh:
			msf = meh
			st = be
			en = i
		if meh < 0:
			meh = 0
			be = i + 1
	return (msf, st, en)

def ncr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % MOD
		den = den * (i + 1) % MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def flush():
	return sys.stdout.flush()
n = int(input())
a = arrIN()
x = [[i, a[i]] for i in range(n)]
x.sort(key=lambda x: x[1], reverse=True)
ans = 0
temp = []
for i in range(n):
	ans += x[i][1] * i + 1
	temp.append(x[i][0] + 1)
print(ans)
print(*temp)


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


import copy
n = int(input())
x = input()
y = x.split()
z = [int(d) for d in y]
a = copy.deepcopy(z)
z.sort(reverse=True)
x = 0
count = 0
l = []
for i in z:
	count = count + i * x + 1
	x += 1
for i in range(len(z)):
	l.append(a.index(max(a)) + 1)
	a[a.index(max(a))] = -1
print(count)
print(*l)


import math
inarr = lambda : map(int, input().split())
for _ in range(1):
	n = int(input())
	s = list(inarr())
	s1 = s.copy()
	sum1 = 0
	j = 0
	a = []
	s.sort()
	s.reverse()
	for i in s:
		a.append(s1.index(i) + 1)
		s1[s1.index(i)] = -1
		sum1 += j * i + 1
		j = j + 1
	print(sum1)
	print(*a)


n = int(input())
a = list(map(int, input().split()))
b = a.copy()
ans = 0
f = []
a.sort(reverse=True)
for r in a:
	for i in range(n):
		if r == b[i]:
			b[i] = 0
			f.append(i + 1)
			break
for i in range(n):
	ans += a[i] * i + 1
print(ans)
for i in f:
	print(i, end=' ')


r = range(int(input()))
c = sorted(zip(map(int, input().split()), r))[::-1]
print(sum((c[i][0] * i + 1 for i in r)))
print(*(c[i][1] + 1 for i in r))


n = int(input())
a = list(map(int, input().split()))
vals = set(a)
x = 0
ans = 0
out = []
while vals:
	curr_max = max(vals)
	for i in range(n):
		if a[i] == curr_max:
			ans += curr_max * x + 1
			x += 1
			out.append(i + 1)
	vals.remove(curr_max)
print(ans)
print(*out)


n = int(input())
(a, i) = ([], 0)
for x in input().split():
	a.append([int(x), i + 1])
	i += 1
a = sorted(a)[::-1]
(x, shots) = (0, 0)
order = []
for x in range(n):
	shots += a[x][0] * x + 1
	order += [a[x][1]]
print(shots)
print(*order)


import copy
n = int(input())
can_seq = list(map(int, input().split()))
can_seq2 = copy.deepcopy(can_seq)
can_seq.sort()
ans_seq = []
ko_cans = 0
shots_taken = 0
for i in range(len(can_seq)):
	j = can_seq.pop()
	shots_taken += j * ko_cans + 1
	ko_cans += 1
	ans_seq.append(can_seq2.index(j) + 1)
	can_seq2[can_seq2.index(j)] = -1
print(shots_taken)
for i in ans_seq:
	print(i, end=' ')


n = int(input())
arr = list(map(lambda x: int(x), input().split(' ')))
for i in range(0, n):
	arr[i] = (arr[i], i)
arr.sort(reverse=True)
cc = 0
for i in range(0, n):
	cc += arr[i][0] * i + 1
print(cc)
for i in range(0, n):
	print(arr[i][1] + 1, end=' ')
print()


q = int(input())
w = input().split()
for x in range(q):
	w[x] = (int(w[x]), x + 1)
w.sort()
w.reverse()
f = 0
o = []
for x in range(q):
	f = f + x * w[x][0] + 1
print(f)
for x in range(q):
	print(w[x][1], end=' ')


n = int(input())
l = [int(i) for i in input().split()]
z = l.copy()
l = sorted(l)
l.reverse()
a = 0
ind = []
for i in range(n):
	a += l[i] * i + 1
	inde = z.index(l[i])
	ind.append(inde + 1)
	z[inde] = -1
print(a)
print(*ind)


n = int(input())
a = list(map(int, input().split()))
li = []
count = 0
for i in range(0, len(a)):
	c = a.index(max(a))
	li.append(c + 1)
	count += i * max(a) + 1
	a[c] = 0
print(count)
print(*li)


def f(A):
	count = 0
	order = []
	for i in range(len(A)):
		maxi = 0
		for j in range(1, len(A)):
			if A[j] > A[maxi]:
				maxi = j
		count += A[maxi] * i + 1
		A[maxi] = -1
		order.append(maxi + 1)
	return (count, order)
assert f([30, 10, 20]) == (43, [1, 3, 2])
assert f([10, 10, 10, 10]) == (64, [1, 2, 3, 4])
assert f([5, 4, 5, 4, 4, 5]) == (69, [1, 3, 6, 2, 4, 5])
assert f([1, 4]) == (3, [2, 1])
n = int(input())
A = list(map(int, input().split()))
(a, b) = f(A)
print(a)
print(' '.join([str(x) for x in b]))


input()
data = sorted(((int(value), index + 1) for (index, value) in enumerate(input().split())), key=lambda v: -v[0])
print(sum((index * value + 1 for (index, (value, _)) in enumerate(data))))
print(' '.join((str(index) for (_, index) in data)))


N = int(input())
a_list = list(map(int, input().split()))
from heapq import *
que = []
for (i, a) in enumerate(a_list):
	que.append((-a, i + 1))
cnt = 0
ans = []
heapify(que)
while len(que) >= 1:
	q = heappop(que)
	cnt += len(ans) * -q[0] + 1
	ans.append(q[1])
print(cnt)
for a in ans:
	print(a, end=' ')


n = int(input())
arr = list(map(int, input().split()))
marr = []
for i in range(n):
	marr.append([arr[i], i])
marr.sort(reverse=True)
ans = 0
for i in range(n):
	ans += marr[i][0] * i + 1
print(ans)
iarr = []
for i in range(n):
	iarr.append(marr[i][1] + 1)
print(*iarr)


n = int(input())
li = list(map(int, input().split()))
li = sorted(zip(li, list(range(len(li)))))[::-1]
ans = 0
for i in range(n):
	ans += li[i][0] * i + 1
print(ans)
ans_li = []
for i in range(n):
	ans_li.append(li[i][1] + 1)
print(*ans_li)


n = int(input())
arr = [int(x) for x in input().split()]
shots = []
seq = [[a, i] for (i, a) in enumerate(arr)]
A = sorted(seq)[::-1]
while len(arr) != 0:
	mx = max(arr)
	shots.append(mx * len(shots) + 1)
	arr.remove(mx)
print(sum(shots))
print(*[A[i][1] + 1 for i in range(n)])


n = int(input())
s = list(map(int, input().split()))
ind_sort = sorted(range(len(s)), key=lambda k: s[k])
l_sort = sorted(s)
temp1 = ind_sort[-1::-1]
for i in range(n):
	temp1[i] += 1
temp2 = l_sort[-1::-1]
SUM = 0
x = 0
for i in range(n):
	SUM += temp2[i] * x + 1
	x += 1
print(SUM)
print(*temp1)


num_cans = int(input())
cans = list(map(int, input().split(' ')))
indexes = [str(i + 1) for i in range(num_cans)]
(cans, indexes) = [list(t) for t in zip(*sorted(zip(cans, indexes), reverse=True))]
num_shots = 0
for i in range(num_cans):
	num_shots += cans[i] * i + 1
print(num_shots)
print(' '.join(indexes))


r = range(int(input()))
a = sorted(zip(map(int, input().split()), r))[::-1]
print(sum((x * y + 1 for ((x, _), y) in zip(a, r))))
print(*(i + 1 for (_, i) in a))


import math, sys
from collections import Counter, defaultdict
from sys import stdin, stdout
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))
n = int(input())
a = li()
b = a.copy()
b.sort(reverse=True)
s = 0
for i in range(0, n):
	s = s + i * b[i] + 1
print(s)
d = Counter(b)
for i in range(0, n):
	print(a.index(b[i]) + 1, end=' ')
	a[a.index(b[i])] = 0


n = int(input())
arr = list(map(int, input().split()))
temp = arr.copy()
temp.sort(reverse=True)
count = 1
sum_ = 1
index = [arr.index(temp[0]) + 1]
arr[arr.index(temp[0])] = 'X'
for i in range(1, n):
	sum_ += count * temp[i] + 1
	index.append(arr.index(temp[i]) + 1)
	arr[arr.index(temp[i])] = 'X'
	count += 1
print(sum_)
print(*index, sep=' ')


input()
N = []
k = 0
for (i, a) in sorted(enumerate(map(int, input().split()), 1), key=lambda x: x[1], reverse=True):
	k += a * len(N) + 1
	N.append(i)
print(k)
print(*N)


from sys import stdin

def ii():
	return int(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline()
n = ii()
a = li()
b = [i for i in range(1, n + 1)]
a = list(zip(a, b))
a.sort(reverse=True)
(a, b) = zip(*a)
p = n
for i in range(n):
	p += i * a[i]
print(p)
print(*b)


cnt = [0 for i in range(1002)]
ind = [[] for i in range(1002)]
n = int(input())
a = list(map(int, input().split()))
max = 0
for i in range(n):
	x = a[i]
	cnt[x] += 1
	ind[x].append(i + 1)
	if x > max:
		max = x
l = 0
N = 0
ans = 0
inn = [0]
while max >= 0:
	if cnt[max] > 0:
		N = l + cnt[max]
		ans += cnt[max] + max * ((N * (N - 1) - l * (l - 1)) // 2)
		l = N
		inn += ind[max]
	max -= 1
print(ans)
for i in range(1, len(inn) - 1):
	print(inn[i], end=' ')
print(inn[len(inn) - 1])


n = int(input())
l = [int(x) for x in input().split()]
l1 = []
shots = 0
for i in range(n):
	l1.append((l[i], i + 1))
l1.sort(reverse=True)
order = []
for i in range(n):
	shots += l1[i][0] * i + 1
	order.append(l1[i][1])
print(shots)
print(*order)


n = int(input())
a = list(map(int, input().split()))
a = [(x, idx) for (idx, x) in enumerate(a)]
a.sort(reverse=True)
ans = 0
for i in range(n):
	ans += a[i][0] * i + 1
print(ans)
print(' '.join((str(i + 1) for (_, i) in a)))


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
B = [[a, i] for (i, a) in enumerate(A)]
B.sort(reverse=True)
ANS = 0
ind = 0
for (b, i) in B:
	ANS += b * ind + 1
	ind += 1
print(ANS)
print(*[B[i][1] + 1 for i in range(n)])


n = int(input())
a = list(map(int, input().split()))
b = list(set(a))
b.sort()
b = b[::-1]
d = {}
for i in range(n):
	x = a[i]
	d[x] = d.get(x, [])
	d[x].append(i + 1)
c = []
p = 0
sum = 0
for x in b:
	l = len(d[x])
	sum += x * (l * (2 * p + l - 1) // 2) + l
	p += l
	c.extend(d[x])
print(sum)
print(*c)


n = int(input().strip())
can_durability = [int(x) for x in input().strip().split(' ')]
can_durability2 = [(cd, i) for (i, cd) in enumerate(can_durability)]
can_durability2.sort(key=lambda t: t[0], reverse=True)
shoots = 0
for i in range(n):
	shoots = shoots + can_durability2[i][0] * i + 1
print(shoots)
for item in can_durability2:
	print(item[1] + 1, end=' ')
print()


n = int(input())
alist = [int(x) for x in input().split(' ')]
blist = list(sorted(alist))
blist.reverse()
ans = 0
for i in range(n):
	ans += i * blist[i] + 1
print(ans)
x = -1
k = 0
for i in range(n):
	if blist[i] != k:
		x = -1
	x = alist.index(blist[i], x + 1)
	k = blist[i]
	print(x + 1, end=' ')


n = int(input())
l = list(map(int, input().split()))
l1 = l.copy()
l2 = []
l.sort(reverse=True)
s = 1
for i in range(1, len(l)):
	s = s + (l[i] * i + 1)
print(s)
for i in range(len(l)):
	p = l1.index(l[i])
	l2.append(p)
	l1[p] = -1
for i in l2:
	print(i + 1, end=' ')


n = int(input())
l = list(map(int, input().split()))
ind = {}
i = 0
s = 0
for j in l:
	if j in ind.keys():
		ind[j].append(str(i + 1))
	else:
		ind[j] = [str(i + 1)]
	i += 1
l.sort(key=lambda x: -x)
for x in range(len(l)):
	s += l[x] * x + 1
print(s)
d = list(ind.items())
d.sort(key=lambda t: -t[0])
for i in d:
	print(' '.join(i[1]), end=' ')


n = int(input())
ls = input().split(' ')
ls = [int(x) for x in ls]
a = []
for i in range(n):
	a.append([ls[i], i])
a.sort()
a.reverse()
ans = 0
for i in range(n):
	ans += a[i][0] * i + 1
print(ans)
for i in range(n):
	print(a[i][1] + 1, end=' ')


n = int(input())
lst = [(v, i + 1) for (i, v) in enumerate(list(map(int, input().split())))]
l = sorted(lst, reverse=True)
count = 0
res = [0] * n
for i in range(n):
	count += i * l[i][0] + 1
	res[i] = l[i][1]
print(count)
print(*res)


n = int(input())
s = input().split()
a = []
for i in s:
	a.append(int(i))
b = []
shots = 0
for i in range(n):
	m = max(a)
	ind = a.index(m)
	shotrequired = a[ind] * len(b) + 1
	a[ind] = 0
	b.append(ind + 1)
	shots += shotrequired
print(shots)
for i in b:
	print(i, end=' ')
print()


import operator
n = input('')
durabilityList = input('').split(' ')
durabilityMap = []
for i in range(len(durabilityList)):
	durabilityMap.append((i + 1, int(durabilityList[i])))
sortedMap = sorted(durabilityMap, key=operator.itemgetter(1), reverse=True)
output = 0
for i in range(len(sortedMap)):
	output += i * int(sortedMap[i][1])
print(output + len(durabilityList))
for tuple in sortedMap:
	print(tuple[0], end=' ')


n = int(input())
a = list(map(int, input().split()))
b = [i for i in range(n)]

def cmp(x):
	global a
	return -a[x]
b.sort(key=cmp)
ans = 0
for i in range(n):
	ans = ans + i * a[b[i]] + 1
	b[i] += 1
print(ans)
print(*b)


def rint():
	return int(input())

def rints():
	return list(map(int, input().split()))
n = rint()
a = rints()
ai = list(range(n))
ai.sort(key=lambda i: a[i], reverse=True)
s = 0
for (i, idx) in enumerate(ai):
	s += a[idx] * i + 1
print(s)
print(' '.join((str(i + 1) for i in ai)))


n = int(input())
l = list(map(int, input().split()))
for i in range(n):
	l[i] = [l[i], i]
l.sort()
(cost, count) = (0, 0)
ans = []
for i in range(n - 1, -1, -1):
	cost += count * l[i][0] + 1
	ans.append(l[i][1] + 1)
	count += 1
print(cost)
print(*ans)


n = int(input())
a = list(map(int, input().split()))
a1 = [i[0] + 1 for i in sorted(enumerate(a), key=lambda x: x[1], reverse=True)]
a = sorted(a, reverse=True)
sum_req = 0
for i in range(n):
	sum_req += i * a[i]
sum_req += n
print(sum_req)
for i in range(n):
	print(a1[i], end=' ')


n = int(input())
x = input().split(' ')
y = []
for i in range(len(x)):
	y.append([int(x[i]), i])
y.sort(reverse=True)
ans = 0
for i in range(len(y)):
	ans = ans + 1 + i * y[i][0]
print(ans)
z = [str(e[1] + 1) for e in y]
z = ' '.join(z)
print(z)


num_cans = int(input())
durability_list = enumerate(map(int, input().split()))
sorted_list = sorted(durability_list, key=lambda t: t[1], reverse=True)
shots = 0
output = []
for (x, (i, d)) in enumerate(sorted_list):
	shots += x * d + 1
	output.append(i + 1)
print(shots)
print(' '.join(map(str, output)))


n = int(input())
a = [int(i) for i in input().split()]
b = []
for i in a:
	b.append(i)
s = 0
j = 0
a.sort(reverse=True)
for i in range(n):
	s = s + (a[i] * j + 1)
	j = j + 1
print(s)
for i in a:
	print(b.index(i) + 1, end=' ')
	b[b.index(i)] = 'q'
print('\n')


n = int(input())
l = list(map(int, input().split()))
(ans, c) = (0, 0)
s = [[l[i], i + 1] for i in range(n)]
s.sort(reverse=True)
for x in s:
	ans += x[0] * c + 1
	c += 1
print(ans)
print(*(s[i][1] for i in range(n)))


n = int(input())
cans = []
raw = input().split()
place = 1
for i in raw:
	cans.append([int(i), place])
	place += 1
cans = sorted(cans, reverse=True)
suma = 0
toprint = []
for i in range(len(cans)):
	suma += cans[i][0] * i + 1
	toprint.append(str(cans[i][1]))
print(suma)
print(' '.join(toprint))


n = int(input())
a = list(map(int, input().split()))
j = res = 0
b = list()
for i in range(n):
	m = max(a)
	res += j * m + 1
	j += 1
	b.append(a.index(m) + 1)
	a[a.index(m)] = -1
print(res)
print(*b)


n = int(input())
s = 0
lst = list(map(int, input().strip().split(' ')))
li = []
for i in range(n):
	li.append([lst[i], i])
li.sort(reverse=True)
sort_index = []
l = []
for x in li:
	l.append(x[0])
	sort_index.append(x[1])
for i in range(n):
	s += l[i] * i + 1
print(s)
for i in range(n):
	print(sort_index[i] + 1, end=' ')


b'\nimport sys\nimport re\npattern = r"\x08(.+)\x01\x08"\nfor line in sys.stdin:\n    line = line.rstrip()\n    if re.search(pattern, line):\n        print(line)\n'
n = int(input())
life = [int(j) for j in input().split()]
staff = []
counter = 0
while len(staff) < n:
	counter += max(life) * len(staff) + 1
	staff.append(life.index(max(life)))
	life[life.index(max(life))] = -365
print(counter)
for i in staff:
	print(i + 1, end=' ')


n = int(input())
ar = [int(i) for i in input().split()]
a = sorted(ar, reverse=True)
c = 0
for i in range(n):
	c += a[i] * i + 1
print(c)
for i in a:
	if i in ar:
		print(ar.index(i) + 1, end=' ')
		ar[ar.index(i)] = -1


n = int(input())
s = map(int, input().split())
s = list(s)
l = [(i, a) for (i, a) in enumerate(s)]
l = sorted(l, reverse=True, key=lambda x: x[1])
banok_sbito = 0
otvet = 0
poryadok_banok = []
for (i, a) in l:
	otvet += a * banok_sbito + 1
	banok_sbito += 1
	poryadok_banok.append(i + 1)
print(otvet)
print(' '.join(map(str, poryadok_banok)))


n = int(input())
a = list(map(int, input().split()))
b = []
ans = []
for i in range(n):
	b.append(a[i])
for i in range(n):
	if a == []:
		break
	m = max(a)
	for j in range(n):
		if b[j] == m:
			ans.append(j + 1)
	a[:] = (value for value in a if value != m)
c = 0
shot = 0
for i in range(n):
	shot += max(b) * c + 1
	c += 1
	del b[b.index(max(b))]
print(shot)
print(*ans)


import re

def input_int():
	return list(map(int, input().split()))
input()
arr = input_int()
arr = zip(range(len(arr)), arr)
sorted_arr = sorted(arr, key=lambda el: el[1], reverse=True)
total = 0
for (i, tup) in enumerate(sorted_arr):
	total += i * tup[1] + 1
print(total)
print(' '.join([str(i[0] + 1) for i in sorted_arr]))


size = int(input())
l = list(map(int, input().split()))
ans = 0
pos = 1
l_i = []
while pos <= size:
	l_i.append(l.index(max(l)) + 1)
	ans += (pos - 1) * max(l) + 1
	pos += 1
	l[l.index(max(l))] = 0
print(ans)
for item in l_i:
	print(item, end=' ')


n = int(input())
A = list(map(int, input().split()))
B = [(a, i) for (i, a) in enumerate(A)]
B.sort(key=lambda x: (-x[0], x[1]))
res = 0
order = [0] * n
for j in range(n):
	(a, id) = B[j]
	res += a * j + 1
	order[j] = id + 1
print(res)
print(*order)


n = int(input())
l = [[int(_), ind + 1] for (ind, _) in enumerate(input().split())]
l.sort(reverse=1)
ans = []
for i in l:
	ans.append(i[1])
for i in range(len(l)):
	l[i] = l[i][0]
x = tot = 0
for i in range(len(l)):
	tot += l[i] * x + 1
	x += 1
print(tot)
print(*ans)


from collections import deque, Counter
import array
from itertools import combinations, permutations
from math import sqrt
import unittest

def read_int():
	return int(input().strip())

def read_int_array():
	return [int(i) for i in input().strip().split(' ')]
n = read_int()
a = [(i, e) for (i, e) in enumerate(read_int_array())]
a.sort(key=lambda x: x[1], reverse=True)
x = 0
j = 0
for (i, e) in a:
	x += e * j + 1
	j += 1
print(x)
print(' '.join((str(i + 1) for (i, e) in a)))


n = int(input())
tab = list(map(int, input().split()))
n_tab = [None] * n
for i in range(n):
	n_tab[i] = (tab[i], i + 1)
n_tab.sort(reverse=True)
score = 1
path = [0] * n
path[0] = n_tab[0][1]
for i in range(1, n):
	score += n_tab[i][0] * i + 1
	path[i] = n_tab[i][1]
print(score)
print(' '.join(map(str, path)))


n = int(input())
lst = list(map(int, input().split()))
Dict = {}
count = 0
for i in lst:
	if Dict.get(i) == None:
		Dict[i] = []
	Dict[i].append(count)
	count += 1
ans = 0
count = 0
for j in sorted(Dict, reverse=True):
	for k in Dict[j]:
		ans = ans + j * count + 1
		count += 1
print(ans)
for j in sorted(Dict, reverse=True):
	for k in Dict[j]:
		print(k + 1, end=' ')
print()


n = int(input())
a = [*map(int, input().split())]
dct = {}
for i in range(n):
	if a[i] not in dct.keys():
		dct[a[i]] = 1
	else:
		dct[a[i]] += 1
b = sorted(dct.keys(), reverse=True)
idx = []
count = 0
num = 0
for el in b:
	for k in range(n):
		if a[k] == el:
			idx.append(k + 1)
			count += el * num + 1
			num += 1
print(count)
print(*idx)


n = int(input())
arr = list(map(int, input().split()))
ans = []
x = 0
shots = 0
rev = sorted(arr, reverse=True)
for i in rev:
	now_ind = arr.index(i)
	for j in range(0, len(arr)):
		if arr[j] == i and str(j + 1) not in ans:
			now_ind = j
	ans.append(str(now_ind + 1))
	shots += arr[now_ind] * x + 1
	x += 1
print(shots)
print(' '.join(ans))


ln = int(input())
s = str(input())
s = s.split(' ')
l = []
for i in range(ln):
	val = int(s[i])
	l.append((val, i + 1))
l.sort(key=lambda x: x[0], reverse=True)
newl = []
tot = 0
for i in range(len(l)):
	newl.append(l[i][1])
	tot += l[i][0] * i + 1
print(tot)
for i in range(len(newl)):
	print(newl[i], end=' ')


N = int(input())
a = map(int, input().split())
cur = 0
t = enumerate(a)
t = sorted(t, key=lambda x: -x[1])
order = []
for j in range(N):
	(i, v) = t[j]
	cur += j * v + 1
	order.append(i + 1)
print(cur)
print(*order)


n = int(input())
c = list(map(int, input().split()))
shoots = 0
ans = []
dic = {}
ctr = 0
for num in c:
	if num in dic:
		dic[num].append(ctr)
	else:
		dic[num] = [ctr]
	ctr += 1
c.sort()
c.reverse()
for (i, num) in enumerate(c):
	shoots += i * num + 1
	ans.append(dic[num][0] + 1)
	del dic[num][0]
print(shoots)
print(*ans)


n = int(input())
a = list(map(int, input().split()))
used = [False] * n
ans = []
x = 0
shots = 0
for i in range(n):
	for j in range(n):
		if used[j] == False:
			m = j
			break
	for j in range(j + 1, n):
		if used[j] == False and a[m] < a[j]:
			m = j
	ans.append(m + 1)
	used[m] = True
	shots += a[m] * x + 1
	x += 1
print(shots)
for i in range(n):
	print(ans[i], end=' ')


def t2(elem):
	return elem[1]
n = int(input())
a = list(map(int, input().split()))
c = list(enumerate(a))
c.sort(key=t2, reverse=True)
s = 0
for i in range(n):
	s += i * c[i][1] + 1
print(s)
for i in range(n):
	print(c[i][0] + 1, end=' ')


from sys import stdin, stdout
get = stdin.readline
put = stdout.write
(n, a) = (int(get()), list(sorted(enumerate(map(int, get().split())), reverse=True, key=lambda x: x[1])))
put(str(sum((a[i][1] * i + 1 for i in range(n)))) + '\n')
print(*[a[i][0] + 1 for i in range(n)])


l = int(input())
sli = [int(i) for i in input().split(' ')]
li = []
for i in range(len(sli)):
	li.append((i, sli[i]))
li.sort(reverse=True, key=lambda x: x[1])
sum = 0
for i in range(l):
	sum += i * li[i][1] + 1
print(sum)
for i in li:
	print(i[0] + 1, end=' ')


n = int(input())
a = list(map(int, input().split()))
k = sorted(list(enumerate(a)), key=lambda x: x[1])[::-1]
c = 0
ans = 0
d = []
for (i, j) in k:
	ans = ans + j * c
	c = c + 1
	d.append(i + 1)
print(ans + n)
print(*d)


N = int(input())
X = list(map(int, input().split()))
MyDict = dict()
for i in range(N):
	if X[i] not in MyDict.keys():
		MyDict[X[i]] = list()
	MyDict[X[i]].append(i + 1)
X = sorted(X, reverse=True)
Answer = list()
Temp = 0
for i in range(N):
	Answer.append(MyDict[X[i]][-1])
	del MyDict[X[i]][-1]
	Temp += i * X[i] + 1
print(Temp)
print(*Answer)


from operator import itemgetter
n = int(input())
ai = list(map(int, input().split()))
ai2 = [[i + 1, ai[i]] for i in range(n)]
ai2.sort(key=itemgetter(1))
num = 0
ans = 0
for i in range(n - 1, -1, -1):
	ans += ai2[i][1] * num + 1
	num += 1
print(ans)
for i in range(n - 1, -1, -1):
	print(ai2[i][0], end=' ')


n = int(input())
a = list(map(int, input().split()))
t = enumerate(a)
t = sorted(t, key=lambda k: -k[1])
perm = []
shoots = 0
x = 0
for (i, e) in t:
	perm.append(i + 1)
	shoots += e * x + 1
	x += 1
print(shoots)
print(*perm)


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

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
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

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

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

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

def string_list():
	return list(input())

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

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

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def solve():
	n = int(input())
	arr = list_input()
	cost = 0
	pos = {}
	for i in range(n):
		try:
			pos[arr[i]].append(i + 1)
		except KeyError:
			pos[arr[i]] = [i + 1]
	arr.sort(reverse=True)
	prev = 0
	for i in arr:
		cost += prev * i + 1
		prev += 1
	print(cost)
	arr = list(pos.keys())
	arr.sort(reverse=True)
	for i in arr:
		print(*pos[i], end=' ')
t = 1
for _ in range(t):
	solve()


n = int(input())
a = sorted([(int(x), -(i + 1)) for (i, x) in enumerate(input().split())], reverse=True)
val = 0
for i in range(n):
	val += i * a[i][0] + 1
print(val)
print(*[-x[1] for x in a])


n = int(input())
x = list(map(int, input().split()))
y = x.copy()
y.sort(reverse=True)
a = []
ans = 0
for i in range(n):
	ans += y[i] * i + 1
	a.append(x.index(y[i]) + 1)
	x[x.index(y[i])] = 0
print(ans)
print(*a)


import sys
import os
from io import IOBase, BytesIO

def main():
	n = int(input())
	arr = get_array()
	tmp = []
	for i in range(n):
		tmp.append((arr[i], i + 1))
	tmp.sort(reverse=True)
	ans = 0
	x = 0
	for i in range(n):
		ans += tmp[i][0] * x + 1
		x += 1
	print(ans)
	for i in range(n):
		print(tmp[i][1], end=' ')
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		py2 = round(0.5)
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2 == 1:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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 get_array():
	return list(map(int, sys.stdin.readline().split()))

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

def input():
	return sys.stdin.readline().strip()
main()


class value:

	def __init__(self, value, index):
		self.value = value
		self.index = index

	def __cmp__(self, other):
		return self.cmp(self.value, other.value)

	def __lt__(self, other):
		return self.value > other.value
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
	temp = value(a[i], i)
	b.append(temp)
b.sort()
ans = 0
for i in range(n):
	ans += i * b[i].value + 1
print(ans)
for x in b:
	print(x.index + 1, end=' ')
print()


n = int(input())
arr = list(map(lambda x: (int(x[0]), x[1]), zip(input().split(), range(n))))
arr.sort(key=lambda x: x[0], reverse=True)
s = 0
for (i, a) in enumerate(arr):
	s += i * a[0] + 1
print(s)
print(*[a[1] + 1 for a in arr])


n = int(input())
a = list(map(int, input().split()))
ar = []
for i in range(n):
	ar.append([a[i], i])
ar.sort(reverse=True)
ans = [0] * n
an = 0
for i in range(n):
	ans[i] = ar[i][1] + 1
	an = an + ar[i][0] * i + 1
print(an)
print(*ans)


n = int(input())
a = [*map(int, input().split())]
for i in range(n):
	a[i] = [a[i], i]
a.sort(reverse=True)
shot = 0
for i in range(n):
	shot += a[i][0] * i + 1
print(shot)
for i in a:
	print(i[1] + 1, end=' ')


n = int(input())
k = list(map(int, input().split()))
shot = 0
b = []
for m in range(n):
	a = max(k)
	shot += a * m + 1
	b.append(k.index(a) + 1)
	k[k.index(a)] = 0
print(shot)
print(' '.join(map(str, b)))


n = int(input())
a = [int(x) for x in input().split()]
poradie = [i[0] for i in sorted(enumerate(a), key=lambda x: x[1])]
poradie.reverse()
ran = 0
for i in range(n):
	ran = ran + i * a[poradie[i]] + 1
print(ran)
print(' '.join([str(x + 1) for x in poradie]))


def comp(elem):
	return elem[1]
n = int(input())
s = input()
b = s.split(' ')
a = []
for i in range(0, n):
	x = int(b[i])
	t = (i + 1, x)
	a.append(t)
a.sort(reverse=True, key=comp)
kq = 0
for i in range(0, n):
	kq = kq + i * a[i][1] + 1
print(kq)
for i in range(0, n):
	b[i] = str(a[i][0])
delim = ' '
print(delim.join(b))


def func(x):
	return x[0]
n = int(input())
a = [int(i) for i in input().split()]
b = []
for i in range(n):
	b.append([a[i], i + 1])
b = sorted(b, key=func, reverse=True)
c = 0
for i in range(n):
	c += i * b[i][0] + 1
print(c)
for i in b:
	print(i[1], end=' ')
print()


a = int(input())
b = list(map(int, input().split()))
h = 0
g = []
for i in range(a):
	k = -1000000
	l = 0
	for j in range(a):
		if b[j] > k:
			k = b[j]
			l = j
	h += k * i + 1
	g.append(l + 1)
	b[l] = 0
print(h)
print(*g)


n = int(input())
p = list(map(int, input().split()))
i = 0
g = []
f = 0
while i < n:
	k = max(p)
	g.append(p.index(max(p)) + 1)
	p[p.index(max(p))] = -1
	f += k * i + 1
	i += 1
print(f)
for i in g:
	print(i, end=' ')


n = int(input())
s = list(map(int, input().split()))
for i in range(n):
	s[i] = [s[i], i + 1]
s.sort()
s.reverse()
q = 0
w = []
for i in range(n):
	q += s[i][0] * i + 1
	w.append(s[i][1])
print(q)
for i in range(n):
	print(w[i])


n = int(input())
a = list(map(int, input().split()))
d = []
for i in range(n):
	d.append([-a[i], i])
d.sort()
s = 0
for i in range(n):
	s += abs(d[i][0]) * i + 1
print(s)
for i in d:
	print(abs(i[1]) + 1, end=' ')


def read_tokens():
	return input().strip().split(' ')

def read_ints():
	return [int(s) for s in read_tokens()]
(n,) = read_ints()
arr = read_ints()

def solve(arr: list):
	n = len(arr)
	b = []
	for i in range(n):
		b.append((arr[i], i))
	b.sort(reverse=True)
	res = 0
	x = 0
	for i in range(n):
		res += b[i][0] * x + 1
		x = x + 1
	print(res)
	for i in range(n):
		print(b[i][1] + 1, end=' ')
	print()
solve(arr)


n = int(input())
l = list(map(int, input().split()))
l1 = l.copy()
l.sort(reverse=True)
sum = 0
s = 0
l2 = []
for i in range(0, n):
	if i == 0:
		sum += 1
		s += 1
		if l[i] in l1:
			l2.append(l1.index(l[i]) + 1)
			l1[l1.index(l[i])] = -1
	else:
		sum += s * l[i] + 1
		s += 1
		if l[i] in l1:
			l2.append(l1.index(l[i]) + 1)
			l1[l1.index(l[i])] = -1
print(sum)
print(*l2)


n = int(input())
ai = list(map(int, input().rstrip().split()))
count = 0
b = []
for i in range(n):
	pos = ai.index(max(ai))
	b.append(pos + 1)
	count += ai[pos] * i + 1
	ai[pos] = -1
print(int(count))
for j in range(len(b)):
	print(b[j], end=' ')


n = int(input())
l = list(map(int, input().split()))
l2 = [(i, l[i]) for i in range(n)]
l3 = sorted(l2, key=lambda x: x[1])
out = 0
out2 = []
for i in range(n):
	nex = l3.pop()
	out += i * nex[1] + 1
	out2.append(str(nex[0] + 1))
print(out)
print(' '.join(out2))


import heapq
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
h = []
for i in range(n):
	heapq.heappush(h, (-a[i], i))
ans = 0
j = 0
p = [0] * n
while h:
	(ai, i) = heapq.heappop(h)
	ans -= j * ai - 1
	p[j] = i + 1
	j += 1
print(ans)
print(*p)


n = int(input())
l = [int(x) for x in input().split(' ')]
order = []
x = 0
shots = 0
while len(order) != len(l):
	m = max(l)
	i = l.index(m)
	if i + 1 not in order:
		shots += l[i] * x + 1
		x = x + 1
		order.append(i + 1)
		l[i] = 0
print(shots)
for i in range(len(order)):
	print(order[i], end=' ')


n = int(input())
quti = list(map(int, input().split()))
sor = []
sor = sorted(quti, reverse=True)
Sum = 0
for (i, val) in enumerate(sor):
	Sum += val * i + 1
	for j in range(n):
		if sor[i] is quti[j]:
			sor[i] = j + 1
			quti[j] = -1
print(Sum)
print(*sor, sep=' ')


n = int(input())
a = list(map(int, input().split()))
idx = list(range(n))
(a, idx) = zip(*sorted(zip(a, idx)))
r = 0
for i in range(n - 1, -1, -1):
	r += a[i] * (n - 1 - i) + 1
print(r)
for i in range(n - 1, -1, -1):
	print(idx[i] + 1, end=' ')


n = int(input())
l = list(map(int, input().split()))
l2 = list(sorted(set(l), reverse=True))
l1 = []
for i in l2:
	for (j, k) in enumerate(l):
		if k == i:
			l1.append(j + 1)
count = 0
add = 0
for i in range(n):
	add += max(l) * count + 1
	l.remove(max(l))
	count += 1
print(add)
print(*l1)


n = int(input())
l = list(map(int, input().split()))
order = []
power = []
for i in range(n):
	k = max(l)
	power.append(k * i + 1)
	order.append(l.index(max(l)) + 1)
	l[l.index(max(l))] = -100
print(sum(power))
for i in order:
	print(i, end=' ')


from sys import stdin

def check_valid(string):
	stack = []
	for i in string:
		if i in ['(', '[']:
			stack.append(i)
		elif i == ')':
			if len(stack) > 0:
				if stack[-1] == '(':
					stack.pop()
					continue
			return False
		elif i == ']':
			if len(stack) > 0:
				if stack[-1] == '[':
					stack.pop()
					continue
			return False
	return len(stack) == 0

def merge(index):
	aux = []
	if len(index) > 0:
		aux = [index[0]]
		for i in range(1, len(index)):
			if index[i][0] == aux[-1][1] + 1:
				aux[-1][1] = index[i][1]
			elif check_valid(string[aux[-1][1] + 1:index[i][0]]):
				aux[-1][1] = index[i][1]
			else:
				aux.append(index[i])
	return aux
n = int(stdin.readline().strip())
arr = []
arr = list(map(int, stdin.readline().split()))
for i in range(n):
	arr[i] = [i, arr[i]]
arr.sort(key=lambda x: x[1], reverse=True)
count = 0
ans = []
total = 0
for i in range(n):
	(index, a) = arr[i]
	ans.append(index + 1)
	total += count * a + 1
	count += 1
print(total)
print(*ans)


def main():
	n = int(input())
	tab = list(map(int, input().split()))
	ntab = []
	for x in range(n):
		ntab.append((tab[x], x))
	ntab.sort(key=lambda x: x[0])
	ntab.reverse()
	m = 0
	for x in range(n):
		m += ntab[x][0] * x + 1
	print(m)
	for x in range(n):
		print(ntab[x][1] + 1, end=' ')
	print()
main()


n = int(input())
arr = list(map(int, input().split()))
pos = []
for i in range(n):
	pos.append(i + 1)
for i in range(n):
	for j in range(n - i - 1):
		if arr[j] < arr[j + 1]:
			temp = arr[j]
			arr[j] = arr[j + 1]
			arr[j + 1] = temp
			temp = pos[j]
			pos[j] = pos[j + 1]
			pos[j + 1] = temp
count = 0
for i in range(n):
	count += 1 + arr[i] * i
print(count)
for i in pos:
	print(i, end=' ')


n = int(input())
a = map(int, input().split())
a = [(i, ai) for (i, ai) in enumerate(a)]
a = sorted(a, key=lambda x: x[1], reverse=True)
x = 0
sum = 0
l = []
for (i, ai) in a:
	sum += ai * x + 1
	x += 1
	l.append(str(i + 1))
print(sum)
print(' '.join(l))


import operator
n = int(input())
cans = [int(x) for x in input().split()]
Hash = dict()
for e in range(0, len(cans)):
	Hash[e + 1] = cans[e]
s = sorted(Hash.items(), key=operator.itemgetter(1))[::-1]
total = 0
way = []
for i in range(0, len(s)):
	total += s[i][1] * i + 1
	way.append(s[i][0])
print(total)
print(*way)


from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest
from math import ceil, floor, log, log2, sqrt, gcd, factorial

def binNumber(n, size=1):
	return bin(n)[2:].zfill(size)

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

def ini():
	return int(input())

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

def instr():
	return str(input())
n = ini()
a = inar()
c = 1
arr = []
for x in a:
	arr.append([x, c])
	c += 1
arr.sort()
arr.reverse()
ans = 0
c = 0
for x in arr:
	ans += x[0] * c + 1
	c += 1
print(ans)
for x in arr:
	print(x[1], end=' ')


import sys, math, queue
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)
n = int(input())
a = list(map(int, input().split()))
a = sorted(enumerate(a), key=lambda x: x[1], reverse=True)
ans = 0
for i in range(n):
	ans += a[i][1] * i + 1
print(ans)
for ai in a:
	print(ai[0] + 1, end=' ')
print()


def quick_sort(_list, low, high):
	if low >= high:
		return
	left = low
	right = high
	pivot = _list[left][0]
	index = _list[left][1]
	while left < right:
		while left < right and _list[right][0] <= pivot:
			right -= 1
		_list[left] = _list[right]
		while left < right and _list[left][0] >= pivot:
			left += 1
		_list[right] = _list[left]
	_list[right] = (pivot, index)
	quick_sort(_list, low, left - 1)
	quick_sort(_list, left + 1, high)
I = input
num = int(I())
cans = list(map(int, I().split()))
result = 0
k = 0
for i in sorted(cans, reverse=True):
	result += i * k + 1
	k += 1
print(result)
for i in range(len(cans)):
	cans[i] = (cans[i], i + 1)
quick_sort(cans, 0, len(cans) - 1)
for i in cans:
	print(i[1], end=' ')


n = int(input())
l1 = list(map(int, input().split()))
l3 = l1.copy()
l2 = []
for i in range(len(l1)):
	a = l1.index(max(l1))
	l2.append(a + 1)
	l1[a] = 0
count = 0
for j in range(len(l2)):
	count = count + l3[l2[j] - 1] * j + 1
print(count)
print(*l2)


n = int(input())
a = [int(s) for s in input().split()]
b = []
k = 0
q = max(a)
i = 0
w = 0
while q != 0:
	for i in range(n):
		if a[i] == q:
			j = i
			a[i] = 0
			break
	k += q * w + 1
	w += 1
	b.append(j + 1)
	q = max(a)
print(k)
print(*b)


import sys
n = int(input())
s = [*map(int, input().split())]
k = []
su = 0
for i in range(n):
	k.append([0] * 2)
	k[i][0] = s[i]
	k[i][1] = i + 1
k = sorted(k, reverse=True)
for i in range(n):
	su += i * k[i][0] + 1
print(su)
for i in range(n):
	sys.stdout.write(str(k[i][1]) + ' ')


T = int(input())
t = input().split()
for x in range(T):
	t[x] = (int(t[x]), x + 1)
t.sort()
t.reverse()
i = 0
o = []
for x in range(T):
	i = i + x * t[x][0] + 1
print(i)
for x in range(T):
	print(t[x][1], end=' ')


n = int(input())
l = list(map(int, input().split()))
l1 = l.copy()
l
l2 = [0] * n
ans = 0
for i in range(n):
	a = l[i]
	l2[i] = i
	for j in range(n):
		if l[j] > a:
			a = l[j]
			l2[i] = j
	l[l2[i]] = 0
for i in range(n):
	x = l2[i]
	ans += i * l1[x] + 1
print(ans)
for i in l2:
	print(i + 1, end=' ')
print()


t = int(input())
s = list(map(int, input().split()))
s1 = []
for i in range(len(s)):
	s1.append((s[i], i + 1))
s1 = sorted(s1, reverse=True)
res = 0
for i in range(len(s1)):
	res += i * s1[i][0] + 1
print(res)
print(' '.join([str(i[1]) for i in s1]))


n = int(input())
x = list(map(int, input().split()))
m = 0
p = []
s = 0
q = x.copy()
x.sort()
x.reverse()
y = x.copy()
for i in range(0, len(y)):
	s = y[i] * m + 1 + s
	m += 1
for i in range(0, len(q)):
	r = q.index(y[i])
	q[r] = 0
	p.append(r + 1)
print(s)
print(*p)


n = int(input())
arr = [int(i) for i in input().split()]
counter = 0
ans = []
ReversedArr = sorted(arr)
ReversedArr.reverse()
for i in range(n - 1):
	sec = [[arr[k], k] for k in range(n)]
	sec.sort(reverse=True)
	counter += ReversedArr[i + 1] * (i + 1)
counter = counter + n
print(counter)
for i in range(n):
	print(sec[i][1] + 1, end=' ')


from collections import deque
n = int(input())
a = [int(x) for x in input().split()]
sr = deque()
for i in sorted(a, reverse=True):
	sr.append(i)
ind = []
x = 0
ans = 0
while sr:
	i = sr.popleft()
	ix = a.index(i)
	ind.append(ix)
	ans += i * x + 1
	a[ix] = -1
	x += 1
print(ans)
print(' '.join([str(x + 1) for x in ind]))


n = int(input())
l = list(map(int, input().split()))
sorted_ = l.copy()
sorted_.sort(reverse=True)
lf = []
shots = 0
down = 0
for i in range(n):
	lf.append(l.index(sorted_[i]) + 1)
	l[l.index(sorted_[i])] = 0
	shots += down * sorted_[i] + 1
	down += 1
print(shots)
print(*lf, sep=' ')


n = int(input())
arr = list(map(int, input().split()))
brr = [[arr[i], i + 1] for i in range(n)]
brr.sort(reverse=True)
(ans, cost) = ([0] * n, 0)
for i in range(n):
	cost += brr[i][0] * i + 1
	ans[i] = brr[i][1]
print(cost)
print(*ans)


def main():
	input()
	a = list(map(int, input().split()))
	a = list(enumerate(a))
	a.sort(key=lambda x: -x[1])
	res = 0
	c = 0
	for (_, x) in a:
		res += x * c + 1
		c += 1
	print(res)
	print(' '.join([str(x + 1) for (x, _) in a]))
main()


import collections
n = int(input())
a = [int(i) for i in input().split()]
b = sorted(a, reverse=True)
count = 0
ans = []
for i in range(0, n):
	count += b[i] * i + 1
	for j in range(0, n):
		if a[j] == b[i]:
			ans.append(j + 1)
			a[j] = 0
print(count)
print(*ans, sep=' ')


n = int(input())
a = list(map(int, input().split()))
poredan = []
for i in range(len(a)):
	tmp = []
	tmp.append(a[i])
	tmp.append(i + 1)
	poredan.append(tmp)
poredan.sort(reverse=True)
metak = 0
lista = []
for i in range(len(poredan)):
	metak += poredan[i][0] * i + 1
	lista.append(poredan[i][1])
print(metak)
print(*lista)


mem = {}
n = int(input())
arr = list(map(int, input().split()))
for i in range(n):
	if arr[i] in mem:
		mem[arr[i]].append(i + 1)
	else:
		mem[arr[i]] = [i + 1]
arr.sort(reverse=True)
j = 0
ans = 0
for i in range(n):
	ans += arr[i] * j + 1
	j += 1
print(ans)
i = 0
while i < n:
	p = len(mem[arr[i]])
	for j in mem[arr[i]]:
		print(j, end=' ')
	i += p
print()


n = int(input())
A = list(map(int, input().split()))
B = [A[i] for i in range(0, n)]
B.sort(reverse=True)
ans = 0
a = []
p = [0 for i in range(n + 1)]
for i in range(0, n):
	ans += B[i] * i + 1
	for j in range(n):
		if B[i] == A[j] and p[j] == 0:
			a.append(j + 1)
			p[j] = 1
			break
print(ans)
print(*a)


n = int(input())
l = []
arr = list(map(int, input().split()))
for i in range(n):
	l.append((arr[i], i + 1))
l.sort(reverse=True)
x = 0
ans = 0
for i in range(0, n):
	ans += l[i][0] * x + 1
	x += 1
print(ans)
for i in range(n):
	print(l[i][1], end=' ')


_ = input()
a = map(int, input().split())

def indexes(l):
	res = {}
	for (index, element) in enumerate(l):
		if element in res.keys():
			res[element].append(index)
		else:
			res[element] = [index]
	return res
a = indexes(a)
ans_num = 0
ans_list = []
x = 0
for key in reversed(sorted(a.keys())):
	for index in a[key]:
		ans_num += x * key + 1
		x += 1
		ans_list.append(index + 1)
print(ans_num)
print(*ans_list)


import math
import sys
input = sys.stdin.readline

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

def invr():
	return list(map(int, input().split()))
n = inp()
a = invr()
b = [0] * len(a)
c = [0] * (max(a) + 1)
ii = [0] * len(a)
for e in a:
	c[e] += 1
for i in range(1, len(c)):
	c[i] += c[i - 1]
i = len(a)
for e in a[::-1]:
	b[c[e] - 1] = e
	ii[c[e] - 1] = str(i)
	c[e] -= 1
	i -= 1
ii.reverse()
b.reverse()
x = 0
cc = 0
for e in b:
	cc += 1 + e * x
	x += 1
print(cc)
print(' '.join(ii))


n = int(input())
li = list(map(int, input().split()))
new = sorted(li, reverse=True)
res = []
cost = 0
for i in range(len(new)):
	cost += new[i] * i + 1
	res.append(li.index(new[i]) + 1)
	li[li.index(new[i])] = -1
print(cost)
for i in res:
	print(i, end=' ')


n = int(input())
l = list(map(int, input().split()))
c = l.copy()
c.sort()
c.reverse()
s = 0
for i in range(len(c)):
	s += c[i] * i + 1
print(s)
t = []
for i in c:
	t.append(l.index(i) + 1)
	l[l.index(i)] = -1
print(*(i for i in t))


from collections import defaultdict

def get_seq(cans):
	indices = defaultdict(list)
	for (idx, el) in enumerate(cans):
		indices[el].append(idx + 1)
	cans = sorted(cans)[::-1]
	count = 0
	for i in range(len(cans)):
		count += i * cans[i] + 1
	cans = list(set(cans))
	seq = []
	for can in cans:
		seq += indices[can]
	return (count, seq)
input()
a = input()
a = [int(q) for q in a.split(' ')]
(w1, w2) = get_seq(a)
w2 = [str(q) for q in w2]
print(w1)
print(' '.join(w2))


n = int(input())
ws = list(map(int, input().split()))
nums = list(range(1, n + 1))
tot_ws = dict(list(zip(nums, ws)))
tot_ws = dict(sorted(tot_ws.items(), key=lambda x: x[1], reverse=True))
nms = list(tot_ws.keys())
ws = list(sorted(ws, reverse=True))
s = 0
x = 0
for el in ws:
	s += el * x + 1
	x += 1
print(s)
for el in nms:
	print(el, end=' ')


def partition(arr, arrindex, low, high):
	i = low - 1
	pivot = arr[high]
	for j in range(low, high):
		if arr[j] >= pivot:
			i = i + 1
			(arr[i], arr[j]) = (arr[j], arr[i])
			(arrindex[i], arrindex[j]) = (arrindex[j], arrindex[i])
	(arr[i + 1], arr[high]) = (arr[high], arr[i + 1])
	(arrindex[i + 1], arrindex[high]) = (arrindex[high], arrindex[i + 1])
	return i + 1

def quickSort(arr, arrindex, low, high):
	if low < high:
		pi = partition(arr, arrindex, low, high)
		quickSort(arr, arrindex, low, pi - 1)
		quickSort(arr, arrindex, pi + 1, high)
qntdlatas = int(input())
lista = [int(x) for x in input().split()]
listaindices = [k for k in range(qntdlatas)]
quickSort(lista, listaindices, 0, qntdlatas - 1)
somatotal = 0
contador = 0
stringfinal = ''
for k in range(qntdlatas):
	if k == qntdlatas - 1:
		somatotal += contador * lista[k] + 1
		stringfinal += str(listaindices[k] + 1)
	else:
		somatotal += contador * lista[k] + 1
		stringfinal += str(listaindices[k] + 1)
		stringfinal += ' '
	contador += 1
print(somatotal)
print(stringfinal)


n = int(input())
seq = list(map(int, input().split()))
remaining = n
total = 0
count = 0
fallSeq = []
while remaining > 0:
	maxCan = max(seq)
	Canindex = seq.index(maxCan)
	seq[Canindex] = -1
	penalty = maxCan * count + 1
	total += penalty
	fallSeq.append(Canindex + 1)
	count += 1
	remaining -= 1
print(total)
print(' '.join([str(x) for x in fallSeq]))


n = int(input())
A = list(map(int, input().split()))
tot = 0
ordine = ''
a = 0
while a < len(A):
	bm = 0
	tm = 0
	c = -1
	x = 0
	while x < len(A):
		if c == -1 or A[x] > A[c]:
			c = x
		x += 1
	ordine += str(c + 1) + ' '
	tot += a * A[c] + 1
	A[c] = 0
	a += 1
print(tot)
print(ordine)


n = int(input())
l = list(map(int, input().split()))
m = []
for i in range(len(l)):
	m.append(i)
(l, m) = zip(*sorted(zip(l, m), reverse=True))
x = 0
ct = 0
k = []
for i in range(len(l)):
	ct = ct + (l[i] * x + 1)
	x = x + 1
	k.append(m[i] + 1)
print(ct)
print(*k)


n = int(input())
arr = list(map(int, input().split()))
sarr = []
for i in range(len(arr)):
	sarr.append((arr[i], i + 1))
sarr.sort(reverse=True)
out = 0
for e in range(len(sarr)):
	out += sarr[e][0] * e + 1
print(out)
print(' '.join((str(x[1]) for x in sarr)))


(n, a) = (int(input()), list(map(int, input().split())))
dict1 = {i + 1: a[i] for i in range(len(a))}
l = list(a)
l.sort()
l.reverse()
x = ''
knocks = 0
for i in l:
	x += str(a.index(i) + 1) + ' '
	a[a.index(i)] = 'm'
for i in range(n):
	knocks += l[i] * i + 1
print(knocks)
print(x)


n = int(input())
strength = input().split()
x = 0
all = 0
pop = []
for i in range(len(strength)):
	strength[i] = int(strength[i])
strength_sup = strength.copy()
strength.sort()
strength.reverse()
for ai in strength:
	pop.append(str(strength_sup.index(ai) + 1))
	strength_sup[strength_sup.index(ai)] = 'none'
	all_local = ai * x + 1
	x += 1
	all += all_local
print(all)
print(' '.join(pop))


n = int(input())
dur = list(map(int, input().split()))
dur2 = []
for (i, d) in enumerate(dur):
	dur2.append((d, i))
dur2.sort()

def shotsNeeded(dur, cans_down):
	return dur * cans_down + 1
shots = 0
cans_down = 0
order_down = []
for i in range(n - 1, -1, -1):
	shots += shotsNeeded(dur2[i][0], cans_down)
	cans_down += 1
	order_down.append(dur2[i][1] + 1)
print(shots)
for i in range(len(order_down) - 1):
	print(order_down[i], end=' ')
print(order_down[len(order_down) - 1], end='')


n = int(input())
l = list(map(int, input().split()))
c = 1
d = {i + 1: l[i] for i in range(n)}
k = sorted(d.items(), key=lambda x: x[1], reverse=True)
for i in range(1, n):
	c += k[i][1] * i + 1
print(c)
for i in range(n):
	print(k[i][0], end=' ')


n = int(input())
a = [int(ele) for ele in input().split()]
i = 0
sum = 0
sol = []
b = a.copy()
b.sort()
b.reverse()
for ele in b:
	sum += ele * i + 1
	i += 1
	ind = a.index(ele)
	sol.append(ind + 1)
	a[ind] = -1
print(sum)
for ele in sol:
	print(ele, end=' ')


n = int(input())
arr = [int(x) for x in input().split()]
x = []
for i in range(n):
	x.append([arr[i], i])
x.sort(reverse=True)
arr.sort(reverse=True)
ans = 1
for i in range(1, n):
	ans += arr[i] * i + 1
print(ans)
for i in range(n):
	print(x[i][1] + 1, end=' ')


n = int(input())
vetor = list(map(int, input().split()))
vetorinal = vetor.copy()
preco = []
latas = []
x = 0
maior = max(vetor)
zas = vetor.index(maior)
vetor.remove(maior)
vetorinal.insert(zas, 0)
vetorinal.remove(vetorinal[zas + 1])
x += 1
total = 1
latas.append(str(zas + 1) + ' ')
for j in range(len(vetor)):
	for i in range(len(vetor)):
		preco.append(vetor[i] * x + 1)
	x += 1
	maiorPreco = max(preco)
	total += maiorPreco
	index = preco.index(maiorPreco)
	zas = vetorinal.index(vetor[index])
	vetorinal.insert(zas, 0)
	vetorinal.remove(vetorinal[zas + 1])
	latas.append(str(zas + 1) + ' ')
	vetor.remove(vetor[index])
	preco = []
seq = str(''.join(latas))
print(total)
print(seq)


n = int(input())
arr = list(map(int, input().split()))
l = sorted([[arr[i], i] for i in range(n)], reverse=True, key=lambda x: x[0])
ans = 0
ans2 = []
for i in range(n):
	(a, b) = l[i]
	ans2.append(b + 1)
	ans += i * a + 1
print(ans)
print(*ans2)


n = int(input())
arr = list(map(int, input().split()))
arr2 = arr.copy()
arr.sort()
arr.reverse()
count = 0
c = []
for i in range(n):
	count = i * arr[i] + 1 + count
print(count)
for i in arr:
	c.append(arr2.index(i))
	arr2[arr2.index(i)] = 0
for i in range(n):
	print(c[i] + 1, end=' ')


n = int(input())
dic = {i: x for (i, x) in zip(range(1, n + 1), map(int, input().split()))}
s_dic = {k: v for (k, v) in sorted(dic.items(), key=lambda item: item[1], reverse=True)}
i = 0
sum = 0
for x in s_dic:
	one = s_dic[x] * i + 1
	i += 1
	sum = sum + one
print(sum)
for x in s_dic:
	print(x, end=' ')


n = int(input())
a = [int(i) for i in input().split()]
copy_of_the_a = a.copy()
positions = []
copy_of_the_a.sort(reverse=True)
total_shots = 0
x = 0
for (ind, a_i) in enumerate(copy_of_the_a):
	total_shots += a_i * x + 1
	x += 1
	positions.append(a.index(a_i) + 1)
	a[a.index(a_i)] = float('inf')
print(total_shots)
print(*positions)


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	cans = []
	for i in range(n):
		cans.append((arr[i], i + 1))
	cans.sort(reverse=True)
	cost = 0
	for i in range(n):
		cost += cans[i][0] * i
		cost += 1
	print(cost)
	for i in cans:
		print(i[1], end=' ')
main()


n = int(input())
arr = list(map(int, input().split()))
count = 0
summ = 0
ans = []
for i in range(n):
	arr[i] = [arr[i], i]
arr.sort(reverse=True)
for i in range(n):
	summ += count * arr[i][0] + 1
	count += 1
	ans.append(arr[i][1] + 1)
print(summ)
print(*ans)


n = int(input())
l = list(map(int, input().split()))
l1 = sorted(l)
l1 = l1[::-1]
cnt = 0
x = 0
z = []
for i in l1:
	k = l.index(i)
	l[k] = 0
	cnt = cnt + i * x + 1
	x += 1
	z.append(k)
print(cnt)
for i in z:
	print(i + 1, end=' ')