malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int M = 2048;   char s[M], b[M], e[M], fb[M], fe[M];   int r[2][M], *p = r[0], *q = r[1], h[M];   int main(void) {     cin >> s >> b >> e;     int ns = strlen(s), nb = strlen(b), ne = strlen(e), nn = nb > ne ? nb : ne,         w = 0;     for (int i = ns; i-- > 0;) {       if (!strncmp(s + i, b, nb)) fb[i] = 1;       if (!strncmp(s + i, e, ne)) fe[i] = 1;     }     for (int i = 0, *t; i < ns; ++i, t = p, p = q, q = t)       for (int j = i; j-- > 0;) {         q[j + 1] = (s[i] == s[j]) ? (p[j] + 1) : 0;         if (h[i] < q[j + 1]) h[i] = q[j + 1];       }     for (int i = ns; i-- > 0;)       if (fb[i])         for (int j = i + nn; j <= ns; ++j)           if (fe[j - ne] && h[j - 1] < j - i) ++w;     cout << w << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int inv[25];   long long a[25];   int power(int a, int b) {     int c = 1;     for (; b; b >>= 1) {       if (b & 1) c = (long long)c * a % mod;       a = (long long)a * a % mod;     }     return c;   }   int C(long long y, int x) {     if (y < 0 || x < 0 || y < x) return 0;     y %= mod;     if (y == 0 || x == 0) return 1;     int ans = 1;     for (int i = 0; i < x; i++) ans = (long long)ans * (y - i) % mod;     for (int i = 1; i <= x; i++) ans = (long long)ans * inv[i] % mod;     return ans;   }   int main() {     int n;     long long m;     long long ans = 0;     for (int i = 1; i <= 20; i++) inv[i] = power(i, mod - 2);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int x = 0; x < (1 << n); x++) {       if (x == 0)         ans = (ans + C(n + m - 1, n - 1)) % mod;       else {         long long t = n + m;         int p = 0;         for (int i = 0; i < n; i++)           if ((x >> i) & 1) {             p++;             t -= a[i + 1];           }         t -= (p + 1);         if (p & 1)           ans = (ans - C(t, n - 1)) % mod;         else           ans = (ans + C(t, n - 1)) % mod;       }     }     cout << (ans + mod) % mod << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   string print_iterable(T1 begin_iter, T2 end_iter, int counter) {     bool done_something = false;     stringstream res;     res <<  [ ;     for (; begin_iter != end_iter and counter; ++begin_iter) {       done_something = true;       counter--;       res << *begin_iter <<  ,  ;     }     string str = res.str();     if (done_something) {       str.pop_back();       str.pop_back();     }     str +=  ] ;     return str;   }   vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {     vector<int> ord(size);     for (int i = 0; i < size; i++) ord[i] = i;     sort(ord.begin(), ord.end(), compare);     return ord;   }   template <typename T>   bool MinPlace(T& a, const T& b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <typename T>   bool MaxPlace(T& a, const T& b) {     if (a < b) {       a = b;       return true;     }     return false;   }   const int MAXN = 100100;   int a[MAXN];   int pr[MAXN];   int last_apparizione[MAXN];   int N;   int res[MAXN];   int EasyCalc(int k) {     if (res[k]) return res[k];     int ris = 1;     int curr_start = 0;     int curr_size = 1;     for (int i = 1; i < N; i++) {       curr_size += curr_start > pr[i];       if (curr_size > k) {         curr_size = 1;         curr_start = i;         ris++;       }     }     return ris;   }   int main() {     ios::sync_with_stdio(false);     cin >> N;     for (int i = 0; i < N; i++) cin >> a[i];     for (int i = 0; i < MAXN; i++) last_apparizione[i] = -1;     for (int i = 0; i < N; i++) {       pr[i] = last_apparizione[a[i]];       last_apparizione[a[i]] = i;     }     int rad = min((int)(2 * sqrt(N)), N);     for (int k = 1; k <= rad; k++) res[k] = EasyCalc(k);     int curr = rad;     while (curr <= N) {       int l = curr + 1;       int r = N + 1;       while (l < r) {         int m = (l + r) / 2;         res[m] = EasyCalc(m);         if (res[m] == res[curr])           l = m + 1;         else           r = m;       }       int prox = l;       for (int i = curr + 1; i < prox; i++) res[i] = res[curr];       curr = prox;     }     for (int k = 1; k <= N; k++) cout << res[k] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   char str[1010];   int pri[510][510];   int pre[510][510];   int f[510][510];   bool v[510] = {0};   int N;   void init() {     gets(str);     scanf( %d , &N);   }   void prework() {     int len = strlen(str);     for (int i = 0; i < len; ++i)       for (int j = 0; j < len; ++j) {         int p = 0;         int tmp = 0;         while (i + p < j - p) {           if (str[i + p] != str[j - p]) tmp++;           p++;         }         pri[i + 1][j + 1] = tmp;       }   }   void dp() {     int len = strlen(str);     memset(f, 10, sizeof(f));     f[0][0] = 0;     for (int i = 1; i <= len; ++i) {       for (int j = 1; j <= N; ++j)         for (int k = 0; k < i; ++k) {           if (f[i][j] > f[k][j - 1] + pri[k + 1][i]) {             f[i][j] = f[k][j - 1] + pri[k + 1][i];             pre[i][j] = k;           }         }     }     int Ans = 1000000000;     int p;     for (int i = 1; i <= N; ++i)       if (f[len][i] < Ans) {         Ans = f[len][i];         p = i;       }     printf( %d n , Ans);     int q = len;     while (q != 0) {       v[pre[q][p]] = 1;       int x = 0;       while (pre[q][p] + x < q - 1 - x) {         str[pre[q][p] + x] = str[q - 1 - x];         x++;       }       q = pre[q][p];       p--;     }     v[0] = 0;     for (int i = 0; i < len; ++i) {       if (v[i]) putchar( + );       putchar(str[i]);     }   }   int main() {     init();     prework();     dp();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, arr[200005];     string swaps;     cin >> n;     for (int i = 1; i <= n; i++) cin >> arr[i];     cin >> swaps;     int m = 0, flag = 0;     for (int i = 1; i < n; i++) {       m = max(m, arr[i]);       if (swaps[i - 1] ==  0  && m > i) {         flag = 1;         break;       }     }     (flag) ? cout <<  NO n  : cout <<  YES n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     char s;     int d = 1, j = 1;     for (int i = 1; i <= n; i++) {       cin >> s;       j -= 1;       if (j == 0) {         cout << s;         d += 1;         j = d;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   const int N = 1e5 + 5;   const double pi = acos(-1);   long long n, m, ans;   char arr[55][55];   bool inrange(int i, int j) {     if (i < n && i >= 0 && j < m && j >= 0) return true;     return false;   }   void solve(int i, int j) {     int cntr1 = 0, cntr2 = 0, cntr3 = 0;     if (inrange(i + 1, j) && inrange(i + 1, j + 1) && inrange(i, j + 1)) {       if (arr[i + 1][j] ==  a  || arr[i + 1][j + 1] ==  a  ||           arr[i][j + 1] ==  a )         cntr1++;       if (arr[i + 1][j] ==  e  || arr[i + 1][j + 1] ==  e  ||           arr[i][j + 1] ==  e )         cntr2++;       if (arr[i + 1][j] ==  c  || arr[i + 1][j + 1] ==  c  ||           arr[i][j + 1] ==  c )         cntr3++;     }     if (cntr1 == 1 && cntr3 == 1 && cntr2 == 1) ans++;     cntr1 = 0, cntr2 = 0, cntr3 = 0;     if (inrange(i + 1, j) && inrange(i + 1, j - 1) && inrange(i, j - 1)) {       if (arr[i + 1][j] ==  a  || arr[i + 1][j - 1] ==  a  ||           arr[i][j - 1] ==  a )         cntr1++;       if (arr[i + 1][j] ==  e  || arr[i + 1][j - 1] ==  e  ||           arr[i][j - 1] ==  e )         cntr2++;       if (arr[i + 1][j] ==  c  || arr[i + 1][j - 1] ==  c  ||           arr[i][j - 1] ==  c )         cntr3++;     }     if (cntr1 == 1 && cntr3 == 1 && cntr2 == 1) ans++;     cntr1 = 0, cntr2 = 0, cntr3 = 0;     if (inrange(i - 1, j) && inrange(i - 1, j - 1) && inrange(i, j - 1)) {       if (arr[i - 1][j] ==  a  || arr[i - 1][j - 1] ==  a  ||           arr[i][j - 1] ==  a )         cntr1++;       if (arr[i - 1][j] ==  e  || arr[i - 1][j - 1] ==  e  ||           arr[i][j - 1] ==  e )         cntr2++;       if (arr[i - 1][j] ==  c  || arr[i - 1][j - 1] ==  c  ||           arr[i][j - 1] ==  c )         cntr3++;     }     if (cntr1 == 1 && cntr3 == 1 && cntr2 == 1) ans++;     cntr1 = 0, cntr2 = 0, cntr3 = 0;     if (inrange(i - 1, j) && inrange(i - 1, j + 1) && inrange(i, j + 1)) {       if (arr[i - 1][j] ==  a  || arr[i - 1][j + 1] ==  a  ||           arr[i][j + 1] ==  a )         cntr1++;       if (arr[i - 1][j] ==  e  || arr[i - 1][j + 1] ==  e  ||           arr[i][j + 1] ==  e )         cntr2++;       if (arr[i - 1][j] ==  c  || arr[i - 1][j + 1] ==  c  ||           arr[i][j + 1] ==  c )         cntr3++;     }     if (cntr1 == 1 && cntr3 == 1 && cntr2 == 1) ans++;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> arr[i][j];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (arr[i][j] ==  f ) solve(i, j);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     cin >> n;     cout << n / 2 + n << endl;     if (n & 1) {       for (int i = 1; i <= n; i++) {         if (!(i & 1)) cout << i <<    ;       }       for (int i = 1; i <= n; i++) {         if (i & 1) cout << i <<    ;       }       for (int i = 1; i <= n; i++) {         if (!(i & 1)) cout << i <<    ;       }     } else {       for (int i = 1; i <= n; i++) {         if (i & 1) cout << i <<    ;       }       for (int i = 1; i <= n; i++) {         if (!(i & 1)) cout << i <<    ;       }       for (int i = 1; i <= n; i++) {         if (i & 1) cout << i <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5, M = 20;   int n, m;   string s;   int pos[(1 << M) - 1], a[M + 5][M + 5], f[(1 << M) + 5], g[(1 << M) + 5][M + 5];   int main() {     memset(a, 0, sizeof(a));     memset(f, 0x3f, sizeof(f));     memset(g, 0, sizeof(g));     cin >> n >> m >> s;     for (int i = 0; i < n - 1; i++) {       a[s[i] -  a ][s[i + 1] -  a ]++;       a[s[i + 1] -  a ][s[i] -  a ]++;     }     for (int i = 0; i < m; i++) pos[1 << i] = i;     for (int i = 1; i < (1 << m); i++)       for (int j = 0; j < m; j++) {         int k = i & (-i);         g[i][j] = g[i ^ k][j] + a[j][pos[k]];       }     f[0] = 0;     for (int i = 0; i < (1 << m) - 1; i++) {       long long sum = 0;       for (int j = 0; j < m; j++)         if ((i & (1 << j)) == 0) sum += g[i][j];       for (int j = 0; j < m; j++)         if ((i & (1 << j)) == 0)           f[i | (1 << j)] = min(f[i] + sum, (long long)f[i | (1 << j)]);     }     cout << f[(1 << m) - 1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[31][31][51];   void Cal() {     for (int i = 0; i <= 30; i++)       for (int j = 0; j <= 30; j++)         for (int k = 0; k <= 50; k++) {           dp[i][j][k] = (k == 0 || k == i * j) ? 0 : 10000000000000000;           for (int kk = 0; kk <= k; kk++) {             for (int ii = 1; ii < i; ii++)               dp[i][j][k] =                   min(dp[i][j][k], dp[ii][j][kk] + dp[i - ii][j][k - kk] + j * j);             for (int jj = 1; jj < j; jj++)               dp[i][j][k] =                   min(dp[i][j][k], dp[i][jj][kk] + dp[i][j - jj][k - kk] + i * i);           }         }   }   int main() {     int T;     scanf( %d , &T);     Cal();     while (T--) {       int n, m, k;       scanf( %d%d%d , &n, &m, &k);       cout << dp[n][m][k] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n;     cin >> m;     int a[m];     for (int i = 0; i < m; i++) {       a[i] = 0;     }     cin >> n;     int p = 0, q = 0, r = 0;     for (int i = 0; i < n; i++) {       cin >> p;       cin >> q;       cin >> r;       a[p - 1] -= r;       a[q - 1] += r;     }     int res = 0;     for (int i = 0; i < m; i++) {       if (a[i] > 0) res += a[i];     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long co[100];   int main() {     long long a, l = 0;     long long ans = 1;     cin >> a;     while (a > 1) {       long long c = 0;       for (int s = 2; s <= sqrt(a); s++) {         if (a % s == 0) {           a /= s, co[l] = s, l++, c = 1;           break;         }       }       if (c == 0) break;     }     if (l == 0)       cout << 1 << endl << 0;     else if (l == 1)       cout << 2;     else {       cout << 1 << endl;       for (int s = 0; s < 2; s++) ans *= co[s];       cout << ans;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d, ans = 0;     scanf( %d%d , &n, &d);     int maxi, t, l;     scanf( %d , &maxi);     for (int i = 1; i < n; i++) {       scanf( %d , &t);       if (t > maxi) {         maxi = t;         continue;       } else {         l = (int)ceil((maxi + 1 - t) / (double)d);         ans += l;         maxi = t + d * l;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5, M = 1e5;   int dfn, cur[M + 1], in[N + 1], pre[N + 1], fin[N + 1], r[N + 1], sz[N + 1];   vector<int> adj[N + 1];   int dfs(int u, int a) {     sz[u] = 1;     r[u] = a;     pre[u] = ++dfn;     for (auto v : adj[u]) sz[u] += dfs(v, a);     fin[u] = ++dfn;     return sz[u];   }   int main() {     int n, m, k, q;     scanf( %d%d%d%d , &n, &m, &k, &q);     for (int i = (0), i_end = (k); i < i_end; ++i) {       int a, b;       scanf( %d%d , &a, &b);       if (cur[b]) {         ++in[a];         adj[cur[b]].push_back(a);       }       cur[b] = a;     }     for (int i = (1), i_end = (n + 1); i < i_end; ++i)       if (!in[i]) dfs(i, i);     for (int i = (0), i_end = (q); i < i_end; ++i) {       int x, y;       scanf( %d%d , &x, &y);       y = cur[y];       if (r[x] == r[y] && pre[y] > pre[x] && fin[y] < fin[x])         printf( %d n , sz[x]);       else         puts( 0 );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 1000 * 1000 * 1000 + 7;   const long long LINF = INF * (long long)INF;   const int MAX = 2 * 1000 * 100 + 47;   struct Item {     int a, t, ind;     bool operator<(const Item& a) const { return t < a.t; }   };   Item A[MAX];   int n, t;   bool ok(int k) {     long long time = 0;     int cnt = 0;     for (int i = (0); i < (n); i++) {       int a = A[i].a;       int tt = A[i].t;       if (a >= k && time + tt <= t) {         cnt++;         time += tt;       }     }     return cnt >= k;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> t;     for (int i = (0); i < (n); i++) {       cin >> A[i].a >> A[i].t;       A[i].ind = i;     }     sort(A, A + n);     int l = 0, r = n + 1;     while (r - l > 1) {       int c = (r + l) / 2;       if (ok(c)) {         l = c;       } else {         r = c;       }     }     int cnt = l;     cout << cnt <<   n  << cnt <<   n ;     for (int i = (0); i < (n); i++) {       if (cnt == 0) break;       if (A[i].a >= l) {         cnt--;         cout << A[i].ind + 1 <<    ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 7;   int n, p[N];   deque<pair<int, int> > deq;   bool mrk[N];   vector<int> dor[2];   int dfs(int v, int d) {     mrk[v] = 1;     if (!mrk[p[v]]) return dfs(p[v], d + 1);     return d;   }   void add(int v, int l) {     dor[l].clear();     int pnt = v;     do {       dor[l].push_back(pnt);       pnt = p[pnt];     } while (pnt != v);   }   void remake(int l) {     int go = dor[l].size() / 2 + 1;     for (int i = 0; i < dor[l].size(); i++) {       p[dor[l][i]] = dor[l][(i + go) % dor[l].size()];     }   }   void merge() {     for (int i = 0; i < dor[0].size(); i++) {       p[dor[0][i]] = dor[1][i];       p[dor[1][i]] = dor[0][(1 + i) % dor[0].size()];     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> p[i];     for (int i = 1; i <= n; i++) {       if (!mrk[i]) {         deq.push_back({dfs(i, 1), i});       }     }     sort(deq.begin(), deq.end());     while (deq.size()) {       if (deq[0].first % 2) {         add(deq[0].second, 0);         remake(0);         deq.pop_front();         continue;       }       if (deq.size() == 1 || deq[1].first != deq[0].first) {         cout << -1;         return 0;       }       add(deq[0].second, 0);       add(deq[1].second, 1);       merge();       deq.pop_front();       deq.pop_front();     }     for (int i = 1; i <= n; i++) cout << p[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200001;   int MAX[N];   vector<int> A[N];   int main() {     ios::sync_with_stdio(false);     set<pair<int, int> > S;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int u, v;       cin >> u >> v;       MAX[u] = v;       A[u].push_back(v);     }     for (int i = 1; i <= n; i++) {       if (MAX[i] > 0) S.insert({MAX[i], i});     }     int q;     cin >> q;     for (int i = 0; i < q; i++) {       int c;       cin >> c;       vector<int> temp;       for (int j = 0; j < c; j++) {         int u;         cin >> u;         temp.push_back(u);         S.erase({MAX[u], u});       }       if (S.size() > 1) {         pair<int, int> p = *S.rbegin(), p2;         S.erase(p);         temp.push_back(p.second);         p2 = *S.rbegin();         int l_lim = 0, u_lim = A[p.second].size();         while (l_lim < u_lim - 1) {           int cur = (l_lim + u_lim) / 2;           if (A[p.second][cur] > p2.first) {             u_lim = cur;           } else {             l_lim = cur;           }         }         if (A[p.second][l_lim] > p2.first) {           cout << p.second <<     << A[p.second][l_lim] <<   n ;         } else {           cout << p.second <<     << A[p.second][l_lim + 1] <<   n ;         }       } else if (S.size() == 1) {         pair<int, int> p = *S.rbegin();         cout << p.second <<     << A[p.second][0] <<   n ;       } else {         cout <<  0 0 n ;       }       while (!temp.empty()) {         if (MAX[temp.back()] > 0) S.insert({MAX[temp.back()], temp.back()});         temp.pop_back();       }     }     return 0;   }
#include <bits/stdc++.h>   using i64 = long long;   using u64 = unsigned long long;   using u32 = unsigned;   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     int n;     std::cin >> n;     std::vector<int> c0(n, 0);     std::vector<int> c1(n, 0);     for (int i = 0; i < n; i++) {       std::cin >> c0[i] >> c1[i];     }     std::vector<int> tmp{0};     for (int i = 0; i < n; i++) {       tmp.emplace_back(c0[i]);       tmp.emplace_back(c1[i]);     }     std::sort(tmp.begin(), tmp.end());     tmp.resize(std::unique(tmp.begin(), tmp.end()) - tmp.begin());     for (int i = 0; i < n; i++) {       c0[i] = std::lower_bound(tmp.begin(), tmp.end(), c0[i]) - tmp.begin();       c1[i] = std::lower_bound(tmp.begin(), tmp.end(), c1[i]) - tmp.begin();     }     std::vector<int> p(tmp.size(), 0);     std::iota(p.begin(), p.end(), 0);     auto find = [&](int x) {       while (x != p[x]) {         x = p[x] = p[p[x]];       }       return x;     };     int ans = 0;     for (int i = 0; i < n; i++) {       int x = c0[i];       int y = c1[i];       x = find(x);       y = find(y);       if (!x && !y) {         std::cout << -1, exit(0);       } else {         if (x == y || !x || !y) {           ans = std::max({ans, x, y});           p[x] = p[y] = 0;         } else {           ans = std::max(ans, std::min(x, y));           p[std::min(x, y)] = std::max(x, y);         }       }     }     std::cout << tmp[ans] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct compare {     bool operator()(const std::string& first, const std::string& second) {       return first.size() > second.size();     }   };   int main() {     ios_base::sync_with_stdio(false);     int n, k, i;     cin >> n >> k;     string arr[110];     for (i = 0; i < n; i++) {       cin >> arr[i];     }     string password;     cin >> password;     long long int tries = 0, equallen = 0;     int plen = password.length();     for (i = 0; i < n; i++) {       if (arr[i].length() < plen) {         tries++;       } else if (arr[i].length() == plen) {         equallen++;       }     }     long long int ans = 0;     ans = ((tries) / k) * 5 + tries + 1;     cout << ans <<    ;     ans = ((tries + equallen - 1) / k) * 5 + (tries + equallen);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s[10] = { O-|-OOOO ,  O-|O-OOO ,  O-|OO-OO ,  O-|OOO-O ,  O-|OOOO- ,                      -O|-OOOO ,  -O|O-OOO ,  -O|OO-OO ,  -O|OOO-O ,  -O|OOOO- };     string num;     while (cin >> num) {       int i = num.size();       while (i--) cout << s[num[i] -  0 ] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 2e5 + 10;   int a[N];   int main() {     string str;     string s;     while (cin >> s) str += s;     for (auto& c : str) {       if (c ==  < ) c =    ;       if (c ==  > ) c =    ;     }     vector<string> vs;     vector<int> ans;     stringstream sin(str);     while (sin >> str) {       if (str[0] ==  / ) {         if (str ==  /table ) {           ans.push_back(a[vs.size() - 1]);         } else {           a[vs.size() - 2] += a[vs.size() - 1];         }         vs.pop_back();         a[vs.size()] = 0;       } else {         if (str ==  td )           a[vs.size()] = 1;         else           a[vs.size()] = 0;         vs.push_back(str);       }     }     sort(ans.begin(), ans.end());     for (auto& x : ans) printf( %d  , x);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   char field[110][110];   bool check_solution(bool do_print, bool swapped) {     for (int r = 0; r < N; ++r) {       int c;       for (c = 0; c < N; ++c) {         if (field[r][c] ==  . ) break;       }       if (c == N) return false;       if (do_print) {         if (swapped)           printf( %d %d n , c + 1, r + 1);         else           printf( %d %d n , r + 1, c + 1);       }     }     return true;   }   int main(void) {     scanf( %d , &N);     for (int r = 0; r < N; ++r) scanf( %s , field[r]);     if (check_solution(false, false)) {       check_solution(true, false);     } else {       for (int r = 0; r < N; ++r) {         for (int c = r + 1; c < N; ++c) {           swap(field[r][c], field[c][r]);         }       }       if (check_solution(false, true))         check_solution(true, true);       else         puts( -1 );     }     return 0;   }