malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1000;   int dist[N * N], memo[N * N];   vector<pair<int, int>> H, T;   vector<int> ladj[N * N];   int vis[N * N];   inline int f(int x, int y) { return x * N + y; }   int bfs(int start) {     int n = N * N;     fill(dist, dist + n, INT_MAX);     fill(memo, memo + n, -1);     dist[start] = 0;     queue<int> Q;     Q.push(start);     while (!Q.empty()) {       int u = Q.front();       Q.pop();       for (int i = 0; i < (int)ladj[u].size(); i++) {         int v = ladj[u][i];         if (dist[v] > dist[u] + 1) {           dist[v] = dist[u] + 1;           Q.push(v);         }       }     }     return dist[0];   }   bool hasCycle(int start) {     if (vis[start] == -1) return true;     if (vis[start]) return false;     vis[start] = -1;     for (int i = 0; i < (int)ladj[start].size(); i++) {       int u = ladj[start][i];       if (hasCycle(u)) return true;     }     vis[start] = 1;     return false;   }   int dp(int u) {     int &ans = memo[u];     if (ans != -1) return ans;     ans = 0;     if (ladj[u].empty()) return 0;     for (int i = 0; i < (int)ladj[u].size(); i++) {       int v = ladj[u][i];       ans = max(ans, dp(v));     }     return ++ans;   }   int main() {     int h, t, r;     cin >> h >> t >> r;     int n;     cin >> n;     H.resize(n);     for (int i = 0; i < n; i++) cin >> H[i].first >> H[i].second;     int m;     cin >> m;     T.resize(m);     for (int i = 0; i < m; i++) cin >> T[i].first >> T[i].second;     for (int i = 0; i <= r; i++)       for (int j = 0; j <= r; j++)         if (i + j <= r) {           for (int k = 1; k <= n && k <= i; k++)             ladj[f(i, j)].push_back(                 f(i - k + H[k - 1].first, j + H[k - 1].second));           for (int k = 1; k <= m && k <= j; k++)             ladj[f(i, j)].push_back(                 f(i + T[k - 1].first, j - k + T[k - 1].second));         }     int start = f(h, t), ans = bfs(start);     if (ans < INT_MAX)       cout <<  Ivan  << endl << ans << endl;     else if (hasCycle(start))       cout <<  Draw  << endl;     else       cout <<  Zmey  << endl << dp(start) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     char x = getchar();     int ans = 0, flag = 1;     while (!isdigit(x))       if (x ==  - )         flag = -1, x = getchar();       else         x = getchar();     while (isdigit(x)) ans = ans * 10 + x -  0 , x = getchar();     return ans * flag;   }   int n, m, d, head[100005], nxt[200005], pnt[200005], E, dp[100005][2];   void add_edge(int u, int v) {     pnt[E] = v;     nxt[E] = head[u];     head[u] = E++;   }   void dfs1(int u, int pre) {     for (int i = head[u]; i != -1; i = nxt[i]) {       int v = pnt[i];       if (v == pre) continue;       dfs1(v, u);       if (dp[v][0] == -1) continue;       if (dp[u][0] < dp[v][0] + 1) {         swap(dp[u][0], dp[u][1]);         dp[u][0] = dp[v][0] + 1;       } else if (dp[u][1] < dp[v][0] + 1) {         dp[u][1] = dp[v][0] + 1;       }     }   }   void dfs2(int u, int pre, int val) {     if (dp[u][0] <= val) {       swap(dp[u][0], dp[u][1]);       dp[u][0] = val;     } else if (dp[u][1] <= val) {       dp[u][1] = val;     }     for (int i = head[u]; i != -1; i = nxt[i]) {       int v = pnt[i];       if (v == pre) continue;       int tmp = dp[u][0];       if (tmp == dp[v][0] + 1) tmp = dp[u][1];       dfs2(v, u, tmp + 1);     }   }   signed main() {     memset(head, -1, sizeof(head));     n = read(), m = read(), d = read();     memset(dp, 128, sizeof(dp));     for (int i = 1; i <= m; i++) {       int u = read();       dp[u][0] = dp[u][1] = 0;     }     for (int i = 1; i < n; i++) {       int u = read(), v = read();       add_edge(u, v);       add_edge(v, u);     }     dfs1(1, 0);     dfs2(1, 0, -1e9);     int ans = 0;     for (int i = 1; i <= n; i++) {       if (dp[i][0] <= d) ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using std::cerr;   using std::cin;   using std::cos;   using std::cout;   using std::endl;   using std::make_pair;   using std::map;   using std::max;   using std::min;   using std::next_permutation;   using std::pair;   using std::priority_queue;   using std::queue;   using std::random_shuffle;   using std::set;   using std::sin;   using std::sort;   using std::sqrt;   using std::stack;   using std::string;   using std::stringstream;   using std::swap;   using std::vector;   const long double PI = 3.14159265358979323846;   int main() {     string s;     cin >> s;     string s1 =  127 ;     if ((s.size() < s1.size()) || ((s.size() == s1.size()) && (s <= s1))) {       cout <<  byte  << endl;       return 0;     }     s1 =  32767 ;     if ((s.size() < s1.size()) || ((s.size() == s1.size()) && (s <= s1))) {       cout <<  short  << endl;       return 0;     }     s1 =  2147483647 ;     if ((s.size() < s1.size()) || ((s.size() == s1.size()) && (s <= s1))) {       cout <<  int  << endl;       return 0;     }     s1 =  9223372036854775807 ;     if ((s.size() < s1.size()) || ((s.size() == s1.size()) && (s <= s1))) {       cout <<  long  << endl;       return 0;     }     cout <<  BigInteger  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int r1, c1, r2, c2;   int chk(int i, int j) {     if (i == r1 || j == c1 ||         (((i == r1 && j == c1) || (i == r2 && j == c2)) ? 1 : 0))       return 1;     if ((((i - 1 == r1 && j - 2 == c1) || (i - 1 == r2 && j - 2 == c2)) ? 1 : 0))       return 1;     if ((((i + 1 == r1 && j - 2 == c1) || (i + 1 == r2 && j - 2 == c2)) ? 1 : 0))       return 1;     if ((((i + 2 == r1 && j - 1 == c1) || (i + 2 == r2 && j - 1 == c2)) ? 1 : 0))       return 1;     if ((((i + 2 == r1 && j + 1 == c1) || (i + 2 == r2 && j + 1 == c2)) ? 1 : 0))       return 1;     if ((((i - 1 == r1 && j + 2 == c1) || (i - 1 == r2 && j + 2 == c2)) ? 1 : 0))       return 1;     if ((((i + 1 == r1 && j + 2 == c1) || (i + 1 == r2 && j + 2 == c2)) ? 1 : 0))       return 1;     if ((((i - 2 == r1 && j - 1 == c1) || (i - 2 == r2 && j - 1 == c2)) ? 1 : 0))       return 1;     if ((((i - 2 == r1 && j + 1 == c1) || (i - 2 == r2 && j + 1 == c2)) ? 1 : 0))       return 1;     return 0;   }   int main() {     char c;     cin >> c >> c1;     r1 = c -  a ;     cin >> c >> c2;     r2 = c -  a ;     c1--;     c2--;     int ans = 64;     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) {         if (chk(i, j)) ans--;       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   long long power(long long base, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret = ret * base % mod;       base = base * base % mod;       b >>= 1;     }     return ret;   }   int n, m;   long long ans, cur;   int main() {     scanf( %d%d , &n, &m);     ans = 1LL * (n + m + 1) * power(m + 1, mod - 2) % mod;     for (int i = 1; i <= n; ++i) {       cur = (cur + power(i, mod - 2)) % mod;     }     cur = cur * m % mod + 1;     printf( %lld , ans * cur % mod);     return 0;   }
#include <bits/stdc++.h>   const int MAXN = 1e5 + 5;   const long long MOD = 998244353;   const int INF = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const double PI = acos(-1);   const double ERR = 1e-10;   const int L = 40;   const int M = 30;   using namespace std;   long long mx = -1e18;   long long mn = 1e18;   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     long long a, b[MAXN], c = 0;     cin >> a;     if (a == 1) {       cout <<  0 ;       return 0;     }     for (int i = 0; i < a; i++) {       cin >> b[i];     }     sort(b, b + a);     for (int i = 0; i < a; i++) {       c += b[a - 1] - b[i];     }     cout << c;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T getint() {     T x = 0, p = 1;     char ch;     do {       ch = getchar();     } while (ch <=    );     if (ch ==  - ) p = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * p;   }   mt19937 gen(chrono::system_clock::now().time_since_epoch().count());   template <typename T1, typename T2>   bool umin(T1 &x, const T2 &y) {     if (x > y) return x = y, true;     return false;   }   template <typename T1, typename T2>   bool umax(T1 &x, const T2 &y) {     if (x < y) return x = y, true;     return false;   }   const int maxn = (int)3e5 + 10;   const int inf = (int)1e9 + 5;   const int mod = (int)1e9 + 7;   const long long llinf = (long long)1e18 + 5;   const double pi = acos(-1.0);   int t[4 * maxn];   int pu[4 * maxn];   void push(int v) {     t[v + v] += pu[v];     pu[v + v] += pu[v];     t[v + v + 1] += pu[v];     pu[v + v + 1] += pu[v];     pu[v] = 0;   }   void add(int v, int l, int r, int x, int tl, int tr) {     if (l <= tl && tr <= r) {       t[v] += x;       pu[v] += x;       return;     }     push(v);     int tm = (tl + tr) / 2;     if (l <= tm) add(v + v, l, r, x, tl, tm);     if (r > tm) add(v + v + 1, l, r, x, tm + 1, tr);     t[v] = min(t[v + v], t[v + v + 1]);   }   int a[maxn], b[maxn];   int main() {     ios_base::sync_with_stdio(0);     int n, len, h;     cin >> n >> len >> h;     vector<int> x;     for (int i = (0); i < (len); i++) {       cin >> b[i];       b[i] = h - b[i];       x.push_back(b[i]);     }     for (int i = (0); i < (n); i++) {       cin >> a[i];       x.push_back(a[i]);     }     sort((x).begin(), (x).end());     x.erase(unique((x).begin(), (x).end()), x.end());     for (int i = (0); i < (len); i++)       b[i] = lower_bound((x).begin(), (x).end(), b[i]) - x.begin();     for (int i = (0); i < (n); i++)       a[i] = lower_bound((x).begin(), (x).end(), a[i]) - x.begin();     for (int i = (0); i < (len); i++) add(1, 0, b[i], -1, 0, maxn - 1);     int res = 0;     for (int i = (0); i < (n); i++) {       add(1, 0, a[i], 1, 0, maxn - 1);       if (i - len >= 0) add(1, 0, a[i - len], -1, 0, maxn - 1);       if (i + 1 >= len && t[1] >= 0) res++;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[201][201] = {0};   int n, m;   int main(int argc, char *argv[]) {     int x = 100;     int y = 100;     int ok = 0;     cin >> n >> m;     a[x][y] = n;     do {       ok = 0;       int max = y;       int min = x;       for (int i = x; i <= y; i++)         for (int j = x; j <= y; j++)           if (a[i][j] >= 4) {             ok = 1;             int numofant = a[i][j];             int mods = numofant % 4;             int temp = (numofant - mods) / 4;             a[i][j - 1] += temp;             a[i][j + 1] += temp;             a[i - 1][j] += temp;             a[i + 1][j] += temp;             a[i][j] = mods;           }       if (a[x - 1][100] >= 4) {         x--;         y++;       }     } while (ok == 1);     long long u, v;     int k[50005];     for (int i = 0; i < m; i++) {       cin >> u >> v;       u += 100;       v += 100;       if (u > 200 || u < 0 || v > 200 || v < 0)         k[i] = 0;       else         k[i] = a[u][v];     }     for (int i = 0; i < m; i++) cout << k[i] << endl;     return EXIT_SUCCESS;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 100005;   bool dp[501][501];   long long a[501], b[501];   signed main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     long long n, k;     cin >> n >> k;     for (long long i = 1; i < n + 1; i++) {       cin >> a[i] >> b[i];     }     dp[0][0] = true;     long long tot = 0;     for (long long i = 1; i < n + 1; i++) {       tot += (a[i] + b[i]);       for (long long j = 0; j < min(k, a[i] + 1); j++) {         long long x = (a[i] - j) % k;         if (x + b[i] < k) continue;         for (long long l = 0; l < k; l++) {           if (!dp[i - 1][l]) continue;           long long rem = (l + j) % k;           dp[i][rem] = true;         }       }       long long j = a[i] % k;       for (long long l = 0; l < k; l++) {         if (!dp[i - 1][l]) continue;         long long rem = (l + j) % k;         dp[i][rem] = true;       }     }     for (long long i = 0; i < k; i++) {       if (dp[n][i]) {         long long ans = (tot - i) / k;         cout << ans;         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   char kol[6];   set<vector<int> > zb;   bool used[6];   int rozw[6];   int obr[][6] = {{1, 2, 3, 4, 5, 6}, {1, 5, 3, 6, 4, 2}, {1, 6, 3, 5, 2, 4},                   {1, 4, 3, 2, 6, 5}, {2, 3, 4, 1, 5, 6}, {2, 6, 4, 5, 3, 1},                   {2, 1, 4, 3, 6, 5}, {2, 5, 4, 6, 1, 3}, {3, 4, 1, 2, 5, 6},                   {3, 6, 1, 5, 4, 2}, {3, 2, 1, 4, 6, 5}, {3, 5, 1, 6, 2, 4},                   {4, 1, 2, 3, 5, 6}, {4, 6, 2, 5, 1, 3}, {4, 3, 2, 1, 6, 5},                   {4, 5, 2, 6, 3, 1}, {5, 1, 6, 3, 2, 4}, {5, 4, 6, 2, 1, 3},                   {5, 3, 6, 1, 4, 2}, {5, 2, 6, 4, 3, 1}, {6, 1, 5, 3, 4, 2},                   {6, 2, 5, 4, 1, 3}, {6, 3, 5, 1, 2, 4}, {6, 4, 5, 2, 3, 1}};   void gogo(int kt) {     if (kt == 6) {       vector<int> pom[24];       for (int i = 0; i < (24); ++i) {         for (int j = 0; j < (6); ++j) pom[i].push_back(rozw[obr[i][j] - 1]);       }       bool only = 1;       for (int i = 0; i < (24); ++i)         if (zb.find(pom[i]) != zb.end()) only = false;       if (only) zb.insert(pom[0]);       return;     }     for (int i = 0; i < (6); ++i) {       if (!used[i]) {         used[i] = true;         rozw[kt] = kol[i];         gogo(kt + 1);         used[i] = false;       }     }   }   int main() {     scanf( %s , kol);     for (int i = 0; i < (6); ++i) used[i] = 0;     gogo(0);     printf( %d n , zb.size());   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long i, a = 0, b, j, b1[26] = {}, b2[26] = {};     string s1, s2;     vector<long> v1, v2;     cin >> s1 >> s2;     if (s1.size() != s2.size()) {       cout <<  NO ;       return 0;     }     for (i = 0; i < s1.size(); i++) {       if (s1[i] != s2[i]) {         a++;         v1.push_back(i);       }     }     if (a != 2) {       cout <<  NO ;       return 0;     }     if ((s1[v1[0]] == s2[v1[1]]) && (s2[v1[0]] == s1[v1[1]]))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(3)   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   using namespace std;   const int N = 7005;   const int M = 200000;   const long long mod = 1e9 + 7;   const long long inf = 0x3f3f3f3f;   namespace FastIO {   template <typename tp>   inline void read(tp& x) {     x = 0;     register char c = getchar();     register bool f = 0;     for (; c <  0  || c >  9 ; f |= (c ==  - ), c = getchar())       ;     for (; c >=  0  && c <=  9 ; x = (x << 3) + (x << 1) + c -  0 , c = getchar())       ;     if (f) x = -x;   }   template <typename tp>   inline void write(tp x) {     if (x == 0) return (void)(putchar( 0 ));     if (x < 0) putchar( - ), x = -x;     long long pr[20];     register long long cnt = 0;     for (; x; x /= 10) pr[++cnt] = x % 10;     while (cnt) putchar(pr[cnt--] +  0 );   }   template <typename tp>   inline void writeln(tp x) {     write(x);     putchar(  n );   }   }  // namespace FastIO   using namespace FastIO;   struct line {     int l, r, val;     line() {}     line(int l, int r, int val) {       this->l = l;       this->r = r;       this->val = val;     }   };   int n, m, lx[M], ly[M];   vector<line> xx[N];   int solve(int d, int x, int y) {     set<int> ans;     for (int i = d; i <= n; i++) {       for (int j = 0; j < xx[i].size(); j++) {         line& c = xx[i][j];         if (c.l <= y && c.r >= x) ans.insert(c.val);       }       x = (lx[x] == -1 ? ly[x] : lx[x]);       y = ly[y];     }     return ans.size();   }   void init() {     int cnt = 1, p = 3;     memset(lx, -1, sizeof(lx));     memset(ly, -1, sizeof(ly));     lx[1] = 1;     ly[1] = 2;     for (int i = 2; i < M; i++) {       if ((1 << cnt) == i) cnt++, lx[i] = p++;       ly[i] = p++;     }   }   int flag, d, x, y, val;   int main() {     init();     read(n), read(m);     for (int i = 0; i < m; i++) {       read(flag);       if (flag == 1)         read(d), read(x), read(y), read(val), xx[d].push_back(line(x, y, val));       else         read(d), read(x), writeln(solve(d, x, x));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int binSearch(int *a, int n, int x) {     int l = 0;     int r = n - 1;     while (l < r) {       int mid = (l + r) / 2;       if (a[mid] == x)         return mid;       else if (a[mid] < x)         l = mid + 1;       else         r = mid - 1;     }     return -1;   }   int main() {     map<long long, long long> mp;     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       mp[a[i]] = i + 1;     }     int q;     cin >> q;     long long cntFirst = 0, cntSecond = 0;     for (int i = 0; i < q; i++) {       int x;       cin >> x;       long long res = mp[x];       cntFirst += res;       cntSecond += (n - res + 1);     }     cout << cntFirst <<     << cntSecond;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC target( sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx )   using namespace std;   const int mod = 1e9 + 7;   const int N = 2e5 + 4;   int a[N], v[N], s[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];       v[i] = 1;     }     sort(a, a + n);     int j = 0;     int res = 0;     int cur = 0;     for (int i = 0; i < n; i++) {       while (j < n && a[j] - a[i] < m) {         cur += v[j];         s[j] = cur;         if (cur >= k && v[j] == 1) {           v[j] = 0;           res++;           cur--;         }         j++;       }       if (v[i]) cur--;     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     string s[105];     set<char> ms;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     long long ans = 1;     for (int i = 0; i < m; i++) {       ms.clear();       for (int j = 0; j < n; j++) ms.insert(s[j][i]);       ans = ans * ms.size() % 1000000007;     }     cout << ans % 1000000007;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int main() {     int t;     int n, m;     long long s = 0;     cin >> n >> m;     vector<long long> a(m);     for (int i = 0; i < m; i++) {       cin >> a[i];     }     s += (a[0] - 1);     for (int i = 1; i < m; i++) {       if (a[i] >= a[i - 1]) {         s += (a[i] - a[i - 1]);       } else {         s += (n - a[i - 1]);         s += (a[i]);       }     }     cout << s << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, ans;   int f[2005][2005], A[2005][2005];   int mul[2005], tr1[2005], tr2[2005], vis[2005], lck[2005];   int Getsum(int *tree, int x) {     int ans = 0;     for (int i = x; i; i -= i & -i) ans += tree[i];     return ans;   }   void Update(int *tree, int x, int v) {     for (int i = x; i <= n; i += i & -i) tree[i] += v;   }   int main() {     scanf( %d , &n);     f[0][0] = 1;     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= i; j++) {         if (j == 0)           f[i][j] = (long long)f[i - 1][j] * i % 998244353;         else {           f[i][j] = (f[i][j] + (long long)(i - j) * f[i - 1][j - 1] % 998244353) %                     998244353;           if (j >= 2)             f[i][j] =                 (f[i][j] + (long long)(j - 1) * f[i - 1][j - 2] % 998244353) %                 998244353;         }       }     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %d , &A[i][j]);     mul[0] = 1;     for (int i = 1; i <= n; i++)       mul[i] = (long long)mul[i - 1] * f[n][n] % 998244353;     for (int i = 1; i <= n; i++) {       int s = A[1][i] - 1 - Getsum(tr1, A[1][i] - 1);       ans = (ans +              (long long)s * f[n - i][0] % 998244353 * mul[n - 1] % 998244353) %             998244353;       Update(tr1, A[1][i], 1);     }     for (int i = 2; i <= n; i++) {       for (int j = 1; j <= n; j++) tr1[j] = tr2[j] = vis[j] = lck[j] = 0;       int all = 0;       for (int j = 1; j <= n; j++) {         int s = A[i][j] - 1 - Getsum(tr1, A[i][j] - 1) -                 ((A[i - 1][j] < A[i][j]) && !vis[A[i - 1][j]]);         int s1 = Getsum(tr2, A[i][j] - 1);         int s2 = s - s1;         lck[A[i - 1][j]] = 1;         if (!vis[A[i - 1][j]]) Update(tr2, A[i - 1][j], 1), all++;         if (s1)           ans = (ans + (long long)s1 * f[n - j][n - j - (all - 1)] % 998244353 *                            mul[n - i] % 998244353) %                 998244353;         if (s2)           ans = (ans + (long long)s2 * f[n - j][n - j - all] % 998244353 *                            mul[n - i] % 998244353) %                 998244353;         vis[A[i][j]] = 1;         if (lck[A[i][j]]) Update(tr2, A[i][j], -1), all--;         Update(tr1, A[i][j], 1);       }     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   struct point {     int id;     bool ok;     int row;     bool operator<(const point &p) const {       return (id == p.id) ? ok < p.ok : id < p.id;     }   };   point a[600100];   vector<int> edge[300100];   int dp[300100];   int truoc[300100];   bool ok[300100];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int x, y, z;       cin >> x >> y >> z;       a[i << 1] = {y, 1, x};       a[i << 1 | 1] = {z + 1, 0, x};     }     sort(a, a + 2 * m);     multiset<int, greater<int> > b;     multiset<int> c;     for (int i = 0; i < 2 * m; i++) {       if (a[i].ok) {         if (b.upper_bound(a[i].row) != b.end()) {           edge[*b.upper_bound(a[i].row)].push_back(a[i].row);         }         if (c.upper_bound(a[i].row) != c.end()) {           edge[a[i].row].push_back(*c.upper_bound(a[i].row));         }         b.insert(a[i].row);         c.insert(a[i].row);       } else {         b.erase(b.find(a[i].row));         c.erase(c.find(a[i].row));       }     }     for (int i = 1; i < n; i++) {       dp[i] = max(dp[i], 1);       for (auto x : edge[i]) {         if (dp[x] < dp[i] + 1) {           dp[x] = dp[i] + 1;           truoc[x] = i;         }       }     }     int max1 = -1;     int id;     for (int i = 1; i <= n; i++) {       if (dp[i] > max1) {         max1 = dp[i];         id = i;       }     }     cout << n - max1 <<   n ;     int cur = id;     while (cur != 0) {       ok[cur] = 1;       cur = truoc[cur];     }     for (int i = 1; i <= n; i++) {       if (!ok[i]) {         cout << i <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int w, m;     cin >> w >> m;     vector<int> v;     while (m > 0) {       v.push_back(m % w);       m /= w;     }     int ok = 1;     for (int i = 0; i < v.size(); i++) {       if (v[i] != 0 && v[i] != 1) {         v[i] -= w;         if (v[i] != -1 && v[i] != 0) {           ok = 0;           break;         }         if (i + 1 != v.size()) v[i + 1]++;       }     }     if (ok == 1)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int pow_mod(long long int a, long long int b) {     long long int res = 1;     while (b != 0) {       if (b & 1) {         res = (res * a) % 1000000007;       }       a = (a * a) % 1000000007;       b /= 2;     }     return res;   }   void solve() {     long long int x1, y1, z1;     cin >> x1 >> y1 >> z1;     long long int x2, y2, z2;     cin >> x2 >> y2 >> z2;     long long int ans = 0;     ans = min(z1, y2);     ans *= 2;     z1 -= min(z1, y2);     z2 -= min(z2, z1);     z2 -= min(z2, x1);     ans -= z2 * 2;     cout << ans << endl;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     t = 1;     cin >> t;     while (t--) solve();     return 0;   }