Ancient Egyptians are known to have used a large set of symbols <image> to write on the walls of the temples. Fafa and Fifa went to one of the temples and found two non-empty words S1 and S2 of equal lengths on the wall of temple written one below the other. Since this temple is very ancient, some symbols from the words were erased. The symbols in the set <image> have equal probability for being in the position of any erased symbol.

Fifa challenged Fafa to calculate the probability that S1 is lexicographically greater than S2. Can you help Fafa with this task?

You know that <image>, i. e. there were m distinct characters in Egyptians' alphabet, in this problem these characters are denoted by integers from 1 to m in alphabet order. A word x is lexicographically greater than a word y of the same length, if the words are same up to some position, and then the word x has a larger character, than the word y.

We can prove that the probability equals to some fraction <image>, where P and Q are coprime integers, and <image>. Print as the answer the value <image>, i. e. such a non-negative integer less than 109 + 7, such that <image>, where <image> means that a and b give the same remainders when divided by m.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the length of each of the two words and the size of the alphabet <image>, respectively.

The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ m) — the symbols of S1. If ai = 0, then the symbol at position i was erased.

The third line contains n integers representing S2 with the same format as S1.

Output

Print the value <image>, where P and Q are coprime and <image> is the answer to the problem.

Examples

Input

1 2
0
1


Output

500000004


Input

1 2
1
0


Output

0


Input

7 26
0 15 12 9 13 0 14
11 1 0 13 15 12 0


Output

230769233

Note

In the first sample, the first word can be converted into (1) or (2). The second option is the only one that will make it lexicographically larger than the second word. So, the answer to the problem will be <image>, that is 500000004, because <image>.

In the second example, there is no replacement for the zero in the second word that will make the first one lexicographically larger. So, the answer to the problem is <image>, that is 0.
'''input
1 2 3
4 5
6 7 8
45 9
'''

import sys
pow2 = pow              # for modular expo pow2(base, n, mod)
from math import *
from time import time
from collections import defaultdict
from bisect import bisect_right, bisect_left
from string import ascii_lowercase as lcs
from string import ascii_uppercase as ucs
from fractions import Fraction, gcd
from decimal import Decimal, getcontext
from itertools import product, permutations, combinations
#getcontext().prec = 500
#sys.setrecursionlimit(30000)

# What doesn't challenge you, makes you weaker.

mod = 10**9 + 7
INF = sys.maxint

raw_input = lambda: sys.stdin.readline().rstrip()
die = lambda : exit(0)
flush= lambda : sys.stdout.flush()

r_s = lambda: raw_input().strip()                   #read str
r_ss = lambda: raw_input().split()          #read stringss
r_i = lambda: int(raw_input())              #read int
r_is = lambda: map(int, raw_input().split())#read ints
r_f = lambda: float(raw_input())            #read float
r_fs = lambda: map(Decimal, raw_input().split()) #read floats

# For effieciently taking lots of queries with each query in a separate line
# having integer values separated by space. A 2d list is made with each row
# corresponding to line. Each row is a list with all the values.
# Use this for fast I/O by taking all input in one go.
r_qs = lambda: map(lambda s:map(int, s.split(' ')), sys.stdin.readlines())

'''-------------------------------------------------------------------'''

# Call it as dbg(varName=varName)
def dbg(**kwargs):
    print "Value of '" + kwargs.keys()[0] + "' is", kwargs[kwargs.keys()[0]]


def main():
    # for _ in xrange(r_i()):
    def invmod(n, p):
        return pow2(n, p-2, p)

    n, m = r_is()
    s1 = r_is()
    s2 = r_is()
    ans = 0
    mod = 10**9+7
    t = invmod(m, mod)
    t2 = invmod(2*m, mod)
    prev = 1
    for i in range(n):
        if s1[i]==0 and s2[i]==0:
            ans = (ans + (m-1)*t2*prev)%mod
            prev = (prev*t)%mod
        elif s1[i]!=0 and s2[i]!=0:
            if s1[i]>s2[i]:
                ans = (ans+prev)%mod
            if s1[i]!=s2[i]:
                break
        elif s1[i]==0:
            ans = (ans + (m-s2[i])*t*prev)%mod
            prev = (prev*t)%mod
        elif s2[i]==0:
            ans = (ans + (s1[i]-1)*t*prev)%mod
            prev = (prev*t)%mod
    print ans

if __name__ == '__main__':
    local = True
    # local = False
    if local:
        try:
            sys.stdin = open('input.txt')
            print 'Running at local.'
            for i in range(r_i()):
                main()
        except IOError:
            main()
    else:
        main()


