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: Runtime Error)

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		Map<Character, HashSet<Integer>> s = new HashMap<Character, HashSet<Integer>>();
		char[] t = new char[n];
		
		String ss = sc.next();
		for(int i = 0; i < n; i++) {
			char tmp = ss.charAt(i);
			
			if(!s.containsKey(tmp)) {
				s.put(tmp, new HashSet<Integer>());
			}
			
			s.get(tmp).add(i);
		}
		
		String st = sc.next();
		for(int i = 0; i < n; i++) {
			t[i] = st.charAt(i);
		}
		
		int[] table = new int[n];
		for(int i = 0;i < n; i++) {
			table[i] = 0;
		}
		table[0] = 1;
		
		for(int i = 1; i < n; i++) {
			for(int x : s.get(t[i])) {
				if(x < i) {
					table[i] += table[x];
				}
			}
		}
		
		System.out.println(table[n - 1]);
	}
}