malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int T, b, w, tmp;     scanf( %d , &T);     while (T--) {       scanf( %d %d , &b, &w);       if (b >= w)         tmp = 2;       else         tmp = 3, swap(b, w);       if (b > 3 * w + 1)         printf( NO n );       else {         printf( YES n );         for (int i = 1; i <= w; ++i) {           printf( %d t%d n , tmp, 2 * i);           printf( %d t%d n , tmp, 2 * i - 1);         }         b -= w;         if (b) printf( %d t%d n , tmp, 2 * w + 1), b--;         int i = 1;         while (b) {           printf( %d t%d n , tmp - 1, 2 * i);           b--;           if (b) printf( %d t%d n , tmp + 1, 2 * i), b--;           i++;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline bool chmin(T1 &a, T2 b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <typename T1, typename T2>   inline bool chmax(T1 &a, T2 b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <typename T>   T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <typename T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <typename T>   T pow(T a, int b) {     return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1;   }   const int mod = 998244353;   long long modpow(long long a, int b) {     return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1;   }   void solve();   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int T;     T = 1;     while (T--) {       solve();     }   }   struct UnionFind {     vector<double> data;     int sz;     UnionFind(int _sz) : data(_sz, -1) { sz = _sz; }     bool connect(int x, int y) {       if ((x = root(x)) == (y = root(y))) return false;       if (data[x] > data[y]) swap(x, y);       data[x] += data[y];       data[y] = x;       sz--;       return true;     }     bool issame(int x, int y) { return root(x) == root(y); }     int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }     int size(int x) { return -data[root(x)]; }     int size() { return sz; }   };   void solve() {     int n;     cin >> n;     set<int> s;     for (int i = 0; i < (n); ++i) {       int b;       cin >> b;       s.insert(b);     }     vector<int> a;     for (auto e : s) a.emplace_back(e);     sort(a.begin(), a.end());     map<long long, int> mp;     for (int i = 0; i < (n); ++i) mp[a[i]] = i + 1;     for (int i = 0; i < (33); ++i) {       UnionFind uni(n);       for (int j = 0; j < (n - 1); ++j) {         long long num = a[j] + pow(2LL, i);         if (mp.count(num)) {           uni.connect(j, mp[num] - 1);         }       }       vector<vector<int> > v(n);       for (int j = 0; j < (n); ++j) {         v[uni.root(j)].emplace_back(a[j]);       }       for (int j = 0; j < (n); ++j) {         if ((int)v[j].size() >= 3) {           cout << 3 << endl;           for (int k = 0; k < (3); ++k) cout << v[j][k] <<    ;           cout << endl;           return;         }       }     }     for (int i = 0; i < (33); ++i) {       UnionFind uni(n);       for (int j = 0; j < (n - 1); ++j) {         long long num = a[j] + pow(2LL, i);         if (mp.count(num)) {           uni.connect(j, mp[num] - 1);         }       }       vector<vector<int> > v(n);       for (int j = 0; j < (n); ++j) {         v[uni.root(j)].emplace_back(a[j]);       }       for (int j = 0; j < (n); ++j) {         if ((int)v[j].size() >= 2) {           cout << 2 << endl;           for (int k = 0; k < (2); ++k) cout << v[j][k] <<    ;           cout << endl;           return;         }       }     }     cout << 1 << endl;     cout << a[0] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int T;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     cin >> T;     for (int i = 0; i < T; i++) {       int n, oneCnt = 0, zeroCnt = 0;       cin >> n;       string str;       for (int j = 0; j < n; j++) {         char ch;         cin >> ch;         str.push_back(ch);         if (ch ==  1 ) oneCnt++;       }       if (oneCnt == 1) {         cout << 0 <<   n ;         continue;       };       int len = str.length();       int start = 0, end = 0;       for (int j = 0; j < len; j++) {         if (str[j] ==  1 ) {           start = j;           break;         }       }       for (int j = len - 1; j > -1; j--) {         if (str[j] ==  1 ) {           end = j;           break;         }       }       for (int j = start; j <= end; j++) {         if (str[j] ==  0 ) zeroCnt++;       }       cout << zeroCnt <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dx[] = {1, -1, 0, 0};   long long dy[] = {0, 0, 1, -1};   const int sz = 2e6 + 5, mod = 998244353;   long long t, n, m, k;   const int MAXN = 2e5 + 7;   const long long lim = 1e18;   const long long inf = 1e15;   vector<long long> Prime;   vector<bool> sie(sz, 1);   void sieve() {     sie[0] = 0;     sie[1] = 0;     for (long long i = 2; i < sz; i++) {       if (sie[i]) {         for (long long j = i * i; j < sz; j += i) sie[j] = 0;       }     }     for (long long i = 0; i < sz; i++) {       if (sie[i]) Prime.push_back(i);     }     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     sieve();     cin >> n;     vector<long long> v(n);     for (auto &i : v) cin >> i;     map<long long, long long> track;     vector<long long> ans;     long long in = -1;     for (int i = 0; i < n; i++) {       long long a = v[i];       bool flag = 0;       vector<long long> pp;       for (long long j = 2; j * j <= a; j++) {         if (a % j == 0) {           while (a % j == 0) {             a /= j;           }           if (track.find(j) != track.end()) {             flag = 1;             break;           } else             track[j];           pp.push_back(j);         }       }       if (a != 1 && flag == 0) {         if (track.find(a) != track.end()) {           flag = 1;         } else           track[a];       }       if (flag) {         for (auto j : pp) track.erase(j);         for (long long j = v[i] + 1; j < sz; j++) {           long long a = j;           bool f = 1;           vector<long long> arr;           for (long long k = 2; k * k <= a; k++) {             if (a % k == 0) {               while (a % k == 0) {                 a /= k;               }               if (track.find(k) != track.end()) {                 f = 0;                 break;               } else                 track[k];               arr.push_back(k);             }           }           if (a != 1 && f) {             if (track.find(a) != track.end()) {               f = 0;             } else               track[a];           }           if (f) {             ans.push_back(j);             break;           } else {             for (auto j : arr) track.erase(j);           }         }         in = i + 1;         break;       }       ans.push_back(v[i]);     }     if (in == -1) {       for (auto i : ans) cout << i <<    ;       return 0;     }     int cnt = ans.size();     int i = 0;     while (cnt < n) {       if (track.find(Prime[i]) == track.end()) {         cnt++;         ans.push_back(Prime[i]);       }       i++;     }     for (auto i : ans) cout << i <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int i, j, p, d, n, m, total, k, ok, a, b, c, op, maxi, rasp, m1, m2,       p1, p2, rez, modu = 1000000007, mini, mij, ls, ld;   pair<long long int, long long int> v[300500];   priority_queue<pair<long long int, long long int> > nxt;   priority_queue<long long int> q;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     cin >> a >> b;     n--;     for (i = 1; i <= n; i++) {       cin >> v[i].first >> v[i].second;     }     sort(v + 1, v + 1 + n);     for (i = 1; i <= n; i++) {       if (v[i].first > a)         q.push((v[i].second - v[i].first + 1) * -1), rez++;       else {         nxt.push(v[i]);       }     }     mini = rez;     while (a && q.size()) {       a += q.top();       q.pop();       if (a < 0) break;       rez--;       while (nxt.size() && nxt.top().first > a) {         q.push((nxt.top().second - nxt.top().first + 1) * -1), rez++;         nxt.pop();       }       mini = min(rez, mini);     }     cout << mini + 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long bipow(long long a) {     if (a == 0) return 1;     long long aea = bipow(a / 2) % 998244353;     if (a % 2 == 0)       return (aea * aea) % 998244353;     else       return ((aea * aea) % 998244353 * 2) % 998244353;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m;     cin >> n >> m;     cout << bipow(n + m) % 998244353 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct numer {     int rost;     int num_of;     numer() : rost(0), num_of(0) {}     numer(int _rost, int _num_of) : rost(_rost), num_of(_num_of) {}   };   int maxim(int a, int b) { return a > b ? a : b; }   int comp(const void *a, const void *b) {     int *A = (int *)a, *B = (int *)b;     return *A < *B ? -1 : *A > *B ? 1 : 0;   }   void push(stack<int> &S, numer &chel) {     for (int i = 0; i < chel.num_of; i++) S.push(chel.rost);   }   int balance(int *Rost, int num, int *&ring, bool else_good = false,               bool good = false) {     qsort(Rost, num, sizeof(int), comp);     vector<numer> people;     numer temp(Rost[0], 1);     stack<int> Stack;     for (int i = 1; i < num; i++) {       if (Rost[i] == Rost[i - 1])         temp.num_of++;       else {         people.push_back(temp);         temp = numer(Rost[i], 1);       }     }     people.push_back(temp);     int kol = people.size(), min = 0, curr = 0, tmp = 0, tmp1, *p = 0;     if (else_good == false) {       for (int i = 1; i <= kol; i++) {         curr += people[i - 1].num_of;         if (i == kol) {           tmp1 = balance(Rost + min, curr - min, p, true, false);           if (tmp1 > tmp) {             ring = p;             tmp = tmp1;           }           continue;         }         if (people[i].rost - people[i - 1].rost >= 2) {           tmp1 = balance(Rost + min, curr - min, p, true, false);           if (tmp1 > tmp) {             ring = p;             tmp = tmp1;           }           min = curr;         }       }     }     if (tmp == 0) {       int new_curr = people[0].num_of, new_min = 0;       if (good == false) {         for (int i = 1; i < kol; i++) {           new_curr += people[i].num_of;           if (people[i].num_of == 1 || i == kol - 1) {             tmp1 = balance(Rost + new_min, new_curr - new_min, p, true, true);             if (tmp1 > tmp) {               ring = p;               tmp = tmp1;             }             new_min = new_curr - people[i].num_of;           }         }         if (kol == 1) {           tmp = tmp1 = new_curr;           ring = new int[tmp];           for (int j = 0; j < tmp; j++) ring[j] = people[0].rost;         }       } else {         for (int i = 0; i < kol; i++) {           Stack.push(people[i].rost);           people[i].num_of--;         }         for (int i = kol - 1; i >= 0; i--) push(Stack, people[i]);         tmp = Stack.size();         ring = new int[tmp];         for (int i = 0; i < tmp; i++) {           ring[i] = Stack.top();           Stack.pop();         }       }     }     return tmp;   }   int main() {     int n;     cin >> n;     int *A = new int[n], *B = 0;     for (int i = 0; i < n; i++) cin >> A[i];     int k = balance(A, n, B);     cout << k << endl;     for (int i = 0; i < k; i++) cout << B[i] <<    ;     delete[] A;     delete[] B;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 6e5;   const long long mo = 1e9 + 7;   const long long inf = 1e9;   const long long Inf = 1e18;   int lz[N], a[N], ls[N], rs[N], mi[N], mx[N];   bool ok[N];   char s[N];   void f(int x, int l, int r, int y, int z, int L, int R) {     if (l == L && r == R && (!z || (L == R))) {       if (z) ok[x] ^= 1;       lz[x] += y;       mi[x] += y;       mx[x] += y;       ls[x] -= y;       rs[x] -= y;       return;     }     int m = (L + R) / 2;     if (lz[x]) {       lz[x * 2] += lz[x];       mi[x * 2] += lz[x];       mx[x * 2] += lz[x];       ls[x * 2] -= lz[x];       rs[x * 2] -= lz[x];       lz[x * 2 + 1] += lz[x];       mi[x * 2 + 1] += lz[x];       mx[x * 2 + 1] += lz[x];       ls[x * 2 + 1] -= lz[x];       rs[x * 2 + 1] -= lz[x];       lz[x] = 0;     }     if (r <= m)       f(x * 2, l, r, y, z, L, m);     else if (l > m)       f(x * 2 + 1, l, r, y, z, m + 1, R);     else {       f(x * 2, l, m, y, z, L, m);       f(x * 2 + 1, m + 1, r, y, 0, m + 1, R);     }     ok[x] = ok[x * 2] | ok[x * 2 + 1];     mi[x] = min(mi[x * 2], mi[x * 2 + 1]);     if (!ok[x * 2]) {       mx[x] = mx[x * 2 + 1];       ls[x] = ls[x * 2 + 1];       a[x] = a[x * 2 + 1];       rs[x] = max(mx[x * 2 + 1] - mi[x * 2] * 2, rs[x * 2 + 1]);     } else if (!ok[x * 2 + 1]) {       mx[x] = mx[x * 2];       rs[x] = rs[x * 2];       a[x] = a[x * 2];       ls[x] = max(mx[x * 2] - mi[x * 2 + 1] * 2, ls[x * 2]);     } else {       mx[x] = max(mx[x * 2], mx[x * 2 + 1]);       ls[x] = max(mx[x * 2] - mi[x * 2 + 1] * 2, max(ls[x * 2], ls[x * 2 + 1]));       rs[x] = max(mx[x * 2 + 1] - mi[x * 2] * 2, max(rs[x * 2], rs[x * 2 + 1]));       a[x] = max(max(ls[x * 2] + mx[x * 2 + 1], mx[x * 2] + rs[x * 2 + 1]),                  max(a[x * 2], a[x * 2 + 1]));     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     scanf( %s , s + 1);     f(1, 0, 0, 0, 1, 0, n * 2 - 2);     for (int i = (1); i <= (n * 2 - 2); ++i) {       if (s[i] ==  ( )         f(1, i, n * 2 - 2, 1, 1, 0, n * 2 - 2);       else         f(1, i, n * 2 - 2, -1, 0, 0, n * 2 - 2);     }     printf( %d n , a[1]);     for (int i = (1); i <= (m); ++i) {       int l, r;       scanf( %d%d , &l, &r);       if (l > r) swap(l, r);       if (s[l] != s[r]) {         if (s[l] ==  ( )           f(1, l, r - 1, -2, 1, 0, n * 2 - 2);         else           f(1, l, r - 1, 2, 1, 0, n * 2 - 2);         f(1, r, r, 0, 1, 0, n * 2 - 2);         swap(s[l], s[r]);       }       printf( %d n , a[1]);     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int tree[maxn * 4], add[maxn * 4];   void push(int v, int tl, int tr) {     if (add[v] != 0) {       tree[v] += add[v];       if (tl != tr) {         int vv = v + v;         add[vv] += add[v];         add[vv + 1] += add[v];         tree[v] = max(tree[vv] + add[vv], tree[vv + 1] + add[vv + 1]);       }       add[v] = 0;     }   }   void upd(int v, int tl, int tr, int l, int r, int x) {     push(v, tl, tr);     if (tl == l and tr == r) {       add[v] += x;       push(v, tl, tr);       return;     }     int tm = tl + tr >> 1, vv = v + v;     if (r <= tm)       upd(vv, tl, tm, l, r, x);     else if (l > tm)       upd(vv + 1, tm + 1, tr, l, r, x);     else {       upd(vv, tl, tm, l, tm, x);       upd(vv + 1, tm + 1, tr, tm + 1, r, x);     }     tree[v] = max(tree[vv] + add[vv], tree[vv + 1] + add[vv + 1]);   }   int get(int v, int tl, int tr) {     push(v, tl, tr);     if (tl == tr) return (tree[v] > 0 ? tl : -1);     int vv = v + v, tm = tl + tr >> 1;     if (tree[vv + 1] + add[vv + 1] > 0) return get(vv + 1, tm + 1, tr);     return get(vv, tl, tm);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     int a[n], b[m];     for (int i = 0; i < n; i++) {       cin >> a[i];       upd(1, 1, maxn, 1, a[i], 1);     }     for (int i = 0; i < m; i++) {       cin >> b[i];       upd(1, 1, maxn, 1, b[i], -1);     }     int q;     cin >> q;     while (q--) {       int type, i, x;       cin >> type >> i >> x;       if (type == 1) {         upd(1, 1, maxn, 1, a[i - 1], -1);         a[i - 1] = x;         upd(1, 1, maxn, 1, a[i - 1], 1);       } else {         upd(1, 1, maxn, 1, b[i - 1], 1);         b[i - 1] = x;         upd(1, 1, maxn, 1, b[i - 1], -1);       }       cout << get(1, 1, maxn) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void chmax(T& a, const T& b) {     a = max(a, b);   }   template <class T>   void chmin(T& a, const T& b) {     a = min(a, b);   }   using ll = long long;   using P = pair<int, int>;   using VI = vector<int>;   using VVI = vector<VI>;   using VL = vector<ll>;   using VVL = vector<VL>;   int dp[6][410][410];   int d[410];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       int n, m;       cin >> n >> m;       for (int k = 0; k < int(5); ++k)         for (int i = 0; i < int(m + 1); ++i)           for (int j = 0; j < int(m + 1); ++j) dp[k][i][j] = 100;       int ans = 100;       for (int _ = 0; _ < int(n); ++_) {         for (int j = 0; j < int(m); ++j) {           char c;           cin >> c;           d[j + 1] = c -  0 ;         }         for (int j = 0; j < int(m); ++j) d[j + 1] += d[j];         for (int k = int(5) - 1; k >= 0; --k)           for (int r = 0; r < int(m + 1); ++r)             for (int l = int(r - 4 + 1) - 1; l >= 0; --l) {               if (k == 0 || k == 4) {                 int x = r - 1 - (l + 1) - (d[r - 1] - d[l + 1]);                 if (k == 4) {                   chmin(ans, x + dp[k][l][r]);                   dp[k][l][r] += d[r - 1] - d[l + 1] + 1 - (d[l + 1] - d[l]) + 1 -                                  (d[r] - d[r - 1]);                 } else {                   dp[1][l][r] = x;                 }               } else {                 int x = d[r - 1] - d[l + 1] + 1 - (d[l + 1] - d[l]) + 1 -                         (d[r] - d[r - 1]);                 if (k < 3) {                   dp[k + 1][l][r] = dp[k][l][r] + x;                 } else {                   chmin(dp[k + 1][l][r], dp[k][l][r] + x);                 }               }             }       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> t1, t2;   long long a, b, n, k, q, day, val, p, t;   void update1(long long i, long long l, long long r, long long qi,                long long qx) {     if (l + 1 == r) {       t1[i] += qx;       t1[i] = min(t1[i], a);       return;     }     long long m = (r + l) >> 1;     if (qi < m) {       update1(2 * i + 1, l, m, qi, qx);     } else {       update1(2 * i + 2, m, r, qi, qx);     }     t1[i] = t1[2 * i + 1] + t1[2 * i + 2];   }   void update2(long long i, long long l, long long r, long long qi,                long long qx) {     if (l + 1 == r) {       t2[i] += qx;       t2[i] = min(t2[i], b);       return;     }     long long m = (r + l) >> 1;     if (qi < m) {       update2(2 * i + 1, l, m, qi, qx);     } else {       update2(2 * i + 2, m, r, qi, qx);     }     t2[i] = t2[2 * i + 1] + t2[2 * i + 2];   }   long long get1(long long i, long long l, long long r, long long ql,                  long long qr) {     if (r <= ql || qr <= l) {       return 0;     }     if (ql <= l && r <= qr) {       return t1[i];     }     long long m = (r + l) / 2;     return get1(2 * i + 1, l, m, ql, qr) + get1(2 * i + 2, m, r, ql, qr);   }   long long get2(long long i, long long l, long long r, long long ql,                  long long qr) {     if (r <= ql || qr <= l) {       return 0;     }     if (ql <= l && r <= qr) {       return t2[i];     }     long long m = (r + l) / 2;     return get2(2 * i + 1, l, m, ql, qr) + get2(2 * i + 2, m, r, ql, qr);   }   void Not_Stable() {     cin >> n >> k >> a >> b >> q;     t1.resize(4 * n);     t2.resize(4 * n);     long long x, y, z;     for (long long i = 0; i < q; i++) {       cin >> x >> y;       if (x == 1) {         cin >> z;         update1(0, 0, n, y - 1, z);         update2(0, 0, n, y - 1, z);       } else {         cout << get2(0, 0, n, 0, y - 1) + get1(0, 0, n, y - 1 + k, n) << endl;       }     }   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr);     ;     long long g = 1;     while (g--) Not_Stable();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 1; i <= n; i++) cin >> a[i];     int c = 0, t = 0;     for (int i = 1; i <= n; i++) {       if (a[i] < 0) {         c++;       } else {         t++;       }     }     if (t == n || n == 1) {       cout <<  1  << endl << n << endl;       return 0;     }     if (c % 2 == 0)       cout << c / 2 << endl;     else       cout << c / 2 + 1 << endl;     int f = 0, d = 0;     for (int i = 1; i < n; i++) {       if (a[i] < 0) {         d++;       }       if (d == 2 && a[i + 1] < 0) {         cout << i - f <<    ;         f = i;         d = 0;       }     }     cout << n - f << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a;     b = a;     long long int x = 0, y = 0, z = 0;     long long int i;     for (i = 0; i < a.size(); i++) {       if (a[i] ==  a ) {         x++;       }       if (a[i] ==  b ) {         y++;       }       if (a[i] ==  c ) {         z++;       }     }     sort(b.begin(), b.end());     if (b == a && (z == x || z == y) && x != 0 && y != 0 && z != 0) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1001][1001];   vector<pair<pair<int, int>, char> > start;   int row[1001][1001], col[1001][1001];   pair<char, int> dir[100001];   vector<char> ans;   void init() {     for (int i = 0; i < 1001; i++) {       for (int j = 0; j < 1001; j++) a[i][j] = -1;     }   }   int main() {     int i, j, n, m, x, y, k, len, f;     string str;     cin >> n >> m;     init();     for (i = 1; i <= n; i++) {       cin >> str;       str =     + str;       for (j = 1; j <= m; j++) {         if (str[j] ==  # )           a[i][j] = -1;         else if (str[j] ==  . )           a[i][j] = 0;         else {           start.push_back(make_pair(make_pair(i, j), str[j]));           a[i][j] = 0;         }       }     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) row[i][j] = row[i][j - 1] + a[i][j];     }     for (j = 1; j <= m; j++) {       for (i = 1; i <= n; i++) col[j][i] = col[j][i - 1] + a[i][j];     }     cin >> k;     for (i = 1; i <= k; i++) cin >> dir[i].first >> dir[i].second;     for (i = 0; i < start.size(); i++) {       x = start[i].first.first;       y = start[i].first.second;       f = 0;       for (j = 1; j <= k; j++) {         len = dir[j].second;         if (dir[j].first ==  N ) {           if (x - len < 1) {             f = 1;             break;           } else if (col[y][x] - col[y][x - len - 1] != 0) {             f = 1;             break;           } else             x = x - len;         } else if (dir[j].first ==  S ) {           if (x + len > n) {             f = 1;             break;           } else if (col[y][x + len] - col[y][x - 1] != 0) {             f = 1;             break;           } else             x = x + len;         } else if (dir[j].first ==  E ) {           if (y + len > m) {             f = 1;             break;           } else if (row[x][y + len] - row[x][y - 1] != 0) {             f = 1;             break;           } else             y = y + len;         } else {           if (y - len < 1) {             f = 1;             break;           } else if (row[x][y] - row[x][y - len - 1] != 0) {             f = 1;             break;           } else             y = y - len;         }       }       if (!f) ans.push_back(start[i].second);     }     if (!ans.size()) {       cout <<  no solution ;       return 0;     }     sort(ans.begin(), ans.end());     for (i = 0; i < ans.size(); i++) cout << ans[i];     return 0;   }