#include <iostream>
using namespace std;
int main(){
int n;
cout << "No.of elements \n";
cin >> n;
int a[n];
for (int i = 0;i<n;i++)
cin >> a[i];
int sum[n];
int total = 0;
for (int i = 0;i<n;i++)
total += a[i];
sum[0]=0;
for (int i = 0;i<n;i++)
sum[0] = sum[0] + i*a[i];
for (int i = 1;i<n;i++)
sum[i] = sum[i-1] - total + n*a[i-1];
int maxi = sum[0];
for (int i = 1;i<n;i++)
if (sum[i] > maxi)
maxi = sum[i];
cout << maxi;
}