#include<bits/stdc++.h>
#define hell                         1000000007
#define M                            1000000007
#define Maxi                      10000000000000000
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long

#define vll                          vector<ll>
#define vi                           vector<long long>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
//#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
#define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define dbg(x)                       cout << #x << " is " << x << endl;
#define endl                           '\n'
 //const ll infl=0x3f3f3f3f3f3f3f3fLL;

 #define pi                           3.141592653589793238
// Debug //

#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

using namespace std;
ll prime[1000006];
ll k;
void fun()
{
  for(ll i=2;i<=1000000;i++)
  {
    if(prime[i]==0)
    {
      for(ll j=i;j<=1000000;j+=i)
      {
        if(prime[j]==0)
        prime[j]=i;
      }
    }
  }
}

// bool divisors(long long n)
// {
//     long long i;
//     vector<ll>v;
//     for(i=2;i*i<=n;i++)
//     {
//         if(n%i==0)
//         {
//             if(n/i==i)
//                 v.pb(i);
//             else
//             {
//                 v.pb(i);
//                 v.pb(n/i);
//             }
//         }
//     }
//     ll x=v.size();
//     if(x==0)
//         return true;
//     else
//         return false;
// }

// ll fact(ll n)
// {
//     ll i,p=1;
//     for(i=1;i<=n;i++)
//     {
//         p*=i;
//         p%=hell;
//     }
//     return p;
// }

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll n,i;
    cin>>n;
    vector<pair<ll,ll>>v;
    for(i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        v.pb({x,i});
    }
    sort(all(v));
    reverse(all(v));
    ll ans[n];
    for(i=0;i<n;i++)
    {
        ll pos=v[i].S;
        ans[pos]=i+1;
    }
    for(int i:ans)
    {
        cout<<i<<" ";
    }
    cout<<endl;
}


#include <iostream>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iomanip>
#include <cmath>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define endl '\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    vector <pair<int,int> >v;
    f(i,0,n){
        int x;
        cin>>x;
        v.pb(mp(x,i));
    }
    sort(v.begin(),v.end());
    int ans;
    f(i,0,v.size()){
        ans = ans+(v[n-i-1].first*i)+1;
    }
    cout<<ans<<endl;
    f(i,0,n){
        cout<<v[i].second+1<<spc;
    }
    cout<<endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iomanip>
#include <cmath>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define endl '\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    vector <pair<int,int> >v;
    f(i,0,n){
        int x;
        cin>>x;
        v.pb(mp(x,i));
    }
    sort(v.begin(),v.end());
    int ans=0;
    f(i,0,v.size()){
        ans = ans+v[n-i-1].first*i+1;
    }
    cout<<ans<<endl;
    f(i,0,n){
        cout<<v[n-i-1].second+1<<spc;
    }
    cout<<endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iomanip>
#include <cmath>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define endl '\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    vector <pair<int,int> >v;
    f(i,0,n){
        int x;
        cin>>x;
        v.pb(mp(x,i));
    }
    int ans=0;
    sort(v.begin(),v.end());
    f(i,0,n){
        ans = ans+v[i].first*(n-i-1)+1;
    }
    cout<<ans<<endl;
    f(i,0,n){
        cout<<v[n-i-1].second+1<<spc;
    }
    cout<<endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iomanip>
#include <cmath>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define endl '\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    vector <pair<int,int> >v;
    f(i,0,n){
        int x;
        cin>>x;
        v.pb(mp(x,i));
    }
    sort(v.begin(),v.end());
    int ans;
    f(i,0,v.size()){
        ans = ans+v[n-i-1].first*i+1;
    }
    cout<<ans<<endl;
    f(i,0,n){
        cout<<v[n-i-1].second+1<<spc;
    }
    cout<<endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iomanip>
#include <cmath>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define endl '\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    vector <pair<int,int> >v;
    f(i,0,n){
        int x;
        cin>>x;
        v.pb(mp(x,i));
    }
    sort(v.begin(),v.end());
    int ans;
    f(i,0,v.size()){
        ans = ans+v[n-i-1].first*i+1;
    }
    cout<<ans<<endl;
    f(i,0,n){
        cout<<v[i].second+1<<spc;
    }
    cout<<endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iomanip>
#include <cmath>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define endl '\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    vector <pair<int,int> >v;
    f(i,0,n){
        int x;
        cin>>x;
        v.pb(mp(x,i));
    }
    sort(v.begin(),v.end());
    int ans=0;
    f(i,0,v.size()){
        ans = ans+v[n-i-1].first*i+1;
    }
    cout<<ans<<endl;
    f(i,0,n){
        cout<<v[i].second+1<<spc;
    }
    cout<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{  int n,ans=1;
     cin>>n;
     vector<pair<int,int> >v(n);
     vector<pair<int,int> >a(n);
     for(int i=0;i<n;i++){
     cin>>v[i].first; v[i].second=i;
     }
    sort(v.begin(),v.end());
    int k=1;
    for(int i=n-2;i>=0;i--)
       {

        ans+=v[i].first*k+1; k++;}
  cout<<ans<<"\n";
   for(int i=n-1;i>=0;i--)
   {
       cout<<v[i].second+1<<" ";
   }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{  int n,ans=1;
     cin>>n;
     vector<pair<int,int> >v(n);
     vector<pair<int,int> >a(n);
     for(int i=0;i<n;i++){
     cin>>v[i].first; v[i].second=i;
     }
    sort(v.begin(),v.end());
    int k=1;
    for(int i=n-2;i>=0;i--)
       {
          // cout<<ans<<" "<<v[i].first<<endl;
        ans+=v[i].first*k+1; k++;}
    for(int i=0;i<n;i++)
    {
       a[i].first=v[i].second;
       a[i].second=i;
    }
   cout<<ans<<endl;
   sort(a.begin(),a.end());
   for(int i=0;i<n;i++)
   {
       cout<<a[i].second+1<<" ";
   }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{  int n,ans=1;
     cin>>n;
     vector<pair<int,int> >v(n);
     vector<pair<int,int> >a(n);
     for(int i=0;i<n;i++){
     cin>>v[i].first; v[i].second=i;
     }
    sort(v.begin(),v.end());
    int k=1;
    for(int i=n-2;i>=0;i--)
       {
          // cout<<ans<<" "<<v[i].first<<endl;
        ans+=v[i].first*k+1; k++;}
  cout<<ans<<"\n";
   for(int i=n-1;i>=0;i--)
   {
       cout<<v[i].second+1<<" ";
   }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{  int n,ans=1;
     cin>>n;
     vector<pair<int,int> >v(n);
     vector<pair<int,int> >a(n);
     for(int i=0;i<n;i++){
     cin>>v[i].first; v[i].second=i;
     }
    sort(v.begin(),v.end());
    int k=1;
    for(int i=n-2;i>=0;i--)
       {
          // cout<<ans<<" "<<v[i].first<<endl;
        ans+=v[i].first*k+1; k++;}
        k=n-1;
    for(int i=0;i<n;i++)
    {
       a[i].first=v[i].second;
       a[i].second=k;k--;
    }
   cout<<ans<<endl;
   sort(a.begin(),a.end());
   for(int i=0;i<n;i++)
   {
       cout<<a[i].second+1<<" ";
   }
}


#include <bits/stdc++.h>
using namespace std;

    const int maxn = 1e3 + 5;
    pair<int, int> a[maxn];
    int ans = 0, n;

    int main(){
    	cin >> n;
    	for (int i = 0; i < n; i++)
    	{
    		int x;
    		cin >> x;
    		a[i] = {x, i};
    	}
    	sort(a, a + n);
    	reverse(a, a + n);
    	for (int i = 0; i < n; i++)
    		ans += i * (a[i].first) + 1;

    	cout << ans << endl;

    	for (int i = 0; i < n; i++)
    		cout << (a[i].second) + 1 << " ";
    }


#include <bits/stdc++.h>

using namespace std;

#define IoFast ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long int
#define float long double
#define foor(i, a, b) for ( int (i) = (a); (i)<(b); (i)++ )
#define foor2(i, a, b) for( int (i) = (a); (i)>(b); (i)-- )
#define foorl(i, a, b) for ( ll (i) = (a); (i)<(b); (i)++ )
#define foorl2(i, a, b) for( ll (i) = (a); (i)>(b); (i)-- )
#define mp make_pair
#define f1 first
#define f2 second
#define pb push_back
#define pii pair<int,int>
#define vpii vector <pii>
#define vi vector<int>
#define sz(a) (int) a.size( )
#define fillArr(n, a) foor(i, 0, n) cin >> a[i];
#define print(a) cout << #a << endl;
#define umax(a,b) a = max ( a, b )
#define umin(a,b) a = min ( a, b )
#define all(k) k.begin ( ), k.end( )
#define rall(k) k.rbegin ( ), k.rend( )
#define clean(k) memset( k, 0, sizeof(k) )
#define endl '\n'

const int maxn = 1020;
pair<int, int> a[maxn];
int ans = 0, n;

int main(){
	IoFast;
	cin >> n;
	foor (i, 0, n){
		int x;
		cin >> x;
		a[i] = {x, i};
	}

	sort(a, a + n);
	reverse(a, a + n);

	foor(i, 0, n)
		ans += i * (a[i].f1) + 1;

	cout << ans << endl;

	foor (i, 0, n)
		cout << a[i].f2 + 1 << " ";
	cout << endl;
}


const int maxn = 1e3 + 5;
pair<int, int> a[maxn];
int ans = 0, n;

int main(){
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		a[i] = {x, i};
	}
	sort(a, a + n);
	reverse(a, a + n);
	for (int i = 0; i < n; i++)
		ans += i * (a[i].first) + 1;

	cout << ans << endl;

	for (int i = 0; i < n; i++)
		cout << (a[i].second) + 1 << " ";
}


#inlcude <bits/stdc++.h>
using namespace std;

    const int maxn = 1e3 + 5;
    pair<int, int> a[maxn];
    int ans = 0, n;

    int main(){
    	cin >> n;
    	for (int i = 0; i < n; i++)
    	{
    		int x;
    		cin >> x;
    		a[i] = {x, i};
    	}
    	sort(a, a + n);
    	reverse(a, a + n);
    	for (int i = 0; i < n; i++)
    		ans += i * (a[i].first) + 1;

    	cout << ans << endl;

    	for (int i = 0; i < n; i++)
    		cout << (a[i].second) + 1 << " ";
    }


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define  pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define mod 998244353
#define all(a) (a).begin(),(a).end()
#define MAX 100004
#define INF 100000000000
#define N 1000005
#define N1 1100006
#define debug(x) cout << "> " << #x << " : " << x << "\n";
typedef pair<ll,ll> Pll;
typedef pair<Pll,ll> PPll;

ll arr[N],dp[N],brr[N];
vector<Pll> v;

signed main() {
    ios_base::sync_with_stdio(false);
    ll t,i=0,j,n,k,x,y,a,b,c,d;
    string s;
    cin>>n;

    ll ans=0;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        v.pb({arr[i],i});
    }
    sort(arr,arr+n);
    sort(all(v));
    for(i=0;i<n;i++)
    {
        ans+=arr[i]*(n-i-1);

    }

    ans+=n;
    cout<<ans<<endl;

    for(i=n-1;i>=0;i--)
    {
        cout<<v[i].ss+1<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define  pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define mod 998244353
#define all(a) (a).begin(),(a).end()
#define MAX 100004
#define INF 100000000000
#define N 1000005
#define N1 1100006
#define debug(x) cout << "> " << #x << " : " << x << "\n";
typedef pair<ll,ll> Pll;
typedef pair<Pll,ll> PPll;

ll arr[N],dp[N],brr[N];
vector<Pll> v;

signed main() {
    ios_base::sync_with_stdio(false);
    ll t,i=0,j,n,k,x,y,a,b,c,d;
    string s;
    cin>>n;

    ll ans=0;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        v.pb({arr[i],i});
    }
    sort(arr,arr+n);
    sort(all(v));
    for(i=0;i<n;i++)
    {
        ans+=arr[i]*(n-i-1);

    }

    ans+=n;
    cout<<ans<<endl;

    for(i=0;i<n;i++)
    {
        brr[v[i].ss]=i+1;
    }
    for(i=0;i<n;i++)
        cout<<n-brr[i]+1<<" ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define  pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define mod 998244353
#define all(a) (a).begin(),(a).end()
#define MAX 100004
#define INF 100000000000
#define N 1000005
#define N1 1100006
#define debug(x) cout << "> " << #x << " : " << x << "\n";
typedef pair<ll,ll> Pll;
typedef pair<Pll,ll> PPll;

ll arr[N],dp[N],brr[N];
vector<Pll> v;

signed main() {
    ios_base::sync_with_stdio(false);
    ll t,i=0,j,n,k,x,y,a,b,c,d;
    string s;
    cin>>n;

    ll ans=0;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        v.pb({arr[i],i});
    }
    sort(arr,arr+n);
    sort(all(v));
    for(i=0;i<n;i++)
    {
        ans+=arr[i]*(n-i-1);

    }

    ans+=n;
    cout<<ans<<endl;

    for(i=0;i<n;i++)
    {
        brr[v[i].ss]=i+1;
    }
    for(i=0;i<n;i++)
        cout<<brr[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define  pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define mod 998244353
#define all(a) (a).begin(),(a).end()
#define MAX 100004
#define INF 100000000000
#define N 1000005
#define N1 1100006
#define debug(x) cout << "> " << #x << " : " << x << "\n";
typedef pair<ll,ll> Pll;
typedef pair<Pll,ll> PPll;

ll arr[N],dp[N],brr[N];
vector<Pll> v;

signed main() {
    ios_base::sync_with_stdio(false);
    ll t,i=0,j,n,k,x,y,a,b,c,d;
    string s;
    cin>>n;

    ll ans=0;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    for(i=0;i<n;i++)
    {
        ans+=arr[i]*(n-i-1);
    }
    ans+=n;
    cout<<ans;
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
#include<map>
#include<vector>
using namespace std;

   int main()
   {
       int n;
       cin >> n;
       vector<pair<int,int>> arr;
       for(int i=0; i<3; i++) {
           int num;
           cin >> num;
           arr.push_back(make_pair(num,i+1));
       }
       sort(arr.begin(),arr.end(),greater<pair<int,int>>());
       int res = 1;
       for(int i=0; i<n; i++) {
           if(i != n-1)
           cout << arr[i].second << " ";
           else
           cout << arr[i].second << endl;
           if(i!=0)
           res += arr[i].first*i+1;
       }
       cout << res << endl;
        return 0;
    }


#include <iostream>
#include<bits/stdc++.h>
#include<map>
#include<vector>
using namespace std;

   int main()
   {
       int n;
       cin >> n;
       vector<pair<int,int>> arr;
       for(int i=0; i<n; i++) {
           int num;
           cin >> num;
           arr.push_back(make_pair(num,i+1));
       }
       sort(arr.begin(),arr.end(),greater<pair<int,int>>());
       int res = 1;
       for(int i=1; i<n; i++) {
           res += arr[i].first*i+1;
       }
       cout << res << endl;
        for(int i=0; i<n; i++) {
           if(i != n-1)
           cout << arr[i].second << " ";
           else
           cout << arr[i].second << endl;;
       }
        return 0;
    }


#include <iostream>
#include<bits/stdc++.h>
#include<map>
#include<vector>
#define P pair<int,int>
using namespace std;

bool cmp(P p1, P p2)
{
	return p1.first > p2.first;
}
   int main()
   {
       int n;
       cin >> n;
       vector<P> arr;
       for(int i=0; i<n; i++) {
           int num;
           cin >> num;
           arr.push_back(make_pair(num,i+1));
       }
       sort(arr.begin(),arr.end(),cmp);
       int res = 0;
       int x(0);
       for(int i=0; i<n; i++) {
           res += arr[i].first*x+1;
           x++;
       }
       cout << res << endl;
        for(int i=0; i<n; i++) {
           if(i != n-1)
           cout << arr[i].second << " ";
           else
           cout << arr[i].second << endl;;
       }
        return 0;
    }


#include <iostream>
#include<bits/stdc++.h>
#include<map>
#include<vector>
using namespace std;

   int main()
   {
       int n;
       cin >> n;
       vector<pair<int,int>> arr;
       for(int i=0; i<3; i++) {
           int num;
           cin >> num;
           arr.push_back(make_pair(num,i+1));
       }
       sort(arr.begin(),arr.end(),greater<pair<int,int>>());
       int res = 1;
       for(int i=1; i<n; i++) {
           res += arr[i].first*i+1;
       }
       cout << res << endl;
        for(int i=0; i<n; i++) {
           if(i != n-1)
           cout << arr[i].second << " ";
           else
           cout << arr[i].second << endl;;
       }
        return 0;
    }


    #include<bits/stdc++.h>
    #define ll          long long

    using namespace std;

    #define N  1000000001

bool isprime(long long int n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}
    int main()
    {
        int n;
        cin>>n;
        vector<vector<int>> A(n,vector<int>(2,0));
        for(int i=0;i<n;i++)
        {
            cin>>A[i][0];
            A[i][1]=i;
        }
        sort(A.begin(),A.end());
        reverse(A.begin(),A.end());
        int count=0;
        for(int i=0;i<n;i++)
        {
            count+=A[i][0]*i+1;
        }
        cout<<count<<endl;
        for(int i=0;i<n;i++)
        {
            cout<<A[i][1]+1<<" ";
        }
        cout<<endl;
        return 0;
    }


    #include<bits/stdc++.h>
    #define ll          long long

    using namespace std;

    #define N  1000000001

bool isprime(long long int n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int n;
        cin>>n;
        vector<vector<int>> A(n,vector<int>(2,0));
        for(int i=0;i<n;i++)
        {
            cin>>A[i][0];
            A[i][1]=i;
        }
        sort(A.begin(),A.end());
        reverse(A.begin(),A.end());
        int count=0;
        for(int i=0;i<n;i++)
        {
            count+=A[i][0]*i+1;
        }
        cout<<count<<endl;
        for(int i=0;i<n;i++)
        {
            cout<<A[i][1]+1<<" ";
        }
        cout<<endl;
        return 0;
    }


    #include<bits/stdc++.h>
    #define ll          long long

    using namespace std;

    #define N  1000000001

bool isprime(long long int n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}
    int main()
    {
        int n;
        cin>>n;
        vector<vector<int>> A(n,vector<int>(2,0));
        for(int i=0;i<n;i++)
        {
            cin>>A[i][0];
            A[i][1]=i;
        }
        sort(A.rbegin(),A.rend());
        int count=0;
        for(int i=0;i<n;i++)
        {
            count+=A[i][0]*i+1;
        }
        cout<<count<<endl;
        for(int i=0;i<n;i++)
        {
            cout<<A[i][1]+1<<" ";
        }
        cout<<endl;
        return 0;
    }


#include <bits/stdc++.h>

using namespace std;

int main()
{
int n;
cin >> n;
vector <pair<int,int>> a(n);
for (int i=0; i<n; i++)
    {
        cin >> a[i].first; a[i].second = i+1;
    }
sort(a.rbegin(),a.rend());

int sum =0;
for (int i=0; i<n; i++)
    sum+= i * a[i].first + 1;

cout << sum << "\n";
for (int i=0; i<n; ++i)
    cout << a[i].second << " ";

}


#include <iostream>
#include <algorithm>
using namespace std;

class initialIndices {
    public:
        int value;
        int index;

        // initialIndices(int value, int index) {
        //     this -> value = value;
        //     this -> index = index;
        // }
};

bool compare(initialIndices ob1, initialIndices ob2) {
    return ob1.value > ob2.value;
}

int main() {
    int n = 201;
    // cin >> n;
    int *cans = new int[n];
    initialIndices *cansWithIndex = new initialIndices[n];

    for(int i=0; i<n; i++) {
        // cin >> cans[i];
        cans[i] = 1000;
        cansWithIndex[i].value = cans[i];
        cansWithIndex[i].index = i + 1;
    }

    sort(cansWithIndex, cansWithIndex + n, compare);

    long long int noOfBullets = 0;
    for(int i=0; i<n; i++) {
        noOfBullets = noOfBullets + (long)(cansWithIndex[i].value * i) + 1;
    }

    cout << noOfBullets << endl;
    for(int i=0; i<n; i++) {
        cout << cansWithIndex[i].index << " ";
    }
}


#include <iostream>
#include <algorithm>
using namespace std;

class initialIndices {
    public:
        int value;
        int index;

        // initialIndices(int value, int index) {
        //     this -> value = value;
        //     this -> index = index;
        // }
};

bool compare(initialIndices ob1, initialIndices ob2) {
    return ob1.value >= ob2.value;
}

int main() {
    int n;
    cin >> n;
    int *cans = new int[n];
    initialIndices *cansWithIndex = new initialIndices[n];

    for(int i=0; i<n; i++) {
        cin >> cans[i];
        cansWithIndex[i].value = cans[i];
        cansWithIndex[i].index = i + 1;
    }

    sort(cansWithIndex, cansWithIndex + n, compare);

    int noOfBullets = 0;
    for(int i=0; i<n; i++) {
        noOfBullets += cansWithIndex[i].value * i + 1;
    }

    cout << noOfBullets << endl;
    for(int i=0; i<n; i++) {
        cout << cansWithIndex[i].index << " ";
    }
}


#include <iostream>
#include <algorithm>
using namespace std;

class initialIndices {
    public:
        int value;
        int index;

        // initialIndices(int value, int index) {
        //     this -> value = value;
        //     this -> index = index;
        // }
};

bool compare(initialIndices ob1, initialIndices ob2) {
    return ob1.value >= ob2.value;
}

int main() {
    int n;
    cin >> n;
    int *cans = new int[n];
    initialIndices *cansWithIndex = new initialIndices[n];

    for(int i=0; i<n; i++) {
        cin >> cans[i];
        cansWithIndex[i].value = cans[i];
        cansWithIndex[i].index = i + 1;
    }

    sort(cansWithIndex, cansWithIndex + n, compare);

    long long int noOfBullets = 0;
    for(int i=0; i<n; i++) {
        noOfBullets += cansWithIndex[i].value * i + 1;
    }

    cout << noOfBullets << endl;
    for(int i=0; i<n; i++) {
        cout << cansWithIndex[i].index << " ";
    }
}


#include <iostream>
#include <algorithm>
using namespace std;

class initialIndices {
    public:
        int value;
        int index;

        // initialIndices(int value, int index) {
        //     this -> value = value;
        //     this -> index = index;
        // }
};

bool compare(initialIndices ob1, initialIndices ob2) {
    return ob1.value > ob2.value;
}

int main() {
    int n;
    cin >> n;
    int *cans = new int[n];
    initialIndices *cansWithIndex = new initialIndices[n];

    for(int i=0; i<n; i++) {
        cin >> cans[i];
        // cans[i] = 1000;
        cansWithIndex[i].value = cans[i];
        cansWithIndex[i].index = i + 1;
    }

    sort(cansWithIndex, cansWithIndex + n, compare);

    long long int noOfBullets = 0;
    for(int i=0; i<n; i++) {
        noOfBullets = noOfBullets + (long)(cansWithIndex[i].value * i) + 1;
    }

    cout << noOfBullets << endl;
    for(int i=0; i<n; i++) {
        cout << cansWithIndex[i].index << " ";
    }
}


#include<iostream>
#include<bits/stdc++.h>

using namespace std;

int main()
{

	int n;
	cin>>n;
	vector<int> cans(n,0);
	vector<pair<int,int> > ord;

	for(int i = 0 ; i <  n ; i++){
		cin>>cans[i];
		ord.push_back(make_pair(cans[i],i));
	}

	sort(ord.begin(),ord.end());
	int knockedDown = 0;
	int sol = 0;
	std::vector<int> soll;

	for(int i = n-1; i>=0 ; i--)
	{
		sol+=((ord[i].first)*knockedDown)+1;
		knockedDown++;
		soll.push_back(ord[i].second+1);
	}

	cout<<sol<<endl;
	for(int i = 0 ; i < n ; i++)
		cout<<soll[i]<<" ";
	cout<<endl;

	return 0;
}


#include<iostream>
#include<bits/stdc++.h>

using namespace std;

void fastIO()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int getNearestMax(vector<int>& v)
{
	int indx;
	int maxVal = INT_MIN;
	for(int i = 0 ; i < int(v.size()) ; i++)
	{
		if(v[i] > maxVal)
		{
			indx = i;
			maxVal = v[i];
		}
	}
	return indx;
}

int main()
{

	//fastIO();

	int n;
	cin>>n;

	vector<int> cans;
	vector<int> sols(n,0);

	for(int i = 0 ;i < n ; i++)
	{
		int temp;
		cin>>temp;
		cans.push_back(temp);
	}

	int knockedDown = 0;
	int turn = 1;

	long long int sol = 0;

	for(int i = 0 ; i < n ; i++)
	{
		int indx = getNearestMax(cans);
		sol+=(knockedDown*cans[indx])+1;
		knockedDown++;
		cans[indx] = INT_MIN;
		sols[indx] = turn++;
	}

	cout<<sol<<endl;
	for(int i = 0 ; i < n ; i++)
		cout<<sols[i]<<" ";
	cout<<endl;
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>

using namespace std;

void fastIO()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int getNearestMax(vector<int>& v)
{
	int indx;
	int maxVal = INT_MIN;
	for(int i = 0 ; i < int(v.size()) ; i++)
	{
		if(v[i] > maxVal)
		{
			indx = i;
			maxVal = v[i];
		}
	}
	return indx;
}

int main()
{

	fastIO();

	int n;
	cin>>n;

	vector<int> cans;
	vector<int> sols(n,0);

	for(int i = 0 ;i < n ; i++)
	{
		int temp;
		cin>>temp;
		cans.push_back(temp);
	}

	int knockedDown = 0;
	int turn = 1;

	long long int sol = 0;

	for(int i = 0 ; i < n ; i++)
	{
		int indx = getNearestMax(cans);
		sol+=knockedDown*cans[indx]+1;
		knockedDown++;
		cans[indx] = INT_MIN;
		sols[indx] = turn;
		turn++;
	}

	cout<<sol<<endl;

	for(int i = 0 ; i < n ; i++)
		cout<<sols[i]<<" ";

	cout<<endl;
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>

using namespace std;

void fastIO()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int getNearestMax(vector<int>& v)
{
	int indx;
	int maxVal = INT_MIN;
	for(int i = 0 ; i < int(v.size()) ; i++)
	{
		if(v[i] > maxVal)
		{
			indx = i;
			maxVal = v[i];
		}
	}
	return indx;
}

int main()
{

	//fastIO();

	int n;
	cin>>n;

	vector<int> cans;
	vector<int> sols(n,0);

	vector<pair<int,int> > vc;

	for(int i = 0 ;i < n ; i++)
	{
		int temp;
		cin>>temp;
		cans.push_back(temp);
	}

	for(int i = 0 ; i < n ; i++)
	{
		vc.push_back(make_pair(cans[i],i));
	}

	sort(vc.begin(),vc.end());

		int knockedDown = 0;
		int turn = 1;
		long long int sol = 0;

	for(int i = n-1; i>=0 ;i--)
	{
		sol+=(knockedDown*vc[i].first)+1;
		knockedDown++;
		sols[vc[i].second] = turn++;
	}
	// for(int i = 0 ; i < n ; i++)
	// {
	// 	int indx = getNearestMax(cans);
	// 	sol+=(knockedDown*cans[indx])+1;
	// 	knockedDown++;
	// 	cans[indx] = INT_MIN;
	// 	sols[indx] = turn++;
	// }

	cout<<sol<<endl;
	for(int i = 0 ; i < n ; i++)
		cout<<sols[i]<<" ";
	cout<<endl;
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>

using namespace std;

void fastIO()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int getNearestMax(vector<int>& v)
{
	int indx;
	int maxVal = INT_MIN;
	for(int i = 0 ; i < int(v.size()) ; i++)
	{
		if(v[i] > maxVal)
		{
			indx = i;
			maxVal = v[i];
		}
	}
	return indx;
}

int main()
{

	//fastIO();

	int n;
	cin>>n;

	vector<int> cans;
	vector<int> sols(n,0);

	vector<pair<int,int> > vc;

	for(int i = 0 ;i < n ; i++)
	{
		int temp;
		cin>>temp;
		cans.push_back(temp);
	}

	for(int i = 0 ; i < n ; i++)
	{
		vc.push_back(make_pair(cans[i],i));
	}

	sort(vc.begin(),vc.end());

		int knockedDown = 0;
		int turn = 1;
		long long int sol = 0;

	for(int i = n-1; i>=0 ;i--)
	{
		sol+=(knockedDown*vc[i].first)+1;
		knockedDown++;
		sols[vc[i].second] = turn++;
	}
	// for(int i = 0 ; i < n ; i++)
	// {
	// 	int indx = getNearestMax(cans);
	// 	sol+=(knockedDown*cans[indx])+1;
	// 	knockedDown++;
	// 	cans[indx] = INT_MIN;
	// 	sols[indx] = turn++;
	// }

	cout<<sol<<endl;
	for(int i = 0 ; i < n ; i++)
		cout<<vc[i].second<<" ";
	cout<<endl;
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>

using namespace std;

void fastIO()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int getNearestMax(vector<int>& v)
{
	int indx;
	int maxVal = INT_MIN;
	for(int i = 0 ; i < int(v.size()) ; i++)
	{
		if(v[i] > maxVal)
		{
			indx = i;
			maxVal = v[i];
		}
	}
	return indx;
}

int main()
{

	//fastIO();

	int n;
	cin>>n;

	vector<int> cans;
	vector<int> sols(n,0);

	vector<pair<int,int> > vc;

	for(int i = 0 ;i < n ; i++)
	{
		int temp;
		cin>>temp;
		cans.push_back(temp);
	}

	for(int i = 0 ; i < n ; i++)
	{
		vc.push_back(make_pair(cans[i],i));
	}

	sort(vc.begin(),vc.end());

		int knockedDown = 0;
		int turn = 1;
		long long int sol = 0;

	for(int i = n-1; i>=0 ;i--)
	{
		sol+=(knockedDown*vc[i].first)+1;
		knockedDown++;
		//sols[vc[i].second] = turn++;
	}
	// for(int i = 0 ; i < n ; i++)
	// {
	// 	int indx = getNearestMax(cans);
	// 	sol+=(knockedDown*cans[indx])+1;
	// 	knockedDown++;
	// 	cans[indx] = INT_MIN;
	// 	sols[indx] = turn++;
	// }

	cout<<sol<<endl;
	for(int i = 0 ; i < n ; i++)
		vc[i].second<<" ";
	cout<<endl;
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>

using namespace std;

int main()
{

	int n;
	cin>>n;

	vector<int> cans;
	vector<int> sols(n,0);

	vector<pair<int,int> > vc;

	for(int i = 0 ;i < n ; i++)
	{
		int temp;
		cin>>temp;
		cans.push_back(temp);
	}

	for(int i = 0 ; i < n ; i++)
	{
		vc.push_back(make_pair(cans[i],i));
	}

	sort(vc.begin(),vc.end());

		int knockedDown = 0;
		int turn = 1;
		long long int sol = 0;

	for(int i = n-1; i>=0 ;i--)
	{
		sol+=(knockedDown*vc[i].first)+1;
		knockedDown++;
		sols[vc[i].second] = turn++;
	}

	cout<<sol<<endl;
	for(int i = 0 ; i < n ; i++)
		cout<<sols[i]<<" ";
	cout<<endl;

	cans.clear();
	sols.clear();
	vc.clear();

	return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<pii> A(N);
    rep(i,N) {
        int a; cin >> a;
        A[i] = make_pair(a,i);
    }

    vector<int> ans(N);
    int cnt = 0;
    sort(all(A));
    reverse(all(A));
    rep(i,N) {
        cnt += A[i].first*i+1;
        ans[A[i].second] = i+1;
    }

    cout << cnt << ln;
    rep(i,N) cout << ans[i] << " ";
    cout << ln;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<pii> A(N);
    rep(i,N) {
        int a; cin >> a;
        A[i] = make_pair(a,i);
    }

    vector<int> ans(N);
    int cnt = 0;
    sort(all(A));
    reverse(all(A));
    rep(i,N) {
        cnt += A[i].first*i+1;
        ans[i] = A[i].second+1;
    }

    cout << cnt << ln;
    rep(i,N) {
        if (i) cout << " ";
        cout << ans[i];
    }
    cout << ln;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<pii> A(N);
    rep(i,N) {
        int a; cin >> a;
        A[i] = make_pair(a,i);
    }

    vector<int> ans(N);
    int cnt = 0;
    sort(all(A));
    reverse(all(A));
    rep(i,N) {
        cnt += A[i].first*i+1;
        ans[A[i].second] = i+1;
    }

    cout << cnt << ln;
    rep(i,N) {
        if (i) cout << " ";
        cout << ans[i];
    }
    cout << ln;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<pii> A(N);
    rep(i,N) {
        int a; cin >> a;
        A[i] = make_pair(a,i);
    }

    vector<int> ans(N);
    int cnt = 0;
    sort(all(A));
    reverse(all(A));
    rep(i,N) {
        cnt += A[i].first*i+1;
        ans[A[i].second] = N-i;
    }

    cout << cnt << ln;
    rep(i,N) {
        if (i) cout << " ";
        cout << ans[i];
    }
    cout << ln;
}


    #include <bits/stdc++.h>

    using namespace std;
    typedef long long ll;
    const int N = 3e5 + 5;

    int n, mn, ans[1111];
    vector<pair<int,int> > v;

    int main() {
        cin >> n;
        for(int i=0;i<n;++i){
            int x;
            cin >> x;
            v.push_back({x,i});
        }
        sort(v.rbegin(),v.rend());
        mn = 1;
        ans[v[0].second] = 1;
        for(int i = 1;i<n;i++){
            mn += i * v[i].first + 1;
            ans[v[i].second] = i + 1;
        }
        cout << mn << endl;
        for(int i=0;i<n;++i)
            cout << ans[i] << " ";
        return 0;
    }


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 3e5 + 5;

int n, mn, ans[1111];
vector<pair<int, int> > v;

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        v.push_back({x, i});
    }
    sort(v.rbegin(), v.rend());
    mn = 1;
    ans[v[0].second] = 1;
    for (int i = 1; i < n; i++) {
        mn += i * v[i].first + 1;
    }
    cout << mn << endl;
    for (int i = 0; i < n; ++i)
        cout <<v[i].second + 1<< " ";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 3e5 + 5;

int n, mn, ans[1111];
vector<pair<int, int> > v;

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        v.push_back({x, i});
    }
    sort(v.rbegin(), v.rend());
    mn = 1;
    ans[v[0].second] = 1;
    for (int i = 1; i < n; i++) {
        mn += i * v[i].first + 1;
        ans[v[i].second] = i + 1;
    }
    cout << mn << endl;
    for (int i = 0; i < n; ++i)
        cout << ans[i] << " ";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 3e5 + 5;

int n, mn, ans[1111];
vector<pair<int,int> > v;

int main() {
    cin >> n;
    for(int i=0;i<n;++i){
        int x;
        cin >> x;
        v.push_back({x,i});
    }
    sort(v.rbegin(),v.rend());
    mn = 1;
    ans[v[0].second] = 1;
    for(int i = 1;i<n;i++){
        mn += i * v[i].first + 1;
        ans[v[i].second] = i + 1;
    }
    cout << mn << endl;
    for(int i=0;i<n;++i)
        cout << ans[i] << " ";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 3e5 + 5;

int n, mn, ans[1111];
vector<pair<int,int> > v;

int main() {
    cin >> n;
    for(int i=0;i<n;++i){
        int x;
        cin >> x;
        v.push_back({x,-i});
    }
    sort(v.rbegin(),v.rend());
    mn = 1;
    ans[v[0].second * -1] = 1;
    for(int i = 1;i<n;i++){
        mn += i * v[i].first + 1;
        ans[v[i].second * -1] = i + 1;
    }
    cout << mn << endl;
    for(int i=0;i<n;++i)
        cout << ans[i] << " ";
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n,a[1002],b[1002],c[1002];

void qsort1(int l,int r)
{
    int i=l,j=r,k=a[(l+r)/2],z=b[(l+r)/2];
    do
    {
        while (a[i]>k || (a[i]==k && b[i]<z)) ++i;
        while (a[j]<k || (a[j]==k && b[j]>z)) --j;
        if (i<=j)
        {
            int tg=a[i];a[i]=a[j];a[j]=tg;
            tg=b[i];b[i]=b[j];b[j]=tg;
            ++i;
            --j;
        };
    } while (i<=j);
    if (l<j) qsort1(l,j);
    if (i<r) qsort1(i,r);
};

int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
        b[i]=i;
    };
    qsort1(1,n);
    long long ans=0,dem=0;
    for (int i=1;i<=n;i++)
    {
        ans=ans+a[i]*dem+1;
        ++dem;
        c[b[i]]=dem;
    };
    cout<<ans<<endl;
    for (int i=1;i<=n;i++) cout<<b[i]<<" ";
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n,a[1002],b[1002],c[1002];

void qsort1(int l,int r)
{
    int i=l,j=r,k=a[(l+r)/2];
    do
    {
        while (a[i]>k) ++i;
        while (a[j]<k) --j;
        if (i<=j)
        {
            int tg=a[i];a[i]=a[j];a[j]=tg;
            tg=b[i];b[i]=b[j];b[j]=tg;
            ++i;
            --j;
        };
    } while (i<=j);
    if (l<j) qsort1(l,j);
    if (i<r) qsort1(i,r);
};

int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
        b[i]=i;
    };
    //qsort1(1,n);
    for (int i=1;i<n;i++)
        for (int j=i+1;j<=n;j++)
            if (a[i]<a[j])
            {
                int tg=a[i];a[i]=a[j];a[j]=tg;
                tg=b[i];b[i]=b[j];b[j]=tg;
            };
    long long ans=0,dem=0;
    for (int i=1;i<=n;i++)
    {
        ans=ans+a[i]*dem+1;
        ++dem;
        c[b[i]]=dem;
    };
    cout<<ans<<endl;
    for (int i=1;i<=n;i++) cout<<c[i]<<" ";
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n,a[1002],b[1002],c[1002];

void qsort1(int l,int r)
{
    int i=l,j=r,k=a[(l+r)/2];
    do
    {
        while (a[i]>k) ++i;
        while (a[j]<k) --j;
        if (i<=j)
        {
            int tg=a[i];a[i]=a[j];a[j]=tg;
            tg=b[i];b[i]=b[j];b[j]=tg;
            ++i;
            --j;
        };
    } while (i<=j);
    if (l<j) qsort1(l,j);
    if (i<r) qsort1(i,r);
};

int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
        b[i]=i;
    };
    qsort1(1,n);
    long long ans=0,dem=0;
    for (int i=1;i<=n;i++)
    {
        ans=ans+a[i]*dem+1;
        ++dem;
        c[b[i]]=dem;
    };
    cout<<ans<<endl;
    for (int i=1;i<=n;i++) cout<<c[i]<<" ";

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n,a[1002],b[1002],c[1002];

void qsort1(int l,int r)
{
    int i=l,j=r,k=a[(l+r)/2],z=b[(l+r)/2];
    do
    {
        while (a[i]>k || (a[i]==k && b[i]<z)) ++i;
        while (a[j]<k || (a[j]==k && b[j]>z)) --j;
        if (i<=j)
        {
            int tg=a[i];a[i]=a[j];a[j]=tg;
            tg=b[i];b[i]=b[j];b[j]=tg;
            ++i;
            --j;
        };
    } while (i<=j);
    if (l<j) qsort1(l,j);
    if (i<r) qsort1(i,r);
};

int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
        b[i]=i;
    };
    qsort1(1,n);
    long long ans=0,dem=0;
    for (int i=1;i<=n;i++)
    {
        ans=ans+a[i]*dem+1;
        ++dem;
        c[b[i]]=dem;
    };
    cout<<ans<<endl;
    for (int i=1;i<=n;i++) cout<<c[i]<<" ";
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n,a[1002],b[1002],c[1002];

void qsort1(int l,int r)
{
    int i=l,j=r,k=a[(l+r)/2];
    do
    {
        while (a[i]>k) ++i;
        while (a[j]<k) --j;
        if (i<=j)
        {
            int tg=a[i];a[i]=a[j];a[j]=tg;
            tg=b[i];b[i]=b[j];b[j]=tg;
            ++i;
            --j;
        };
    } while (i<=j);
    if (l<j) qsort1(l,j);
    if (i<r) qsort1(i,r);
};

int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
        b[i]=i;
    };
    qsort1(1,n);
    long long ans=0,dem=0;
    for (int i=1;i<=n;i++)
    {
        ans=ans+a[i]*dem+1;
        ++dem;
        c[b[i]]=dem;
    };
    cout<<ans<<endl;
    for (int i=1;i<=n;i++) cout<<c[i]<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node{
	int num;
	int pindex;
	int bindex;
}a[1005];
bool cmp1(node x,node y){
	return x.num>y.num;
}
bool cmp2(node x,node y){
	return x.pindex<y.pindex;
}
int main(){
	int n;
	int sum;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].num;
		a[i].pindex=i;
	}
	sort(a+1,a+n+1,cmp1);
	//for(int i=1;i<=n;i++)cout<<a[i].num;
	for(int i=1;i<=n;i++){
		sum+=(i-1)*a[i].num+1;
		a[i].bindex=i;
	}
	cout<<sum<<endl;
	sort(a+1,a+1+n,cmp2);
	for(int i=1;i<=n;i++){
		cout<<a[i].bindex;
		if(i!=n)cout<<" ";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node{
	int num;
	int pindex;
	int bindex;
}a[1005];
bool cmp1(node x,node y){
	return x.num>y.num;
}
bool cmp2(node x,node y){
	return x.pindex<y.pindex;
}
int main(){
	int n;
	int sum=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].num;
		a[i].pindex=i;
	}
	sort(a+1,a+n+1,cmp1);
	//for(int i=1;i<=n;i++)cout<<a[i].num;
	for(int i=1;i<=n;i++){
		sum+=(i-1)*a[i].num+1;
		a[i].bindex=i;
	}
	cout<<sum<<endl;
	sort(a+1,a+1+n,cmp2);
	for(int i=1;i<=n;i++){
		cout<<a[i].bindex;
		if(i!=n)cout<<" ";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node{
	int num;
	int pindex;
	int bindex;
}a[1005];
bool cmp1(node x,node y){
	return x.num>y.num;
}
bool cmp2(node x,node y){
	return x.pindex<y.pindex;
}
int main(){
	int n;
	int sum;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].num;
		a[i].pindex=i;
	}
	sort(a+1,a+n+1,cmp1);
	//for(int i=1;i<=n;i++)cout<<a[i].num;
	for(int i=1;i<=n;i++){
		sum+=(i-1)*a[i].num+1;
		a[i].bindex=i;
	}
	cout<<sum<<endl;
	sort(a+1,a+1+n,cmp2);
	for(int i=1;i<=n;i++){
		cout<<a[i].bindex<<" ";
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node{
	int num;
	int index;
}a[1005];
bool cmp(node x,node y){
	return x.num>y.num;
}
int main(){
	int n;
	int sum=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].num;
		a[i].index=i;
	}
	sort(a+1,a+n+1,cmp);
	//for(int i=1;i<=n;i++)cout<<a[i].num;
	for(int i=1;i<=n;i++){
		sum+=(i-1)*a[i].num+1;
	}
	cout<<sum<<endl;
	for(int i=1;i<=n;i++){
		cout<<a[i].index<<" ";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node{
	int num;
	int pindex;
	int bindex;
}a[1005];
bool cmp1(node x,node y){
	return x.num>y.num;
}
bool cmp2(node x,node y){
	return x.pindex<y.pindex;
}
int main(){
	int n;
	int sum;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].num;
		a[i].pindex=i;
	}
	sort(a+1,a+n+1,cmp1);
	//for(int i=1;i<=n;i++)cout<<a[i].num;
	for(int i=1;i<=n;i++){
		sum+=(i-1)*a[i].num+1;
		a[i].bindex=i;
	}
	cout<<sum<<endl;
	sort(a+1,a+1+n,cmp2);
	for(int i=1;i<=n;i++){
		cout<<a[i].bindex<<" ";
	}
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;
const ll maxx = 1e6;
const int base = 39;
//set<pair<int, int> > q;
bool check;
ll n, m = 0, a[102], mn, b[102], c, t = 0, t1 = 0, tong = 0,x , y;
bool lf(ll x, ll y)
{
    return a[x] < a[y];
}
void sol()
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        b[i] = i;
    }
    sort(b+1, b+1+n, lf);
    for(int i = 1; i <= n; i ++)cout << b[i] <<" ";
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    sol();
}
/*centroid tree
#include <iostream>
#include "assert.h"
typedef long long int LL;

using namespace std;

LL getNumberOfCardsInFullHouse(LL floors) {
  return 3 * floors * (floors + 1) / 2 - floors;
}

LL getMaxHeight(LL n) {
  LL l = 0;
  LL r = 10000000;
  assert(getNumberOfCardsInFullHouse(r) > 1e13);
  while (l + 1 < r) {
    LL m = (l + r) / 2;
    if (getNumberOfCardsInFullHouse(m) <= n) l = m;
    else r = m;
  }
  return l;
}

LL solve(LL n) {
  LL mx = getMaxHeight(n);
  while ((mx + n) % 3) mx--;
  return (mx + 3 - 1) / 3;
}

int main() {
  LL n; cin >> n;
  cout << solve(n);
}
*/


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;
const ll maxx = 1e6;
const int base = 39;
//set<pair<int, int> > q;
bool check;
ll n, m = 0, a[102], mn, b[102], c, t = 0, t1 = 0, tong = 0,x , y;
bool lf(ll x, ll y)
{
    return a[x] < a[y];
}
void sol()
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        b[i] = i;
    }
    sort(b+1, b+1+n, lf);
    tong = 0;
    m = 0;
    for(int i = 1; i <= n; i ++)
    {
        tong += m * a[b[i]] + 1;
        ++m;
    }
    for(int i = 1; i <= n; i ++)cout << b[i] <<" ";
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    sol();
}
/*centroid tree
#include <iostream>
#include "assert.h"
typedef long long int LL;

using namespace std;

LL getNumberOfCardsInFullHouse(LL floors) {
  return 3 * floors * (floors + 1) / 2 - floors;
}

LL getMaxHeight(LL n) {
  LL l = 0;
  LL r = 10000000;
  assert(getNumberOfCardsInFullHouse(r) > 1e13);
  while (l + 1 < r) {
    LL m = (l + r) / 2;
    if (getNumberOfCardsInFullHouse(m) <= n) l = m;
    else r = m;
  }
  return l;
}

LL solve(LL n) {
  LL mx = getMaxHeight(n);
  while ((mx + n) % 3) mx--;
  return (mx + 3 - 1) / 3;
}

int main() {
  LL n; cin >> n;
  cout << solve(n);
}
*/


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;
const ll maxx = 1e6;
const int base = 39;
//set<pair<int, int> > q;
bool check;
ll n, m = 0, a[102], mn, b[102], c, t = 0, t1 = 0, tong = 0,x , y;
bool lf(ll x, ll y)
{
    return a[x] > a[y];
}
void sol()
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        b[i] = i;
    }
    sort(b+1, b+1+n, lf);
    tong = 0;
    m = 0;
    for(int i = 1; i <= n; i ++)
    {
        tong += (i-1) * a[b[i]] + 1;
        //cout << a[b[i]];
    }
    cout << tong<<'\n';
    for(int i = 1; i <= n; i ++)cout << b[i] <<" ";
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    sol();
}
/*centroid tree
#include <iostream>
#include "assert.h"
typedef long long int LL;

using namespace std;

LL getNumberOfCardsInFullHouse(LL floors) {
  return 3 * floors * (floors + 1) / 2 - floors;
}

LL getMaxHeight(LL n) {
  LL l = 0;
  LL r = 10000000;
  assert(getNumberOfCardsInFullHouse(r) > 1e13);
  while (l + 1 < r) {
    LL m = (l + r) / 2;
    if (getNumberOfCardsInFullHouse(m) <= n) l = m;
    else r = m;
  }
  return l;
}

LL solve(LL n) {
  LL mx = getMaxHeight(n);
  while ((mx + n) % 3) mx--;
  return (mx + 3 - 1) / 3;
}

int main() {
  LL n; cin >> n;
  cout << solve(n);
}
*/


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;
const ll maxx = 1e6;
const int base = 39;
//set<pair<int, int> > q;
bool check;
ll n, m = 0, a[maxx], mn, b[maxx], c, t = 0, t1 = 0, tong = 0,x , y;
bool lf(ll x, ll y)
{
    return a[x] > a[y];
}
void sol()
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        b[i] = i;
    }
    sort(b+1, b+1+n, lf);
    tong = 0;
    m = 0;
    for(int i = 1; i <= n; i ++)
    {
        tong += (i-1) * a[b[i]] + 1;
        //cout << a[b[i]];
    }
    cout << tong<<'\n';
    for(int i = 1; i <= n; i ++)cout << b[i] <<" ";
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    sol();
}
/*centroid tree
#include <iostream>
#include "assert.h"
typedef long long int LL;

using namespace std;

LL getNumberOfCardsInFullHouse(LL floors) {
  return 3 * floors * (floors + 1) / 2 - floors;
}

LL getMaxHeight(LL n) {
  LL l = 0;
  LL r = 10000000;
  assert(getNumberOfCardsInFullHouse(r) > 1e13);
  while (l + 1 < r) {
    LL m = (l + r) / 2;
    if (getNumberOfCardsInFullHouse(m) <= n) l = m;
    else r = m;
  }
  return l;
}

LL solve(LL n) {
  LL mx = getMaxHeight(n);
  while ((mx + n) % 3) mx--;
  return (mx + 3 - 1) / 3;
}

int main() {
  LL n; cin >> n;
  cout << solve(n);
}
*/


#include<bits/stdc++.h>
using namespace std;
int main()
{
        int n;
        cin>>n;
        vector <int> a(n);
        vector <int> ans(n);
        vector <int> b(n);
        set <int,greater <int>> :: iterator itr;
        set <int, greater <int> > g;
        for(int i =0;i<n;i++)
        {
                cin>>a.at(i);
                b.at(i) = a.at(i);
                g.insert(a.at(i));
        }
        sort(a.begin(),a.end());
        long long s{0};
        for(int i = 0;i<n;i++)
                s = s+(a.at(i)*(n-i-1)) + 1;
        cout<<s<<"\n";
        int x = 0;
        for(itr  = g.begin();itr != g.end();itr++)
        {
                for(int i =0;i<n;i++)
                {
                        if(*itr == b.at(i))
                        {
                                ans.at(x) = i+1;
                                x++;
                        }
                }
        }
        for(int z : ans)
                cout<<z<<" ";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
        ios::sync_with_stdio(0);
        cin.tie(0);
        int n;
        cin>>n;
        vector<pair<int,int> > st(n);
        for(int i = 0;i<n;i++)
        {
                int t;
                cin>>t;
                st[i] = make_pair(t,i);
        }
        sort(st.begin(),st.end());
        long long s{0};
        for(int i =0;i<n;i++)
                s = s+(st[i].first*(n-i-1)) + 1;
        cout<<s<<'\n';
        vector <int> ans (n);
        for(int i =0;i<n;i++)
        {
                ans[st[i].second] = n-i;
        }
        for(int it : ans)
                cout<<it<<' ';
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
        ios::sync_with_stdio(0);
        cin.tie(0);
        int n;
        cin>>n;
        vector<pair<int,int> > st(n);
        for(int i = 0;i<n;i++)
        {
                int t;
                cin>>t;
                st[i] = make_pair(t,i);
        }
        sort(st.begin(),st.end());
        long long s{0};
        for(int i =0;i<n;i++)
                s = s+(st[i].first*(n-i-1)) + 1;
        cout<<s<<'\n';
        for(int i =n-1;i>=0;i--)
                cout<<st[i].second+1<<' ';
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " = " << x <<endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define fore(i,a,b) for(int i=(int)a;i<=(int)b;++i)
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n;
pii arr[1004];
bool cmp(pii a, pii b){
    return a.F<b.F;
}
int main(){
#ifdef LOCAL
    //freopen("h.txt", "r", stdin);
    // freopen("main.out", "w", stdout);
#else
    ios::sync_with_stdio(0), cin.tie(0);
    #define endl '\n'
#endif

    cin>>n;
    forn(i,n)cin>>arr[i].F,arr[i].S=i;
    sort(arr,arr+n,cmp);
    ll sum=0;
    ll ai=0;
    string ans="";
    for(int i=n-1;i>=0;i--){
        sum+=ai*arr[i].F+1;
        ans+='0'+(arr[i].S+1);
        ans+=" ";
        ai++;
    }
    cout<<sum<<endl;
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " = " << x <<endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define fore(i,a,b) for(int i=(int)a;i<=(int)b;++i)
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n;
pii arr[1004];
bool cmp(pii a, pii b){
    return a.F<b.F;
}
int main(){
#ifdef LOCAL
    //freopen("h.txt", "r", stdin);
    // freopen("main.out", "w", stdout);
#else
    ios::sync_with_stdio(0), cin.tie(0);
    #define endl '\n'
#endif

    cin>>n;
    forn(i,n)cin>>arr[i].F,arr[i].S=i+1;
    sort(arr,arr+n,cmp);
    ll sum=0;
    ll ai=0;
    string ans="";
    for(int i=n-1;i>=0;i--){
        sum+=ai*arr[i].F+1;
        ans+=to_string(arr[i].S)+" ";
        ai++;
    }
    cout<<sum<<endl;
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " = " << x <<endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define fore(i,a,b) for(int i=(int)a;i<=(int)b;++i)
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
bool cmp(pii a, pii b){
    return a.F<=b.F;
}
int main(){
#ifdef LOCAL
    //freopen("h.txt", "r", stdin);
    // freopen("main.out", "w", stdout);
#else
    ios::sync_with_stdio(0), cin.tie(0);
    #define endl '\n'
#endif
    int n;
    cin>>n;
    pii arr[n];
    forn(i,n)cin>>arr[i].F,arr[i].S=i;
    sort(arr,arr+n,cmp);
    ll sum=0;
    ll ai=0;
    string ans="";
    for(int i=n-1;i>=0;i--){
        sum+=ai*arr[i].F+1;
        ans+='0'+(arr[i].S+1);
        ans+=" ";
        ai++;
    }
    cout<<sum<<endl;
    cout<<ans<<endl;
    return 0;
}


import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[] a = sc.nextIntList(N);
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			list.add(a[i]);
		}
		list.sort(null);

		int now = 1;
		for (int i = 0; i < N; i++) {
			int x = list.get(i);
			if (now < x) {
				a[i] = now;
				now++;
			} else {
				now = x + 1;
			}
		}
		System.out.println(now);
	}

}

class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[] a = sc.nextIntList(N);
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			list.add(a[i]);
		}
		list.sort(null);

		int now = 1;
		for (int i = 0; i < N; i++) {
			int x = list.get(i);
			if (now < x) {
				a[i] = now;
				now++;
			} else {
				now = x + 1;
			}
		}
		System.out.println(a[N - 1] + 1);
	}

}

class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		String s = sc.nextLine();
		String[] e = s.split(" ");
		for (int i = 0; i < N; i++) {
			a[i] = Integer.parseInt(sc.next());
		}

		Arrays.sort(a);
		int now = 1;
		for (int i = 0; i < N; i++) {
			if (now < a[i]) {
				a[i] = now;
				now++;
			} else {
				now = a[i] + 1;
			}
		}
		System.out.println(a[N - 1] + 1);
	}

}

class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		String[] e = sc.nextLine().split(" ");
		for (int i = 0; i < N; i++) {
			a[i] = Integer.parseInt(e[i]);
		}

		Arrays.sort(a);
		int now = 1;
		for (int i = 0; i < N; i++) {
			if (now < a[i]) {
				a[i] = now;
				now++;
			} else {
				now = a[i] + 1;
			}
		}
		System.out.println(a[N - 1] + 1);
	}

}

class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[] a = sc.nextIntList(N);

		List<Integer> list = new ArrayList<>();
		for (int x : a)
			list.add(x);
		Collections.shuffle(list);
		for (int i = 0; i < N; i++)
			a[i] = list.get(i);

		Arrays.sort(a);
		int now = 1;
		for (int i = 0; i < N; i++) {
			if (now < a[i]) {
				a[i] = now;
				now++;
			} else {
				now = a[i] + 1;
			}
		}
		System.out.println(a[N - 1] + 1);
	}

}

class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}

		Arrays.sort(a);
		int now = 1;
		for (int i = 0; i < N; i++) {
			if (now < a[i]) {
				a[i] = now;
				now++;
			} else {
				now = a[i] + 1;
			}
		}
		System.out.println(a[N - 1] + 1);
	}

}

class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}


import java.util.Scanner;

public class contest {

	public static Scanner input = new Scanner(System.in);

	public static void main(String[] args) {

		int n = input.nextInt();
		int[] nums = new int[n];

		for (int i = 0; i < n; i++) {
			nums[i] = input.nextInt();
		}

		int firstMax = nums[0];

		for (int i = 0; i < n; i++) {
			if (firstMax < nums[i]) {
				firstMax = nums[i];
			}
		}

		boolean found = true;
		int notFound = firstMax+1 ;

		for (int i = 1; i < n; i++) {
			int max = firstMax - i;

			for (int j = 0; j < n; j++) {

				if (max == nums[j]) {
					found = true;
					break;
				}
				else {
					found = false;
					notFound = max;
				}
			}
			if (!found){
				break;
			}
		}

		if (!found){
			System.out.println(notFound);
		}
		else {
			System.out.println(firstMax+1);
		}

	}

}


import java.util.Scanner;

public class contest {

	public static Scanner input = new Scanner(System.in);

	public static void main(String[] args) {

		int n = input.nextInt();
		int[] nums = new int[n];

		for (int i = 0; i < n; i++) {
			nums[i] = input.nextInt();
		}

		int firstMax = nums[0];

		for (int i = 0; i < n; i++) {
			if (firstMax < nums[i]) {
				firstMax = nums[i];
			}
		}

		int sum = 0 ;

		for (int i = 0; i < n ; i++){
			sum+=nums[i];
		}

		boolean found = true;
		int notFound = firstMax+1 ;

		for (int i = 1; i < firstMax; i++) {
			int max = firstMax - i;

			for (int j = 0; j < n&& max <= sum; j++) {

				if (max == nums[j]) {
					found = true;
					break;
				}
				else {
					found = false;
					notFound = max;
				}
			}
			if (!found){
				break;
			}
		}

		if (!found){
			System.out.println(notFound);
		}
		else if(found&& firstMax+1 >= sum)  {
			System.out.println(firstMax+1);
		}

	}

}


import java.util.Scanner;

public class contest {

	public static Scanner input = new Scanner(System.in);

	public static void main(String[] args) {

		int n = input.nextInt();
		int[] nums = new int[n];

		int[] re = new int[n];

		int moreThan = 0 ;

		for (int i = 0; i < n; i++) {
			nums[i] = input.nextInt();
		}

		for (int i = 0; i < n; i++) {
			if (nums[i]>n){
				moreThan++;
			}

			else {
				re[nums[i]-1]++;
			}
		}

		int needed = 0 ;

		for (int i = 0 ; i < n ; i++){

			if (re[i]==0){
				needed++;
			}
			else if (re[i]>1) {
				needed = (needed-re[i])+1;
				if (needed < 0 ){
					needed = 0;
				}
			}
		}

		needed = needed - moreThan;
		System.out.println(n+1-needed);

	}

}


import java.util.Scanner;

public class contest {

	public static Scanner input = new Scanner(System.in);

	public static void main(String[] args) {

		int n = input.nextInt();
		int[] nums = new int[n];

		for (int i = 0; i < n; i++) {
			nums[i] = input.nextInt();
		}

		int firstMax = nums[0];

		for (int i = 0; i < n; i++) {
			if (firstMax < nums[i]) {
				firstMax = nums[i];
			}
		}

		boolean found = true;
		int notFound = firstMax+1 ;

		for (int i = 1; i < firstMax; i++) {

			int max = firstMax - i;

			for (int j = 0; j < n && n>=max-1; j++) {

				if (max == nums[j]) {
					found = true;
					break;
				}
				else {
					found = false;
					notFound = max;
				}
			}
			if (!found){
				break;
			}
		}

		if (!found){
			System.out.println(notFound);
		}
		else if(found && n >=firstMax)  {
			System.out.println(firstMax+1);
		}

	}

}


import java.util.Scanner;

public class contest {

	public static Scanner input = new Scanner(System.in);

	public static void main(String[] args) {

		int n = input.nextInt();
		int[] nums = new int[n];

		for (int i = 0; i < n; i++) {
			nums[i] = input.nextInt();
		}

		int firstMax = nums[0];

		for (int i = 0; i < n; i++) {
			if (firstMax < nums[i]) {
				firstMax = nums[i];
			}
		}

		int sum = 0 ;

		for (int i = 0; i < n ; i++){
			sum+=nums[i];
		}

		boolean found = true;
		int notFound = firstMax+1 ;

		for (int i = 1; i < firstMax; i++) {
			int max = firstMax - i;

			for (int j = 0; j < n&& max <= sum&&n>=max-1; j++) {

				if (max == nums[j]) {
					found = true;
					break;
				}
				else {
					found = false;
					notFound = max;
				}
			}
			if (!found){
				break;
			}
		}

		if (!found){
			System.out.println(notFound);
		}
		else if(found&& firstMax+1 >= sum && n >=firstMax)  {
			System.out.println(firstMax+1);
		}

	}

}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

import org.omg.Messaging.SyncScopeHelper;

import java.math.BigInteger;
import java.util.Arrays;

public class Solution {

	private static final Scanner input = new Scanner(System.in);

	public static void main(String[] args) {

		int n = input.nextInt();

		int[] a = new int[n];

		int mex = 1;

		for (int i = 0 ; i < n ; i++) a[i] = input.nextInt();

		Arrays.sort(a);

		for (int i = 0 ; i < n ; i++) {

			 if (a[i]>=mex) {
				a[i]=mex;

			if (a[i]==mex) mex++;
			}
		}

		System.out.println(mex);

	}
}


import java.util.Scanner;

public class contest {

	public static Scanner input = new Scanner(System.in);

	public static void main(String[] args) {

		int n = input.nextInt();
		int[] nums = new int[n];

		for (int i = 0; i < n; i++) {
			nums[i] = input.nextInt();
		}

		boolean found = true;

		int i = n + 1;

		for (; i > 0; i--) {

			for (int j = 0; j < n; j++) {

				if (nums[j] == i) {
					found = true;
					break;
				} else {
					found = false;
				}

			}
			if (!found){
				break;
			}
		}

		System.out.println(i);

	}

}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

import org.omg.Messaging.SyncScopeHelper;

import java.math.BigInteger;

public class Solution {

	private static final Scanner input = new Scanner(System.in);

	public static void main(String[] args) {

		int n = input.nextInt();

		ArrayList<Integer> a = new ArrayList<>();

		int mex = 1;

		for (int i = 0 ; i < n ; i++) {
			a.add(input.nextInt());
		}

		Collections.sort(a);

		for (int i = 0 ; i < n ; i++) {

			if (a.get(i)>=mex) mex++;

		}

		System.out.println(mex);

	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author o_panda_o(emailofpanda@yahoo.com)
 */
public class Code_682B_AlyonaAndMex{
    public static void main(String[] args){
        InputStream inputStream=System.in;
        OutputStream outputStream=System.out;
        InputReader in=new InputReader(inputStream);
        OutputWriter out=new OutputWriter(outputStream);
        _682B_ solver=new _682B_();
        solver.solve(1,in,out);
        out.close();
    }

    static class _682B_{
        public void solve(int testNumber,InputReader in,OutputWriter out){
            /**
             * Date: 17th May 2017
             * Question number: 01
             * Start time: 5:46 AM
             * Submission-1: 6:03 AM(17 minutes)
             * Submission-2: 6:05 AM(19 minutes)
             */
            int n=in.nextInt();
            int array[]=in.nextSortedIntArray(n);
            int mex=1;
            if(n==1 || allOnes(array)){
                out.print(2);
                return;
            }
            for(int i=0;i<n;++i){
                if(array[i]>=mex) array[i]=mex;
                while(i<n && array[i]==mex) ++i;
                ++mex;
            }
            out.print(mex+1);
        }

        public boolean allOnes(int array[]){
            for(int i=0;i<array.length;++i)
                if(array[i]!=1)
                    return false;
            return true;
        }

    }

    static class InputReader{
        private InputStream stream;
        private byte[] buf=new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream){
            this.stream=stream;
        }

        public int read(){
            if(numChars==-1){
                throw new InputMismatchException();
            }
            if(curChar>=numChars){
                curChar=0;
                try{
                    numChars=stream.read(buf);
                }catch(IOException e){
                    throw new InputMismatchException();
                }
                if(numChars<=0){
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt(){
            int c=read();
            while(isSpaceChar(c)){
                c=read();
            }
            int sgn=1;
            if(c=='-'){
                sgn=-1;
                c=read();
            }
            int res=0;
            do{
                if(c<'0' || c>'9'){
                    throw new InputMismatchException();
                }
                res*=10;
                res+=c-'0';
                c=read();
            }while(!isSpaceChar(c));
            return res*sgn;
        }

        public boolean isSpaceChar(int c){
            if(filter!=null){
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c){
            return c==' ' || c=='\n' || c=='\r' || c=='\t' || c==-1;
        }

        public int[] nextIntArray(int n){
            int[] array=new int[n];
            for(int i=0;i<n;++i) array[i]=nextInt();
            return array;
        }

        public int[] nextSortedIntArray(int n){
            int array[]=nextIntArray(n);
            Arrays.sort(array);
            return array;
        }

        public interface SpaceCharFilter{
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter{
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream){
            writer=new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer){
            this.writer=new PrintWriter(writer);
        }

        public void close(){
            writer.close();
        }

        public void print(int i){
            writer.print(i);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author o_panda_o(emailofpanda@yahoo.com)
 */
public class Code_682B_AlyonaAndMex{
    public static void main(String[] args){
        InputStream inputStream=System.in;
        OutputStream outputStream=System.out;
        InputReader in=new InputReader(inputStream);
        OutputWriter out=new OutputWriter(outputStream);
        _682B_ solver=new _682B_();
        solver.solve(1,in,out);
        out.close();
    }

    static class _682B_{
        public void solve(int testNumber,InputReader in,OutputWriter out){
            /**
             * Date: 17th May 2017
             * Question number: 01
             * Start time: 5:46 AM
             * Submission-1: 6:03 AM(17 minutes)
             * Submission-2: 6:05 AM(19 minutes)
             */
            int n=in.nextInt();
            int array[]=in.nextSortedIntArray(n);
            int mex=1;
            if(n==1){
                out.print(2);
                return;
            }
            for(int i=0;i<n;++i){
                if(array[i]>=mex) array[i]=mex;
                while(i<n && array[i]==mex) ++i;
                ++mex;
            }
            out.print(mex+1);
        }

    }

    static class InputReader{
        private InputStream stream;
        private byte[] buf=new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream){
            this.stream=stream;
        }

        public int read(){
            if(numChars==-1){
                throw new InputMismatchException();
            }
            if(curChar>=numChars){
                curChar=0;
                try{
                    numChars=stream.read(buf);
                }catch(IOException e){
                    throw new InputMismatchException();
                }
                if(numChars<=0){
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt(){
            int c=read();
            while(isSpaceChar(c)){
                c=read();
            }
            int sgn=1;
            if(c=='-'){
                sgn=-1;
                c=read();
            }
            int res=0;
            do{
                if(c<'0' || c>'9'){
                    throw new InputMismatchException();
                }
                res*=10;
                res+=c-'0';
                c=read();
            }while(!isSpaceChar(c));
            return res*sgn;
        }

        public boolean isSpaceChar(int c){
            if(filter!=null){
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c){
            return c==' ' || c=='\n' || c=='\r' || c=='\t' || c==-1;
        }

        public int[] nextIntArray(int n){
            int[] array=new int[n];
            for(int i=0;i<n;++i) array[i]=nextInt();
            return array;
        }

        public int[] nextSortedIntArray(int n){
            int array[]=nextIntArray(n);
            Arrays.sort(array);
            return array;
        }

        public interface SpaceCharFilter{
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter{
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream){
            writer=new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer){
            this.writer=new PrintWriter(writer);
        }

        public void close(){
            writer.close();
        }

        public void print(int i){
            writer.print(i);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author o_panda_o(emailofpanda@yahoo.com)
 */
public class Code_682B_AlyonaAndMex{
    public static void main(String[] args){
        InputStream inputStream=System.in;
        OutputStream outputStream=System.out;
        InputReader in=new InputReader(inputStream);
        OutputWriter out=new OutputWriter(outputStream);
        _682B_ solver=new _682B_();
        solver.solve(1,in,out);
        out.close();
    }

    static class _682B_{
        public void solve(int testNumber,InputReader in,OutputWriter out){
            /**
             * Date: 17th May 2017
             * Question number: 01
             * Start time: 5:46 AM
             * Submission-1: 6:03 AM( minutes)
             */
            int n=in.nextInt();
            int array[]=in.nextSortedIntArray(n);
            int mex=1;
            for(int i=0;i<n;++i){
                if(array[i]>=mex) array[i]=mex;
                while(i<n && array[i]==mex) ++i;
                ++mex;
            }
            out.print(mex+1);
        }

    }

    static class InputReader{
        private InputStream stream;
        private byte[] buf=new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream){
            this.stream=stream;
        }

        public int read(){
            if(numChars==-1){
                throw new InputMismatchException();
            }
            if(curChar>=numChars){
                curChar=0;
                try{
                    numChars=stream.read(buf);
                }catch(IOException e){
                    throw new InputMismatchException();
                }
                if(numChars<=0){
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt(){
            int c=read();
            while(isSpaceChar(c)){
                c=read();
            }
            int sgn=1;
            if(c=='-'){
                sgn=-1;
                c=read();
            }
            int res=0;
            do{
                if(c<'0' || c>'9'){
                    throw new InputMismatchException();
                }
                res*=10;
                res+=c-'0';
                c=read();
            }while(!isSpaceChar(c));
            return res*sgn;
        }

        public boolean isSpaceChar(int c){
            if(filter!=null){
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c){
            return c==' ' || c=='\n' || c=='\r' || c=='\t' || c==-1;
        }

        public int[] nextIntArray(int n){
            int[] array=new int[n];
            for(int i=0;i<n;++i) array[i]=nextInt();
            return array;
        }

        public int[] nextSortedIntArray(int n){
            int array[]=nextIntArray(n);
            Arrays.sort(array);
            return array;
        }

        public interface SpaceCharFilter{
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter{
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream){
            writer=new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer){
            this.writer=new PrintWriter(writer);
        }

        public void close(){
            writer.close();
        }

        public void print(int i){
            writer.print(i);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Collections;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author o_panda_o(emailofpanda@yahoo.com)
 */
public class Code_682B_AlyonaAndMex{
    public static void main(String[] args){
        InputStream inputStream=System.in;
        OutputStream outputStream=System.out;
        InputReader in=new InputReader(inputStream);
        OutputWriter out=new OutputWriter(outputStream);
        _682B_ solver=new _682B_();
        solver.solve(1,in,out);
        out.close();
    }

    static class _682B_{
        public void solve(int testNumber,InputReader in,OutputWriter out){
            int n=in.nextInt();
            ArrayList<Integer> integers=new ArrayList<>();
            for(int i=0;i<n;++i) integers.add(in.nextInt());
            Collections.sort(integers);
            int current=0;
            int i=0;
            while(i<n){
                while(i<n && integers.get(i)==current) ++i;
                if(i<n && integers.get(i)>current){
                    ++current;
                    ++i;
                }
            }
            out.print(current+1);
        }

    }

    static class InputReader{
        private InputStream stream;
        private byte[] buf=new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream){
            this.stream=stream;
        }

        public int read(){
            if(numChars==-1){
                throw new InputMismatchException();
            }
            if(curChar>=numChars){
                curChar=0;
                try{
                    numChars=stream.read(buf);
                }catch(IOException e){
                    throw new InputMismatchException();
                }
                if(numChars<=0){
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt(){
            int c=read();
            while(isSpaceChar(c)){
                c=read();
            }
            int sgn=1;
            if(c=='-'){
                sgn=-1;
                c=read();
            }
            int res=0;
            do{
                if(c<'0' || c>'9'){
                    throw new InputMismatchException();
                }
                res*=10;
                res+=c-'0';
                c=read();
            }while(!isSpaceChar(c));
            return res*sgn;
        }

        public boolean isSpaceChar(int c){
            if(filter!=null){
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c){
            return c==' ' || c=='\n' || c=='\r' || c=='\t' || c==-1;
        }

        public interface SpaceCharFilter{
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter{
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream){
            writer=new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer){
            this.writer=new PrintWriter(writer);
        }

        public void close(){
            writer.close();
        }

        public void print(int i){
            writer.print(i);
        }

    }
}