#include #include #include #include using namespace std; typedef long long ll; const int maxn = 505; ll potions[maxn]; ll dp[maxn][maxn]; ll sum(int i, int j) { ll result = 0; for(int k = i; k <= j; k++) { result += potions[k]; } return result % 100; } ll rec(int i, int j) { if(i + 1 == j) { return potions[i] * potions[j]; } if(i >= j) { return 0; } if(dp[i][j] != -1) { return dp[i][j]; } ll result = 2e15; for(int k = i; k < j; k++) { result = min(result, rec(i, k) + rec(k + 1, j) + sum(i, k) * sum(k + 1, j)); } return dp[i][j] = result; } int main() { ios_base::sync_with_stdio(false); int n; while(cin >> n) { for(int i = 0; i < n; i++) { cin >> potions[i]; } memset(dp, -1, sizeof dp); cout << rec(0, n - 1) << endl; } return 0; }