n,m = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))
mod = 10**9 + 7

dp = [[0 for j in range(m+1)] for i in range(n+1)]

sum_dp = [[0 for j in range(m+1)] for i in range(n+1)]

dp[0][0] = 1
for i,x in enumerate(S):
    for j,y in enumerate(T):
        if x == y:
            dp[i+1][j+1] = sum_dp[i][j]+1
            dp[i+1][j+1] %= mod
        else:
            dp[i+1][j+1] = 0
        sum_dp[i+1][j+1] = sum_dp[i][j+1]+sum_dp[i+1][j]-sum_dp[i][j]+dp[i+1][j+1]
        sum_dp[i+1][j+1] %= mod

ans = 0
for x in dp:
    ans += sum(x)
    ans %= mod

print(ans) 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 mod = 10**9 + 7 mod 10**9 + 7 10**9 10 9 7 [0 for j in range(m+1)] for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) [0 for j in range(m+1)] dp = [[0 for j in range(m+1)] for i in range(n+1)] dp [[0 for j in range(m+1)] for i in range(n+1)] [0 for j in range(m+1)] for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) [0 for j in range(m+1)] sum_dp = [[0 for j in range(m+1)] for i in range(n+1)] sum_dp [[0 for j in range(m+1)] for i in range(n+1)] dp[0][0] = 1 dp[0][0] [0] dp 0 0 1 for i,x in enumerate(S):
    for j,y in enumerate(T):
        if x == y:
            dp[i+1][j+1] = sum_dp[i][j]+1
            dp[i+1][j+1] %= mod
        else:
            dp[i+1][j+1] = 0
        sum_dp[i+1][j+1] = sum_dp[i][j+1]+sum_dp[i+1][j]-sum_dp[i][j]+dp[i+1][j+1]
        sum_dp[i+1][j+1] %= mod i x enumerate(S) enumerate S for j,y in enumerate(T):
        if x == y:
            dp[i+1][j+1] = sum_dp[i][j]+1
            dp[i+1][j+1] %= mod
        else:
            dp[i+1][j+1] = 0
        sum_dp[i+1][j+1] = sum_dp[i][j+1]+sum_dp[i+1][j]-sum_dp[i][j]+dp[i+1][j+1]
        sum_dp[i+1][j+1] %= mod j y enumerate(T) enumerate T if x == y:
            dp[i+1][j+1] = sum_dp[i][j]+1
            dp[i+1][j+1] %= mod
        else:
            dp[i+1][j+1] = 0
         x == y x y dp[i+1][j+1] = sum_dp[i][j]+1 dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 sum_dp[i][j]+1 sum_dp[i][j] [i] sum_dp i j 1 dp[i+1][j+1] %= mod dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 mod dp[i+1][j+1] = 0 dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 0 sum_dp[i+1][j+1] = sum_dp[i][j+1]+sum_dp[i+1][j]-sum_dp[i][j]+dp[i+1][j+1] sum_dp[i+1][j+1] [i+1] sum_dp i+1 i 1 j+1 j 1 sum_dp[i][j+1]+sum_dp[i+1][j]-sum_dp[i][j]+dp[i+1][j+1] sum_dp[i][j+1]+sum_dp[i+1][j]-sum_dp[i][j] sum_dp[i][j+1]+sum_dp[i+1][j] sum_dp[i][j+1] [i] sum_dp i j+1 j 1 sum_dp[i+1][j] [i+1] sum_dp i+1 i 1 j sum_dp[i][j] [i] sum_dp i j dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 sum_dp[i+1][j+1] %= mod sum_dp[i+1][j+1] [i+1] sum_dp i+1 i 1 j+1 j 1 mod ans = 0 ans 0 for x in dp:
    ans += sum(x)
    ans %= mod x dp ans += sum(x) ans sum(x) sum x ans %= mod ans mod print(ans) print ans dp = [[0 for j in range(m+1)] for i in range(n+1)] [[0 for j in range(m+1)] for i in range(n+1)] dp ans += sum(x) sum(x) ans m = map(int,input().split()) map(int,input().split()) m ans = 0 0 ans S = list(map(int,input().split())) list(map(int,input().split())) S T = list(map(int,input().split())) list(map(int,input().split())) T ans %= mod mod ans sum_dp = [[0 for j in range(m+1)] for i in range(n+1)] [[0 for j in range(m+1)] for i in range(n+1)] sum_dp n,m = map(int,input().split()) map(int,input().split()) n 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()))
mod = 10**9 + 7

dp = [[0 for j in range(m+1)] for i in range(n+1)]

sum_dp = [[0 for j in range(m+1)] for i in range(n+1)]

dp[0][0] = 1
for i,x in enumerate(S):
    for j,y in enumerate(T):
        if x == y:
            dp[i+1][j+1] = sum_dp[i][j]+1
            dp[i+1][j+1] %= mod
        else:
            dp[i+1][j+1] = 0
        sum_dp[i+1][j+1] = sum_dp[i][j+1]+sum_dp[i+1][j]-sum_dp[i][j]+dp[i+1][j+1]
        sum_dp[i+1][j+1] %= mod

ans = 0
for x in dp:
    ans += sum(x)
    ans %= mod

print(ans)