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 JAVA (judge verdict: Accepted)

import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] s = new int[n];
		int[] t = new int[n];
		
		String ss = sc.next();
		for(int i = 0; i < n; i++) {
			s[i] = ss.charAt(i) - 'a';
		}
		
		String st = sc.next();
		for(int i = 0; i < n; i++) {
			t[i] = st.charAt(i) - 'a';
		}
		
		int[] table = new int[26];
		for(int i = 0;i < 26; i++) {
			table[i] = 0;
		}
		table[s[0]] = 1;
		
		for(int i = 1; i < n - 1; i++) {
			table[s[i]] += table[t[i]];
			table[s[i]] %= 1000000007;
		}
		
		System.out.println(table[t[n-1]]);
	}
}