#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<i64> a(n);
	for(int i = 0; i < n; i++) scanf("%lld", &a[i]);

	i64 ans = 0;
	std::vector<int> order(2 * n);
	for(int i = 0; i < n; i++) order[i] = order[i + n] = i;
	for(int i = 0; i < n; i++) {
		i64 tmp = 0;
		for(int j = 0; j < n; j++) {
			tmp += a[j] * std::abs(j - order[i + j]);
		}
		ans = std::max(ans, tmp);
	}

	printf("%lld\n", ans);
	return 0;
}
