/**
 * Created by IntelliJ IDEA.
 * User: m09cke
 * Date: 18.11.2009
 * Time: 17:07:50
 * To change this template use File | Settings | File Templates.
 */
import java.lang.*;
import java.io.*;
import java.util.Arrays;
import java.util.Scanner;
import java.util.ArrayList;

public class Main implements Runnable{

    class Cab implements Comparable<Cab>{
           int n;
           int r;
           Cab(int a, int b){
               n = a;
               r = b;
           }
           public int getN(){
               return(n);
           }
           public int getR(){
               return(r);
           }
           public int compareTo(Cab a){
               return(r-a.r);
           }
       }

   public void run(){
       try{
           StreamTokenizer in = new StreamTokenizer( new BufferedReader( new FileReader( new File( "salesman.in"))));
           PrintStream out = new PrintStream(new File("salesman.out"));
           in.nextToken();
           int n = (int)in.nval;
           int sum = 0;
           Cab[] a = new Cab[n];
           for (int i=0; i<n; i++){
               in.nextToken();
               a[i] = new Cab(i+1,(int)in.nval);
               sum = sum + a[i].r;
           }
           Arrays.sort(a);
           for (int i=0; i<n-2; i++){
               sum = sum + a[i].r;
           }
           int[] mas = new int[n];
           for (int i=0; i<n; i++){
               mas[i]=a[i].n;
               //Cab t = a[i];
               //a[i] = a[(i+1)%n];
               //a[(i+1)%n] = t;
           }
           out.println(sum);
           for (int i=0; i<n; i++){
               out.print(mas[(i-1+n)%n]+" ");
           }
       }
       catch(Exception e){
           e.printStackTrace();
           System.exit(1);
       }
   }

   public static void main(String[] args){
       new Thread(new Main()).start();
   }

}