malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int f(string s) {     int answer = 0;     answer += 600 * (int(s[0]) - 48);     answer += 60 * (int(s[1]) - 48);     answer += 10 * (int(s[3]) - 48);     answer += (int(s[4]) - 48);     return answer;   }   string s(int a) {     string answer;     answer.clear();     answer += char(a / 600 + 48);     a = a % 600;     answer += char(a / 60 + 48);     a = a % 60;     answer +=  : ;     answer += char(a / 10 + 48);     a = a % 10;     answer += char(a + 48);     return answer;   }   int timer[2880] = {0};   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       timer[f(s) % 1440] = 1;       timer[(f(s) % 1440) + 1440] = 1;     }     int best = 0;     int temp = 0;     for (int i = 0; i < 2880; i++) {       if (timer[i] == 0)         temp++;       else {         best = max(best, temp);         temp = 0;       }     }     cout << s(best);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     pair<int, char> p[200005];     for (int i = 0; i < n; i++) {       scanf( %d %c , &p[i].first, &p[i].second);     }     sort(p, p + n);     int minred = 1e9 + 1, maxred = 1e9 + 1;     int mingreen = 1e9 + 1, maxgreen = 1e9 + 1;     for (int i = 0; i < n; i++) {       if (p[i].second ==  R ) {         maxred = p[i].first;         minred = min(minred, p[i].first);       } else if (p[i].second ==  B ) {         maxgreen = p[i].first;         mingreen = min(mingreen, p[i].first);       } else {         maxred = p[i].first;         minred = min(minred, p[i].first);         maxgreen = p[i].first;         mingreen = min(mingreen, p[i].first);       }     }     long long ans = (long long)maxred - minred + maxgreen - mingreen;     int lastp = -1;     for (int i = 0; i < n; i++) {       if (p[i].second ==  P ) {         if (lastp != -1) {           int lastr = p[lastp].first;           int lastg = p[lastp].first;           int maxr = 0, maxg = 0;           for (int j = lastp + 1; j < i; j++) {             if (p[j].second ==  R ) {               maxr = max(p[j].first - lastr, maxr);               lastr = p[j].first;             } else {               maxg = max(p[j].first - lastg, maxg);               lastg = p[j].first;             }           }           maxr = max(p[i].first - lastr, maxr);           maxg = max(p[i].first - lastg, maxg);           ans -= max(0, maxr + maxg - (p[i].first - p[lastp].first));         }         lastp = i;       }     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int a[1005], dp[1005][1005], dp_sum[1005][1005];   int main() {     ios::sync_with_stdio(false);     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     int limit = a[n] / (k - 1);     int ans = 0;     for (int diff = 1; diff <= limit; diff++) {       for (int j = 1; j <= n; j++) dp_sum[j][1] = j, dp[j][1] = 1;       for (int ct = 2; ct <= k; ct++) {         for (int j = 1, l = 1; j <= n; j++) {           while (l < j && a[j] - a[l] >= diff) l++;           dp[j][ct] = dp_sum[l - 1][ct - 1];           dp_sum[j][ct] = dp[j][ct] + dp_sum[j - 1][ct];           if (dp_sum[j][ct] >= 998244353) dp_sum[j][ct] -= 998244353;         }       }       ans += dp_sum[n][k];       if (ans >= 998244353) ans -= 998244353;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long t, n, a[205], b, c[205];   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> t;     while (t--) {       cin >> n >> b;       for (int i = 0; i < n; i++) {         cin >> a[i];         c[a[i]] = 1;       }       for (int i = 1;; i++) {         if (c[i] == 0) {           b--;         }         if (b == 0) {           for (int j = i + 1;; j++) {             if (c[j] == 0) {               cout << j - 1 <<   n ;               break;             }           }           break;         }       }       for (int i = 0; i < 105; i++) {         a[i] = 0;         c[i] = 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int d[8], f1[8], f2[8];   bool Check(int f[], int a, int b, int c) {     return (f[1] + f[2] + f[3] + f[4] <= a) && (f[1] + f[2] + f[5] + f[6] <= b) &&            (f[1] + f[3] + f[5] + f[7] <= c);   }   int main() {     int t;     cin >> t;     while (t--) {       int a1, b1, c1, a2, b2, c2;       cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2;       for (int i = 1; i < 8; ++i) {         cin >> d[i];       }       bool found = false;       for (int x = 0, xmax = min(d[2], min(a1, b1)); x <= xmax && !found; ++x) {         for (int y = 0, ymax = min(d[3], min(a1 - x, c1)); y <= ymax && !found;              ++y) {           for (int z = 0, zmax = min(d[5], min(b1 - x, c1 - y));                z <= zmax && !found; ++z) {             f1[2] = x, f1[3] = y, f1[5] = z;             f1[1] =                 max(0, min(min(d[1], a1 - x - y), min(b1 - x - z, c1 - y - z)));             f1[4] = min(d[4], max(0, a1 - x - y - f1[1]));             f1[6] = min(d[6], max(0, b1 - x - z - f1[1]));             f1[7] = min(d[7], max(0, c1 - y - z - f1[1]));             f2[1] = d[1] - f1[1];             f2[2] = d[2] - f1[2];             f2[3] = d[3] - f1[3];             f2[4] = d[4] - f1[4];             f2[5] = d[5] - f1[5];             f2[6] = d[6] - f1[6];             f2[7] = d[7] - f1[7];             found = Check(f2, a2, b2, c2);           }         }       }       if (!found) {         cout <<  -1 n ;         continue;       }       for (int i = 1; i < 8; ++i) {         cout << f1[i] <<    ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100005];   vector<pair<int, int>> t;   bool pairsort(pair<int, int> e1, pair<int, int> e2) {     return e1.first <= e2.first;   }   int main() {     int n;     cin >> n;     int pos, pow;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &pos, &pow);       t.push_back(make_pair(pos, pow));     }     sort(t.begin(), t.end(), pairsort);     memset(a, 0, sizeof(a));     a[0] = 0;     a[1] = 1;     for (int i = 1; i < t.size(); i++) {       if (t[i].first - t[i].second > t[i - 1].first) {         a[i + 1] = a[i] + 1;       } else {         int l = 0;         int r = i - 1;         int k = t[i].first - t[i].second;         while (r > l) {           int mid = (r + l) / 2;           if (t[mid].first >= k)             r = mid;           else             l = mid + 1;         }         a[i + 1] = a[l] + 1;       }     }     int max = 0;     for (int i = 0; i <= n; i++) {       max = max > a[i] ? max : a[i];     }     int ans = n - max;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct fenwickTree {     long long n;     vector<long long> bit;     fenwickTree() {}     fenwickTree(long long siz) : n(siz + 5), bit(siz + 5, 0) {}     void add(long long pos, long long upd) {       for (; pos < n; pos += pos & (-pos)) bit[pos] += upd;     }     long long sum(long long pos) {       long long ret = 0;       for (; pos; pos -= pos & (-pos)) ret += bit[pos];       return ret;     }     long long query(long long pos) {       return sum(n - 1) - sum(min(n - 1, pos - 1));     }   };   const long long nax = 100005;   long long c[nax], ss[nax] = {0}, dsu[nax], siz[nax] = {0}, ans[nax];   vector<long long> g[nax];   vector<pair<long long, long long>> q[nax];   vector<map<long long, long long>> mp(nax);   vector<fenwickTree> bitarr(nax);   void dfs(long long u, long long p) {     ss[u] = siz[u] = 1;     long long mx = -1, mxc = -1;     for (auto &k : g[u])       if (k != p) {         dfs(k, u);         ss[u] += ss[k];         if (ss[k] > mx) mx = ss[k], mxc = k;       }     if (mxc != -1) {       dsu[u] = dsu[mxc];       siz[dsu[mxc]] = ss[u];     }   }   void add(long long u, long long col, long long cnt) {     if (!cnt) return;     if (mp[u].count(col)) bitarr[u].add(mp[u][col], -1);     mp[u][col] += cnt;     bitarr[u].add(mp[u][col], 1);   }   void dfs2(long long u, long long p) {     for (auto &k : g[u])       if (k != p) dfs2(k, u);     add(dsu[u], c[u], 1);     for (auto &k : g[u])       if (k != p && dsu[k] != dsu[u])         for (auto &col : mp[dsu[k]]) add(dsu[u], col.first, col.second);     for (auto &qry : q[u]) ans[qry.first] = bitarr[dsu[u]].query(qry.second);   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, m;     cin >> n >> m;     for (long long i = 1; i <= n; i++) dsu[i] = i;     for (long long i = 1; i <= n; i++) cin >> c[i];     for (long long i = 0; i < n - 1; i++) {       long long u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     dfs(1, 1);     for (long long i = 1; i <= n; i++) bitarr[i] = fenwickTree(siz[i]);     for (long long i = 0; i < m; i++) {       long long a, b;       cin >> a >> b;       q[a].push_back({i + 1, b});     }     dfs2(1, 1);     for (long long i = 1; i <= m; i++) cout << ans[i] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5, inf = 0x3f3f3f3f;   int main() {     int a, b, h1, h2;     while (cin >> h1 >> h2) {       cin >> a >> b;       int add = a * 12, de = b * 12, first = 8 * a;       if (a <= b) {         if (h1 + first >= h2)           puts( 0 );         else           puts( -1 );         continue;       }       int ans = 0;       h1 += first;       if (h1 >= h2)         puts( 0 );       else {         add -= de;         ans += (h2 - h1) / add;         if ((h2 - h1) % add) ans++;         printf( %d n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 159, INF = 2e9 + 9;   struct mat {     bitset<MAX> a[MAX];     mat(int v = 0) {       for (int i = 0; i < MAX; i++)         for (int j = 0; j < MAX; j++)           if (i == j)             a[i][j] = v;           else             a[i][j] = 0;     }   } adj(0);   mat operator*(mat a, mat b) {     mat tmp(0), ret(0);     for (int i = 0; i < MAX; i++)       for (int j = 0; j < MAX; j++) tmp.a[i][j] = b.a[j][i];     for (int i = 0; i < MAX; i++)       for (int j = 0; j < MAX; j++)         ret.a[i][j] = ((a.a[i] & tmp.a[j]).count() > 0);     return ret;   }   mat operator^(mat a, int n) {     mat ret(1);     if (!n) return ret;     ret = a ^ (n >> 1);     if (n & 1) return ret * ret * a;     return ret * ret;   }   map<int, vector<pair<int, int> > > m;   bitset<MAX> can, t;   bool mark[MAX];   vector<int> g[MAX];   long long n, e, a, b, d, dis[MAX][MAX], h[MAX];   queue<int> q;   long long bfs() {     while (q.size()) {       int v = q.front();       q.pop();       if (v == n - 1) return h[v];       for (auto u : g[v])         if (!mark[u]) q.push(u), h[u] = h[v] + 1, mark[u] = true;     }     return INF;   }   int main() {     cin >> n >> e;     for (int i = 0; i < MAX; i++)       for (int j = 0; j < MAX; j++) dis[i][j] = (i == j ? 0 : INF);     for (int i = 0; i < e; i++)       cin >> a >> b >> d, a--, b--, m[d].push_back({a, b}), dis[a][b] = 1;     can[0] = 1, m[0].push_back({0, 0}), m[0].pop_back();     long long last, ans = INF;     for (map<int, vector<pair<int, int> > >::iterator it = m.begin();          it != m.end(); it++) {       long long d1 = it->first;       it++;       if (it == m.end()) {         it--;         last = it->first;         break;       }       long long d2 = it->first;       it--;       for (auto i : it->second)         adj.a[i.first][i.second] = 1, g[i.first].push_back(i.second);       memset(h, 0, sizeof h), memset(mark, 0, sizeof mark);       while (q.size()) q.pop();       for (int i = 0; i < MAX; i++)         if (can[i]) mark[i] = true, q.push(i);       ans = min(ans, bfs() + d1);       mat tmp = adj, tmp2;       tmp = tmp ^ (d2 - d1);       for (int i = 0; i < MAX; i++)         for (int j = 0; j < MAX; j++) tmp2.a[i][j] = tmp.a[j][i];       t = can;       for (int i = 0; i < MAX; i++) can[i] = (t & tmp2.a[i]).count() > 0;     }     for (int k = 0; k < MAX; k++)       for (int i = 0; i < MAX; i++)         for (int j = 0; j < MAX; j++)           dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);     for (int i = 0; i < MAX; i++)       if (can[i]) ans = min(ans, dis[i][n - 1] + last);     if (ans < INF)       cout << ans;     else       cout <<  Impossible ;   }
#include <bits/stdc++.h>   using namespace std;   int getint() {     int x = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) x *= 10, x += (c -  0 ), c = getchar();     return x;   }   vector<pair<int, int> > v[2];   int n, a[2][10010];   void XOR(int i, int j, int idx) {     v[idx].push_back(make_pair(i, j));     a[idx][i] ^= a[idx][j];   }   void init() {     n = getint();     for (int j = 0; j < 2; j++)       for (int i = 0; i < n; i++) a[j][i] = getint();   }   void Gauss(int idx) {     int pre = 0;     for (int i = 30; i >= 0; i--)       for (int j = pre; j < n; j++)         if (a[idx][j] & (1 << i)) {           if (j != pre) {             XOR(j, pre, idx);             XOR(pre, j, idx);             XOR(j, pre, idx);           }           for (int k = 0; k < n; k++)             if (k != pre && (a[idx][k] & (1 << i))) XOR(k, pre, idx);           pre++;           break;         }   }   void solve() {     for (int i = 0; i < 2; i++) Gauss(i);     for (int i = 0; i < n; i++)       if (a[0][i]) {         int bs = (1 << 30);         while ((a[0][i] & bs) == 0) bs >>= 1;         for (int j = 0; j <= 30 && j < n; j++)           if ((a[0][j] ^ a[1][j]) & bs) XOR(j, i, 0);       } else         break;     for (int i = 0; i < n; i++)       if (a[0][i] != a[1][i]) {         puts( -1 );         return;       }     printf( %d n , (int)v[0].size() + (int)v[1].size());     for (int i = 0; i < (int)v[0].size(); i++)       printf( %d %d n , v[0][i].first + 1, v[0][i].second + 1);     for (int i = (int)v[1].size() - 1; i >= 0; i--)       printf( %d %d n , v[1][i].first + 1, v[1][i].second + 1);   }   int main() {     init();     solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, zheng = 0, mmax = 0, strc, stra, cuowu;     char a[1000], b[26], c[1000];     double bb[26], sheng[26], bisheng[26], cc[26];     cin >> a;     cin >> n;     sort(a, a + strlen(a));     memset(c, 0, sizeof(c));     b[0] =  a ;     for (int i = 1; i < 26; i++) {       b[i] = b[i - 1] + 1;     }     for (int i = 0; i < 26; i++) {       bb[i] = 0, cc[i] = 0, sheng[i] = 0, bisheng[i] = 0;     }     for (int i = 0; i < strlen(a); i++) {       for (int j = 0; j < 26; j++) {         if (a[i] == b[j]) bb[j]++;       }     }     for (int i = 0; i < 26; i++) {       if (bb[i] != 0) zheng++;       if (bb[i] > mmax) mmax = bb[i];     }     stra = strlen(a);     if (n > strlen(a)) {       cout << 1 << endl;       int cuowu = 0;       for (int k = 0; k < 26; k++) {         if (sheng[k] > sheng[cuowu]) cuowu = k;       }       for (int i = 0; i < n - stra; i++) {         a[i + stra] = a[cuowu];       }       for (int i = 0; i < n; i++) {         cout << a[i];       }       cout << endl;     } else if (n < zheng) {       cout << -1 << endl;     } else {       int j = 0, yu;       for (int i = 0; i < 26; i++) {         sheng[i] = bb[i];         bisheng[i] = bb[i];         if (bb[i] != 0) {           c[j] = b[i];           cc[i] = 1;           j++;         }       }       yu = n - strlen(c);       if (yu == 0) {         cout << mmax << endl;         cout << c << endl;       } else {         strc = strlen(c);         mmax = 0;         for (int i = 0; i < yu; i++) {           for (int k = 0; k < 26; k++) {             if (sheng[k] > sheng[mmax]) mmax = k;           }           cc[mmax] += 1;           sheng[mmax] = bisheng[mmax] / cc[mmax];           c[i + strc] = b[mmax];         }         for (int k = 0; k < 26; k++) {           if (sheng[k] > sheng[mmax]) mmax = k;         }         cout << ceil(sheng[mmax]) << endl;         cout << c << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     vector<pair<int, int>> vec;     int n, a, b;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a >> b;       if (a != b) {         cout <<  rated ;         return 0;       }       vec.push_back({a, b});     }     for (int i = 0; i < vec.size() - 1; i++) {       if (vec[i].first < vec[i + 1].first) {         cout <<  unrated ;         return 0;       }     }     cout <<  maybe ;   }
#include <bits/stdc++.h>   #define int long long   #define F0R(i, n) for(int i = 0; i < (n); i++)   using namespace std;      signed main()   {       ios::sync_with_stdio(0);       cin.tie(0), cout.tie(0);       int T; cin >> T;       F0R(cas,T) {           int N; cin >> N;           vector<int> a(N);           for(int &x : a)               cin >> x;           sort(a.begin(),a.end(),greater<int>());           int evsum = 0, odsum = 0;           F0R(i,N) {               if(i%2 && a[i]%2)                   odsum += a[i];               if((i%2 == 0) && (a[i]%2 == 0))                   evsum += a[i];           }           if(evsum >  odsum) cout <<  Alice n ;           if(evsum == odsum) cout <<  Tie n ;           if(evsum <  odsum) cout <<  Bob n ;       }       return 0;   }
#include <bits/stdc++.h>   #pragma optimize( TKACHENKO-GORYACHENKO )   using namespace std;   const int maxn = 11e5;   const int inf = 1e18;   int n, m, k;   int A[maxn];   int B[maxn];   int C[maxn];   int V[4 * maxn];   int T[4 * maxn];   inline void push(int v, int tl, int tr) {     if (T[v] == 0) {       return;     }     V[v] += T[v];     if (tl != tr) {       T[2 * v] += T[v];       T[2 * v + 1] += T[v];     }     T[v] = 0;   }   inline void build(int v, int tl, int tr) {     if (tl == tr) {       V[v] = C[tl];       return;     }     int tm = (tl + tr) / 2;     build(2 * v, tl, tm);     build(2 * v + 1, tm + 1, tr);     V[v] = min(V[2 * v], V[2 * v + 1]);   }   inline void update(int v, int tl, int tr, int l, int r, int color) {     push(v, tl, tr);     if (l > r || tl > r || l > tr) {       return;     }     if (tl == l && tr == r) {       T[v] += color;       push(v, tl, tr);       return;     }     int tm = (tl + tr) / 2;     update(2 * v, tl, tm, l, min(r, tm), color);     update(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, color);     V[v] = min(V[2 * v], V[2 * v + 1]);   }   inline void changea(int i, int j) {     if (j >= i) {       update(1, 0, maxn - 1, i + 1, j, -1);     } else {       update(1, 0, maxn - 1, j + 1, i, 1);     }   }   inline void changeb(int i, int j) {     if (j >= i) {       update(1, 0, maxn - 1, i + 1, j, 1);     } else {       update(1, 0, maxn - 1, j + 1, i, -1);     }   }   inline int getans(int v, int tl, int tr) {     push(v, tl, tr);     int tm = (tl + tr) / 2;     if (tl != tr) {       push(2 * v, tl, tm);       push(2 * v + 1, tm + 1, tr);     }     if (V[v] >= 0) {       return -1;     }     if (tl == tr) {       return tl;     }     if (V[2 * v + 1] < 0) {       return getans(2 * v + 1, tm + 1, tr);     }     if (V[2 * v] < 0) {       return getans(2 * v, tl, tm);     }   }   int main() {     int q, w, e, a, b, f;     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m;     for (q = 0; q < n; q++) {       cin >> A[q];       C[A[q]]--;     }     for (q = 0; q < m; q++) {       cin >> B[q];       C[B[q]]++;     }     cin >> k;     for (q = maxn - 2; q >= 0; q--) {       C[q] += C[q + 1];     }     build(1, 0, maxn - 1);     for (e = 0; e < k; e++) {       int i, x, comm;       cin >> comm >> i >> x;       i--;       if (comm == 1) {         changea(A[i], x);         A[i] = x;       } else {         changeb(B[i], x);         B[i] = x;       }       cout << getans(1, 0, maxn - 1) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     bool tr = false;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       if (x != y) tr = true;     }     if (tr)       cout <<  Happy Alex n ;     else       cout <<  Poor Alex n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool ACS(string s) {     int n1 = s.length();     for (int i = 1; i < n1; i++)       if (s[i] != s[0]) return false;     return true;   }   int main() {     long long int t;     cin >> t;     while (t--) {       string s;       cin >> s;       if (s.length() == 1)         cout << 0 << endl;       else if (s[0] == s[1] && ACS(s))         cout << 1 << endl;       else {         int ss1 = 0;         map<char, int> m1;         for (int i = 0; i < s.length(); i++) m1[s[i]]++;         for (int i = 0; i < m1.size(); i++) {           if (m1[i] > 2)             ss1 = ss1 + 2;           else             ss1 = ss1 + m1[i];         }         if (ss1 % 2)           cout << (ss1 - 1) / 2 << endl;         else           cout << ss1 / 2 << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   void fn(long long int a[], long long int a1, long long int b, long long int n) {     for (long long int i = 0; i < n; i++) {       a[i] = a1;       a1 += b;     }   }   void solve() {     long long int n, x, y;     cin >> n >> x >> y;     long long int bst = INT_MAX;     long long int a[n];     for (long long int i = 1; i < 51; i++) {       for (long long int j = 1; j < 51; j++) {         long long int x1 = 0, y1 = 0;         long long int a1[n];         fn(a1, i, j, n);         for (long long int i = 0; i < n; i++) {           if (a1[i] == x) {             x1 = 1;           }           if (a1[i] == y) {             y1 = 1;           }         }         if (x1 and y1 and a1[n - 1] < bst) {           for (long long int i = 0; i < n; i++) {             a[i] = a1[i];           }           bst = a[n - 1];         }       }     }     for (long long int i = 0; i < n; i++) {       cout << a[i] <<    ;     }     cout <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v[3];   int main() {     int n;     cin >> n;     string s1, s2;     cin >> s1 >> s2;     int ans1 = 0, ans2 = 0;     for (int i = 0; i < s1.size(); i++) {       if (s1[i] ==  a ) {         ans1++;       }       if (s2[i] ==  a ) {         ans1++;       }       if (s1[i] ==  b ) {         ans2++;       }       if (s2[i] ==  b ) {         ans2++;       }     }     if (s1 == s2) {       cout << 0 << endl;       return 0;     }     if (ans1 % 2 || ans2 % 2) {       cout << -1 << endl;       return 0;     } else {       s1 =     + s1;       s2 =     + s2;       for (int i = 1; i <= s1.size(); i++) {         if (s1[i] == s2[i]) {           continue;         }         if (s1[i] ==  a ) {           v[1].push_back(i);           continue;         } else {           v[2].push_back(i);         }       }       int ans = 0;       int flag = 0;       if (v[1].size() % 2) {         flag = v[1].back();         v[2].push_back(v[1].back());         v[1].pop_back();         ans++;       }       ans = ans + v[1].size() / 2 + v[2].size() / 2;       cout << ans << endl;       if (flag) cout << flag <<     << flag << endl;       if (v[1].size() > 0)         for (int i = 0; i < v[1].size() - 1; i += 2) {           cout << v[1][i] <<     << v[1][i + 1] << endl;         }       if (v[2].size() > 0)         for (int i = 0; i < v[2].size() - 1; i += 2) {           cout << v[2][i] <<     << v[2][i + 1] << endl;         }     }     return 0;   }