Problem:
Score : 200 points

Problem Statement

You are given a string S of length N.
Among its subsequences, count the ones such that all characters are different, modulo 10^9+7. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings.

Here, a subsequence of a string is a concatenation of one or more characters from the string without changing the order.

Constraints

1 \leq N \leq 100000

S consists of lowercase English letters.

|S|=N

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of the subsequences such that all characters are different, modulo 10^9+7.

Sample Input 1

4
abcd

Sample Output 1

15

Since all characters in S itself are different, all its subsequences satisfy the condition.

Sample Input 2

3
baa

Sample Output 2

5

The answer is five: b, two occurrences of a, two occurrences of ba. Note that we do not count baa, since it contains two as.

Sample Input 3

5
abcab

Sample Output 3

17

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		String[] S = s.split("");
		int[] alphabetnum = new int[26];
		long answer = 1;
		for(int i = 0; i < n; i++) {
			if(S[i].equals("a")) alphabetnum[0] += 1;
			if(S[i].equals("b")) alphabetnum[1] += 1;
			if(S[i].equals("c")) alphabetnum[2] += 1;
			if(S[i].equals("d")) alphabetnum[3] += 1;
			if(S[i].equals("e")) alphabetnum[4] += 1;
			if(S[i].equals("f")) alphabetnum[5] += 1;
			if(S[i].equals("g")) alphabetnum[6] += 1;
			if(S[i].equals("h")) alphabetnum[7] += 1;
			if(S[i].equals("i")) alphabetnum[8] += 1;
			if(S[i].equals("j")) alphabetnum[9] += 1;
			if(S[i].equals("k")) alphabetnum[10] += 1;
			if(S[i].equals("l")) alphabetnum[11] += 1;
			if(S[i].equals("m")) alphabetnum[12] += 1;
			if(S[i].equals("n")) alphabetnum[13] += 1;
			if(S[i].equals("o")) alphabetnum[14] += 1;
			if(S[i].equals("p")) alphabetnum[15] += 1;
			if(S[i].equals("q")) alphabetnum[16] += 1;
			if(S[i].equals("r")) alphabetnum[17] += 1;
			if(S[i].equals("s")) alphabetnum[18] += 1;
			if(S[i].equals("t")) alphabetnum[19] += 1;
			if(S[i].equals("u")) alphabetnum[20] += 1;
			if(S[i].equals("v")) alphabetnum[21] += 1;
			if(S[i].equals("w")) alphabetnum[22] += 1;
			if(S[i].equals("x")) alphabetnum[23] += 1;
			if(S[i].equals("y")) alphabetnum[24] += 1;
			if(S[i].equals("z")) alphabetnum[25] += 1;
		}
		for(int i = 0; i < 26; i++) {
			answer *= (alphabetnum[i]+1);
			answer %= 1000000007;
		}
		answer -= 1;
		System.out.println(answer);
	}

}