malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   const int INF = 0x3f3f3f3f;   const double PI = acos(-1.0);   const double EPS = 1e-9;   inline int sgn(double a) { return a < -EPS ? -1 : a > EPS; }   struct node {     long long v;     int id;     int date;     node(long long a = 0, int b = 0, int c = 0) {       v = a;       id = b;       date = c;     }   };   bool cmp(node x, node y) { return x.v < y.v; }   int n, m, k;   long long s;   long long a[maxn];   long long b[maxn];   int t[maxn];   long long c[maxn];   int p1[maxn];   int p2[maxn];   vector<node> ans;   bool judge(int x) {     ans.clear();     for (int i = 1; i <= m; i++) {       if (t[i] == 1) {         node xx = node((long long)(a[p1[x]] * c[i]), i, p1[x]);         ans.push_back(xx);       } else {         node xx = node((long long)(b[p2[x]] * c[i]), i, p2[x]);         ans.push_back(xx);       }     }     sort(ans.begin(), ans.end(), cmp);     long long sum = 0;     for (int i = 0; i < k; i++) {       sum += ans[i].v;     }     return sum <= s;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k >> s;     p1[0] = 1;     p2[0] = 1;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] < a[p1[i - 1]]) {         p1[i] = i;       } else         p1[i] = p1[i - 1];     }     for (int i = 1; i <= n; i++) {       cin >> b[i];       if (b[i] < b[p2[i - 1]])         p2[i] = i;       else         p2[i] = p2[i - 1];     }     for (int i = 1; i <= m; i++) {       cin >> t[i] >> c[i];     }     int l = 0;     int r = n + 1;     int mid;     while (l + 1 < r) {       mid = (l + r) >> 1;       if (judge(mid)) {         r = mid;       } else         l = mid;     }     if (r == n + 1) {       cout << -1 <<   n ;       return 0;     }     judge(r);     int tt = 0;     for (int i = 0; i < k; i++) {       tt = max(tt, ans[i].date);     }     cout << tt <<   n ;     for (int i = 0; i < k; i++) {       cout << ans[i].id <<     << ans[i].date <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long Fac[1000010], Inv[1000010], inv[1000010];   void ini() {     Fac[0] = Inv[0] = Fac[1] = Inv[1] = inv[1] = 1;     for (int i = 2; i < 1000010; i++) {       Fac[i] = Fac[i - 1] * i % 1000000007;       inv[i] = inv[1000000007 % i] * (1000000007 - 1000000007 / i) % 1000000007;       Inv[i] = Inv[i - 1] * inv[i] % 1000000007;     }   }   long long C(int n, int m) {     return Fac[n] * Inv[m] % 1000000007 * Inv[n - m] % 1000000007;   }   long long dp[1000010];   long long tmp = 0;   void add(int x) { tmp = (tmp + dp[x] * Inv[x]) % 1000000007; }   void del(int x) { tmp = (tmp - dp[x] * Inv[x]) % 1000000007; }   int main() {     ini();     int n, k;     scanf( %d %d , &n, &k);     dp[0] = 1;     for (int i = 1; i <= n; i++) {       add(i - 1);       if (i - k - 1 >= 0) del(i - k - 1);       dp[i] = (Fac[i - 1] * tmp % 1000000007 + 1000000007) % 1000000007;     }     long long res = Fac[n];     for (int i = 1; i <= n; i++) {       res = (res - dp[i - 1] * C(n - 1, i - 1) % 1000000007 * Fac[n - i]) %             1000000007;     }     cout << (res + 1000000007) % 1000000007;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10, M = (1 << 18);   int n, a[N], fa[N], cnt;   long long ans;   pair<int, int> mx[M][2], cur[M];   int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); }   bool merge(int x, int y) {     x = getfa(x), y = getfa(y);     if (x == y) return 0;     fa[x] = y;     return 1;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]), fa[i] = i;       ans -= a[i];     }     cnt = n + 1;     while (cnt > 1) {       for (int i = 0; i <= M - 1; i++)         for (int j = 0; j <= 1; j++) mx[i][j] = make_pair(-1, -1);       for (int i = 0; i <= n; i++) {         pair<int, int> t = make_pair(a[i], getfa(i));         if (mx[a[i]][0] < t) {           if (mx[a[i]][0].second != t.second) mx[a[i]][1] = mx[a[i]][0];           mx[a[i]][0] = t;         } else if (mx[a[i]][1] < t) {           if (mx[a[i]][0].second != t.second) mx[a[i]][1] = t;         }       }       for (int i = 0; i <= M - 1; i++) {         for (int j = 0; j <= 18; j++) {           if (i & (1 << j)) {             for (int k = 0; k <= 1; k++) {               if (mx[i][0] < mx[i ^ (1 << j)][k]) {                 if (mx[i][0].second != mx[i ^ (1 << j)][k].second)                   mx[i][1] = mx[i][0];                 mx[i][0] = mx[i ^ (1 << j)][k];               } else if (mx[i][1] < mx[i ^ (1 << j)][k]) {                 if (mx[i][0].second != mx[i ^ (1 << j)][k].second)                   mx[i][1] = mx[i ^ (1 << j)][k];               }             }           }         }       }       for (int i = 0; i <= n; i++) cur[i] = make_pair(-1, -1);       for (int i = 0; i <= n; i++) {         int f = getfa(i);         int t = ((M - 1) ^ a[i]);         if (mx[t][0].second != -1 && mx[t][0].second != f) {           cur[f] = max(cur[f], make_pair(mx[t][0].first + a[i], mx[t][0].second));         } else if (mx[t][1].second != -1 && mx[t][1].second != f) {           cur[f] = max(cur[f], make_pair(mx[t][1].first + a[i], mx[t][1].second));         }       }       for (int i = 0; i <= n; i++) {         if (fa[i] == i && merge(i, cur[i].second)) {           cnt--, ans += cur[i].first;         }       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T sqr(T x) {     return x * x;   }   const double EPS = 1e-6;   const int INF = 0x3fffffff;   const long long LINF = INF * 1ll * INF;   const double PI = acos(-1.0);   using namespace std;   bool vis[205][205];   int main(void) {     int a, b;     cin >> a >> b;     string s;     cin >> s;     int x = 0, y = 0;     vis[100][100] = 1;     for (int i = 0; s[i]; i++) {       if (s[i] ==  R )         x++;       else if (s[i] ==  L )         x--;       else if (s[i] ==  D )         y--;       else         y++;       vis[100 + x][100 + y] = true;     }     for (int i = 0; i <= 200; i++)       for (int j = 0; j <= 200; j++) {         if (vis[i][j]) {           long long dx = i - 100, dy = j - 100;           dx = a - dx, dy = b - dy;           if (x == 0) {             if (y == 0) {               if (dx == dy && dx == 0) {                 cout <<  Yes  << endl;                 return 0;               }             } else if (dx == 0 && dy % y == 0 && 1ll * dy * y >= 0) {               cout <<  Yes  << endl;               return 0;             }           } else if (1ll * dx * y == 1ll * dy * x && dx % x == 0 &&                      1ll * dx * x >= 0) {             cout <<  Yes  << endl;             return 0;           }         }       }     cout <<  No  << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, d, m, l, i, j, x;     cin >> n >> d >> m >> l;     for (i = 0; i < n - 1; i++) {       if ((i * m + l) / d * d + d < (i + 1) * m) break;     }     cout << (i * m + l) / d * d + d;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> k;     vector<vector<int> > dp(1 << n, vector<int>(1 << n, 0));     vector<int> G[n];     int all = (1 << n) - 1;     for (int i = 1; i <= m; ++i) {       int u, v;       cin >> u >> v;       u--;       v--;       G[u].emplace_back(v);       G[v].emplace_back(u);       dp[(1 << u) | (1 << v)][(1 << u) | (1 << v)]++;     }     for (int m1 = 0; m1 < (1 << n); m1++) {       for (int m2 = 0; m2 < (1 << n); m2++) {         if (!dp[m1][m2]) continue;         for (int i = 0; i < n; i++) {           if (!(m1 >> i & 1)) continue;           for (auto v : G[i]) {             if (m1 >> v & 1) continue;             int m3 = (m2 | (1 << v)) & (all ^ (1 << i));             if (!((m3 >> v) ^ 1)) dp[m1 | (1 << v)][m3] += dp[m1][m2];           }         }       }     }     long long res = 0;     for (int i = 0; i <= all; i++) {       if (__builtin_popcount(i) == k) res += dp[all][i];     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     vector<int> cnt(n + 1, false), idx(n + 1), ans(m + 1), b(m + 1);     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       cnt[x]++;       idx[x] = i;     }     for (int i = 1; i <= m; i++) {       cin >> b[i];       if (!cnt[b[i]]) {         cout <<  Impossible  << endl;         return 0;       }     }     for (int i = 1; i <= m; i++) {       if (cnt[b[i]] > 1) {         cout <<  Ambiguity  << endl;         return 0;       }       ans[i] = idx[b[i]];     }     cout <<  Possible  << endl;     for (int i = 1; i <= m; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[10] = {4, 8, 15, 16, 23, 42};   int q[5];   int main() {     for (int i = 1; i <= 4; i++) {       printf( ? %d %d n , i, i + 1);       fflush(stdout);       cin >> q[i];     }     do {       if (a[1] * a[0] == q[1] && a[2] * a[1] == q[2] && a[3] * a[2] == q[3] &&           a[4] * a[3] == q[4])         break;     } while (next_permutation(a, a + 6));     printf( ! );     for (int i = 0; i < 6; i++) printf(  %d , a[i]);     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int first[maxn];   int n;   int main() {     int num, i;     while (scanf( %d , &n) != EOF) {       memset(first, 0, sizeof(first));       for (i = 1; i <= n; i++) {         scanf( %d , &num);         if (i <= n / 2) {           if (num - (i - 1) > 0) first[num - (i - 1)]++;         } else {           if (num - (n - i) > 0) first[num - (n - i)]++;         }       }       int Max = 0;       for (i = 1; i < maxn; i++)         if (first[i] > Max) Max = first[i];       printf( %d n , n - Max);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long inf = 1000000000009;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long l{}, r{}, x{}, y{}, k{}, f{};     cin >> l >> r >> x >> y >> k;     for (int i = x, sz = (int)y + 1; i < sz; i++) {       if (l <= i * k && i * k <= r) {         f = 1;         break;       }     }     (f) ? cout <<  YES                 <<   n          : cout <<  NO                 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000000 * 2][2], g[1000000], v[1000000], d[20], f[1000000], e[20];   int n;   void ins(int x, int y) {     static int sum = 1;     a[++sum][0] = y, a[sum][1] = g[x], g[x] = sum;   }   int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }   void dfs(int x, int Gcd, int fa) {     int dd[20], ee[20];     for (int i = 0; i < 20; i++) dd[i] = d[i], ee[i] = e[i];     for (int i = g[x]; i; i = a[i][1])       if (a[i][0] != fa) {         int Gcd1 = gcd(Gcd, v[a[i][0]]);         for (int j = 1; j <= d[0]; j++)           d[j] = gcd(v[a[i][0]] / Gcd1, d[j]), e[j] = gcd(e[j], v[a[i][0]]);         if (Gcd1 != Gcd) d[++d[0]] = Gcd / Gcd1, e[d[0]] = Gcd;         if (x == 1) d[++d[0]] = v[a[i][0]] / Gcd1, e[d[0]] = v[a[i][0]];         int tot = 0;         for (int j = 1; j <= d[0]; j++)           if (d[j] != 1) d[++tot] = d[j], e[tot] = e[j];         d[0] = tot;         f[a[i][0]] = Gcd1;         for (int j = 1; j <= d[0]; j++) f[a[i][0]] = max(f[a[i][0]], Gcd1 * d[j]);         dfs(a[i][0], Gcd1, x);         for (int j = 0; j < 20; j++) d[j] = dd[j], e[j] = ee[j];       }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &v[i]);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       ins(x, y), ins(y, x);     }     f[1] = v[1];     dfs(1, v[1], 0);     for (int i = 1; i <= n; i++) {       printf( %d , f[i]);       if (i != n) printf(   );     }     return 0;   }
/*   python3 ../../CompetitionHelpers/run_codeforces.py --problem A --test 0   g++ -ggdb -fsanitize=address -std=c++17 A.cpp && ./a.out <<<  1   4   0 3 5 6    */      #include <bits/stdc++.h>   using namespace std;      #define rep(i, a, b) for (int i = a; i < (b); i++)   #define trav(a, x) for (auto& a : x)   #define all(x) begin(x), end(x)   #define sz(x) (int)(x).size()   typedef long long ll;   typedef pair<int, int> pii;   typedef vector<int> vi;      string to_string(pii p) { return  (  + to_string(p.first) +  ,  + to_string(p.second) +  ) ; }   template <typename A>   string to_string(A v) { int cnt = 0; string res; for (const auto &x : v) { if (cnt++) res +=    ; res += to_string(x); } return  [  + res +  ] ; }   string to_string(const string& s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string) s); }      void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) { cerr <<     << to_string(H); debug_out(T...); }   #define debug(...) cerr <<  [  << #__VA_ARGS__ <<  ]: , debug_out(__VA_ARGS__)      template<typename T>   void output_vector(const vector<T> &v, int start = 0, int end = -1) {       if (end < 0) end = int(v.size());       for (int i = start; i < end; i++)           cout << v[i] << (i < end - 1 ?     :   n );   }      int main() {       cin.sync_with_stdio(0); cin.tie(0);       cin.exceptions(cin.failbit);          int T; cin >> T; while (T--) {           ll n; cin >> n;           vector<ll> Arr(n); rep(i, 0, n) cin >> Arr[i];              sort(all(Arr));              ll ans = Arr.back();           for (ll i = 1; i < n; i++) {               ans -= (Arr[i] - Arr[i - 1]) * i * (n - i);           }              cout << ans <<   n ;       }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 500;   char s[MAX_N + 2][MAX_N + 2];   int D[2][MAX_N + 1][MAX_N + 1];   int main() {     int N, M;     scanf( %d%d n , &N, &M);     for (int i = 0; i <= M; ++i) s[0][i] =  # ;     for (int i = 1; i <= N; ++i) {       s[i][0] =  # ;       gets(s[i] + 1);     }     for (int i = 1; i <= N; ++i)       for (int j = 1; j <= M; ++j) {         D[0][i][j] = D[0][i - 1][j] + D[0][i][j - 1] - D[0][i - 1][j - 1] +                      (((s[i][j - 1] !=  # )) & -(s[i][j] !=  # ));         D[1][i][j] = D[1][i - 1][j] + D[1][i][j - 1] - D[1][i - 1][j - 1] +                      (((s[i - 1][j] !=  # )) & -(s[i][j] !=  # ));       }     int numQuery;     scanf( %d , &numQuery);     while (numQuery--) {       int x, y, X, Y;       scanf( %d%d%d%d , &x, &y, &X, &Y);       y++;       int SUM = D[0][X][Y] - D[0][x - 1][Y] - D[0][X][y - 1] + D[0][x - 1][y - 1];       y--;       x++;       SUM += D[1][X][Y] - D[1][x - 1][Y] - D[1][X][y - 1] + D[1][x - 1][y - 1];       printf( %d n , SUM);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void ECHO(string _s) {     cout << endl;     (void)_s;   }   template <typename T, typename... Args>   void ECHO(string _s, T x, Args... args) {     unsigned _i;     string _s2 =   ;     for (_i = 0; _i < _s.length(); ++_i) {       if (_s[_i] ==  , ) break;       if (_s[_i] !=    ) _s2 += _s[_i];     }     if (_i == _s.length()) {       --_i;     }     cout <<    (  << _s2 <<  ):  << x;     ECHO(_s.substr(_i + 1, _s.length() - _i - 1), args...);   }   template <typename T0, typename T1>   inline ostream& operator<<(ostream& os, pair<T0, T1>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   inline ostream& operator<<(ostream& os, vector<T>& v) {     for (unsigned i = 0; i < v.size(); ++i) {       cout << v[i] <<  _ ;     }     cout << endl;     return os;   }   template <typename T>   inline T _min(T x1, T x2, T x3) {     return min(x1, min(x2, x3));   }   template <typename T>   inline T _min(T x1, T x2, T x3, T x4) {     return min(min(x1, x2), min(x2, x3));   }   inline long long _gcd(long long a, long long b) {     while (b) b %= a ^= b ^= a ^= b;     return a;   }   int main() {     ios::sync_with_stdio(false);     int q;     cin >> q;     while (q--) {       long long n, n5, n3, n2, contador;       cin >> n;       contador = 0;       n5 = (n % 5);       while ((n5) == 0) {         n = 4 * n;         n = n / 5;         n5 = (n % 5);         contador = contador + 1;       }       n3 = (n % 3);       while ((n3) == 0) {         n = (2) * n;         n = n / 3;         n3 = (n % 3);         contador = contador + 1;       }       n2 = (n % 2);       while ((n2) == 0) {         n = n / 2;         n2 = (n % 2);         contador = contador + 1;       }       if (n == 1) {         cout << contador <<   n ;       } else {         cout << -1 <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read(T& x) {     x = 0;     int f = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) f |= (ch ==  - ), ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x = f ? -x : x;   }   int q, t, l, r, x, last;   map<int, int> fa;   map<int, int> val;   int Find(int x) {     if (fa.find(x) == fa.end()) return fa[x] = x;     if (fa[x] == x) return x;     int root = Find(fa[x]);     val[x] ^= val[fa[x]];     return fa[x] = root;   }   int main() {     for (read(q); q--;) {       read(t);       if (t == 1) {         read(l), read(r), read(x);         l ^= last, r ^= last, x ^= last;         if (l > r) swap(l, r);         l--;         int p = Find(l), q = Find(r);         if (p ^ q) {           if (p < q) swap(p, q);           fa[p] = q;           val[p] = val[l] ^ val[r] ^ x;         }       } else {         read(l), read(r);         l ^= last, r ^= last;         if (l > r) swap(l, r);         l--;         int p = Find(l), q = Find(r);         if (p == q) {           printf( %d n , val[p] ^ val[l] ^ val[r]);           last = val[p] ^ val[l] ^ val[r];         } else {           puts( -1 );           last = 1;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const double pi = acos(-1);   const int M = 3e5 + 10;   const int inf = 2e9 + 10;   const int mod = 1e9 + 7;   int n, stk[M], le[M], ri[M], f[M], cnt[M];   char s[M], s1[M];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> s + 1;     int num = 0, min = 0, id = 0;     for (int i = 1; i <= n; ++i) {       if (s[i] ==  ( )         ++num;       else         --num;       if (num < min) {         min = num;         id = i;       }     }     if (num) {       cout <<  0 n1 1 n ;       return 0;     }     for (int i = 1; i <= id; ++i) s1[n + i - id] = s[i];     for (int i = id + 1; i <= n; ++i) s1[i - id] = s[i];     int top = 0;     num = 0;     for (int i = 1; i <= n; ++i) {       if (s1[i] ==  ( ) {         stk[++top] = ++num;         le[num] = i;       } else {         int t1 = stk[top];         ri[t1] = i;         f[t1] = stk[--top];         ++cnt[stk[top]];       }     }     int ans = cnt[0], lans = 1, rans = 1;     for (int i = 1; i <= num; ++i) {       if (cnt[i] + 1 > ans && !f[i]) {         ans = cnt[i] + 1;         lans = le[i];         rans = ri[i];       }       if (cnt[i] + 1 + cnt[0] > ans && f[i] && !f[f[i]]) {         ans = cnt[i] + 1 + cnt[0];         lans = le[i];         rans = ri[i];       }     }     lans = (lans + id - 1) % n + 1;     rans = (rans + id - 1) % n + 1;     cout << ans <<   n  << lans <<     << rans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long N = 2e5 + 6;   const long long inf = 1e15;   long long ex, ey, ez, bx, by, bz, a[7];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     if (fopen( inp.txt ,  r )) {       freopen( inp.txt ,  r , stdin);       freopen( outp.txt ,  w , stdout);     }     cin >> ex >> ey >> ez;     cin >> bx >> by >> bz;     long long i, ans = 0;     for (i = 1; i <= 7; i++) cin >> a[i];     if (ex > bx)       ans += a[6];     else if (ex < 0)       ans += a[5];     if (ey > by)       ans += a[2];     else if (ey < 0)       ans += a[1];     if (ez > bz)       ans += a[4];     else if (ez < 0)       ans += a[3];     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2055, mod = (int)1e9 + 7;   template <class o>   void qr(o &x) {     char c = getchar();     x = 0;     while (!isdigit(c)) c = getchar();     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();   }   int n, m, L, last[N], ys[N], tot, vis[N], col[N];   struct P {     int x, y, c, i;   } a[N];   bool cmpx(P a, P b) { return a.x < b.x; }   bool cmpy(P a, P b) { return a.y < b.y; }   struct Q {     int l[N], r[N];     void del(int x) {       l[r[x]] = l[x];       r[l[x]] = r[x];     }   } q, nq;   struct node {     int mn, mx, s, tag;     node(int a = 0, int b = 0, int c = 0, int d = 0) {       mn = a;       mx = b;       s = c;       tag = d;     }     node operator+(node b) const {       return node(min(mn, b.mn), max(mx, b.mx), (s + b.s) % mod, 0);     }   } tr[N * 2];   int f[N];   void bt(int x, int l, int r) {     if (l == r) {       tr[x] = node(f[l], f[l], 1LL * (ys[r] - ys[l - 1]) * f[l] % mod, 0);       return;     }     int mid = (l + r) / 2;     bt((x << 1), l, mid);     bt((x << 1 | 1), mid + 1, r);     tr[x] = tr[(x << 1)] + tr[(x << 1 | 1)];   }   void upd(int x, int l, int r, long long t) {     tr[x] = node(t, t, t * (ys[r] - ys[l - 1]) % mod, t);   }   void change(int x, int l, int r, int L, long long t) {     if (tr[x].mn >= t) return;     if (tr[x].mx <= t && l == L) {       upd(x, l, r, t);       return;     }     int mid = (l + r) / 2;     if (tr[x].tag) {       upd((x << 1), l, mid, tr[x].tag);       upd((x << 1 | 1), mid + 1, r, tr[x].tag);       tr[x].tag = 0;     }     if (L <= mid) change((x << 1), l, mid, L, t);     change((x << 1 | 1), mid + 1, r, max(mid + 1, L), t);     tr[x] = tr[(x << 1)] + tr[(x << 1 | 1)];   }   int main() {     qr(n);     qr(m);     qr(L);     for (int i = 1; i <= n; i++) qr(a[i].x), qr(a[i].y), qr(a[i].c);     sort(a + 1, a + n + 1, cmpy);     a[0].x = a[0].y = -1;     a[n + 1].x = a[n + 1].y = L;     for (int i = 0; i <= n + 1; i++) ys[i] = a[i].y, a[i].i = i;     for (int i = 1; i <= n; i++) {       int l = nq.l[i] = last[a[i].c];       last[a[i].c] = i;       nq.r[i] = n + 1;       nq.r[l] = i;     }     sort(a + 1, a + n + 1, cmpx);     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (a[i].x ^ a[i - 1].x) {         q = nq;         for (int j = 1; j < i; j++) col[a[j].i] = 0;         for (int j = i; j <= n; j++) col[a[j].i] = a[j].c;         for (int l = 1, r = 1; l <= n; l++) {           for (; r <= n && tot < m; r++)             if (col[r] && !vis[col[r]]++) tot++;           f[l] = (tot < m) ? L : ys[r - 1];           if (col[l] && !--vis[col[l]]) tot--;         }         bt(1, 1, n);         for (int j = n; j >= i; j--) {           ans += (1LL * (ys[n] + 1) * L - tr[1].s) % mod * (a[i].x - a[i - 1].x) %                  mod * (a[j + 1].x - a[j].x) % mod;           int id = a[j].i, L = q.l[id], R = q.r[id];           change(1, 1, n, L + 1, ys[R]);           q.del(id);         }         ans %= mod;       }       nq.del(a[i].i);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 10;   int arr[MAX];   int n;   string s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     set<array<int, 4> > vis;     pair<int, int> p;     for (int tc = 1; tc <= t; ++tc) {       vis.clear();       cin >> s;       array<int, 4> a;       int ans = 0;       int x = 0, y = 0;       for (int i = 0; i < s.size(); ++i) {         a[0] = x;         a[1] = y;         if (s[i] ==  N ) y++;         if (s[i] ==  S ) y--;         if (s[i] ==  E ) x++;         if (s[i] ==  W ) x--;         a[2] = x;         a[3] = y;         if (vis.count(a))           ans++;         else           ans += 5;         vis.insert(a);         swap(a[0], a[2]);         swap(a[1], a[3]);         vis.insert(a);       }       cout << ans <<   n ;     }     return 0;   }