import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;


immutable int MOD = 10^^9+7;

long powmod(long a, long x, long m) {
    a %= m;
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];
    auto A = readln.split.map!(to!int).array;
    auto B = readln.split.map!(to!int).array;

    assert(N.iota.map!(i => A[i] == B[i]).all);

    auto dp = new long[][](N+1, K+1);
    foreach (i; 0..N+1) fill(dp[i], 0);
    //fill(dp[0], 1);
    dp[0][0] = 1;

    foreach (i; 1..N+1) {
        foreach (j; 0..K+1) {
            foreach (k; 0..j+1) {
                dp[i][j] += dp[i-1][k] * powmod(A[i-1], j-k, MOD) % MOD;
                dp[i][j] %= MOD;
            }
        }
    }

    //dp.writeln;
    dp[N][K].writeln;
}
