malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   bool comp(pair<unsigned long long, unsigned long long> a,             pair<unsigned long long, unsigned long long> b) {     unsigned long long s1, s2, h1, h2;     tie(s1, h1) = a;     tie(s2, h2) = b;     if (s1 * h2 > s2 * h1) return true;     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     unsigned long long ans = 0;     string str;     vector<pair<unsigned long long, unsigned long long> > arr(n);     for (int i = 0; i < n; i++) {       cin >> str;       unsigned long long s1 = 0, h = 0;       for (auto x : str) {         if (x ==  s )           s1++;         else if (x ==  h )           h++, ans += s1;       }       arr[i] = make_pair(s1, h);     }     sort((arr).begin(), (arr).end(), comp);     unsigned long long s1 = 0;     for (auto i : arr) {       ans += s1 * 1LL * (i.second);       s1 += i.first;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long s[1000], x[1000], size;   void tob(long long a, long long arr[], long long& len) {     len = 0;     while (a != 0) {       arr[len++] = a % 2;       a /= 2;     }   }   long long DP(long long n, long long carry) {     if (n >= size) return 1 - carry;     if (x[n] == 1) {       if (((carry + 1) % 2) == s[n]) {         return 2 * DP(n + 1, carry);       } else         return 0;     } else {       long long ans = 0;       if ((carry) == s[n]) {         ans += DP(n + 1, 0);       }       if (((carry + 2) % 2) == s[n]) {         ans += DP(n + 1, 1);       }       return ans;     }   }   void solve(long long n, long long m) {     long long len1, len2, ans;     tob(n, s, len1);     tob(m, x, len2);     size = max(len1, len2);     ans = DP(0, 0);     if (n == m)       cout << ans - 2 << endl;     else       cout << ans << endl;   }   int main() {     long long n, m;     cin >> n >> m;     solve(n, m);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, d[210000];   long long cnt[210000];   long long solve() {     cnt[1] *= 2;     cnt[n] *= 2;     int Min = cnt[1], Max = cnt[1];     for (int i = 1; i <= n; ++i) {       if (Min > cnt[i])         Min = cnt[i];       else if (Max < cnt[i])         Max = cnt[i];     }     if (Min == Max) {       for (int i = 2; i <= n; ++i)         if (d[i] - d[i - 1] != d[2] - d[1]) return -1;       return cnt[1] * (d[n] - d[1]) - d[2] + d[1];     } else {       long long temp = 0;       for (int i = 1; i < n; ++i) {         temp += (d[i + 1] - d[i]) * min(cnt[i], cnt[i + 1]);       }       return temp;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &d[i]);     scanf( %d , &m);     for (int i = 1; i <= m; ++i) {       int temp;       scanf( %d , &temp);       ++cnt[temp];     }     printf( %I64d n , solve());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     int n, num[105], ans;     scanf( %d , &n);     for (int i = 1; i <= n; i++) cin >> num[i];     sort(num + 1, num + 1 + n);     ans = num[1];     for (int i = 2; i <= n; i++) ans = gcd(ans, num[i]);     printf( %d n , ans * n);   }
#include <bits/stdc++.h>   using namespace std;   int arr[(int)1e5 + 1];   int q[(int)1e5 + 1];   int sol[(int)1e5 + 1];   int main() {     int n, m;     cin >> n;     cin >> arr[0];     for (int i = 1; i < n; i++) {       int x;       cin >> x;       arr[i] = arr[i - 1] + x;     }     cin >> m;     for (int i = 0; i < m; i++) {       cin >> q[i];     }     for (int i = 0; i < m; i++) {       int lo = 0, hi = n - 1, res = -1;       while (lo <= hi) {         int md = (hi + lo) >> 1;         if (arr[md] >= q[i] && q[i] >= arr[md - 1]) {           hi = md - 1;           res = md;         } else if (arr[md] >= q[i])           hi = md - 1;         else           lo = md + 1;       }       sol[i] = res + 1;     }     for (int i = 0; i < m; i++) {       cout << sol[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int m, n, j, k, l, i, o, p, __t;   int V[200][2000], tim[200][2000], T[200], cop[200][2000];   char ch;   void read(int &a) {     for (ch = getchar(); (ch <  0  || ch >  9 ) && (ch !=  - ); ch = getchar())       ;     if (ch ==  - )       a = 0, __t = -1;     else       a = ch -  0 , __t = 1;     for (ch = getchar(); ch >=  0  && ch <=  9 ; ch = getchar())       a = a * 10 + ch -  0 ;     a *= __t;   }   int main() {     read(m), read(n);     for (int i = 1; i <= m; i++) {       read(T[i]);       for (int j = 1; j <= T[i]; j++)         read(V[i][j]), read(tim[i][j]), cop[i][j] = tim[i][j];     }     int ans = 0;     for (int i = 1; i <= m; i++) {       for (int j = i + 1; j <= m; j++) {         for (int k = 1; k <= T[i]; k++) tim[i][k] = cop[i][k];         for (int k = 1; k <= T[j]; k++) tim[j][k] = cop[j][k];         int x0 = 0, x1 = 0, who = 0;         if (V[i][1] > V[j][1])           who = -1;         else           who = 1;         for (int t1 = 1, t2 = 1; t1 <= T[i] && t2 <= T[j];) {           int dece = min(tim[i][t1], tim[j][t2]);           int y0 = x0 + dece * V[i][t1];           int y1 = x1 + dece * V[j][t2], nexwho;           if (y0 == y1)             nexwho = who;           else if (y0 < y1)             nexwho = 1;           else             nexwho = -1;           if (nexwho != who) ans++;           who = nexwho;           x0 = y0, x1 = y1;           tim[i][t1] -= dece;           tim[j][t2] -= dece;           if (tim[i][t1] == 0) t1++;           if (tim[j][t2] == 0) t2++;         }       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, t, cur;   void solve() {     scanf( %d %d , &n, &k);     t = n - k;     for (int i = 1; i <= t; i++) printf( %d  , i);     for (int i = k, j = 1; i >= 1; i--, j *= -1) {       t += i * j;       printf( %d  , t);     }   }   int main(void) {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans, n;   vector<pair<int, int> > vec;   string s, t;   int lcp1[5005][5005];   int lcp2[5005][5005];   void LCP(string &s, string &t, int lcp[5005][5005]) {     for (int i = (int)s.size() - 1; i >= 0; i--) {       for (int j = (int)t.size() - 1; j >= 0; j--) {         if (s[i] == t[j]) {           lcp[i][j] = lcp[i + 1][j + 1] + 1;         } else {           lcp[i][j] = 0;         }       }     }   }   void solve() {     LCP(s, t, lcp1);     reverse(s.begin(), s.end());     LCP(s, t, lcp2);     for (int ti = 0; ti < t.size();) {       int mx1 = 0, mx1_si = -1;       int mx2 = 0, mx2_si = -1;       for (int si = 0; si < s.size(); si++) {         if (mx1 < lcp1[si][ti]) {           mx1 = lcp1[si][ti];           mx1_si = si;         }         if (mx2 < lcp2[si][ti]) {           mx2 = lcp2[si][ti];           mx2_si = si;         }       }       if (mx1 == 0 && mx2 == 0) {         ans = -1;         break;       } else if (mx1 >= mx2) {         ans++;         vec.push_back(pair<int, int>(mx1_si + 1, mx1_si + mx1 - 1 + 1));         ti += mx1;       } else {         ans++;         vec.push_back(pair<int, int>(n - mx2_si, n - (mx2_si + mx2 - 1)));         ti += mx2;       }     }     cout << ans << endl;     for (int i = 0; i < (ans); i++) {       cout << vec[i].first <<     << vec[i].second << endl;     }   }   int main() {     cin >> s;     cin >> t;     n = (int)s.size();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     string s1, s2;     cin >> n >> s1 >> s2;     long long count = 0;     for (long long i = 0; i < n / 2; i++) {       char a[4] = {s1[i], s1[n - i - 1], s2[i], s2[n - i - 1]};       if ((a[0] == a[1] and a[2] == a[3]) || (a[0] == a[3] and a[1] == a[2]) ||           (a[0] == a[2] and a[1] == a[3]))         count += 0;       else if ((a[0] == a[2] and a[1] != a[3]) ||                (a[0] == a[3] and a[1] != a[2]) ||                (a[0] != a[2] and a[1] == a[3]) ||                (a[0] != a[3] and a[1] == a[2]) || (a[0] != a[1] and a[2] == a[3]))         count += 1;       else         count += 2;     }     if (n % 2 == 1) count += (s1[n / 2] != s2[n / 2]);     cout << count;     return 0;   }
#include <bits/stdc++.h>   void doubleIntSort(double d[], int m[], int s) {     int i, j, r;     double k1, k2, t;     if (s <= 1) return;     k1 = (d[0] + d[s - 1]) / 2.0;     k2 = k1 + 1e-10;     k1 -= 1e-10;     i = -1;     j = s;     for (;;) {       while (d[++i] < k1)         ;       while (d[--j] > k2)         ;       if (i >= j) break;       t = d[i];       d[i] = d[j];       d[j] = t;       r = m[i];       m[i] = m[j];       m[j] = r;     }     doubleIntSort(d, m, i);     doubleIntSort(d + j + 1, m + j + 1, s - j - 1);   }   int n;   int nf, ne, ns;   int rf, re, rs;   double Rf, Re, Rs;   int df, de;   int h[21];   double res;   double x[100];   int ev[100];   int F, E, S;   void calc(void) {     int i, j, k;     double w, tmp;     if (n % 2 == 0) {       i = h[0] + h[1] * 10;       j = h[n - 2] + h[n - 1] * 10;       if (i > j) return;     }     F = E = S = 0;     for (i = 0; i < n; i++) {       if (h[i] == 0) {         x[2 * i] = (i / 2) - Rf;         x[2 * i + 1] = (i / 2) + Rf;         ev[2 * i] = 1;         ev[2 * i + 1] = -1;       }       if (h[i] == 1) {         x[2 * i] = (i / 2) - Re;         x[2 * i + 1] = (i / 2) + Re;         ev[2 * i] = 2;         ev[2 * i + 1] = -2;       }       if (h[i] == 2) {         x[2 * i] = (i / 2) - Rs;         x[2 * i + 1] = (i / 2) + Rs;         ev[2 * i] = 3;         ev[2 * i + 1] = -3;       }     }     doubleIntSort(x, ev, 2 * n);     tmp = 0;     for (i = 0; i < 2 * n - 1; i++) {       w = x[i + 1] - x[i];       if (ev[i] == 1) F++;       if (ev[i] == -1) F--;       if (ev[i] == 2) E++;       if (ev[i] == -2) E--;       if (ev[i] == 3) S++;       if (ev[i] == -3) S--;       tmp += (F * df + E * de) * (w * (S + 1));     }     if (res < tmp) res = tmp;   }   void brute(int depth) {     if (depth == n) calc();     if (nf > 0) {       h[depth] = 0;       nf--;       if (depth % 2 == 0 || h[depth - 1] <= h[depth]) brute(depth + 1);       nf++;     }     if (ne > 0) {       h[depth] = 1;       ne--;       if (depth % 2 == 0 || h[depth - 1] <= h[depth]) brute(depth + 1);       ne++;     }     if (ns > 0) {       h[depth] = 2;       ns--;       if (depth % 2 == 0 || h[depth - 1] <= h[depth]) brute(depth + 1);       ns++;     }   }   int main() {     int i, j, k, l, m;     res = 0;     scanf( %d%d%d , &nf, &ne, &ns);     n = nf + ne + ns;     scanf( %d%d%d , &rf, &re, &rs);     scanf( %d%d , &df, &de);     Rf = sqrt(rf * rf - 1);     if (rf == 1) Rf = 0;     Re = sqrt(re * re - 1);     if (re == 1) Re = 0;     Rs = sqrt(rs * rs - 1);     if (rs == 1) Rs = 0;     brute(0);     printf( %.15f n , res);     return 0;   }
#include <bits/stdc++.h>   struct data {     int val;     data(int val) : val(val) {}   };   bool operator<(const data lhs, const data rhs) {     std::cout <<  ?   << lhs.val <<     << rhs.val << std::endl;     char c;     std::cin >> c;     return c ==  < ;   }   int t, n;   std::set<data> a, b;   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     std::cout.tie(nullptr);     std::cin >> t;     while (t--) {       std::cin >> n;       a.clear();       b.clear();       for (int i = 1; i <= 2 * n; ++i) {         if (a.size() < b.size())           a.emplace(i);         else           b.emplace(i);         if (a.size() + b.size() > n)           if (*a.begin() < *b.begin())             a.erase(a.begin());           else             b.erase(b.begin());       }       std::cout <<  !  << std::endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n;   long long int f(long long int x) {     long long int sq = sqrt(x);     for (long long int i = 2; i <= sq; i++)       if (x % i == 0) return 0;     return 1;   }   int main() {     cin >> n;     if (f(n)) {       cout << 1 << endl << n << endl;       return 0;     }     cout << 3 << endl;     cout << 3 <<    ;     n -= 3;     for (long long int i = 2; i < n; i++) {       if (f(i) && f(n - i)) return cout << i <<     << n - i << endl, 0;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, q;   const int N = 2e5 + 10;   const int inf = 1e9;   char s[N];   struct Node {     Node() {       for (int i = 0; i < 5; i++) {         for (int j = 0; j < 5; j++) {           dp[i][j] = (i == j) ? 0 : inf;         }       }     }     int dp[5][5];   };   Node operator*(const Node& u, const Node& v) {     Node ans;     for (int i = 0; i < 5; i++) {       for (int j = 0; j < 5; j++) {         ans.dp[i][j] = inf;         for (int k = 0; k < 5; k++) {           ans.dp[i][j] = min(u.dp[i][k] + v.dp[k][j], ans.dp[i][j]);         }       }     }     return ans;   }   Node nodes[N * 4];   void build_tree(int l, int r, int rt) {     Node& v = nodes[rt];     if (l == r) {       char c = s[l - 1];       if (c ==  2 ) {         v.dp[0][0] = 1;         v.dp[0][1] = 0;       } else if (c ==  0 ) {         v.dp[1][1] = 1;         v.dp[1][2] = 0;       } else if (c ==  1 ) {         v.dp[2][2] = 1;         v.dp[2][3] = 0;       } else if (c ==  7 ) {         v.dp[3][3] = 1;         v.dp[3][4] = 0;       } else if (c ==  6 ) {         v.dp[3][3] = 1;         v.dp[4][4] = 1;       }       return;     }     int m = (l + r) >> 1;     build_tree(l, m, 2 * rt);     build_tree(m + 1, r, 2 * rt + 1);     v = nodes[2 * rt] * nodes[2 * rt + 1];   }   Node query(int L, int R, int l, int r, int rt) {     Node& v = nodes[rt];     if (L <= l && R >= r) return v;     int m = (l + r) >> 1;     bool left = false, right = false;     Node ltemp, rtemp;     if (L <= m) {       ltemp = query(L, R, l, m, rt * 2);       left = true;     }     if (R > m) {       rtemp = query(L, R, m + 1, r, rt * 2 + 1);       right = true;     }     if (left && right) return ltemp * rtemp;     if (left) return ltemp;     if (right) return rtemp;   }   int main() {     scanf( %d %d , &n, &q);     scanf( %s , s);     build_tree(1, n, 1);     for (int i = 0; i < q; i++) {       int l, r;       scanf( %d %d , &l, &r);       Node v = query(l, r, 1, n, 1);       if (v.dp[0][4] == inf)         cout << -1 << endl;       else         cout << v.dp[0][4] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Point {     int x;     int y;     Point(int x_, int y_) : x(x_), y(y_) {}   };   template <class T>   T sqr(const T& t) {     return t * t;   }   template <class T>   T abs(const T& t) {     return ((t > 0) ? (t) : (-t));   }   void initialize() {     freopen( _.in ,  r , stdin);     freopen( _.out ,  w , stdout);   }   bool isSqr(int x) {     int a = static_cast<int>(sqrt(static_cast<double>(x)));     return (a * a == x);   }   int sqrt(int x) { return static_cast<int>(sqrt(static_cast<double>(x))); }   int sign(int x) {     if (x < 0) return 0;     return 1;   }   int main() {     int x, y;     cin >> x >> y;     int r = x * x + y * y;     bool ok = true;     int b = sqrt(r);     int val = 2 + sign(x * y) + sqrt(r);     if (isSqr(r) || (sign(x * y) + sqrt(r)) % 2 == 1) {       cout <<  black ;     } else {       cout <<  white ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int res[100005], sz;   bool prime[100005], used[100005];   int main() {     int n;     cin >> n;     for (int p = 2; p <= n / 2; ++p) {       if (prime[p]) continue;       for (int j = p; j <= n; j += p) prime[j] = 1;       if (p == 2) continue;       int len = 0;       for (int j = p; j <= n; j += p) {         if (j == 2 * p) continue;         if (used[j]) continue;         used[j] = 1;         res[sz++] = j;         len++;       }       if (len & 1) {         res[sz++] = 2 * p;         used[2 * p] = 1;       }     }     for (int i = 2; i <= n; i += 2)       if (!used[i]) res[sz++] = i;     cout << sz / 2 << endl;     for (int i = 0; i + 1 < sz; i += 2) printf( %d %d n , res[i], res[i + 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mul(long long a, long long b) { return (a * b) % 1000000007; }   long long add(long long a, long long b) {     a += b;     if (a >= 1000000007) a -= 1000000007;     return a;   }   long long binary_expo(long long base, long long expo) {     long long res = 1;     while (expo) {       if (expo % 2) {         res = mul(res, base);       }       expo /= 2;       base = mul(base, base);     }     return res;   }   void solve() {     long long n;     cin >> n;     cout << n <<   n ;     for (long long i = 1; i <= n; i++) {       cout <<  1  ;     }     cout <<   n ;   }   signed main() {     long long t;     ios_base::sync_with_stdio(false);     t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   long long n, a[3][333333], x, y, sum[4][333333], r[4][333333];   set<pair<long long, long long> > s[333333];   map<pair<long long, long long>, long long> d;   map<long long, long long> last[4];   void read(long long &x) { scanf( %lld , &x); }   int main() {     cin >> n;     for (long long i = 1; i <= 2; i++)       for (long long j = 1; j <= n; j++) read(a[i][j]);     for (long long i = 1; i <= 2; i++)       for (long long j = n; j >= 1; j--) {         sum[i][j] = sum[i][j + 1] + a[i][j];         sum[3][j] += sum[i][j];       }     last[1][0] = last[2][0] = last[3][0] = n + 1;     r[1][n + 1] = r[2][n + 1] = r[3][n + 1] = n + 1;     for (long long i = 1; i <= 3; i++)       for (long long j = n; j >= 1; j--) {         r[i][j] = r[i][j + 1];         if (last[i].count(sum[i][j]))           r[i][j] = min(r[i][j], last[i][sum[i][j]] - 1);         last[i][sum[i][j]] = j;       }     s[0].insert(make_pair(0, 0));     d[make_pair(0, 0)] = 0;     for (long long i = 0; i < n; i++) {       for (pair<long long, long long> cur : s[i]) {         x = cur.first;         y = cur.second;         if (x <= y) {           s[min(x + 1, y)].insert(make_pair(x + 1, y));           d[make_pair(x + 1, y)] =               max(d[make_pair(x + 1, y)], d[make_pair(x, y)]);           s[min(r[1][x + 1], y)].insert(make_pair(r[1][x + 1], y));           d[make_pair(r[1][x + 1], y)] =               max(d[make_pair(r[1][x + 1], y)], d[make_pair(x, y)] + 1);         }         if (y <= x) {           s[min(x, y + 1)].insert(make_pair(x, y + 1));           d[make_pair(x, y + 1)] =               max(d[make_pair(x, y + 1)], d[make_pair(x, y)]);           s[min(r[2][y + 1], x)].insert(make_pair(x, r[2][y + 1]));           d[make_pair(x, r[2][y + 1])] =               max(d[make_pair(x, r[2][y + 1])], d[make_pair(x, y)] + 1);         }         if (x == y) {           s[r[3][x + 1]].insert(make_pair(r[3][x + 1], r[3][x + 1]));           d[make_pair(r[3][x + 1], r[3][x + 1])] =               max(d[make_pair(r[3][x + 1], r[3][x + 1])], d[make_pair(x, y)] + 1);         }         d.erase(make_pair(x, y));       }       s[i].clear();     }     assert(d.size() <= 4 * n);     cout << d[make_pair(n, n)];   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a > b) swap(a, b);     if (a == 0) return b;     return gcd(b % a, a);   }   int log2(int x, int max) { return max - __builtin_clz(x) - 1; }   long long powerMod(long long x, long long y) {     long long res = 1;     x %= 1000000007;     while (y > 0) {       if (y & 1) res = (res * x) % 1000000007;       y = y >> 1;       x = (x * x) % 1000000007;     }     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     ;     int n, m, i, j, k, l, x, y, c;     vector<pair<int, int> > v, dir;     cin >> n >> m;     string s[n];     int row[n][m];     int col[n][m];     memset((row), 0, sizeof((row)));     memset((col), 0, sizeof((col)));     for (i = 0; i < n; i++) {       row[i][0] = 1;     }     for (i = 0; i < m; i++) {       col[0][i] = 1;     }     for (i = 0; i < n; i++) {       cin >> s[i];       for (j = 0; j < m; j++) {         if (s[i][j] >=  A  && s[i][j] <=  Z ) v.push_back(make_pair(i, j));         if (j > 0) {           if (s[i][j] ==  # )             row[i][j] = row[i][j - 1] + 1;           else             row[i][j] = row[i][j - 1];         }         if (i > 0) {           if (s[i][j] ==  # )             col[i][j] = col[i - 1][j] + 1;           else             col[i][j] = col[i - 1][j];         }       }     }     cin >> k;     string st;     for (i = 0; i < k; i++) {       cin >> st >> l;       if (st[0] ==  N ) dir.push_back(make_pair(0, l));       if (st[0] ==  S ) dir.push_back(make_pair(1, l));       if (st[0] ==  E ) dir.push_back(make_pair(2, l));       if (st[0] ==  W ) dir.push_back(make_pair(3, l));     }     st =   ;     for (l = 0; l < v.size(); l++) {       x = v[l].first, y = v[l].second;       for (i = 0; i < k; i++) {         j = dir[i].first;         c = dir[i].second;         if (j == 0) {           if (x < c) goto loop;           if (col[x][y] - col[x - c][y] == 0 && s[x - c][y] !=  # )             x -= c;           else             goto loop;         }         if (j == 1) {           if (x + c >= n) goto loop;           if (col[x + c][y] - col[x][y] == 0)             x += c;           else             goto loop;         }         if (j == 2) {           if (y + c >= m) goto loop;           if (row[x][y + c] - row[x][y] == 0)             y += c;           else             goto loop;         }         if (j == 3) {           if (y < c) goto loop;           if (row[x][y] - row[x][y - c] == 0 && s[x][y - c] !=  # )             y -= c;           else             goto loop;         }       }       st += s[v[l].first][v[l].second];     loop:;     }     if (st ==   ) {       cout <<  no solution n ;       return 0;     }     sort(st.begin(), st.end());     cout << st << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9;   const long long base = 1e9 + 7;   const int N = 5e3 + 2;   int n, m, k;   int a[N][N];   pair<int, int> h[N], c[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m >> k;     long long x, y, z;     for (int i = (1), b_ = (k); i <= b_; ++i) {       cin >> x >> y >> z;       if (x == 1) {         h[y].first = z;         h[y].second = i;       } else {         c[y].first = z;         c[y].second = i;       }     }     for (int i = (1), b_ = (n); i <= b_; ++i) {       for (int j = (1), b_ = (m); j <= b_; ++j) {         if (h[i].second == 0 && c[j].second == 0)           cout << 0 <<    ;         else if (h[i].second > c[j].second)           cout << h[i].first <<    ;         else           cout << c[j].first <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int S[1000007], X[1000007], Y[1000007], W[1000007], C[1000007];   char s[10];   void dfs(int x) {     if (!S[x]) {       W[x] = X[x];       return;     }     dfs(X[x]);     if (S[x] > 1) dfs(Y[x]);     if (S[x] == 1) W[x] = W[X[x]] ^ 1;     if (S[x] == 2) W[x] = W[X[x]] & W[Y[x]];     if (S[x] == 3) W[x] = W[X[x]] | W[Y[x]];     if (S[x] == 4) W[x] = W[X[x]] ^ W[Y[x]];   }   void change(int x) {     if (!S[x]) return;     if (S[x] == 1) C[X[x]] = C[x];     if (S[x] == 2) {       if (!W[X[x]] && !W[Y[x]])         C[X[x]] = C[Y[x]] = 0;       else if (W[X[x]] && W[Y[x]])         C[X[x]] = C[Y[x]] = C[x];       else         C[X[x]] = W[X[x]] ? 0 : C[x], C[Y[x]] = W[Y[x]] ? 0 : C[x];     }     if (S[x] == 3) {       if (!W[X[x]] && !W[Y[x]])         C[X[x]] = C[Y[x]] = C[x];       else if (W[X[x]] && W[Y[x]])         C[X[x]] = C[Y[x]] = 0;       else         C[X[x]] = W[X[x]] ? C[x] : 0, C[Y[x]] = W[Y[x]] ? C[x] : 0;     }     if (S[x] == 4) C[X[x]] = C[Y[x]] = C[x];     change(X[x]);     if (S[x] > 1) change(Y[x]);   }   int main() {     int n, m, x, u, v, w, q;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf(  %s%d , s, &X[i]);       if (s[0] ==  I ) S[i] = 0;       if (s[0] ==  N ) S[i] = 1;       if (s[0] ==  A ) S[i] = 2;       if (s[0] ==  O ) S[i] = 3;       if (s[0] ==  X ) S[i] = 4;       if (S[i] > 1) scanf( %d , &Y[i]);     }     C[1] = 1;     dfs(1);     change(1);     for (int i = 1; i <= n; i++) {       if (!S[i]) printf( %d , W[1] ^ C[i]);     }     printf(  n );     return 0;   }