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: Wrong Answer)

import java.util.Scanner;

public class Main {

	static long MOD = 1000000007;
	//	static long MOD = 7;

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		char[] S = in.next().toCharArray();
		int[] alph = new int[26];
		for (int i = 0; i < S.length; i++) {
			alph[S[i] - 'a']++;
		}
		long ans = modpow(2, N) - 1;
		int countUnderOne = 0;
		int countOverOne = 0;
		for (int i = 0; i < alph.length; i++) {
			if (alph[i] == 1) {
				countUnderOne++;
			} else if (S.length == alph[i]) {
				ans = alph[i];
				break;
			} else if (alph[i] > 1) {
				countOverOne++;
				long modpow = modpow(2, S.length - alph[i]);
				long count = modpow(2, alph[i]) - 1 - alph[i];
				while (count < 0) {
					count += MOD;
				}
				ans = ans - (modpow * count % MOD);
				while (ans < 0) {
					ans += MOD;
				}
			}
		}
		if (countOverOne > 1) {
			long modpow = modpow(2, countOverOne) - 1 - countOverOne;
			while (modpow < 0) {
				modpow += MOD;
			}
			ans += modpow(2, countUnderOne) * modpow;
		}
		System.out.println(ans %= MOD);
		in.close();
	}

	static long modpow(long a, long n) {
		long res = 1;
		while (n > 0) {
			if ((n & 1) > 0)
				res = res * a % MOD;
			a = a * a % MOD;
			n >>= 1;
		}
		return res;
	}
}