MOD = 1000000007

N, M = map(int, input().split())
S = [int(s) for s in input().split()]
T = [int(s) for s in input().split()]

m = [[0] * (M + 1) for _ in range(N + 1)]

for i in range(1, N + 1):
    for j in range(1, M + 1):
        if S[i-1] == T[j-1]:
            m[i][j] = m[i - 1][j] + m[i][j - 1] + 1
            m[i][j] %= MOD
        else:
            m[i][j] = m[i - 1][j] + m[i][j - 1] - m[i - 1][j - 1]
            m[i][j] %= MOD
print((m[N][M] + 1) % MOD) MOD = 1000000007 MOD 1000000007 N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M int(s) for s in input().split() for s in input().split() s input().split() ().split () input split for s in input().split() int(s) int s S = [int(s) for s in input().split()] S [int(s) for s in input().split()] int(s) for s in input().split() for s in input().split() s input().split() ().split () input split for s in input().split() int(s) int s T = [int(s) for s in input().split()] T [int(s) for s in input().split()] [0] * (M + 1) for _ in range(N + 1) for _ in range(N + 1) _ range(N + 1) range N + 1 N 1 for _ in range(N + 1) [0] * (M + 1) [0] 0 M + 1 M 1 m = [[0] * (M + 1) for _ in range(N + 1)] m [[0] * (M + 1) for _ in range(N + 1)] for i in range(1, N + 1):
    for j in range(1, M + 1):
        if S[i-1] == T[j-1]:
            m[i][j] = m[i - 1][j] + m[i][j - 1] + 1
            m[i][j] %= MOD
        else:
            m[i][j] = m[i - 1][j] + m[i][j - 1] - m[i - 1][j - 1]
            m[i][j] %= MOD i range(1, N + 1) range 1 N + 1 N 1 for j in range(1, M + 1):
        if S[i-1] == T[j-1]:
            m[i][j] = m[i - 1][j] + m[i][j - 1] + 1
            m[i][j] %= MOD
        else:
            m[i][j] = m[i - 1][j] + m[i][j - 1] - m[i - 1][j - 1]
            m[i][j] %= MOD j range(1, M + 1) range 1 M + 1 M 1 if S[i-1] == T[j-1]:
            m[i][j] = m[i - 1][j] + m[i][j - 1] + 1
            m[i][j] %= MOD
        else:
            m[i][j] = m[i - 1][j] + m[i][j - 1] - m[i - 1][j - 1]
            m[i][j] %= MOD S[i-1] == T[j-1] S[i-1] S i-1 i 1 T[j-1] T j-1 j 1 m[i][j] = m[i - 1][j] + m[i][j - 1] + 1 m[i][j] [i] m i j m[i - 1][j] + m[i][j - 1] + 1 m[i - 1][j] + m[i][j - 1] m[i - 1][j] [i - 1] m i - 1 i 1 j m[i][j - 1] [i] m i j - 1 j 1 1 m[i][j] %= MOD m[i][j] [i] m i j MOD m[i][j] = m[i - 1][j] + m[i][j - 1] - m[i - 1][j - 1] m[i][j] [i] m i j m[i - 1][j] + m[i][j - 1] - m[i - 1][j - 1] m[i - 1][j] + m[i][j - 1] m[i - 1][j] [i - 1] m i - 1 i 1 j m[i][j - 1] [i] m i j - 1 j 1 m[i - 1][j - 1] [i - 1] m i - 1 i 1 j - 1 j 1 m[i][j] %= MOD m[i][j] [i] m i j MOD print((m[N][M] + 1) % MOD) print (m[N][M] + 1) % MOD m[N][M] + 1 m[N][M] [N] m N M 1 MOD m = [[0] * (M + 1) for _ in range(N + 1)] [[0] * (M + 1) for _ in range(N + 1)] m MOD = 1000000007 1000000007 MOD M = map(int, input().split()) map(int, input().split()) M N, M = map(int, input().split()) map(int, input().split()) N S = [int(s) for s in input().split()] [int(s) for s in input().split()] S T = [int(s) for s in input().split()] [int(s) for s in input().split()] T
MOD = 1000000007

N, M = map(int, input().split())
S = [int(s) for s in input().split()]
T = [int(s) for s in input().split()]

m = [[0] * (M + 1) for _ in range(N + 1)]

for i in range(1, N + 1):
    for j in range(1, M + 1):
        if S[i-1] == T[j-1]:
            m[i][j] = m[i - 1][j] + m[i][j - 1] + 1
            m[i][j] %= MOD
        else:
            m[i][j] = m[i - 1][j] + m[i][j - 1] - m[i - 1][j - 1]
            m[i][j] %= MOD
print((m[N][M] + 1) % MOD)
