#include<iostream> using namespace std; int main() { int sum = 0; int n; cin >> n; int V[n]; for (int i = 0; i < n; cin >> V[i++]); for (int i = 0, j = n-1, k = 1; k <= n; k++ ) { if (V[i] < V[j]) { sum += V[i] * k; i++; } else { sum += V[j] * k; j--; } } cout << sum; return 0; }