malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 9, M = 2e5 + 9, OO = 0x3f3f3f3f, mod = 1e9 + 7;   long long n, aS, bS, aT, bT;   string s, t;   vector<long long> bMis, aMis;   int main() {     cin >> n >> s >> t;     for (auto i : s) {       aS += (i ==  a );       bS += (i ==  b );     }     for (auto i : t) {       aT += (i ==  a );       bT += (i ==  b );     }     if ((aS + aT) % 2) return cout <<  -1 , 0;     if ((bS + bT) % 2) return cout <<  -1 , 0;     for (int i = 0; i < n; ++i) {       if (s[i] ==  b  and t[i] ==  a ) bMis.push_back(i + 1);       if (s[i] ==  a  and t[i] ==  b ) aMis.push_back(i + 1);     }     long long nSwap = (bMis.size() / 2) + (aMis.size() / 2);     if (bMis.size() % 2) nSwap += 2;     cout << nSwap <<   n ;     for (int i = 0; i < bMis.size(); i += 2) {       if (i == bMis.size() - 1) break;       cout << bMis[i] <<     << bMis[i + 1] <<   n ;     }     for (int i = 0; i < aMis.size(); i += 2) {       if (i == aMis.size() - 1) break;       cout << aMis[i] <<     << aMis[i + 1] <<   n ;     }     if (bMis.size() % 2) {       cout << aMis.back() <<     << aMis.back() <<   n ;       cout << aMis.back() <<     << bMis.back() <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   bool isUpper(string s) {     return std::all_of(s.begin(), s.end(),                        [](unsigned char c) { return std::isupper(c); });   }   int main() {     string s1, s2;     cin >> s1 >> s2;     transform(s1.begin(), s1.end(), s1.begin(), ::tolower);     transform(s2.begin(), s2.end(), s2.begin(), ::tolower);     int ans = 0;     for (int i = 0; i < s1.length(); i++) {       if (s1[i] > s2[i]) {         ans = 1;         break;       } else if (s1[i] < s2[i]) {         ans = -1;         break;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<string> pril, sush, glag;   void Init() {     pril.push_back( lios );     pril.push_back( liala );     sush.push_back( etr );     sush.push_back( etra );     glag.push_back( initis );     glag.push_back( inites );   }   pair<int, bool> Check(string str) {     pair<int, bool> res;     for (int i = 0; i < 2; i++) {       if (str.length() >= pril[i].length() &&           str.substr(str.length() - pril[i].length(), pril[i].length()) ==               pril[i])         return make_pair(0, i);     }     for (int i = 0; i < 2; i++) {       if (str.length() >= sush[i].length() &&           str.substr(str.length() - sush[i].length(), sush[i].length()) ==               sush[i])         return make_pair(1, i);     }     for (int i = 0; i < 2; i++) {       if (str.length() >= glag[i].length() &&           str.substr(str.length() - glag[i].length(), glag[i].length()) ==               glag[i])         return make_pair(2, i);     }     return make_pair(-1, 0);   }   int main() {     Init();     int f[3];     for (int i = 0; i < 3; i++) f[i] = 0;     char s;     string str;     bool inStr = false, sol = true;     int type = -1;     int step = -1;     int res = 0;     bool pol = false;     while ((s = getchar()) != EOF) {       if (s >=  a  && s <=  z ) {         if (!inStr) inStr = true;         str.push_back(s);       } else if (inStr) {         inStr = false;         pair<int, bool> r = Check(str);         if (r.first == -1) {           sol = false;           break;         }         if (type == -1) {           type = r.first;           pol = r.second;           f[type]++;         } else {           if (pol != r.second)             sol = false;           else if (type + 1 == r.first) {             type = r.first;             f[type]++;           } else if (type == r.first) {             if (type == 1) sol = false;             f[type]++;           } else             sol = false;           if (!sol) break;         }         str.clear();       }     }     if (!sol)       printf( NO );     else {       if (inStr) {         inStr = false;         pair<int, bool> r = Check(str);         if (r.first == -1) {           sol = false;         }         if (type == -1) {           type = r.first;           pol = r.second;           f[type]++;         } else {           if (pol != r.second)             sol = false;           else if (type + 1 == r.first) {             type = r.first;             f[type]++;           } else if (type == r.first) {             if (type == 1) sol = false;             f[type]++;           } else             sol = false;         }         str.clear();       }       int sum = 0;       for (int i = 0; i < 3; i++) sum += f[i];       if (sum == 1)         printf( YES );       else {         if (sum == f[0] || sum == f[1] || sum == f[2])           printf( NO );         else           printf( YES );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int N = 300005;   long long n, e, idx[N], low[N], T, q[300005], ans = 0, ans2 = 1, scc[100005],                                                 mini[300005], cn, second[3000005];   vector<vector<long long> > g;   vector<long long> S;   bool vis[N];   long long compID[N], cmp;   void DFS(int u) {     idx[u] = low[u] = ++T;     S.push_back(u);     vis[u] = true;     for (int i = 0; i < g[u].size(); ++i) {       long long v = g[u][i];       if (idx[v] == 0) DFS(v);       if (vis[v]) low[u] = min(low[u], low[v]);     }     if (idx[u] == low[u]) {       long long ee = 1e10;       cn++;       while (true) {         long long v = S.back();         ee = min(ee, q[v]);         scc[v] = cn;         S.pop_back();         vis[v] = false;         compID[v] = cmp;         if (v == u) break;       }       mini[cn] = ee;       ans += ee;       ++cmp;     }   }   int main() {     cin >> n;     g.resize(n);     for (int i = 0; i < n; i++) cin >> q[i];     cin >> e;     for (int i = 0; i < e; ++i) {       int from, to;       cin >> from >> to;       --from;       --to;       g[from].push_back(to);     }     for (int i = 0; i < n; ++i) {       if (idx[i] == 0) {         DFS(i);       }     }     for (int i = 0; i < n; i++) {       int in1 = scc[i];       int uu = mini[in1];       if (q[i] == uu) second[in1]++;     }     for (int i = 1; i <= cn; i++) {       ans2 *= second[i];       ans2 %= mod;     }     cout << ans <<     << ans2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> factor[500010];   int m, q;   long long n;   int p[10000], c[10000];   int divide(long long n) {     int ans = 0;     while (n % 5 == 0) n = n / 5 * 4, ans++;     while (n % 3 == 0) n = n / 3 * 2, ans++;     while (n % 2 == 0) n = n / 2, ans++;     if (n > 1) return -1;     return ans;   }   int main() {     scanf( %d , &q);     while (q--) {       scanf( %lld , &n);       int p = divide(n);       if (p == -1)         printf( -1 n );       else         printf( %d n , p);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxsize = 100;   int n, m;   bool visited[maxsize][maxsize];   string v, h;   int go[][2] = {1, 0, -1, 0, 0, -1, 0, 1};   map<char, int> dir;   int cnt;   void dfs(int row, int col) {     if (visited[row][col]) return;     visited[row][col] = true;     cnt++;     int n_row = -1, n_col = -1;     n_row = row + go[dir[h[row]]][0];     n_col = col + go[dir[h[row]]][1];     if (n_col >= 0 && n_col < m) {       dfs(n_row, n_col);     }     n_row = row + go[dir[v[col]]][0];     n_col = col + go[dir[v[col]]][1];     if (n_row >= 0 && n_row < n) {       dfs(n_row, n_col);     }   }   int main(int argc, char* argv[]) {     dir[ > ] = 3;     dir[ < ] = 2;     dir[ ^ ] = 1;     dir[ v ] = 0;     while (scanf( %d%d , &n, &m) != EOF) {       cin >> h >> v;       bool flag = true;       for (int ii = 0; ii < n && flag; ii++) {         for (int jj = 0; jj < m && flag; jj++) {           memset(visited, false, sizeof(visited));           cnt = 0;           dfs(ii, jj);           if (cnt != n * m) flag = false;         }       }       if (cnt == n * m)         printf( YES n );       else         printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T nextInt() {     T x = 0, p = 1;     char ch;     do {       ch = getchar();     } while (ch <=    );     if (ch ==  - ) {       p = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + (ch -  0 );       ch = getchar();     }     return x * p;   }   const int maxN = (int)5e2 + 10;   const int INF = (int)1e9;   const int mod = (int)1e9 + 7;   const long long LLINF = (long long)1e18;   long long a[maxN];   int n;   bool ok = false;   bool bad(int idx) {     for (int i = 0; i < idx; ++i) {       int r = 0;       for (int j = 0; j < n; ++j) {         if (((a[i] >> j) & 1) != ((a[idx] >> j) & 1)) {           r--;         } else {           r++;         }       }       if (r != 0) return true;     }     return false;   }   int cnt = 0;   void print() {     ok = 0;     for (int i = 0; i < 30; ++i) putchar( - );     putchar(  n );     char f[] = { * ,  + };     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         cout << f[(a[i] >> j) & 1];       }       cout <<   n ;     }     cout <<   n ;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         cout << f[(a[i] >> j) & 1];         if (j == n / 2 - 1) putchar(   );       }       cout <<   n ;       if (i == n / 2 - 1) putchar(  n );     }     cout <<   n ;     for (int i = 0; i < 30; ++i) putchar( - );     putchar(  n );   }   void dfs(int idx, int n) {     if (idx == n) {       print();       return;     }     for (long long mask = 0; mask < (1LL << n) && ok; ++mask) {       a[idx] = mask;       if (bad(idx)) continue;       dfs(idx + 1, n);     }   }   char rev(char x) {     if (x ==  + ) return  * ;     return  + ;   }   vector<vector<char> > build(int k) {     vector<vector<char> > ret(1 << k, vector<char>(1 << k,  ? ));     if (k == 0) {       ret[0][0] =  * ;       return ret;     }     vector<vector<char> > prev = build(k - 1);     int prevsz = (1 << k) / 2;     for (int i = 0; i < prevsz; ++i) {       for (int j = 0; j < prevsz; ++j) {         ret[i][2 * j] = ret[i][2 * j + 1] = prev[i][j];       }     }     for (int j = prevsz - 1; j >= 0; --j) {       for (int i = 0; i < prevsz; ++i) {         ret[prevsz + i][2 * j + 1] = prev[i][j];         ret[prevsz + i][2 * j] = rev(prev[i][j]);       }     }     return ret;   }   int main() {     int k;     cin >> k;     vector<vector<char> > answer = build(k);     for (int i = 0; i < answer.size(); ++i) {       for (int j = 0; j < answer[i].size(); ++j) {         putchar(answer[i][j]);       }       putchar(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   long long k;   int res[1000];   long long dp[205][205];   int p[105][105];   pair<int, int> a[10005];   long long calc(int i, int j) {     if (j < 0) return 0;     if (i == n + m - 1) {       return (j == 0);     }     if (dp[i][j] != -1) return dp[i][j];     long long &ans = dp[i][j];     ans = 0;     if (res[i] != 0)       ans = calc(i + 1, j + res[i]);     else {       ans = calc(i + 1, j + 1) + calc(i + 1, j - 1);     }     if (ans >= k) ans = k;     return ans;   }   long long solve() {     memset(dp, -1, sizeof(dp));     return calc(0, 0);   }   int main() {     cin >> n >> m >> k;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         int x;         cin >> x;         a[x - 1] = make_pair(i, j);       }     }     for (int l = 0; l < n * m; ++l) {       int i = a[l].first;       int j = a[l].second;       if (res[i + j] == 0) {         res[i + j] = 1;         long long cur = solve();         if (cur >= k) continue;         k -= cur;         res[i + j] = -1;       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (res[i + j] == 1)           putchar( ( );         else           putchar( ) );       }       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker, ”/ STACK : 38777216“   using namespace std;   const int N = 200005;   const int inf = 1000 * 1000 * 1000;   const int mod = 1000 * 1000 * 1000 + 7;   int n, a[N];   set<int> q;   set<int>::iterator it;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (a[i] == 0) q.insert(i);     }     for (int i = 1; i <= n; i++) {       if (a[i] == 0)         printf( 0  );       else {         int answ = inf;         q.insert(i);         it = q.find(i);         ++it;         if (it != q.end()) answ = min(answ, *it - i);         --it;         if (it != q.begin()) {           --it;           answ = min(answ, i - *it);           ++it;         }         q.erase(i);         printf( %d  , answ);       }     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     ;     cin.tie(0);     cout.tie(0);     int n, a, b, i;     string s;     cin >> n >> a >> b >> s;     int tot = a + b, p = 0;     for (i = 0; i < n; i++) {       if (s[i] ==  * ) {         p = 0;         continue;       }       if (p == 0) {         if (a >= b) {           a--;           p = 1;         } else {           b--;           p = 2;         }       } else if (p == 1 && b > 0) {         b--;         p = 2;       } else if (p == 1)         p = 0;       else if (p == 2 && a > 0) {         a--;         p = 1;       } else if (p == 2)         p = 0;       if (a + b == 0) break;     }     cout << tot - (a + b);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100001;   int main() {     char c[3][3], cc[3][3];     char s[3][3];     int ind1, ind2;     int ii = 0;     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) {         cin >> c[i][j];         cc[i][j] = c[i][j];       }     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) {         cin >> s[i][j];       }     for (ii = 0; ii < 60; ii++) {       int t = 0;       for (int i = 0; i < 2; i++) {         for (int j = 0; j < 2; j++) {           if (c[i][j] ==  X ) {             ind1 = i;             ind2 = j;           }         }       }       if (ind1 == 0 && ind2 == 0) swap(c[0][0], c[1][0]);       if (ind1 == 0 && ind2 == 1) swap(c[0][1], c[0][0]);       if (ind1 == 1 && ind2 == 0) swap(c[1][0], c[1][1]);       if (ind1 == 1 && ind2 == 1) swap(c[1][1], c[0][1]);       for (int i = 0; i < 2; i++)         for (int j = 0; j < 2; j++) {           if (s[i][j] != c[i][j]) {             t = 1;             break;           }         }       if (t == 0) {         cout <<  YES  << endl;         return 0;       }     }     for (ii = 0; ii < 60; ii++) {       int t = 0;       for (int i = 0; i < 2; i++) {         for (int j = 0; j < 2; j++) {           if (cc[i][j] ==  X ) {             ind1 = i;             ind2 = j;           }         }       }       if (ind1 == 0 && ind2 == 0) swap(c[0][0], c[0][1]);       if (ind1 == 0 && ind2 == 1) swap(c[0][1], c[1][1]);       if (ind1 == 1 && ind2 == 0) swap(c[1][0], c[0][0]);       if (ind1 == 1 && ind2 == 1) swap(c[1][1], c[1][0]);       for (int i = 0; i < 2; i++)         for (int j = 0; j < 2; j++) {           if (s[i][j] != c[i][j]) {             t = 1;             break;           }         }       if (t == 0) {         cout <<  YES  << endl;         return 0;       }     }     cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   vector<int> tree[maxn];   int n;   bool flag[maxn];   double dfs(int deep, int at) {     flag[at] = false;     double ret = 0;     for (int i = 0; i < tree[at].size(); i++) {       int one = tree[at][i];       if (flag[one]) ret += dfs(deep + 1, one);     }     return ret + 1.0 / (deep);   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) flag[i] = true;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       tree[a].push_back(b);       tree[b].push_back(a);     }     printf( %.9lf , dfs(1, 0));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void prnt(bool ok) { cout << (ok ?  YES  :  NO ); }   const int ppr = 257;   const long long INF = 2e18;   const int inf = 2e9;   const int mod = 1e9 + 7;   const int N = 1e6 + 123;   const long double pi = 3.141592653589793238462643;   const int dx[] = {1, 0, -1, 0};   const int dy[] = {0, 1, 0, -1};   int T, n, m;   bool u[N];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> T;     while (T--) {       cin >> n >> m;       for (int i = 1; i <= 3 * n; i++) u[i] = 0;       vector<int> cur;       for (int i = 1; i <= m; i++) {         int x, y;         cin >> x >> y;         if (u[x] || u[y]) continue;         u[x] = u[y] = 1;         cur.push_back(i);       }       if (cur.size() >= n) {         cout <<  Matching n ;         for (int i = 0; i < n; i++) cout << cur[i] <<    ;       } else {         cout <<  IndSet n ;         int cnt = 0;         for (int i = 1; i <= 3 * n; i++) {           if (cnt == n) break;           if (!u[i]) {             cnt++;             cout << i <<    ;           }         }       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MX = 2e5 + 1;   bool sieve[MX], in_graph[MX], vstd[MX];   vector<int> pos[MX], adj[MX];   int mu[MX];   ll res[MX];   void init() {     vector<int> primes;     mu[1] = 1;     for (int i = 2; i < MX; ++i) {       if (!sieve[i]) {         mu[i] = -1;         primes.push_back(i);       }       for (auto j : primes) {         if (i * j >= MX) break;         sieve[i * j] = true;         if (i % j == 0) {           mu[i * j] = 0;           break;         }         mu[i * j] = -mu[i];       }     }   }   int dfs(int u, int p) {     int res = 1;     vstd[u] = true;     for (auto c : adj[u]) {       if (c == p || !in_graph[c]) continue;       res += dfs(c, u);     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     init();     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       int a;       cin >> a;       for (int j = 1; j * j <= a; ++j) {         if (a % j) continue;         pos[j].push_back(i);         if (a / j != j) {           pos[a / j].push_back(i);         }       }     }     for (int i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 1; i < MX; ++i) {       for (auto j : pos[i]) {         in_graph[j] = true;       }       for (auto j : pos[i]) {         if (!vstd[j]) {           ll cnt = dfs(j, 0);           res[i] += cnt * (cnt + 1) / 2;         }       }       for (auto j : pos[i]) {         in_graph[j] = false;         vstd[j] = false;       }     }     for (int i = 1; i < MX; ++i) {       ll ans = 0;       for (int j = 1; j * i < MX; ++j) {         ans += mu[j] * res[j * i];       }       if (ans) {         cout << i <<     << ans <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m;     cin >> n >> m;     long long int arr[n];     vector<long long int> a, onsum, offsum;     for (long long int i = 0; i < n; i++) {       cin >> arr[i];     }     a.push_back(arr[0]);     for (long long int i = 1; i < n; i++) {       a.push_back(arr[i] - arr[i - 1]);     }     a.push_back(m - arr[n - 1]);     long long int sum1 = 0, sum2 = 0;     for (long long int i = 0; i < a.size(); i++) {       if (i % 2 == 0) {         sum1 = sum1 + a[i];         offsum.push_back(sum1);       } else {         sum2 = sum2 + a[i];         onsum.push_back(sum2);       }     }     long long int sum = 0;     vector<long long int> z;     for (long long int i = 0; i < onsum.size(); i++) {       if (i == 0)         sum = offsum[i] + onsum[onsum.size() - 1] - 1;       else         sum = offsum[i] + onsum[onsum.size() - 1] - onsum[i - 1] - 1;       z.push_back(sum);     }     sum = 0;     for (long long int i = 0; i < a.size(); i++) {       if (i % 2 == 0) sum = sum + a[i];     }     z.push_back(sum);     sort(z.begin(), z.end());     cout << z[z.size() - 1];     return 0;   }
#include <bits/stdc++.h>   const int INF = 1e9;   using namespace std;   inline string gtStr() {     char st[200];     scanf( %s , st);     return st;   }   long long sum[1001];   int cnt[11];   int main() {     int n, m, f;     cin >> n >> m;     for (int i = 0; i < n; i++) {       scanf( %d , &f);       cnt[f]++;     }     long long ans = 0;     for (int i = 1; i <= 9; i++) {       for (int j = i + 1; j <= 10; j++) {         ans += 1LL * cnt[i] * cnt[j];       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);   typedef long long ll;   typedef long double ld;   typedef vector<ll> vll;   typedef pair<ll,ll> pll;   #define F first   #define S second   #define PB push_back   #define MP make_pair   #define all(x) x.begin(),x.end()   #define foru(i, a, b) for(ll i=a; i < (b) ; i++)   #define fore(i, a, b) for(ll i=a ; i <= (b); i++)   const ll mod = 1e9+7, N = 2e6+7, M = 2e6+7, INF = INT_MAX/10;      ll power(ll x, ll y){ x = x%mod, y=y%(mod-1);ll ans = 1;while(y>0){if (y&1){ans = (1ll * x * ans)%mod;}y>>=1;x = (1ll * x * x)%mod;}return ans;}   ll str_to_int(string s){stringstream asteya(s); ll x=0; asteya>>x; return x;}   string int_to_str(ll n){return to_string(n);}         void testcase(){       ll a,b,ans,moves,sub;       cin>>a>>b;          if(a==0  and b==0)       cout<<0<<   <<0<<endl;       else{              ans = abs(a-b);              if(ans == 0) sub=0;              else               sub = min(a,b)%ans;           if(ans > 0 && ans !=1)           moves = min(sub, (ans-(a%ans))%ans);           else           moves = 0;              cout<<ans<<   <<moves<<endl;       }          }      int main(){       fast;       int t=1;       cin >> t;          while(t--){        testcase();       }         return 0;   }
#include <bits/stdc++.h>   using namespace std;   using lint = long long;   int a[111][111];   void solve(istream& cin, ostream& cout) {     int n, m;     cin >> n >> m;     bool sw = n > m;     for (int i = (0); i < int(n); ++i) {       for (int j = (0); j < int(m); ++j) {         if (sw) {           cin >> a[j][i];         } else {           cin >> a[i][j];         }       }     }     if (sw) {       swap(n, m);     }     vector<pair<int, int>> ans;     for (int i = (0); i < int(n); ++i) {       int mn = *min_element(a[i], a[i] + m);       if (mn > 0) {         ans.push_back({i, mn});         for (int j = (0); j < int(m); ++j) {           a[i][j] -= mn;         }       }     }     for (int j = (0); j < int(m); ++j) {       int mn = 1e9;       for (int i = (0); i < int(n); ++i) {         mn = min(a[i][j], mn);       }       if (mn > 0) {         ans.push_back({-j - 1, mn});         for (int i = (0); i < int(n); ++i) {           a[i][j] -= mn;         }       }     }     for (int i = (0); i < int(n); ++i) {       for (int j = (0); j < int(m); ++j) {         if (a[i][j] != 0) {           cout << -1;           return;         }       }     }     int cop = 0;     for (auto& i : ans) {       cop += i.second;     }     cout << cop <<   n ;     for (auto& i : ans) {       for (int j = (0); j < int(i.second); ++j) {         if (i.first >= 0) {           if (sw) {             cout <<  col   << i.first + 1;           } else {             cout <<  row   << i.first + 1;           }         } else {           if (sw) {             cout <<  row   << -i.first;           } else {             cout <<  col   << -i.first;           }         }         cout <<   n ;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve(cin, cout);     return 0;   }