N,M = [int(x) for x in input().split()]
S = [int(x) for x in input().split()]+[0]
T = [int(x) for x in input().split()]+[0]
MOD = 10**9+7
dp=[[[0]*2 for _ in range(M+2)] for _ in range(N+2)]
dp[0][0][0]=1
for i in range(N+1):
    for j in range(M+1):
        dp[i+1][j][0] += dp[i][j][0]
        dp[i+1][j][0] %= MOD
        dp[i][j][1] += dp[i][j][0]
        dp[i][j][1] %= MOD
        dp[i][j+1][1] += dp[i][j][1]
        dp[i][j+1][1] %= MOD
        if(S[i]==T[j]):
            dp[i+1][j+1][0] += dp[i][j][1]
            dp[i+1][j+1][0] %= MOD

print(dp[N][M][1]) int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x N,M = [int(x) for x in input().split()] N [int(x) for x in input().split()] M int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x S = [int(x) for x in input().split()]+[0] S [int(x) for x in input().split()]+[0] [int(x) for x in input().split()] [0] 0 int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x T = [int(x) for x in input().split()]+[0] T [int(x) for x in input().split()]+[0] [int(x) for x in input().split()] [0] 0 MOD = 10**9+7 MOD 10**9+7 10**9 10 9 7 [[0]*2 for _ in range(M+2)] for _ in range(N+2) for _ in range(N+2) _ range(N+2) range N+2 N 2 for _ in range(N+2) [[0]*2 for _ in range(M+2)] dp=[[[0]*2 for _ in range(M+2)] for _ in range(N+2)] dp [[[0]*2 for _ in range(M+2)] for _ in range(N+2)] dp[0][0][0]=1 dp[0][0][0] [0] [0] dp 0 0 0 1 for i in range(N+1):
    for j in range(M+1):
        dp[i+1][j][0] += dp[i][j][0]
        dp[i+1][j][0] %= MOD
        dp[i][j][1] += dp[i][j][0]
        dp[i][j][1] %= MOD
        dp[i][j+1][1] += dp[i][j][1]
        dp[i][j+1][1] %= MOD
        if(S[i]==T[j]):
            dp[i+1][j+1][0] += dp[i][j][1]
            dp[i+1][j+1][0] %= MOD i range(N+1) range N+1 N 1 for j in range(M+1):
        dp[i+1][j][0] += dp[i][j][0]
        dp[i+1][j][0] %= MOD
        dp[i][j][1] += dp[i][j][0]
        dp[i][j][1] %= MOD
        dp[i][j+1][1] += dp[i][j][1]
        dp[i][j+1][1] %= MOD
        if(S[i]==T[j]):
            dp[i+1][j+1][0] += dp[i][j][1]
            dp[i+1][j+1][0] %= MOD j range(M+1) range M+1 M 1 dp[i+1][j][0] += dp[i][j][0] dp[i+1][j][0] [j] [i+1] dp i+1 i 1 j 0 dp[i][j][0] [j] [i] dp i j 0 dp[i+1][j][0] %= MOD dp[i+1][j][0] [j] [i+1] dp i+1 i 1 j 0 MOD dp[i][j][1] += dp[i][j][0] dp[i][j][1] [j] [i] dp i j 1 dp[i][j][0] [j] [i] dp i j 0 dp[i][j][1] %= MOD dp[i][j][1] [j] [i] dp i j 1 MOD dp[i][j+1][1] += dp[i][j][1] dp[i][j+1][1] [j+1] [i] dp i j+1 j 1 1 dp[i][j][1] [j] [i] dp i j 1 dp[i][j+1][1] %= MOD dp[i][j+1][1] [j+1] [i] dp i j+1 j 1 1 MOD if(S[i]==T[j]):
            dp[i+1][j+1][0] += dp[i][j][1]
            dp[i+1][j+1][0] %= MOD S[i]==T[j] S[i] S i T[j] T j dp[i+1][j+1][0] += dp[i][j][1] dp[i+1][j+1][0] [j+1] [i+1] dp i+1 i 1 j+1 j 1 0 dp[i][j][1] [j] [i] dp i j 1 dp[i+1][j+1][0] %= MOD dp[i+1][j+1][0] [j+1] [i+1] dp i+1 i 1 j+1 j 1 0 MOD print(dp[N][M][1]) print dp[N][M][1] [M] [N] dp N M 1 MOD = 10**9+7 10**9+7 MOD N,M = [int(x) for x in input().split()] [int(x) for x in input().split()] N M = [int(x) for x in input().split()] [int(x) for x in input().split()] M dp=[[[0]*2 for _ in range(M+2)] for _ in range(N+2)] [[[0]*2 for _ in range(M+2)] for _ in range(N+2)] dp S = [int(x) for x in input().split()]+[0] [int(x) for x in input().split()]+[0] S T = [int(x) for x in input().split()]+[0] [int(x) for x in input().split()]+[0] T
N,M = [int(x) for x in input().split()]
S = [int(x) for x in input().split()]+[0]
T = [int(x) for x in input().split()]+[0]
MOD = 10**9+7
dp=[[[0]*2 for _ in range(M+2)] for _ in range(N+2)]
dp[0][0][0]=1
for i in range(N+1):
    for j in range(M+1):
        dp[i+1][j][0] += dp[i][j][0]
        dp[i+1][j][0] %= MOD
        dp[i][j][1] += dp[i][j][0]
        dp[i][j][1] %= MOD
        dp[i][j+1][1] += dp[i][j][1]
        dp[i][j+1][1] %= MOD
        if(S[i]==T[j]):
            dp[i+1][j+1][0] += dp[i][j][1]
            dp[i+1][j+1][0] %= MOD

print(dp[N][M][1])
