        #include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second
        #define pb push_back
        #define ld long double
        #define int long long
        #define print(t) cout << "Case #" << t << ": ";
        int32_t main()
        {
            tani_nachi_ke  
            
            int n;
            cin >> n;
            int dp[n+1][2] = {0};
            int a[n];
            for(int i = 0; i < n; i++)
                cin >> a[i];

            priority_queue<pair<int,pair<int,int>>> pq;
            for(int i = 0; i < n; i++)
            {
                for(int j = 0; j < n; j++)
                    pq.push({a[i]*abs(i-j), {i,j}});
            }
            int sum = 0;
            while(!pq.empty())
            {
                auto u = pq.top();
                pq.pop();
                if(dp[u.ss.ff][0] || dp[u.ss.ss][1])
                    continue;
                else 
                {
                    int i = u.ss.ff;
                    int j = u.ss.ss;
                    int d = abs(i-j);
                    if(i - d >= 0 && i + d < n)
                    {
                        if(j > i)
                        {
                            if(dp[i-d][0] == 1 && dp[i-d][1] == 0)
                                continue;
                        }
                        else
                        {
                            if(dp[i+d][0] == 1 && dp[i+d][1] == 0)
                                continue;
                        }
                    }
                    // cout << u.ff << '\n';
                    // cout << u.ss.ff << " " << u.ss.ss << '\n';
                    dp[u.ss.ff][0] = dp[u.ss.ss][1] = 1;
                    sum += u.ff;
                }
            }
            cout << sum << endl;


           return 0;
        }
          