样例全过了,提交10分,求调,必关
#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using i128 = __int128;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define frep(i, b, a) for (int i = b; i >= a; i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define s second
#define f first
const int inf = (1 << 30) - 1;
const ll INF = 1LL << 60LL;
const int mod = 998244353;
using namespace std;
const int N = 110;
int n, a[N];
ll ans, dp[N][N];
int main() {
scanf("%d", &n);
rep(i, 1, n) scanf("%d", &a[i]), a[n + i] = a[i];
n *= 2;
rep(l, 1, n) {
rep(r, l + 1, n) {
rep(k, l, r - 1) dp[l][r] = max(dp[l][r], dp[l][k] + dp[k + 1][r] + a[l] * a[r + 1] * a[k + 1]);
ans = max(ans, dp[l][r]);
}
}
printf("%lld\n", ans);
}