malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int marked[1000006];   int f(int i, int j) {     if (j == 1) {       return marked[i];     }     return f(marked[i], j - 1);   }   vector<int> v;   int main() {     int n, a, b;     scanf( %d %d %d , &n, &a, &b);     int cut = -1;     for (int i = 0; i <= n; i++) {       if (i % a == 0 && (n - i) % b == 0) {         cut = i;         break;       }     }     if (cut == -1) {       printf( -1 n );       return 0;     }     int cnt = 0;     for (int i = 1; i <= cut; i++) {       cnt++;       v.push_back(i);       if (cnt == a) {         if ((int)v.size() >= 2) {           rotate(v.begin(), v.begin() + 1, v.end());         }         for (int j = 0; j < v.size(); j++) {           printf( %d  , v[j]);         }         cnt = 0;         v.clear();       }     }     cnt = 0;     for (int i = cut + 1; i <= n; i++) {       cnt++;       v.push_back(i);       if (cnt == b) {         if ((int)v.size() >= 2) {           rotate(v.begin(), v.begin() + 1, v.end());         }         for (int j = 0; j < v.size(); j++) {           printf( %d  , v[j]);         }         cnt = 0;         v.clear();       }     }   }
#include <bits/stdc++.h>   using namespace std;   void vin(vector<long long int> &v, long long int t) {     for (long long int i = 0; i < t; i++) cin >> v[i];   }   void vout(vector<long long int> &v, long long int t) {     for (long long int i = 0; i < t; i++) cout << v[i] <<    ;     cout << endl;   }   void ingraph(vector<vector<long long int>> &graph, long long int m) {     long long int x, y;     for (long long int i = 0; i < m; i++) {       cin >> x >> y;       x--, y--;       graph[x].push_back(y);       graph[y].push_back(x);     }   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long int lcm(long long int a, long long int b) {     return a * b / gcd(a, b);   }   void solve() {     long long int n, m;     cin >> n >> m;     vector<vector<long long int>> a(n, vector<long long int>(m)),         dp(n, vector<long long int>(m));     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < m; j++) cin >> a[i][j];     }     long long int ans = (long long int)1e18;     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < m; j++) {         long long int b = a[i][j] - i - j;         if (a[0][0] < b) continue;         vector<vector<long long int>> dp(             n, vector<long long int>(m, (long long int)1e18));         dp[0][0] = a[0][0] - b;         for (long long int p = 0; p < n; p++) {           for (long long int q = 0; q < m; q++) {             if (a[p][q] < (b + p + q)) continue;             if (p > 0)               dp[p][q] = min(dp[p][q], dp[p - 1][q] + a[p][q] - (b + q + p));             if (q > 0)               dp[p][q] = min(dp[p][q], dp[p][q - 1] + a[p][q] - (b + q + p));           }         }         ans = min(ans, dp[n - 1][m - 1]);       }     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct SCC {     int N;     vector<bool> used;     vector<int> vs;     vector<int> cmp;     void dfs(int v, const vector<int> G[]) {       used[v] = true;       for (auto u : G[v]) {         if (!used[u]) dfs(u, G);       }       vs.push_back(v);     }     void rdfs(int v, int k, const vector<int> rG[]) {       used[v] = true;       cmp[v] = k;       for (auto u : rG[v]) {         if (!used[u]) rdfs(u, k, rG);       }     }     void calculate(int Nin, const vector<int> G[], const vector<int> rG[]) {       N = Nin;       used.resize(N);       fill(used.begin(), used.end(), false);       for (int v = 0; v < N; v++) {         if (!used[v]) dfs(v, G);       }       fill(used.begin(), used.end(), false);       cmp.resize(N);       int k = 0;       for (int i = vs.size() - 1; i >= 0; i--) {         if (!used[vs[i]]) rdfs(vs[i], k++, rG);       }     }     int dump_graph(const vector<int> G[], vector<int> edges2[]) {       for (int i = 0; i < N; i++) {         for (auto j : G[i]) {           if (cmp[i] != cmp[j]) {             edges2[cmp[i]].push_back(cmp[j]);           }         }       }       return *max_element(cmp.begin(), cmp.end()) + 1;     }   };   vector<int> edges[5000000], edges2[5000000];   int main() {     int N, M, D;     cin >> N >> M >> D;     for (int i = 0; i < M; i++) {       int a, b;       scanf( %d %d , &a, &b);       a--;       b--;       for (int d = 0; d < D; d++) {         int s = a * D + d, t = b * D + (d + 1) % D;         edges[s].push_back(t);         edges2[t].push_back(s);       }     }     SCC scc;     scc.calculate(D * N, edges, edges2);     for (int i = 0; i < N * D; i++) edges2[i].clear();     int N2 = scc.dump_graph(edges, edges2);     vector<int> num(N * D);     char s[50];     for (int i = 0; i < N; i++) {       scanf( %s , s);       set<int> st;       for (int d = 0; d < D; d++) {         if (s[d] ==  0 ) continue;         int c = scc.cmp[i * D + d];         if (!st.count(c)) {           num[c]++;           st.insert(c);         }       }     }     vector<int> indeg(N2);     for (int i = 0; i < N2; i++)       for (int j : edges2[i]) indeg[j]++;     vector<int> dp(N2);     queue<int> que;     for (int i = 0; i < N2; i++) {       dp[i] = -1e9;       if (indeg[i] == 0) que.push(i);     }     int st = scc.cmp[0];     dp[st] = num[st];     while (que.size()) {       int i = que.front();       que.pop();       for (int j : edges2[i]) {         dp[j] = max(dp[j], dp[i] + num[j]);         indeg[j]--;         if (indeg[j] == 0) que.push(j);       }     }     int ans = *max_element(dp.begin(), dp.end());     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int n(0);     scanf( %d n , &n);     std::string number;     getline(std::cin, number);     if (number.size() <= 3) {       std::cout << number << std::endl;     } else {       int index(0);       if (number.size() % 2) {         std::cout << number.substr(0, 3);         index = 3;       } else {         std::cout << number.substr(0, 2);         index = 2;       }       while (index < number.size()) {         std::cout <<  - ;         std::cout << number.substr(index, 2);         index += 2;       }       std::cout << std::endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct E {     int ad, id, ne;   } e[100010 * 4];   int n, m, q, u[100010], v[100010], w[100010], h1[100010], h2[100010],       de[100010], fa[100010], f[100010], p0[100010], p1[100010];   bool o[100010];   void add(int* he, int x, int y, int d) {     static int t = 0;     ++t, e[t].ne = he[x], he[x] = t, e[t].ad = y, e[t].id = d;   }   int ff(int* f, int x) {     if (f[x] == x)       return x;     else       return f[x] = ff(f, f[x]);   }   void ff1(int x) {     p0[x] = p1[x] = x;     for (int p = h1[x]; p; p = e[p].ne) {       int y = e[p].ad;       if (!de[y]) {         fa[y] = x, de[y] = de[x] + 1, ff1(y), p1[y] = x;         if (ff(p0, x) == ff(p0, y)) o[x] |= o[y];       } else if (de[y] + 1 < de[x]) {         int z = ff(p0, x);         while (de[z] > de[y] + 1) p0[z] = fa[z], z = ff(p0, z);         if ((de[x] - de[y]) % 2 == 0) o[x] = 1;       }     }     for (int p = h2[x]; p; p = e[p].ne)       if (de[e[p].ad]) w[e[p].id] = ff(p1, e[p].ad);   }   void ff2(int x) {     if (o[ff(p0, x)]) f[x]++;     for (int i = h1[x]; i; i = e[i].ne) {       int y = e[i].ad;       if (de[y] == de[x] + 1) {         if (ff(p0, x) == ff(p0, y)) o[y] |= o[x];         f[y] = f[x], ff2(y);       }     }   }   bool chk(int u, int v, int w) {     if (ff(p1, u) != ff(p1, v)) return 0;     if ((de[u] - de[v]) % 2) return 1;     return f[u] + f[v] - f[w] * 2 > 0;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1, x, y; i <= m; i++)       scanf( %d%d , &x, &y), add(h1, x, y, i), add(h1, y, x, i);     scanf( %d , &q);     for (int i = 1; i <= q; i++)       scanf( %d%d , u + i, v + i), add(h2, u[i], v[i], i), add(h2, v[i], u[i], i);     for (int i = 1; i <= n; i++)       if (!de[i]) de[i] = 1, ff1(i), ff2(i);     for (int i = 1; i <= q; i++) puts(chk(u[i], v[i], w[i]) ?  Yes  :  No );   }
#include <bits/stdc++.h>   #pragma GCC optimize( -O3 ,  unroll-loops )   using namespace std;   template <typename T1, typename T2>   inline void chmin(T1& a, T2 b) {     if (a > b) a = b;   }   template <typename T1, typename T2>   inline void chmax(T1& a, T2 b) {     if (a < b) a = b;   }   const long long MOD = 1e9 + 7;   const long long MAX = 200010;   const double pi = acos(-1);   vector<long long> G[200010];   long long dp[200020];   long long dp_init(long long n, long long pre) {     if (dp[n] != 0) return dp[n];     long long res = 1;     for (auto nex : G[n]) {       if (nex == pre) continue;       res += dp_init(nex, n);     }     dp[n] = res;     return res;   }   long long ans = 0;   long long N;   bool used[200020];   void calc(long long n, long long res) {     used[n] = true;     for (auto nex : G[n]) {       if (used[nex]) continue;       long long tmp = res + N - 2 * dp[nex];       chmax(ans, tmp);       used[nex] = true;       calc(nex, tmp);     }   }   void solve() {     cin >> N;     for (long long i = 0; i < N - 1; i++) {       long long u, v;       cin >> u >> v;       u--, v--;       G[u].push_back(v);       G[v].push_back(u);     }     long long root = 0;     dp_init(0, 0);     long long tmp = 0;     for (long long i = 0; i < N; i++) tmp += dp[i];     ans = tmp;     calc(0, tmp);     cout << ans <<   n ;     ;   }   signed main() {     cin.tie(0);     ios::sync_with_stdio(false);     solve();   }
#include <bits/stdc++.h>   using namespace std;   int xd[] = {0, 1, 0, -1};   int yd[] = {1, 0, -1, 0};   int xx[] = {0, 1, 0, -1, 1, -1, 1, -1};   int yy[] = {1, 0, -1, 0, 1, 1, -1, -1};   int kx[] = {-2, -1, -2, -1, 1, 2, 2, 1};   int ky[] = {1, 2, -1, -2, -2, -1, 1, 2};   bool islucky(int x) {     int four = 0, seven = 0;     while (x) {       if (x % 10 != 7 && x % 10 != 4) return false;       if (x % 10 == 7)         seven++;       else         four++;       x = x / 10;     }     return four == seven;   }   bool is_prime(long long x) {     if (x == 1) return false;     for (int i = 2; i * i <= x; i++)       if (x % i == 0) return false;     return true;   }   long long C(int k, int l) {     if (l == k) return 1;     if (l * 2 > k) l = k - l;     long long res = 1, temp = l;     for (int i = k - l + 1; i <= k; i++) {       res *= i / temp;       temp--;     }     return res;   }   long long sumOfDigit(int x) {     int res = 0;     while (x) {       res += x % 10;       x /= 10;     }     return res;   }   uint64_t bigPow(uint64_t base, uint64_t p) {     uint64_t temp = 1;     while (p--) {       temp *= base;     }     return temp;   }   vector<int> soso;   bool prime[10000001] = {0};   void SieveOfEratosthenes(int n) {     soso.push_back(2);     for (int p = 3; p * p <= n; p += 2) {       if (prime[p] == false) {         for (int i = p * 2; i <= n; i += p) prime[i] = true;       }     }     for (int i = 3; i <= n; i += 2)       if (!prime[i]) soso.push_back(i);   }   vector<vector<int> > AdjList;   bool visited[100005];   void dfs(int s) {     if (visited[s]) return;     visited[s] = 1;     for (int i = 0; i < AdjList[s].size(); i++) dfs(AdjList[s][i]);     return;   }   long long gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int main() {     char grid[8][8];     for (int i = 0; i < 8; i++) cin >> grid[i];     int w = 0, b = 0;     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) {         if (grid[i][j] !=  . ) {           char c = grid[i][j];           if (c ==  q ) b += 9;           if (c ==  Q ) w += 9;           if (c ==  r ) b += 5;           if (c ==  R ) w += 5;           if (c ==  b  || c ==  n ) b += 3;           if (c ==  B  || c ==  N ) w += 3;           if (c ==  p ) b += 1;           if (c ==  P ) w += 1;         }       }     if (b == w)       cout <<  Draw ;     else if (b > w)       cout <<  Black ;     else       cout <<  White ;   }
#include <bits/stdc++.h>   const long long N = 100100;   const long long MAX = 1000000100;   using namespace std;   long long a[N] = {0};   int main() {     long long n;     while (scanf( %lld , &n) != EOF) {       map<long long, long long> num;       for (long long i = 0; i < n; i++) {         scanf( %lld , &a[i]);         num[a[i]]++;       }       sort(a, a + n);       long long min1 = MAX + 1, min2 = MAX + 2, min3 = MAX + 3;       for (long long i = 0; i < n; i++) {         if (a[i] < min1) {           min1 = a[i];         } else if (a[i] > min1 && a[i] < min2) {           min2 = a[i];         } else if (a[i] > min2 && a[i] < min3) {           min3 = a[i];           break;         }       }       if (num[min1] >= 3) {         long long sum = 1;         for (long long i = 3; i >= 1; i--) sum *= num[min1]--;         cout << sum / 6 << endl;       } else if (num[min1] == 2) {         cout << num[min2] << endl;       } else {         if (num[min2] >= 2) {           long long sum = 1;           for (long long i = 2; i >= 1; i--) sum *= num[min2]--;           cout << sum / 2 << endl;         } else {           cout << num[min3] << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int m = 0, b = 0;   int main() {     int n;     cin >> n;     int Arrpi[n];     for (int j = 0; j < n; ++j) {       cin >> Arrpi[j];     }     int A[n];     for (int l = 0; l < n; ++l) {       m = Arrpi[l] - 1;       b = l + 1;       A[m] = b;     }     for (int y = 0; y < n; ++y) {       cout << A[y] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char getc() {     char c = getchar();     while ((c <  A  || c >  Z ) && (c <  a  || c >  z ) && (c <  0  || c >  9 ))       c = getchar();     return c;   }   int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); }   int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     return x * f;   }   int n, k, a[5010], f[5010][5010], ans;   int ksm(int a, int k) {     int s = 1;     for (; k; k >>= 1, a = 1ll * a * a % 1000000007)       if (k & 1) s = 1ll * s * a % 1000000007;     return s;   }   int inv(int a) { return ksm(a, 1000000007 - 2); }   void inc(int &x, int y) {     x += y;     if (x >= 1000000007) x -= 1000000007;   }   signed main() {     const char LL[] =  %lld n ;     n = read(), k = read();     for (int i = 1; i <= n; i++) a[i] = read();     f[0][0] = 1;     for (int i = 1; i <= n; i++) {       f[i][0] = 1ll * f[i - 1][0] * a[i] % 1000000007;       for (int j = 1; j <= i; j++)         f[i][j] = (1ll * f[i - 1][j] * a[i] - f[i - 1][j - 1] + 1000000007) %                   1000000007;     }     int s = 1;     for (int i = 0; i <= min(k, n); i++) {       inc(ans, 1ll * ksm(n, k - i) * f[n][i] % 1000000007 * s % 1000000007);       s = 1ll * s * (k - i) % 1000000007;     }     ans = 1ll * ans * inv(ksm(n, k)) % 1000000007;     ans = (f[n][0] - ans + 1000000007) % 1000000007;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read() {     register T sum = 0;     register char cc = getchar();     int sym = 1;     while (cc !=  -  && (cc >  9  || cc <  0 )) cc = getchar();     if (cc ==  - ) sym = -1, cc = getchar();     sum = sum * 10 + cc -  0 ;     cc = getchar();     while (cc >=  0  && cc <=  9 ) sum = sum * 10 + cc -  0 , cc = getchar();     return sym * sum;   }   template <typename T>   inline T read(T& a) {     a = read<T>();     return a;   }   template <typename T, typename... Others>   inline void read(T& a, Others&... b) {     a = read(a);     read(b...);   }   int n, ans = 0x7fffffff, b[200010], prim[1000010];   long long a[200010];   set<long long> s;   void init() {     for (int i = 2; i <= 1000000; i++) {       if (!prim[i]) prim[++prim[0]] = i;       for (int j = 1; j <= prim[0] && i * prim[j] <= 1000000; j++) {         prim[i * prim[j]] = true;         if (i % prim[j]) break;       }     }   }   void div(long long x) {     for (int i = 1; i <= prim[0]; i++) {       if (x % prim[i]) continue;       s.insert(prim[i]);       while (x % prim[i] == 0) x /= prim[i];     }     if (x != 1) s.insert(x);   }   int solve(long long p) {     long long res = 0;     for (int i = 1; i <= n; i++) {       long long d = a[i] < p ? p - a[i] : min(a[i] % p, p - a[i] % p);       res = min(1ll * n, res + d);     }     return res;   }   int main() {     srand(time(NULL));     init();     read(n);     for (int i = 1; i <= n; i++) {       read(a[i]);       b[i] = i;     }     random_shuffle(b + 1, b + 1 + n);     for (int i = 1; i <= 100 && i <= n; i++) {       long long t = a[b[i]];       div(t);       div(t + 1);       if (t > 1) div(t - 1);     }     for (auto i : s) ans = min(ans, solve(i));     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, c, q, i;     cin >> q;     for (i = 1; i <= q; i++) {       cin >> n;       c = 0;       while (1) {         if (n % 2 == 0) {           n = n / 2;           c++;         } else if (n % 3 == 0) {           n = (2 * n) / 3;           c++;         } else if (n % 5 == 0) {           n = (4 * n) / 5;           c++;         } else           break;       }       if (n == 1)         cout << c << endl;       else         cout << -1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1505;   const int mo = 998244353;   int n, m, a[N][N];   int fa[N], sz[N], S[N];   int f[N][N], tmp[N];   pair<int, int> e[N * N];   int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); }   void merge(int x, int y) {     memset(tmp, 0, sizeof(tmp));     for (int i = (int)(1); i <= (int)(sz[x]); i++)       for (int j = (int)(1); j <= (int)(sz[y]); j++)         tmp[i + j] = (tmp[i + j] + 1ll * f[x][i] * f[y][j]) % mo;     memcpy(f[x], tmp, sizeof(f[x]));     sz[x] += sz[y];     S[x] += S[y];     fa[y] = x;   }   bool cmp(pair<int, int> x, pair<int, int> y) {     return a[x.first][x.second] < a[y.first][y.second];   }   int main() {     scanf( %d , &n);     for (int i = (int)(1); i <= (int)(n); i++)       for (int j = (int)(1); j <= (int)(n); j++) scanf( %d , &a[i][j]);     for (int i = (int)(1); i <= (int)(n); i++)       for (int j = (int)(i + 1); j <= (int)(n); j++)         e[++m] = pair<int, int>(i, j);     sort(e + 1, e + m + 1, cmp);     for (int i = (int)(1); i <= (int)(n); i++)       fa[i] = i, sz[i] = 1, S[i] = 0, f[i][1] = 1;     for (int i = (int)(1); i <= (int)(m); i++) {       int x = get(e[i].first);       int y = get(e[i].second);       if (x != y) merge(x, y);       ++S[x];       if (S[x] == sz[x] * (sz[x] - 1) / 2) f[x][1] = (f[x][1] + 1) % mo;     }     for (int i = (int)(1); i <= (int)(n); i++) cout << f[get(1)][i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   const int inf = 1000000009;   int i, j, k, l, m, n, q;   int ans;   int a[4][1000][1000], h[4][1000][1000], W[4], H[4];   void prec(int k, int i) {     for (int j = 0; j < H[k]; j++) {       if (h[k][i][j] == 0)         a[k][i][j] = 0;       else {         a[k][i][j] = 1;         if (j > 0) a[k][i][j] += a[k][i][j - 1];       }     }   }   void fl(int k, int i, int j) {     h[k][i][j] ^= 1;     prec(k, i);   }   int best(int k, int i, int j) {     int ret = 0;     int i1 = i - 1, i2 = i + 1, y = a[k][i][j];     while (y > 0) {       while (i1 >= 0 && a[k][i1][j] >= y) i1--;       while (i2 < W[k] && a[k][i2][j] >= y) i2++;       ret = max(ret, (i2 - i1 - 1) * y);       y--;     }     return ret;   }   int main() {     scanf( %d%d%d , &m, &n, &q);     W[0] = W[2] = H[1] = H[3] = m;     H[0] = H[2] = W[1] = W[3] = n;     for (int i = 0; i < m; i++)       for (int j = 0; j < n; j++) {         scanf( %d , &h[0][i][j]);         h[1][j][m - i - 1] = h[0][i][j];         h[2][m - i - 1][n - j - 1] = h[0][i][j];         h[3][n - j - 1][i] = h[0][i][j];       }     for (int k = 0; k < 4; k++)       for (int i = 0; i < W[k]; i++) prec(k, i);     while (q--) {       int op;       scanf( %d%d%d , &op, &i, &j);       i--;       j--;       if (op == 1) {         fl(0, i, j);         fl(1, j, m - i - 1);         fl(2, m - i - 1, n - j - 1);         fl(3, n - j - 1, i);       } else {         int ans = max(max(best(0, i, j), best(1, j, m - i - 1)),                       max(best(2, m - i - 1, n - j - 1), best(3, n - j - 1, i)));         cout << ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   string s;   string result;   int main() {     cin >> N;     cin >> s;     result = s;     result[(N - 1) / 2] = s[0];     int sign = N % 2 == 0 ? 1 : -1;     int val = 1;     int start = (N - 1) / 2;     for (int i = 1; i < N; ++i, sign *= -1, val++)       start = start + val * sign, result[start] = s[i];     cout << result;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 5;   struct edge {     int u, v, id;     edge(int a = 0, int b = 0, int c = 0) { u = a, v = b, id = c; }   };   vector<edge> S, M, E;   struct dsu {     int par[N];     vector<edge> ed;     dsu() { memset(par, -1, sizeof par); }     int get_par(int u) { return ~par[u] ? par[u] = get_par(par[u]) : u; }     bool merge(edge e) {       if (get_par(e.u) == get_par(e.v)) return false;       par[get_par(e.u)] = get_par(e.v), ed.push_back(e);       return true;     }     int size() { return ed.size(); }   } A, B, C;   int n, m;   void notValid() { cout <<  -1 n , exit(0); }   void readInput() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       char c;       int u, v;       cin >> u >> v >> c;       u--, v--;       if (c ==  S )         S.push_back(edge(u, v, i));       else         M.push_back(edge(u, v, i));     }   }   void solve() {     for (auto e : S) C.merge(e);     if (n & 1 ^ 1 || C.size() < n >> 1) notValid();     for (auto e : M)       if (C.merge(e)) A.merge(e);     if (C.size() != n - 1) notValid();     for (auto e : M)       if (A.size() < n >> 1) A.merge(e);     if (A.size() != n >> 1) notValid();     E = A.ed;     for (auto e : S)       if (A.merge(e)) B.merge(e);     E.insert(E.end(), B.ed.begin(), B.ed.end());   }   void writeOutput() {     cout << n - 1 << endl;     for (auto e : E) cout << e.id + 1 <<    ;   }   int main() {     ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);     readInput(), solve(), writeOutput();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll inf = 1e9 + 10;   const ll inf_ll = 1e18 + 10;   ll qry(ll t, ll i, ll j, ll k) {     cout << t <<     << i <<     << j <<     << k << endl;     ll r;     cin >> r;     return r;   }   int main() {     ll n;     cin >> n;     ll b = 2;     for (ll i = 2; i <= n; i++)       if (i != b && qry(2, 1, i, b) > 0) b = i;     vector<ll> h(n + 5), ord(n - 2), l, r;     for (ll i = 2; i <= n; i++)       if (i != b) h[i] = qry(1, 1, i, b);     iota((ord).begin(), (ord).end(), 3);     for (ll& i : ord)       if (i == b) i = 2;     sort((ord).begin(), (ord).end(), [&](ll i, ll j) { return h[i] < h[j]; });     ll c = ord.back();     for (ll i : ord) {       if (i != c && qry(2, 1, c, i) > 0)         l.push_back(i);       else         r.push_back(i);     }     cout <<  0 1   << b;     for (ll i : r) cout <<     << i;     reverse((l).begin(), (l).end());     for (ll i : l) cout <<     << i;     cout << endl;   }
#include <bits/stdc++.h>   int main() {     int n;     int x;     int sum = 0;     std::cin >> n;     std::cin >> x;     unsigned int t1 = 0, t2 = 0, tcurr = 1;     for (int i = 0; i < n; i++) {       std::cin >> t1;       std::cin >> t2;       sum += (t1 - tcurr) % x + t2 - t1 + 1;       tcurr = t2 + 1;     }     std::cout << sum;     return 0;   }