#define ll long long const ll inf = 1e18; usingnamespace std; int n, m, sx, sy; int dx[4] = {0, 0, 1, -1}; int dy[4] = {1, -1, 0, 0}; bool book[302][302]; ll a[302][302], dp[302][302][24], pat[302][302];
ll read(){ ll s = 0, w = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { s = (s << 1) + (s << 3) + ch - '0'; ch = getchar(); } return s * w; }
inlineboolcheck(int x, int y){ if (x < 0 || x > m || y < 0 || y > n) returnfalse; elseif (a[x][y] == -1) returnfalse; elseif (x == sx && y == sy) returnfalse; elsereturntrue; }
voiddfs(int x, int y){ for (int i = 0; i < 4; i++) { int nx = x + dx[i]; int ny = y + dy[i]; if (nx < 0 || nx > m || ny < 0 || ny > n) continue; if (book[nx][ny] || a[nx][ny] == -1 || a[nx][ny] == 0) continue; book[nx][ny] = true; dfs(nx, ny); } }
intmain(){ n = read(); m = read(); for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { a[i][j] = read(); if (a[i][j] == -1) { for (int k = 0; k <= 23; k++) { dp[i][j][k] = -inf; } } elseif (a[i][j] == 0) { sx = i; sy = j; dp[i][j][0] = 0; } } } book[sx][sy] = true; dfs(sx, sy); for (int k = 1; k <= 23; k++) { for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { if (abs(i - sx) + abs(j - sy) > k) continue; if (!book[i][j]) continue; ll cnt = -inf; if (check(i, j - 1)) cnt = max(cnt, dp[i][j - 1][k - 1]); if (check(i, j + 1)) cnt = max(cnt, dp[i][j + 1][k - 1]); if (check(i + 1, j)) cnt = max(cnt, dp[i + 1][j][k - 1]); if (check(i - 1, j)) cnt = max(cnt, dp[i - 1][j][k - 1]); dp[i][j][k] = cnt + a[i][j]; } } } ll ans = -inf; for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { ans = max(dp[i][j][23], ans); } } cout << ans; return0; }
bign operator+(const bign &b) { bign c = *this; int i; for (int i = 0; i < b.len; i++) { c.d[i] += b.d[i]; if (c.d[i] > 9) c.d[i++] %= 10, c.d[i + 1]++; } while (c.d[i] > 9) c.d[i++] %= 10, c.d[i]++; c.len = max(len, b.len); if (c.d[i] && c.len <= i) c.len = i + 1; return c; }
bign operator-(const bign &b) { bign c = *this; int i; for (int i = 0; i < b.len; i++) { c.d[i] -= b.d[i]; if (c.d[i] < 0) c.d[i] += 10, c.d[i + 1]--; } while (c.d[i] < 0) c.d[i++] += 10, c.d[i]--; clean(); return c; }
bign operator*(const bign &b) const { int i, j; bign c; c.len = len + b.len; for (j = 0; j < b.len; j++) { for (i = 0; i < len; i++) c.d[i + j] += d[i] * b.d[j]; } for (i = 0; i < c.len - 1; i++) c.d[i + 1] += c.d[i] / 10, c.d[i] %= 10; c.clean(); return c; }
bign operator/(const bign &b) { int i, j; bign c = *this, a = 0; for (i = len - 1; i >= 0; i--) { a = a * 10 + d[i]; for (j = 0; j < 10; j++) if (a < b * (j + 1)) break; c.d[i] = j; a = a - b * j; } c.clean(); return c; }
booloperator<(const bign &b) const { if (len != b.len) return len < b.len; for (int i = len - 1; i >= 0; i--) { if (d[i] != b.d[i]) return d[i] < b.d[i]; } returnfalse; }
booloperator>(const bign &b) const { return b < *this; }
string str()const{ char s[N] = {}; for (int i = 0; i < len; i++) s[len - i - 1] = d[i] + '0'; return s; }
};
istream &operator>>(istream &in, bign &x) { string s; in >> s; x = s.c_str(); return in; }
intmain(){ //freopen("a.in","r",stdin); bign n, m; cin >> m >> n; n = n / m; int cnt = 0; while (!(n < 2)) { cnt++; n = n / 2; while (!(n < 8192)) { n = n / 8192; cnt += 13; } } cnt++; if (cnt % 6 == 1) printf("0"); else { int ans = 1; int num = cnt % 6 - 1; if (num < 0) num += 6; for (int i = 1; i <= num; i++) { ans *= 2; } printf("%d", ans); } return0; }
#define ll long long usingnamespace std; ll n, k; ll w[100005];
ll read(){ ll s = 0, w = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { s = (s << 1) + (s << 3) + ch - '0'; ch = getchar(); } return s * w;
}
priority_queue<ll> q;
intmain(){ n = read(), k = read(); for (int i = 1; i <= n; i++) { w[i] = read(); q.push(w[i]); } while (q.size() != 1) { ll a, b, c; a = q.top(); q.pop(); b = q.top(); q.pop(); c = (a + b) / k; q.push(c); } cout << q.top(); return0; }