malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int mpow(int base, int exp);   void ipgraph(int m);   void dfs(int u, int par);   const int mod = 1000000007;   const int N = 1e6, M = N;   const int LN = 1e9;   long long dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   struct cmp {     bool operator()(const pair<int, int> &a, const pair<int, int> &b) {       int len1 = a.second - a.first + 1;       int len2 = b.second - b.first + 1;       if (len1 == len2) {         return a.first < b.first;       }       return len1 > len2;     }   };   long long fac[N], inv[N], b[N];   int mpow(int base, int exp) {     base %= mod;     int result = 1;     while (exp > 0) {       if (exp & 1) result = ((long long)result * base) % mod;       base = ((long long)base * base) % mod;       exp >>= 1;     }     return result;   }   void pre() {     int i;     fac[0] = inv[0] = 1;     fac[1] = inv[1] = 1;     for (i = 2; 2 < N ? i < N : i > N; 2 < N ? i += 1 : i -= 1) {       fac[i] = (i * fac[i - 1]) % mod;       inv[i] = (mpow(i, mod - 2) * inv[i - 1]) % mod;     }   }   long long C(int n, int r) {     if (r > n) return 0;     long long ans = fac[n];     ans *= inv[r];     ans %= mod;     ans *= inv[n - r];     ans %= mod;     return ans;   }   long long n;   vector<vector<int>> arr(50, vector<int>(50));   vector<int> permutation;   int chosen[100] = {0};   long long power(long long a, long long b) {     long long ans = 1;     while (b--) ans *= a;     return ans;   }   long long k;   long long dp[N][2];   vector<int> adj[N];   long long m;   void solve() {     long long a, b, c, p = 0, q, d, r, s, l, t, x, h, y, z, avg, x1, x2, y1, y2,                        i, j, ii, jj, count = 0;     string s1, s2 =   , sa =   , sb =   , sc =   , ans =   ;     cin >> a >> b >> c;     if (a >= c) {       cout << -1 <<    ;     } else {       cout << 1 <<    ;     }     if (c < a * b) {       cout << b << endl;     } else       cout << -1 << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int const MOD = 1000000007;   void add(int &a, int b) {     a += b;     if (a >= MOD) a -= MOD;   }   int f[42], when[42];   int main() {     int n, k;     scanf( %d%d , &n, &k);     int s = 1;     int c = getchar();     while (c <= 32) {       c = getchar();     }     int cn = 0;     while (c > 32) {       int olds = s;       add(s, s);       add(s, MOD - f[c -  a ]);       f[c -  a ] = olds;       when[c -  a ] = ++cn;       c = getchar();     }     for (int i = 0; i < n; i++) {       int v = -1;       for (int j = 0; j < k; j++) {         if (v < 0 || when[v] > when[j]) {           v = j;         }       }       when[v] = ++cn;       int olds = s;       add(s, s);       add(s, MOD - f[v]);       f[v] = olds;     }     printf( %d n , s);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int l, d, v, g, r, tmu;     double tm, tmod;     scanf( %d%d%d%d%d , &l, &d, &v, &g, &r);     tmu = (int)((long double)(d / v) / (g + r));     tmod = (double)d / v - tmu * (g + r);     if (tmod < g)       tm = (double)l / v;     else       tm = (double)l / v + (r - tmod + g);     printf( %.8f n , tm);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a;     cin >> n >> m;     int l = 0, r = n + 1;     string s, s1;     for (int i = 0; i < m; i++) {       cin >> s >> s >> s1 >> s >> a;       if (s1[0] ==  r )         l = max(l, a);       else         r = min(a, r);     }     int ans = r - l - 1;     if (ans <= 0)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y;     cin >> n >> x >> y;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       int j = i - x;       int k = i + y;       if (j < 0) j = 0;       if (k > n - 1) k = n - 1;       int min = INT_MAX, index = -1;       for (int l = j; l <= k; l++) {         if (min > a[l]) {           min = a[l];           index = l;         }       }       if (index == i) {         cout << index + 1 <<   n ;         break;       } else {         i = index - 1;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void reverseStr(string& str) {     int n = str.length();     for (int i = 0; i < n / 2; i++) swap(str[i], str[n - i - 1]);   }   int main() {     string str, str1;     cin >> str;     cin >> str1;     reverseStr(str);     if (str == str1) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   void solve() {     long long n, m;     cin >> n >> m;     vector<long long> out(n);     long long leafs = n;     for (long long i = 0; i < m; ++i) {       long long x, y;       cin >> x >> y;       --x;       --y;       if (x > y) swap(x, y);       out[x]++;       if (out[x] == 1) --leafs;     }     long long q;     cin >> q;     while (q--) {       long long t;       cin >> t;       if (t == 3) {         cout << leafs << endl;       } else if (t == 1) {         long long u, v;         cin >> u >> v;         --u;         --v;         if (u > v) swap(u, v);         ++out[u];         if (out[u] == 1) --leafs;       } else {         long long u, v;         cin >> u >> v;         --u;         --v;         if (u > v) swap(u, v);         --out[u];         if (out[u] == 0) ++leafs;       }     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cout << fixed << setprecision(15);     long long t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> graph[3010];   int cycle[3010];   int cycle_size;   bool visited[3010];   bool found_cycle;   int dist[3010];   int b, e;   void dfs(int node, int father, int c) {     if (found_cycle) return;     visited[node] = true;     for (int i = 0; i < graph[node].size() && !found_cycle; i++) {       int nextn = graph[node][i];       if (visited[nextn] && nextn != father) {         cycle[c] = node;         cycle_size = c + 1;         while (cycle[c] != nextn) {           c--;         }         b = c;         found_cycle = true;         return;       }       if (nextn == father) continue;       cycle[c] = node;       dfs(nextn, node, c + 1);     }   }   void bfs() {     queue<pair<int, int> > q;     for (int i = b; i < cycle_size; i++) {       visited[cycle[i]] = true;       q.push(make_pair(cycle[i], 0));     }     while (!q.empty()) {       pair<int, int> aux = q.front();       q.pop();       dist[aux.first] = aux.second;       for (int i = 0; i < graph[aux.first].size(); i++) {         int nextn = graph[aux.first][i];         if (visited[nextn]) continue;         visited[nextn] = true;         q.push(make_pair(nextn, aux.second + 1));       }     }   }   int main() {     int n;     scanf( %d , &n);     int xi, yi;     for (int i = 0; i < n; i++) {       scanf( %d %d , &xi, &yi);       graph[xi].push_back(yi);       graph[yi].push_back(xi);     }     found_cycle = false;     memset(visited, false, sizeof(visited));     dfs(1, -1, 0);     memset(visited, false, sizeof(visited));     bfs();     for (int i = 1; i <= n; i++) printf( %d  , dist[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int N = 2e5 + 10;   int T, n, a[N], vis[N], d[N], mi, mx;   signed main() {     cin >> T;     while (T--) {       cin >> n;       mi = 0x3f3f3f3f, mx = -999;       for (int i = 1; i <= n; i++) scanf( %d , &a[i]), vis[a[i]] = i;       for (int i = 1; i <= n; i++) {         mi = min(mi, vis[i]), mx = max(mx, vis[i]);         if (mx - mi == i - 1)           putchar( 1 );         else           putchar( 0 );       }       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000 * 1000 * 1000;   const int MOD = INF + 7;   const int XD = 100100;   int facts[XD << 1];   void calcFacts(int n) {     facts[0] = 1;     for (int i = 1; i <= n; ++i) {       facts[i] = 1LL * facts[i - 1] * i % MOD;     }   }   int exgcd(int a, int b, int &x, int &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     int xx, yy;     int d = exgcd(b % a, a, xx, yy);     x = yy - b / a * xx;     y = xx;     return d;   }   int getInv(int n) {     int x, y;     exgcd(n, MOD, x, y);     x = (x % MOD + MOD) % MOD;     return x;   }   int cnk(int n, int k) {     return 1LL * facts[n] * getInv(facts[n - k]) % MOD * getInv(facts[k]) % MOD;   }   int main() {     int zeroes, ones, sm;     cin >> zeroes >> ones >> sm;     if (zeroes == 0) {       if (sm == 1) {         cout << ((ones == 1) ? 1 : 0);       } else {         cout << ((ones == 1) ? 0 : 1);       }       return 0;     }     if (ones == 0) {       if (sm == 1) {         cout << ((zeroes & 1) ? 0 : 1);       } else {         cout << ((zeroes & 1) ? 1 : 0);       }       return 0;     }     calcFacts(zeroes + ones);     int res = 0;     for (int pos = 0; pos <= zeroes; ++pos) {       if (sm == 0 &&           (pos % 2 == 0 && (pos < zeroes || pos == zeroes && ones > 1) ||            pos % 2 == 1 && (pos == zeroes && ones == 1))) {         res += cnk(zeroes + ones - pos - 1, ones - 1);         res %= MOD;       }       if (sm == 1 &&           (pos % 2 == 1 && (pos < zeroes || pos == zeroes && ones > 1) ||            pos % 2 == 0 && (pos == zeroes && ones == 1))) {         res += cnk(zeroes + ones - pos - 1, ones - 1);         res %= MOD;       }     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[200][200], ans, n;   bool flag = true;   int main() {     ios::sync_with_stdio(false);     cin >> a[80][80] >> n;     while (flag) {       flag = false;       for (int i = 1; i < 160; i++)         for (int j = 1; j < 160; j++)           if (a[i][j] >= 4) {             flag = true;             int k = a[i][j] / 4;             a[i + 1][j] += k, a[i - 1][j] += k;             a[i][j + 1] += k, a[i][j - 1] += k;             a[i][j] -= 4 * k;           }     }     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       if (-80 < x && x < 80 && -80 < y && y < 80)         cout << a[x + 80][y + 80] <<   n ;       else         cout << 0 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     long long int n, m, k;     cin >> n >> m >> k;     vector<long long int> ans;     if (k > 1) {       long long int last = 0;       for (long long int i = 0; i < k; i++) {         ans.push_back(0);       }       last = n - 1;       for (long long int i = 1; i < n + m; i++) {         if (i == last) {           ans.push_back(i);         } else if (i == last + 1) {           for (long long int j = 0; j < k - 1; j++) ans.push_back(i);           last = i + n - 1;         }       }     } else {       ans.push_back(0);       long long int last = n - 1;       for (long long int i = 1; i < n + m; i++) {         if (i == last) {           ans.push_back(i);           last = i + n - 1;         }       }     }     cout << ans.size() <<   n ;     for (auto i : ans) cout << i + 1 <<    ;     return 0;   }
#include <bits/stdc++.h>   int a, b, c, d, n;   char s[4 << 20];   void output() {     for (int i = 0; i < n; ++i)       if (s[i] ==  4 )         a--;       else         b--;     for (int i = 0; i < n; ++i)       if (s[i] ==  4 ) {         while (a) {           printf( 4 );           a--;         }         printf( 4 );       } else {         while ((i + 2 >= n) && b) {           printf( 7 );           b--;         }         printf( 7 );       }     printf(  n );     exit(0);   }   void look(char c4, char c7, int a, int b, int c, int d) {     n = 0;     while (c) {       if (n) d--;       s[n++] = c4;       s[n++] = c7;       a--;       b--;       c--;     }     if (d > 0) {       s[n++] = c4;       a--;       d--;     }     if ((a < 0) || (b < 0) || (c != 0) || (d != 0)) return;     output();   }   int main() {     scanf( %d%d%d%d , &a, &b, &c, &d);     look( 4 ,  7 , a, b, c, d);     look( 7 ,  4 , b, a, d, c);     printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   const int inf = 0x3f3f3f3f;   int n, m;   long long ans;   long long b[maxn], g[maxn];   bool cmp(int a, int b) { return a > b; }   int main() {     long long bmx = 0;     int flag = 1, cnt = 0;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %lld , &b[i]);       ans += b[i] * m;       bmx = max(bmx, b[i]);     }     sort(b + 1, b + 1 + n, cmp);     for (int i = 1; i <= m; i++) {       scanf( %lld , &g[i]);       if (g[i] < bmx) flag = 0;       if (g[i] > bmx) {         cnt++;         ans += g[i] - b[1 + cnt / m];       }     }     if (flag) {       printf( %lld n , ans);     } else {       printf( -1 n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n * 2];     for (int i = 0; i < n * 2; i++) {       cin >> a[i];     }     int room = 0;     for (int i = 0; i < n * 2; i++) {       if (i % 2 == 0) {         if (a[i + 1] - a[i] >= 2) {           room++;         }       }     }     cout << room;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s =   ;     int f[n];     f[0] = 1, f[1] = 1;     if (n > 1 && n < 5) {       for (int i = 2; i < 2 * n; i++) f[i] = f[i - 2] + f[i - 1];       int g = 1, k = 0;       while (g <= n) {         for (int j = 0; j < 2 * n; j++)           if (g == f[j]) {             k++;           }         if (k > 0)           s = s +  O ;         else if (k == 0)           s = s +  o ;         g++;         k = 0;       }     } else {       for (int i = 2; i < n; i++) f[i] = f[i - 2] + f[i - 1];       int g = 1, k = 0;       while (g <= n) {         for (int j = 0; j < n; j++)           if (g == f[j]) {             k++;           }         if (k > 0)           s = s +  O ;         else if (k == 0)           s = s +  o ;         g++;         k = 0;       }     }     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool check(long long int arr1[], long long int arr2[], long long int m,              long long int n) {     sort(arr1, arr1 + n);     sort(arr2, arr2 + m);     for (int i = 0; i < n; i++)       if (arr1[i] != arr2[i]) return false;     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, m, x, y;       cin >> n >> m >> x >> y;       char a[n][m], dp[n + 1][m + 1];       long long int c = 0, ans = 0;       for (long long int i = 0; i < n; i++) {         for (long long int j = 0; j < m; j++) {           cin >> a[i][j];         }       }       memset(dp, 0, sizeof(dp));       dp[1][1] = x;       for (long long int i = 0; i < n; i++) {         c = 0;         for (long long int j = 0; j < m; j++) {           if (a[i][j] ==  .  && j + 1 < m && a[i][j + 1] ==  . ) {             ans += min(x * 2, y);             j++;           } else if (a[i][j] ==  . )             ans += x;         }       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2e9 + 10;   int read() {     int xx = 0, ww = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) ww = -ww;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       xx = 10 * xx + ch - 48;       ch = getchar();     }     return xx * ww;   }   deque<int> q;   int n, k, a;   int main() {     n = read();     k = read();     for (int i = 1; i <= n; i++) q.push_back(i);     for (int i = 1; i <= k; i++) {       a = read();       a %= q.size();       while (a--) {         q.push_back(q.front());         q.pop_front();       }       int v = q.front();       q.pop_front();       if (i != 1) printf(   );       printf( %d , v);     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, l, r, x, ans[300300], tree[4 * 300300];   void build(int node, int st, int en) {     if (st == en) {       tree[node] = 1;       return;     }     build((node << 1), st, (st + en) / 2);     build((node << 1) + 1, ((st + en) / 2) + 1, en);     tree[node] = tree[(node << 1)] + tree[(node << 1) + 1];   }   void update(int node, int st, int en, int left, int right, int val) {     if (left > en || right < st) return;     if (tree[node] == 0) return;     if (st == en) {       tree[node] = (st == x ? 1 : 0);       ans[st] = val;       return;     }     update((node << 1), st, (st + en) / 2, left, right, val);     update((node << 1) + 1, ((st + en) / 2) + 1, en, left, right, val);     tree[node] = tree[(node << 1)] + tree[(node << 1) + 1];   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     build(1, 1, n);     while (m--) {       cin >> l >> r >> x;       update(1, 1, n, l, r, x);     }     ans[x] = 0;     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   struct Nodo {     int a;     int sgte;   } Nodo[100100];   long long aux[50010][510];   long long int cont;   int dir[50001];   int n, k;   void agregar(int x, int y, int c);   void busqueda(int fa, int u);   int main() {     int x, y, i, t, cargado = 0;     scanf( %d %d , &n, &k);     for (t = 0; t < 50010; t++) {       dir[t] = -1;     }     for (i = 0; i < (n - 1); i++) {       scanf( %d %d , &x, &y);       agregar(x, y, cargado);       cargado++;       agregar(y, x, cargado);       cargado++;     }     busqueda(0, 1);     printf( %I64d , cont);     return 0;   }   void busqueda(int ant, int act) {     int i = 0, v, j;     aux[act][0] = 1;     for (i = dir[act]; i != -1; i = Nodo[i].sgte) {       v = Nodo[i].a;       if (ant != v) {         busqueda(act, v);         for (j = 0; j < k; j++) {           cont += aux[act][j] * aux[v][k - j - 1];         }         for (j = 1; j <= k; j++) {           aux[act][j] += aux[v][j - 1];         }       }     }   }   void agregar(int x, int y, int c) {     Nodo[c].a = y;     Nodo[c].sgte = dir[x];     dir[x] = c;   }
#include <bits/stdc++.h>   using namespace std;   long long k;   long long maxi = 0, mini = 0;   vector<long long> v[200001];   long long dp[200001];   unordered_map<long long, unordered_map<long long, long long> > dis;   long long f(long long parent) {     if (dp[parent] > 0) return dp[parent];     dp[parent] = -1;     long long ans = 0;     for (long long i = 0; i < v[parent].size(); i++) {       long long child = v[parent][i];       if (dp[child] != -1) ans += f(child);     }     dp[parent] = ans + 1;     for (long long i = 0; i < v[parent].size(); i++) {       long long child = v[parent][i];       if (dp[child] != -1) {         maxi += (min(dp[child], 2 * k - dp[child]) * (dis[child][parent]));         if (dp[child] % 2 == 1 || 2 * k - dp[child] % 2 == 1)           mini += dis[child][parent];       }     }     return dp[parent];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       maxi = 0;       mini = 0;       long long start;       cin >> k;       for (long long i = 1; i <= 2 * k; i++) v[i].clear();       dp[2 * k - 1] = 0;       dp[2 * k] = 0;       for (long long i = 0; i < 2 * k - 1; i++) {         dp[i] = 0;         long long u1, u2, time;         cin >> u1 >> u2 >> time;         v[u1].push_back(u2);         v[u2].push_back(u1);         dis[u2][u1] = time;         dis[u1][u2] = time;       }       for (long long i = 1; i <= 2 * k; i++) {         if (v[i].size() == 1) {           start = i;           dp[i] = 1;         }       }       dp[start] = -1;       f(start);       cout << mini <<     << maxi << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int arr[1009];     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &arr[i]);     int x1, y1, x2, y2;     for (int i = 0; i < n - 1; i++) {       x1 = min(arr[i], arr[i + 1]);       y1 = max(arr[i], arr[i + 1]);       for (int j = i + 1; j < n - 1; j++) {         x2 = min(arr[j], arr[j + 1]);         y2 = max(arr[j], arr[j + 1]);         if ((x1 < x2 && y1 > x2 && y2 > y1) || (x2 < x1 && y2 > x1 && y1 > y2)) {           printf( yes n );           return 0;         }       }     }     printf( no n );     return 0;   }
#include <bits/stdc++.h>   int a[4 * 4];   int n, n2;   std::map<int, int> sums[4 + 1];   void gens(int p, int cnt, int sum, std::map<int, int>& s) {     if (cnt == 0) {       std::map<int, int>::iterator it = s.find(sum);       if (it == s.end())         s[sum] = 1;       else         ++it->second;       return;     }     if (p >= n2) return;     gens(p + 1, cnt, sum, s);     gens(p + 1, cnt - 1, sum + a[p], s);   }   int m[4][4];   int hs[4], vs[4], ds1, ds2;   bool used[4 * 4];   int sum;   void doit(int i, int j, int v) {     hs[i] += v;     vs[j] += v;     if (i == j) ds1 += v;     if (i == n - j - 1) ds2 += v;   }   bool gen(int i, int j) {     if (i == n) return true;     for (int k = 0; k < n2; ++k)       if (!used[k]) {         int v = a[k];         m[i][j] = v;         doit(i, j, v);         if (i == n - 1 && vs[j] != sum) {           doit(i, j, -v);           continue;         }         if (j == n - 1 && hs[i] != sum) {           doit(i, j, -v);           continue;         }         if (i == n - 1 && j == 0 && ds2 != sum) {           doit(i, j, -v);           continue;         }         if (i == n - 1 && j == n - 1 && ds1 != sum) {           doit(i, j, -v);           continue;         }         if (hs[i] > sum || vs[j] > sum || ds1 > sum || ds2 > sum) {           doit(i, j, -v);           continue;         }         used[k] = true;         int i2 = i, j2 = j + 1;         if (j2 == n) {           ++i2;           j2 = 0;         }         if (gen(i2, j2)) return true;         used[k] = false;         doit(i, j, -v);       }     return false;   }   int main() {     scanf( %d , &n);     n2 = n * n;     int min = 0;     for (int i = 0; i < n2; ++i) {       scanf( %d , &a[i]);       if (a[i] < min) min = a[i];     }     min = -min;     for (int i = 0; i < n2; ++i) a[i] += min;     for (int i = 1; i <= n; ++i) {       gens(0, i, 0, sums[i]);     }     bool res = false;     for (std::map<int, int>::const_iterator i = sums[n].begin();          i != sums[n].end(); ++i) {       sum = i->first;       memset(hs, 0, sizeof(hs));       memset(vs, 0, sizeof(vs));       memset(used, 0, sizeof(used));       ds1 = 0;       ds2 = 0;       if (gen(0, 0)) {         res = true;         break;       }     }     if (!res) {       printf( sorry. i am failed );       return 0;     }     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j) m[i][j] -= min;     int s = 0;     for (int i = 0; i < n; ++i) s += m[i][0];     printf( %d n , s);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         if (j > 0) printf(   );         printf( %d , m[i][j]);       }       printf(  n );     }     return 0;   }