n,m = map(int,input().split())
s = list(map(int,input().split()))
t = list(map(int,input().split()))
dp0 = [[0 for i in range(m+2)] for j in range(n+2)]
dp1 = [[0 for i in range(m+2)] for j in range(n+2)]
dp0[0][0] = 1
mod = 10**9+7
for i in range(n+1):
    for j in range(m+1):
        dp0[i+1][j] = (dp0[i+1][j]+dp0[i][j])%mod
        dp1[i][j] = (dp1[i][j]+dp0[i][j])%mod
        dp1[i][j+1] = (dp1[i][j+1]+dp1[i][j])%mod
        if i != n and j != m and s[i] == t[j]:
            dp0[i+1][j+1] = (dp1[i+1][j+1]+dp1[i][j])%mod
print(dp1[n][m]) n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m s = list(map(int,input().split())) s list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split t = list(map(int,input().split())) t list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split [0 for i in range(m+2)] for j in range(n+2) for j in range(n+2) j range(n+2) range n+2 n 2 for j in range(n+2) [0 for i in range(m+2)] dp0 = [[0 for i in range(m+2)] for j in range(n+2)] dp0 [[0 for i in range(m+2)] for j in range(n+2)] [0 for i in range(m+2)] for j in range(n+2) for j in range(n+2) j range(n+2) range n+2 n 2 for j in range(n+2) [0 for i in range(m+2)] dp1 = [[0 for i in range(m+2)] for j in range(n+2)] dp1 [[0 for i in range(m+2)] for j in range(n+2)] dp0[0][0] = 1 dp0[0][0] [0] dp0 0 0 1 mod = 10**9+7 mod 10**9+7 10**9 10 9 7 for i in range(n+1):
    for j in range(m+1):
        dp0[i+1][j] = (dp0[i+1][j]+dp0[i][j])%mod
        dp1[i][j] = (dp1[i][j]+dp0[i][j])%mod
        dp1[i][j+1] = (dp1[i][j+1]+dp1[i][j])%mod
        if i != n and j != m and s[i] == t[j]:
            dp0[i+1][j+1] = (dp1[i+1][j+1]+dp1[i][j])%mod i range(n+1) range n+1 n 1 for j in range(m+1):
        dp0[i+1][j] = (dp0[i+1][j]+dp0[i][j])%mod
        dp1[i][j] = (dp1[i][j]+dp0[i][j])%mod
        dp1[i][j+1] = (dp1[i][j+1]+dp1[i][j])%mod
        if i != n and j != m and s[i] == t[j]:
            dp0[i+1][j+1] = (dp1[i+1][j+1]+dp1[i][j])%mod j range(m+1) range m+1 m 1 dp0[i+1][j] = (dp0[i+1][j]+dp0[i][j])%mod dp0[i+1][j] [i+1] dp0 i+1 i 1 j (dp0[i+1][j]+dp0[i][j])%mod dp0[i+1][j]+dp0[i][j] dp0[i+1][j] [i+1] dp0 i+1 i 1 j dp0[i][j] [i] dp0 i j mod dp1[i][j] = (dp1[i][j]+dp0[i][j])%mod dp1[i][j] [i] dp1 i j (dp1[i][j]+dp0[i][j])%mod dp1[i][j]+dp0[i][j] dp1[i][j] [i] dp1 i j dp0[i][j] [i] dp0 i j mod dp1[i][j+1] = (dp1[i][j+1]+dp1[i][j])%mod dp1[i][j+1] [i] dp1 i j+1 j 1 (dp1[i][j+1]+dp1[i][j])%mod dp1[i][j+1]+dp1[i][j] dp1[i][j+1] [i] dp1 i j+1 j 1 dp1[i][j] [i] dp1 i j mod if i != n and j != m and s[i] == t[j]:
            dp0[i+1][j+1] = (dp1[i+1][j+1]+dp1[i][j])%mod i != n and j != m and s[i] == t[j] i != n and j != m i != n i n j != m j m s[i] == t[j] s[i] s i t[j] t j dp0[i+1][j+1] = (dp1[i+1][j+1]+dp1[i][j])%mod dp0[i+1][j+1] [i+1] dp0 i+1 i 1 j+1 j 1 (dp1[i+1][j+1]+dp1[i][j])%mod dp1[i+1][j+1]+dp1[i][j] dp1[i+1][j+1] [i+1] dp1 i+1 i 1 j+1 j 1 dp1[i][j] [i] dp1 i j mod print(dp1[n][m]) print dp1[n][m] [n] dp1 n m dp1 = [[0 for i in range(m+2)] for j in range(n+2)] [[0 for i in range(m+2)] for j in range(n+2)] dp1 m = map(int,input().split()) map(int,input().split()) m t = list(map(int,input().split())) list(map(int,input().split())) t n,m = map(int,input().split()) map(int,input().split()) n s = list(map(int,input().split())) list(map(int,input().split())) s dp0 = [[0 for i in range(m+2)] for j in range(n+2)] [[0 for i in range(m+2)] for j in range(n+2)] dp0 mod = 10**9+7 10**9+7 mod
n,m = map(int,input().split())
s = list(map(int,input().split()))
t = list(map(int,input().split()))
dp0 = [[0 for i in range(m+2)] for j in range(n+2)]
dp1 = [[0 for i in range(m+2)] for j in range(n+2)]
dp0[0][0] = 1
mod = 10**9+7
for i in range(n+1):
    for j in range(m+1):
        dp0[i+1][j] = (dp0[i+1][j]+dp0[i][j])%mod
        dp1[i][j] = (dp1[i][j]+dp0[i][j])%mod
        dp1[i][j+1] = (dp1[i][j+1]+dp1[i][j])%mod
        if i != n and j != m and s[i] == t[j]:
            dp0[i+1][j+1] = (dp1[i+1][j+1]+dp1[i][j])%mod
print(dp1[n][m])