malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int inf = 2e9;   const long long INF = 8e18;   const int maxn = 2e5 + 5;   int n, k, cnt;   int a[maxn], b[maxn], p[maxn], fp[maxn], num[maxn];   vector<int> zz[maxn];   inline void init() {     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       ++num[x];     }     for (int i = 1; i <= k; ++i) {       int x;       cin >> x;       if (!p[x]) p[x] = ++cnt, fp[cnt] = x;       a[cnt] += num[i];       while (num[i]--) zz[cnt].push_back(i);     }     for (int i = 1; i <= cnt; ++i) b[i] = fp[i] - fp[i + 1];     int x = 0;     for (int i = cnt; i >= 1; --i) {       if (!a[i])         x += b[i];       else         b[i] += x, x = 0;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     init();     vector<vector<int> > ans;     vector<pair<int, int> > now, last;     for (int i = cnt; i >= 1; --i) {       if (!a[i]) continue;       last.push_back({i, a[i]});     }     while (!last.empty()) {       int val = 0, z = 0;       vector<int> res;       for (auto &x : last) {         int id = x.first, w = x.second;         val += b[id];         b[id] += z;         int mi = min(x.second, val);         w -= mi;         val -= mi;         while (mi--) res.push_back(id);         if (w)           now.push_back({id, w}), z = 0;         else           z = b[id];       }       ans.push_back(res);       last = now;       now.clear();     }     cout << ans.size() <<   n ;     for (auto &x : ans) {       cout << x.size() <<    ;       for (auto y : x) {         cout << zz[y].back() <<    ;         zz[y].pop_back();       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char BUFFER[100000 + 5];   bool readn(int &n) { return scanf( %d , &n) == 1; }   bool readl(long long &n) { return scanf( %I64d , &n) == 1; }   bool readd(double &n) { return scanf( %lf , &n) == 1; }   bool reads(string &s) {     s =   ;     int n = scanf( %s , BUFFER);     if (n == 1) s = BUFFER;     return n == 1;   }   bool readln(string &s) {     char *valid = gets(BUFFER);     if (valid) s = BUFFER;     return ((bool)valid);   }   int Print(long long a, long long b) {     cout << a <<     << b;     return 0;   }   void update(long long &su, long long n, long long mod) {     su *= n;     su %= mod;   }   int doit(long long n, long long mod) {     long long su = 1;     int i;     for (i = 1; i < n; i++) {       su *= 10;       su %= mod;     }     update(su, 3, mod);     update(su, 3, mod);     update(su, 5, mod);     update(su, 2, mod);     update(su, 3, mod);     update(su, 3, mod);     su++;     su %= mod;     long long a = 1, b = 1;     for (i = 0; i < n; i++) b *= 10;     if (0 == su) return Print(a, b);     su = mod - su;     return Print(a + su, b + su);   }   int main() {     long long a;     cin >> a;     doit(18, a);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   long double PI = 4 * atan(1);   int n, r, val[2001], x, flag, ch[2001];   bool isChild[2001][2001];   pair<int, int> p[2001];   vector<int> v[2001];   queue<int> q1, q2, ans;   void solve(int i) {     int rem = ch[i] - p[i].second;     while (ans.size()) {       x = ans.front();       if (isChild[i][x]) {         if (rem > 0) {           val[x]++;           q2.push(x);         } else {           if (rem == 0) {             q2.push(i);             val[i] = val[x] + 1;           }           q2.push(x);         }         rem--;       } else {         q1.push(x);       }       ans.pop();     }     if (rem == 0 || !q2.size()) {       q2.push(i);       val[i] = 1;     }     while (q1.size() && q2.size()) {       if (val[q1.front()] >= val[q2.front()]) {         ans.push(q1.front());         q1.pop();       } else {         ans.push(q2.front());         q2.pop();       }     }     while (q1.size()) {       ans.push(q1.front());       q1.pop();     }     while (q2.size()) {       ans.push(q2.front());       q2.pop();     }   }   void dfs(int i, int p) {     for (int a : v[i]) {       if (a != p) {         dfs(a, i);       }     }     solve(i);     return;   }   void calc(int par, int i, int p) {     ch[par]++;     isChild[par][i] = true;     for (int a : v[i]) {       if (a != p) {         calc(par, a, i);       }     }   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n;     for (int i = 1; i < n + 1; i++) {       cin >> p[i].first >> p[i].second;       if (p[i].first != 0)         v[p[i].first].push_back(i);       else         r = i;     }     for (int i = 1; i < n + 1; i++) calc(i, i, p[i].first), ch[i]--;     for (int i = 1; i < n + 1; i++) {       if (p[i].second > ch[i]) {         cout <<  NO ;         return 0;       }     }     dfs(r, 0);     cout <<  YES n ;     for (int i = 1; i < n + 1; i++) cout << val[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, s;     scanf( %lld , &a);     a = a - 2;     if (a % 3 == 0) {       printf( 1 2 %lld , a - 1);     } else       printf( 1 1 %lld , a);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   int findGCD(int arr[], int n) {     int result = arr[0];     for (int i = 1; i < n; i++) {       result = gcd(arr[i], result);     }     return result;   }   void swap(int* a, int* b) {     int t = *a;     *a = *b;     *b = t;   }   void merge(int arr[], int l, int m, int r) {     int i, j, k;     int n1 = m - l + 1;     int n2 = r - m;     int L[n1], R[n2];     for (i = 0; i < n1; i++) {       L[i] = arr[l + i];     }     for (j = 0; j < n2; j++) {       R[j] = arr[m + 1 + j];     }     i = 0;     j = 0;     k = l;     while (i < n1 && j < n2) {       if (L[i] <= R[j]) {         arr[k] = L[i];         i++;       } else {         arr[k] = R[j];         j++;       }       k++;     }     while (i < n1) {       arr[k] = L[i];       i++;       k++;     }     while (j < n2) {       arr[k] = R[j];       j++;       k++;     }   }   void mergeSort(int arr[], int l, int r) {     if (l < r) {       int m = l + (r - l) / 2;       mergeSort(arr, l, m);       mergeSort(arr, m + 1, r);       merge(arr, l, m, r);     }   }   int main() {     int n, i, gcd, pointsToBeAdded = 0;     cin >> n;     int arr[n];     int differences[n - 1];     for (i = 0; i < n; i++) {       cin >> arr[i];     }     mergeSort(arr, 0, n - 1);     for (i = 1; i < n; i++) {       differences[i - 1] = arr[i] - arr[i - 1];     }     gcd = findGCD(differences, n - 1);     for (i = 0; i < n - 1; i++) {       differences[i] /= gcd;       pointsToBeAdded += differences[i] - 1;     }     cout << pointsToBeAdded;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using i64 = long long;   using f64 = double;   using f80 = long double;   using pii = pair<int, int>;   using ptx = pair<f64, f64>;   const int N = 105;   bool f[N][N];   int n, m, first, second;   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int tip = 1;     int a, b;     cin >> n >> m;     cin >> first >> second;     cout << first <<     << second <<   n ;     f[first][second] = true;     for (int j = 1; j <= m; ++j) {       if (!f[first][j]) {         cout << first <<     << j <<   n ;         f[first][j] = true;         a = first, b = j;       }     }     tip = -1;     for (int i = 1; i <= n; ++i)       if (!f[i][m] && !f[i][1]) {         for (a = i; true; b += tip) {           cout << a <<     << b <<   n ;           f[a][b] = true;           if (!(1 <= b + tip && b + tip <= m)) break;         }         tip *= -1;       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, a[1003][1003], row[1003], col[1003];   int main() {     scanf( %d%d%d , &n, &m, &k);     int i, j;     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) scanf( %d , &a[i][j]);     for (i = 0; i <= n; i++) row[i] = i;     for (i = 0; i <= m; i++) col[i] = i;     char s;     int x, y;     for (i = 0; i < k; i++) {       scanf(  n%c %d %d , &s, &x, &y);       if (s ==  g ) printf( %d n , a[row[x]][col[y]]);       if (s ==  c ) {         j = col[x];         col[x] = col[y];         col[y] = j;       }       if (s ==  r ) {         j = row[x];         row[x] = row[y];         row[y] = j;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long r(long long a) {     long long i = 0;     while (a % 2 == 0) {       a /= 2;       ++i;     }     return i;   }   void one_case() {     long long a, b;     cin >> a >> b;     auto ra = r(a);     auto rb = r(b);     a /= (1ll << ra);     b /= (1ll << rb);     if (a != b) {       cout <<  -1 n ;       return;     }     cout << (abs(ra - rb) + 2) / 3 <<   n ;   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     int t = 1;     cin >> t;     while (t--) {       one_case();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int high[500005], ata[500005], cost[500005], par[500005], der[500005];   long long ans;   vector<int> v[500005];   int n, k, m, x, y, z;   vector<pair<int, pair<int, int> > > e;   int bul(int node, int ar[]) {     if (node == ar[node]) return node;     return ar[node] = bul(ar[node], ar);   }   void update(int a, int b, int cst) {     a = bul(a, high);     b = bul(b, high);     while (a != b) {       if (der[a] < der[b]) swap(a, b);       cost[a] = cst;       a = high[a] = bul(par[a], high);     }   }   void dfs(int node, int ata) {     par[node] = ata;     der[node] = der[ata] + 1;     for (int i : v[node])       if (i != ata) dfs(i, node);   }   int main() {     scanf( %d %d %d , &n, &k, &m);     for (int i = 1; i <= n; i++) ata[i] = i;     for (int i = 1; i <= k; i++) {       scanf( %d %d , &x, &y);       ata[bul(x, ata)] = bul(y, ata);       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= m; i++) {       scanf( %d %d %d , &x, &y, &z);       e.push_back({z, {x, y}});     }     sort(e.begin(), e.end());     for (int i = 0; i < m; i++) {       pair<int, pair<int, int> > edge = e[i];       if (bul(edge.second.first, ata) != bul(edge.second.second, ata)) {         v[edge.second.first].push_back(edge.second.second);         v[edge.second.second].push_back(edge.second.first);         ata[ata[edge.second.first]] = ata[edge.second.second];         ans -= edge.first;       }     }     dfs(1, 0);     for (int i = 1; i <= n; i++) {       high[i] = i;       cost[i] = 2000000000;     }     for (int i = 0; i < m; i++) {       pair<int, pair<int, int> > edge = e[i];       update(edge.second.first, edge.second.second, edge.first);     }     for (int i = 2; i <= n; i++) {       if (cost[i] == 2000000000) {         printf( -1 );         return 0;       }       ans += cost[i];     }     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int64_t inf = 1e18;   vector<vector<int64_t> > adj;   int64_t inp() {     int64_t x;     cin >> x;     return x;   }   vector<int64_t> level;   int64_t res = 0;   void dfs(int64_t u, int64_t LV = 0) {     level[u] = LV;     res = max(res, LV);     for (auto v : adj[u]) {       dfs(v, LV + 1);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     for (int64_t _ = (1); _ >= (1); _--) {       int64_t n;       cin >> n;       adj.resize(n + 1);       level.resize(n + 1);       for (int64_t node = (1); node <= (n); node++)         adj[max(inp(), int64_t(0))].push_back(node);       dfs(0);       cout << res;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long po(long long a, long long x, long long m) {     if (x == 0) {       return 1;     }     long long ans = 1;     long long k = 1;     while (k <= x) {       if (x & k) {         ans = ((ans * a) % m);       }       k <<= 1;       a *= a;       a %= m;     }     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       string a, b;       cin >> a >> b;       bool f[n + 1][2];       for (long long i = 0; i < n; i++) {         if (a[i] ==  1  || a[i] ==  2 )           f[i][0] = false;         else           f[i][0] = true;         if (b[i] ==  1  || b[i] ==  2 )           f[i][1] = false;         else           f[i][1] = true;       }       long long bll = 0;       bool flag = true;       bool k = false;       for (long long i = 0; i < n; i++) {         if (i != n && !f[i][bll]) {           continue;         }         if (i != n && (f[i][0] && !f[i][1]) || (f[i][1] && !f[i][0])) {           flag = false;           break;         }         bll ^= 1;       }       if (flag && bll == 1)         cout <<  YES               <<   n ;       else         cout <<  NO               <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 200100;   int N, M;   char S[MX];   int A[MX];   struct Segment {     int a, b, c, d, e;     int z, l, r;     void add(int x) { a += x, b += x, c -= x, d -= x, z += x; }   } T[MX << 2];   inline void PushUp(int i) {     Segment &t = T[i], &x = T[(i << 1)], &y = T[(i << 1 | 1)];     t.a = max(x.a, y.a);     t.b = min(x.b, y.b);     t.c = max(max(x.c, y.c), x.a - 2 * y.b);     t.d = max(max(x.d, y.d), y.a - 2 * x.b);     t.e = max(max(x.e, y.e), max(x.c + y.a, x.a + y.d));   }   inline void PushDown(int i) {     if (T[i].z) T[(i << 1)].add(T[i].z), T[(i << 1 | 1)].add(T[i].z), T[i].z = 0;   }   void Build(int i, int l, int r) {     T[i].l = l, T[i].r = r;     if (l == r) {       T[i].a = T[i].b = A[l], T[i].c = T[i].d = -A[l];       return;     }     int m = (l + r) >> 1;     Build((i << 1), l, m), Build((i << 1 | 1), m + 1, r);     PushUp(i);   }   void Add(int i, int a, int b, int x) {     if (a <= T[i].l && T[i].r <= b) {       T[i].add(x);       return;     }     PushDown(i);     if (a <= T[(i << 1)].r) Add((i << 1), a, b, x);     if (b >= T[(i << 1 | 1)].l) Add((i << 1 | 1), a, b, x);     PushUp(i);   }   int main() {     int n;     scanf( %d%d%s , &n, &M, S + 1), N = strlen(S + 1);     for (int i = (1); i <= (N); ++i) A[i] = A[i - 1] + (S[i] ==  (  ? 1 : -1);     Build(1, 0, N);     printf( %d n , T[1].e);     for (int i = (1); i <= (M); ++i) {       int l, r;       scanf( %d%d , &l, &r);       if (l > r) swap(l, r);       if (S[l] != S[r]) Add(1, l, r - 1, S[l] ==  (  ? -2 : 2), swap(S[l], S[r]);       printf( %d n , T[1].e);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   int a[maxn];   int n, l, t;   int main() {     scanf( %d%d%d , &n, &l, &t);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     double ans = 0;     int k = 2 * t / l, c = 2 * t % l;     for (int i = 0; i < n; i++) {       int w = a[i] - c;       int cnt = 0;       if (w >= 0) {         cnt = i - (lower_bound(a, a + n, w) - a);       } else {         cnt += i;         cnt += n - (lower_bound(a, a + n, l + w) - a);       }       ans += 0.5 * 0.5 * k * (n - 1) + 0.5 * 0.5 * cnt;     }     cout.setf(ios::fixed);     cout << setprecision(9) << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > dist(51, vector<int>(3, 100));   int n, m;   int dp[51][8];   void calc_s(int i, string &s) {     for (int j = 0; j < s.length(); j++) {       if (s[j] ==  #  || s[j] ==  *  || s[j] ==  & ) {         dist[i][2] = min(dist[i][2], j);         dist[i][2] = min(dist[i][2], m - j);       } else if (s[j] >=  a  && s[j] <=  z ) {         dist[i][0] = min(dist[i][0], j);         dist[i][0] = min(dist[i][0], m - j);       } else if (s[j] >=  0  && s[j] <=  9 ) {         dist[i][1] = min(dist[i][1], j);         dist[i][1] = min(dist[i][1], m - j);       }     }   }   int calc(int i, int j) {     if (j == 7) return 0;     if (i == (n + 1)) return 100;     if (dp[i][j] != -1) return dp[i][j];     int x = 100;     for (int k = 0; k < 3; k++) {       x = min(x, dist[i][k] + calc(i + 1, (j | (1 << k))));     }     dp[i][j] = x;     return dp[i][j];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       string s;       cin >> s;       calc_s(i, s);     }     memset(dp, -1, sizeof(dp));     cout << calc(1, 0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mult(int a, int b, int p = 1000000007) { return ((a % p) * (b % p)) % p; }   int multbig(int a, int b, int mod) {     if (a == 0 or b == 0) return 0;     if (a == 1 or b == 1) return (a * b) % mod;     int cur = multbig(a, b / 2, mod);     cur = (2 * cur) % mod;     if (b % 2) cur = (cur + a) % mod;     return cur;   }   int add(int a, int b, int p = 1000000007) { return (a % p + b % p) % p; }   int fpow(int n, int k, int p = 1000000007) {     int r = 1;     for (; k; k >>= 1LL) {       if (k & 1LL) r = mult(r, n, p);       n = mult(n, n, p);     }     return r;   }   int inv(int a, int p = 1000000007) { return fpow(a, p - 2, p); }   int inv_euclid(int a, int m = 1000000007) {     int m0 = m;     int y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       int q = a / m;       int t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   vector<pair<int, int>> vvv;   pair<int, int> aa[200003];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < (int)m; i++) {       int p, q;       cin >> p >> q;       if (p > q) {         swap(p, q);       }       aa[i].first = p;       aa[i].second = q;       vvv.push_back(make_pair(p, q));     }     sort(vvv.begin(), vvv.end());     int f = 0;     for (int i = 2; i <= n; i++) {       if (n % i == 0) {         int lol = n / i;         vector<pair<int, int>> vv;         for (int i = 0; i < (int)m; i++) {           int p = aa[i].first + lol;           int q = aa[i].second + lol;           if (p > n) {             p = p - n;           }           if (q > n) {             q = q - n;           }           if (p > q) {             swap(p, q);           }           vv.push_back(make_pair(p, q));         }         sort(vv.begin(), vv.end());         if (vv == vvv) {           f = 1;           break;         }       }     }     if (f) {       cout <<  Yes n ;     } else       cout <<  No n ;   }
#include <bits/stdc++.h>   using namespace std;   void dice() {     int x, y;     cin >> x >> y;     x = max(x, y);     vector<string> str;     str = { 1/6 ,  1/3 ,  1/2 ,  2/3 ,  5/6 ,  1/1 };     x = 6 - x + 1;     cout << str[x - 1] << endl;   }   int main() { dice(); }
#include <bits/stdc++.h>   using namespace std;   int ask(int c, int d) {     cout <<  ?   << c <<     << d << endl;     fflush(stdout);     int x;     cin >> x;     return x;   }   void go(int a, int b) {     cout <<  !   << a <<     << b << endl;     fflush(stdout);     exit(0);   }   bool same[50];   signed main() {     int type = ask(0, 0);     if (type == 0) {       int ans = 0;       for (int i = 29; i >= 0; i--) {         int q = ask((1 << i), 0);         if (q == 0) {           continue;         }         if (q == 1) {           ans += 0;         } else {           ans += (1 << i);         }       }       go(ans, ans);     }     bool A, B;     if (type == 1) {       A = 1;       B = 0;     } else {       A = 0;       B = 1;     }     int ansA = 0, ansB = 0;     for (int i = 29; i >= 0; i--) {       int q = ask(ansA + (1 << i), ansB + (1 << i));       if (q == 0) {         for (int pos = i; pos >= 0; pos--) {           same[pos] = 1;         }         break;       }       if (A == 1) {         if (q == 1) {           same[i] = 1;         } else {           ansA += (1 << i);           ansB += 0;           int qq = ask(ansA, ansB);           if (qq == 1) A = 1, B = 0;           if (qq == -1) A = 0, B = 1;         }       } else {         if (q == -1) {           same[i] = 1;         } else {           ansA += 0;           ansB += (1 << i);           int qq = ask(ansA, ansB);           if (qq == 1) A = 1, B = 0;           if (qq == -1) A = 0, B = 1;         }       }     }     for (int i = 29; i >= 0; i--) {       if (same[i]) {         int q = ask(ansA + (1 << i), ansB);         if (q == 0) {           continue;         }         if (q == 1) {           ansA += 0;           ansB += 0;         } else {           ansA += (1 << i);           ansB += (1 << i);         }       }     }     go(ansA, ansB);   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1010;   bool z[MAXN] = {0};   void prework() {     for (int i = 2; i <= 1000; i++) {       if (z[i]) continue;       for (int k = i + i; k <= 1000; k += i) z[k] = true;     }   }   struct node {     char c;     int n;     bool operator<(node b) const { return n > b.n; }   };   vector<int> v;   int num[50] = {0};   string s;   node a[27];   char ans[1010] = {0};   int main() {     prework();     string s;     cin >> s;     int L = s.size();     int all = 0;     for (int i = 2; i <= L; i++) {       if (z[i]) continue;       if (i * 2 <= L) continue;       v.push_back(i);       all++;     }     v.push_back(1);     all++;     for (string::iterator k = s.begin(); k != s.end(); k++) num[*k -  a  + 1]++;     for (int i = 1; i <= 26; i++) {       a[i].c =  a  + i - 1;       a[i].n = num[i];     }     sort(a + 1, a + 27);     all = L - all;     if (a[1].n < all) {       cout <<  NO  << endl;       return 0;     }     a[1].n -= all;     int now = 1;     for (vector<int>::iterator k = v.begin(); k != v.end(); k++) {       while (!a[now].n) now++;       ans[*k] = a[now].c;       a[now].n--;     }     for (int i = 1; i <= L; i++)       if (!ans[i]) ans[i] = a[1].c;     cout <<  YES  << endl;     string sss(ans + 1);     cout << sss << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     if (n == 1)       cout << 2;     else if (n == 2)       cout << 3;     else if (n == 3)       cout << 1;     else if (n == 4)       cout << 2;     else       cout << 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Mo = (int)1e9 + 7;   int i, j, m, n, p, k, sum, id, x, y, a[1000005], flag, ans;   int power(int x, int y) {     int sum = 1;     for (; y; y >>= 1) {       if (y & 1) sum = 1ll * x * sum % Mo;       x = 1ll * x * x % Mo;     }     return sum;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     id = 1;     for (i = 1; i <= m; ++i) {       scanf( %d%d , &x, &y);       if (y - x != 1 && y - x != k + 1) {         printf( 0 n );         return 0;       } else if (y - x != 1)         a[x]++, ++sum, id = x;     }     for (i = 1; i <= n; ++i) a[i] += a[i - 1];     for (i = id; i <= n && i + k + 1 <= n; ++i)       if (a[max(0, i - k - 1)] == 0)         ans = (ans + power(2, (i - 1 - max(0, i - k - 1) -                                (a[i - 1] - a[max(0, i - k - 1)])))) %               Mo;     if (!a[n]) ans = (ans + 1) % Mo;     printf( %d n , ans);   }