inpl = lambda: list(map(int,input().split()))
MOD = 10**9 + 7
N, M = inpl()
S = inpl()
T = inpl()

total = [0]*(N+1)*(M+1)
for i in range(N):
	for j in range(M):
		if S[i] == T[j]:
			n = total[(M+1)*i+j] + 1
		else:
			n = 0
		total[(M+1)*(i+1)+(j+1)] = (n + total[(M+1)*i+(j+1)] + total[(M+1)*(i+1)+j] - total[(M+1)*i+j]) % MOD
print((total[-1]+1) % MOD) inpl = lambda: list(map(int,input().split())) inpl lambda: list(map(int,input().split())) 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 N, M = inpl() N inpl() inpl M S = inpl() S inpl() inpl T = inpl() T inpl() inpl total = [0]*(N+1)*(M+1) total [0]*(N+1)*(M+1) [0]*(N+1) [0] 0 N+1 N 1 M+1 M 1 for i in range(N):
	for j in range(M):
		if S[i] == T[j]:
			n = total[(M+1)*i+j] + 1
		else:
			n = 0
		total[(M+1)*(i+1)+(j+1)] = (n + total[(M+1)*i+(j+1)] + total[(M+1)*(i+1)+j] - total[(M+1)*i+j]) % MOD i range(N) range N for j in range(M):
		if S[i] == T[j]:
			n = total[(M+1)*i+j] + 1
		else:
			n = 0
		total[(M+1)*(i+1)+(j+1)] = (n + total[(M+1)*i+(j+1)] + total[(M+1)*(i+1)+j] - total[(M+1)*i+j]) % MOD j range(M) range M if S[i] == T[j]:
			n = total[(M+1)*i+j] + 1
		else:
			n = 0
		 S[i] == T[j] S[i] S i T[j] T j n = total[(M+1)*i+j] + 1 n total[(M+1)*i+j] + 1 total[(M+1)*i+j] total (M+1)*i+j (M+1)*i M+1 M 1 i j 1 n = 0 n 0 total[(M+1)*(i+1)+(j+1)] = (n + total[(M+1)*i+(j+1)] + total[(M+1)*(i+1)+j] - total[(M+1)*i+j]) % MOD total[(M+1)*(i+1)+(j+1)] total (M+1)*(i+1)+(j+1) (M+1)*(i+1) M+1 M 1 i+1 i 1 j+1 j 1 (n + total[(M+1)*i+(j+1)] + total[(M+1)*(i+1)+j] - total[(M+1)*i+j]) % MOD n + total[(M+1)*i+(j+1)] + total[(M+1)*(i+1)+j] - total[(M+1)*i+j] n + total[(M+1)*i+(j+1)] + total[(M+1)*(i+1)+j] n + total[(M+1)*i+(j+1)] n total[(M+1)*i+(j+1)] total (M+1)*i+(j+1) (M+1)*i M+1 M 1 i j+1 j 1 total[(M+1)*(i+1)+j] total (M+1)*(i+1)+j (M+1)*(i+1) M+1 M 1 i+1 i 1 j total[(M+1)*i+j] total (M+1)*i+j (M+1)*i M+1 M 1 i j MOD print((total[-1]+1) % MOD) print (total[-1]+1) % MOD total[-1]+1 total[-1] total -1 1 MOD T = inpl() inpl() T inpl = lambda: list(map(int,input().split())) lambda: list(map(int,input().split())) inpl n = 0 0 n total = [0]*(N+1)*(M+1) [0]*(N+1)*(M+1) total S = inpl() inpl() S M = inpl() inpl() M N, M = inpl() inpl() N MOD = 10**9 + 7 10**9 + 7 MOD n = total[(M+1)*i+j] + 1 total[(M+1)*i+j] + 1 n
inpl = lambda: list(map(int,input().split()))
MOD = 10**9 + 7
N, M = inpl()
S = inpl()
T = inpl()

total = [0]*(N+1)*(M+1)
for i in range(N):
	for j in range(M):
		if S[i] == T[j]:
			n = total[(M+1)*i+j] + 1
		else:
			n = 0
		total[(M+1)*(i+1)+(j+1)] = (n + total[(M+1)*i+(j+1)] + total[(M+1)*(i+1)+j] - total[(M+1)*i+j]) % MOD
print((total[-1]+1) % MOD)