malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename A>   ostream &operator<<(ostream &cout, vector<A> const &v);   template <typename A, typename B>   ostream &operator<<(ostream &cout, pair<A, B> const &p) {     return cout <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename A>   ostream &operator<<(ostream &cout, vector<A> const &v) {     cout <<  [ ;     for (int i = 0; i < v.size(); i++) {       if (i) cout <<  ,  ;       cout << v[i];     }     return cout <<  ] ;   }   template <typename A, typename B>   istream &operator>>(istream &cin, pair<A, B> &p) {     cin >> p.first;     return cin >> p.second;   }   mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());   void usaco(string filename) {     freopen((filename +  .in ).c_str(),  r , stdin);     freopen((filename +  .out ).c_str(),  w , stdout);   }   const long double pi = 3.14159265358979323846;   const long long mod = 1000000007;   struct dsu {     int n;     vector<int> sizes, marks;     vector<vector<int>> graph;     void init(int rn) {       n = rn;       sizes = vector<int>(n);       fill(sizes.begin(), sizes.end(), 1);       marks = vector<int>(n);       for (int i = 0; i < n; i++) marks[i] = i;       graph = vector<vector<int>>(n);     }     void mark(int m, int node) {       if (marks[node] == m) return;       marks[node] = m;       for (int i : graph[node]) mark(m, i);     }     bool merge(int a, int b) {       if (marks[a] == marks[b]) return 0;       graph[a].push_back(b);       graph[b].push_back(a);       if (sizes[marks[a]] > sizes[marks[b]]) swap(a, b);       sizes[marks[b]] += sizes[marks[a]];       sizes[marks[a]] = 0;       mark(marks[b], a);       return 1;     }     int find(int n) { return marks[n]; }   };   long long n, m, k, q, l, r, x, y, z;   const long long template_array_size = 1e6 + 6884;   long long a[template_array_size];   long long b[template_array_size];   long long c[template_array_size];   string second, t;   long long ans = 0;   pair<long long, pair<long long, long long>> vals[200005];   long long root[100005];   bool cnt[100005];   dsu d;   void solve(int tc = 0) {     cin >> m >> n;     for (long long i = 0; i < m; i++) cin >> a[i];     for (long long i = 0; i < n; i++) cin >> b[i];     long long ans = 0, second = 0;     for (long long i = 0; i < m; i++) {       cin >> x;       for (long long j = 0; j < x; j++) {         cin >> y;         --y;         ans += a[i] + b[y];         vals[second++] = make_pair(-a[i] - b[y], make_pair(i, y));       }     }     sort(vals, vals + second);     memset(cnt, 0, sizeof(cnt));     d.init(n);     for (long long i = 0; i < second; i++) {       long long a = vals[i].second.first, b = vals[i].second.second,                 val = vals[i].first;       if (!cnt[a]) {         cnt[a] = 1;         root[a] = b;         ans += val;       } else {         if (d.merge(root[a], b)) ans += val;       }     }     cout << ans <<   n ;   }   int main() {     { ios_base::sync_with_stdio(false); }     { cin.tie(NULL); }     cout << setprecision(12) << fixed;     int tc = 1;     for (int t = 0; t < tc; t++) solve(t);   }
#include <bits/stdc++.h>   using namespace std;   FILE *in;   FILE *out;   const int MAX = 1048576;   const int TREE = 2097152;   const int MOD = 1000000007;   int n;   int a[MAX];   int tree[TREE];   bool seen[MAX];   int query(int idx1, int idx2) {     idx1 += (TREE >> 1);     idx2 += (TREE >> 1);     if (idx1 == idx2) return tree[idx1];     int ret = 0;     ret += tree[idx1];     if (ret >= MOD) ret -= MOD;     int flag1 = !(idx1 & 1);     idx1 >>= 1;     ret += tree[idx2];     if (ret >= MOD) ret -= MOD;     int flag2 = (idx2 & 1);     idx2 >>= 1;     while (idx1 != idx2) {       if (flag1) {         ret += tree[(idx1 << 1) + 1];         if (ret >= MOD) ret -= MOD;       }       if (flag2) {         ret += tree[(idx2 << 1) + 0];         if (ret >= MOD) ret -= MOD;       }       flag1 = !(idx1 & 1);       idx1 >>= 1;       flag2 = (idx2 & 1);       idx2 >>= 1;     }     return ret;   }   void update(int idx, int val) {     idx += (TREE >> 1);     while (idx) {       tree[idx] += val;       if (tree[idx] >= MOD) tree[idx] -= MOD;       idx >>= 1;     }   }   int main(void) {     in = stdin;     out = stdout;     fscanf(in,  %d , &n);     for (int i = 0; i < n; i++) fscanf(in,  %d , &a[i]);     int ans = 0;     memset(tree, 0, sizeof(tree));     for (int i = n - 1; i >= 0; i--) {       int cur = ((long long)a[i] * (query(a[i], MAX - 1) + 1)) % MOD;       ans += cur;       if (ans >= MOD) ans -= MOD;       int sub = query(a[i], a[i]);       ans -= sub;       if (ans < 0) ans += MOD;       update(a[i], (cur - sub + MOD) % MOD);     }     fprintf(out,  %d n , ans);     return 0;   }
#include <bits/stdc++.h>   int main() {     int cnt = 0, f[4], i, j, x[200], y[200], n;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d %d , &x[i], &y[i]);     }     for (i = 0; i < n; i++) {       f[1] = 0;       f[2] = 0;       f[3] = 0;       f[0] = 0;       for (j = 0; j < n; j++) {         if (j != i) {           if (x[i] == x[j] && y[i] < y[j]) f[0] = 1;           if (x[i] == x[j] && y[i] > y[j]) f[1] = 1;         }       }       for (j = 0; j < n; j++) {         if (j != i) {           if (y[i] == y[j] && x[i] < x[j]) f[2] = 1;           if (y[i] == y[j] && x[i] > x[j]) f[3] = 1;         }       }       if (f[0] == 1 && f[1] == 1 && f[2] == 1 && f[3] == 1) {         cnt++;       }     }     printf( %d , cnt);   }
#include <bits/stdc++.h>   using namespace std;   template <class A, class B>   ostream& operator<<(ostream& o, pair<A, B>& p) {     return o <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& o, const vector<T>& v) {     o <<  { ;     for (typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)       o << *it <<  ,  ;     return o <<  } ;   }   struct debugger {     ostream& out;     bool first;     void start() { first = true; }     debugger(ostream& out) : out(out) { start(); }     void nl() {       out << endl;       start();     }     template <class T>     debugger& operator,(T& v) {       if (first)         first = false;       else         out <<  ,  ;       out << v;       return *this;     }     template <class T>     debugger& operator,(pair<T*, int> arr) {       out <<  { ;       for (typeof((arr.second) - 1) i = (0); i <= ((arr.second) - 1); i++) {         out << arr.first[i] <<  ,  ;       }       out <<  } ;       return *this;     }   } dbg(cerr);   long long pyra(long long n) { return (n + 1) * (n + 1); }   long long incr(long long n) { return (n * (n + 1)) / 2; }   long long f(long long x, long long y, long long step, long long n) {     long long ret = 2 * pyra(step) - (2 * step + 1);     if (x + step > n) {       ret -= pyra(x + step - n - 1);     }     if (y + step > n) {       ret -= pyra(y + step - n - 1);     }     if (x - step < 1) {       ret -= pyra(1 - (x - step) - 1);     }     if (y - step < 1) {       ret -= pyra(1 - (y - step) - 1);     }     if (step - 1 - (n - x) - (n - y) > 0) {       ret += incr(step - 1 - (n - x) - (n - y));     }     if (step - 1 - (n - x) - (y - 1) > 0) {       ret += incr(step - 1 - (n - x) - (y - 1));     }     if (step - 1 - (x - 1) - (y - 1) > 0) {       ret += incr(step - 1 - (x - 1) - (y - 1));     }     if (step - 1 - (x - 1) - (n - y) > 0) {       ret += incr(step - 1 - (x - 1) - (n - y));     }     return ret;   }   int main() {     long long n, x, y, c, lo, hi;     cin >> n >> x >> y >> c;     lo = 0;     hi = 1e9 + 10;     {}     while (lo < hi) {       long long mid = (lo + hi) / 2;       if (f(x, y, mid, n) < c)         lo = mid + 1;       else         hi = mid;     }     cout << lo << endl;     return 0;   }
#include <bits/stdc++.h>   int minDig(uint64_t n) {     int k = n % 10, min = k;     n /= 10;     while (n != 0) {       k = n % 10;       if (k <= min) min = k;       n /= 10;     }     return min;   }   int maxDig(uint64_t n) {     int k = n % 10, max = k;     n /= 10;     while (n != 0) {       k = n % 10;       if (k >= max) max = k;       n /= 10;     }     return max;   }   int searchzero(uint64_t n) {     while (n != 0) {       if (n % 10 == 0) return 1;       n /= 10;     }     return 0;   }   int main(void) {     int t;     uint64_t a, k;     scanf( %d , &t);     while (t--) {       scanf( %llu %llu , &a, &k);       for (uint64_t i = 1; i < k; i++) {         a += (minDig(a) * maxDig(a));         if (searchzero(a) == 1) break;       }       printf( %llu n , a);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     std::cerr << name <<   :   << arg1 << endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     std::cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   bool findfxn(string a, string b) {     size_t found = a.find(b);     if (found != string::npos)       return 1;     else       return 0;   }   long long int power(long long int a, long long int b) {     if (b == 0) {       return 1;     } else if (b % 2 == 0) {       return power(a * a, b / 2);     } else {       return a * power(a * a, (b - 1) / 2);     }   }   void solve() {     long long int n, p, k, z = 0;     cin >> n >> p >> k;     int a[n];     int sum[n + 10];     for (int i = 0; i < (n); i++) {       cin >> a[i];     }     sort(a, a + n);     int i = 0;     for (i = 0; i < n; i++) {       if (i > 1) {         sum[i] = sum[i - 2] + a[i];       } else         sum[i] = a[i];       if (sum[i] > p) {         break;       }     }     cout << i << endl;     return;   }   signed main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t = 1;     cin >> t;     while (t--) solve();     return 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[10005][6], n, m;   map<int, int> f[10005];   int power(int x, int y) {     int s = 1;     for (; y; y /= 2, x = 1ll * x * x % 1000000007)       if (y & 1) s = 1ll * s * x % 1000000007;     return s;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 2; i <= m; i++)       for (int j = 1; j < i; j++) {         a[i][++a[i][0]] = j;         f[i][j] = f[j][i] = 1000000007 - 1;         f[i][i]++;         f[j][j]++;       }     for (int i = m + 1; i <= n; i++) {       a[i][0] = m;       for (int j = 1; j <= m; j++) {         scanf( %d , &a[i][j]);         f[i][a[i][j]] = f[a[i][j]][i] = 1000000007 - 1;         f[i][i]++;         f[a[i][j]][a[i][j]]++;       }     }     int ans = 1;     for (int i = n; i > 1; i--) {       int t = power(f[i][i], 1000000007 - 2);       ans = 1ll * ans * f[i][i] % 1000000007;       for (int j = 1; j <= a[i][0]; j++)         for (int k = 1; k <= a[i][0]; k++)           (f[a[i][j]][a[i][k]] += 1000000007 - 1ll * f[a[i][j]][i] *                                                    f[i][a[i][k]] % 1000000007 *                                                    t % 1000000007) %= 1000000007;     }     printf( %d , ans);   }
#include<bits/stdc++.h>   #define L(i, j, k) for(int i = (j), i##E = k; i <= i##E; i++)    #define R(i, j, k) for(int i = (j), i##E = k; i >= i##E; i--)   #define mkp make_pair   #define pii pair<int, int>   #define ll long long   #define db double   #define sz(a) a.size()   #define x first   #define y second   #define vi vector<int>   using namespace std;   const int N = 1e4, M = 100, mod = 998244353;   int m;   struct Matrix {    int f[M][M];    Matrix (int x = 1) {     L(i, 1, m) L(j, 1, m) f[i][j] = (i == j ? x : 0);    }   } ;   Matrix operator * (Matrix aa, Matrix bb) {    Matrix res(0);    L(i, 1, m) L(j, 1, m) L(k, 1, m) (res.f[i][j] += (ll) aa.f[i][k] * bb.f[k][j] % mod) %= mod;    return res;   }   Matrix operator ^ (Matrix x, ll y) {    Matrix res(1);    for(; y; x = x * x, y >>= 1) if(y & 1) res = res * x;    return res;   }      int n, nousex, otp, s[N], tot, v[N], sv[N], ns;   ll a[N], p[N], mx, val, arr[N], sl[N], sr[N];   void calc(int l, int r) {    ll mx = 0;    p[l] = 0, tot = 0;    L(i, l + 1, r) {     sl[i] = (p[i - 1] + (a[i] < 0 ? -1 : 1)), p[i] = p[i - 1] + a[i], sr[i] = p[i];     if(sl[i] > sr[i]) swap(sl[i], sr[i]);     mx = max(mx, p[i]);     }    if(val != mx) return;    sl[l + 1] = 0;    L(i, l + 1, r)      arr[++tot] = sl[i] - 1, arr[++tot] = sl[i], arr[++tot] = sl[i] + 1,      arr[++tot] = sr[i] - 1, arr[++tot] = sr[i], arr[++tot] = sr[i] + 1;    sort(arr + 1, arr + tot + 1), tot = unique(arr + 1, arr + tot + 1) - arr - 1;    m = r - l;    memset(v, 0, sizeof(v));    v[1] = 1, arr[0] = -1;    L(k, 1, tot) if(arr[k] <= mx) {     Matrix G(0);     L(i, l + 1, r) if(sl[i] <= arr[k - 1] + 1 && arr[k] <= sr[i]) {      L(j, l + 1, i - 1) G.f[j - l][i - l] = 1;      if(a[i] > 0) G.f[i - l][i - l] = 1;     }     G = G ^ (arr[k] - arr[k - 1]);     L(i, 1, m) L(j, 1, m) (sv[j] += (ll) v[i] * G.f[i][j] % mod) %= mod;     L(i, 1, m) v[i] = sv[i], sv[i] = 0;    }    L(i, 1, m) (ns += v[i]) %= mod;   }   void Main() {    cin >> n >> nousex;    L(i, 1, n) {     cin >> a[i];     if(a[i]) a[++otp] = a[i];    }    n = otp, otp = 0;    L(i, 1, n)      if((a[i] > 0 && a[i - 1] > 0) || (a[i] < 0 && a[i - 1] < 0)) a[otp] += a[i];     else a[++otp] = a[i];    n = otp;    L(i, 1, n) mx += a[i], val = max(val, mx), mx = max(mx, 0ll);    cout << val + 1 <<    ;    if(val == 0) {     int sum = 1;     L(i, 1, n) (sum += abs(a[i]) % mod) %= mod;     return cout << sum <<   n , void();    }    int top = 0;    mx = 0;    L(i, 1, n) {     mx += a[i];     if(mx < 0) s[++top] = i, mx = 0;    }    s[++top] = n + 1;    L(i, 1, top) calc(s[i - 1], s[i] - 1);    cout << ns <<   n ;   }   int main() {    ios::sync_with_stdio(false);    cin.tie(0); cout.tie(0);    Main();    return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Point {     double x, y;     Point() {}     Point(double a, double b) {       x = a;       y = b;     }     Point operator+(Point who) { return {x + who.x, y + who.y}; }     Point operator-(Point who) { return {x - who.x, y - who.y}; }     Point operator/(double val) { return {x / val, y / val}; }     Point operator*(double val) { return {x * val, y * val}; }     bool operator==(const Point who) const {       return max(abs(x - who.x), abs(y - who.y)) <= 1e-7;     }     bool operator<(const Point who) const {       if (*this == who) return false;       return make_pair(x, y) < make_pair(who.x, who.y);     }   };   struct Line {     double a, b, c;     Line(){};     Line(double _a, double _b, double _c) {       a = _a;       b = _b;       c = _c;     }     Line(Point A, Point B) {       a = B.y - A.y;       b = A.x - B.x;       c = -(A.x * a + B.x * b);     }     Line operator||(Point A) { return {a, b, -(a * A.x + b * A.y)}; }     Line perp() {       Line ans = {a, b, c};       swap(ans.a, ans.b);       ans.a *= -1;       return ans;     }     Point intersect(Line who) {       double up_x = who.c * b - c * who.b;       double up_y = c * who.a - a * who.c;       double down = a * who.b - b * who.a;       return {up_x / down, up_y / down};     }     bool is_parallel(Line who) { return abs(a * who.b - b * who.a) <= 1e-7; }   };   int n, i, j, ans;   Point P[2017], mid, Origin(0.00, 0.00);   bool used[2017];   Line aux;   Point _P[2017], _mid;   map<Point, int> M;   vector<Line> ant;   void remove_sym() {     int i, j;     for (i = 1; i <= n; i++) {       for (j = i; j <= n; j++) {         if (used[j]) continue;         if (P[i] + P[j] == mid * 2) {           used[i] = used[j] = true;           break;         }       }     }   }   Point get_proj(Point A, Line L) {     Line aux = (L.perp() || A);     return aux.intersect(L);   }   bool check(Line act) {     int i;     int rm = 0;     Point sym;     M.clear();     _mid = get_proj(mid, act);     for (i = 1; i <= n; i++) {       _P[i] = get_proj(P[i], act);       if (_P[i] == _mid) {         rm++;         continue;       }       sym = _mid * 2 - _P[i];       if (M[sym] > 0) {         rm += 2;         M[sym]--;         continue;       }       M[_P[i]]++;     }     if (rm != n) return false;     return true;   }   int main() {     scanf( %d , &n);     mid = {0, 0};     for (i = 1; i <= n; i++) {       scanf( %lf%lf , &P[i].x, &P[i].y);       mid = mid + P[i];     }     mid = mid / n;     remove_sym();     for (i = 1; used[i] && i <= n; i++)       ;     if (i == n + 1) {       printf( -1 );       return 0;     }     for (j = i; j <= n; j++) {       if (used[j]) continue;       aux = Line(mid, (P[i] + P[j]) / 2);       aux = (aux.perp() || Origin);       bool ok = true;       for (auto e : ant) {         if (e.is_parallel(aux)) {           ok = false;           break;         }       }       if (!ok) continue;       ant.push_back(aux);       if (check(aux)) ans++;     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long nInf = -1000000000;   const long long pInf = 1000000000;   const long long mod = 1000000007;   const int MAXN = 3010;   void getdata();   void preproc();   void solve();   vector<int> g[MAXN];   bool gr[MAXN][MAXN];   int n, m;   int main() {     int t = 1;     for (int i = 0; i < t; i++) {       getdata();       preproc();       solve();     }     return 0;   }   void getdata() {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d %d , &x, &y);       x--;       y--;       g[x].push_back(y);       gr[x][y] = true;     }   }   void preproc() {}   void solve() {     long long res = 0;     for (int a = 0; a < n; a++) {       for (int c = 0; c < n; c++) {         if (a == c) continue;         int count = 0;         for (int i = 0; i < (int)g[a].size(); i++) {           int b = g[a][i];           if (gr[b][c]) {             count++;           }         }         res += count * (count - 1) / 2;       }     }     printf( %I64d n , res);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100, mod = 1e9 + 7;   long long a[N], k, n;   struct mat {     int d[N][N];     mat() { memset(d, 0, sizeof d); }     mat operator*(const mat& o) {       mat p;       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           for (int k = 0; k < n; k++) {             p.d[i][j] = (p.d[i][j] + 1ll * d[i][k] * o.d[k][j]) % mod;           }         }       }       return p;     }     mat pw(long long k) {       mat result;       for (int i = 0; i < n; i++) result.d[i][i] = 1;       mat s = *this;       while (k) {         if (k & 1) {           result = result * s;         }         s = s * s;         k >>= 1;       }       return result;     }   };   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     mat adj;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         long long x = a[i] ^ a[j];         int cnt = 0;         while (x) {           if (x & 1) cnt++;           x >>= 1;         }         if (cnt % 3 == 0) adj.d[i][j] = 1;       }     }     mat r = adj.pw(k - 1);     int ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         ans = (ans + r.d[i][j]) % mod;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int op(int y) {     if (y < 0) y = -y;     return y;   }   int n, pos, l, r;   int main() {     cin >> n >> pos >> l >> r;     if (l == 1 && r == n) {       cout << 0;     }     if (l == 1 && r != n) {       cout << op(r - pos) + 1;     }     if (l != 1 && r == n) {       cout << op(l - pos) + 1;     }     if (l != 1 && r != n) {       if (op(r - pos) < op(l - pos))         cout << r - l + op(r - pos) + 2;       else         cout << r - l + op(l - pos) + 2;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mn[1111];   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < m; i++) {       mn[i] = 1e9;     }     for (int i = 0; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       --x;       mn[x] = min(mn[x], y);     }     int s = 0;     for (int i = 0; i < m; i++) {       s += mn[i];     }     cout << min(s, k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const long long int MOD = 1e9 + 7;   const int N = 1e6 + 6;   int sum[N][3], prv[N][3];   int main() {     int n;     string s;     cin >> n >> s;     s =  *  + s;     prv[0][0] = prv[0][1] = -1;     for (int i = 1; i <= n; i++) {       sum[i][0] = sum[i - 1][0];       sum[i][1] = sum[i - 1][1];       prv[i][0] = prv[i - 1][0];       prv[i][1] = prv[i - 1][1];       if (s[i] ==  1 ) {         sum[i][1]++;         prv[i][1] = i;       }       if (s[i] ==  0 ) {         sum[i][0]++;         prv[i][0] = i;       }     }     for (int len = 1; len <= n; len++) {       int now = 1;       int cnt = 0;       while (now + len - 1 <= n) {         if (sum[now + len - 1][1] - sum[now - 1][1] == 0 ||             sum[now + len - 1][0] - sum[now - 1][0] == 0) {           cnt++;           now += len;           continue;         }         now = min(prv[now + len - 1][0], prv[now + len - 1][1]) + 1;       }       cout << cnt <<    ;     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > anom;   long long int fact[200005];   long long int invfact[200005];   long long int MOD = 1000000007;   long long int dp[2005][25];   long long int invmod(long long int i) {     long long int ans = 1;     long long int mult = i;     long long int exp = MOD - 2;     while (exp > 0) {       if (exp % 2 == 1) {         ans = (ans * mult) % MOD;       }       mult = (mult * mult) % MOD;       exp /= 2;     }     return ans;   }   void precomp() {     fact[0] = 1;     invfact[0] = 1;     for (long long int i = 1; i < 200005; i++) {       fact[i] = (fact[i - 1] * i) % MOD;       invfact[i] = (invfact[i - 1] * invmod(i)) % MOD;     }   }   long long int comb(int a, int b) {     long long int ans = (fact[a] * invfact[b]) % MOD;     ans = (ans * invfact[a - b]) % MOD;     return ans;   }   long long int paths(int a, int b, int c, int d) {     if (a <= c && b <= d) {       return comb(c - a + d - b, c - a);     }     return 0;   }   int main() {     precomp();     int n, m, k, s;     cin >> n >> m >> k >> s;     if (k == 0) {       cout << s << endl;       return 0;     }     int limred = ceil(log2(s)) + 1;     int a, b;     for (int i = 0; i < k; i++) {       cin >> a >> b;       anom.push_back({a, b});     }     sort(anom.begin(), anom.end());     bool beginanom = true;     if (k > 0 && anom[k] != make_pair(1, 1)) {       anom.push_back({1, 1});       beginanom = false;       k++;     }     sort(anom.begin(), anom.end());     for (int i = k - 1; i >= 0; i--) {       dp[i][0] = paths(anom[i].first, anom[i].second, n, m);       for (int j = i + 1; j < k; j++) {         dp[i][0] = (dp[i][0] -                     (dp[j][0] * paths(anom[i].first, anom[i].second,                                       anom[j].first, anom[j].second)) %                         MOD +                     MOD) %                    MOD;       }     }     for (int i = 1; i <= limred; i++) {       for (int j = k - 1; j >= 0; j--) {         dp[j][i] = paths(anom[j].first, anom[j].second, n, m);         for (int p = j + 1; p < k; p++) {           dp[j][i] = (dp[j][i] -                       (dp[p][i] * paths(anom[j].first, anom[j].second,                                         anom[p].first, anom[p].second)) %                           MOD +                       MOD) %                      MOD;         }         for (int p = 0; p < i; p++) {           dp[j][i] = (dp[j][i] - dp[j][p] + MOD) % MOD;         }       }     }     int prevs;     long long int expsum = 0;     long long int numways = 0;     for (int i = 0; i <= limred; i++) {       prevs = s;       s = ceil(s / 2.0);       if (beginanom) {         expsum = (expsum + (s * dp[0][i]) % MOD) % MOD;       } else {         expsum = (expsum + (prevs * dp[0][i]) % MOD) % MOD;       }       numways = (numways + dp[0][i]) % MOD;     }     long long int leftways = paths(1, 1, n, m);     leftways = (leftways - numways + MOD) % MOD;     expsum = (expsum + leftways) % MOD;     long long int ans = (expsum * invmod(comb(n + m - 2, n - 1))) % MOD;     cout << ans << endl;   }