#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <utility>
#include <stdbool.h>

using namespace std;

int main(void)
{
    int n;
    cin >> n;

    vector<pair<int, int>> a;
    int temp;
    for(int i = 0; i < n; i ++)
    {
        cin >> temp;
        a.push_back(pair<int, int>{temp, i});
    }

    bool flag[n] = {false};
    int sum = 0;
    for(int i = 0; i < n; i ++)
    {
        int left = a[i].second;
        int right = (n - 1)- a[i].second;

		while(true)
        {
	        if (left < 0 && right < 0)
               break;

            if (left >= right)
            {
		        if (left >= 0 && flag[a[i].second - left] == false)
		        {
		           flag[a[i].second - left] = true;
		           sum += a[i].first * left;
                   break;
		        }
                else
	                left --;
            }
            else
            {
                sum += 1;
                if (right >= 0 && flag[a[i].second + right] == false)
	            {
	                flag[a[i].second + right] = true;
                    sum += a[i].first * right;
                    break;
		        }
	            else
                    right --;
            }
	    }	       
    }

    cout << sum << endl;

    return 0;
}