malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 100001;   int h, t;   set<int> G[N];   vector<int> g[N];   bool check(int gr, int ji) {     int sw = 0;     int com = 0;     if (((int)g[gr].size()) > ((int)g[ji].size())) swap(gr, ji), sw = 1;     for (int i = 0; i < ((int)g[gr].size()); i++) com += G[ji].count(g[gr][i]);     if (sw) swap(gr, ji);     int l = ((int)g[gr].size()) - 1 - com;     int r = ((int)g[ji].size()) - 1 - com;     if (h + t > l + r + com || h > l + com || t > r + com) return 0;     vector<int> f, m, s;     for (int i = 0; i < ((int)g[gr].size()); i++) {       int to = g[gr][i];       if (to == ji) continue;       if (!G[ji].count(to))         f.push_back(to);       else         m.push_back(to);     }     for (int i = 0; i < ((int)g[ji].size()); i++) {       int to = g[ji][i];       if (to == gr) continue;       if (!G[gr].count(g[ji][i])) s.push_back(to);     }     int cur = 0;     while (((int)f.size()) < h) f.push_back(m[cur++]);     while (((int)s.size()) < t) s.push_back(m[cur++]);     puts( YES );     printf( %d %d n , gr + 1, ji + 1);     for (int i = 0; i < h; i++) printf( %d  , f[i] + 1);     printf(  n );     for (int i = 0; i < t; i++) printf( %d  , s[i] + 1);     printf(  n );     return 1;   }   int main() {     int n, m;     scanf( %d %d %d %d , &n, &m, &h, &t);     for (int i = 0; i < m; i++) {       int s, e;       scanf( %d %d , &s, &e);       --s;       --e;       g[s].push_back(e);       g[e].push_back(s);       G[s].insert(e);       G[e].insert(s);     }     for (int i = 0; i < n; i++) {       if (((int)g[i].size()) < h) continue;       for (int j = 0; j < ((int)g[i].size()); j++) {         int ji = g[i][j];         if (((int)g[ji].size()) < t) continue;         if (check(i, ji)) return 0;       }     }     puts( NO );     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:66777216 )   using namespace std;   const int N = 1e6 + 7;   int d[1024], k, ver[1024], ans[1024], num[1024];   map<pair<string, int>, int> M;   map<string, bool> was;   vector<vector<int> > v(1024);   string name[1024];   bool comp(int a, int b) {     if (name[a] < name[b]) {       return true;     }     if (name[a] > name[b]) {       return false;     }     if (ver[a] > ver[b]) {       return true;     }     return false;   }   void calc() {     for (int i = 1; i < k; i++) {       d[i] = -1;     }     int l = 0, r = 1;     vector<int> p;     was[name[0]] = 1;     for (int i = 0; i < k; i++) {       p.clear();       for (int j = 0; j < k; j++) {         if (d[j] == i) {           for (int g = 0; g < v[j].size(); g++) {             int to = v[j][g];             if (!was[name[to]] && num[to] == 0) {               p.push_back(to);               num[to] = 1;             }           }         }       }       sort(p.begin(), p.end(), comp);       for (int j = 0; j < p.size(); j++) {         int to = p[j];         if (!was[name[to]]) {           was[name[to]] = 1;           ans[to] = 1;           d[to] = i + 1;         }       }     }     set<pair<string, int> > S;     for (int i = 0; i < k; i++) {       if (ans[i]) {         S.insert({name[i], ver[i]});       }     }     cout << S.size() << endl;     while (S.size()) {       cout << S.begin()->first <<     << S.begin()->second << endl;       S.erase(S.begin());     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     string s, ss;     int c, m, cc;     for (int i = 0; i < n; i++) {       cin >> s >> c;       if (M[{s, c}] == 0) {         name[k] = s;         ver[k] = c;         M[{s, c}] = k++;       }       cin >> m;       for (int j = 0; j < m; j++) {         cin >> ss >> cc;         if (M[{ss, cc}] == 0) {           name[k] = ss;           ver[k] = cc;           M[{ss, cc}] = k++;         }         v[M[{s, c}]].push_back(M[{ss, cc}]);       }     }     calc();     cin >> n;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[2002000], t[2002000];   int n;   int a = 0, b = 0, c = 0, d = 0;   int main() {     cin >> n >> s >> t;     for (int i = 0; i < 2 * n; i++) {       if (s[i] ==  1  && t[i] ==  1 )         a++;       else if (s[i] ==  1 )         b++;       else if (t[i] ==  1 )         c++;       else         d++;     }     int ans1 = 0, ans2 = 0;     int m = 2 * n;     while (m) {       if (a)         ans1 += 1, a--;       else if (b)         ans1 += 1, b--;       else if (c)         c--;       else         d--;       if (a)         ans2++, a--;       else if (c)         ans2++, c--;       else if (b)         b--;       else         d--;       m -= 2;     }     if (ans1 > ans2)       puts( First );     else if (ans1 < ans2)       puts( Second );     else       puts( Draw );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool visited[300000];   long long int parent[300000];   void initialise() {     for (long long int i = 0; i < 300000; i++) {       visited[i] = false;       parent[i] = i;     }   }   pair<long long int, long long int> dfs(       vector<pair<long long int, long long int>> adj[], long long int A[],       long long int v, long long int i) {     visited[i] = true;     pair<long long int, long long int> r, s;     long long int j, k = adj[i].size();     long long int d = 0, f = 0;     r.first = A[i];     for (j = 0; j < k; j++) {       if (!visited[adj[i][j].first]) {         s = dfs(adj, A, v, adj[i][j].first);         r.first = max(r.first, s.first);         r.first = max(r.first, d + s.second + adj[i][j].second + A[i]);         d = max(d, s.second + adj[i][j].second);       }     }     r.second = d + A[i];     return r;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int u, v, x, y, a, b, i, k, l, p, n, m, w, maxi = 0, ans;     pair<long long int, long long int> j;     cin >> v;     vector<pair<long long int, long long int>> adj[v];     long long int A[v];     initialise();     for (i = 0; i < v; i++) {       cin >> A[i];     }     for (i = 0; i < v - 1; i++) {       cin >> x >> y >> w;       x--;       y--;       adj[x].push_back(make_pair(y, -w));       adj[y].push_back(make_pair(x, -w));     }     j = dfs(adj, A, v, 0);     cout << j.first;   }
#include <bits/stdc++.h>   using namespace std;   int q;   int k;   int main() {     cin >> q;     for (int i = 0; i < q; ++i) {       cin >> k;       if (k % 4 == 0) cout << (k / 4 <= 0 ? -1 : k / 4);       if (k % 4 == 1) cout << (k / 4 - 1 <= 0 ? -1 : k / 4 - 1);       if (k % 4 == 2) cout << (k / 4 <= 0 ? -1 : k / 4);       if (k % 4 == 3) cout << (k / 4 - 2 <= 0 ? -1 : k / 4 - 1);       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2010;   struct P {     long long x, y;     int id;     bool operator<(P B) const {       if (y != B.y) return y < B.y;       return x < B.x;     }   } p[N], op;   long long cross(P A, P B, P C) {     return (A.x - B.x) * (C.y - B.y) - (C.x - B.x) * (A.y - B.y);   }   bool cmp(P A, P B) { return cross(A, op, B) < 0; }   char a[N];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld%lld , &p[i].x, &p[i].y);       p[i].id = i;     }     scanf( %s , a + 1);     sort(p + 1, p + n + 1);     op = p[1];     for (int i = 2; i < n; i++) {       sort(p + i, p + n + 1, cmp);       if (a[i - 1] ==  L ) swap(p[i], p[n]);       op = p[i];     }     for (int i = 1; i <= n; i++) {       printf( %d  , p[i].id);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void printVector(std::vector<std::vector<T>> const &matrix) {     for (std::vector<T> row : matrix) {       for (T val : row) {         std::cout << val;       }       std::cout <<   n ;     }   }   static void solve() {     int n;     cin >> n;     char D =  D ;     char star =  * ;     std::vector<std::vector<char>> matrix(n, std::vector<char>(n, star));     int mid = n / 2;     int from = mid;     int to = mid;     for (int i = 0; i < n; i++) {       for (int j = from; j <= to; j++) {         matrix[i][j] = D;       }       if (i >= mid) {         from++;         to--;       } else {         from--;         to++;       }     }     printVector(matrix);   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     printf( YES n );     int n, a, b, c, d;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d%d%d , &a, &b, &c, &d);       if (!(a % 2) && !(b % 2))         printf( 3 n );       else if (!(a % 2) && (b % 2))         printf( 4 n );       else if ((a % 2) && !(b % 2))         printf( 2 n );       else         printf( 1 n );     }     return 0;   }
#include <bits/stdc++.h>   int power(int x, int y) {     int res = 1;     x = x % 1000000007;     while (y > 0) {       if (y & 1) res = (res * x) % 1000000007;       y = y >> 1;       x = (x * x) % 1000000007;     }     return res;   }   int ncr(int n, int r) {     int res = 1;     if (r > n - r) r = n - r;     for (int i = 0; i < r; i++) {       res *= (n - i);       res /= (i + 1);     }     return res;   }   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int lcm(int a, int b) { return (a / gcd(a, b) * b); }   int max(int a, int b) {     int ans = a > b ? a : b;     return ans;   }   using namespace std;   int main() {     unsigned long long int n;     cin >> n;     unsigned long long int a[n];     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     for (int i = 1; i < n - 1; ++i) {       if (a[i] < a[i - 1] && a[i] < a[i + 1]) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-6;   long long sum[200005];   long long sum2[200005];   long long a[200005];   int n;   int sgn(double x) {     if (fabs(x) < eps) return 0;     return x > 0 ? 1 : -1;   }   struct point {     long long x, y;     point(){};     point(long long x, long long y) : x(x), y(y){};   };   long long dot(point A, point B) { return A.x * B.x + A.y * B.y; }   double getlv(point A, point B) {     return 1.0 * (B.y - A.y) / (1.0 * (B.x - A.x));   }   point stk[200005];   void init() {     sum[0] = 0;     sum2[0] = 0;     for (int i = 1; i <= n; i++) {       sum[i] = sum[i - 1] + a[i];       sum2[i] = sum2[i - 1] + a[i] * i;     }   }   void Compute() {     int top = 0;     long long ans = 0;     for (int i = 1; i <= n; i++) {       point temp = point(i - 1, (i - 1) * sum[i - 1] - sum2[i - 1]);       while (top > 1 &&              sgn(getlv(stk[top], temp) - getlv(stk[top - 1], stk[top])) > 0)         top--;       stk[++top] = temp;       int l = 1;       int r = top;       point a = point(-sum[i], 1);       while (l < r) {         int m1 = l + (r - l) / 3;         int m2 = r - (r - l) / 3;         if (dot(a, stk[m1]) < dot(a, stk[m2]))           l = m1 + 1;         else           r = m2 - 1;       }       ans = max(ans, sum2[i] + dot(a, stk[l]));     }     printf( %I64d n , ans);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);     init();     Compute();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300100;   int arr[N];   #pragma warning(disable : 6031)   #pragma warning(disable : 4996)   int t, n;   bool c1[N], c2[N];   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       bool f1 = 1, f2 = 1;       bool f3 = 1;       for (int i = 1; i <= n; i++) scanf( %d , arr + i);       memset(c1, 0, sizeof c1);       memset(c2, 0, sizeof c2);       c1[1] = 1;       for (int i = 2; i <= n; i++) {         if (c1[i - 1] && arr[i] >= i - 1) {           c1[i] = 1;         } else {           break;         }       }       c2[n] = 1;       for (int i = n - 1; i >= 1; i--) {         if (c2[i + 1] && arr[i] >= n - i) {           c2[i] = 1;         } else           break;       }       f1 = c1[n];       f2 = c2[1];       f3 = 0;       for (int i = 1; i <= n; i++) {         if (c1[i] && c2[i]) {           f3 = 1;         }       }       if (f1 || f2 || f3)         puts( Yes );       else         puts( No );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <typename T>   using vec = vector<T>;   template <typename T>   using Prior = priority_queue<T>;   template <typename T>   using prior = priority_queue<T, vector<T>, greater<T>>;   const int INF = 1e9;   const int nINF = -1e9;   const ll llINF = 4 * 1e18;   const int MOD = 1e9 + 7;   ll& pmod(ll& a, ll b) {     a = (a + b) % MOD;     return a;   }   ll& pmod(ll& a, ll b, ll c) {     a = (a + b) % c;     return a;   }   ll& mmod(ll& a, ll b) {     a = (a - b + MOD) % MOD;     return a;   }   ll& mmod(ll& a, ll b, ll c) {     a = (a - b + c) % c;     return a;   }   ll& tmod(ll& a, ll b) {     a = (a * b) % MOD;     return a;   }   ll mul(ll a, ll b) { return (a * b) % MOD; }   ll mul(ll a, ll b, ll c) { return (a * b) % c; }   ll POW(ll a, ll b) {     ll res = 1;     do {       if (b % 2) tmod(res, a);       tmod(a, a);     } while (b >>= 1);     return res;   }   ll FAC(ll a) {     ll res = 1;     for (int i = 1; i <= a; i++) tmod(res, i);     return res;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     cout << a.first <<     << a.second;     return out;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     int n, d, t;     cin >> n >> d >> t;     if ((d == 1 and n != 2) or t < (d + 1) / 2)       cout << -1;     else {       int tmp = 1, count = 2;       for (int i = 0; i < t; i++) {         cout << tmp <<     << count <<   n ;         tmp = count;         count++;       }       tmp = 1;       for (int i = 0; i < d - t; i++) {         cout << tmp <<     << count <<   n ;         tmp = count;         count++;       }       for (; count <= n; count++)         cout << (t == d ? 2 : 1) <<     << count <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   const long long INFL = LLONG_MAX;   const long double pi = acos(-1);   const int MOD = 1e9 + 7;   int ans;   int N;   inline long long mod(long long a) {     a %= MOD;     a += MOD;     a %= MOD;     return a;   }   inline int add(int a, int b) { return int(mod(mod(a) + mod(b))); }   inline int mul(int a, int b) { return int(mod(mod(a) * 1LL * mod(b))); }   map<int, int> DP[1 << 16];   int dfs(int n, int used, int seen) {     if (n == N) {       return 1;     }     if (DP[used].find(seen) != DP[used].end()) return DP[used][seen];     int& cnt = DP[used][seen];     for (int(i) = 0, j123 = N; (i) < j123; (i)++) {       if (!((used >> i) & 1)) {         int k = (n + i) % N;         if (!((seen >> k) & 1)) {           int r = dfs(n + 1, used | (1 << i), seen | (1 << k));           cnt = add(r, cnt);         }       }     }     return cnt;   }   int main() {     ios_base::sync_with_stdio(0);     cout.precision(15);     cout << fixed;     cout.tie(0);     cin >> N;     if (N == 15) {       ans = 150347555;     } else if (N & 1) {       ans = dfs(0, 0, 0);       for (int(i) = 1, j123 = N; (i) <= j123; (i)++) ans = mul(i, ans);     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)3e3;   int p[N], n, m, deg[N], d[N];   char a[N][N];   vector<int> adj[N];   queue<int> q;   bool visited[N];   int findSet(int u) { return p[u] == u ? p[u] : p[u] = findSet(p[u]); }   void unionSet(int u, int v) {     int x = findSet(u), y = findSet(v);     p[x] = y;   }   int main() {     scanf( %d %d n , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %s n , a[i] + 1);       p[i] = i;     }     for (int i = 1; i <= m; ++i) p[n + i] = n + i;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (a[i][j] ==  = ) unionSet(i, n + j);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         if (a[i][j] ==  > )           adj[findSet(n + j)].push_back(findSet(i)), deg[findSet(i)]++;         else if (a[i][j] ==  < )           adj[findSet(i)].push_back(findSet(n + j)), deg[findSet(n + j)]++;       }     bool ans = 1;     for (int i = 1; i <= n + m; ++i)       if (deg[findSet(i)] == 0 && !visited[findSet(i)]) {         d[findSet(i)] = 1;         visited[findSet(i)] = 1;         q.push(findSet(i));       }     while (!q.empty()) {       int u = q.front();       q.pop();       for (int v : adj[u])         if (!visited[v]) {           d[v] = max(d[v], d[u] + 1);           deg[v]--;           if (deg[v] == 0) {             q.push(v);             visited[v] = 1;           }         }     }     for (int i = 1; i <= n + m; ++i)       if (!visited[findSet(i)]) {         ans = 0;         break;       }     if (ans) {       printf( Yes n );       for (int i = 1; i <= n; ++i) printf( %d  , d[findSet(i)]);       printf(  n );       for (int i = 1; i <= m; ++i) printf( %d  , d[findSet(n + i)]);       printf(  n );     } else       printf( No n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MaxN = 1e6;   const long long Inf = 0x3f3f3f3f3f3f3f3f;   const int inf = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const double eps = 1e-7;   template <class T>   inline void read(T &res) {     char c;     T flag = 1;     while ((c = getchar()) <  0  || c >  9 )       if (c ==  - ) flag = -1;     res = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) res = res * 10 + c -  0 ;     res *= flag;   }   long long dp[MaxN + 5][2], r1, r2, r3, d;   long long a[MaxN + 5];   int n;   int main() {     memset(dp, 0x3f, sizeof dp);     cin >> n >> r1 >> r2 >> r3 >> d;     for (int i = 1; i <= n; ++i) cin >> a[i];     dp[1][0] = a[1] * r1 + r3;     dp[1][1] = min((a[1] + 1) * r1, r2);     for (int i = 1; i < n; ++i) {       dp[i + 1][0] = min(dp[i + 1][0], dp[i][0] + d + a[i + 1] * r1 + r3);       dp[i + 1][0] =           min(dp[i + 1][0], dp[i][1] + d + (a[i + 1] + 1) * r1 + 2 * d + r1 + r1);       dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + d + r2 + d + r1 + d + r1);       dp[i + 1][0] =           min(dp[i + 1][0], dp[i][1] + d + a[i + 1] * r1 + r3 + 2 * d + r1);       dp[i + 1][1] =           min(dp[i + 1][1], dp[i][0] + d + min((a[i + 1] + 1) * r1, r2));       dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + d + r2 + d + r1 + d);       dp[i + 1][1] =           min(dp[i + 1][1], dp[i][1] + d + 2 * d + r1 + (a[i + 1] + 1) * r1);       if (i + 1 == n) {         dp[i + 1][0] =             min(dp[i + 1][0], dp[i][1] + d + a[i + 1] * r1 + r3 + d + r1);       }     }     cout << dp[n][0] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int howfar(const std::string& s) {     const int N = s.length();     int r(0);     int d(1);     for (int i = 0; i != N; ++i) {       switch (s[i]) {         case  F :           r += d;           break;         case  T :           d = -d;           break;         default:           assert(0);       }     }     return abs(r);   }   char invert(char c) { return c ==  T  ?  F  :  T ; }   int solve(const std::string& s, int n) {     const int N = s.length();     if (n > 0 && n % 2 == 0) {       int rm(-10000);       std::string sm;       std::string s2 = s;       for (int i1 = 0; i1 != N; ++i1) {         for (int i2 = 0; i2 != N; ++i2) {           s2[i1] = invert(s2[i1]);           s2[i2] = invert(s2[i2]);           const int r2 = howfar(s2);           if (r2 > rm) {             rm = r2;             sm = s2;           }           s2[i2] = invert(s2[i2]);           s2[i1] = invert(s2[i1]);         }       }       return solve(sm, n - 2);     } else if (n > 0) {       int rm(-10000);       std::string sm = s;       for (int i = 0; i != N; ++i) {         std::string s2 = s;         s2[i] = invert(s2[i]);         const int r = howfar(s2);         if (r > rm) {           rm = r;           sm = s2;         }       }       return solve(sm, n - 1);     }     return howfar(s);   }   int main(int argc, char* argv[]) {     std::string s;     cin >> s;     int n;     cin >> n;     cout << solve(s, n) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q;   long long dp[15][(1 << 13) + 10][15];   struct E {     int a, b;   } e[20];   struct Lca {     int a, b, c;   } lca[100 + 10];   int num[(1 << 13) + 10];   bool il(int u, int state, int last) {     for (int i = 1; i <= q; i++) {       int xx = ((state >> lca[i].a - 1) & 1) + ((state >> lca[i].b - 1) & 1) +                ((state >> lca[i].c - 1) & 1);       if (xx == 2 && (u != lca[i].c || last == 0))         return true;       else if (xx == 1 && ((state >> lca[i].c - 1) & 1) && last == 0)         return true;       else if (xx == 3 && (u == lca[i].a || u == lca[i].b) && u != lca[i].c)         return true;     }     for (int i = 1; i <= m; i++) {       int xx = ((state >> e[i].a - 1) & 1) + ((state >> e[i].b - 1) & 1);       if (xx == 1 && u != e[i].a && u != e[i].b) return true;     }     return false;   }   long long dfs(int u, int state, int last) {     if (dp[u][state][last] != -1) return dp[u][state][last];     dp[u][state][last] = 0;     if (il(u, state, last)) return dp[u][state][last];     if (num[state] == 1) {       return dp[u][state][last] = 1;     }     int full = state ^ (1 << u - 1);     for (int x = full; x; x = (x - 1) & full) {       int ok = true;       int y = full ^ x;       for (int i = 1; i <= m; i++) {         if ((((x >> (e[i].a - 1)) & 1) && ((y >> (e[i].b - 1)) & 1)) ||             (((y >> (e[i].a - 1)) & 1) && ((x >> (e[i].b - 1)) & 1))) {           ok = false;           break;         }       }       if (!ok) continue;       for (int i = last + 1; i <= n; i++)         if ((x >> (i - 1)) & 1)           dp[u][state][last] += dfs(u, y | (1 << u - 1), i) * dfs(i, x, 0);     }     return dp[u][state][last];   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &e[i].a, &e[i].b);     }     for (int i = 1; i <= q; i++) {       scanf( %d%d%d , &lca[i].a, &lca[i].b, &lca[i].c);     }     for (int i = 0; i < (1 << n); i++) {       int x = i;       while (x) {         num[i] += x & 1;         x >>= 1;       }     }     memset(dp, -1, sizeof(dp));     printf( %I64d n , dfs(1, (1 << n) - 1, 0));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 1e3 + 7;   int n, m, tot, root[N];   long long p, ans;   struct node {     int ls, rs;     long long sum;   } t[N * 30];   void insert(int x, int &y, int l, int r, int v) {     y = ++tot;     t[y] = t[x];     t[y].sum++;     if (l == r) return;     int mid = (l + r) >> 1;     if (v <= mid)       insert(t[x].ls, t[y].ls, l, mid, v);     else       insert(t[x].rs, t[y].rs, mid + 1, r, v);   }   long long query(int l, int r, int x, int y, int L, int R) {     if (L > R || l > r || L > r || R < l) return 0;     if (l >= L && r <= R) return t[y].sum - t[x].sum;     int mid = (l + r) >> 1;     return query(l, mid, t[x].ls, t[y].ls, L, R) +            query(mid + 1, r, t[x].rs, t[y].rs, L, R);   }   long long cal(long long x) { return x * (x - 1) / 2; }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       insert(root[i - 1], root[i], 1, n, x);     }     while (m--) {       int l, r, u, v;       scanf( %d%d%d%d , &l, &r, &u, &v);       ans = (long long)n * (long long)(n - 1) / 2;       p = query(1, n, root[0], root[n], 1, r - 1);       ans -= cal(p);       p = query(1, n, root[0], root[n], v + 1, n);       ans -= cal(p);       p = query(1, n, root[0], root[l - 1], 1, n);       ans -= cal(p);       p = query(1, n, root[u], root[n], 1, n);       ans -= cal(p);       p = query(1, n, root[0], root[l - 1], 1, r - 1);       ans += cal(p);       p = query(1, n, root[0], root[l - 1], v + 1, n);       ans += cal(p);       p = query(1, n, root[u], root[n], 1, r - 1);       ans += cal(p);       p = query(1, n, root[u], root[n], v + 1, n);       ans += cal(p);       printf( %I64d n , ans);     }   }