#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import copy
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
#mint
class ModInt:
    def __init__(self, x):
        self.x = x % mod
    
    def __str__(self):
        return str(self.x)
    
    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

    __radd__ = __add__
        
    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

    def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
    def __rtruediv(self, other):
        if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod))

def main():
    N, M = MI()
    S = [i for i in ST().split()]
    T = [i for i in ST().split()]

    dp = [[ModInt(1)] * (M + 1) for _ in range(N + 1)] #dp[i][j]:=i,j文字目までの整数列組数

    for i,s in enumerate(S,start = 1):
        for j,t in enumerate(T,start = 1):
            if t == s:
                dp[i][j] = dp[i-1][j] + dp[i][j-1]
            else:
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
    print(dp[-1][-1])

if __name__ == '__main__':
    main() import sys sys input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline from math import floor,ceil,sqrt,factorial,log from heapq import heappop, heappush, heappushpop from collections import Counter,defaultdict from itertools import accumulate,permutations,combinations,product,combinations_with_replacement from bisect import bisect_left, bisect_right from copy import copy inf=float('inf') inf float('inf') float 'inf' mod = 10**9+7 mod 10**9+7 10**9 10 9 7 def INT_(n): return int(n)-1 INT_ n n def MI(): return map(int,input().split()) MI def MF(): return map(float, input().split()) MF def MI_(): return map(INT_,input().split()) MI_ def LI(): return list(MI()) LI int(x) - 1 for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) - 1 int(x) int x 1 def LI_(): return [int(x) - 1 for x in input().split()] LI_ def LF(): return list(MF()) LF I() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) I() I def LIN(n:int): return [I() for _ in range(n)] LIN n:int n LI() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LI() LI def LLIN(n: int): return [LI() for _ in range(n)] LLIN n: int n LI_() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LI_() LI_ def LLIN_(n: int): return [LI_() for _ in range(n)] LLIN_ n: int n list(map(int, l.split() )) for l in input() for l in input() l input() input for l in input() list(map(int, l.split() )) list map(int, l.split() ) map int l.split() l.split l split def LLI(): return [list(map(int, l.split() )) for l in input()] LLI def I(): return int(input()) I def F(): return float(input()) F def ST(): return input().replace('\n', '')
#mint ST class ModInt:
    def __init__(self, x):
        self.x = x % mod
    
    def __str__(self):
        return str(self.x)
    
    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

    __radd__ = __add__
        
    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

    def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
    def __rtruediv(self, other):
        if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod)) ModInt def __init__(self, x):
        self.x = x % mod
    
     __init__ self.x = x % mod self.x self x x % mod x mod self self x x def __str__(self):
        return str(self.x)
    
     __str__ return str(self.x) str(self.x) str self.x self x self self __repr__ = __str__ __repr__ __str__ def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

     __add__ if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

     isinstance(other, ModInt) isinstance other ModInt return ModInt(self.x + other.x) ModInt(self.x + other.x) ModInt self.x + other.x self.x self x other.x other x return ModInt(self.x + other) ModInt(self.x + other) ModInt self.x + other self.x self x other self self other other __radd__ = __add__ __radd__ __add__ def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

     __sub__ if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

     isinstance(other, ModInt) isinstance other ModInt return ModInt(self.x - other.x) ModInt(self.x - other.x) ModInt self.x - other.x self.x self x other.x other x return ModInt(self.x - other) ModInt(self.x - other) ModInt self.x - other self.x self x other self self other other def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

     __rsub__ if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

     isinstance(other, ModInt) isinstance other ModInt return ModInt(other.x - self.x) ModInt(other.x - self.x) ModInt other.x - self.x other.x other x self.x self x return ModInt(other - self.x) ModInt(other - self.x) ModInt other - self.x other self.x self x self self other other def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

     __mul__ if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

     isinstance(other, ModInt) isinstance other ModInt return ModInt(self.x * other.x) ModInt(self.x * other.x) ModInt self.x * other.x self.x self x other.x other x return ModInt(self.x * other) ModInt(self.x * other) ModInt self.x * other self.x self x other self self other other __rmul__ = __mul__ __rmul__ __mul__ def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
     __truediv__ if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
     isinstance(other, ModInt) isinstance other ModInt return ModInt(self.x * pow(other.x, mod-2,mod)) ModInt(self.x * pow(other.x, mod-2,mod)) ModInt self.x * pow(other.x, mod-2,mod) self.x self x pow(other.x, mod-2,mod) pow other.x other x mod-2 mod 2 mod return ModInt(self.x * pow(other, mod - 2, mod)) ModInt(self.x * pow(other, mod - 2, mod)) ModInt self.x * pow(other, mod - 2, mod) self.x self x pow(other, mod - 2, mod) pow other mod - 2 mod 2 mod self self other other def __rtruediv(self, other):
        if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

     __rtruediv if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

     isinstance(other, self) isinstance other self return ModInt(other * pow(self.x, mod - 2, mod)) ModInt(other * pow(self.x, mod - 2, mod)) ModInt other * pow(self.x, mod - 2, mod) other pow(self.x, mod - 2, mod) pow self.x self x mod - 2 mod 2 mod return ModInt(other.x * pow(self.x, mod - 2, mod)) ModInt(other.x * pow(self.x, mod - 2, mod)) ModInt other.x * pow(self.x, mod - 2, mod) other.x other x pow(self.x, mod - 2, mod) pow self.x self x mod - 2 mod 2 mod self self other other def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

     __pow__ if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

     isinstance(other, ModInt) isinstance other ModInt return ModInt(pow(self.x, other.x, mod)) ModInt(pow(self.x, other.x, mod)) ModInt pow(self.x, other.x, mod) pow self.x self x other.x other x mod return ModInt(pow(self.x, other, mod)) ModInt(pow(self.x, other, mod)) ModInt pow(self.x, other, mod) pow self.x self x other mod self self other other def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod)) __rpow__ if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod)) isinstance(other, ModInt) isinstance other ModInt return ModInt(pow(other.x, self.x, mod)) ModInt(pow(other.x, self.x, mod)) ModInt pow(other.x, self.x, mod) pow other.x other x self.x self x mod return ModInt(pow(other, self.x, mod)) ModInt(pow(other, self.x, mod)) ModInt pow(other, self.x, mod) pow other self.x self x mod self self other other def main():
    N, M = MI()
    S = [i for i in ST().split()]
    T = [i for i in ST().split()]

    dp = [[ModInt(1)] * (M + 1) for _ in range(N + 1)] #dp[i][j]:=i,j文字目までの整数列組数

    for i,s in enumerate(S,start = 1):
        for j,t in enumerate(T,start = 1):
            if t == s:
                dp[i][j] = dp[i-1][j] + dp[i][j-1]
            else:
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
    print(dp[-1][-1]) main N, M = MI() N MI() MI M i for i in ST().split() for i in ST().split() i ST().split() ().split () ST split for i in ST().split() i S = [i for i in ST().split()] S [i for i in ST().split()] i for i in ST().split() for i in ST().split() i ST().split() ().split () ST split for i in ST().split() i T = [i for i in ST().split()] T [i for i in ST().split()] [ModInt(1)] * (M + 1) for _ in range(N + 1) for _ in range(N + 1) _ range(N + 1) range N + 1 N 1 for _ in range(N + 1) [ModInt(1)] * (M + 1) [ModInt(1)] ModInt(1) ModInt 1 M + 1 M 1 dp = [[ModInt(1)] * (M + 1) for _ in range(N + 1)] dp [[ModInt(1)] * (M + 1) for _ in range(N + 1)] for i,s in enumerate(S,start = 1):
        for j,t in enumerate(T,start = 1):
            if t == s:
                dp[i][j] = dp[i-1][j] + dp[i][j-1]
            else:
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
     i s enumerate(S,start = 1) enumerate S start = 1 start 1 for j,t in enumerate(T,start = 1):
            if t == s:
                dp[i][j] = dp[i-1][j] + dp[i][j-1]
            else:
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
     j t enumerate(T,start = 1) enumerate T start = 1 start 1 if t == s:
                dp[i][j] = dp[i-1][j] + dp[i][j-1]
            else:
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
     t == s t s dp[i][j] = dp[i-1][j] + dp[i][j-1] dp[i][j] [i] dp i j dp[i-1][j] + dp[i][j-1] dp[i-1][j] [i-1] dp i-1 i 1 j dp[i][j-1] [i] dp i j-1 j 1 dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] dp[i][j] [i] dp i j dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] dp[i-1][j] + dp[i][j-1] dp[i-1][j] [i-1] dp i-1 i 1 j dp[i][j-1] [i] dp i j-1 j 1 dp[i-1][j-1] [i-1] dp i-1 i 1 j-1 j 1 print(dp[-1][-1]) print dp[-1][-1] [-1] dp -1 -1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def LIN(n:int): return [I() for _ in range(n)] def LIN(n:int): return [I() for _ in range(n)] LIN def MI_(): return map(INT_,input().split()) def MI_(): return map(INT_,input().split()) MI_ input=sys.stdin.readline sys.stdin.readline input inf=float('inf') float('inf') inf def LF(): return list(MF()) def LF(): return list(MF()) LF mod = 10**9+7 10**9+7 mod def MF(): return map(float, input().split()) def MF(): return map(float, input().split()) MF def LI(): return list(MI()) def LI(): return list(MI()) LI def LLIN(n: int): return [LI() for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] LLIN def ST(): return input().replace('\n', '')
#mint def ST(): return input().replace('\n', '')
#mint ST def F(): return float(input()) def F(): return float(input()) F def INT_(n): return int(n)-1 def INT_(n): return int(n)-1 INT_ def LLIN_(n: int): return [LI_() for _ in range(n)] def LLIN_(n: int): return [LI_() for _ in range(n)] LLIN_ class ModInt:
    def __init__(self, x):
        self.x = x % mod
    
    def __str__(self):
        return str(self.x)
    
    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

    __radd__ = __add__
        
    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

    def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
    def __rtruediv(self, other):
        if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod)) class ModInt:
    def __init__(self, x):
        self.x = x % mod
    
    def __str__(self):
        return str(self.x)
    
    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

    __radd__ = __add__
        
    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

    def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
    def __rtruediv(self, other):
        if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod)) ModInt def MI(): return map(int,input().split()) def MI(): return map(int,input().split()) MI def LI_(): return [int(x) - 1 for x in input().split()] def LI_(): return [int(x) - 1 for x in input().split()] LI_ def main():
    N, M = MI()
    S = [i for i in ST().split()]
    T = [i for i in ST().split()]

    dp = [[ModInt(1)] * (M + 1) for _ in range(N + 1)] #dp[i][j]:=i,j文字目までの整数列組数

    for i,s in enumerate(S,start = 1):
        for j,t in enumerate(T,start = 1):
            if t == s:
                dp[i][j] = dp[i-1][j] + dp[i][j-1]
            else:
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
    print(dp[-1][-1]) def main():
    N, M = MI()
    S = [i for i in ST().split()]
    T = [i for i in ST().split()]

    dp = [[ModInt(1)] * (M + 1) for _ in range(N + 1)] #dp[i][j]:=i,j文字目までの整数列組数

    for i,s in enumerate(S,start = 1):
        for j,t in enumerate(T,start = 1):
            if t == s:
                dp[i][j] = dp[i-1][j] + dp[i][j-1]
            else:
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
    print(dp[-1][-1]) main def LLI(): return [list(map(int, l.split() )) for l in input()] def LLI(): return [list(map(int, l.split() )) for l in input()] LLI def I(): return int(input()) def I(): return int(input()) I
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import copy
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
#mint
class ModInt:
    def __init__(self, x):
        self.x = x % mod
    
    def __str__(self):
        return str(self.x)
    
    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

    __radd__ = __add__
        
    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

    def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
    def __rtruediv(self, other):
        if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod))

def main():
    N, M = MI()
    S = [i for i in ST().split()]
    T = [i for i in ST().split()]

    dp = [[ModInt(1)] * (M + 1) for _ in range(N + 1)] #dp[i][j]:=i,j文字目までの整数列組数

    for i,s in enumerate(S,start = 1):
        for j,t in enumerate(T,start = 1):
            if t == s:
                dp[i][j] = dp[i-1][j] + dp[i][j-1]
            else:
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
    print(dp[-1][-1])

if __name__ == '__main__':
    main()