malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 5;   int n, v, e;   bool bo[N][N], vis[N];   vector<int> path[N][N];   int a[N], b[N];   vector<int> G[N];   long long A, B;   void dfs(int x) {     A += a[x];     B += b[x];     vis[x] = 1;     for (int i = 0; i < G[x].size(); i++) {       int u = G[x][i];       if (vis[u]) continue;       dfs(u);     }   }   int ans, X[N * N], Y[N * N], D[N * N];   void dfs(int st, int pre, int ed) {     path[st][ed] = path[st][pre];     path[st][ed].push_back(ed);     vis[ed] = 1;     for (int i = 0; i < G[ed].size(); i++) {       int u = G[ed][i];       if (vis[u]) continue;       dfs(st, ed, u);     }   }   void work(int st, int ed, int flow, int id) {     int tmp = path[st][ed][id];     if (tmp == ed) return;     int tmp1 = path[st][ed][++id];     ++ans;     X[ans] = tmp;     Y[ans] = tmp1;     D[ans] = max(0, flow - a[tmp1]);     int rem = flow - D[ans];     if (rem == flow) ans--;     work(st, ed, flow, id);     if (rem) {       ++ans;       X[ans] = tmp;       Y[ans] = tmp1;       D[ans] = rem;     }   }   int main() {     scanf( %d%d%d , &n, &v, &e);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= n; i++) scanf( %d , b + i);     while (e--) {       int x, y;       scanf( %d%d , &x, &y);       G[x].push_back(y);       G[y].push_back(x);       bo[x][y] = bo[y][x] = 1;     }     for (int i = 1; i <= n; i++) {       if (vis[i]) continue;       A = B = 0;       dfs(i);       if (A != B) return puts( NO );     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         for (int k = 1; k <= n; k++) bo[j][k] |= bo[j][i] && bo[i][k];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) vis[j] = 0;       dfs(i, 0, i);     }     while (1) {       bool ok = 1;       for (int i = 1; i <= n; i++) {         if (b[i] >= a[i]) continue;         for (int j = 1; j <= n; j++) {           if (i == j || !bo[i][j]) continue;           if (b[j] <= a[j]) continue;           int flow = min(a[i] - b[i], b[j] - a[j]);           work(i, j, flow, 0);           a[i] -= flow;           a[j] += flow;           ok = 0;         }       }       if (ok) break;     }     printf( %d n , ans);     for (int i = 1; i <= ans; i++) printf( %d %d %d n , X[i], Y[i], D[i]);   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void rd(T &x) {     x = 0;     int f = 1;     char c;     while (!isdigit(c = getchar()))       if (c ==  - ) f = -1;     do {       x = (x << 1) + (x << 3) + (c ^ 48);     } while (isdigit(c = getchar()));     x *= f;   }   const int N = 3e5 + 5;   struct ANS {     int l, r, d;   };   struct node {     int v, id;     bool operator<(const node &x) const { return v < x.v; }   } s[N];   vector<ANS> ans;   int t[N], n;   int main() {     rd(n);     for (int i = 1; i <= n; i++) rd(s[i].v), s[i].id = i;     for (int i = 1; i <= n; i++) rd(t[i]);     sort(s + 1, s + n + 1);     sort(t + 1, t + n + 1);     int i = 1, j = 2;     while (1) {       if (s[i].v > t[i]) return !printf( NO );       while (s[j].v <= t[j]) j++;       while (s[i].v == t[i]) i++;       if (j >= n + 1 || i > j) break;       int tmp = min((s[j].v - s[i].v) >> 1, min(t[i] - s[i].v, s[j].v - t[j]));       if (tmp)         ans.push_back({s[i].id, s[j].id, tmp}), s[i].v += tmp, s[j].v -= tmp;     }     for (int i = 1; i <= n; i++)       if (s[i].v != t[i]) return !printf( NO );     cout <<  YES  << endl << ans.size() << endl;     for (auto it : ans) cout << it.l <<     << it.r <<     << it.d << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p[2048];   vector<int> s[2048];   int main() {     int n;     int a;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a;       p[i] = a;       s[a].push_back(i);     }     int res = 0;     bool fl = true;     int k = 1;     while (fl) {       fl = false;       for (int i = 1; i <= n; i++) {         if (p[i] == -k) {           p[i] = 0;           for (int j = 0; j < s[i].size(); j++) p[s[i][j]] = -k - 1;           fl = true;         }       }       if (fl) res++;       k++;     }     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int int_inf = 0x3f3f3f3f;   const long long int ll_inf = 0x3f3f3f3f3f3f3f3f;   const int max_n = 1e5 + 5;   bool g[max_n];   int head[max_n], nxt[max_n << 2], to[max_n << 2], cnt;   int dis[max_n];   int n, start, end1;   struct nodes {     int dis, v;     bool operator<(const struct nodes a) const { return dis > a.dis; }   };   void add(int a, int b) {     nxt[++cnt] = head[a];     head[a] = cnt;     to[cnt] = b;     return;   }   int max1;   void dijkstra() {     int i;     for (i = 0; i <= n; i++) dis[i] = int_inf;     dis[start] = 0;     priority_queue<nodes> q;     q.push((nodes){0, start});     while (!q.empty()) {       nodes t = q.top();       q.pop();       if (t.dis > dis[t.v]) continue;       dis[t.v] = t.dis;       max1 = max(max1, t.dis);       int tdis = t.dis + 1;       if (g[t.v]) tdis = 1;       if (t.v == end1) break;       for (i = head[t.v]; i; i = nxt[i]) {         if (tdis < dis[to[i]]) {           dis[to[i]] = tdis;           q.push((nodes){tdis, to[i]});         }       }     }     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int i, j;     int m, k;     cin >> n >> m >> k;     for (i = 0; i < k; i++) {       int num;       cin >> num;       g[num] = true;     }     while (m--) {       int a, b;       cin >> a >> b;       add(a, b);       add(b, a);     }     cin >> start >> end1;     if (!g[start]) {       if (start == end1)         cout << 0 << endl;       else         cout << -1 << endl;     } else {       max1 = -1;       dijkstra();       cout << ((dis[end1] == int_inf) ? -1 : max1) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double PI = 3.14159265358979323843;   void Time() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   void print(int n) {     if (n == 0) {       return;     }     print(n - 1);     cout <<  Hello world  << endl;   }   long long arr[100000];   int main() {     Time();     string s;     int A = 0, B = 0, C = 0;     for (int i = 0; i < 3; i++) {       cin >> s;       if (s[0] ==  A  && s[1] ==  >  || s[2] ==  A  && s[1] ==  < ) {         A++;       } else if (s[0] ==  B  && s[1] ==  >  || s[2] ==  B  && s[1] ==  < ) {         B++;       } else if (s[0] ==  C  && s[1] ==  >  || s[2] ==  C  && s[1] ==  < ) {         C++;       }     }     if (A == B && A == C) {       cout <<  Impossible  << endl;     } else if (A > B && A > C && B > C) {       cout <<  CBA  << endl;     } else if (A > B && A > C && C > B) {       cout <<  BCA  << endl;     } else if (B > A && B > C && A > C) {       cout <<  CAB  << endl;     } else if (B > A && B > C && C > A) {       cout <<  ACB  << endl;     } else if (C > A && C > B && A > B) {       cout <<  BAC  << endl;     } else if (C > A && C > B && B > A) {       cout <<  ABC  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int n, m;   char s[5005];   long long state[5005];   long long dp[5005][5005];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %s , s + 1);       for (int j = 1; j <= n; j++)         if (s[j] ==  1 ) state[j] |= (1ll << (i - 1));     }     dp[0][0] = 1;     for (int i = 1; i <= n; i++) {       dp[i][0] = dp[i - 1][i - 1];       for (int j = 1; j <= n; j++) {         dp[i][j] = (dp[i - 1][j - 1] + dp[i][j - 1]);         if (dp[i][j] >= mod) dp[i][j] -= mod;       }     }     sort(state + 1, state + 1 + n);     long long ans = 1;     for (int i = 1; i <= n; i++) {       int j = i;       for (j = i; state[j] == state[i] && j <= n; j++)         ;       ans *= (dp[j - i][0]);       ans %= mod;       i = j - 1;     }     printf( %I64d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300000 + 7;   int n, q;   long long val[N];   struct edge {     int to, nex;     long long wei;   } e[N << 1];   int fir[N], eid;   int siz[N], dep[N], fa[N], son[N], ltp[N];   long long faw[N];   int dfn[N], inx;   long long f[N], g[N];   long long bit[N];   void addedge(int u, int v, int w);   void dfs1(int s);   void dfs2(int s);   void dfs3(int s, long long up);   void build();   int lca(int x, int y);   long long get(int x, int z);   void add(int i, long long v);   long long sum(int i);   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; ++i) scanf( %lld , val + i);     for (int i = 1, u, v, w; i < n; ++i)       scanf( %d%d%d , &u, &v, &w), addedge(u, v, w), addedge(v, u, w);     dfs1(1);     ltp[1] = 1;     dfs2(1);     dfs3(1, 0);     build();     for (int x, y, z; q; --q) {       scanf( %d%d , &x, &y);       if (x == y)         printf( %lld n , g[x]);       else         z = lca(x, y), printf( %lld n , g[z] + get(x, z) + get(y, z));     }     return 0;   }   void addedge(int u, int v, int w) {     e[++eid] = (edge){v, fir[u], 1ll * w};     fir[u] = eid;   }   void dfs1(int s) {     siz[s] = 1;     f[s] = val[s];     for (int i = fir[s]; i; i = e[i].nex) {       if (e[i].to == fa[s]) continue;       fa[e[i].to] = s;       faw[e[i].to] = e[i].wei;       dep[e[i].to] = dep[s] + 1;       dfs1(e[i].to);       siz[s] += siz[e[i].to];       son[s] = siz[e[i].to] > siz[son[s]] ? e[i].to : son[s];       f[s] += max(0ll, f[e[i].to] - 2 * e[i].wei);     }   }   void dfs2(int s) {     dfn[s] = ++inx;     if (!son[s]) return;     ltp[son[s]] = ltp[s];     dfs2(son[s]);     for (int i = fir[s]; i; i = e[i].nex)       if (e[i].to != fa[s] && e[i].to != son[s])         ltp[e[i].to] = e[i].to, dfs2(e[i].to);   }   void dfs3(int s, long long up) {     g[s] = f[s] + max(0ll, up);     for (int i = fir[s]; i; i = e[i].nex)       if (e[i].to != fa[s])         dfs3(e[i].to, g[s] - max(0ll, f[e[i].to] - 2 * e[i].wei) - 2 * e[i].wei);   }   void build() {     for (int i = 1; i <= n; ++i)       add(dfn[i], f[i] - max(0ll, f[i] - 2 * faw[i]) - faw[i]);   }   int lca(int x, int y) {     for (; ltp[x] != ltp[y]; x = fa[ltp[x]])       if (dep[ltp[x]] < dep[ltp[y]]) swap(x, y);     return dep[x] < dep[y] ? x : y;   }   long long get(int x, int z) {     long long t = 0;     for (; ltp[x] != ltp[z]; x = fa[ltp[x]])       t += sum(dfn[x]) - sum(dfn[ltp[x]] - 1);     return t + sum(dfn[x]) - sum(dfn[z]);   }   void add(int i, long long v) {     for (; i <= n; i += i & -i) bit[i] += v;   }   long long sum(int i) {     long long t = 0;     for (; i; i -= i & -i) t += bit[i];     return t;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000001;   int eu[N], ev[N];   vector<pair<int, int> > g[N];   bool vis[N];   bool be[N];   int dfn[N], low[N], vbel[N], ebel[N], dfc, ebcc;   int sz[N];   int dfs_ebcc(int u, int f) {     static int s[N], t;     s[++t] = u;     dfn[u] = low[u] = ++dfc;     for (pair<int, int> p : g[u]) {       int v = p.first, i = p.second;       if (vis[i]) continue;       vis[i] = 1;       s[++t] = -i;       if (!dfn[v]) {         if (eu[i] != u) swap(eu[i], ev[i]);         low[u] = min(low[u], dfs_ebcc(v, i));       } else {         if (low[v] < low[u] && eu[i] != u) swap(eu[i], ev[i]);         low[u] = min(low[u], low[v]);       }     }     if (dfn[u] == low[u]) {       for (++ebcc; s[t] != -f; --t)         s[t] > 0 ? vbel[s[t]] = ebcc : ebel[-s[t]] = ebcc;       if (t) --t;     }     return low[u];   }   vector<pair<int, int> > gt[N];   void dfs_dir(int u, int f) {     for (pair<int, int> p : gt[u]) {       int v = p.first, i = p.second;       if (v == f) continue;       if (vbel[eu[i]] == u) swap(eu[i], ev[i]);       dfs_dir(v, u);     }   }   int tarjan_ebcc(int n, int m) {     dfc = ebcc = 0;     fill_n(vis + 1, m, 0);     fill_n(ebel + 1, m, 0);     fill_n(dfn + 1, n, 0);     for (int u = 1; u <= n; ++u)       if (!dfn[u]) dfs_ebcc(u, 0);     for (int i = 1; i <= n; ++i) sz[vbel[i]]++;     for (int i = 1; i <= m; ++i) {       if (ebel[i]) continue;       gt[vbel[eu[i]]].emplace_back(vbel[ev[i]], i);       gt[vbel[ev[i]]].emplace_back(vbel[eu[i]], i);     }     int r = max_element(sz + 1, sz + ebcc + 1) - sz;     dfs_dir(r, 0);     return sz[r];   }   int main(void) {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; ++i) {       int u, v;       scanf( %d%d , &u, &v);       eu[i] = u;       ev[i] = v;       g[u].emplace_back(v, i);       g[v].emplace_back(u, i);     }     int ans = tarjan_ebcc(n, m);     printf( %d n , ans);     for (int i = 1; i <= m; ++i) printf( %d %d n , eu[i], ev[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     for (int(_) = 0; (_) < (n); (_)++) {       string S, T;       cin >> S >> T;       S.push_back( A );       T.push_back( A );       vector<pair<char, int> > sl, tl;       char ns = S[0];       int cs = 1;       for (int i = 1; i <= (int)(((int)(S).size()) - 1); i++) {         if (S[i] == ns)           cs++;         else {           sl.push_back(make_pair(ns, cs));           ns = S[i];           cs = 1;         }       }       char nt = T[0];       int ct = 1;       for (int i = 1; i <= (int)(((int)(T).size()) - 1); i++) {         if (T[i] == nt)           ct++;         else {           tl.push_back(make_pair(nt, ct));           nt = T[i];           ct = 1;         }       }       bool ans = true;       if (((int)(sl).size()) != ((int)(tl).size())) ans = false;       for (int(i) = 0; (i) < (((int)(sl).size())); (i)++) {         if (sl[i].first != tl[i].first) ans = false;         if (sl[i].second > tl[i].second) ans = false;       }       if (ans)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long n, a[100001], b[100001], c[100001], k, x;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       b[a[i]] = i;     }     c[b[n]] = 0;     for (long long i = n - 1; i >= 1; i--) {       x = b[i];       for (long long j = (x - 1) % i + 1; j <= n; j += i) {         if (a[j] > i && c[j] == 0) {           c[x] = 1;           break;         }       }     }     for (int i = 1; i <= n; i++) {       if (c[i])         cout <<  A ;       else         cout <<  B ;     }   }
#include <bits/stdc++.h>   using namespace std;   int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};   int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};   const double PI = acos(-1.0);   const double EPS = 1e-6;   const int MOD = (int)1e9 + 7;   const int maxn = (int)3e5 + 10;   const int LOGN = 20;   struct Upd {     int x, d;     Upd(int xx, int dd) {       x = xx;       d = dd;     }   };   int n;   long long c[maxn];   vector<Upd> upd[maxn];   vector<int> g[maxn];   int dep[maxn];   long long BIT[maxn];   void add(int pos, int val) {     while (pos <= n) {       BIT[pos] += val;       pos += (pos & -pos);     }   }   long long sum(int pos) {     long long sum = 0;     while (pos > 0) {       sum += BIT[pos];       pos -= (pos & -pos);     }     return sum;   }   void dfs_cal(int u, int p) {     dep[u] = dep[p] + 1;     for (Upd up : upd[u]) {       add(1, up.x);       add(dep[u] + up.d, -up.x);     }     c[u] += sum(dep[u]);     for (int v : g[u])       if (v != p) {         dfs_cal(v, u);       }     for (Upd up : upd[u]) {       add(1, -up.x);       add(dep[u] + up.d, up.x);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 1; i <= (n - 1); i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     int q;     cin >> q;     for (int i = 1; i <= (q); i++) {       int v, d, x;       cin >> v >> d >> x;       ++d;       d = min(d, n);       upd[v].push_back(Upd(x, d));     }     dfs_cal(1, 0);     for (int i = 1; i <= (n); i++) cout << c[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using ld = long double;   using ll = long long;   using namespace std;      int MOD = 998244353;      void solve() {    int n; cin >> n;    vector<vector<int>> p(n + n, vector<int>(n));    for (int i = 0; i < 2 * n; i++) {     for (int j = 0; j < n; j++) {      cin >> p[i][j]; p[i][j]--;     }    }    vector<int> cnt(n);    bool good = 1;    vector<int> result;    vector<int> del(n + n);    vector<int> cros(n + n);       int cringe = 0;       auto accept = [&](int k) {     del[k] = 1;     for (int i = 0; i < n + n; i++) {      if (del[i]) continue;      for (int j = 0; j < n; j++) {       if (p[i][j] == p[k][j]) {        del[i] = 1;        cringe = 1;        break;       }      }     }     cros[k] = 1;     result.push_back(k);    };    while (good) {     good = 0;     for (int i = 0; i < n; i++) {      fill(cnt.begin(), cnt.end(), 0);      for (int j = 0; j < n + n; j++) if (!del[j]) cnt[p[j][i]]++;      for (int j = 0; j < n; j++) {       if (cnt[j] == 1) {        good = 1;        for (int k = 0; k < n + n; k++) {         if (!del[k] && p[k][i] == j) {          accept(k);          break;         }        }        break;       }      }      if (good) break;     }    }    vector<vector<int>> g(n + n);    for (int i = 0; i < n + n; i++) {     for (int j = 0; j < n + n; j++) {      for (int k = 0; k < n; k++) {       if (del[i] && !cros[i]) continue;       if (del[j] && !cros[j]) continue;       if (p[i][k] == p[j][k]) g[i].push_back(j);      }     }    }    vector<int> col(n + n, -1);    int rs = 1;       function<void(int, int)> dfs = [&](int v, int c=0) {     if (col[v] != -1) return;     col[v] = c;     for (auto u : g[v]) dfs(u, 1-c);    };        for (int i = 0; i < n + n; i++) {     if (cros[i]) {      if (col[i] == -1) dfs(i, 1);     }    }        for (int i = 0; i < n + n; i++) {     if (!del[i])     if (col[i] == -1) rs = rs * 2 % MOD, dfs(i, 1);    }    cout << rs <<   n ;    for (int i = 0; i < n + n; i++) {     if (col[i] == 1) cout << i + 1 <<    ;    }     cout <<   n ;   }      int main() {    ios_base::sync_with_stdio(0);     cin.tie(0);    cout.precision(30);    int t; cin >> t;    while (t--)     solve();    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j, k = 1, cnt = 0, cnt1 = 0, q = 2;     cin >> n;     int ar[n + 5];     for (i = 0; i < n / 2; i++) {       cin >> ar[i];     }     sort(ar, ar + (n / 2));     for (i = 0; i < n / 2; i++) {       cnt += abs(k - ar[i]);       k += 2;     }     for (i = 0; i < n / 2; i++) {       cnt1 += abs(q - ar[i]);       q += 2;     }     cout << min(cnt, cnt1) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     cin >> N;     while (N--) {       int n;       cin >> n;       int mid = n / 2 + 1;       for (int i = 0; i < n; i++) {         if (i == 0)           cout << mid <<    ;         else if (i % 2)           cout << mid - i / 2 - 1 <<    ;         else           cout << mid + i / 2 <<    ;       }       cout <<   n ;     }     return 0;   };
#include <bits/stdc++.h>   using namespace std;   const long long N = 50, INF = 0, MOD = 0;   long long n, m, a[N], tmp;   vector<long long> v;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> m >> n;     for (long long i = 0; i < n; i++) {       cout << 1 << endl;       fflush(stdout);       cin >> tmp;       if (tmp == 0 || tmp == -2) return 0;       if (tmp == -1) a[i] = 0;       if (tmp == 1) a[i] = 1;     }     long long l = 0, r = m + 1, cnt = 0;     while (r - l > 2 && cnt + n < 60) {       long long mid = (l + r) / 2;       cout << mid << endl;       fflush(stdout);       cin >> tmp;       if (tmp == 0 || tmp == -2) return 0;       if (a[cnt] == 0) tmp *= -1;       if (tmp == -1) r = mid;       if (tmp == 1) l = mid;       v.push_back(tmp);       cnt = (cnt + 1) % n;     }     cout << r - 1 << endl;     fflush(stdout);     cin >> tmp;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     long long A, B, n;     cin >> A >> B >> n;     for (int i = 0; i < n; ++i) {       long long l, t, m;       cin >> l >> t >> m;       if (A + (l - 1) * B > t) {         cout <<  -1 n ;       } else {         long long ans = (t - A) / B + 1 - l + 1;         long long left = 1, right = ans + 1;         while (right - left > 1) {           long long temp = (right + left) >> 1;           if ((A + (l - 1) * B) * temp + (temp - 1) * temp * B / 2 > t * m)             right = temp;           else             left = temp;         }         cout << left + l - 1 <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long n, long long m) {     return n % m == 0 ? m : gcd(m, n % m);   }   const int Maxn = 2e3 + 10;   bool enable[Maxn][Maxn];   string Number[10] = { 1110111 ,  0010010 ,  1011101 ,  1011011 ,  0111010 ,                         1101011 ,  1101111 ,  1010010 ,  1111111 ,  1111011 };   int val[10];   int dval[Maxn];   void Ini() {     for (long long i = 0; i <= 9; i++)       for (long long j = 0; j <= 6; j++)         if (Number[i][j] ==  1 ) val[i] |= 1 << (7 - j - 1);   }   void Input(int& n, int& k) {     cin >> n >> k;     for (long long i = 1; i <= n; i++) {       string s;       cin >> s;       for (long long j = 0; j <= 6; j++)         if (s[j] ==  1 ) dval[i] |= 1 << (7 - j - 1);     }   }   void solve(int n, int k) {     enable[n + 1][0] = true;     for (int i = n; i >= 1; i--)       for (int j = 9; j >= 0; j--) {         if ((val[j] & dval[i]) == dval[i]) {           int diff = __builtin_popcount(val[j] ^ dval[i]);           for (int kk = diff; kk <= k; kk++)             enable[i][kk] |= enable[i + 1][kk - diff];         }       }     if (!enable[1][k]) {       cout << -1 << endl;       return;     }     string ans =   ;     int remain = k;     for (int i = 1; i <= n; i++)       for (int j = 9; j >= 0; j--) {         if ((val[j] & dval[i]) == dval[i]) {           int diff = __builtin_popcount(val[j] ^ dval[i]);           if (enable[i + 1][remain - diff]) {             ans += j +  0 ;             remain -= diff;             break;           }         }       }     cout << ans;   }   int main() {     ios::sync_with_stdio(false);     Ini();     int n, k;     Input(n, k);     solve(n, k);     return 0;   }
#include <vector>   #include <algorithm>   #include <queue>   #include <iostream>   #include <string>   #include <stack>   #include <map>   #include <fstream>   #include <random>   #include <iomanip>    #include <set>   #include <cmath>   #include <cassert>   #include <unordered_set>   #include <unordered_map>   using namespace std;      typedef long long int ll;   typedef long double ld;      const ll INF = 1e10;         ll gcd(ll a, ll b) {    return (b == 0 ? a : gcd(b, a % b));   }         ll binpow(ll a, ll p) {    if (p == 0) return 1;    if (p % 2) {     ll b = binpow(a, p - 1);     return b * a;    }    else {     ll b = binpow(a, p / 2);     return b * b;    }   }         vector<ll> get_primes(ll size) {    vector<bool> is_pr(size, true);    vector<ll> pr;       is_pr[0] = is_pr[1] = false;       for (ll i = 0; i < size; i++) {     if (is_pr[i] == false) continue;        pr.push_back(i);     for (ll j = i *i ; j < size; j+=i)      is_pr[j] = false;    }       return pr;   }         int main() {    //ifstream cin( input.txt );    //ofstream cout( output.txt );       int t; cin >> t;       vector<ll> primes = get_primes(4000);    while (t--) {     int n, k;     cin >> n >> k;        vector<ll> arr(n);        for (int i = 0; i < n; i++) {      cin >> arr[i];         for (ll p : primes) {       while (arr[i] % (p * p) == 0 && arr[i] >= p * p) {        arr[i] /= (p * p);       }          if (arr[i] < p * p) break;      }     }        ll res = 1;     set<ll> elem = { arr[0] };     for (int i = 1; i < n; i++) {      if (elem.find(arr[i]) == elem.end()) {       elem.insert(arr[i]);      }      else {       elem.clear();       elem.insert(arr[i]);       res++;      }     }        cout << res << endl;    }             return 0;   }