#include <bits/stdc++.h>

using namespace std;

int main()
{
   int N;
   cin >> N;
   vector<int> balloons(N);
   for (int i = 0; i < N; i++)
      cin >> balloons[i];

   int n = balloons.size();
   balloons.insert(balloons.begin(), 1);
   balloons.push_back(1);
   vector<vector<int>> dp(balloons.size(), vector<int>(balloons.size(), 0));
   for (int len = 1; len <= n; ++len)
   {
      for (int left = 1; left <= n - len + 1; ++left)
      {
         int right = left + len - 1;
         for (int k = left; k <= right; ++k)
            dp[left][right] = max(dp[left][right], balloons[left - 1] * balloons[k] * balloons[right + 1] + dp[left][k - 1] + dp[k + 1][right]);
      }
   }

   cout << dp[1][n] << endl;

   return 0;
}