malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<int> V(n);     for (int i = 0; i < m; ++i) {       int k;       cin >> k;       V[k - 1]++;     }     int mn = 1e9;     for (int i = 0; i < n; ++i) mn = min(mn, V[i]);     cout << mn <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000 * 1000];   int main() {     int t;     cin >> t;     double s = 0;     for (int i = 0; i < t; i++) {       cin >> a[i];       s += a[i];     }     vector<int> ind;     for (int i = 0; i < t; i++) {       double p = ((s - a[i]) / (t - 1));       if (a[i] == p) ind.push_back(i + 1);     }     cout << ind.size() << endl;     for (int i = 0; i < ind.size(); i++) {       cout << ind[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   int n;   long long pts[MAXN][2];   unsigned long long area(int i, int j, int k) {     return (abs(pts[i][0] * pts[j][1] + pts[j][0] * pts[k][1] +                 pts[k][0] * pts[i][1] - pts[i][1] * pts[j][0] -                 pts[j][1] * pts[k][0] - pts[k][1] * pts[i][0]));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; ++i) cin >> pts[i][0] >> pts[i][1];     int x = -1, y = -1;     long long c = 2e9, d = 2e9;     for (int i = 0; i < n; ++i) {       if (pts[i][0] < c) {         c = pts[i][0], d = pts[i][1], x = i;       } else if (pts[i][0] == c && pts[i][1] < d) {         c = pts[i][0], d = pts[i][1], x = i;       }     }     c = 2e9, d = 2e9;     for (int i = 0; i < n; ++i) {       if (i == x) continue;       if (pts[i][0] < c) {         c = pts[i][0], d = pts[i][1], y = i;       } else if (pts[i][0] == c && pts[i][1] < d) {         c = pts[i][0], d = pts[i][1], y = i;       }     }     long long minarea = 6e18;     int ind = -1;     for (int i = 0; i < n; ++i) {       if (i == x || i == y) continue;       long long a = area(x, y, i);       if (a == 0) continue;       if (a < minarea) {         minarea = a;         ind = i;       }     }     cout << x + 1 <<     << y + 1 <<     << ind + 1 << endl;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const char E =   n ;   const int N = 20015;   const int NN = 1000000;   const long long md = 1e9 + 7;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     int tttt;     cin >> tttt;     while (tttt--) {       int n;       cin >> n;       vector<long long> a(n + 5);       for (int i = 1; i <= n; i++) {         cin >> a[i];       }       long long l = 1, mn = 1001007000;       long long mx = 0;       for (int i = 2; i <= n; i++) {         if (a[i] < a[l] && i != n) {           mn = min(mn, a[i]);           continue;         }         mn = min(mn, a[i]);         mx = max(mx, a[l] - mn);         mn = 1001007000;         l = i;       }       long long ans = 0;       long long t = 0;       while (t < mx) {         ans++;         t += (1 << (ans - 1));       }       cout << ans << E;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[5011][5011];   void solve() {     long long n, m;     cin >> n >> m;     string s1, s2;     cin >> s1 >> s2;     s1 =  .  + s1;     s2 =  .  + s2;     long long ans = 0;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= m; j++) {         dp[i][j] = max({0ll, dp[i - 1][j] - 1, dp[i][j - 1] - 1});         if (s1[i] == s2[j])           dp[i][j] = max(               {0ll, dp[i - 1][j] - 1, dp[i][j - 1] - 1, dp[i - 1][j - 1] + 2});         ans = max(ans, dp[i][j]);       }     }     cout << ans;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       int a[3];       cin >> a[0] >> a[1] >> a[2];       sort(a, a + 3);       if (a[2] == a[0] + a[1])         cout <<  YES ;       else if (a[2] == a[1] && a[0] % 2 == 0)         cout <<  YES ;       else if (a[0] == a[1] && a[2] % 2 == 0)         cout <<  YES ;       else         cout <<  NO ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 15;   const int LL = 1e9 + 15;   const int SSS = 1e6 + 15;   int dx[10] = {0, 1, -1, 1, -1, 2, -2, 2, -2};   int dy[10] = {0, 2, 2, -1, -1, 1, 1, -1, -1};   int n, ii, a[5010], ans[5010], mx, st[5010];   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       mx = 0;       ii = 0;       for (int j = 1; j <= n; ++j) st[j] = 0;       for (int j = i; j >= 1; --j) {         ++st[a[j]];         if (st[a[j]] > mx || (st[a[j]] == mx && ii > a[j])) {           mx = st[a[j]];           ii = a[j];         }         ++ans[ii];       }     }     for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<char> v;     long long ca = 0, ci = 0, cf = 0;     for (long long i = 0; i < n; i++) {       char a;       cin >> a;       v.push_back(a);       if (a ==  A ) ca++;       if (a ==  I ) ci++;       if (a ==  F ) cf++;     }     if (ca + cf == n)       cout << ca;     else {       if (ci > 1)         cout << 0;       else         cout << ci;     }     for (long long i = 1; i < n; i++) {     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const int MAXA = 2e5 + 10;   const int MAX = 2e3 + 10;   int n, m, k;   int a[MAXA];   int M = 0;   pair<int, int> p[MAX];   long long sum[MAX];   long long memo[MAX];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> k;     for (int i = 0; i < n; i++) cin >> a[i];     vector<int> f(MAX, -1);     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       if (x > MAX) continue;       f[x] = max(f[x], y);     }     for (int i = 1; i < MAX; i++) {       if (f[i] == -1) continue;       p[M++] = {i, f[i]};     }     partial_sort(&a[0], &a[min(n, MAX)], &a[n]);     sum[0] = 0;     for (int i = 0; i < k; i++) {       sum[i + 1] = sum[i] + a[i];     }     memo[k] = 0;     for (int i = k - 1; i >= 0; i--) {       long long ans = a[i] + memo[i + 1];       for (int j = 0; j < M; j++) {         if (i + p[j].first > k) break;         long long r = memo[i + p[j].first];         ans = min(ans, sum[i + p[j].first] - sum[i + p[j].second] + r);       }       memo[i] = ans;     }     cout << memo[0] <<   n ;     exit(0);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, e, f, g;     cin >> a >> b >> c;     d = a + b + c;     e = 2 * (a + b);     f = 2 * (b + c);     g = 2 * (c + a);     if (d <= e && d <= f && d <= g) {       cout << d;     } else if (e <= f && e <= g) {       cout << e;     } else if (f <= g) {       cout << f;     } else {       cout << g;     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T BigMod(T b, T p, T m) {     if (p == 0) return 1;     if (p % 2 == 0) {       T s = BigMod(b, p / 2, m);       return ((s % m) * (s % m)) % m;     }     return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;   }   template <typename T>   T ModInv(T b, T m) {     return BigMod(b, m - 2, m);   }   template <typename T>   T gcd(T a, T b) {     if (!b) return a;     return gcd(b, a % b);   }   int a[1004];   vector<int> v;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t, i, j, e, n, k, l, ed, res, p, y, n1, n2, sum, cnt, dif, idx, x, m, val,         cst, st, sz;     cin >> x;     for (i = 1; i <= x; i++) {       cin >> a[i];       if (i > 1) v.push_back(a[i] - a[i - 1]);     }     bool fl = 0;     sz = v.size();     for (i = 0; i <= sz - 1; i++) {       if (i > 0) {         if (v[i] == v[i - 1]) continue;         fl = 1;         break;       }     }     if (fl)       cout << a[x] << endl;     else       cout << a[x] + v[sz - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, s, x, y, nb;   vector<pair<long long, long long> > t, v;   long long dp[102];   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     return a.first + a.second > b.first + b.second;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> s;     for (long long i = 0; i < n; i++) {       cin >> x >> y;       if (y >= 0) {         t.push_back(make_pair(x, y));       } else {         v.push_back(make_pair(y, x));       }     }     sort(t.begin(), t.end());     for (long long i = 0; i < t.size(); i++) {       if (t[i].first > s) break;       s += t[i].second;       nb++;     }     sort(v.begin(), v.end(), cmp);     n = v.size();     for (long long i = 1; i < n + 1; i++) dp[i] = -1;     dp[0] = s;     for (long long i = 0; i < n; i++) {       for (long long j = i + 1; j > 0; j--) {         if (dp[j - 1] >= v[i].second) dp[j] = max(dp[j], dp[j - 1] + v[i].first);       }     }     long long i;     for (i = n; dp[i] == -1; i--)       ;     cout << nb + i <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct dulieu {     long int gt, tt;   };   long int n;   dulieu a[3 * 100005];   bool sx1(dulieu a, dulieu b) { return a.gt < b.gt; }   bool sx2(dulieu a, dulieu b) { return a.tt < b.tt; }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i].gt;       a[i].tt = i;     }     sort(a, a + n, sx1);     for (int i = 0; i < n; i++)       if (a[i].gt <= a[i - 1].gt) a[i].gt = a[i - 1].gt + 1;     sort(a, a + n, sx2);     for (int i = 0; i < n; i++) cout << a[i].gt <<    ;   }
#include <bits/stdc++.h>   using namespace std;   char a[1001], b[1001];   int main() {     int sa, sb, i, j, ta = 0, tb = 0;     cin >> a >> b;     sa = strlen(a);     sb = strlen(b);     for ((i) = 0; (i) < (sa); (i)++)       if (a[i] ==  1 ) ta++;     for ((i) = 0; (i) < (sb); (i)++)       if (b[i] ==  1 ) tb++;     if (ta >= tb)       cout <<  YES  << endl;     else if (ta % 2 && tb == ta + 1)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> tree[100005];   int bad[100005];   vector<int> result;   int SubTree[100005];   int dfs(int v, int pv) {     SubTree[v] = (int)(bad[v] == 1);     for (auto u : tree[v]) {       if (u == pv) continue;       SubTree[v] += dfs(u, v);     }     if (SubTree[v] == 1) result.push_back(v);     return SubTree[v];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int N;     cin >> N;     for (int i = 0; i < N - 1; i++) {       int a, b, c;       cin >> a >> b >> c;       tree[a].push_back(b);       tree[b].push_back(a);       if (c == 2) {         bad[a] = bad[b] = 1;       }     }     dfs(1, 0);     cout << result.size() <<   n ;     for (auto i : result) cout << i <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int mod = 1000000007;   int N;   vector<int> g[100001];   vector<int> time_in(100001);   vector<int> time_out(100001);   int cnt;   void dfs(int v) {     cnt++;     time_in[v] = cnt;     for (int i : g[v]) {       if (time_in[i] == 0) dfs(i);     }     cnt++;     time_out[v] = cnt;   }   void slv() {     cin >> N;     if (N % 2) {       cout << -1;       return;     }     int x, y;     for (int i = 1; i <= N - 1; i++) {       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     for (int i = 1; i <= N; i++) {       if (g[i].size() == 1) {         dfs(i);         break;       }     }     int ans = 0;     for (int i = 1; i <= N; i++) {       int cur = time_out[i] - time_in[i] + 1;       if (cur == 0) continue;       if (cur % 4 == 0) {         ans++;       }     }     cout << (ans == 0 ? -1 : ans - 1);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int T = 1;     while (T--) slv();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100009;   long long n, a[maxn], b[maxn], c[maxn], in[maxn], color[maxn];   void read(long long a[]) {     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);   }   void over() {     cout << -1;     exit(0);   }   vector<int> vec[maxn];   void dfs(int now, int fa, int se1, int se2) {     for (int i = 0; i < vec[now].size(); i++) {       int v = vec[now][i];       if (v == fa) continue;       color[v] = 6 - se1 - se2;       dfs(v, now, se2, color[v]);     }   }   long long ans = 1e18;   long long isok(int i, int s) {     if (s == 1)       return a[i];     else if (s == 2)       return b[i];     else       return c[i];   }   void DP(int q, int w, int e) {     long long temp = 0;     for (int i = 1; i <= n; i++)       if (color[i] == 1)         temp += isok(i, q);       else if (color[i] == 2)         temp += isok(i, w);       else         temp += isok(i, e);     ans = min(ans, temp);   }   void sovle(int q, int w, int e) {     long long temp = 0;     for (int i = 1; i <= n; i++)       if (color[i] == 1)         temp += isok(i, q);       else if (color[i] == 2)         temp += isok(i, w);       else         temp += isok(i, e);     if (temp != ans) return;     for (int i = 1; i <= n; i++)       if (color[i] == 1)         cout << q <<    ;       else if (color[i] == 2)         cout << w <<    ;       else         cout << e <<    ;     exit(0);   }   int main() {     cin >> n;     read(a), read(b), read(c);     for (int i = 1; i < n; i++) {       int l, r;       scanf( %d%d , &l, &r);       in[l]++, in[r]++;       vec[l].push_back(r);       vec[r].push_back(l);     }     for (int i = 1; i <= n; i++)       if (in[i] >= 3) over();     int last;     for (int i = 1; i <= n; i++)       if (in[i] == 1) last = i;     color[last] = 1, color[vec[last][0]] = 2;     dfs(vec[last][0], last, 1, 2);     for (int i = 1; i <= 3; i++)       for (int j = 1; j <= 3; j++) {         if (j == i) continue;         for (int q = 1; q <= 3; q++) {           if (q == i || q == j) continue;           DP(i, j, q);         }       }     cout << ans << endl;     for (int i = 1; i <= 3; i++)       for (int j = 1; j <= 3; j++) {         if (j == i) continue;         for (int q = 1; q <= 3; q++) {           if (q == i || q == j) continue;           sovle(i, j, q);         }       }   }
#include <bits/stdc++.h>   using namespace std;   unordered_set<int> int_set;   set<int, greater<int> > divisors;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     string a;     cin >> a;     if ((a.size()) == 1) {       cout << a << a <<   n ;       return 0;     } else {       string rev = string(a.rbegin(), a.rend());       a += rev;       cout << a <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 2.0 * acos(0.0);   const double EPS = 1e-6;   int a[100005];   bitset<100005> sign;   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , a + i);     long long sum = 0LL;     for (int i = n - 1; i >= 0; i--) {       if (abs(sum - a[i]) < abs(sum + a[i])) {         sum -= a[i];         sign[i] = true;       } else {         sum += a[i];       }     }     for (int i = 0; i < n; i++) printf( %c , sign[i] ^ (sum > 0) ?  +  :  - );     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     scanf( %d , &n);     int m = n / 3;     for (int i = 1; i <= m; i++) printf( %d %d n , 4, 2 * i);     for (int i = 1; i <= n - m; i++) printf( %d %d n , 1, i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   void solve() {     int m, n;     cin >> n >> m;     vector<long long> v(n);     for (int i = 0; i < n; i++) {       string s;       cin >> s;       for (char c : s) {         v[i] *= 2;         v[i] += c -  0 ;       }     }     long long need = ((1ll << m) - n - 1) / 2 + 1;     long long cur = (1ll << (m - 1)) - 1;     while (true) {       long long left = cur + 1;       bool flag = false;       for (int i = 0; i < n; i++) {         flag |= v[i] == cur;         if (v[i] <= cur) {           left--;         }       }       if (left == need && !flag) {         string s;         for (int i = 0; i < m; i++) {           s += (char)(cur % 2 +  0 );           cur /= 2;         }         reverse(s.begin(), s.end());         cout << s << endl;         return;       } else if (left < need) {         cur++;       } else {         cur--;       }     }   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int q;   int cnt[1 << 20];   int trans(long long v) {     int rt = 0;     for (int i = 0; i < 18; i++, v /= 10) {       if ((v % 10) & 1) {         rt |= 1 << i;       }     }     return rt;   }   void insert(long long v) { cnt[trans(v)]++; }   void erase(long long v) { cnt[trans(v)]--; }   int query(long long v) {     int bit = 0;     for (int i = 0; i < 18; i++, v /= 10) {       if (v & 1) {         bit |= 1 << i;       }     }     return cnt[bit];   }   int main() {     cin >> q;     while (q--) {       char ch[10];       long long v;       cin >> ch >> v;       if (ch[0] ==  + ) {         insert(v);       } else if (ch[0] ==  - ) {         erase(v);       } else {         cout << query(v) << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int dp[201];   int main() {     int n, t, w, sumt = 0, sumw = 0;     memset(dp, -1, sizeof(dp));     dp[0] = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d , &t, &w);       sumt += t;       sumw += w;       for (int j = 200; j >= t; j--) {         if (dp[j - t] != -1) dp[j] = max(dp[j], dp[j - t] + w);       }     }     int ans = sumt;     for (int i = 0; i <= sumt; i++) {       if (sumw - dp[i] <= i) {         ans = i;         break;       }     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   const int inf = (1 << 28) - 1;   struct Point {     double x, y;     Point() {}     Point(double _x, double _y) {       x = _x;       y = _y;     }     Point operator-(const Point &b) const { return Point(x - b.x, y - b.y); }     double operator^(const Point &b) const { return x * b.y - y * b.x; }     double operator*(const Point &b) const { return x * b.x + y * b.y; }     void transXY(double B) {       double tx = x, ty = y;       x = tx * cos(B) - ty * sin(B);       y = tx * sin(B) + ty * cos(B);     }   };   struct Line {     Point s, e;     Line() {}     Line(Point _s, Point _e) {       s = _s;       e = _e;     }   };   double dist(Point a, Point b) { return sqrt((a - b) * (a - b)); }   Point NearestPointToLineSeg(Point P, Line L) {     Point result;     double t = ((P - L.s) * (L.e - L.s)) / ((L.e - L.s) * (L.e - L.s));     if (t >= 0 && t <= 1) {       result.x = L.s.x + (L.e.x - L.s.x) * t;       result.y = L.s.y + (L.e.y - L.s.y) * t;     } else {       if (dist(P, L.s) < dist(P, L.e))         result = L.s;       else         result = L.e;     }     return result;   }   const double PAI = acos(-1);   int main() {     Point A, tmp, now, sta;     int n;     scanf( %d%lf%lf , &n, &A.x, &A.y);     double Max = -1, Min = inf;     for (int i = 1; i <= n; ++i) {       scanf( %lf%lf , &now.x, &now.y);       if (i > 1)         Min = min(Min, dist(A, NearestPointToLineSeg(A, Line(tmp, now))));       else         sta = now;       Min = min(Min, dist(A, now));       Max = max(Max, dist(A, now));       tmp = now;     }     Min = min(Min, dist(A, NearestPointToLineSeg(A, Line(sta, now))));     printf( %.18lf n , (PAI * Max * Max) - (PAI * Min * Min));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     long long n;     int k;     cin >> n >> k;     long long num = 0;     long long idx = 1;     long long todie = n;     for (int i = 0; i < k; ++i) {       long long x;       cin >> x;       if (n % x < todie) {         todie = n % x;         idx = i + 1;         num = n / x;       }     }     cout << idx <<     << num;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int N;     scanf( %d , &N);     long long res = 0;     for (int i = 2; i <= N / 2; i++) {       long long m = N / i;       res += (m * (m + 1) / 2 - 1) * 4;     }     printf( %lld n , res);   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-6;   const int INF = 0x3f3f3f3f;   const int MAXN = 2e3 + 10;   int ans[MAXN * 3], vis[MAXN][MAXN];   int dp[MAXN][MAXN], n, kk, dir[4][2] = {1, 0, 0, 1};   char mp[MAXN][MAXN];   struct Node {     int x, y, s;     Node(int x, int y, int s) : x(x), y(y), s(s){};   };   queue<Node> q;   void bfs() {     while (!q.empty()) {       Node u = q.front();       q.pop();       int x = u.x;       int y = u.y;       int s = u.s;       if (n == 100 && kk == 1 && q.size() > 100000) {         printf( siz = %d, x = %d, y = %d, s = %d n , q.size(), x, y, s);         return;       }       if (s >= 2 * n - 1) continue;       if (mp[x][y] -  a  > ans[s]) continue;       for (int i = 0; i < 2; i++) {         int dx = x + dir[i][0];         int dy = y + dir[i][1];         if (dx > n || dy > n) continue;         if (mp[dx][dy] -  a  <= ans[s + 1] && vis[dx][dy] == 0) {           vis[dx][dy] = 1;           ans[s + 1] = mp[dx][dy] -  a ;           q.push(Node(dx, dy, s + 1));         }       }     }   }   int main() {     cin >> n >> kk;     memset(ans, INF, sizeof ans);     memset(dp, -1, sizeof dp);     for (int i = 1; i <= n; i++) scanf( %s , mp[i] + 1);     int cnt = 0;     if (kk) {       if (mp[1][1] ==  a )         dp[1][1] = kk;       else         dp[1][1] = kk - 1;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) {           if (i - 1 >= 1 && dp[i - 1][j] >= 0) {             int tmp = dp[i - 1][j];             if (mp[i][j] !=  a ) tmp--;             dp[i][j] = max(dp[i][j], tmp);           }           if (j - 1 >= 1 && dp[i][j - 1] >= 0) {             int tmp = dp[i][j - 1];             if (mp[i][j] !=  a ) tmp--;             dp[i][j] = max(dp[i][j], tmp);           }           if (dp[i][j] >= 0) cnt = max(cnt, i + j - 1);         }       if (dp[n][n] >= 0) {         for (int i = 1; i < 2 * n; i++) printf( a );         return 0;       }       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           if (dp[i][j] == 0 && i + j - 1 == cnt) {             vis[i][j] = 1;             q.push(Node(i, j, cnt));             mp[i][j] =  a ;           }       for (int i = 1; i <= cnt; i++) ans[i] = 0;     } else {       vis[1][1] = 1;       q.push(Node(1, 1, 1));       ans[1] = mp[1][1] -  a ;     }     bfs();     for (int i = 1; i < 2 * n; i++) printf( %c , ans[i] +  a );     return 0;   }