intmain() { for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) { if (i == j) f[i][i] = g[i][i] = 0; else { f[i][j] = PosInf; g[i][j] = -PosInf; } }
std::cin >> n; for (int i = 1; i <= n; i++) { std::cin >> a[i]; a[i + n] = a[i]; } for (int i = 1; i <= n * 2; i++) s[i] = s[i - 1] + a[i];
for (int len = 1; len <= n; len++) for (int l = 1; l + len - 1 <= n * 2; l++) { int r = l + len - 1; for (int k = l; k < r; k++) { f[l][r] = std::min(f[l][r], f[l][k] + f[k + 1][r] + s[r] - s[l - 1]); g[l][r] = std::max(g[l][r], g[l][k] + g[k + 1][r] + s[r] - s[l - 1]); } }
int wMin = PosInf, wMax = -PosInf; for (int l = 1; l <= n; l++) { wMin = std::min(wMin, f[l][l + n - 1]); wMax = std::max(wMax, g[l][l + n - 1]); } std::cout << wMin << std::endl; std::cout << wMax << std::endl; return0; }
intmain() { std::cin >> n; for (int i = 1; i <= n; i++) { std::cin >> a[i]; a[i + n] = a[i]; }
for (int len = 3; len <= n + 1; len++) for (int l = 1; l + len - 1 <= n * 2; l++) { int r = l + len - 1; for (int k = l + 1; k < r; k++) f[l][r] = std::max(f[l][r], f[l][k] + f[k][r] + a[l] * a[k] * a[r]); }
int wMax = -PosInf; for (int l = 1; l <= n; l++) wMax = std::max(wMax, f[l][l + n]); std::cout << wMax << std::endl; return0; }
voidAdd(longlong a[], longlong b[]) { staticlonglong c[M]; memset(c, 0, sizeof(c)); for (int i = 0, t = 0; i < M; i++) { t += a[i] + b[i]; c[i] = t % 10; t /= 10; } memcpy(a, c, sizeof(c)); }
voidMul(longlong a[], longlong b) { staticlonglong c[M]; memset(c, 0, sizeof(c)); longlong t = 0; for (int i = 0; i < M; i++) { t += a[i] * b; c[i] = t % 10; t /= 10; } memcpy(a, c, sizeof(c)); }
intComp(longlong a[], longlong b[]) { for (int i = M - 1; i >= 0; i--) if (a[i] > b[i]) return1; elseif (a[i] < b[i]) return-1; return0; }
intmain() { std::cin >> n; for (int i = 1; i <= n; i++) std::cin >> w[i];
longlong temp[M]; for (int len = 3; len <= n + 1; len++) for (int l = 1; l + len - 1 <= n; l++) { int r = l + len - 1; f[l][r][M - 1] = 1; for (int k = l + 1; k < r; k++) { memset(temp, 0, sizeof(temp)); temp[0] = w[l]; Mul(temp, w[k]); Mul(temp, w[r]); Add(temp, f[l][k]); Add(temp, f[k][r]); if (Comp(f[l][r], temp) > 0) memcpy(f[l][r], temp, sizeof(temp)); } }
int k = M - 1; while (k > 0 && f[1][n][k] == 0) k--; for (int i = k; i >= 0; i--) std::cout << f[1][n][i]; std::cout << std::endl; return0; }
int n, s[M][M]; double f[M][M][M][M][N]; double average;
inlinedoubleCalc(int x1, int y1, int x2, int y2) { double sum = s[x2][y2] - s[x2][y1 - 1] - s[x1 - 1][y2] + s[x1 - 1][y1 - 1]; return (sum - average) * (sum - average) / n; }
inlinedoubleSearch(int x1, int y1, int x2, int y2, int k) { double &v = f[x1][y1][x2][y2][k]; if (v >= 0) return v; if (k == 1) return v = Calc(x1, y1, x2, y2);
v = PosInf; for (int i = x1; i < x2; i++) { v = std::min(v, Search(x1, y1, i, y2, k - 1) + Calc(i + 1, y1, x2, y2)); v = std::min(v, Search(i + 1, y1, x2, y2, k - 1) + Calc(x1, y1, i, y2)); } for (int i = y1; i < y2; i++) { v = std::min(v, Search(x1, y1, x2, i, k - 1) + Calc(x1, i + 1, x2, y2)); v = std::min(v, Search(x1, i + 1, x2, y2, k - 1) + Calc(x1, y1, x2, i)); }
return v; }
intmain() { std::cin >> n; for (int i = 1; i <= m; i++) for (int j = 1; j <= m; j++) { std::cin >> s[i][j]; s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1]; }
memset(f, -1, sizeof(f)); average = (double)s[m][m] / n;
intCalc(int x1, int y1, int x2, int y2) { double sum = s[x2][y2] - s[x2][y1 - 1] - s[x1 - 1][y2] + s[x1 - 1][y1 - 1]; return sum * sum; }
doubleSearch(int x1, int y1, int x2, int y2, int k) { double &v = f[x1][y1][x2][y2][k]; if (v >= 0) return v; if (k == 1) return v = Calc(x1, y1, x2, y2);
v = PosInf; for (int i = x1; i < x2; i++) { v = std::min(v, Search(x1, y1, i, y2, k - 1) + Calc(i + 1, y1, x2, y2)); v = std::min(v, Search(i + 1, y1, x2, y2, k - 1) + Calc(x1, y1, i, y2)); } for (int i = y1; i < y2; i++) { v = std::min(v, Search(x1, y1, x2, i, k - 1) + Calc(x1, i + 1, x2, y2)); v = std::min(v, Search(x1, i + 1, x2, y2, k - 1) + Calc(x1, y1, x2, i)); }
return v; }
intmain() { std::cin >> n; for (int i = 1; i <= m; i++) for (int j = 1; j <= m; j++) { std::cin >> s[i][j]; s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1]; }