malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   set<int> S;   priority_queue<pair<int, pair<int, int> >, vector<pair<int, pair<int, int> > >,                  greater<pair<int, pair<int, int> > > >       H;   int i, j, k, n, a[222222], nl, nr, sz, aa, bb, u[222222], o;   pair<int, pair<int, int> > pp;   set<pair<int, int> >::iterator it;   char s[222222];   int next(int k) {     set<int>::iterator it = S.find(k);     ++it;     if (it == S.end())       return -1;     else       return *it;   }   int pred(int k) {     set<int>::iterator it = S.find(k);     if (it == S.begin())       return -1;     else {       --it;       return *it;     }   }   int main() {     scanf( %d , &n);     gets(s);     gets(s);     for (i = 0; i < n; i++)       if (s[i] ==  B )         ++aa;       else         ++bb;     sz = min(aa, bb);     printf( %d n , sz);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 1; i <= n; i++) S.insert(i);     for (i = 1; i < n; i++)       if (s[i - 1] != s[i])         H.push(make_pair(abs(a[i] - a[i - 1]), make_pair(i, i + 1)));     o = 0;     while (o != sz) {       pp = H.top();       H.pop();       if (u[pp.second.first]) continue;       if (u[pp.second.second]) continue;       printf( %d %d n , pp.second.first, pp.second.second);       nl = pred(pp.second.first);       nr = next(pp.second.second);       if (nl > -1 && nr > -1 && s[nl - 1] != s[nr - 1])         H.push(make_pair(abs(a[nl - 1] - a[nr - 1]), make_pair(nl, nr)));       S.erase(S.find(pp.second.first));       S.erase(S.find(pp.second.second));       u[pp.second.first] = 1;       u[pp.second.second] = 1;       ++o;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)3 * 1e5 + 21;   const double eps = (double)1e-8;   const int mod = (int)1000000007;   int a[maxn], b[maxn];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, x;     memset((a), 0, sizeof(a));     ;     memset((b), 0, sizeof(b));     ;     cin >> n >> x;     long long ans = 0;     for (int i = (0); i < (n); i++) {       cin >> a[i];       ans += b[a[i] ^ x];       b[a[i]]++;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int ToInt(string& s, int len) {     int r = 0;     for (int i = 0, max_ = (len); i < max_; ++i) {       r *= 10;       r += s[i] -  0 ;     }     return r;   }   int GCD(int a, int b) { return b != 0 ? GCD(b, a % b) : a; }   int LCM(int a, int b) { return a * (b / GCD(a, b)); }   long long Pow(long long n, long long e) {     if (e == 0) return 1;     if (e == 1)       return n;     else if (e & 1) {       long long t = Pow(n, e / 2);       return n * t * t;     } else {       long long t = Pow(n, e / 2);       return t * t;     }   }   vector<int> v[100005];   bool usedDiv[100005], usedCol[100005];   int divID[100005];   int main() {     int N, M;     scanf( %d %d , &N, &M);     for (int i = (1), max_ = (N + 1); i < max_; ++i) {       int j = 1;       while (j * j <= i) {         if (i % j == 0) {           if (j != 1) v[i].push_back(j);           v[i].push_back(i / j);         }         ++j;       }     }     char c;     int n;     for (int i = 0, max_ = (M); i < max_; ++i) {       cin >> c >> n;       if (c ==  + ) {         if (usedCol[n])           printf( Already on n );         else {           int collisionWith = -1;           bool collision = false;           for (int j = 0, max_ = ((int)(v[n]).size()); j < max_; ++j)             if (usedDiv[v[n][j]]) {               collision = true;               collisionWith = divID[v[n][j]];               break;             }           if (collision) {             printf( Conflict with %d n , collisionWith);           } else {             printf( Success n );             usedCol[n] = true;             for (int j = 0, max_ = ((int)(v[n]).size()); j < max_; ++j) {               usedDiv[v[n][j]] = true;               divID[v[n][j]] = n;             }           }         }       } else if (c ==  - ) {         if (!usedCol[n])           printf( Already off n );         else {           printf( Success n );           usedCol[n] = false;           for (int j = 0, max_ = ((int)(v[n]).size()); j < max_; ++j)             usedDiv[v[n][j]] = false;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9, MAX = 100100, mod = 1000000007;   signed main() {     long long n, k, A, B;     cin >> n >> k >> A >> B;     long long ans = 0;     if (k == 1)       cout << (n - 1) * A;     else {       while (n != 1) {         if (n < k) {           ans = ans + (n - 1) * A;           n = 1;         } else if (n % k != 0) {           ans = ans + (n % k) * A;           n = n - n % k;         } else {           long long nis = n / k;           ans += min(B, (n - nis) * A);           n = n / k;         }       }       cout << ans;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int a, b, n, s;       cin >> a >> b >> n >> s;       if (((s % n) <= b) && (((a * n) + b) >= s)) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:268435456 )   using namespace std;   template <typename T>   inline T abs(T a) {     return ((a < 0) ? -a : a);   }   template <typename T>   inline T sqr(T a) {     return a * a;   }   template <class T>   T gcd(T a, T b) {     return a ? gcd(b % a, a) : b;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class T>   T sign(T a) {     return a > 0 ? 1 : (a < 0 ? -1 : 0);   }   const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, 1, 0, -1};   const int dxK[] = {-1, -1, 0, 1, 1, 1, 0, -1};   const int dyK[] = {0, 1, 1, 1, 0, -1, -1, -1};   const int dxKn[] = {-2, -1, 1, 2, 2, 1, -1, -2};   const int dyKn[] = {1, 2, 2, 1, -1, -2, -2, -1};   const int N = int(1e6) + 9;   const int M = int(2e2) + 9;   const int LOGN = 22;   const int SQN = 350;   const int MOD = int(1e9) + 7;   const int INF = 1e9 + 100;   const long long INF64 = 2e18;   const long double PI = 3.1415926535897932384626433832795;   const long double EPS = 1e-9;   long long d, v, n;   pair<long long, long long> p[N];   void solve() {     scanf( %I64d %I64d %I64d , &d, &v, &n);     for (int i = 0; i < (int)(n); ++i)       scanf( %I64d %I64d , &p[i].first, &p[i].second);     p[n++] = make_pair(0, 0);     p[n++] = make_pair(d, 0);     sort(p, p + n);     p[n] = make_pair(d, 0);     multiset<pair<long long, long long> > s;     long long res = 0;     long long remd = v;     for (int i = 0; i < (int)(n); ++i) {       long long dist = p[i + 1].first - p[i].first;       if (dist > v) {         cout << -1;         return;       }       long long cost = p[i].second;       while (!s.empty() && s.rbegin()->first > cost) {         pair<long long, long long> cur = *s.rbegin();         s.erase(--s.end());         res -= cur.first * 1LL * cur.second;         remd += cur.second;       }       if (remd) {         res += cost * remd;         s.insert(make_pair(cost, remd));         remd = 0;       }       while (dist > 0) {         pair<long long, long long> cur = *s.begin();         s.erase(s.begin());         long long curdist = min(dist, cur.second);         dist -= curdist;         cur.second -= curdist;         remd += curdist;         if (cur.second > 0) s.insert(cur);       }     }     cout << res;   }   int main() {     srand(time(NULL));     srand(time(NULL));     cout << setprecision(10) << fixed;     cerr << setprecision(10) << fixed;     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 5;   const int CNTV = 105;   const int LENSUFF = 11;   const int K = 4;   const int MOD = 1e9 + 9;   struct node {     int go[K], suff, p, pch, lev, cr;     node() {       memset(go, -1, sizeof go);       suff = p = pch = cr = -1;       lev = 0;     }   };   int sz = 1, num[256];   node a[CNTV];   inline void add(string second) {     int v = 0;     for (int i = 0; i < second.size(); ++i) {       int c = num[second[i]];       if (a[v].go[c] == -1) {         a[sz].lev = a[v].lev + 1;         a[sz].p = v;         a[sz].pch = c;         a[v].go[c] = sz++;       }       v = a[v].go[c];     }     a[v].cr = v;   }   int go(int v, int c);   int sufflink(int v);   int go(int v, int c) {     if (a[v].go[c] != -1) return a[v].go[c];     if (v == 0) return a[v].go[c] = 0;     return a[v].go[c] = go(sufflink(v), c);   }   int sufflink(int v) {     if (v == 0 || a[v].p == 0) return a[v].suff = 0;     if (a[v].suff != -1) return a[v].suff;     return a[v].suff = go(sufflink(a[v].p), a[v].pch);   }   int cross(int v) {     if (a[v].cr != -1) return a[v].cr;     return a[v].cr = cross(sufflink(v));   }   int n, m, dp[N][CNTV][LENSUFF];   int main() {     num[ A ] = 0;     num[ C ] = 1;     num[ G ] = 2;     num[ T ] = 3;     a[0].cr = 0;     cin >> n >> m;     string second;     for (int i = 0; i < m; ++i) {       cin >> second;       add(second);     }     dp[0][0][0] = 1;     for (int len = 0; len < n; ++len)       for (int v = 0; v < sz; ++v)         for (int need = 0; need < 10; ++need)           for (int c = 0; c < 4; ++c) {             int to = go(v, c);             if (a[to].lev >= need + 1) {               int cr = cross(to);               if (a[cr].lev >= need + 1)                 dp[len + 1][to][0] =                     (dp[len + 1][to][0] + dp[len][v][need]) % MOD;               else                 dp[len + 1][to][need + 1] =                     (dp[len + 1][to][need + 1] + dp[len][v][need]) % MOD;             }           }     int ans = 0;     for (int v = 0; v < sz; ++v) ans = (ans + dp[n][v][0]) % MOD;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     cin >> n;     vector<int> d(n), bal(n + 2);     vector<long long> pref(n + 1);     for (int i = 0; i < n; i++) scanf( %d , &d[i]);     sort(d.begin(), d.end());     for (int i = 0; i < n; i++) pref[i + 1] = pref[i] + d[i];     int j = 0;     for (int k = 1; k <= n; k++) {       long long L = pref[n] - pref[n - k], R = (long long)k * (k - 1);       while (j < n && d[j] < k) j++;       int up = min(n - k, j);       R += pref[up] + (long long)k * ((n - k) - up);       int bound = d[n - k];       {         long long diff = L - R;         if (diff <= k && diff <= bound) {           bal[max(diff, 0LL)]++;           bal[bound + 1]--;         }       }       {         L -= d[n - k];         R += min(d[n - k], k);         long long diff = R - L;         if (diff >= bound + 1) {           bal[bound + 1]++;           bal[min(diff + 1, n + 1LL)]--;         }       }     }     vector<int> res;     int B = 0;     for (int i = 0; i <= n; i++) {       B += bal[i];       if (B == n) {         if ((pref[n] + i) % 2 == 0) {           res.push_back(i);         }       }     }     if (res.empty()) return cout << -1 << endl, 0;     for (int i = 0; i < (int)res.size(); i++) cout << res[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i;     string s;     cin >> s;     int right = s.size() - 1;     int left = 0;     vector<int> ans;     ans.resize(s.size());     for ((i) = (0); (i) < (int)(s.size()); (i)++) {       if (s[i] ==  l ) {         ans[right] = i + 1;         right--;       } else {         ans[left] = i + 1;         left++;       }     }     for (__typeof((ans).begin()) it = (ans).begin(); it != (ans).end(); it++) {       cout << *it << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)2e6 + 7;   char c[N];   struct super_hash {     vector<int> h[2], p[2];     int m[2], b[2];     super_hash(string s, int m1, int m2, int b1, int b2) {       m[0] = m1, m[1] = m2;       b[0] = b1, b[2] = b2;       int n = s.size();       for (int t = 0; t < 2; t++) {         h[t].resize(n + 1);         p[t].resize(n + 1);         p[t][0] = 1;         h[t][0] = 0;         for (int i = 1; i <= n; i++) {           h[t][i] = (h[t][i - 1] * (long long)b[t] + s[i - 1]) % m[t];           p[t][i] = (p[t][i - 1] * (long long)b[t]) % m[t];         }       }     }     pair<int, int> get(int l, int r) {       int res[2];       for (int t = 0; t < 2; t++) {         res[t] = (h[t][r] - (h[t][l] * (long long)p[t][r - l]) % m[t]);         if (res[t] < 0) res[t] += m[t];       }       return {res[0], res[1]};     }   };   bool prime(int x) {     for (int i = 2; i * i <= x; i++)       if (x % i == 0) return false;     return true;   }   int get_prime(int x) {     x += rand();     while (!prime(x)) x--;     return x;   }   int get_mod() { return get_prime(1000000000); }   int get_base() { return get_prime(239); }   map<pair<int, int>, int> num;   string nxt() {     scanf(  %s , c);     return string(c);   }   int main() {     srand(time(NULL));     int m[2], b[2];     for (int t = 0; t < 2; t++) {       m[t] = get_mod();       b[t] = get_base();     }     int n, k;     scanf( %d%d , &n, &k);     vector<int> ans[k];     set<int> res[k];     string s = nxt();     for (int i = 0; i < k; i++) s += s[i];     int g;     scanf( %d , &g);     for (int i = 1; i <= g; i++) {       string t = nxt();       super_hash h(t, m[0], m[1], b[0], b[1]);       num[h.get(0, k)] = i;     }     super_hash h(s, m[0], m[1], b[0], b[1]);     for (int i = 0; i < n * k; i++) {       int f = num[h.get(i, i + k)];       if (!f) continue;       res[i % k].insert(f);       ans[i % k].push_back(f);     }     for (int i = 0; i < k; i++) {       if ((int)res[i].size() == n) {         puts( YES );         for (auto c : ans[i]) {           printf( %d  , c);         }         puts(  );         return 0;       }     }     puts( NO );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, five = 0, zero = 0;     cin >> n;     while (n--) {       cin >> k;       if (k == 5)         five += 1;       else         zero += 1;     }     if (five >= 9 && zero > 0) {       for (size_t i = 0; i < five / 9; i++) cout <<  555555555 ;       for (size_t i = 0; i < zero; i++) cout <<  0 ;     } else if (zero > 0)       cout <<  0 ;     else       cout <<  -1 ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, x, y;     cin >> n >> m;     vector<int> deg(n, 0), uf(n), uf_cnt(n, 1);     for (int i = 0; i < n; ++i) uf[i] = i;     for (int i = 0; i < m; ++i) {       cin >> x >> y;       deg[--x]++;       deg[--y]++;       while (x != uf[x]) x = uf[x];       while (y != uf[y]) y = uf[y];       if (x < y) {         uf_cnt[x] += uf_cnt[y];         uf_cnt[y] = 0;         uf[y] = x;       }       if (y < x) {         uf_cnt[y] += uf_cnt[x];         uf_cnt[x] = 0;         uf[x] = y;       }     }     for (int i = 0; i < n; ++i) {       int j = i;       while (j != uf[j]) j = uf[j];       if (deg[i] + 1 != uf_cnt[j]) {         cout <<  NO n ;         return 0;       }     }     cout <<  YES n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   vector<int> vec[111111];   int num1[N], num2[N], pos[N];   int main() {     int n, i, j;     cin >> n;     for (i = 1; i <= n; i++) {       scanf( %d , &num1[i]);       num2[i] = num1[i];     }     sort(num2 + 1, num2 + n + 1);     map<int, int> mp;     for (i = 1; i <= n; i++) {       mp[num2[i]] = i;     }     for (i = 1; i <= n; i++) {       pos[i] = mp[num1[i]];     }     int vis[N] = {0};     int cnt = 0;     for (i = 1; i <= n; i++) {       if (!vis[i]) {         int x = i;         while (!vis[x]) {           vis[x] = 1;           vec[cnt].push_back(x);           x = pos[x];         }         cnt++;       }     }     cout << cnt <<   n ;     for (i = 0; i < cnt; i++) {       int len = vec[i].size();       if (len) cout << len;       for (j = 0; j < len; j++) printf(  %d , vec[i][j]);       if (len) puts(  );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k, c = 0;     n = 4;     m = 14;     string arr[n][m];     cin >> k;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (j == 0)           arr[i][j] =  |# ;         else {           if (j == m - 3 && i == 0 || j == m - 3 && i == 1 ||               j == m - 3 && i == 3)             arr[i][j] =  .| ;           else if (j == m - 3 && i == 2)             arr[i][j] =  .. ;           else if (j == m - 2 && i == 0)             arr[i][j] =  D| ;           else if (j == m - 2 && i == 1 || j == m - 2 && i == 3 ||                    j == m - 2 && i == 2)             arr[i][j] =  .| ;           else if (j == m - 1 && i == 0 || j == m - 1 && i == 3)             arr[i][j] =  ) ;           else if (j == m - 1 && i == 1 || j == m - 1 && i == 2)             continue;           else if (i == 2 && j != 0 || i == 2 && j != m - 2 ||                    i == 2 && j != m - 1)             arr[i][j] =  .. ;           else             arr[i][j] =  .# ;         }       }     }     while (k) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (j == c) {             if (arr[i][j] ==  |#  && k != 0) {               arr[i][j] =  |O ;               k--;             } else if (arr[i][j] ==  .#  && k != 0) {               arr[i][j] =  .O ;               k--;             }           }         }       }       c++;     }     for (int i = 0; i < m; i++) {       if (i == 0)         cout <<  + ;       else if (i == m - 1)         cout <<  + ;       else         cout <<  -- ;     }     cout << endl;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << arr[i][j];       }       cout << endl;     }     for (int i = 0; i < m; i++) {       if (i == 0)         cout <<  + ;       else if (i == m - 1)         cout <<  + ;       else         cout <<  -- ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int a, b, c, i, l;     scanf( %d%d%d , &a, &b, &c);     if (a > b) {       for (i = a; i > 0; i++) {         if (i % a == 0 && i % b == 0) {           l = i;           break;         } else {           continue;         }       }     } else if (b > a) {       for (i = b; i > 0; i++) {         if (i % a == 0 && i % b == 0) {           l = i;           break;         } else {           continue;         }       }     } else {       l = a;     }     printf( %d , (c / l));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double a[200000 + 100], sum[200000 + 100];   int main() {     int n, k;     double ans = 0;     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       double s;       scanf( %lf , &a[i]);     }     sum[0] = 0;     for (int i = 0; i < k; i++) sum[0] += a[i];     for (int i = k; i < n; i++) sum[i - k + 1] = sum[i - k] - a[i - k] + a[i];     for (int i = 0; i < n - k + 1; i++) ans += sum[i];     ans /= (n - k + 1);     printf( %lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<long long> num(1, 0);     vector<long long> arr(1, 0);     for (int i = 1; i <= 1e5; i++) {       num.push_back(num.back() + 1 + floor(log10(i)));       arr.push_back(arr.back() + num.back());     }     int q;     cin >> q;     while (q--) {       int x;       cin >> x;       x--;       x -= *--upper_bound(arr.begin(), arr.end(), x);       int p = upper_bound(num.begin(), num.end(), x) - num.begin();       x -= num[p - 1];       x = floor(log10(p)) - x;       while (x--) p /= 10;       cout << p % 10 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     n--;     string str[] = { Sheldon ,  Leonard ,  Penny ,  Rajesh ,  Howard };     while (n >= 5) {       n = n - 5;       n = n / 2;     }     cout << str[n] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[505][505], b[505][505], num[250005], c[505];   int read() {     int A;     bool K;     char C;     C = A = K = 0;     while (C <  0  || C >  9 ) K |= C ==  - , C = getchar();     while (C >  /  && C <  : ) A = (A << 3) + (A << 1) + (C ^ 48), C = getchar();     return (K ? -A : A);   }   void write(int X) {     if (X < 0) putchar( - ), X = -X;     if (X > 9) write(X / 10);     putchar(X % 10 | 48);   }   int main() {     int t, i, j, n, m;     t = read();     while (t--) {       n = read(), m = read();       for (i = 1; i <= (n); i++)         for (j = 1; j <= (m); j++) a[i][j] = read();       for (j = 1; j <= (m); j++)         for (i = 1; i <= (n); i++) b[j][i] = read(), num[b[j][i]] = j;       for (j = 1; j <= (m); j++) c[j] = num[a[1][j]];       for (i = 1; i <= (n); i++) {         for (j = 1; j <= (m); j++) write(b[c[j]][i]), putchar(   );         putchar(  n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxk = 101, maxn = 100000 + 10;   long long n, k, a[maxk], dp[maxk][maxn];   long long f(int x, long long num) {     if (num == 0) return 0;     if (x == k + 1) return num;     if (num < maxn && dp[x][num] != -1) return dp[x][num];     long long p = f(x + 1, num) - f(x + 1, num / a[x]);     if (num < maxn) return dp[x][num] = p;     return p;   }   bool cmp(int x, int y) { return y < x; }   int main() {     memset(dp, -1, sizeof dp);     cin >> n >> k;     for (int i = 1; i <= k; i++) cin >> a[i];     sort(a + 1, a + 1 + k, cmp);     cout << f(1, n) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (int)(2e9);   const long long INF = (long long)(5e18);   const int N = 305;   set<pair<int, int> > st;   int n, m;   int bl[N * N], a[N][N], vis[N][N];   int ans[N][N];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) scanf( %d , &a[i][j]);     for (int i = 1; i <= n; i++) {       int mx = 0;       for (int j = 1; j <= m; j++) mx = max(mx, a[i][j]);       st.insert(make_pair(mx, 1));       bl[mx] = 1;     }     for (int j = 1; j <= m; j++) {       int mx = 0;       for (int i = 1; i <= n; i++) mx = max(mx, a[i][j]);       st.insert(make_pair(mx, -1));       bl[mx] = 1;     }     int hang = 1, lie = 1, now = 1;     while (!st.empty()) {       pair<int, int> u = *st.begin();       st.erase(u);       pair<int, int> tmp = *st.begin();       if (tmp.first == u.first) {         st.erase(tmp);         u.second = 2;       }       vector<int> v;       ans[hang][lie] = u.first;       if (u.second == 1) {         v.clear();         for (int i = lie + 1; i <= m; i++) {           while (bl[now]) now++;           v.push_back(now);           now++;         }         for (int i = m, j = 0; i >= lie + 1; i--) {           ans[hang][i] = v[j];           j++;         }         hang++;       } else if (u.second == -1) {         v.clear();         for (int i = hang + 1; i <= n; i++) {           while (bl[now]) now++;           v.push_back(now);           now++;         }         for (int i = n, j = 0; i >= hang + 1; i--) {           ans[i][lie] = v[j];           j++;         }         lie++;       } else {         v.clear();         for (int i = lie + 1; i <= m; i++) {           while (bl[now]) now++;           v.push_back(now);           now++;         }         for (int i = m, j = 0; i >= lie + 1; i--) {           ans[hang][i] = v[j];           j++;         }         v.clear();         for (int i = hang + 1; i <= n; i++) {           while (bl[now]) now++;           v.push_back(now);           now++;         }         for (int i = n, j = 0; i >= hang + 1; i--) {           ans[i][lie] = v[j];           j++;         }         lie++;         hang++;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) printf( %d  , ans[i][j]);       puts(  );     }     return 0;   }