func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 100010;   const int mod = 1e9 + 7;   const int M = 2010;   pair<int, int> p[M];   int n, m, k, s, x, y, cnt;   int fac[2 * N], inv[2 * N], K[30], f[M][30];   bool pd1, pd2;   int Pow(int a, int b) {     if (b == 0) return 1;     int ret = Pow(a, b / 2);     ret = 1LL * ret * ret % mod;     if (b & 1) ret = 1LL * ret * a % mod;     return ret;   }   int com(int n, int m) {     if (m > n) return 0;     return 1LL * fac[n] * inv[m] % mod * inv[n - m] % mod;   }   int cal(int i, int j) {     if (p[i].first > p[j].first || p[i].second > p[j].second) return 0;     return com(p[j].first - p[i].first + p[j].second - p[i].second,                p[j].first - p[i].first);   }   int main() {     fac[0] = inv[0] = 1;     for (int i = 1; i < 2 * N; i++) fac[i] = 1LL * fac[i - 1] * i % mod;     for (int i = 1; i < 2 * N; i++) inv[i] = Pow(fac[i], mod - 2);     scanf( %d%d%d%d , &n, &m, &k, &s);     for (int i = 0; i < k; i++) {       scanf( %d%d , &x, &y);       if (x == 1 && y == 1) pd1 = true;       if (x == n && y == m) pd2 = true;       p[i] = make_pair(x, y);     }     if (n == 1 && m == 1) {       if (pd1)         printf( %d n , (s + 1) / 2);       else         printf( %d n , s);       return 0;     }     p[k] = make_pair(1, 1);     p[k + 1] = make_pair(n, m);     sort(p, p + k + 2);     if (pd1) s = (s + 1) / 2;     for (int tmp = s; tmp != 1; tmp = (tmp + 1) / 2) K[cnt++] = tmp;     K[cnt++] = 1;     int tot = 0;     for (int i = 0; i < k + 2; i++)       if (i == 0 || p[i] != p[i - 1]) p[tot++] = p[i];     f[0][0] = 1;     for (int i = 1; i < tot - 1; i++) {       int tmp = 0;       for (int j = 1; j < cnt; j++) {         f[i][j] = com(p[i].first - 1 + p[i].second - 1, p[i].first - 1);         f[i][j] = (f[i][j] - tmp) % mod;         for (int q = 0; q < i; q++)           f[i][j] = (f[i][j] - 1LL * f[q][j] * cal(q, i) % mod) % mod;         tmp = (tmp + f[i][j]) % mod;       }     }     if (!pd2) {       int tmp = 0;       for (int j = 0; j < cnt; j++) {         f[tot - 1][j] = com(p[tot - 1].first - 1 + p[tot - 1].second - 1,                             p[tot - 1].first - 1);         f[tot - 1][j] = (f[tot - 1][j] - tmp) % mod;         for (int q = 0; q < tot - 1; q++)           f[tot - 1][j] =               (f[tot - 1][j] - 1LL * f[q][j + 1] * cal(q, tot - 1) % mod) % mod;         tmp = (tmp + f[tot - 1][j]) % mod;       }     } else {       int tmp = 0;       for (int j = 1; j < cnt - 1; j++) {         f[tot - 1][j] = com(p[tot - 1].first - 1 + p[tot - 1].second - 1,                             p[tot - 1].first - 1);         f[tot - 1][j] = (f[tot - 1][j] - tmp) % mod;         for (int q = 0; q < tot - 1; q++)           f[tot - 1][j] =               (f[tot - 1][j] - 1LL * f[q][j] * cal(q, tot - 1) % mod) % mod;         tmp = (tmp + f[tot - 1][j]) % mod;       }       f[tot - 1][cnt - 1] = (com(p[tot - 1].first - 1 + p[tot - 1].second - 1,                                  p[tot - 1].first - 1) -                              tmp) %                             mod;     }     int ans = 0;     for (int i = 0; i < cnt; i++)       ans = (ans + 1LL * K[i] * f[tot - 1][i] % mod) % mod;     ans = 1LL * ans * Pow(com(n - 1 + m - 1, n - 1), mod - 2) % mod;     ans = (ans + mod) % mod;     printf( %d n , ans);     return 0;   }   