Problem:
Transporter

In the year 30XX, an expedition team reached a planet and found a warp machine suggesting the existence of a mysterious supercivilization. When you go through one of its entrance gates, you can instantaneously move to the exit irrespective of how far away it is. You can move even to the end of the universe at will with this technology!

The scientist team started examining the machine and successfully identified all the planets on which the entrances to the machine were located. Each of these N planets (identified by an index from $1$ to $N$) has an entrance to, and an exit from the warp machine. Each of the entrances and exits has a letter inscribed on it.

The mechanism of spatial mobility through the warp machine is as follows:

If you go into an entrance gate labeled with c, then you can exit from any gate with label c.

If you go into an entrance located on the $i$-th planet, then you can exit from any gate located on the $j$-th planet where $i < j$.

Once you have reached an exit of the warp machine on a planet, you can continue your journey by entering into the warp machine on the same planet. In this way, you can reach a faraway planet. Our human race has decided to dispatch an expedition to the star $N$, starting from Star $1$ and using the warp machine until it reaches Star $N$. To evaluate the possibility of successfully reaching the destination. it is highly desirable for us to know how many different routes are available for the expedition team to track.

Given information regarding the stars, make a program to enumerate the passages from Star $1$ to Star $N$.

Input

The input is given in the following format.

$N$
$s$
$t$

The first line provides the number of the stars on which the warp machine is located $N$ ($2 \leq N \leq 100,000$). The second line provides a string $s$ of length $N$, each component of which represents the letter inscribed on the entrance of the machine on the star. By the same token, the third line provides a string $t$ of length $N$ consisting of the letters inscribed on the exit of the machine. Two strings $s$ and $t$ consist all of lower-case alphabetical letters, and the $i$-th letter of these strings corresponds respectively to the entrance and exit of Star $i$ machine.

Output

Divide the number of possible routes from Star $1$ to Star $N$ obtained above by 1,000,000,007, and output the remainder.

Sample Input 1

6
abbaba
baabab

Sample Output 1

5

Sample Input 2

25
neihsokcpuziafoytisrevinu
universityofaizupckoshien

Sample Output 2

4

Solution in C# (judge verdict: Accepted)

using System.Collections.Generic;
using System;

public class P
{
    public int sum { get; set; }
    public int p { get; set; }
}

public class hello
{
    public const int MOD = 1000000007;
    public static void Main()
    {
        var alp = "abcdefghijklmnopqrstuvwxyz";
        var d = new Dictionary<char, List<int>>();
        var d2 = new Dictionary<char, P>();
        for (int i = 0; i < 26; i++)
        {
            d[alp[i]] = new List<int>();
            d2[alp[i]] = new P { p = -1 };
        }
        var n = int.Parse(Console.ReadLine().Trim());
        var s = Console.ReadLine().Trim();
        var t = Console.ReadLine().Trim();
        for (int i = 0; i < n; i++) d[s[i]].Add(i);
        var ans = goDP(d, d2, s, t, n);
        Console.WriteLine(ans);
    }
    public static int goDP(Dictionary<char, List<int>> d, Dictionary<char, P> d2, string s, string t, int n)
    {
        var dp = new int[n];
        dp[0] = 1;
        for (int i = 1; i < n; i++)
        {
            dp[i] = getSum(d, d2, dp, t[i], i);
            d2[s[i]].p++;
            d2[s[i]].sum += dp[i];
            d2[s[i]].sum %= MOD;
        }
        return dp[n - 1];
    }
    public static int getSum(Dictionary<char, List<int>> d, Dictionary<char, P> d2, int[] dp, char c, int i)
    {
        var ans = 0;
        if (d2[c].p == -1 | d2[c].sum == 0)
        {
            var pp = 0;
            foreach (var x in d[c])
                if (x < i)
                {
                    ans += dp[x];
                    ans %= MOD;
                    pp++;
                }
                else break;
            if (pp > 0) pp--;
            d2[c].p = pp;
            d2[c].sum = ans;
        }
        else ans = d2[c].sum;
        return ans;
    }
}