#include <bits/stdc++.h>
using namespace std;
int n, k;
int m1[100100], m2[100100];
int d[100100];
int safeMul(int a, int b) {
  unsigned long long res = a;
  res *= b;
  res %= 1000000007;
  return res;
}
int safePow(int a, int b) {
  int res = 1, x = a;
  for (; b > 0; b >>= 1) {
    if (b & 1) {
      res = safeMul(res, x);
    }
    x = safeMul(x, x);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  int z1 = safePow(k, 1000000007 - 2);
  int z2 = safePow(safeMul(2, k), 1000000007 - 2);
  for (int i = 0; i < n; ++i) {
    cin >> m1[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> m2[i];
  }
  d[n] = 0;
  for (int i = n - 1; i >= 0; --i) {
    if (m1[i] != 0 && m2[i] != 0) {
      if (m1[i] == m2[i]) {
        d[i] = d[i + 1];
      } else {
        d[i] = (m1[i] > m2[i]);
      }
    } else {
      if (m1[i] == 0 && m2[i] == 0) {
        d[i] = (safeMul(k - 1, z2) + safeMul(d[i + 1], z1)) % 1000000007;
      } else if (m1[i] == 0) {
        d[i] = (safeMul(d[i + 1], z1) + safeMul(k - m2[i], z1)) % 1000000007;
      } else {
        d[i] = (safeMul(d[i + 1], z1) + safeMul(m1[i] - 1, z1)) % 1000000007;
      }
    }
  }
  cout << d[0];
  return 0;
}
