int ans; intmain(){ cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i], a[i + n] = a[i]; for (int l = 2; l <= n; ++l) for (int i = 1; i + l - 1 <= 2 * n - 1; ++i) { int j = i + l - 1; for (int k = i; k < j; ++k) f[i][j] = max(f[i][j], f[i][k] + f[k + 1][j] + a[i] * a[k + 1] * a[j + 1]); } for (int i = 1; i <= n; ++i) ans = max(ans, f[i][i + n - 1]); cout << ans << endl; return0; }