func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const double eps = 1e-10;   const int INF = 0x3f3f3f3f;   const long long INFLL = 0x3f3f3f3f3f3f3f3fll;   const int MAXN = 2e5 + 5;   const int mod = 1e9 + 7;   int a[MAXN], b[MAXN];   long long fastpow(long long a, int n) {     long long base = a, ret = 1;     while (n) {       if (n & 1) ret = ret * base % MOD;       base = base * base % MOD;       n >>= 1;     }     return ret;   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     long long prob = 1, ans = 0;     for (int i = 1; i <= n; i++) {       if (a[i] == 0) {         if (b[i] == 0)           ans = (ans + prob * (1 - fastpow(m, MOD - 2) + MOD) % MOD *                            fastpow(2, MOD - 2) % MOD) %                 MOD;         else           ans = (ans + prob * (m - b[i]) % MOD * fastpow(m, MOD - 2) % MOD) % MOD;         prob = prob * fastpow(m, MOD - 2) % MOD;       } else {         if (b[i] == 0) {           ans = (ans + prob * (a[i] - 1) % MOD * fastpow(m, MOD - 2) % MOD) % MOD;           prob = prob * fastpow(m, MOD - 2) % MOD;         } else {           if (b[i] > a[i])             break;           else if (b[i] < a[i]) {             ans = (ans + prob) % MOD;             break;           }         }       }     }     printf( %lld n , ans);     return 0;   }   