import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Solution {
    static final int B7 = 1000 * 1000 * 1000 + 7;

    public static void main(String[] args) throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        String s = in.readLine(), t = in.readLine();
        int sl = s.length(), tl = t.length();

        int[][] f = new int[sl][tl];

        for (int i = 0; i < sl; i++)
            f[i][tl - 1] = s.charAt(i) == t.charAt(tl - 1) ? 1 : 0;

        f[sl - 1][tl - 1] = s.charAt(sl - 1) == t.charAt(tl - 1) ? 1 : 0;
        for (int j = tl - 2; j >= 0; j--)
            f[sl - 1][j] = f[sl - 1][j + 1] + (s.charAt(sl - 1) == t.charAt(j) ? 1 : 0);

        for (int i = sl - 2; i >= 0; i--)
            for (int j = tl - 2; j >= 0; j--)
                if (s.charAt(i) != t.charAt(j))
                    f[i][j] = f[i][j + 1];
                else
                    f[i][j] = (f[i][j + 1] + f[i + 1][j + 1] + 1) % B7;

        int ans = 0;

        for (int i = 0; i < sl; i++)
            ans = (ans + f[i][0]) % B7;

        out.println(ans);
        out.close();
    }
}

/**
 * Created by Alex on 9/22/2014.
 */

import java.io.*;
import java.util.*;

public class A163 {
    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;

    public String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public static void main(String[] args) throws IOException {
        new A163().run();
    }

    public void solve() throws IOException {
        char[] s = nextToken().toCharArray();
        char[] t = nextToken().toCharArray();
        int[][] d = new int[s.length][t.length];
        int s1, s2 = 0;
        final int MOD = (int)1e9 + 7;
        int ans = 0;
        int sum[] = new int[t.length];
        int[] sum1;
        for (int i = 0; i < s.length; ++i) {
            sum1 = sum;
            sum = new int[t.length];
            for (int j = 0; j < t.length; ++j) {
                if (s[i] != t[j])
                    d[i][j] = 0;
                else
                    d[i][j] = j > 0 ? sum1[j - 1] + 1 : 1;
                sum[j] = (j > 0 ? sum[j - 1] : 0) + d[i][j];
                sum[j] %= MOD;
                ans += d[i][j];
                ans %= MOD;
            }
        }
        out.print(ans);
    }

    public void run() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
}

import java.io.*;
import java.util.*;
import java.math.*;

import static java.lang.System.out;
// import static java.lang.Math.*;

public class Main implements Runnable {

    final int mod = 1000000007;

    char[] a, b;
    int m, n;
    int[][][] F;

    int calc(int i, int j, int needi) {
      if (i < 0 || j < 0) return 1;
      int res = F[i][j][needi];
      if (res != -1) return res;
      res = 0;
      if (a[i] == b[j]) {
        res += calc(i - 1, j - 1, 1);
        res %= mod;
      }
      res += calc(i, j - 1, needi);
      res %= mod;
      if (needi == 0) {
        res += calc(i - 1, j, 0);
        res %= mod;
        res -= calc(i - 1, j - 1, 0);
        res %= mod;
        res += mod;
        res %= mod;
      }
      viet(i, j, needi, res);
      return F[i][j][needi] = res;
    }

    public void run() {
      a = nextStr().toCharArray();
      b = nextStr().toCharArray();
      m = a.length;
      n = b.length;
      /* F = new int[m + 1][n + 1][2];
      for (int[][] a2 : F) for (int[] a1 : a2) Arrays.fill(a1, -1);
      int res = (calc(m - 1, n - 1, 0) - 1 + mod) % mod;
      out.println(res); */
      int[][] F = new int[n][2];
      int[][] G = new int[n][2];
      for (int[] a1 : F) Arrays.fill(a1, 1);
      for (int i = 0; i < m; ++i) {
        for (int[] a1 : G) Arrays.fill(a1, 0);
        for (int j = 0; j < n; ++j) {
          for (int needi = 0; needi < 2; ++needi) {
            if (a[i] == b[j]) {
              G[j][needi] = (G[j][needi] + (j > 0 ? F[j - 1][1] : 1)) % mod;
            }
            G[j][needi] = (G[j][needi] + (j > 0 ? G[j - 1][needi] : 1)) % mod;
            if (needi == 0) {
              G[j][needi] = (G[j][needi] + F[j][0]) % mod;
              G[j][needi] = (G[j][needi] - (j > 0 ? F[j - 1][0] : 1) + mod) % mod;
            }
            // viet(i, j, needi, G[j][needi]);
          }
        }
        int[][] tmp = F; F = G; G = tmp;
      }
      out.println((F[n - 1][0] - 1 + mod) % mod);
    }

    int[] ar(int st, int en) { int[] res = new int[Math.max(en - st, 0)]; for (int i = st; i < en; ++i) res[i - st] = i; return res; }
    int[] ar(int n) { return ar(0, n); }
    void viet(Object...os) { System.err.println(Arrays.deepToString(os)); }
    BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer strtok = null;

    String nextStr() {
        try {
            while(strtok == null || !strtok.hasMoreTokens())
                strtok = new StringTokenizer(keyboard.readLine());
            return strtok.nextToken();
        }
        catch(Exception ex) {
            System.out.println(ex.getMessage());
            ex.printStackTrace();
            return null;
        }
    }

    int nextInt() {
        return Integer.parseInt(nextStr());
    }

    long nextLong() {
        return Long.parseLong(nextStr());
    }

    double nextDouble() {
        return Double.parseDouble(nextStr());
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

import java.util.*;
import static java.lang.Math.*;
import java.io.*;

public class A {
	public static void p(Object...o) {System.out.println(Arrays.deepToString(o));}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String S = in.next();
		String T = in.next();
		int NS = S.length();
		int NT = T.length();
		long[] DP1 = new long[NT + 1];
		long[] DP2 = new long[NT + 1];
		Arrays.fill(DP2, 1);

		long ans = 0;
		for (int s = NS-1; s >= 0; s--) {
			Arrays.fill(DP1, 0);
			DP1[NT] = 1;
			for (int t = NT - 1; t >= 0; t--) {
				DP1[t] = DP1[t+1];
				if (S.charAt(s) == T.charAt(t))
					DP1[t] += DP2[t+1];
				DP1[t] %= MOD;
			}
			ans = (ans + (DP1[0]-1)) % MOD;
			long[] temp = DP1;
			DP1 = DP2;
			DP2 = temp;
		}
		System.out.println(ans);
	}
	static long MOD = 1000000007L;

}

import java.io.*;
import java.util.*;

public class A implements Runnable {
    private MyScanner in;
    private PrintWriter out;

    private final int MOD = 1000000007;

    private int mod(int n) {
        if (n < 0) {
            return n + MOD;
        }
        if (n >= MOD) {
            return n - MOD;
        }
        return n;
    }

    private void solve() {
        char[] s = in.next().toCharArray();
        char[] t = in.next().toCharArray();
        int n = s.length;
        int m = t.length;
        int[][] num = new int[n + 1][m + 1];
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                num[i][j + 1] = mod(num[i][j] + num[i][j + 1]);
                if (s[i] == t[j]) {
                    num[i + 1][j + 1] = mod(num[i][j] + num[i + 1][j + 1] + 1);
                    ans = mod(ans + num[i + 1][j + 1]);
                }
            }
        }
        out.println(ans);
    }

    @Override
    public void run() {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    public static void main(String[] args) {
        new A().run();
    }

    static class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public void close() {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                    return null;
                }
            }
            return st.nextToken();
        }

        public String nextLine() {
            try {
                st = null;
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public boolean hasNext() {
            if (st != null && st.hasMoreTokens()) {
                return true;
            }
            try {
                while (br.ready()) {
                    st = new StringTokenizer(br.readLine());
                    if (st != null && st.hasMoreTokens()) {
                        return true;
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return false;
        }
    }
}

import java.util.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class  test  {

	//ArrayList<Integer> lis = new ArrayList<Integer>();
	//ArrayList<String> lis = new ArrayList<String>();
	//ArrayList<test> lis = new ArrayList<test>();
//	static long sum=0;

public  static void main(String[] args) {
   Scanner sc =new Scanner(System.in);
   while(sc.hasNext()){
		 // =ni(sc)
	   String s=sc.next(),t=sc.next();
	   long r=0;
 	// db(s);
  	   int l=s.length(),ll=t.length();
	 int dp[][] = new int[l+1][ll+1];

	 for(int i=1; i<l+1 ; i++){
		 for(int u=1; u<ll+1 ; u++) {

		dp[i][u] = (  (s.charAt(i-1)==t.charAt(u-1) ? dp[i-1][u-1]+1 : 0) + dp[i][u-1]  ) %1000000007 ;
		//db( i,u,dp[i][u]);
		 }
	 }

	 for(int i=0; i<l+1 ; i++) r=(r+dp[i][ll])%1000000007;

	 System.out.println(r);

}

}

    static int ni(Scanner in){
	return in.nextInt();
 }

    static void db(Object... os){
	         System.err.println(Arrays.deepToString(os));

	}

}

/*class pr implements Comparable<pr>{
    int v,vv;
	pr(int v,int vv){
		this.v=v;
	    this.vv=vv;
	}

public int compareTo(pr x){

	if( v==x.v )return vv-x.vv;
	return -v+x.v;
}

}*/

import java.io.OutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskA {
    int MOD = 1000000007;
    public void solve(int testNumber, MyScanner in, PrintWriter out) {
        String s = in.next();
        String t = in.next();
        long[][] dp = new long[2][t.length()];
        int cur=0,nxt=1;
        long res =0 ;
        for (int i = 0; i < s.length(); i++) {
            long sum = 0;
            Arrays.fill(dp[nxt],0);
            for(int j=0;j<t.length();j++){
                if(t.charAt(j)==s.charAt(i)){
                    dp[nxt][j] = 1 + sum;
                    if(dp[nxt][j]>=MOD)dp[nxt][j] -= MOD;
                    res += dp[nxt][j];
                    if(res >= MOD)res -= MOD;
                }
                if(i>0 && t.charAt(j)==s.charAt(i-1)){
                    sum += dp[cur][j];
                    if(sum >= MOD)sum -= MOD;
                }
            }
            int tmp=cur;cur=nxt;nxt=tmp;
        }
        out.println(res);
    }
}

class MyScanner {
    private final InputStream in;
    public MyScanner(InputStream in){
        this.in = in;
    }

    char[] buf = new char[2000000];
    int strLen;
    public String next() {
        try {
            strLen = 0;
            int c;
            do{
                c = in.read();
                if(c==-1)throw new NoSuchElementException();
            }while(Character.isWhitespace(c));
            do {
                buf[strLen++] = (char)c;
                c = in.read();
            } while (c!=-1 && !Character.isWhitespace(c));
            return new String(buf,0,strLen);
        } catch (IOException e) {
            throw new NoSuchElementException();
        }
    }

    }

import java.io.*;
import java.util.*;
import java.math.*;

public class Seqs implements Runnable {
	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;
	Random rnd;

	int mod = 1000000007;

	int sum(int a, int b) {
		return (a + b) % mod;
	}

	void solve() throws IOException {
		String a = nextToken();
		String b = nextToken();

		int n = a.length(), m = b.length();

		int[][] d = new int[n + 1][m + 1];
		int[] sums = new int[m + 1];

		for(int i = 1; i <= n; i++) {
			char ac = a.charAt(i - 1);

			for(int j = 1; j <= m; j++) {
				char bc = b.charAt(j - 1);

				if(ac == bc) {
					int check = sums[j - 1];

					d[i][j] = sum(d[i][j], sum(check, 1));
				}
			}

			Arrays.fill(sums, 0);

			sums[0] = d[i][0];

			for(int j = 1; j <= m; j++) {
				sums[j] = sum(sums[j - 1], d[i][j]);
			}
		}

		/*for(int i = 0; i <= n; i++) {
			out.println(Arrays.toString(d[i]));
		}*/

		int res = 0;

		for(int i = 0; i <= n; i++) {
			for(int j = 0; j <= m; j++) {
				res = sum(res, d[i][j]);
			}
		}

		while(res < 0) {
			res += mod;
		}

		out.println(res);
	}

	public static void main(String[] args) {
		new Thread(null, new Seqs(), "solution", 1 << 24).start();
	}

	public void run() {
		try {
			final String className = this.getClass().getName().toLowerCase();

			try {
				in = new BufferedReader(new FileReader(className + ".in"));
				out = new PrintWriter(new FileWriter(className + ".out"));
			} catch (FileNotFoundException e) {
				in = new BufferedReader(new InputStreamReader(System.in));
				out = new PrintWriter(System.out);
			}

			rnd = new Random();

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(42);
		}
	}

	String nextToken() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String line = in.readLine();

			if (line == null)
				return null;

			st = new StringTokenizer(line);
		}

		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

import java.awt.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

import com.sun.org.apache.bcel.internal.generic.LLOAD;

/*
	br = new BufferedReader(new FileReader("input.txt"));
	pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
	br = new BufferedReader(new InputStreamReader(System.in));
	pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

 */

public class Main {
	private static BufferedReader br;
	private static StringTokenizer st;
	private static PrintWriter pw;

	static int[] dx = new int[]{-1,0,1,0};
	static int[] dy = new int[]{0,1,0,-1};

	public static void main(String[] args) throws IOException	{
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		//int qq = 1;
		int qq = Integer.MAX_VALUE;
		//int qq = readInt();
		final int MOD = 1000000007;
		for(int casenum = 1; casenum <= qq; casenum++)	{
			String a = nextToken();
			String b = nextToken();
			int[] dp = new int[a.length()+1];
			for(int i = 0; i < b.length(); i++)	{
				int[] next = new int[a.length()+1];
				for(int j = 0; j <= a.length(); j++)
					next[j] = dp[j];
				for(int j = 0; j < a.length(); j++)	{
					if(a.charAt(j) == b.charAt(i))	{
						next[j+1]++;
						next[j+1] += dp[j];
						if(next[j+1] >= MOD)
							next[j+1] -= MOD;
					}
				}
				dp = next;
			}
			int ret = 0;
			for(int out: dp)	{
				ret += out;
				if(ret >= MOD)	{
					ret -= MOD;
				}
			}
			pw.println(ret);
		}
		pw.close();
	}

	private static long readLong() throws IOException	{
		return Long.parseLong(nextToken());
	}

	private static double readDouble() throws IOException	{
		return Double.parseDouble(nextToken());
	}

	private static int readInt() throws IOException	{
		return Integer.parseInt(nextToken());
	}

	private static String nextToken() throws IOException	{
		while(st == null || !st.hasMoreTokens())	{
			if(!br.ready())	{
				pw.close();
				System.exit(0);
			}
			st = new StringTokenizer(br.readLine().trim());
		}
		return st.nextToken();
	}
}

import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.geom.*;

import static java.lang.Math.*;

public class Solution implements Runnable {

	static final int MOD = 1000000007;

	int d [][];
	boolean calc [][];

	String t, s;
	int n, m;

	int doIt (int i, int j) {
		if (i >= n || j >= m) return 0;
		if (calc [i][j]) return d[i][j];
		calc [i][j] = true;
		if (t.charAt(i) == s.charAt(j))
			d[i][j] = (d[i][j] + doIt(i + 1, j + 1) + 1) % MOD;
		d[i][j] = (d[i][j] + doIt(i, j + 1)) % MOD;
		return d[i][j];
	}

	public void solve () throws Exception {
		t = nextToken();
		s = nextToken();
		n = t.length();
		m = s.length();
		d = new int [n + 1][m + 1];
		calc = new boolean [n + 1][m + 1];
		int result = 0;
		for (int i = 0; i < n; i++) {
			result = (result + doIt(i, 0)) % MOD;
		}
		out.println(result);
	}

	final String fname = "";

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;

	private String nextToken () throws Exception {
		if (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}
		return st.nextToken();
	}

	private int nextInt () throws Exception {
		return Integer.parseInt(nextToken());
	}

	private long nextLong () throws Exception {
		return Long.parseLong(nextToken());
	}

	private double nextDouble () throws Exception {
		return Double.parseDouble(nextToken());
	}

	@Override
	public void run() {
		try {
			//in = new BufferedReader(new FileReader(fname+".in"));
			//out = new PrintWriter(new FileWriter(fname+".out"));
			in = new BufferedReader (new InputStreamReader(System.in));
			out = new PrintWriter (System.out);
			solve ();
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) {
		new Thread(null, new Solution(), "", 1<<25).start();
	}

}

import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;

public class A {
	Scanner sc = new Scanner(System.in);

	int M = 1000000007;

	void run() {
		char[] S = sc.next().toCharArray();
		char[] T = sc.next().toCharArray();
		int n = S.length, m = T.length;
		int[] crt = new int[m + 1];
		crt[0] = 1;
		int res = 0;
		for (int i = 0; i < n; i++) {
			int[] next = new int[m + 1];
			next[0] = 1;
			int sum = 0;
			for (int j = 0; j < m; j++) {
				sum += crt[j];
				if (sum >= M) sum -= M;
				if (S[i] == T[j]) {
					next[j + 1] = sum;
					res += sum;
					if (res >= M) res -= M;
				}
			}
			crt = next;
		}
		System.out.println(res);
	}

	void debug(Object...os) {
		System.err.println(deepToString(os));
	}

	public static void main(String[] args) {
		new A().run();
	}
}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Reader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A implements Runnable {

	char[] s;
	char[] t;
	static final int MOD = 1000000007;
	private void solve() throws NumberFormatException, IOException {
		String ss = in.next();
		String st = in.next();
		s = ss.toCharArray();
		t = st.toCharArray();
		int dp[][] = new int[s.length + 1][t.length + 1];
		for (int i = 0; i < s.length; i++) {
			for (int j = 1; j <= t.length; j++)
			{
				dp[i][j] = dp[i][j - 1];
				if (t[j - 1] == s[i])
					if (i > 0) {
						dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % MOD;
					} else {
						dp[i][j] = (dp[i][j] + 1) % MOD;
					}
			}

		}

		int sum = 0;
		for (int i = 0; i < s.length; i++)
		{
			sum = (sum + dp[i][t.length]) % MOD;
		}
		out.println(sum);
	}

	FastScanner in;
	PrintWriter out;

	class FastScanner {
		BufferedReader in;
		StringTokenizer st;

		public FastScanner(Reader reader) {
			in = new BufferedReader(reader);
		}

		private boolean hasNext() throws IOException {
			while (st == null || !st.hasMoreTokens()) {
				String line = in.readLine();
				if (line == null)
					return false;
				st = new StringTokenizer(line);
			}
			return true;
		}

		private String next() throws IOException {
			if (!hasNext()) {
				return null;
			} else {
				return st.nextToken();
			}
		}

		private int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}
	}

	public static void main(String[] args) {
		new A().run();
	}

	@Override
	public void run() {
		try {
			in = new FastScanner(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			out.flush();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

import java.util.*;
import java.io.*;
public class a {
    static long mod = 1000000007;
    static ArrayList<Integer>[] g;
public static void main(String[] args) throws IOException
{
    //Scanner input = new Scanner(new File("input.txt"));
    //PrintWriter out = new PrintWriter(new File("output.txt"));
  input.init(System.in);
  PrintWriter out  = new PrintWriter((System.out));
  String s = input.next(), t = input.next();
  int n = s.length(), m = t.length();
  int[][] dp = new int[n][m+1];
  for(int i = 1; i<m+1; i++) dp[0][i] = dp[0][i-1] + (s.charAt(0) == t.charAt(i-1) ? 1 : 0);
  for(int i = 1; i<n; i++)
      for(int j = 1; j<=m; j++)
      {
          char c1 = s.charAt(i), c2 = t.charAt(j-1);
          //out.println(i+" "+j+" "+c1+" "+c2);
          dp[i][j] = dp[i][j-1] + (c1==c2 ? 1+dp[i-1][j-1] : 0);
          dp[i][j] %= mod;
      }
  long res = 0;
//  for(int i = 0; i<n; i++)
//  {
//    for(int j = 0; j<=m; j++)
//        out.print(dp[i][j]+" ");
//    out.println();
//  }
  for(int i = 0; i<n; i++)
  {
      res = (res+dp[i][m])%mod;
  }
  out.println(res);

  out.close();
}
static long pow (long a, long p)
{
    if(p==0) return 1;
    if((p&1) == 0)
    {
        long sqrt = pow(a, p/2);
        return (sqrt*sqrt)%mod;
    }
    return (a*pow(a,p-1))%mod;
}
static class input {
  static BufferedReader reader;
  static StringTokenizer tokenizer;

  /** call this method to initialize reader for InputStream */
  static void init(InputStream input) {
      reader = new BufferedReader(
                   new InputStreamReader(input) );
      tokenizer = new StringTokenizer("");
  }

  /** get next word */
  static String next() throws IOException {
      while ( ! tokenizer.hasMoreTokens() ) {
          //TODO add check for eof if necessary
          tokenizer = new StringTokenizer(
                 reader.readLine() );
      }
      return tokenizer.nextToken();
  }

  static int nextInt() throws IOException {
      return Integer.parseInt( next() );
  }

  static double nextDouble() throws IOException {
      return Double.parseDouble( next() );
  }
  static long nextLong() throws IOException {
      return Long.parseLong( next() );
  }
  static String nextLine() throws IOException {
    return reader.readLine();
  }
}
}

import java.util.Scanner;

public class Prob163A {

	public static void main(String[] Args) {
		Scanner in = new Scanner(System.in);
		String s2 = in.next();
		String s1 = in.next();

		int mod = 1000000007;

		int[][] dp = new int[s1.length() + 1][s2.length() + 1];
		for (int i = 0; i < dp.length - 1; i++)
			for (int j = 0; j < dp[i].length - 1; j++)
				dp[i + 1][j + 1] = (dp[i][j + 1] + (s1.charAt(i) == s2
						.charAt(j) ? dp[i][j] + 1 : 0)) % mod;

		long answer = 0;
		for (int i = 0; i < dp[s1.length()].length; i++)
			answer = (answer + dp[s1.length()][i]) % mod;
		System.out.println(answer);
	}
}

import java.io.*;
import java.util.*;

public class Solution {

	private StringTokenizer st;
	private BufferedReader in;
	private PrintWriter out;

	public void solve() throws IOException {
		String a = next();
		String b = next();
		int n = a.length();
		int m = b.length();
		final int mod = 1000000007;
		int[][] d = new int[n + 1][m + 1];
		int ans = 0;
		for (int i = 0; i <= n; ++i) {
			d[i][0] = 1;
			for (int j = 0; j < m; ++j) {
				d[i][j + 1] = (d[i][j + 1] + d[i][j]) % mod;
				if (i < n && a.charAt(i) == b.charAt(j)) {
					d[i + 1][j + 1] = (d[i + 1][j + 1] + d[i][j]) % mod;
				}
			}
			ans = (ans + d[i][m]) % mod;
		}
		ans = (ans + mod - n - 1) % mod;
		out.println(ans);
	}

	public void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		eat("");

		solve();

		out.close();
	}

	void eat(String s) {
		st = new StringTokenizer(s);
	}

	String next() throws IOException {
		while (!st.hasMoreTokens()) {
			String line = in.readLine();
			if (line == null) {
				return null;
			}
			eat(line);
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public static void main(String[] args) throws IOException {
		Locale.setDefault(Locale.US);
		new Solution().run();
	}

}

import java.io.*;
import java.util.*;

public class Test {

	final String filename = new String("Test").toLowerCase();

	final int mod = 1000 * 1000 * 1000 + 7;

	void solve() throws Exception {
		String s1 = nextToken();
		String s2 = nextToken();
		int n = s1.length();
		int m = s2.length();
		int[][] dp = new int[n + 1][m + 1];
		dp[0][0] = 0;
		long ans = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {
				if (s1.charAt(i - 1) == s2.charAt(j - 1)) {
					dp[i][j] = 1 + dp[i - 1][j - 1];
				}
				dp[i][j] += dp[i][j - 1];
				dp[i][j] %= mod;
			}
		}
		for (int i = 0; i <= n; i++) {
			ans += dp[i][m];
			ans %= mod;
		}
		out.println(ans);
	}

	void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			//			in = new BufferedReader(new FileReader("input.txt"));
			//			out = new PrintWriter("output.txt");

			solve();

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	BufferedReader in;
	StringTokenizer st;
	PrintWriter out;

	String nextToken() throws Exception {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

	int nextInt() throws Exception {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws Exception {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws Exception {
		return Double.parseDouble(nextToken());
	}

	public static void main(String[] args) {
		new Test().run();
	}

}

import java.util.*;

public class A
{
   public static void main(String[] args)
   {
      new A(new FastScanner());
   }

   String[] sa;
   char[] as;
   char[] bs;
   int N, M;

   int hash(int b, int i, int j)
   {
      return b*N*M+i*M+j;
   }

   int MODO = 1000000007;
   int[][] next;

   int[] memo;
   int go(int b, int i, int j)
   {
      if ((i >= N)||(j >= M))
         return 0;

      int hv = hash(b,i,j);
      if (memo[hv] != -1)
         return memo[hv];
      int res = 0;
      if (b == 0) res = go(0,i+1,j);
      int nj = next[(int)(as[i]-'a')][j];
      if (nj < M) res = (res+1+go(1,i+1,nj+1))%MODO;
      res = (res+go(1,i,nj+1))%MODO;

      return memo[hv] = res;
   }

   public A(FastScanner in)
   {
      as = in.next().toCharArray();
      bs = in.next().toCharArray();
      N = as.length;
      M = bs.length;

      next = new int[26][M];
      for (int c=0; c<26; c++)
         Arrays.fill(next[c],M);
      for (int i=0; i<M; i++)
      {
         for (char c='a'; c<='z'; c++)
         {
            int id = (int)(c-'a');
            for (int j=i; j<M; j++)
            {
               if (bs[j] == c)
               {
                  next[id][i] = j;
                  break;
               }
            }
         }
      }

      memo = new int[2*N*M];
      Arrays.fill(memo,-1);
      System.out.println(go(0,0,0));
   }
}

class FastScanner{
    int nextInt(){
        try{
            int c=System.in.read();
            if(c==-1) return c;
            while(c!='-'&&(c<'0'||'9'<c)){
                c=System.in.read();
                if(c==-1) return c;
            }
            if(c=='-') return -nextInt();
            int res=0;
            do{
                res*=10;
                res+=c-'0';
                c=System.in.read();
            }while('0'<=c&&c<='9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    long nextLong(){
        try{
            int c=System.in.read();
            if(c==-1) return -1;
            while(c!='-'&&(c<'0'||'9'<c)){
                c=System.in.read();
                if(c==-1) return -1;
            }
            if(c=='-') return -nextLong();
            long res=0;
            do{
                res*=10;
                res+=c-'0';
                c=System.in.read();
            }while('0'<=c&&c<='9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    double nextDouble(){
        return Double.parseDouble(next());
    }

    String next(){
        try{
            StringBuilder res=new StringBuilder("");
            int c=System.in.read();
            while(Character.isWhitespace(c))
                c=System.in.read();
            do{
                res.append((char)c);
            }while(!Character.isWhitespace(c=System.in.read()));
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    String nextLine(){
        try{
            StringBuilder res=new StringBuilder("");
            int c=System.in.read();
            while(c=='\r'||c=='\n')
                c=System.in.read();
            do{
                res.append((char)c);
                c=System.in.read();
            }while(c!='\r'&&c!='\n');
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }
}

import static java.util.Arrays.fill;

import java.io.*;
import java.util.*;

public class A {

	private static void solve() throws IOException {
		String s = nextToken(), t = nextToken();
		int answer = get(s, t);
		out.println(answer);
	}

	static final int MOD = 1000000007;

	static int get(String s, String t) {
		int[] dp = new int[t.length() + 1];
		int[] next = new int[t.length() + 1];
		fill(dp, 1);
		long answer = 0;
		for (int sPos = 0; sPos < s.length(); sPos++) {
			char sCur = s.charAt(sPos);
			for (int tPos = 0; tPos < t.length(); tPos++) {
				char tCur = t.charAt(tPos);
				if (tCur == sCur) {
					next[tPos + 1] += dp[tPos];
					if (next[tPos + 1] >= MOD) {
						next[tPos + 1] -= MOD;
					}
				}
			}
			next[0] = 1;
			for (int i = 0; i < t.length(); i++) {
				next[i + 1] += next[i];
				if (next[i + 1] >= MOD) {
					next[i + 1] -= MOD;
				}
			}
			answer += next[t.length()] - 1;
			int[] tmp = dp;
			dp = next;
			next = tmp;
			fill(next, 0);
		}
		answer %= MOD;
		if (answer < 0) {
			answer += MOD;
		}
		return (int) answer;
	}

	public static void main(String[] args) {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(239);
		}
	}

	static BufferedReader br;
	static StringTokenizer st;
	static PrintWriter out;

	static String nextToken() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String line = br.readLine();
			if (line == null) {
				return null;
			}
			st = new StringTokenizer(line);
		}
		return st.nextToken();
	}

	static int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 *
 *
 * @author pttrung
 */
public class C {

    //   public static long x, y, gcd;
    public static int Mod = 1000000007;
    public static PrintWriter out;
    public static String s, t;
    public static int[][] dp;

    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner();
        out = new PrintWriter(System.out);
        //   System.out.println(Integer.MAX_VALUE);
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File("output.txt")));
        s = in.next();
        t = in.next();
        long result = 0;
        dp = new int[s.length()][t.length()];

        for (int i = s.length() - 1; i >= 0; i--) {
            // System.out.println(i + " " + j);
            for (int j = t.length() - 1; j >= 0; j--) {
                if (s.charAt(i) == t.charAt(j)) {
                    dp[i][j]++;
                    if (j + 1 < t.length() && i + 1 < s.length()) {
                        dp[i][j] += dp[i + 1][ j + 1];
                        dp[i][j] %= Mod;
                    }
                }
                if (j + 1 < t.length()) {
                    dp[i][j] += dp[i][j + 1];
                    dp[i][j] %= Mod;
                }
            }
            result += dp[i][0];
            result %= Mod;
        }

        out.println(result);
        out.close();
    }

    public static int cross(Point a, Point b) {
        int val = a.x * b.y - a.y * b.x;
        return val;
    }

    public static long pow(long a, long b) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2);
        if (b % 2 == 0) {
            return val * val;
        } else {
            return val * val * a;
        }
    }

    public static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(Point o) {
            if (x != o.x) {
                return x - o.x;
            } else {
                return y - o.y;
            }
        }
    }
//    public static void extendEuclid(long a, long b) {
//        if (b == 0) {
//            x = 1;
//            y = 0;
//            gcd = a;
//            return;
//        }
//        extendEuclid(b, a % b);
//        long x1 = y;
//        long y1 = x - (a / b) * y;
//        x = x1;
//        y = y1;
//
//    }

    public static class FT {

        int[] data;

        FT(int n) {
            data = new int[n];
        }

        public void update(int index, int value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public int get(int index) {
            int result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}

import java.util.Scanner;

public class P163A
{
	private static int arr[][];

	private static int solve(String s, String t, int a, int b)
	{
		if (a >= arr.length || b >= arr[0].length) return 0;
		if (arr[a][b] != 0) return arr[a][b];
		else
		{
			return arr[a][b] = (solve(s, t, a, b + 1) +
							(	(s.charAt(a) == t.charAt(b)) ? (solve(s, t, a + 1, b + 1) + 1) : 0))
							% 1000000007;
		}

	}

	public static void main(String[] args)
	{
		Scanner myScanner = new Scanner(System.in);
		String s = myScanner.nextLine();
		String t = myScanner.nextLine();
		arr = new int[s.length()][t.length()];
		int sum = 0;
		for (int i = 0; i < arr.length; i++)
		{
			sum = (sum + solve(s, t, i, 0)) % 1000000007;
		}
		System.out.println(sum);
	}
}

//package VkCup2012_Div_2;
// Valxon Yuldashev 25.09.2015,
//
//        \    /    /\    |         |
//         \  /    /__\   |         |
//          \/    /    \  |___|     |
//

import java.util.Scanner;

public class C {
public static void main(String[] args) {
     Scanner sc=new Scanner(System.in);
     char []s=sc.next().toCharArray();
     char [] a=sc.next().toCharArray();
     int [] d=new int['z'+1];
     int dp[][]=new int [5001][5001];
     for (int i = 0; i < a.length; i++) {
        d[a[i]]++;
    }
//   String g="";
     long javob=0;
     for (int i = 0; i < s.length; i++) {
         int summa=0;
        for (int j =0; j <a.length; j++) {
            if(s[i] == a[j]) {
                dp[i][j] = (1+summa)%1000000007;
                javob = (javob+dp[i][j])%1000000007;
              }
              if(i>0) summa+= dp[i-1][j];
              summa %= 1000000007;
        }
    }
     System.out.println(javob);
}

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author zodiacLeo
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC
    {
        private final int MOD = (int) 1e9 + 7;

        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            char s[] = in.next().toCharArray();
            char t[] = in.next().toCharArray();
            int dp[][] = new int[s.length][t.length];
            int sum[][] = new int[s.length][t.length];

            int result = 0;
            for (int i = 0; i < s.length; i++)
            {
                for (int j = 0; j < t.length; j++)
                {
                    if (s[i] == t[j])
                    {
                        dp[i][j] = 1;
                        if (i - 1 >= 0 && j - 1 >= 0)
                        {
                            dp[i][j] = mmd(dp[i][j] + sum[i - 1][j - 1]);
                        }
                    }
                    sum[i][j] = mmd(dp[i][j]);
                    if (j - 1 >= 0)
                    {
                        sum[i][j] = mmd(sum[i][j] + sum[i][j - 1]);
                    }
                    result = mmd(result + dp[i][j]);
                }
            }
            out.println(result);

        }

        public int mmd(int x)
        {
            return x >= MOD ? x - MOD : x;
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author zodiacLeo
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC
    {
        private final int MOD = (int) 1e9 + 7;

        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            String ss = in.next();
            String tt = in.next();
            int n = ss.length() + 1;
            int m = tt.length() + 1;

            char s[] = new char[n];
            char t[] = new char[m];
            for (int i = 1; i < n; i++)
            {
                s[i] = ss.charAt(i - 1);
            }
            for (int i = 1; i < m; i++)
            {
                t[i] = tt.charAt(i - 1);
            }

            int dp[][] = new int[n + 1][m + 1];
            int sum[][] = new int[n + 1][m + 1];

            int result = 0;
            for (int i = 1; i < n; i++)
            {
                for (int j = 1; j < m; j++)
                {
                    if (s[i] == t[j])
                    {
                        dp[i][j] = mmd(1 + sum[i - 1][j - 1]);
                    }
                    sum[i][j] = mmd(sum[i][j - 1] + dp[i][j]);
                    result = mmd(result + dp[i][j]);
                }
            }
            out.println(result);

        }

        public int mmd(int x)
        {
            return x >= MOD ? x - MOD : x;
        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    IIO io;

    Main(IIO io) {
        this.io = io;
    }

    public static void main(String[] args) throws IOException {

        ConsoleIO io = new ConsoleIO();
        Main m = new Main(io);
        m.solve();
        io.flush();

//        Tester test = new Tester();test.run();
    }

    public void solve() {
        char[] str = io.readLine().toCharArray();
        char[] seq = io.readLine().toCharArray();
        long mod = 1000000007;
        long res = 0;
        long[] prev = new long[seq.length];
        for (int i = 0; i < str.length; i++) {
            long[] cur = new long[seq.length];
            long acc = 0;
            int c1 = str[i];
            for (int j = 0; j < seq.length; j++) {
                if (seq[j] == c1) {
                    if (i > 0 && j > 0) acc += prev[j - 1];
                    acc++;
                }
                cur[j] = acc % mod;
            }
            res += cur[cur.length - 1];
            prev = cur;
        }
        io.writeLine(Long.toString(res % mod));
    }

}

class ConsoleIO extends BaseIO {
    BufferedReader br;
    PrintWriter out;
    public ConsoleIO(){
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }
    public void flush(){
        this.out.close();
    }
    public void writeLine(String s) {
        this.out.println(s);
    }
    public void writeInt(int a) {
        this.out.print(a);
        this.out.print(' ');
    }
    public void writeWord(String s){
        this.out.print(s);
    }
    public String readLine() {
        try {
            return br.readLine();
        }
        catch (Exception ex){
            return "";
        }
    }
    public int read(){
        try {
            return br.read();
        }
        catch (Exception ex){
            return -1;
        }
    }
}
abstract class BaseIO implements IIO {

    public long readLong() {
        return Long.parseLong(this.readLine());
    }

    public int readInt() {
        return Integer.parseInt(this.readLine());
    }

    public int[] readIntArray() {
        String line = this.readLine();
        String[] nums = line.split(" ");
        int[] res = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            res[i] = Integer.parseInt(nums[i]);
        }
        return res;
    }
    public long[] readLongArray() {
        String line = this.readLine();
        String[] nums = line.split(" ");
        long[] res = new long[nums.length];
        for (int i = 0; i < nums.length; i++) {
            res[i] = Long.parseLong(nums[i]);
        }
        return res;
    }
}
interface IIO {
    void writeLine(String s);
    void writeInt(int a);
    void writeWord(String s);
    String readLine();
    long readLong();
    int readInt();
    int read();
    int[] readIntArray();
    long[] readLongArray();
}

import java.io.*;

public class A163 {

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String s = in.readLine();
		String t = in.readLine();
		long r = (long) 1e9 + 7;
		int[][] d = new int[s.length()][t.length()];
		for (int i = s.length() - 1; i >= 0; i--) {
			for (int j = t.length() - 1; j >= 0; j--) {
				long tmp = 0;
				if (j != t.length() - 1) {
					tmp = d[i][j + 1];
				}
				if ((i != s.length() - 1) && (j != t.length() - 1)) {
					if (s.charAt(i) == t.charAt(j)) {
						tmp += d[i + 1][j + 1] + 1;
					}
				} else {
					if (s.charAt(i) == t.charAt(j)) {
						tmp++;
					}
				}
				d[i][j] = (int) (tmp % r);
			}

		}
		long ans = 0;
		for (int i = 0; i < s.length(); i++) {
			ans += (long) d[i][0] % r;
			ans %= r;
		}
		System.out.println(ans);
		in.close();
	}

}

import java.util.Scanner;

public class A {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        int n = a.length(), m = b.length();
        int[][]dp = new int[n+1][m+1];
        int p = (int) (1e9+7);
        for (int i = n-1; i >= 0; i--) {
            for (int j = m-1; j >= 0; j--) {
                dp[i][j] = dp[i][j+1];
                if (a.charAt(i)==b.charAt(j))
                    dp[i][j] = (dp[i][j]+dp[i+1][j+1]+1) % p;
            }
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            ans = (ans+dp[i][0]) % p;
        }
        System.out.println(ans);
    }
}

import java.util.Arrays;
import java.util.Scanner;
public class A {
	static final int MOD = 1000000007;
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String S = s.next(), T = s.next();
		int SL = S.length(), TL = T.length();
		int[][] dp = new int[SL][TL];
		// remove the empty-empty case later
		for (int i = 0; i < SL; i++) {
			int[] ct = new int[26];
			for (int j = 0; j < TL; j++) {
				int chat = T.charAt(j)-'a';
				ct[chat]++;
				int ans = 0;
				if (S.charAt(i)==T.charAt(j)) {
					if (i > 0 && j > 0) ans = dp[i-1][j-1];
					if (j > 0) ans += dp[i][j-1];
					ans += 1;
					ans %= MOD;
				} else {
					if (j > 0) ans = dp[i][j-1];
				}
				dp[i][j] = ans;
			}
		}
		int ans = 0;
		for (int i = 0; i < SL; i++) {
			ans += dp[i][TL-1];
			ans %= MOD;
		}
		System.out.println(ans);
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

        a = r.readLine().toCharArray();
        b = r.readLine().toCharArray();

        for(int[] i : DP)
            Arrays.fill(i, -1);

        int ret = 0;
        for(int s = 0; s < a.length; s++){
            ret += go(s, 0);
            ret %= mod;
        }

        System.out.println(ret);
    }
    static char[] a, b;
    static int[][] DP = new int[5001][5001];
    static int mod = 1000000007;
    private static int go(int i, int j) {
        if(i >= a.length || j >= b.length) return 0;

        if(DP[i][j] != -1)return DP[i][j];

        if(a[i] == b[j]){
            return DP[i][j] = (1 + go(i + 1, j + 1) + go(i, j + 1)) % mod;
        }else{
            return DP[i][j] = go(i, j + 1);
        }
    }
}

import java.util.*;
import java.io.*;

public class CF170A {
    static Scanner in;
    static PrintWriter out;

    public static void main(String[] args) {
        in = new Scanner(System.in);
        out = new PrintWriter(System.out);

        String s = in.next();
        String t = in.next();
        int slength = s.length(), tlength = t.length();

        int dp[][] = new int[2][tlength+1];

        int tot = 0;
        for (int i = 1; i <= slength; i++) {
            for (int j = 1; j <= tlength; j++) {
                int ct = dp[i%2][j-1];
                if (s.charAt(i-1) == t.charAt(j-1)) {
                    ct += 1;
                    ct += dp[(i-1)%2][j-1];
                }
                dp[i%2][j] = ct % (1000 * 1000 * 1000 + 7);
            }
            tot += dp[i%2][tlength];
            tot %= 1000 * 1000 * 1000 + 7;
        }

        out.println(tot);
        out.flush();
    }
}

import java.util.*;
import java.io.*;

//import java.math.*;

public class SolA implements Runnable {
	public static void main(String[] args) {
		new Thread(new SolA()).start();
	}

	@Override
	public void run() {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	boolean eof = false;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return "0";
			}
		}
		return st.nextToken();
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	class RSQ {
		int[] a;
		int n;

		RSQ(int m) {
			n = 1;
			while (n < m) {
				n *= 2;
			}
			a = new int[2 * n];
		}

		void add(int x, int v) {
			x += n;
			while (x >= 1) {
				a[x] = (a[x] + v) % MOD;
				x /= 2;
			}
		}

		int sum(int l, int r, int ll, int rr, int x) {
			if (rr < l || r < ll) return 0;
			if (l <= ll && rr <= r) return a[x];
			return (sum(l, r, ll, (ll + rr) / 2, 2 * x) + sum(l, r, (ll + rr) / 2 + 1, rr, 2 * x + 1)) % MOD;
		}

		int sum(int l, int r) {
			return sum(l, r, 0, n - 1, 1);
		}
	}
	int MOD = 1000000007;

	void solve() {
		char[] s = nextToken().toCharArray();
		char[] t = nextToken().toCharArray();
//		{
//			int tt = 1000;
//			s = new char[tt];
//			t = new char[tt];
//			Arrays.fill(s, 'a');
//			Arrays.fill(t, 'a');
//		}
		int n = s.length;
		int m = t.length;
//		RSQ rsq = new RSQ(m + 1);
//		RSQ nrsq = new RSQ(m + 1);
//		rsq.add(0, 1);
//		nrsq.a = rsq.a.clone();
		int ans = 0;
		int[] a = new int[m + 1];
		int[] b = new int[m + 1];
		Arrays.fill(a, 1);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < b.length; j++) {
//				nrsq.a[j] = 0;
				b[j] = 0;
			}
			b[0] = 1;
//			nrsq.add(0, 1);
			for (int j = 0; j < m; j++) {
				if (s[i] == t[j]) {
					b[j + 1] = (b[j + 1] + a[j]) % MOD;
//					nrsq.add(j + 1, rsq.sum(0, j));
				}
			}
			a[0] = b[0];
			for (int j = 1; j < b.length; j++) {
				a[j] = (b[j] + a[j - 1]) % MOD;
			}
//				for (int j = 0; j < nrsq.a.length; j++) {
//				rsq.a[j] = nrsq.a[j];
//			}
			ans = ((ans + a[m] - 1) % MOD + MOD) % MOD;
//			ans = (ans + rsq.sum(1, m)) % MOD;
		}
		out.println(ans);
	}
}

import java.io.*;
import java.util.*;
import java.math.*;

public class Main
{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer tokenizer=null;

	public static void main(String[] args) throws IOException
	{
		new Main().execute();
	}

	void debug(Object...os)
	{
		System.out.println(Arrays.deepToString(os));
	}

	int ni() throws IOException
	{
		return Integer.parseInt(ns());
	}

	long nl() throws IOException
	{
		return Long.parseLong(ns());
	}

	double nd() throws IOException
	{
		return Double.parseDouble(ns());
	}

	String ns() throws IOException
	{
		while (tokenizer == null || !tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(br.readLine());
		return tokenizer.nextToken();
	}

	String nline() throws IOException
	{
		tokenizer=null;
		return br.readLine();
	}

	//Main Code starts Here
	int totalCases, testNum;
	int m,n;
	int mod = 1000000007;
	void execute() throws IOException
	{
		totalCases = 1;
		for(testNum = 1; testNum <= totalCases; testNum++)
		{
			input();
			solve();
		}
	}
	int[][] dp;
	void solve()
	{
		dp = new int[n+1][m+1];
		for(int i = 1; i<=n;i++)
			for(int j = 1;j<=m;j++)
			{
				if(a.charAt(i-1)==b.charAt(j-1))
					dp[i][j]=(dp[i-1][j-1]+dp[i][j-1]+1)%mod;
				else
					dp[i][j] = dp[i][j-1];

				//debug(i,j,dp[i][j]);
			}
		long count=0;

		for(int i = 0 ;i<=n;i++)
			count=(count+dp[i][m])%mod;
		System.out.println(count);
	}

	void printarr(int [] a,int b)
	{
		for(int i = 0;i<=b;i++)
		{
			if(i==0)
				System.out.print(a[i]);
			else
				System.out.print(" "+a[i]);
		}
		System.out.println();
	}
	String a,b;
	boolean input() throws IOException
	{
		a = nline();
		b = nline();

		n = a.length();
		m = b.length();
		return true;
	}
}

import java.io.*;
import java.util.*;

public class CF_163A {
	final static int N = 5010;
	final static long md = 1000000007;
	static long [][] d = new long [2][N];
	static String s, t;
	static int sn, tn;

	public static void main(String[] args) {
		Scanner in = new Scanner (new InputStreamReader (System.in) );
		int cur = 1, last = 0;
		s = in.next (); sn = s.length();
		t = in.next (); tn = t.length();
		long ans = 0;
		for (int i = 1; i <= sn; i++) {
			Arrays.fill (d[cur], 0);
			for (int j = 1; j <= tn; j++)
				d[cur][j] = (d[cur][j] + d[cur][j-1] + (s.charAt(i-1) == t.charAt(j-1)? d[last][j-1] + 1 : 0)) % md;
			ans = (ans + d[cur][tn]) % md;
			cur ^= 1; last ^= 1;
		}
		System.out.println (ans);
	}

}

import java.util.Scanner;

public class A_Substring_and_Subsequence {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.next();
        String s2 = sc.next();
        int [][]dp = new int [s1.length()+1][s2.length()+1];
        int mod = (int)(1e9)+7;
        for (int i = s1.length()-1; i >=0; i--) {
            for (int j = s2.length()-1; j >=0; j--) {
                dp[i][j] = dp[i][j+1];
                if (s1.charAt(i) == s2.charAt(j)) dp[i][j] = (dp[i][j]+dp[i+1][j+1]+1)%mod;
            }
        }
        int ans = 0;
        for (int i = 0; i <s1.length(); i++) {
            ans = (ans+dp[i][0])%mod;
        }
        System.out.println(ans);
    }
}

import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author AlexFetisov
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    private static final int MOD = (int) 1e9 + 7;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        char[] s = in.nextString().toCharArray();
        char[] t = in.nextString().toCharArray();
        int n = s.length;
        int m = t.length;
        int[][] dp = new int[n + 1][m + 1];
        int[] sum = new int[m];
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                if (s[i] == t[j]) {
                    dp[i][j] = 1;
                    if (i != 0 && j != 0) {
                        dp[i][j] += sum[j-1];
                    }
                    if (dp[i][j] >= MOD) {
                        dp[i][j] -= MOD;
                    }
                }
            }
            Arrays.fill(sum, 0);
            for (int j = 0; j < m; ++j) {
                if (j != 0) {
                    sum[j] = sum[j-1];
                }
                if (s[i] == t[j]) {
                    sum[j] += dp[i][j];
                    if (sum[j] >= MOD) {
                        sum[j] -= MOD;
                    }
                }
            }
        }
        int res = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                res += dp[i][j];
                if (res >= MOD) {
                    res -= MOD;
                }
            }
        }
        out.println(res);
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer stt;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    public String nextString() {
        while (stt == null || !stt.hasMoreTokens()) {
            stt = new StringTokenizer(nextLine());
        }
        return stt.nextToken();
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.stream.Stream;

public class Main implements Runnable {
	static final double time = 1e9;
	static final int MOD = (int) 1e9 + 7;
	static final long mh = Long.MAX_VALUE;
	static final Reader in = new Reader();
	static final PrintWriter out = new PrintWriter(System.out);
	StringBuilder answer = new StringBuilder();
	long start = System.nanoTime();
	public static void main(String[] args) {
		new Thread(null, new Main(), "persefone", 1 << 28).start();
	}

	@Override
	public void run() {

		solve();
		printf();
		long elapsed = System.nanoTime() - start;
//		out.println("stamp : " + elapsed / time);
//		out.println("stamp : " + TimeUnit.SECONDS.convert(elapsed, TimeUnit.NANOSECONDS));
		close();
	}

	void solve() {
		char[] s = in.next().toCharArray();
		char[] t = in.next().toCharArray();
		int n = s.length, m = t.length;
		int[][] f = new int[n + 1][m + 1];
		long ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				f[i + 1][j + 1] = f[i + 1][j];
				if (s[i] == t[j])
					f[i + 1][j + 1] = (f[i + 1][j + 1] + f[i][j] + 1) % MOD;
			}
			ans = (ans + f[i + 1][m]) % MOD;
		}
		printf(ans);
	}

	public interface Hash {
		public void computeHashArray();
		public void computeModArray();

	}

	class StringHash implements Hash {
		// length of string s
		private final long MH = Long.MAX_VALUE;
		private int n;
		private char[] ch;
		private long[] hash, mod;
		StringHash(char[] ch) {
			this.ch = ch;
			n = ch.length;
			hash = new long[n + 1];
			mod = new long[n + 1];
			computeHashArray();
			computeModArray();
		}

		StringHash(String s) {
			this(s.toCharArray());
		}

		StringHash(CharSequence s) {
			this(s.toString());
		}

		@Override
		public void computeModArray() {
			mod[0] = 1;
			for (int i = 1; i <= n; i++) mod[i] = (mod[i - 1] * 53) % MH;
		}

		@Override
		public void computeHashArray() {
			for (int i = 0; i < n; i++) hash[i + 1] = (hash[i] * 53 + ch[i] - 'a') % MH;
		}

		public long getHash(int i, int j) {
			return (hash[j] - hash[i] * mod[j - i] + MH * MH) % MH;
		}

		public long getHash(String s) {
			long h = 0;
			for (int i = 0; i < s.length(); i++) h = (h * 53 + s.charAt(i) - 'a') % MH;
			return h;
		}

		public long[] getHashArray() { return hash; }
		public long[] getModArray() { return mod; }
	}

	public interface Manacher {
		public void oddPalindrome();
		public void evenPalindrome();
	}

	class Palindrome implements Manacher {
		private int n;
		private char[] ch;
		private int[] oddPal, evenPal;
		public Palindrome() {}
		public Palindrome(String s) {
			this(s.toCharArray());
		}
		public Palindrome(char[] ch) {
			this.ch = ch;
			n = ch.length;
			oddPal = new int[ch.length];
			evenPal = new int[ch.length];
			oddPalindrome();
			evenPalindrome();
		}

		@Override
		public void oddPalindrome() {
			for (int i = 0, l = 0, r = -1; i < n; i++) {
				int k = i > r ? 1 : Math.min(oddPal[r + l - i], r - i);
				while (0 <= i - k && i + k < n && ch[i - k] == ch[i + k]) k++;
				oddPal[i] = k--;
				if (i + k > r) {
					l = i - k;
					r = i + k;
				}
			}
		}
		@Override
		public void evenPalindrome() {
			for (int i = 0, l = 0, r = -1; i < n; i++) {
				int k = i > r ? 0 : Math.min(evenPal[r + l - i + 1], r - i + 1);
				while (0 <= i - k - 1 && i + k < n && ch[i - k - 1] == ch[i + k]) k++;
				evenPal[i] = k--;
				if (i + k > r) {
					l = i - k - 1;
					r = i + k;
				}
			}
		}
	}

	void printf() {
		out.print(answer);
	}

	void close() {
		out.close();
	}

	void printf(Stream<?> str) {
		str.forEach(o -> add(o, " "));
		add("\n");
	}

	void printf(Object... obj) {
		printf(false, obj);
	}

	void printfWithDescription(Object... obj) {
		printf(true, obj);
	}

	private void printf(boolean b, Object... obj) {

		if (obj.length > 1) {
			for (int i = 0; i < obj.length; i++) {
				if (b) add(obj[i].getClass().getSimpleName(), " - ");
				if (obj[i] instanceof Collection<?>) {
					printf((Collection<?>) obj[i]);
				} else if (obj[i] instanceof int[][]) {
					printf((int[][])obj[i]);
				} else if (obj[i] instanceof long[][]) {
					printf((long[][])obj[i]);
				} else if (obj[i] instanceof double[][]) {
					printf((double[][])obj[i]);
				} else printf(obj[i]);
			}
			return;
		}

		if (b) add(obj[0].getClass().getSimpleName(), " - ");
		printf(obj[0]);
	}

	void printf(Object o) {
		if (o instanceof int[])
			printf(Arrays.stream((int[]) o).boxed());
		else if (o instanceof char[])
			printf(new String((char[]) o));
		else if (o instanceof long[])
			printf(Arrays.stream((long[]) o).boxed());
		else if (o instanceof double[])
			printf(Arrays.stream((double[]) o).boxed());
		else if (o instanceof boolean[]) {
			for (boolean b : (boolean[]) o) add(b, " ");
			add("\n");
		}
		else
			add(o, "\n");
	}

	void printf(int[]... obj) {
		for (int i = 0; i < obj.length; i++) printf(obj[i]);
	}

	void printf(long[]... obj) {
		for (int i = 0; i < obj.length; i++) printf(obj[i]);
	}

	void printf(double[]... obj) {
		for (int i = 0; i < obj.length; i++) printf(obj[i]);
	}

	void printf(boolean[]... obj) {
		for (int i = 0; i < obj.length; i++) printf(obj[i]);
	}

	void printf(Collection<?> col) {
		printf(col.stream());
	}

	<T, K> void add(T t, K k) {
		if (t instanceof Collection<?>) {
			((Collection<?>) t).forEach(i -> add(i, " "));
		} else if (t instanceof Object[]) {
			Arrays.stream((Object[]) t).forEach(i -> add(i, " "));
		} else
			add(t);
		add(k);
	}

	<T> void add(T t) {
		answer.append(t);
	}

	@SuppressWarnings("unchecked")
	<T extends Comparable<? super T>> T min(T... t) {
		if (t.length == 0)
			return null;
		T m = t[0];
		for (int i = 1; i < t.length; i++)
			if (t[i].compareTo(m) < 0)
				m = t[i];
		return m;
	}

	@SuppressWarnings("unchecked")
	<T extends Comparable<? super T>> T max(T... t) {
		if (t.length == 0)
			return null;
		T m = t[0];
		for (int i = 1; i < t.length; i++)
			if (t[i].compareTo(m) > 0)
				m = t[i];
		return m;
	}

	int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	// c = gcd(a, b) -> extends gcd method: ax + by = c <----> (b % a)p + q = c;
	int[] ext_gcd(int a, int b) {
		if (b == 0) return new int[] {a, 1, 0 };
		int[] vals = ext_gcd(b, a % b);
		int d = vals[0]; // gcd
	    int p = vals[2]; //
		int q = vals[1] - (a / b) * vals[2];
		return new int[] { d, p, q };
	}

	// find any solution of the equation: ax + by = c using extends gcd
	boolean find_any_solution(int a, int b, int c, int[] root) {
		int[] vals = ext_gcd(Math.abs(a), Math.abs(b));
		if (c % vals[0] != 0) return false;
		printf(vals);
		root[0] = c * vals[1] / vals[0];
		root[1] = c * vals[2] / vals[0];
		if (a < 0) root[0] *= -1;
		if (b < 0) root[1] *= -1;
		return true;
	}

	int mod(int x) { return x % MOD; }

	int mod(int x, int y) { return mod(mod(x) + mod(y)); }

	long mod(long x) { return x % MOD; }

	long mod (long x, long y) { return mod(mod(x) + mod(y)); }

	int lw(long[] f, int l, int r, long k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (f[m] >= k) r = m - 1; else l = m + 1;
		}
		return l;
	}

	int up(long[] f, int l, int r, long k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (f[m] > k) r = m - 1; else l = m + 1;
		}
		return l;
	}

	int lw(int[] f, int l, int r, int k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (f[m] >= k) r = m - 1; else l = m + 1;
		}
		return l;
	}

	int up(int[] f, int l, int r, int k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (f[m] > k) r = m - 1; else l = m + 1;
		}
		return l;
	}

	long calc(int base, int exponent) {
		if (exponent == 0) return 1;
		long m = calc(base, exponent >> 1);
		if (exponent % 2 == 0) return m * m % MOD;
		return base * m * m % MOD;
	}

	long power(int base, int exponent) {
		if (exponent == 0) return 1;
		long m = power(base, exponent >> 1);
		if (exponent % 2 == 0) return m * m;
		return base * m * m;
	}

	void swap(int[] a, int i, int j) {
		a[i] ^= a[j];
		a[j] ^= a[i];
		a[i] ^= a[j];
	}

	void swap(long[] a, int i, int j) {
		long tmp = a[i];
		a[i] = a[j];
		a[j] = tmp;
	}

	static class Pair<K extends Comparable<? super K>, V extends Comparable<? super V>>
			implements Comparable<Pair<K, V>> {
		private K k;
		private V v;

		Pair() {}

		Pair(K k, V v) {
			this.k = k;
			this.v = v;
		}

		K getK() { return k; }

		V getV() { return v; }

		void setK(K k) { this.k = k; }

		void setV(V v) { this.v = v; }

		void setKV(K k, V v) {
			this.k = k;
			this.v = v;
		}

		@SuppressWarnings("unchecked")
		@Override
		public boolean equals(Object o) {
			if (this == o) return true;
			if (o == null || !(o instanceof Pair)) return false;
			Pair<K, V> p = (Pair<K, V>) o;
			return k.compareTo(p.k) == 0 && v.compareTo(p.v) == 0;
		}

		@Override
		public int hashCode() {
			int hash = 31;
			hash = hash * 89 + k.hashCode();
			hash = hash * 89 + v.hashCode();
			return hash;
		}

		@Override
		public int compareTo(Pair<K, V> pair) {
			return k.compareTo(pair.k) == 0 ? v.compareTo(pair.v) : k.compareTo(pair.k);
		}

		@Override
		public Pair<K, V> clone() {
			return new Pair<K, V>(this.k, this.v);
		}

		@Override
		public String toString() {
			return String.valueOf(k).concat(" ").concat(String.valueOf(v)).concat("\n");
		}
	}

	static class Reader {
		private BufferedReader br;
		private StringTokenizer st;

		Reader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			try {
				while (st == null || !st.hasMoreTokens()) {
					st = new StringTokenizer(br.readLine());
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++)
				arr[i] = nextInt();
			return arr;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String s = "";
			try {
				s = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return s;
		}
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.stream.Stream;

public class Main implements Runnable {
	static final double time = 1e9;
	static final int MOD = (int) 1e9 + 7;
	static final long mh = Long.MAX_VALUE;
	static final Reader in = new Reader();
	static final PrintWriter out = new PrintWriter(System.out);
	StringBuilder answer = new StringBuilder();
	long start = System.nanoTime();
	public static void main(String[] args) {
		new Thread(null, new Main(), "persefone", 1 << 28).start();
	}

	@Override
	public void run() {

		solve();
		printf();
		long elapsed = System.nanoTime() - start;
//		out.println("stamp : " + elapsed / time);
//		out.println("stamp : " + TimeUnit.SECONDS.convert(elapsed, TimeUnit.NANOSECONDS));
		close();
	}

	void solve() {
		char[] s = " ".concat(in.next()).toCharArray();
		char[] t = " ".concat(in.next()).toCharArray();
		int n = s.length - 1, m = t.length - 1;
		int[][] f = new int[n + 1][m + 1];
		long ans = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {
				f[i][j] = f[i][j - 1];
				if (s[i] == t[j])
					f[i][j] = (f[i][j] + f[i - 1][j - 1] + 1) % MOD;
			}
			ans = (ans + f[i][m]) % MOD;
		}
		printf(ans);
	}

	public interface Hash {
		public void computeHashArray();
		public void computeModArray();

	}

	class StringHash implements Hash {
		// length of string s
		private final long MH = Long.MAX_VALUE;
		private int n;
		private char[] ch;
		private long[] hash, mod;
		StringHash(char[] ch) {
			this.ch = ch;
			n = ch.length;
			hash = new long[n + 1];
			mod = new long[n + 1];
			computeHashArray();
			computeModArray();
		}

		StringHash(String s) {
			this(s.toCharArray());
		}

		StringHash(CharSequence s) {
			this(s.toString());
		}

		@Override
		public void computeModArray() {
			mod[0] = 1;
			for (int i = 1; i <= n; i++) mod[i] = (mod[i - 1] * 53) % MH;
		}

		@Override
		public void computeHashArray() {
			for (int i = 0; i < n; i++) hash[i + 1] = (hash[i] * 53 + ch[i] - 'a') % MH;
		}

		public long getHash(int i, int j) {
			return (hash[j] - hash[i] * mod[j - i] + MH * MH) % MH;
		}

		public long getHash(String s) {
			long h = 0;
			for (int i = 0; i < s.length(); i++) h = (h * 53 + s.charAt(i) - 'a') % MH;
			return h;
		}

		public long[] getHashArray() { return hash; }
		public long[] getModArray() { return mod; }
	}

	public interface Manacher {
		public void oddPalindrome();
		public void evenPalindrome();
	}

	class Palindrome implements Manacher {
		private int n;
		private char[] ch;
		private int[] oddPal, evenPal;
		public Palindrome() {}
		public Palindrome(String s) {
			this(s.toCharArray());
		}
		public Palindrome(char[] ch) {
			this.ch = ch;
			n = ch.length;
			oddPal = new int[ch.length];
			evenPal = new int[ch.length];
			oddPalindrome();
			evenPalindrome();
		}

		@Override
		public void oddPalindrome() {
			for (int i = 0, l = 0, r = -1; i < n; i++) {
				int k = i > r ? 1 : Math.min(oddPal[r + l - i], r - i);
				while (0 <= i - k && i + k < n && ch[i - k] == ch[i + k]) k++;
				oddPal[i] = k--;
				if (i + k > r) {
					l = i - k;
					r = i + k;
				}
			}
		}
		@Override
		public void evenPalindrome() {
			for (int i = 0, l = 0, r = -1; i < n; i++) {
				int k = i > r ? 0 : Math.min(evenPal[r + l - i + 1], r - i + 1);
				while (0 <= i - k - 1 && i + k < n && ch[i - k - 1] == ch[i + k]) k++;
				evenPal[i] = k--;
				if (i + k > r) {
					l = i - k - 1;
					r = i + k;
				}
			}
		}
	}

	void printf() {
		out.print(answer);
	}

	void close() {
		out.close();
	}

	void printf(Stream<?> str) {
		str.forEach(o -> add(o, " "));
		add("\n");
	}

	void printf(Object... obj) {
		printf(false, obj);
	}

	void printfWithDescription(Object... obj) {
		printf(true, obj);
	}

	private void printf(boolean b, Object... obj) {

		if (obj.length > 1) {
			for (int i = 0; i < obj.length; i++) {
				if (b) add(obj[i].getClass().getSimpleName(), " - ");
				if (obj[i] instanceof Collection<?>) {
					printf((Collection<?>) obj[i]);
				} else if (obj[i] instanceof int[][]) {
					printf((int[][])obj[i]);
				} else if (obj[i] instanceof long[][]) {
					printf((long[][])obj[i]);
				} else if (obj[i] instanceof double[][]) {
					printf((double[][])obj[i]);
				} else printf(obj[i]);
			}
			return;
		}

		if (b) add(obj[0].getClass().getSimpleName(), " - ");
		printf(obj[0]);
	}

	void printf(Object o) {
		if (o instanceof int[])
			printf(Arrays.stream((int[]) o).boxed());
		else if (o instanceof char[])
			printf(new String((char[]) o));
		else if (o instanceof long[])
			printf(Arrays.stream((long[]) o).boxed());
		else if (o instanceof double[])
			printf(Arrays.stream((double[]) o).boxed());
		else if (o instanceof boolean[]) {
			for (boolean b : (boolean[]) o) add(b, " ");
			add("\n");
		}
		else
			add(o, "\n");
	}

	void printf(int[]... obj) {
		for (int i = 0; i < obj.length; i++) printf(obj[i]);
	}

	void printf(long[]... obj) {
		for (int i = 0; i < obj.length; i++) printf(obj[i]);
	}

	void printf(double[]... obj) {
		for (int i = 0; i < obj.length; i++) printf(obj[i]);
	}

	void printf(boolean[]... obj) {
		for (int i = 0; i < obj.length; i++) printf(obj[i]);
	}

	void printf(Collection<?> col) {
		printf(col.stream());
	}

	<T, K> void add(T t, K k) {
		if (t instanceof Collection<?>) {
			((Collection<?>) t).forEach(i -> add(i, " "));
		} else if (t instanceof Object[]) {
			Arrays.stream((Object[]) t).forEach(i -> add(i, " "));
		} else
			add(t);
		add(k);
	}

	<T> void add(T t) {
		answer.append(t);
	}

	@SuppressWarnings("unchecked")
	<T extends Comparable<? super T>> T min(T... t) {
		if (t.length == 0)
			return null;
		T m = t[0];
		for (int i = 1; i < t.length; i++)
			if (t[i].compareTo(m) < 0)
				m = t[i];
		return m;
	}

	@SuppressWarnings("unchecked")
	<T extends Comparable<? super T>> T max(T... t) {
		if (t.length == 0)
			return null;
		T m = t[0];
		for (int i = 1; i < t.length; i++)
			if (t[i].compareTo(m) > 0)
				m = t[i];
		return m;
	}

	int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	// c = gcd(a, b) -> extends gcd method: ax + by = c <----> (b % a)p + q = c;
	int[] ext_gcd(int a, int b) {
		if (b == 0) return new int[] {a, 1, 0 };
		int[] vals = ext_gcd(b, a % b);
		int d = vals[0]; // gcd
	    int p = vals[2]; //
		int q = vals[1] - (a / b) * vals[2];
		return new int[] { d, p, q };
	}

	// find any solution of the equation: ax + by = c using extends gcd
	boolean find_any_solution(int a, int b, int c, int[] root) {
		int[] vals = ext_gcd(Math.abs(a), Math.abs(b));
		if (c % vals[0] != 0) return false;
		printf(vals);
		root[0] = c * vals[1] / vals[0];
		root[1] = c * vals[2] / vals[0];
		if (a < 0) root[0] *= -1;
		if (b < 0) root[1] *= -1;
		return true;
	}

	int mod(int x) { return x % MOD; }

	int mod(int x, int y) { return mod(mod(x) + mod(y)); }

	long mod(long x) { return x % MOD; }

	long mod (long x, long y) { return mod(mod(x) + mod(y)); }

	int lw(long[] f, int l, int r, long k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (f[m] >= k) r = m - 1; else l = m + 1;
		}
		return l;
	}

	int up(long[] f, int l, int r, long k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (f[m] > k) r = m - 1; else l = m + 1;
		}
		return l;
	}

	int lw(int[] f, int l, int r, int k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (f[m] >= k) r = m - 1; else l = m + 1;
		}
		return l;
	}

	int up(int[] f, int l, int r, int k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (f[m] > k) r = m - 1; else l = m + 1;
		}
		return l;
	}

	long calc(int base, int exponent) {
		if (exponent == 0) return 1;
		long m = calc(base, exponent >> 1);
		if (exponent % 2 == 0) return m * m % MOD;
		return base * m * m % MOD;
	}

	long power(int base, int exponent) {
		if (exponent == 0) return 1;
		long m = power(base, exponent >> 1);
		if (exponent % 2 == 0) return m * m;
		return base * m * m;
	}

	void swap(int[] a, int i, int j) {
		a[i] ^= a[j];
		a[j] ^= a[i];
		a[i] ^= a[j];
	}

	void swap(long[] a, int i, int j) {
		long tmp = a[i];
		a[i] = a[j];
		a[j] = tmp;
	}

	static class Pair<K extends Comparable<? super K>, V extends Comparable<? super V>>
			implements Comparable<Pair<K, V>> {
		private K k;
		private V v;

		Pair() {}

		Pair(K k, V v) {
			this.k = k;
			this.v = v;
		}

		K getK() { return k; }

		V getV() { return v; }

		void setK(K k) { this.k = k; }

		void setV(V v) { this.v = v; }

		void setKV(K k, V v) {
			this.k = k;
			this.v = v;
		}

		@SuppressWarnings("unchecked")
		@Override
		public boolean equals(Object o) {
			if (this == o) return true;
			if (o == null || !(o instanceof Pair)) return false;
			Pair<K, V> p = (Pair<K, V>) o;
			return k.compareTo(p.k) == 0 && v.compareTo(p.v) == 0;
		}

		@Override
		public int hashCode() {
			int hash = 31;
			hash = hash * 89 + k.hashCode();
			hash = hash * 89 + v.hashCode();
			return hash;
		}

		@Override
		public int compareTo(Pair<K, V> pair) {
			return k.compareTo(pair.k) == 0 ? v.compareTo(pair.v) : k.compareTo(pair.k);
		}

		@Override
		public Pair<K, V> clone() {
			return new Pair<K, V>(this.k, this.v);
		}

		@Override
		public String toString() {
			return String.valueOf(k).concat(" ").concat(String.valueOf(v)).concat("\n");
		}
	}

	static class Reader {
		private BufferedReader br;
		private StringTokenizer st;

		Reader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			try {
				while (st == null || !st.hasMoreTokens()) {
					st = new StringTokenizer(br.readLine());
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++)
				arr[i] = nextInt();
			return arr;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String s = "";
			try {
				s = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return s;
		}
	}
}

import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws IOException {
        PrintWriter out = new PrintWriter(System.out);
        //Scanner sc = new Scanner();
        Reader in = new Reader();
        Main solver = new Main();
        solver.solve(out, in);
        out.flush();
        out.close();

    }

    //<>

    static int maxn = (int)1e5*2;
    static long mod=(int)1e9+7;
    static int n,m,k,t;

    void solve(PrintWriter out, Reader in) throws IOException{
        String a = in.next();
        String b = in.next();

        n = a.length();
        m = b.length();

        long[][] dp = new long[n+1][m+1];

        //<>

        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(a.charAt(i-1)==b.charAt(j-1)){
                    dp[i][j] = (dp[i-1][j-1]+1+dp[i][j-1])%mod;
                }else dp[i][j] = dp[i][j-1];
            }
        }

        //<>

        long ans =0;
        for(int i=1;i<=n;i++) ans = (ans+dp[i][m])%mod;
        out.println(ans);

    }

    static class Edge {
        int d,w;

        Edge(int d,int w){
            this.d = d;
            this.w = w;
        }
    }

    static class Reader {

        private InputStream mIs;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public Reader() {
            this(System.in);
        }

        public Reader(InputStream is) {
            mIs = is;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();

        }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = mIs.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }
}

import java.io.*;
import java.util.*;

public class A {
	public static void main(String[] args) {
		new A().run();
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	boolean eof;

	public void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(-1);
		} finally {
			out.close();
		}
	}

	String nextToken() {
		while (st == null || !st.hasMoreElements()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return "0";
			}
		}
		return st.nextToken();
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}

	final int MOD = 1000000007;

	void solve() throws IOException {
		String s = nextToken();
		String t = nextToken();
//		String s = "";
//		String t = "";
//		for (int i = 0; i < 5000; ++i) {
//			s += "a";
//			t += "a";
//		}
//		long time = System.currentTimeMillis();
		int[] D = new int[s.length()];
		for (char c : t.toCharArray()) {
			for (int i = D.length - 1; i >= 0; --i) {
				if (s.charAt(i) == c) {
					++D[i];
					if (i > 0) {
						D[i] += D[i - 1];
					}
					while (D[i] >= MOD) D[i] -= MOD;
				}
			}
		}
		int ans = 0;
		for (int i : D) {
			ans += i;
			if (ans >= MOD) ans -= MOD;
		}
		out.println(ans);
//		System.err.println(System.currentTimeMillis() - time);
	}
}

import java.util.*;
import java.io.*;
import java.awt.Point;
import static java.lang.Math.*;

public class P163A {
    static int[] S;
    static int[] T;
    static int n;
    static int m;

    static int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        String t = in.next();
        n = s.length();
        m = t.length();
        S = new int[n];
        T = new int[m];
        for(int i=0; i<n; i++)
            S[i] = s.charAt(i)-'a';
        for(int i=0; i<m; i++)
            T[i] = t.charAt(i)-'a';

        for(int i=0; i<=5000; i++)
        for(int j=0; j<=5000; j++)
            dp[i][j] = -1;
        long ans = 0;
        for(int i=0; i<n; i++)
            ans = (ans+dp(i,0))%MOD;
        System.out.println(ans);
    }

    static int[][] dp = new int[5001][5001];
    public static int dp(int s, int t) {
        if(s >= n || t >= m) return 0;
        if(dp[s][t] >= 0) return dp[s][t];

        int ans = dp(s,t+1);
        if(S[s] == T[t])
            ans = (ans+1+dp(s+1,t+1)) % MOD;
        return dp[s][t] = ans;
    }
}

import java.util.*;
import java.io.*;

public class A {
	FastScanner in;
	PrintWriter out;

	final long mod = (long) (1e9 + 7);

	public void solve() throws IOException {
		char[] s = in.next().toCharArray();
		char[] t = in.next().toCharArray();
		int n = s.length;
		int m = t.length;
		long[][] dp = new long[n][m];
		if (s[0] == t[0])
			dp[0][0] = 1;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				dp[i][j] = (j != 0) ? dp[i][j - 1] : 0;
				if (s[i] == t[j]) {
					dp[i][j] = (dp[i][j] + (i != 0 && j != 0 ? dp[i - 1][j - 1] : 0) + 1) % mod;
				}
			}
		}
		long ans = 0;
		for (int i = 0; i < n; i++) {
			ans = (ans + dp[i][m - 1]) % mod;
		}
		out.println(ans);
	}

	public void run() {
		try {
			in = new FastScanner();
			out = new PrintWriter(System.out);

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] arg) {
		new A().run();
	}
}

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;

public class Main {

    long MODULO = 1000_000_007;
    long INF = Integer.MAX_VALUE;

    class Pair {
        long k, b;

        public Pair(long k, long b) {
            this.k = k;
            this.b = b;
        }

        long valueAt(int x) {
            return k * x + b;
        }
    }

    void solve() throws IOException {
        char[] s = readString().toCharArray();
        char[] t = readString().toCharArray();

        int n = s.length;
        int m = t.length;

        long[][] dp = new long[2][m + 1];
        long[][] prefSum = new long[2][m + 1];
        long ans = 0;
        for (int i = 1; i <= n; ++i) {
            int x = i % 2;
            int prevX = x ^ 1;
            for (int j = 1; j <= m; ++j) {
                int y = j;
                int prevY = j - 1;
                dp[x][y] = 0;
                prefSum[x][y] = 0;
                if (s[i - 1] == t[j - 1]) {
                    dp[x][y] = prefSum[prevX][prevY] + 1;
                }
                prefSum[x][y] += (prefSum[x][prevY] + dp[x][y]) % MODULO;
                ans += dp[x][y];
                ans %= MODULO;
            }
        }
        out.println(ans);
    }

    long gcd(long a, long b) {
        return a % b == 0 ? b : gcd(b, a % b);
    }

    int[][] steps = {{1, 0}, {0, 1}};
    String fileName = "";
    private final static Random rnd = new Random();

    boolean checkBit(long mask, int bit) {
        return (mask & (1l << bit)) > 0;
    }

    ////////////////////////////////////////////////////////////
    public static void main(String[] args) throws NumberFormatException, IOException {
        // TODO Auto-generated method stub
        new Main().run();
    }

    void run() throws NumberFormatException, IOException {
        solve();
        out.close();
    }

    ;

    BufferedReader in;
    PrintWriter out;

    StringTokenizer tok;
    String delim = " ";

    Main() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            if (fileName.isEmpty()) {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                in = new BufferedReader(new FileReader(fileName + ".in"));
                out = new PrintWriter(fileName + ".out");
            }

        }
        tok = new StringTokenizer("");
    }

    String readLine() throws IOException {
        return in.readLine();
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (null == nextLine) {
                return null;
            }

            tok = new StringTokenizer(nextLine);
        }
        return tok.nextToken(delim);
    }

    int readInt() throws NumberFormatException, IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws NumberFormatException, IOException {
        return Long.parseLong(readString());
    }

    int[] readIntArray(int n) throws NumberFormatException, IOException {
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = readInt();
        }
        return a;
    }

    double readDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(readString());
    }
}

import java.util.*;
import java.io.*;

public class Main2 {
    public static void main(String[] args) throws Exception {
        solve();
        out.flush();
    }
    static long mod = (long)1e9 + 7l;
    public static void solve() throws Exception {
        char[] l1 = nx().toCharArray();
        char[] l2 = nx().toCharArray();
        long[] count = new long[l1.length];
        long[] temp = new long[l1.length];
        int[] stk = new int[l1.length+10];
        int stkptr = 0;
        for (char e: l2){
            for (int  i=0;i < l1.length ;i++){
                if (l1[i] == e){
                    temp[i]++;
                    if (i > 0){
                        temp[i] += count[i - 1];
                    }
                    stk[stkptr++] = i;
                }
            }
            for (int j = 0; j < stkptr; j++){
                int idx = stk[j];
                count[idx] += temp[idx];
                count[idx] %= mod;
                temp[idx] = 0;
            }
            stkptr = 0;
//          px(count);
        }
        long fin = 0;
        for (long e: count){
            fin += e;
            fin %= mod;
        }
        pn(fin);
    }

    public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    public static StringTokenizer st = null;

    public static String nx() throws Exception {
        for (; st == null || !st.hasMoreTokens();) {
            String k1 = in.readLine();
            if (k1 == null) return null;
            st = new StringTokenizer(k1);
        }
        return st.nextToken();
    }

    public static int ni() throws Exception {
        return Integer.parseInt(nx());
    }

    public static long nl() throws Exception {
        return Long.parseLong(nx());
    }

    public static double nd() throws Exception {
        return Double.parseDouble(nx());
    }

    public static void px(Object... l1) {
        System.out.println(Arrays.deepToString(l1));
    }

    public static boolean FLUSH = false;
    public static PrintWriter out = new PrintWriter(System.out, FLUSH);

    public static void p(Object... l1) {
        for (int i = 0; i < l1.length; i++) {
            if (i != 0) out.print(' ');
            out.print(l1[i].toString());
        }
    }

    public static void pn(Object... l1) {
        for (int i = 0; i < l1.length; i++) {
            if (i != 0) out.print(' ');
            out.print(l1[i].toString());
        }
        out.println();
    }

}

import java.util.*;
import java.io.*;

public class Main2 {
    public static void main(String[] args) throws Exception {
        solve();
        out.flush();
    }
    static long mod = (long)1e9 + 7l;
    public static void solve() throws Exception {
        char[] l1 = nx().toCharArray();
        char[] l2 = nx().toCharArray();
        long[] count = new long[l1.length];
        long[] temp = new long[l1.length];
        for (char e: l2){
            for (int  i=0;i < l1.length ;i++){
                if (l1[i] == e){
                    temp[i]++;
                    if (i > 0){
                        temp[i] += count[i - 1];
                    }
                }
            }
            for (int j = 0; j < l1.length; j++){
                count[j] += temp[j];
                count[j] %= mod;
                temp[j] = 0;
            }
//          px(count);
        }
        long fin = 0;
        for (long e: count){
            fin += e;
            fin %= mod;
        }
        pn(fin);
    }

    public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    public static StringTokenizer st = null;

    public static String nx() throws Exception {
        for (; st == null || !st.hasMoreTokens();) {
            String k1 = in.readLine();
            if (k1 == null) return null;
            st = new StringTokenizer(k1);
        }
        return st.nextToken();
    }

    public static int ni() throws Exception {
        return Integer.parseInt(nx());
    }

    public static long nl() throws Exception {
        return Long.parseLong(nx());
    }

    public static double nd() throws Exception {
        return Double.parseDouble(nx());
    }

    public static void px(Object... l1) {
        System.out.println(Arrays.deepToString(l1));
    }

    public static boolean FLUSH = false;
    public static PrintWriter out = new PrintWriter(System.out, FLUSH);

    public static void p(Object... l1) {
        for (int i = 0; i < l1.length; i++) {
            if (i != 0) out.print(' ');
            out.print(l1[i].toString());
        }
    }

    public static void pn(Object... l1) {
        for (int i = 0; i < l1.length; i++) {
            if (i != 0) out.print(' ');
            out.print(l1[i].toString());
        }
        out.println();
    }

}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Vector;

public class Solution {

	long modd = 1000000007;

	void solve() throws Exception {
		String s = nextToken();
		int n = s.length();
		String t = nextToken();
		int m = t.length();
		int[][] dp = new int[n + 1][m + 1];
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {
				dp[i][j] = (int)((long)dp[i][j - 1]);
				if (s.charAt(i - 1) == t.charAt(j - 1)) {
					dp[i][j] = (int)(((long)dp[i][j] + dp[i - 1][j - 1] + 1) % modd);
				}
			}
		}
		long ans = 0;
		for (int i = 0; i <= n; i++) ans = (ans + dp[i][m]) % modd;
		out.println(ans);
	}

	public static void main(String[] args) {
		new Solution().run();
	}

	public void run() {
		try {
			Locale.setDefault(Locale.UK);
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		} finally {
			out.close();
		}
	}

	String nextToken() throws Exception {
		while (st == null || !st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null) return null;
			st = new StringTokenizer(s);
		}
		return st.nextToken();
	}

	int nextInt() throws Exception {
		return Integer.parseInt(nextToken());
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;

}

import java.io.*;
import java.util.*;

public class p163a {
	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;

	String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(in.readLine());
			} catch (Exception e) {
			}
		}
		return st.nextToken();
	}

	int nextInt() {
		return Integer.parseInt(next());
	}

	long nextLong() {
		return Long.parseLong(next());
	}

	double nextDouble() {
		return Double.parseDouble(next());
	}

	public void run() throws Exception {
		in = new BufferedReader(new InputStreamReader(System.in));
		//in = new BufferedReader(new FileReader(new File("./src/input.txt")));
		out = new PrintWriter(System.out);

		String s = next();
		String t = next();

		int n = s.length();
		int m = t.length();

		int d[][] = new int[5002][5002];
		int ans = 0;
		int md = 1000000000+7;

		for (int i = 1; i <= n; i++){
			for (int j = 1; j<=m; j++){
				if (s.charAt(i-1) == t.charAt(j-1)){
					d[i][j] = d[i-1][j-1] + 1;
				}
				d[i][j] = (d[i][j] + d[i][j-1]) % md;
			}
			ans = (ans + d[i][m]) % md;
		}

		out.println(ans);
		out.close();
	}

	public static void main(String[] args) throws Exception {
		new p163a().run();
	}

}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class CodeC
{
	static class Scanner
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		public String nextLine()
		{
			try
			{
				return br.readLine();
			}
			catch(Exception e)
			{
				throw(new RuntimeException());
			}
		}

		public String next()
		{
			while(!st.hasMoreTokens())
			{
				String l = nextLine();
				if(l == null)
					return null;
				st = new StringTokenizer(l);
			}
			return st.nextToken();
		}

		public int nextInt()
		{
			return Integer.parseInt(next());
		}

		public long nextLong()
		{
			return Long.parseLong(next());
		}

		public double nextDouble()
		{
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n)
		{
			int[] res = new int[n];
			for(int i = 0; i < res.length; i++)
				res[i] = nextInt();
			return res;
		}

		public long[] nextLongArray(int n)
		{
			long[] res = new long[n];
			for(int i = 0; i < res.length; i++)
				res[i] = nextLong();
			return res;
		}

		public double[] nextDoubleArray(int n)
		{
			double[] res = new double[n];
			for(int i = 0; i < res.length; i++)
				res[i] = nextLong();
			return res;
		}
		public void sortIntArray(int[] array)
		{
			Integer[] vals = new Integer[array.length];
			for(int i = 0; i < array.length; i++)
				vals[i] = array[i];
			Arrays.sort(vals);
			for(int i = 0; i < array.length; i++)
				array[i] = vals[i];
		}

		public void sortLongArray(long[] array)
		{
			Long[] vals = new Long[array.length];
			for(int i = 0; i < array.length; i++)
				vals[i] = array[i];
			Arrays.sort(vals);
			for(int i = 0; i < array.length; i++)
				array[i] = vals[i];
		}

		public void sortDoubleArray(double[] array)
		{
			Double[] vals = new Double[array.length];
			for(int i = 0; i < array.length; i++)
				vals[i] = array[i];
			Arrays.sort(vals);
			for(int i = 0; i < array.length; i++)
				array[i] = vals[i];
		}

		public String[] nextStringArray(int n)
		{
			String[] vals = new String[n];
			for(int i = 0; i < n; i++)
				vals[i] = next();
			return vals;
		}
	}

	static char[] a;
	static char[] b;
	static int[][] dp = new int[5001][5001];

	static int dp(int enA, int enB)
	{
		if(enA >= a.length || enB >= b.length)
			return 0;
		if(dp[enA][enB] != -1)
			return dp[enA][enB];
		if(a[enA] == b[enB])
			return dp[enA][enB] = (1 + dp(enA + 1, enB + 1) + dp(enA, enB + 1)) % 1000000007;
		else
			return dp[enA][enB] = dp(enA, enB + 1);
	}

	public static void main(String[] args)
	{
		Scanner sc = new Scanner();
		a = sc.next().toCharArray();
		b = sc.next().toCharArray();
		int ans = 0;
		for(int i = 0; i < a.length; i++)
			for(int j = 0; j < b.length; j++)
				dp[i][j] = -1;
		for(int i = 0; i < a.length; i++)
		{
			ans += dp(i, 0);
			ans %= 1000000007;
		}
		System.out.println(ans);
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        final int mod = 1000000007;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next();
            String t = in.next();
            int[][] dp = new int[s.length()][t.length()];
            int[][] dpPref = new int[s.length()][t.length()];
            for (int i = 0; i < s.length(); i++) {
                for (int j = 0; j < t.length(); j++) {
                    if (j > 0) dpPref[i][j] = dpPref[i][j - 1];
                    if (s.charAt(i) == t.charAt(j)) {
                        dp[i][j] = 1;
                        if (i > 0 && j > 0) {
                            dp[i][j] = (dp[i][j] + dpPref[i - 1][j - 1]) % mod;
                        }
                        dpPref[i][j] = (dpPref[i][j] + dp[i][j]) % mod;
                    }
                }
            }
            int ans = 0;
            for (int i = 0; i < s.length(); i++) {
                for (int j = 0; j < t.length(); j++) {
                    ans = (ans + dp[i][j]) % mod;
                }
            }
            out.println(ans);
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer stt;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String next() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

    }
}

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
import java.io.*;
public class codeforces
{
   static class Student{
       int x,y;
        Student(int x,int y){
            this.x=x;
            this.y=y;
            //this.z=z;
        }
    }
    static int prime[];
    static void sieveOfEratosthenes(int n)
    {
        // Create a boolean array "prime[0..n]" and initialize
        // all entries it as true. A value in prime[i] will
        // finally be false if i is Not a prime, else true.
        int pos=0;
        prime= new int[n+1];
        for(int p = 2; p*p <=n; p++)
        {
            // If prime[p] is not changed, then it is a prime
            if(prime[p] == 0)
            {
                // Update all multiples of p
                prime[p]=p;
                for(int i = p*p; i <= n; i += p)
                    if(prime[i]==0)
                    prime[i] = p;
            }
        }
    }
static    class Sortbyroll implements Comparator<Student>
{
    // Used for sorting in ascending order of
    // roll number
    public int compare(Student c, Student b)
    {
        return c.y-b.y;
    }
}
static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    static class Edge{
        int a,b;
        Edge(int a,int b){
            this.a=a;
            this.b=b;
        }
    }
    static class Trie{
        HashMap<Character,Trie>map;
         int c;
        Trie(){
            map=new HashMap<>();
            //z=null;
            //o=null;
            c=0;
        }
    }
    //static long ans;
    static int parent[];
    static int rank[];
   // static int b[][];
    static int bo[];
    static int ho[];
    static int seg[];
    //static int pos;
     static long mod=1000000007;
    //static int dp[][];
    static HashMap<Integer,Integer>map;
    static PriorityQueue<Student>q=new PriorityQueue<>();
    //static Stack<Integer>st;
   // static ArrayList<Character>ans;
    static ArrayList<ArrayList<Integer>>adj;
    //static long ans;
    static int pos;
    static Trie root;
    static long fac[];
    static int gw,gb;
    //static long mod=(long)(998244353);
    //static int ans;
    static void solve()throws IOException{
        FastReader sc=new FastReader();
        String s,t;
        int i,j;
        s=sc.nextLine();
        t=sc.nextLine();
        long ans=0;
        long dp[][]=new long[s.length()+1][t.length()+1];
        for(i=1;i<=s.length();i++){
            for(j=1;j<=t.length();j++){
                dp[i][j]=dp[i][j-1];
                if(s.charAt(i-1)==t.charAt(j-1)){
                    dp[i][j]=(dp[i][j]+1+dp[i-1][j-1])%mod;
                    //ans=(ans+dp[i][j])%mod;
                }
            }
            ans=(ans+dp[i][j-1])%mod;
        }
        System.out.println(ans);
    }
    static long fac(long x,long y){
        if(y==0||x==0)
            return 1;
        return x * fac(x-1,y-1);
    }
    static long nCr(long n, long r,
                                    long p)
    {
        return (fac[(int)n]* modInverse(fac[(int)r], p)
                % p * modInverse(fac[(int)(n-r)], p)
                                    % p) % p;
    }
    //static int prime[];
    //static int dp[];
    public static void main(String[] args){
        //long sum=0;
        try {
                codeforces.solve();
                } catch (Exception e) {
                    e.printStackTrace();
                }
    }
       static long modInverse(long n, long p)
    {
        return power(n, p-(long)2,p);
    }
 static long power(long x, long y, long p)
{
    long res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y %(long)2!=0)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res%p;
 }
    /*public static long power(long x,long a) {
		if(a==0) return 1;
		if(a%2==1)return (x*1L*power(x,a-1))%mod;
		return (power((int)((x*1L*x)%mod),a/2))%mod;
	}*/
   static int find(int x)
    {
        // Finds the representative of the set
        // that x is an element of
        while(parent[x]!=x)
        {
            // if x is not the parent of itself
            // Then x is not the representative of
            // his set,
            x=parent[x];

            // so we recursively call Find on its parent
            // and move i's node directly under the
            // representative of this set
        }

        return x;
    }
    static void union(int x, int y)
    {
        // Find representatives of two sets
        int xRoot = find(x), yRoot = find(y);

        // Elements are in the same set, no need
        // to unite anything.
        if (xRoot == yRoot)
            return;

         // If x's rank is less than y's rank
        if (rank[xRoot] < rank[yRoot])

            // Then move x under y  so that depth
            // of tree remains less
            parent[xRoot] = yRoot;

        // Else if y's rank is less than x's rank
        else if (rank[yRoot] < rank[xRoot])

            // Then move y under x so that depth of
            // tree remains less
            parent[yRoot] = xRoot;

        else // if ranks are the same
        {
            // Then move y under x (doesn't matter
            // which one goes where)
            parent[yRoot] = xRoot;

            // And increment the the result tree's
            // rank by 1
            rank[xRoot] = rank[xRoot] + 1;
        }
    }
    static long gcd(long a, long b)
    {
        if (a == 0){
             //ans+=b;
            return b;
        }
        return gcd(b % a, a);
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class substringandsubsequence {
	static int MOD = (int) (Math.pow(10,9)+7);
	public static void main(String[] args) throws IOException {
		 BufferedReader br = new BufferedReader(
                 new InputStreamReader(System.in));

StringTokenizer st = new StringTokenizer(br.readLine());
		String s = st.nextToken();
		st = new StringTokenizer(br.readLine());
		String t = st.nextToken();
		int [][] dp = new int[s.length()][t.length()];
		if(t.charAt(0)==s.charAt(0)) {
			dp[0][0] = 1;
		}
		for(int i=1;i<t.length();i++) {
			dp[0][i]=dp[0][i-1];
			if(t.charAt(i)==s.charAt(0)) {
				dp[0][i]++;
			}

		}
		for(int j=1;j<s.length();j++) {
			if(s.charAt(j)==t.charAt(0)) {
				dp[j][0] =1;
			}
		}
		for(int i=1;i<s.length();i++) {
			for(int j=1;j<t.length();j++) {
				dp[i][j] = dp[i][j-1];
				if(s.charAt(i)==t.charAt(j)) {
					dp[i][j]+=(dp[i-1][j-1]+1);
				}
				dp[i][j] = dp[i][j]%MOD;

			}
		}
//		for(int i=0;i<s.length();i++) {
//			for(int j=0;j<t.length();j++) {
//				System.out.print(dp[i][j]);
//			}
//			System.out.println();
//		}
		int count = 0;
		for(int i=0;i<s.length();i++) {
			count+=dp[i][t.length()-1];
			count = (count%MOD);
		}
		System.out.println(count);
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Locale;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					long prevTime = System.currentTimeMillis();
					new Main().run();
					System.err.println("Total time: "
							+ (System.currentTimeMillis() - prevTime) + " ms");
					System.err.println("Memory status: " + memoryStatus());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start();
	}

	void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		Object o = solve();
		if (o != null)
			out.println(o);
		out.close();
		in.close();
	}

	int n;
	int m;
	int MOD = 1000000007;

	private Object solve() throws IOException {
		String s = in.readLine();
		String t = in.readLine();
		n = s.length();
		m = t.length();
		int[][] dp = new int[n][m];

		for (int i = n - 1; i >= 0; i--)
			if (s.charAt(i) == t.charAt(m - 1))
				dp[i][m - 1]++;

		for (int j = m - 2; j >= 0; j--) {
			dp[n - 1][j] = dp[n - 1][j + 1];
			if (s.charAt(n - 1) == t.charAt(j))
				dp[n - 1][j] = (dp[n - 1][j] + 1) % MOD;

			for (int i = n - 2; i >= 0; i--) {
				dp[i][j] = dp[i][j + 1];
				if (s.charAt(i) == t.charAt(j))
					dp[i][j] = (dp[i][j] + dp[i + 1][j + 1]+1) % MOD;
			}
		}

		int ret = 0;
		for (int i = 0; i < n; i++)
			ret = (ret + dp[i][0]) % MOD;
		return ret;
	}
	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

	int ni() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nl() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nd() throws IOException {
		return Double.parseDouble(nextToken());
	}

	int[] nia(int size) throws IOException {
		int[] ret = new int[size];
		for (int i = 0; i < size; i++)
			ret[i] = ni();
		return ret;
	}

	long[] nla(int size) throws IOException {
		long[] ret = new long[size];
		for (int i = 0; i < size; i++)
			ret[i] = nl();
		return ret;
	}

	double[] nda(int size) throws IOException {
		double[] ret = new double[size];
		for (int i = 0; i < size; i++)
			ret[i] = nd();
		return ret;
	}

	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}

	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}

	void printRepeat(String s, int count) {
		for (int i = 0; i < count; i++)
			out.print(s);
	}

	void printArray(int[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i > 0)
				out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}

	void printArray(long[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i > 0)
				out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}

	void printArray(double[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i > 0)
				out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}

	void printArray(double[] array, String spec) {
		for (int i = 0; i < array.length; i++) {
			if (i > 0)
				out.print(' ');
			out.printf(Locale.US, spec, array[i]);
		}
		out.println();
	}

	void printArray(Object[] array) {
		boolean blank = false;
		for (Object x : array) {
			if (blank)
				out.print(' ');
			else
				blank = true;
			out.print(x);
		}
		out.println();
	}

	@SuppressWarnings("rawtypes")
	void printCollection(Collection collection) {
		boolean blank = false;
		for (Object x : collection) {
			if (blank)
				out.print(' ');
			else
				blank = true;
			out.print(x);
		}
		out.println();
	}

	static String memoryStatus() {
		return (Runtime.getRuntime().totalMemory()
				- Runtime.getRuntime().freeMemory() >> 20)
				+ "/" + (Runtime.getRuntime().totalMemory() >> 20) + " MB";
	}
}

import java.util.Scanner;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author @zhendeaini6001
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
     public final long MOD = 1000000007;
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        String a = in.next();
        String b = in.next();
        long[][] dp = new long[2][5001];
        ArrayUtils.fill(dp, 0);
        int flag = 0;
        long res = 0;
        for (int i = 0; i < a.length(); ++i){
            Arrays.fill(dp[i&1], 0);
            for (int j = 0; j < b.length(); ++j){
                if (j >= 1){
                    dp[i&1][j] = dp[i&1][j - 1];
                }
                if (a.charAt(i) == b.charAt(j)){
                    ++dp[i&1][j];
                    if (i >= 1 && j >= 1){
                        dp[i&1][j] += dp[(i-1)&1][j-1];
                    }
                    dp[i&1][j] %= MOD;
                }
            }
            res += dp[i&1][b.length() -  1];       res %= MOD;
        }
        out.println(res);
        return;
    }

}

class ArrayUtils {

    public static void fill(long[][] array, long value) {
        for (long[] row : array)
            Arrays.fill(row, value);
    }

    }

// Submitted by Subhash Yadav
import java.io.*;
import java.util.*;

public class A {

	static int m=(int) 1e9 +7;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		char s[]=sc.next().toCharArray(),t[]=sc.next().toCharArray();
		long dp[][]=new long[5005][5005];
		int j = 0;
		for(int i=0;i<s.length;i++) {
			for( j=0;j<t.length;j++) {
				dp[i+1][j+1]=dp[i+1][j]+((s[i]==t[j])?(dp[i][j]+1):0)%m;
			}
		}

		long ans=0;
		for(int i=0;i<s.length;i++) {
			ans=(ans+dp[i+1][j])%m;
		}
		System.out.println(ans);
	}

	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			while (!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] readArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}

import java.util.*;
import java.math.*;
import java.io.*;
public class Main
	{
	public static void main(String args[])	throws IOException
		{
		Scanner c=new Scanner(System.in);
		char A[]=c.next().toCharArray();
		char B[]=c.next().toCharArray();

		int N=A.length;
		int M=B.length;
		int DP[][]=new int[N][M];		//substring ending at char i, subsequence contains chars upto j
		if(A[0]==B[0])
			DP[0][0]=1;
		for(int j=1;j<M;j++)
			{
			if(B[j]==A[0])
				DP[0][j]=1+DP[0][j-1];
			else
				DP[0][j]=DP[0][j-1];
			}
		for(int i=1;i<N;i++)
			{
			for(int j=0;j<M;j++)
				{
				//include B[j] in subsequence
				if(A[i]==B[j])
					{
					if(j>0)
						{
						//System.out.println("adding 1 for ("+i+","+j+")");
						DP[i][j]=1+DP[i-1][j-1];
						}
					else
						DP[i][j]=1;
					}
				//B[j] is not in the subsequence
				if(j!=0)
					DP[i][j]+=DP[i][j-1];
				DP[i][j]%=1000000007;
				}
			}
		/*for(int i=0;i<N;i++)
			{
			System.out.println(Arrays.toString(DP[i]));
			}
		*/
		long sum=0;
		for(int i=0;i<N;i++)
			{
			sum+=DP[i][M-1];
			}
		System.out.println(sum%1000000007);
		}
	}

//must declare new classes here

import java.io.*;
import java.util.*;

public class test
{

	public static void main(String[] args)
	{
		new test().run();
	}

	PrintWriter out = null;

	int[][] dp = null;

	void run()
	{
		Scanner in = new Scanner(System.in);
		out = new PrintWriter(System.out);

		char[] s = in.next().toCharArray();
		char[] t = in.next().toCharArray();

		int slen = s.length;
		int tlen = t.length;
		int mod = 1000000007;

		dp = new int[slen][tlen];

		int total = 0;

		for (int i = 0; i < slen; i++)
		{
			if (s[i] == t[0])
			{
				total++;
				total %= mod;
				dp[i][0] = 1;
			}
		}

		for (int j = 1; j < tlen; j++)
		{
			if (s[0] == t[j])
			{
				total++;
				total %= mod;
				dp[0][j] = 1;
			}
		}

		for (int i = 1; i < slen; i++)
		{
			int sum = 0;

			for (int j = 1; j < tlen; j++)
			{
				sum += dp[i - 1][j - 1];
				sum %= mod;
				if (s[i] == t[j])
				{
					dp[i][j] = sum + 1;
					total += sum + 1;
					total %= mod;
				}
			}
		}

		out.println(total);
		out.close();
	}
}

import java.util.Scanner;

public class CF_169C {
	private static final int MODULO_PRIME = 1000000007;

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		char[] s = in.next().toCharArray();
		char[] t = in.next().toCharArray();

		int[][] dp = new int[s.length + 1][t.length + 1];
		for(int i = s.length - 1; i >= 0; i--) {
			for(int j = t.length - 1; j >= 0; j--) {
				dp[i][j] = (dp[i][j+1] + (s[i] == t[j] ? 1 + dp[i+1][j+1] : 0)) % MODULO_PRIME;
			}
		}

		// sum up choices for all possible substring start indexes
		int count = 0;
		for(int i = 0; i < s.length; i++) {
			count = (count + dp[i][0]) % MODULO_PRIME;
		}

		System.out.println(count);
	}
}

//package vk_cup_round2;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StreamTokenizer;
import java.io.Writer;
/**
 * Date     : 01.05.2012
 * Time     : 12:57:08
 * Email    : denys.astanin@gmail.com
 */

public class C {
	public static void main(String[] args) throws IOException {
		new C().run();
	}

	int nextInt() throws IOException {
		in.nextToken();
		return (int) in.nval;
	}

	String nextString() throws IOException {
		in.nextToken();
		return (String) in.sval;
	}

	StreamTokenizer in;
	Writer writer;
	Reader reader;

	void run() throws IOException {
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		reader = oj ? new InputStreamReader(System.in, "ISO-8859-1")
				: new FileReader("src/vk_cup_round2/C.txt");
		writer = new OutputStreamWriter(System.out, "ISO-8859-1");
		in = new StreamTokenizer(new BufferedReader(reader));
		PrintWriter out = new PrintWriter(writer);
		String s = nextString();
		String t = nextString();
		int mod = 1000000007;
		int result = 0;
		int[][] dp = new int [s.length() + 1][t.length() + 1];
		for (int i = 0; i < s.length(); i++) {
			for (int j = 0; j < t.length(); j++) {
				dp[i + 1][j + 1] = (dp[i + 1][j] + (t.charAt(j) == s.charAt(i) ? 1 : 0) * (dp[i][j] + 1)) % mod;
			}
		}
		for (int i = 0; i < s.length(); i++) {
			result = (result + dp[i + 1][t.length()]) % mod;
		}
		out.println(result);
		out.flush();
		out.close();
	}
}

import java.io.*;
import java.util.*;

public class test
{

	public static void main(String[] args)
	{
		new test().run();
	}

	PrintWriter out = null;

	int[][] dp = new int[2][];

	void run()
	{
		Scanner in = new Scanner(System.in);
		out = new PrintWriter(System.out);

		char[] s = in.next().toCharArray();
		char[] t = in.next().toCharArray();

		int slen = s.length;
		int tlen = t.length;
		int mod = 1000000007;

		dp[0] = new int[tlen];
		dp[1] = new int[tlen];

		int total = 0;

		for (int j = 0; j < tlen; j++)
		{
			if (s[0] == t[j])
			{
				total++;
				dp[0][j] = 1;
			}
		}

		for (int i = 1; i < slen; i++)
		{
			if (s[i] == t[0])
			{
				dp[1][0] = 1;
				total++;
			}

			int sum = 0;

			for (int j = 1; j < tlen; j++)
			{
				sum += dp[0][j - 1];
				sum %= mod;
				if (s[i] == t[j])
				{
					dp[1][j] = sum + 1;
					total += sum + 1;
					total %= mod;
				}
			}

			int[] tmp = dp[0];
			dp[0] = dp[1];
			dp[1] = tmp;
			Arrays.fill(dp[1], 0);
		}

		out.println(total);
		out.close();
	}
}

//package vkcup2012.r2;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;

public class A {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int mod = 1000000007;
		char[] a = ns(5000);
		char[] b = ns(5000);
		int n = a.length, m = b.length;

//		int[][] dp = new int[m+1][n+1];
		int[][] rowsum = new int[m+1][n+1];
		long ret = 0;
		for(int i = 1;i <= m;i++){
			for(int j = 1;j <= n;j++){
				int rs = rowsum[i-1][j];
				if(a[j-1] == b[i-1]){
//					dp[i][j] = (rowsum[i-1][j-1]+1) % mod;
					ret += rowsum[i-1][j-1]+1;
					rs += rowsum[i-1][j-1]+1;
				}
				rowsum[i][j] = rs % mod;
			}
		}
		out.println(ret%mod);
	}

	void run() throws Exception
	{
//		int n = 5000;
//		StringBuilder sb = new StringBuilder();
//		for (int i = 0; i < n; i++) {
//			sb.append('a');
//		}
//		sb.append("\n");
//		for (int i = 0; i < n; i++) {
//			sb.append('a');
//		}
//		sb.append("\n");
//		INPUT = sb.toString();

		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception
	{
		new A().run();
	}

	public int ni()
	{
		try {
			int num = 0;
			boolean minus = false;
			while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
			if(num == '-'){
				num = 0;
				minus = true;
			}else{
				num -= '0';
			}

			while(true){
				int b = is.read();
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
			}
		} catch (IOException e) {
		}
		return -1;
	}

	public long nl()
	{
		try {
			long num = 0;
			boolean minus = false;
			while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
			if(num == '-'){
				num = 0;
				minus = true;
			}else{
				num -= '0';
			}

			while(true){
				int b = is.read();
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
			}
		} catch (IOException e) {
		}
		return -1;
	}

	public String ns()
	{
		try{
			int b = 0;
			StringBuilder sb = new StringBuilder();
			while((b = is.read()) != -1 && (b == '\r' || b == '\n' || b == ' '));
			if(b == -1)return "";
			sb.append((char)b);
			while(true){
				b = is.read();
				if(b == -1)return sb.toString();
				if(b == '\r' || b == '\n' || b == ' ')return sb.toString();
				sb.append((char)b);
			}
		} catch (IOException e) {
		}
		return "";
	}

	public char[] ns(int n)
	{
		char[] buf = new char[n];
		try{
			int b = 0, p = 0;
			while((b = is.read()) != -1 && (b == ' ' || b == '\r' || b == '\n'));
			if(b == -1)return null;
			buf[p++] = (char)b;
			while(p < n){
				b = is.read();
				if(b == -1 || b == ' ' || b == '\r' || b == '\n')break;
				buf[p++] = (char)b;
			}
			return Arrays.copyOf(buf, p);
		} catch (IOException e) {
		}
		return null;
	}

	double nd() { return Double.parseDouble(ns()); }
	boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}

import java.io.*;
import java.util.*;

public class A163 {
    FastScanner in;
    PrintWriter out;

    final int MOD = 1000_000_007;

    public void run() {
        try {
            in = new FastScanner();
            out = new PrintWriter(System.out);
            Locale.setDefault(Locale.US);

            String s = in.nextToken(), t = in.nextToken();
            int dyn[][] = new int[s.length() + 1][t.length() + 1];
            for (int i = 0; i < s.length(); i++)
                for (int j = 0; j < t.length(); j++) {
                    dyn[i + 1][j + 1] = dyn[i + 1][j];
                    if (s.charAt(i) == t.charAt(j))
                        dyn[i + 1][j + 1] = (dyn[i + 1][j + 1] + dyn[i][j] + 1) % MOD;
                }
            int ans = 0;
            for (int i = 0; i <= s.length(); i++)
                ans = (ans + dyn[i][t.length()]) % MOD;
            out.println(ans);

            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new A163().run();
    }

    class FastScanner {
        BufferedReader reader;
        StringTokenizer tokenizer;

        FastScanner() {
            reader = new BufferedReader(new InputStreamReader(System.in));
        }

        FastScanner(String filename) throws FileNotFoundException {
            reader = new BufferedReader(new FileReader(filename));
        }

        String nextToken() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}

import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class C {

    long P = 1000000007;

    void run() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        long[] dp = new long[t.length()];
        long[] tmp = new long[t.length()];

        long ans = 0;
        for(int i=0;i<t.length();i++) if(s.charAt(0) == t.charAt(i)) {
            tmp[i] = dp[i] = (dp[i]+1)%P;
            ans = (ans+dp[i])%P;
        }
        for(int i=1;i<s.length();i++) {
            long sum = 0;
            for(int j=0;j<t.length();j++) {
                dp[j] = 0;
                if( s.charAt(i) == t.charAt(j) ) {
                    dp[j] = (dp[j]+sum+1)%P;
                }
                if(s.charAt(i-1) == t.charAt(j)) sum = (sum+tmp[j])%P;
                tmp[j] = dp[j];
                ans = (ans+dp[j])%P;
            }
        }
        System.out.println(ans);
    }

    public static void main(String[] args) {
        new C().run();
    }
}

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.Locale;

public class A {

	static {
		final Locale us = Locale.US;
		if (!Locale.getDefault().equals(us)) {
			Locale.setDefault(us);
		}
	}

	static boolean file = false;
	static boolean isLocal = false;

	private static int nextInt() throws IOException {
		in.nextToken();
		return (int) in.nval;
	}

	private static String nextWord() throws IOException {
		in.nextToken();
		return in.sval;
	}

	static StreamTokenizer in;
	static {
		try {
			// in = new Scanner(file ? new
			// FileInputStream("c:\\var\\tmp\\in.txt")
			// : System.in);

			// in = new BufferedReader(new InputStreamReader(
			// file ? new FileInputStream("c:\\var\\tmp\\in.txt")
			// : System.in));

			in = new StreamTokenizer(new BufferedReader(new InputStreamReader(
					file ? new FileInputStream("c:\\var\\tmp\\in.txt")
							: System.in)));
		} catch (final FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	static PrintWriter out;
	static {
		try {
			out = file ? new PrintWriter(
					new FileWriter("c:\\var\\tmp\\out.txt")) : new PrintWriter(
					System.out);
		} catch (final IOException e) {
			e.printStackTrace();
		}
	}

	static PrintStream err;
	static {
		err = System.err;
	}

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(final String[] args) throws IOException {

		final long startTime = System.nanoTime();
		final int t = 1;// nextInt();

		for (int i = 0; i < t; ++i) {
			solve(i + 1);
			if (isLocal && file) {
				err.println(i + 1 + "/" + t);
			}
			if (isLocal && !file) {
				out.flush();
			}
		}

		if (isLocal) {
			err.println(String.format("Completed after %d ms.",
					(System.nanoTime() - startTime) / 1000000));
		}

		out.flush();
		if (file) {
			out.close();
		}

	}

	private static void Assert(final boolean x) {
		if (!x) {
			System.err.println("Assertion failed");
		}
	}

	private static void solve(final int testId) throws IOException {
		final String s1 = nextWord();
		final String s2 = nextWord();

		final long mod = 1000000007;
		final int[][] dp = new int[2][s2.length() + 1];
		final int[][] suff = new int[2][s2.length() + 1];

		for (final int[] q : dp) {
			Arrays.fill(q, 0);
		}

		for (final int[] q : suff) {
			Arrays.fill(q, 0);
		}

		for (int i = 1; i <= s1.length(); ++i) {
			for (int j = 1; j <= s2.length(); ++j) {
				final int ii = i % 2, rii = 1 - ii;

				// suff
				{
					long q = suff[ii][j - 1];
					if (s1.charAt(i - 1) == s2.charAt(j - 1)) {
						q += 1 + suff[rii][j - 1];
					}
					suff[ii][j] = (int) (q % mod);
				}

				// dp
				{
					dp[ii][j] = (int) ((dp[rii][j] + suff[ii][j]) % mod);
				}
			}
		}

		out.println(dp[s1.length() & 1][s2.length()]);
	}
}

import java.util.*;
import java.io.*;
public class Main
{
    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
    public static void main(String args[])throws Exception
    {
        Reader sc=new Reader();
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        char c[]=br.readLine().toCharArray();
        char t[]=br.readLine().toCharArray();
        int n=c.length,m=t.length;
        long arr[][]=new long[n+1][m+1];
        final long mod=(long)1e9+7;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(c[i-1]==t[j-1])
                arr[i][j]=(arr[i-1][j-1]+arr[i][j-1]+1)%mod;
                else
                arr[i][j]=arr[i][j-1];
            }
        }
        long ans=0;
        for(int i=1;i<=n;i++)
        {
            ans=ans+arr[i][m];
            ans%=mod;
        }
        pw.println(ans);
        pw.flush();
        pw.close();
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;

public class R2_D2_D {
    static String s1;
    static String s2;
    static int mod = 1000000007;
    static int DP[][];

    public static int call(int index1, int index2) {
        if (index1 == s2.length())
            return 1;
        if (DP[index1][index2] != -1)
            return DP[index1][index2];
        if (index2 < s1.length() && s2.charAt(index1) == s1.charAt(index2)) {
            int a = call(index1 + 1, index2 + 1) + call(index1 + 1, index2);
            if (a >= mod)
                a -= mod;
            return DP[index1][index2] = a;
        } else
            return DP[index1][index2] = call(index1 + 1, index2);
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        s1 = in.readLine();
        s2 = in.readLine();
        DP = new int[s2.length() + 1][s1.length() + 1];
        for (int i = 0; i < DP.length; i++) {
            Arrays.fill(DP[i], -1);
        }
        long res = 0;
        for (int i = 0; i < s1.length(); i++) {
            int a = 0;
            a = call(0, i) - 1;
            res = (res + a) % mod;
        }
        System.out.println(res);
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1000];
        private int curChar, numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long readLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private String readLine0() {
            StringBuffer buf = new StringBuffer();
            int c = read();
            while (c != '\n' && c != -1) {
                buf.appendCodePoint(c);
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0)
                s = readLine0();
            return s;
        }

        public String readLine(boolean ignoreEmptyLines) {
            if (ignoreEmptyLines)
                return readLine();
            else
                return readLine0();
        }

        public char readCharacter() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            return (char) c;
        }

        public double readDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, readInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, readInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }
    }

}

import java.io.*;
import java.math.*;
import java.util.*;

public class Main implements Runnable {

	final int mod = 1000000007;

	String s, t;
	boolean[][] pos;
	int[] dp;

	@Override
	public void run() {
		try {
			//InputStream is = new FileInputStream("input.txt");
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			s = nextToken();
			t = nextToken();
			pos = new boolean[26][t.length()];
			for (int i = 0; i < t.length(); i++) {
				pos[t.charAt(i) - 'a'][i] = true;
			}
			int ans = 0;
			dp = new int[t.length()];
			for (int i = 0; i < s.length(); i++) {
				int ch = s.charAt(i) - 'a';
				int[] tmp = Arrays.copyOf(dp, dp.length);
				for (int j = 1; j < tmp.length; j++) {
					tmp[j] = (tmp[j] + tmp[j - 1]) % mod;
				}
				ans = (ans + tmp[tmp.length - 1]) % mod;
				for (int j = 0; j < t.length(); j++) {
					if (pos[ch][j]) {
						dp[j] = 1;
						if (j > 0) {
							dp[j] = (dp[j] + tmp[j - 1]) % mod;
						}
					} else
						dp[j] = 0;
				}
			}
			for (int i = 0; i < t.length(); i++) {
				ans = (ans + dp[i]) % mod;
			}
			writer.println(ans);
			reader.close();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public static void main(String args[]) {
		new Main().run();
	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

}

import java.util.Random;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStreamReader;
import java.io.File;
import java.math.BigInteger;

public class Task{

	static final boolean readFromFile = false;
	static final String fileInputName = "input.txt",
						fileOutputName = "output.txt";

	public static void main(String args[]){
		FileInputStream fileInputStream;
		FileOutputStream fileOutputStream;
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		if (readFromFile){
			try{
				fileInputStream = new FileInputStream(new File(fileInputName));
				fileOutputStream = new FileOutputStream(new File(fileOutputName));
			}catch (FileNotFoundException e){
				throw new RuntimeException(e);
			}
		}
		PrintWriter out = new PrintWriter((readFromFile)?fileOutputStream:outputStream);
		InputReader in  = new InputReader((readFromFile)?fileInputStream:inputStream);

		Solver s = new Solver(in, out);
		s.solve();

		out.close();
	}
}

class Solver{
	private PrintWriter out;
	private InputReader in;

	private static final int mod=(int)(1e9)+7;

	public void solve(){
		String s1 = in.nextLine(),
				s2 = in.nextLine();
		char a[] = s1.toCharArray(),
			b[] = s2.toCharArray();
		int d[][] = new int[5555][5555],
			n = s1.length(),
			m = s2.length();
		for (int i=n-1;i>=0;i--)
			for (int j=m-1;j>=0;j--){
				d[i][j]=d[i][j+1];
				if (a[i]==b[j])
					d[i][j] = (d[i][j]+d[i+1][j+1]+1)%mod;
			}
		int answer = 0;
		for (int i=0;i<n;i++)
			answer = (answer+d[i][0])%mod;
		out.println(answer);
	}

	Solver(InputReader in, PrintWriter out){
		this.in = in;
		this.out = out;
	}
}

class InputReader{
	StringTokenizer tok;
	BufferedReader buf;

	InputReader(InputStream in){
		tok = null;
		buf = new BufferedReader(new InputStreamReader(in));
	}

	InputReader(FileInputStream in){
		tok = null;
		buf = new BufferedReader(new InputStreamReader(in));
	}

	public String next(){
		while (tok==null || !tok.hasMoreTokens()){
			try{
				tok = new StringTokenizer(buf.readLine());
			}catch (IOException e){
				throw new RuntimeException(e);
			}
		}
		return tok.nextToken();
	}

	public int nextInt(){
		return Integer.parseInt(next());
	}
	public long nextLong(){
		return Long.parseLong(next());
	}
	public double nextDouble(){
		return Double.parseDouble(next());
	}
	public float nextFloat(){
		return Float.parseFloat(next());
	}
	public String nextLine(){
		try{
			return buf.readLine();
		}catch (IOException e){
			return null;
		}
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class C {
    static int[][] next;
    static int[][] dp;
    static char[] s, t;

    static int mod = 1000000007;

    static int solve(int sIdx, int tIdx) {
        if (sIdx == s.length || tIdx == t.length)
            return 1;
        if (dp[sIdx][tIdx] != -1)
            return dp[sIdx][tIdx];
        long res = 0;
        if (next[tIdx][s[sIdx] - 'a'] != -1) {
            res = solve(sIdx, next[tIdx][s[sIdx] - 'a']);
            if (sIdx < s.length - 1 && (next[tIdx][s[sIdx + 1] - 'a'] != -1)) {
                res = ((res + 1) % mod + solve(sIdx + 1,
                        next[tIdx][s[sIdx + 1] - 'a']))
                        % mod;
            } else {
                res = (res + 1) % mod;
            }
        } else {
            if (sIdx < s.length - 1 && (next[tIdx][s[sIdx + 1] - 'a'] != -1)) {
                res = ((res + 1) % mod + solve(sIdx + 1,
                        next[tIdx][s[sIdx + 1] - 'a']))
                        % mod;
            } else
                res = (res + 1) % mod;
        }
        return dp[sIdx][tIdx] = (int) (res % mod);
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         s = br.readLine().toCharArray();
         t = br.readLine().toCharArray();
//      s = new char[5000];
//      t = new char[5000];
//      for (int i = 0; i < 5000; i++) {
//          s[i] = 'a';
//          t[i] = 'a';
//      }
        next = new int[t.length][26];
        for (int i = 0; i < t.length; i++)
            Arrays.fill(next[i], -1);
        for (int i = 0; i < t.length; i++) {
            for (int j = i + 1; j < t.length; j++) {
                if (next[i][t[j] - 'a'] == -1) {
                    next[i][t[j] - 'a'] = j;
                }
            }
        }
        dp = new int[s.length+1][t.length+1];
        for (int sIdx = s.length; sIdx >= 0; sIdx--) {
            for (int tIdx = t.length; tIdx >= 0; tIdx--) {
                if (sIdx == s.length || tIdx == t.length) {
                    dp[sIdx][tIdx] = 1;
                    continue;
                }
                if (s[sIdx] != t[tIdx]) {
                    dp[sIdx][tIdx] = 0;
                    continue;
                }
                long res = 0;
                if (next[tIdx][s[sIdx] - 'a'] != -1) {
                    res = dp[sIdx][next[tIdx][s[sIdx] - 'a']];
                    if (sIdx < s.length - 1
                            && (next[tIdx][s[sIdx + 1] - 'a'] != -1)) {
                        res = ((res + 1) % mod + dp[sIdx + 1][next[tIdx][s[sIdx + 1] - 'a']])
                                % mod;
                    } else {
                        res = (res + 1) % mod;
                    }
                } else {
                    if (sIdx < s.length - 1
                            && (next[tIdx][s[sIdx + 1] - 'a'] != -1)) {
                        res = ((res + 1) % mod + dp[sIdx + 1][next[tIdx][s[sIdx + 1] - 'a']])
                                % mod;
                    } else
                        res = (res + 1) % mod;
                }
                dp[sIdx][tIdx] = (int) (res % mod);
            }
        }
//      for (int i = 0; i < s.length; i++)
//          Arrays.fill(dp[i], -1);

        long res = 0;
        for (int i = 0; i < s.length; i++) {
            for (int j = 0; j < t.length; j++) {
                if (s[i] == t[j]) {
                    res = (res + dp[i][j]) % mod;
                    break;
                }
            }
        }
        System.out.println(res);
    }
}

import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class C {

    long P = 1000000009;

    void run() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        long[] dp = new long[t.length()];
        long[] tmp = new long[t.length()];

        long ans = 0;
        for(int i=0;i<t.length();i++) if(s.charAt(0) == t.charAt(i)) {
            tmp[i] = dp[i] = (dp[i]+1)%P;
            ans = (ans+dp[i])%P;
        }
        for(int i=1;i<s.length();i++) {
            long sum = 0;
            for(int j=0;j<t.length();j++) {
                dp[j] = 0;
                if( s.charAt(i) == t.charAt(j) ) {
                    dp[j] = (dp[j]+sum+1)%P;
                }
                if(s.charAt(i-1) == t.charAt(j)) sum = (sum+tmp[j])%P;
                tmp[j] = dp[j];
                ans = (ans+dp[j])%P;
            }
        }
        System.out.println(ans);
    }

    public static void main(String[] args) {
        new C().run();
    }
}

import java.io.*;
import java.util.*;

public class solver implements Runnable{

 public static void main(String [] args){
   (new solver()).run();
 }

 int[][] dp;

 public void solver() throws IOException{

  String s=nextToken();
  String w=nextToken();
  int n=s.length();
  int m=w.length();

  dp=new int[5005][5005];

  dp[0][0]=0;
  //for(int j=0;j<=m;j++) dp[0][j]=1;
  //for(int i=0;i<=n;i++) dp[i][0]=1;

  for(int i=1;i<=n;i++)
  for(int j=1;j<=m;j++)
  {
   dp[i][j]=dp[i][j-1];
   if(s.charAt(i-1)==w.charAt(j-1))
    dp[i][j]+=1+dp[i-1][j-1];

  }

  int ans=0;

  for(int i=0;i<=n;i++)
  ans+=dp[i][m];

  out.print(ans);

  /*System.out.println(dp[n][m]);

  for(int i=0;i<10;i++){
  System.out.print(i+":");
  for(int j=0;j<10;j++)
   System.out.print(dp[i][j]+" ");
  System.out.println();
  }*/

 }

 public void run(){
  try{
    reader=new BufferedReader(new InputStreamReader(System.in));
    //reader=new BufferedReader(new FileReader("input.txt"));
    tokenizer=null;
    out=new PrintWriter(System.out);
	 solver();
    out.close();
    reader.close();
  }
  catch(Exception e){
   e.printStackTrace();
   System.exit(1);
  }

 }

 public String nextToken() throws IOException{
  while(tokenizer==null || !tokenizer.hasMoreTokens() )
   tokenizer=new StringTokenizer(reader.readLine());
  return tokenizer.nextToken();
 }

 BufferedReader reader;
 StringTokenizer tokenizer;
 PrintWriter out;

}

import java.util.Scanner;

public class substringandsubsequence {
	static int MOD = (int) (Math.pow(10,9)+7);
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int [][] dp = new int[s.length()][t.length()];
		if(t.charAt(0)==s.charAt(0)) {
			dp[0][0] = 1;
		}
		for(int i=1;i<t.length();i++) {
			dp[0][i]=dp[0][i-1];
			if(t.charAt(i)==s.charAt(0)) {
				dp[0][i]++;
			}

		}
		for(int j=1;j<s.length();j++) {
			if(s.charAt(j)==t.charAt(0)) {
				dp[j][0] =1;
			}
		}
		for(int i=1;i<s.length();i++) {
			for(int j=1;j<t.length();j++) {
				dp[i][j] = (dp[i][j-1]%MOD+MOD)%MOD;
				if(s.charAt(i)==t.charAt(j)) {
					dp[i][j]+=((dp[i-1][j]+1)%MOD+MOD)%MOD;
				}
				dp[i][j] = ((dp[i][j]%MOD)+MOD)%MOD;

			}
		}
//		for(int i=0;i<s.length();i++) {
//			for(int j=0;j<t.length();j++) {
//				System.out.print(dp[i][j]);
//			}
//			System.out.println();
//		}
		int count = 0;
		for(int i=0;i<s.length();i++) {
			count+=dp[i][t.length()-1];
			count = (count%MOD)+MOD;
			count%=MOD;
		}
		System.out.println(count);
	}
}

// Submitted by Subhash Yadav
import java.io.*;
import java.util.*;

public class A {

	static int m=(int) 1e9 +7;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		char s[]=sc.next().toCharArray(),t[]=sc.next().toCharArray();
		int dp[][]=new int[5005][5005];
		int j = 0;
		for(int i=0;i<s.length;i++) {
			for( j=0;j<t.length;j++) {
				dp[i+1][j+1]=dp[i+1][j]+((s[i]==t[j])?(dp[i][j]+1):0)%m;
			}
		}

		long ans=0;
		for(int i=0;i<s.length;i++) {
			ans=(ans+dp[i+1][j])%m;
		}
		System.out.println(ans);
	}

	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			while (!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] readArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}

import java.io.*;
import java.util.*;

public class A163 {
    FastScanner in;
    PrintWriter out;

    public void run() {
        try {
            in = new FastScanner();
            out = new PrintWriter(System.out);
            Locale.setDefault(Locale.US);

            String s = in.nextToken(), t = in.nextToken();
            long dyn[][] = new long[s.length() + 1][t.length() + 1];
            for (int i = 0; i < s.length(); i++)
                for (int j = 0; j < t.length(); j++) {
                    dyn[i + 1][j + 1] = dyn[i + 1][j];
                    if (s.charAt(i) == t.charAt(j))
                        dyn[i + 1][j + 1] += dyn[i][j] + 1;
                }
            long ans = 0;
            for (int i = 0; i <= s.length(); i++)
                ans += dyn[i][t.length()];
            out.println(ans);

            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new A163().run();
    }

    class FastScanner {
        BufferedReader reader;
        StringTokenizer tokenizer;

        FastScanner() {
            reader = new BufferedReader(new InputStreamReader(System.in));
        }

        FastScanner(String filename) throws FileNotFoundException {
            reader = new BufferedReader(new FileReader(filename));
        }

        String nextToken() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}

import java.io.*;
import java.util.*;
import java.lang.*;

public class cf {
    public static void main(String[] args) {
	InputStream inputStream=System.in;
	OutputStream outputStream=System.out;
	InputReader in=new InputReader(inputStream);
	PrintWriter out=new PrintWriter(outputStream);
	Task task=new Task();
	task.run(in,out);
	out.close();
    }
}

class InputReader {
    public BufferedReader br;
    public StringTokenizer st;
    public InputReader(InputStream stream) {
        br=new BufferedReader(new InputStreamReader(stream),32768);
        st=null;
    }
    public String next() {
        while (st==null || !st.hasMoreTokens()) {
            try {
                st=new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }
    public int nextInt() {return Integer.parseInt(next());}
    public long nextLong() {return Long.parseLong(next());}
    public double nextDouble() {return Double.parseDouble(next());}
}

class Task {
    public void run(InputReader in,PrintWriter out) {
	char[] s=in.next().toCharArray(),t=in.next().toCharArray();
	int mod=1000000007;
	int[][] dp=new int[s.length][t.length];
	for (int i=0;i<s.length;i++){
	    for (int j=0;j<t.length;j++) {
		dp[i][0]=(s[i]==t[0])?1:0;
	    }
	}
	for (int j=0;j<t.length-1;j++) {
	    dp[0][j+1]+=dp[0][j]+((s[0]==t[j+1])?1:0);
	    dp[0][j+1]%=mod;
	}
	for (int i=1;i<s.length;i++) {
	    for (int j=0;j<t.length-1;j++) {
		dp[i][j+1]+=dp[i][j]+((s[i]==t[j+1])?dp[i-1][j]+1:0);
		dp[i][j+1]%=mod;
	    }
	}
	int sum=0;
	for (int i=0;i<s.length;i++) {
	    sum+=dp[i][t.length-1];
	}
	out.print(sum%mod);
    }
}

import java.io.*;
import java.util.*;
import java.lang.*;

public class cf {
    public static void main(String[] args) {
	InputStream inputStream=System.in;
	OutputStream outputStream=System.out;
	InputReader in=new InputReader(inputStream);
	PrintWriter out=new PrintWriter(outputStream);
	Task task=new Task();
	task.run(in,out);
	out.close();
    }
}

class InputReader {
    public BufferedReader br;
    public StringTokenizer st;
    public InputReader(InputStream stream) {
        br=new BufferedReader(new InputStreamReader(stream),32768);
        st=null;
    }
    public String next() {
        while (st==null || !st.hasMoreTokens()) {
            try {
                st=new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }
    public int nextInt() {return Integer.parseInt(next());}
    public long nextLong() {return Long.parseLong(next());}
    public double nextDouble() {return Double.parseDouble(next());}
}

class Task {
    public void run(InputReader in,PrintWriter out) {
	char[] s=in.next().toCharArray(),t=in.next().toCharArray();
	int[][] dp=new int[s.length][t.length];
	for (int i=0;i<s.length;i++){
	    for (int j=0;j<t.length;j++) {
		dp[i][0]=(s[i]==t[0])?1:0;
	    }
	}
	for (int j=0;j<t.length-1;j++) {
	    dp[0][j+1]+=dp[0][j]+((s[0]==t[j+1])?1:0);
	}
	for (int i=1;i<s.length;i++) {
	    for (int j=0;j<t.length-1;j++) {
		dp[i][j+1]+=dp[i][j]+((s[i]==t[j+1])?dp[i-1][j]+1:0);
	    }
	}
	long sum=0;
	for (int i=0;i<s.length;i++) {
	    sum+=dp[i][t.length-1];
	}
	out.print(sum);
    }
}

import java.io.*;
import java.util.*;
import java.lang.*;

public class cf {
    public static void main(String[] args) {
	InputStream inputStream=System.in;
	OutputStream outputStream=System.out;
	InputReader in=new InputReader(inputStream);
	PrintWriter out=new PrintWriter(outputStream);
	Task task=new Task();
	task.run(in,out);
	out.close();
    }
}

class InputReader {
    public BufferedReader br;
    public StringTokenizer st;
    public InputReader(InputStream stream) {
        br=new BufferedReader(new InputStreamReader(stream),32768);
        st=null;
    }
    public String next() {
        while (st==null || !st.hasMoreTokens()) {
            try {
                st=new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }
    public int nextInt() {return Integer.parseInt(next());}
    public long nextLong() {return Long.parseLong(next());}
    public double nextDouble() {return Double.parseDouble(next());}
}

class Task {
    public void run(InputReader in,PrintWriter out) {
	char[] s=in.next().toCharArray(),t=in.next().toCharArray();
	int[][] dp=new int[s.length][t.length];
	for (int i=0;i<s.length;i++){
	    for (int j=0;j<t.length;j++) {
		dp[i][0]=(s[i]==t[0])?1:0;
	    }
	}
	for (int j=0;j<t.length-1;j++) {
	    dp[0][j+1]+=dp[0][j]+((s[0]==t[j+1])?1:0);
	}
	for (int i=1;i<s.length;i++) {
	    for (int j=0;j<t.length-1;j++) {
		dp[i][j+1]+=dp[i][j]+((s[i]==t[j+1])?dp[i-1][j]+1:0);
	    }
	}
	int sum=0;
	for (int i=0;i<s.length;i++) {
	    sum+=dp[i][t.length-1];
	}
	out.print(sum);
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskA {
    int MOD = 1000000007;
    public void solve(int testNumber, MyScanner in, PrintWriter out) {
        String s = in.next();
        String t = in.next();
        long[][] dp = new long[2][t.length()];
        int cur=0,nxt=1;
        long res =0 ;
        for (int i = 0; i < s.length(); i++) {
            long sum = 0;
            Arrays.fill(dp[nxt],0);
            for(int j=0;j<t.length();j++){
                if(t.charAt(j)==s.charAt(i)){
                    dp[nxt][j] = 1 + sum;
                    if(dp[nxt][j]>=MOD)dp[nxt][j] -= MOD;
                    res += dp[nxt][j];
                    if(res >= MOD)res -= dp[nxt][j];
                }
                if(i>0 && t.charAt(j)==s.charAt(i-1))sum += dp[cur][j];
            }
            int tmp=cur;cur=nxt;nxt=tmp;
        }
        out.println(res);
    }
}

class MyScanner {
    private final InputStream in;
    public MyScanner(InputStream in){
        this.in = in;
    }

    char[] buf = new char[2000000];
    int strLen;
    public String next() {
        try {
            strLen = 0;
            int c;
            do{
                c = in.read();
                if(c==-1)throw new NoSuchElementException();
            }while(Character.isWhitespace(c));
            do {
                buf[strLen++] = (char)c;
                c = in.read();
            } while (c!=-1 && !Character.isWhitespace(c));
            return new String(buf,0,strLen);
        } catch (IOException e) {
            throw new NoSuchElementException();
        }
    }

    }

import java.io.OutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskA {
    int MOD = 1000000007;
    public void solve(int testNumber, MyScanner in, PrintWriter out) {
        String s = in.next();
        String t = in.next();
        long[][] dp = new long[2][t.length()];
        int cur=0,nxt=1;
        long res =0 ;
        for (int i = 0; i < s.length(); i++) {
            long sum = 0;
            Arrays.fill(dp[nxt],0);
            for(int j=0;j<t.length();j++){
                if(t.charAt(j)==s.charAt(i)){
                    dp[nxt][j] = 1 + sum;
                    if(dp[nxt][j]>=MOD)dp[nxt][j] -= MOD;
                    res += dp[nxt][j];
                    if(res >= MOD)res -= dp[nxt][j];
                }
                if(i>0 && t.charAt(j)==s.charAt(i-1)){
                    sum += dp[cur][j];
                    if(sum >= MOD)sum -= MOD;
                }
            }
            int tmp=cur;cur=nxt;nxt=tmp;
        }
        out.println(res);
    }
}

class MyScanner {
    private final InputStream in;
    public MyScanner(InputStream in){
        this.in = in;
    }

    char[] buf = new char[2000000];
    int strLen;
    public String next() {
        try {
            strLen = 0;
            int c;
            do{
                c = in.read();
                if(c==-1)throw new NoSuchElementException();
            }while(Character.isWhitespace(c));
            do {
                buf[strLen++] = (char)c;
                c = in.read();
            } while (c!=-1 && !Character.isWhitespace(c));
            return new String(buf,0,strLen);
        } catch (IOException e) {
            throw new NoSuchElementException();
        }
    }

    }

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Reader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A implements Runnable {

	char[] s;
	char[] t;
	static final int MOD = 1000000007;
	private void solve() throws NumberFormatException, IOException {
		String ss = in.next();
		String st = in.next();
		s = ss.toCharArray();
		t = st.toCharArray();
		int dp[][] = new int[s.length + 1][t.length + 1];
		for (int i = 0; i < s.length; i++) {
			for (int j = 1; j <= t.length; j++)
			{
				dp[i][j] = dp[i][j - 1];
				if (t[j - 1] == s[i])
					if (i > 0) {
						dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % MOD;
					} else {
						dp[i][j] = (dp[i][j] + 1) % MOD;
					}
			}

		}

		int sum = 0;
		for (int i = 0; i < s.length; i++)
		{
			sum = sum + (dp[i][t.length]) % MOD;
		}
		out.println(sum);
	}

	FastScanner in;
	PrintWriter out;

	class FastScanner {
		BufferedReader in;
		StringTokenizer st;

		public FastScanner(Reader reader) {
			in = new BufferedReader(reader);
		}

		private boolean hasNext() throws IOException {
			while (st == null || !st.hasMoreTokens()) {
				String line = in.readLine();
				if (line == null)
					return false;
				st = new StringTokenizer(line);
			}
			return true;
		}

		private String next() throws IOException {
			if (!hasNext()) {
				return null;
			} else {
				return st.nextToken();
			}
		}

		private int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}
	}

	public static void main(String[] args) {
		new A().run();
	}

	@Override
	public void run() {
		try {
			in = new FastScanner(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			out.flush();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

import java.util.Scanner;

public class Prob163A {

	public static void main(String[] Args) {
		Scanner in = new Scanner(System.in);
		String s2 = in.next();
		String s1 = in.next();

		int mod = 1000000007;

		int[][] dp = new int[s1.length() + 1][s2.length() + 1];
		for (int i = 0; i < dp.length - 1; i++)
			for (int j = 0; j < dp[i].length - 1; j++)
				dp[i + 1][j + 1] = (dp[i][j + 1] + (s1.charAt(i) == s2
						.charAt(j) ? dp[i][j] + 1 : 0)) % mod;

		long answer = 0;
		for (int i = 0; i < dp[s1.length()].length; i++)
			answer += dp[s1.length()][i] % mod;
		System.out.println(answer);
	}
}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 *
 *
 * @author pttrung
 */
public class C {

    //   public static long x, y, gcd;
    public static int Mod = 1000000007;
    public static PrintWriter out;
    public static String s, t;
    public static int[][] dp;

    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner();
        out = new PrintWriter(System.out);
        //   System.out.println(Integer.MAX_VALUE);
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File("output.txt")));
        s = in.next();
        t = in.next();
        long result = 0;
        dp = new int[s.length()][t.length()];
        for (int[] a : dp) {
            Arrays.fill(a, -1);
        }

        for (int i = 0; i < s.length(); i++) {
            for (int j = 0; j < t.length(); j++) {
                // System.out.println(i + " " + j);
                if (dp[i][j] == -1) {
                    result += cal(i, j);
                } else {
                    result += dp[i][j];
                }
                result %= Mod;
            }
        }

        out.println(result);
        out.close();
    }

    public static int cal(int i, int j) {
        if (dp[i][j] != -1) {
            return dp[i][j];
        }
        long result = 0;
        if (s.charAt(i) == t.charAt(j)) {
            result++;
        }
        if (i + 1 < s.length() && j + 1 < t.length()) {
            result += cal(i + 1, j + 1);
            result %= Mod;
        }
        return dp[i][j] = (int) result;
    }

    public static int cross(Point a, Point b) {
        int val = a.x * b.y - a.y * b.x;
        return val;
    }

    public static long pow(long a, long b) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2);
        if (b % 2 == 0) {
            return val * val;
        } else {
            return val * val * a;
        }
    }

    public static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(Point o) {
            if (x != o.x) {
                return x - o.x;
            } else {
                return y - o.y;
            }
        }
    }
//    public static void extendEuclid(long a, long b) {
//        if (b == 0) {
//            x = 1;
//            y = 0;
//            gcd = a;
//            return;
//        }
//        extendEuclid(b, a % b);
//        long x1 = y;
//        long y1 = x - (a / b) * y;
//        x = x1;
//        y = y1;
//
//    }

    public static class FT {

        int[] data;

        FT(int n) {
            data = new int[n];
        }

        public void update(int index, int value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public int get(int index) {
            int result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}

import java.util.Scanner;

public class P169C
{
	private static int arr[][];

	private static int solve(String s, String t, int a, int b)
	{
		if (a >= arr.length || b >= arr[0].length) return 0;
		if (arr[a][b] != 0) return arr[a][b];
		else
		{
			return arr[a][b] = solve(s, t, a, b + 1) +
							(	(s.charAt(a) == t.charAt(b)) ? (solve(s, t, a + 1, b + 1) + 1) : 0);
		}

	}

	public static void main(String[] args)
	{
		Scanner myScanner = new Scanner(System.in);
		String s = myScanner.nextLine();
		String t = myScanner.nextLine();
		arr = new int[s.length()][t.length()];
		int sum = 0;
		for (int i = 0; i < arr.length; i++)
		{
			sum = (sum + solve(s, t, i, 0)) % 1000000007;
		}
		System.out.println(sum);
	}
}

import java.io.*;

public class A163 {

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String s = in.readLine();
		String t = in.readLine();
		long r = (long) 1e9 + 7;
		int[][] d = new int[s.length()][t.length()];
		for (int i = s.length() - 1; i >= 0; i--) {
			for (int j = t.length() - 1; j >= 0; j--) {
				if (j != t.length() - 1) {
					d[i][j] = d[i][j + 1];
				}
				if ((i != s.length() - 1) && (j != t.length() - 1)) {
					if (s.charAt(i) == t.charAt(j)) {
						d[i][j] += d[i + 1][j + 1] + 1;
					}
				} else {
					if (s.charAt(i) == t.charAt(j)) {
						d[i][j]++;
					}
				}

			}
		}
		long ans = 0;
		for (int i = 0; i < s.length(); i++) {
			ans += (long) d[i][0] % r;
			ans %= r;
		}
		System.out.println(ans);
		in.close();
	}

}

import java.io.*;

public class A163 {

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String s = in.readLine();
		String t = in.readLine();
		long r = (long) 1e9 + 7;
		int[][] d = new int[s.length()][t.length()];
		for (int i = s.length() - 1; i >= 0; i--) {
			for (int j = t.length() - 1; j >= 0; j--) {
				if (j != t.length() - 1) {
					d[i][j] = d[i][j + 1];
				}
				if ((i != s.length() - 1) && (j != t.length() - 1)) {
					if (s.charAt(i) == t.charAt(j)) {
						d[i][j] += d[i + 1][j + 1] + 1;
					}
				} else {
					if (s.charAt(i) == t.charAt(j)) {
						d[i][j]++;
					}
				}

			}
		}
		long ans = 0;
		for (int i = 0; i < s.length(); i++) {
			ans += (long) d[i][0] % r;
		}
		System.out.println(ans);
		in.close();
	}

}

import java.awt.geom.Line2D;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.TreeSet;

import javax.swing.text.Segment;

public class q1
{
	public static void main(String[] args) {
		//      FasterScanner in=new FasterScanner();
		//      PrintWriter out=new PrintWriter(System.out);
		//      int t=in.nextInt();
		//      for(int ii=0;ii<t;ii++)
		//      {
		new q1().solve();
		//      }//System.out.println(Long.MIN_VALUE);
		//      out.close();
	}

	public q1()
	{
		in=new FasterScanner();
		out=new PrintWriter(System.out);
	}

	FasterScanner in;
	PrintWriter out;
	long mod=1000000007L ;
	long mod1=(long)(1e18+3);
	public void solve()
	{
		String str1=in.nextLine();
		String str2=in.nextLine();
		int[][] dp=new int[str1.length()+2][str2.length()+2];
		for(int i=str1.length();i>0;i--)
		{
			for(int j=str2.length();j>0;j--)
			{
				dp[i][j]=dp[i][j+1];
				if(str1.charAt(i-1)==str2.charAt(j-1))
				{
					dp[i][j]+=dp[i+1][j+1]+1;
				}
			}
		}
		long ans=0;
		for(int i=1;i<=str1.length();i++)
			ans+=dp[i][1];

		out.println(ans);
		out.close();
	}

	public static class FasterScanner {
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = System.in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n) {
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nextLong();
			}
			return arr;
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.util.Locale;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					long prevTime = System.currentTimeMillis();
					new Main().run();
					System.err.println("Total time: "
							+ (System.currentTimeMillis() - prevTime) + " ms");
					System.err.println("Memory status: " + memoryStatus());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start();
	}

	void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		Object o = solve();
		if (o != null)
			out.println(o);
		out.close();
		in.close();
	}

	int n;
	int m;
	int MOD = 1000000007;

	private Object solve() throws IOException {
		String s = in.readLine();
		String t = in.readLine();
		n = s.length();
		m = t.length();
		System.out.println(n+" "+m);
		int[][] dp = new int[n][m];
		for (int[] arr : dp)
			Arrays.fill(arr, -1);
		int ret = 0;
		for (int i = 0; i < n; i++)
			ret = (ret + go(dp, s, t,i, 0) ) % MOD;
		return ret;
	}

	private int go(int[][] dp, String s, String t, int i, int j) {
		if (dp[i][j] != -1)
			return dp[i][j];
		dp[i][j] = 0;
		if (j < m - 1) {
			dp[i][j] = (go(dp, s, t, i, j + 1) + dp[i][j]) % MOD;
		}
		if (s.charAt(i) == t.charAt(j)) {
			if (i < n - 1 && j < m - 1) {
				dp[i][j] = (dp[i][j] + 1 + go(dp, s, t, i + 1, j + 1)) % MOD;
			} else {
				dp[i][j] = (dp[i][j] + 1) % MOD;
			}

		}
		return dp[i][j];
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

	int ni() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nl() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nd() throws IOException {
		return Double.parseDouble(nextToken());
	}

	int[] nia(int size) throws IOException {
		int[] ret = new int[size];
		for (int i = 0; i < size; i++)
			ret[i] = ni();
		return ret;
	}

	long[] nla(int size) throws IOException {
		long[] ret = new long[size];
		for (int i = 0; i < size; i++)
			ret[i] = nl();
		return ret;
	}

	double[] nda(int size) throws IOException {
		double[] ret = new double[size];
		for (int i = 0; i < size; i++)
			ret[i] = nd();
		return ret;
	}

	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}

	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}

	void printRepeat(String s, int count) {
		for (int i = 0; i < count; i++)
			out.print(s);
	}

	void printArray(int[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i > 0)
				out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}

	void printArray(long[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i > 0)
				out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}

	void printArray(double[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i > 0)
				out.print(' ');
			out.print(array[i]);
		}
		out.println();
	}

	void printArray(double[] array, String spec) {
		for (int i = 0; i < array.length; i++) {
			if (i > 0)
				out.print(' ');
			out.printf(Locale.US, spec, array[i]);
		}
		out.println();
	}

	void printArray(Object[] array) {
		boolean blank = false;
		for (Object x : array) {
			if (blank)
				out.print(' ');
			else
				blank = true;
			out.print(x);
		}
		out.println();
	}

	@SuppressWarnings("rawtypes")
	void printCollection(Collection collection) {
		boolean blank = false;
		for (Object x : collection) {
			if (blank)
				out.print(' ');
			else
				blank = true;
			out.print(x);
		}
		out.println();
	}

	static String memoryStatus() {
		return (Runtime.getRuntime().totalMemory()
				- Runtime.getRuntime().freeMemory() >> 20)
				+ "/" + (Runtime.getRuntime().totalMemory() >> 20) + " MB";
	}
}

import java.io.*;
import java.util.*;

public class A163 {
    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;

    public String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public static void main(String[] args) throws IOException {
        new A163().run();
    }

    public void solve() throws IOException {
        char[] s = nextToken().toCharArray();
        char[] t = nextToken().toCharArray();
        int[][] dp = new int[s.length][t.length];
        for (int i = 0; i < s.length; i++) {
            int cur = 1;
            for (int j = 0; j < t.length; j++) {
                if (s[i] != t[j]) {
                    dp[i][j] = 0;
                } else {
                    dp[i][j] = cur;
                }
                cur += i == 0? 0 : dp[i - 1][j];
            }
        }
        long ans = 0;
        for (int i = 0; i < s.length; i++) {
            for (int j = 0; j < t.length; j++) {
                ans += dp[i][j];
            }
        }
        out.println(ans);
    }

    public void run() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
}

import java.io.*;
import java.util.*;

public class test
{

	public static void main(String[] args)
	{
		new test().run();
	}

	PrintWriter out = null;

	int[][] dp = null;

	void run()
	{
		Scanner in = new Scanner(System.in);
		out = new PrintWriter(System.out);

		char[] s = in.next().toCharArray();
		char[] t = in.next().toCharArray();

		int slen = s.length;
		int tlen = t.length;
		int mod = 1000000007;

		dp = new int[slen][tlen];

		int total = 0;

		for (int i = 0; i < slen; i++)
		{
			if (s[i] == t[0])
			{
				total++;
				total %= mod;
				dp[i][0] = 1;
			}
		}

		for (int j = 1; j < tlen; j++)
		{
			if (s[0] == t[j])
			{
				total++;
				total %= mod;
				dp[0][j] = 1;
			}
		}

		for (int i = 1; i < slen; i++)
		{
			int sum = 0;

			for (int j = 1; j < tlen; j++)
			{
				sum += dp[i - 1][j - 1];
				if (s[i] == t[j])
				{
					dp[i][j] = sum + 1;
					total += sum + 1;
					total %= mod;
				}
			}
		}

		out.println(total);
		out.close();
	}
}