#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
vector<pair<int, int> > vp;
for (int i = 0; i < n; ++i) {
vp.push_back(make_pair(a[i], i));
}
sort(vp.begin(), vp.end());
int x=0;
int sum=0;
sort(a,a+n, greater<int>());
for(int i=0;i<n;i++){
sum+=a[i]*x+1;
x++;
}
cout<<sum<<endl;
for(int i=n-1;i>=0;i--){
cout<<vp[i].second+1<<" ";
}
// your code goes here
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbGwgbG9uZyBsb25nCmludCBtYWluKCkgewoJaW50IG47CgljaW4+Pm47CglpbnQgYVtuXTsKCWZvcihpbnQgaT0wO2k8bjtpKyspewoJCWNpbj4+YVtpXTsKCX0KCXZlY3RvcjxwYWlyPGludCwgaW50PiA+IHZwOyAKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7IAogICAgICAgIHZwLnB1c2hfYmFjayhtYWtlX3BhaXIoYVtpXSwgaSkpOyAKICAgIH0gCiAgICBzb3J0KHZwLmJlZ2luKCksIHZwLmVuZCgpKTsKCWludCB4PTA7CglpbnQgc3VtPTA7Cglzb3J0KGEsYStuLCBncmVhdGVyPGludD4oKSk7Cglmb3IoaW50IGk9MDtpPG47aSsrKXsKCQlzdW0rPWFbaV0qeCsxOwoJCXgrKzsKCX0KCWNvdXQ8PHN1bTw8ZW5kbDsKCWZvcihpbnQgaT1uLTE7aT49MDtpLS0pewoJCWNvdXQ8PHZwW2ldLnNlY29uZCsxPDwiICI7Cgl9CgkvLyB5b3VyIGNvZGUgZ29lcyBoZXJlCglyZXR1cm4gMDsKfQ==