MOD = 10**9 + 7
n, m = [int(item) for item in input().split()]
s = [int(item) for item in input().split()]
t = [int(item) for item in input().split()]

dp = [[0] * (n+1) for _ in range(m+1)]
for i, tt in enumerate(t):
    val = 0 
    for j, ss in enumerate(s):
        # Update Partial
        if ss == tt:
            val += dp[i][j] + 1
            val %= MOD
        # Keep prev
        dp[i+1][j+1] += dp[i][j+1] + val
        dp[i+1][j+1] %= MOD 
print((dp[m][n]+1) % MOD) MOD = 10**9 + 7 MOD 10**9 + 7 10**9 10 9 7 int(item) for item in input().split() for item in input().split() item input().split() ().split () input split for item in input().split() int(item) int item n, m = [int(item) for item in input().split()] n [int(item) for item in input().split()] m int(item) for item in input().split() for item in input().split() item input().split() ().split () input split for item in input().split() int(item) int item s = [int(item) for item in input().split()] s [int(item) for item in input().split()] int(item) for item in input().split() for item in input().split() item input().split() ().split () input split for item in input().split() int(item) int item t = [int(item) for item in input().split()] t [int(item) for item in input().split()] [0] * (n+1) for _ in range(m+1) for _ in range(m+1) _ range(m+1) range m+1 m 1 for _ in range(m+1) [0] * (n+1) [0] 0 n+1 n 1 dp = [[0] * (n+1) for _ in range(m+1)] dp [[0] * (n+1) for _ in range(m+1)] for i, tt in enumerate(t):
    val = 0 
    for j, ss in enumerate(s):
        # Update Partial
        if ss == tt:
            val += dp[i][j] + 1
            val %= MOD
        # Keep prev
        dp[i+1][j+1] += dp[i][j+1] + val
        dp[i+1][j+1] %= MOD  i tt enumerate(t) enumerate t val = 0 val 0 for j, ss in enumerate(s):
        # Update Partial
        if ss == tt:
            val += dp[i][j] + 1
            val %= MOD
        # Keep prev
        dp[i+1][j+1] += dp[i][j+1] + val
        dp[i+1][j+1] %= MOD  j ss enumerate(s) enumerate s if ss == tt:
            val += dp[i][j] + 1
            val %= MOD
        # Keep prev
         ss == tt ss tt val += dp[i][j] + 1 val dp[i][j] + 1 dp[i][j] [i] dp i j 1 val %= MOD val MOD dp[i+1][j+1] += dp[i][j+1] + val dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 dp[i][j+1] + val dp[i][j+1] [i] dp i j+1 j 1 val dp[i+1][j+1] %= MOD dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 MOD print((dp[m][n]+1) % MOD) print (dp[m][n]+1) % MOD dp[m][n]+1 dp[m][n] [m] dp m n 1 MOD s = [int(item) for item in input().split()] [int(item) for item in input().split()] s val += dp[i][j] + 1 dp[i][j] + 1 val dp = [[0] * (n+1) for _ in range(m+1)] [[0] * (n+1) for _ in range(m+1)] dp t = [int(item) for item in input().split()] [int(item) for item in input().split()] t val %= MOD MOD val MOD = 10**9 + 7 10**9 + 7 MOD n, m = [int(item) for item in input().split()] [int(item) for item in input().split()] n m = [int(item) for item in input().split()] [int(item) for item in input().split()] m val = 0 0 val
MOD = 10**9 + 7
n, m = [int(item) for item in input().split()]
s = [int(item) for item in input().split()]
t = [int(item) for item in input().split()]

dp = [[0] * (n+1) for _ in range(m+1)]
for i, tt in enumerate(t):
    val = 0 
    for j, ss in enumerate(s):
        # Update Partial
        if ss == tt:
            val += dp[i][j] + 1
            val %= MOD
        # Keep prev
        dp[i+1][j+1] += dp[i][j+1] + val
        dp[i+1][j+1] %= MOD 
print((dp[m][n]+1) % MOD)
