malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   inline int add(int a, int b);   inline int mult(int a, int b);   inline int sub(int a, int b);   inline int divv(int a, int b);   int p1[300500];   int p2[300500];   int pow1 = 37;   int pow2 = 41;   int mod1 = 1000000007;   int mod2 = 1000000009;   int32_t main() {     std::iostream::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(10);     string s;     cin >> s;     int half = s.size() / 2;     set<char> st;     for (int i = 0; i < half; i++) st.insert(s[i]);     if (st.size() <= 1) {       cout <<  Impossible n ;       return 0;     }     for (int i = 1; i < s.size(); i++) {       string s1 = s.substr(0, i);       string s2 = s.substr(i, s.size());       string t = s2 + s1;       string rt = t;       reverse(rt.begin(), rt.end());       if (t != s && t == rt) {         cout <<  1 n ;         return 0;       }     }     cout <<  2 n ;     return 0;   }   int add(int a, int b) {     int result = a + b;     if (result >= mod) result -= mod;     return result;   }   int sub(int a, int b) {     int result = a - b;     if (result < 0) result += mod;     return result;   }   int mult(int a, int b) { return (a * 1ll * b) % mod; }   int bin(int a, int n) {     int res = 1;     while (n) {       if (n & 1) res = mult(res, a);       a = mult(a, a);       n /= 2;     }     return res;   }   int divv(int a, int b) { return mult(a, bin(b, mod - 2)); }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 3e3 + 4;   long long dp[N];   int main() {     int n;     scanf( %d , &n);     vector<pair<int, int>> v(n);     for (int i = 0; i < n; i++)       scanf( %d , &v[i].first), scanf( %d , &v[i].second);     sort(v.begin(), v.end());     dp[n - 1] = v[n - 1].second;     for (int i = n - 2; i >= 0; i--) {       dp[i] = v[i].second + dp[i + 1];       long long sum = 0;       for (int j = i; j < n; j++) {         sum += (v[j].first - v[i].first);         dp[i] = min(dp[i], sum + dp[j + 1] + v[i].second);       }     }     cout << dp[0];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     if (a[n - 1] >= a[n - 2] + a[n - 3]) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     for (long long i = 0; i < n; i += 2) cout << a[i] <<    ;     for (long long i = n - n % 2 - 1; i >= 0; i -= 2) cout << a[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int k, d, t;     cin >> k >> d >> t;     long long int k1, k2;     k1 = k;     k2 = (k / d) * d + (int)(k % d != 0) * d - k;     t *= 2;     long long int bal = 2 * k1 + k2;     long long int n = t / bal;     double time = n * (k1 + k2);     double extra = 1 - ((double)n / (double)t) * (double)bal;     double work_done_by_k1 = 2 * (double)k1 / (double)t;     double work_done_by_k2 = (double)k2 / (double)t;     if (extra > work_done_by_k1) {       time += (k1 + (double)(extra - work_done_by_k1) * (double)t);     } else {       time += (double)extra * (double)t / 2;     }     printf( %f n , time);   }
#include <bits/stdc++.h>   using namespace std;   int x1, yy1, r1, R1;   int x2, y2, r2, R2;   int dis;   inline bool inside(int r, int R) {     double dist = sqrt((double)dis);     if (dist <= double(R - r)) return true;     return false;   }   inline bool outside(int r, int R) {     double dist = sqrt((double)dis);     if (dist >= double(R + r)) return true;     return false;   }   int main() {     scanf( %d%d%d%d , &x1, &yy1, &r1, &R1);     scanf( %d%d%d%d , &x2, &y2, &r2, &R2);     dis = (x1 - x2) * (x1 - x2) + (yy1 - y2) * (yy1 - y2);     if (R1 > R2) {       swap(x1, x2);       swap(yy1, y2);       swap(r1, r2);       swap(R1, R2);     }     int ans = 0;     if (inside(r1, r2) || outside(r1, R2)) ans++;     if (inside(R1, r2) || outside(R1, R2)) ans++;     if (inside(R1, r2) || inside(r2, r1) || outside(r2, R1)) ans++;     if (inside(R1, R2) || outside(R1, R2)) ans++;     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int T, n, cnta[4], cntb[4], dy[2][2], ans[4040], k;   char a[4040], b[4040];   int main() {     dy[0][0] = 0, dy[0][1] = 1, dy[1][0] = 2, dy[1][1] = 3;     scanf( %d , &T);     while (T--) {       scanf( %s %s , a + 1, b + 1);       n = strlen(a + 1);       k = 0;       for (int i = 1; i <= n; ++i) a[i] -=  0 , b[i] -=  0 ;       cnta[0] = cnta[1] = cnta[2] = cnta[3] = 0;       for (int i = 2; i <= n; i += 2) ++cnta[dy[a[i - 1]][a[i]]];       cntb[0] = cntb[1] = cntb[2] = cntb[3] = 0;       for (int i = 2; i <= n; i += 2) ++cntb[dy[b[i - 1]][b[i]]];       if (cnta[0] != cntb[0] || cnta[3] != cntb[3]) {         printf( -1 n );         continue;       }       if (abs(cnta[1] - cnta[2]) >= abs(cntb[1] - cntb[2])) {         if (cnta[1] != cntb[2]) {           int now = 0;           for (int i = 2; i <= n; i += 2) {             if (dy[a[i - 1]][a[i]] == 1) ++now;             if (dy[a[i - 1]][a[i]] == 2) --now;             if (cnta[1] - cnta[2] - 2 * now == cntb[2] - cntb[1]) {               reverse(a + 1, a + i + 1);               ans[++k] = i;               break;             }           }         }         for (int i = 2; i <= n; i += 2) {           int p, c = dy[b[n - i + 2]][b[n - i + 1]];           for (int j = i; j <= n; j += 2)             if (dy[a[j - 1]][a[j]] == c) {               p = j;               break;             }           reverse(a + 1, a + 1 + p - 2), ans[++k] = p - 2;           reverse(a + 1, a + 1 + p), ans[++k] = p;         }         int cnt = 0;         for (int i = 1; i <= k; ++i)           if (ans[i]) {             if (cnt && ans[i] == ans[cnt])               --cnt;             else               ans[++cnt] = ans[i];           }         printf( %d n , cnt);         for (int i = 1; i <= cnt; ++i) printf( %d  , ans[i]);         printf(  n );       } else {         int now = 0;         for (int i = 2; i <= n; i += 2) {           if (dy[b[i - 1]][b[i]] == 1) --now;           if (dy[b[i - 1]][b[i]] == 2) ++now;           if (cnta[1] - cnta[2] == cntb[2] - cntb[1] - 2 * now) {             reverse(b + 1, b + i + 1);             ans[++k] = i;             break;           }         }         for (int i = 2; i <= n; i += 2) {           int p, c = dy[a[n - i + 2]][a[n - i + 1]];           for (int j = i; j <= n; j += 2)             if (dy[b[j - 1]][b[j]] == c) {               p = j;               break;             }           reverse(b + 1, b + 1 + p - 2), ans[++k] = p - 2;           reverse(b + 1, b + 1 + p), ans[++k] = p;         }         reverse(ans + 1, ans + 1 + k);         int cnt = 0;         for (int i = 1; i <= k; ++i)           if (ans[i]) {             if (cnt && ans[i] == ans[cnt])               --cnt;             else               ans[++cnt] = ans[i];           }         printf( %d n , cnt);         for (int i = 1; i <= cnt; ++i) printf( %d  , ans[i]);         printf(  n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   vector<int> v;   int main() {     ios_base::sync_with_stdio(0);     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n, x;     bool tt = 0;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> x;       v.push_back(x);     }     for (int i = 1; i < n; ++i) {       if (v[i] <= v[i - 1])         tt = true;       else if (tt && v[i] > v[i - 1])         return cout <<  NO n , 0;     }     reverse(v.begin(), v.end());     tt = 0;     for (int i = 1; i < n; ++i) {       if (v[i] <= v[i - 1])         tt = true;       else if (tt && v[i] > v[i - 1])         return cout <<  NO n , 0;     }     cout <<  YES n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6;   const int inf = 1e6;   int n, m;   int a[maxn + 5], b[maxn + 5];   int tag[maxn << 2], mx[maxn << 2];   void seta(int p, int d) {     tag[p] += d;     mx[p] += d;   }   void push(int p) {     seta(p + p, tag[p]);     seta(p + p + 1, tag[p]);     tag[p] = 0;   }   void modify(int p, int l, int r, int ql, int qr, int d) {     if (l == ql && r == qr) {       seta(p, d);       return;     }     push(p);     int mid = (l + r) >> 1;     if (qr <= mid)       modify(p + p, l, mid, ql, qr, d);     else if (mid < ql)       modify(p + p + 1, mid + 1, r, ql, qr, d);     else       modify(p + p, l, mid, ql, mid, d),           modify(p + p + 1, mid + 1, r, mid + 1, qr, d);     mx[p] = max(mx[p + p], mx[p + p + 1]);   }   int query(int p, int l, int r) {     if (l == r) return l;     push(p);     int mid = (l + r) >> 1;     if (mx[p + p + 1] > 0)       return query(p + p + 1, mid + 1, r);     else       return query(p + p, l, mid);   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       modify(1, 1, inf, 1, a[i], 1);     }     for (int i = 1; i <= m; i++) {       scanf( %d , &b[i]);       modify(1, 1, inf, 1, b[i], -1);     }     int q;     scanf( %d , &q);     while (q--) {       int op, i, x;       scanf( %d %d %d , &op, &i, &x);       if (op == 1) {         modify(1, 1, inf, 1, a[i], -1);         a[i] = x;         modify(1, 1, inf, 1, a[i], 1);       } else {         modify(1, 1, inf, 1, b[i], 1);         b[i] = x;         modify(1, 1, inf, 1, b[i], -1);       }       if (mx[1] <= 0)         printf( %d n , -1);       else         printf( %d n , query(1, 1, inf));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 + 5;   struct node {     long long x, y;     int id;     bool operator<(const node &ope) const { return y < ope.y; }   } a[maxn];   bool vis[maxn][maxn];   long long dp[maxn][maxn];   bool vis2[maxn];   inline void init() {     memset(dp, -1, sizeof(dp));     memset(vis, false, sizeof(vis));     memset(vis2, false, sizeof(vis2));   }   void solve(int n, int k) {     init();     dp[0][0] = 0;     sort(a + 1, a + 1 + n);     for (int i = 1; i <= n; ++i) {       int t = ((i) < (k) ? (i) : (k));       for (int j = 0; j <= t; ++j) {         if (dp[i - 1][j] >= 0) dp[i][j] = dp[i - 1][j] + (k - 1) * 1ll * a[i].y;         if (j > 0 && dp[i - 1][j - 1] >= 0) {           if (dp[i][j] >= dp[i - 1][j - 1] + a[i].x + (j - 1) * 1ll * a[i].y)             continue;           dp[i][j] = dp[i - 1][j - 1] + a[i].x + (j - 1) * 1ll * a[i].y;           vis[i][j] = true;         }       }     }   }   void print(int n, int k) {     printf( %d n , k + (n - k) * 2);     for (int i = n, j = k; i > 0 && j >= 0; --i) {       if (vis[i][j]) vis2[i] = true, --j;     }     int t = 0;     for (int i = 1; i <= n; ++i) {       if (!vis2[i]) continue;       if (++t == k) {         t = a[i].id;         break;       }       printf( %d  , a[i].id);     }     for (int i = 1; i <= n; ++i) {       if (!vis2[i]) printf( %d %d  , a[i].id, -a[i].id);     }     printf( %d n , t);   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, k;       scanf( %d%d , &n, &k);       for (int i = 1; i <= n; ++i) {         scanf( %lld%lld , &a[i].x, &a[i].y);         a[i].id = i;       }       solve(n, k);       print(n, k);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, n, m, a[105], S;   int main() {     cin >> t;     while (t--) {       cin >> n >> m;       S = 0;       for (int i = 1; i <= n; ++i) {         cin >> a[i];         S = S + a[i];       }       if (S == m)         cout <<  YES ;       else         cout <<  NO ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   void _print() { cout <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     cout << t;     if (sizeof...(v)) cout <<  ,  ;     _print(v...);   }   using ll = long long int;   using ld = long double;   template <typename T, typename V>   using P = pair<T, V>;   template <typename T>   using V = vector<T>;   constexpr ll MOD = 1e9 + 7;   constexpr ll INF = 0x3f3f3f3f;   constexpr ld PI = 3.1415926535897932384626;   constexpr ld EPS = 1e-9;   constexpr ll MAX = 1e5 + 5;   void solve() {     ll n;     cin >> n;     V<ll> a(n + 1);     for (ll i = (ll)(1); i < (ll)(n + 1); i++) cin >> a[i];     if (a[1]) {       cout << n + 1 <<    ;       for (ll i = (ll)(1); i < (ll)(n + 1); i++) cout << i <<    n [i == n];       return;     } else if (!a[n]) {       for (ll i = (ll)(1); i < (ll)(n + 1); i++) cout << i <<    ;       cout << n + 1 <<   n ;       return;     }     for (ll i = (ll)(1); i < (ll)(n); i++)       if (!a[i] && a[i + 1]) {         for (ll j = (ll)(1); j < (ll)(i + 1); j++) cout << j <<    ;         cout << n + 1 <<    ;         for (ll j = (ll)(i + 1); j < (ll)(n + 1); j++) cout << j <<    n [j == n];         return;       }     cout <<  -1 n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     ll t = 1;     cin >> t;     for (ll i = (ll)(1); i < (ll)(t + 1); i++) solve();   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   struct line {     int sx, sy, ex, ey;     friend bool operator<(const line &A, const line &B) { return A.sx < B.sx; }   };   map<char, line> mp;   int n, m;   char s[2005][2005], p[2005][2005], mxx;   void init() {     for (char x =  a ; x <=  z ; ++x) {       mp[x].sx = 0, mp[x].sy = 0;       mp[x].ex = 0, mp[x].ey = 0;     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         p[i][j] =  . ;       }     }   }   bool check() {     for (char x =  a ; x <= mxx; ++x) {       if (mp[x].sx != mp[x].ex and mp[x].sy != mp[x].ey) {         return false;       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if (s[i][j] != p[i][j]) return false;       }     }     return true;   }   void slove() {     cin >> n >> m;     mxx = 0;     init();     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         cin >> s[i][j];         mxx = max(mxx, s[i][j]);         if (mp[s[i][j]].sx == 0) {           mp[s[i][j]].sx = i;           mp[s[i][j]].sy = j;           mp[s[i][j]].ex = i;           mp[s[i][j]].ey = j;         } else {           mp[s[i][j]].ex = i;           mp[s[i][j]].ey = j;         }       }     }     for (char x =  a ; x <= mxx; ++x) {       if (mp[x].sx == 0) {         mp[x] = mp[mxx];       }       for (int xx = mp[x].sx; xx <= mp[x].ex; ++xx) {         for (int yy = mp[x].sy; yy <= mp[x].ey; ++yy) {           p[xx][yy] = x;         }       }     }     if (!check()) {       cout <<  NO  << endl;       return;     }     cout <<  YES  << endl;     cout << max(0, mxx -  a  + 1) << endl;     for (char x =  a ; x <= mxx; ++x) {       cout << mp[x].sx <<     << mp[x].sy <<    ;       cout << mp[x].ex <<     << mp[x].ey << endl;     }     return;   }   signed main() {     ios ::sync_with_stdio(false);     int T;     cin >> T;     while (T--) {       slove();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct disjoint_set {     vector<int> p;     disjoint_set(int n) : p(n, -1) {}     bool share(int a, int b) { return root(a) == root(b); }     int sz(int u) { return -p[root(u)]; }     int root(int u) { return p[u] < 0 ? u : p[u] = root(p[u]); }     bool merge(int u, int v) {       u = root(u), v = root(v);       if (u == v) return false;       p[u] += p[v], p[v] = u;       return true;     }   };   int main() {     cin.tie(0)->sync_with_stdio(0);     int n;     string s;     cin >> n >> s;     vector<array<int, 2>> dp(n + 1);     vector<int> reach(n);     for (auto i = n - 1; i >= 0; --i) {       if (s[i] !=  1 ) {         dp[i][0] = dp[i + 1][0] + 1;       }       if (s[i] !=  0 ) {         dp[i][1] = dp[i + 1][1] + 1;       }       reach[i] = max(dp[i][0], dp[i][1]);     }     disjoint_set dsu(n + 1);     for (auto l = 1; l <= n; ++l) {       int res = 0;       for (auto i = 0; i < n;) {         if (reach[i] < l) {           dsu.merge(i + 1, i);           i = dsu.root(i);         } else {           res += reach[i] / l;           i += reach[i] / l * l;         }       }       cout << res <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[1001][7];   int n, a[30], p, m, ch, j, mn, mx, val, o;   long long sum;   struct chestie {     int c, fr, ok, nr;   } v[30];   int pow(int N, int E);   bool comp(chestie X, chestie Y);   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin.get();       cin >> s[i];       m = strlen(s[i]);       for (int j = 0; j < m; j++) {         ch = s[i][j] -  a ;         if (ch > mx) mx = ch;         if (v[ch].fr == 0) o++;         v[ch].fr += (pow(10, (m - j - 1)));         v[ch].c = ch;         if (j == 0 && m >= 1) v[ch].ok = 1;       }     }     sort(v + 0, v + mx + 1, comp);     val = 1;     j = 1;     for (int i = 0; i < o; i++) {       if (v[i].ok || j == 0) {         v[i].nr = val;         sum += (v[i].fr * val);         val++;       } else if (j)         v[i].nr = 0, j = 0, a[v[i].c] = 0;     }     cout << sum;     return 0;   }   int pow(int N, int E) {     int R = 1;     while (E) R = R * N, E--;     return R;   }   bool comp(chestie X, chestie Y) {     if (X.fr > Y.fr) return 1;     if (X.fr < Y.fr) return 0;     if (X.c < Y.c) return 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   long long gMin = 1e12, gMax = -1e12, rMin = 1e12, rMax = -1e12, bMin = 1e12,             bMax = -1e12, lasty = -1e12, ret = 0;   vector<long long> notGreen[2];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(18);     cin >> N;     for (int i = 0; i <= N; i++) {       long long x = 1e12;       char c =  G ;       if (i < N) cin >> x >> c;       if (c ==  G ) {         if (i < N) {           gMin = min(gMin, x);           gMax = max(gMax, x);         }         long long add1 = x - lasty, add2 = add1 * 2;         if (add1 >= 1e10) add1 = 0;         for (int j = 0; j < 2; j++) {           if (notGreen[j].size() == 0) continue;           add1 += x - lasty;           long long maxi =               max(notGreen[j].front() - lasty, x - notGreen[j].back());           for (int k = 0; k < notGreen[j].size() - 1; k++)             maxi = max(maxi, notGreen[j][k + 1] - notGreen[j][k]);           add1 -= maxi;           notGreen[j] = vector<long long>();         }         ret += min(add1, add2);         lasty = x;       } else if (c ==  R ) {         notGreen[0].push_back(x);         rMin = min(rMin, x);         rMax = max(rMax, x);       } else {         notGreen[1].push_back(x);         bMin = min(bMin, x);         bMax = max(bMax, x);       }     }     if (gMin > gMax) ret = max(0ll, rMax - rMin) + max(0ll, bMax - bMin);     cout << ret <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int x, y;   };   int n, m, d[5005];   node a[5005];   bool cmp(const node &x, const node &y) {     return x.x == y.x ? x.y < y.y : x.x < y.x;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d%d , &a[i].x, &a[i].y);     sort(a + 1, a + 1 + n, cmp);     memset(d, 0, sizeof(d));     int ans = min(a[1].x, a[1].y);     for (int i = 2; i <= n; i++)       if (ans > a[i].y)         ans = a[i].x;       else         ans = a[i].y;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   template <typename T>   void Print(T a[], T n) {     for (int i = 0; i < n; i++) {       cout << a[i] <<    ;     }     cout << endl;   }   void solve() {     int n;     cin >> n;     string s, t;     cin >> s >> t;     if (s == t) {       cout << 0 <<   n ;       return;     }     int same1 = 0, diff1 = 0, same = 0;     for (int i = 0; i < n; i++) {       if (s[i] == t[i]) {         same++;         if (s[i] ==  1 ) same1++;       } else {         if (s[i] ==  1 ) diff1++;       }     }     int diff = n - same;     if (same == n) {       cout << 0 <<   n ;       return;     }     int ans = INT_MAX;     if (same1 - 1 == same - same1) {       ans = min(ans, same);     }     if (diff1 == diff - diff1) {       ans = min(ans, diff);     }     if (ans != INT_MAX)       cout << ans <<   n ;     else       cout << -1 <<   n ;   }   void solve1() {     int n;     cin >> n;     string s, t;     cin >> s >> t;     if (s == t) {       cout << 0 <<   n ;       return;     }     int same1 = 0, diff1 = 0, same = 0;     for (int i = 0; i < n; i++) {       if (s[i] == t[i]) {         same++;         if (s[i] ==  1 ) same1++;       } else {         if (s[i] ==  1 ) diff1++;       }     }     int diff = n - same;     int ans = INT_MAX;     if (diff % 2 == 0) {       int one = (diff + 1) / 2;       if (diff1 == one) {         ans = min(ans, diff);       }     }     if (same % 2 != 0) {       int one = (same + 1) / 2;       if (same1 == one) {         ans = min(ans, same);       }     }     if (ans == INT_MAX)       cout << -1 <<   n ;     else       cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     int t;     cin >> t;     while (t--) solve1();   }