n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
q = 10**9 + 7

dp = [[None] * m for _ in range(n)] #[i][j]: s[i], t[j]を使ってできる部分列の数
sumdp = [[None] * m for _ in range(n)]

if s[0] == t[0]:
    dp[0][0] = 1
    sumdp[0][0] = 2
else:
    dp[0][0] = 0
    sumdp[0][0] = 1
    
# j=0
for i in range(1, n):
    if s[i] == t[0]:
        dp[i][0] = 1
        #dp[i][j] = sumdp[i-1][j-1] or 0
        sumdp[i][0] = sumdp[i-1][0] + 1
        sumdp[i][0] %= q
        #sumdp[i][j] = dp[i][j] + (sumdp[i-1][j] - sumdp[i-1][j-1])
        #              + (sum[i][j-1] - sumdp[i-1][j-1]) + sumdp[i-1][j-1]
        
    else:
        dp[i][0] = 0
        sumdp[i][0] = sumdp[i-1][0]
        
for j in range(1, m):
    if s[0] == t[j]:
        dp[0][j] = 1
        sumdp[0][j] = sumdp[0][j-1] + 1
        sumdp[0][j] %= q
    else:
        dp[0][j] = 0
        sumdp[0][j] = sumdp[0][j-1]
        
for i in range(1, n):
    for j in range(1, m):
        if s[i] == t[j]:
            dp[i][j] = sumdp[i-1][j-1]
        else:
            dp[i][j] = 0
        sumdp[i][j] = dp[i][j] + sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1]
        sumdp[i][j] %= q

print(sumdp[n-1][m-1]) 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 q = 10**9 + 7 q 10**9 + 7 10**9 10 9 7 [None] * m for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [None] * m [None] None m dp = [[None] * m for _ in range(n)] dp [[None] * m for _ in range(n)] [None] * m for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [None] * m [None] None m sumdp = [[None] * m for _ in range(n)] sumdp [[None] * m for _ in range(n)] if s[0] == t[0]:
    dp[0][0] = 1
    sumdp[0][0] = 2
else:
    dp[0][0] = 0
    sumdp[0][0] = 1
    
# j=0 s[0] == t[0] s[0] s 0 t[0] t 0 dp[0][0] = 1 dp[0][0] [0] dp 0 0 1 sumdp[0][0] = 2 sumdp[0][0] [0] sumdp 0 0 2 dp[0][0] = 0 dp[0][0] [0] dp 0 0 0 sumdp[0][0] = 1 sumdp[0][0] [0] sumdp 0 0 1 for i in range(1, n):
    if s[i] == t[0]:
        dp[i][0] = 1
        #dp[i][j] = sumdp[i-1][j-1] or 0
        sumdp[i][0] = sumdp[i-1][0] + 1
        sumdp[i][0] %= q
        #sumdp[i][j] = dp[i][j] + (sumdp[i-1][j] - sumdp[i-1][j-1])
        #              + (sum[i][j-1] - sumdp[i-1][j-1]) + sumdp[i-1][j-1]
        
    else:
        dp[i][0] = 0
        sumdp[i][0] = sumdp[i-1][0]
         i range(1, n) range 1 n if s[i] == t[0]:
        dp[i][0] = 1
        #dp[i][j] = sumdp[i-1][j-1] or 0
        sumdp[i][0] = sumdp[i-1][0] + 1
        sumdp[i][0] %= q
        #sumdp[i][j] = dp[i][j] + (sumdp[i-1][j] - sumdp[i-1][j-1])
        #              + (sum[i][j-1] - sumdp[i-1][j-1]) + sumdp[i-1][j-1]
        
    else:
        dp[i][0] = 0
        sumdp[i][0] = sumdp[i-1][0]
         s[i] == t[0] s[i] s i t[0] t 0 dp[i][0] = 1 dp[i][0] [i] dp i 0 1 sumdp[i][0] = sumdp[i-1][0] + 1 sumdp[i][0] [i] sumdp i 0 sumdp[i-1][0] + 1 sumdp[i-1][0] [i-1] sumdp i-1 i 1 0 1 sumdp[i][0] %= q sumdp[i][0] [i] sumdp i 0 q dp[i][0] = 0 dp[i][0] [i] dp i 0 0 sumdp[i][0] = sumdp[i-1][0] sumdp[i][0] [i] sumdp i 0 sumdp[i-1][0] [i-1] sumdp i-1 i 1 0 for j in range(1, m):
    if s[0] == t[j]:
        dp[0][j] = 1
        sumdp[0][j] = sumdp[0][j-1] + 1
        sumdp[0][j] %= q
    else:
        dp[0][j] = 0
        sumdp[0][j] = sumdp[0][j-1]
         j range(1, m) range 1 m if s[0] == t[j]:
        dp[0][j] = 1
        sumdp[0][j] = sumdp[0][j-1] + 1
        sumdp[0][j] %= q
    else:
        dp[0][j] = 0
        sumdp[0][j] = sumdp[0][j-1]
         s[0] == t[j] s[0] s 0 t[j] t j dp[0][j] = 1 dp[0][j] [0] dp 0 j 1 sumdp[0][j] = sumdp[0][j-1] + 1 sumdp[0][j] [0] sumdp 0 j sumdp[0][j-1] + 1 sumdp[0][j-1] [0] sumdp 0 j-1 j 1 1 sumdp[0][j] %= q sumdp[0][j] [0] sumdp 0 j q dp[0][j] = 0 dp[0][j] [0] dp 0 j 0 sumdp[0][j] = sumdp[0][j-1] sumdp[0][j] [0] sumdp 0 j sumdp[0][j-1] [0] sumdp 0 j-1 j 1 for i in range(1, n):
    for j in range(1, m):
        if s[i] == t[j]:
            dp[i][j] = sumdp[i-1][j-1]
        else:
            dp[i][j] = 0
        sumdp[i][j] = dp[i][j] + sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1]
        sumdp[i][j] %= q i range(1, n) range 1 n for j in range(1, m):
        if s[i] == t[j]:
            dp[i][j] = sumdp[i-1][j-1]
        else:
            dp[i][j] = 0
        sumdp[i][j] = dp[i][j] + sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1]
        sumdp[i][j] %= q j range(1, m) range 1 m if s[i] == t[j]:
            dp[i][j] = sumdp[i-1][j-1]
        else:
            dp[i][j] = 0
         s[i] == t[j] s[i] s i t[j] t j dp[i][j] = sumdp[i-1][j-1] dp[i][j] [i] dp i j sumdp[i-1][j-1] [i-1] sumdp i-1 i 1 j-1 j 1 dp[i][j] = 0 dp[i][j] [i] dp i j 0 sumdp[i][j] = dp[i][j] + sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1] sumdp[i][j] [i] sumdp i j dp[i][j] + sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1] dp[i][j] + sumdp[i-1][j] + sumdp[i][j-1] dp[i][j] + sumdp[i-1][j] dp[i][j] [i] dp i j sumdp[i-1][j] [i-1] sumdp i-1 i 1 j sumdp[i][j-1] [i] sumdp i j-1 j 1 sumdp[i-1][j-1] [i-1] sumdp i-1 i 1 j-1 j 1 sumdp[i][j] %= q sumdp[i][j] [i] sumdp i j q print(sumdp[n-1][m-1]) print sumdp[n-1][m-1] [n-1] sumdp n-1 n 1 m-1 m 1 m = map(int, input().split()) map(int, input().split()) m s = list(map(int, input().split())) list(map(int, input().split())) s q = 10**9 + 7 10**9 + 7 q dp = [[None] * m for _ in range(n)] [[None] * m for _ in range(n)] dp t = list(map(int, input().split())) list(map(int, input().split())) t sumdp = [[None] * m for _ in range(n)] [[None] * m for _ in range(n)] sumdp n, m = map(int, input().split()) map(int, input().split()) n
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
q = 10**9 + 7

dp = [[None] * m for _ in range(n)] #[i][j]: s[i], t[j]を使ってできる部分列の数
sumdp = [[None] * m for _ in range(n)]

if s[0] == t[0]:
    dp[0][0] = 1
    sumdp[0][0] = 2
else:
    dp[0][0] = 0
    sumdp[0][0] = 1
    
# j=0
for i in range(1, n):
    if s[i] == t[0]:
        dp[i][0] = 1
        #dp[i][j] = sumdp[i-1][j-1] or 0
        sumdp[i][0] = sumdp[i-1][0] + 1
        sumdp[i][0] %= q
        #sumdp[i][j] = dp[i][j] + (sumdp[i-1][j] - sumdp[i-1][j-1])
        #              + (sum[i][j-1] - sumdp[i-1][j-1]) + sumdp[i-1][j-1]
        
    else:
        dp[i][0] = 0
        sumdp[i][0] = sumdp[i-1][0]
        
for j in range(1, m):
    if s[0] == t[j]:
        dp[0][j] = 1
        sumdp[0][j] = sumdp[0][j-1] + 1
        sumdp[0][j] %= q
    else:
        dp[0][j] = 0
        sumdp[0][j] = sumdp[0][j-1]
        
for i in range(1, n):
    for j in range(1, m):
        if s[i] == t[j]:
            dp[i][j] = sumdp[i-1][j-1]
        else:
            dp[i][j] = 0
        sumdp[i][j] = dp[i][j] + sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1]
        sumdp[i][j] %= q

print(sumdp[n-1][m-1])