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 C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    int n;cin>>n;
    string s;cin>>s;
    map<char,int>a;
    rep(i,n)a[s[i]]++;
    sort(all(s));
    s.erase(unique(all(s)),s.end());
    ll ans=0;
    int m=s.size();
    if(m<=13){
    for(int i=1;i<(1<<s.size());++i){
        ll cnt=1;
        for(int j=0;j<s.size();++j){
            if((i>>j)&1){
                cnt*=a[s[j]];
                cnt%=MOD;
            }
        }
        ans+=cnt;
        ans%=MOD;
    }
    }
    else{
        vl c,d;
        for(int i=1;i<(1<<13);++i){
            ll cnt=1;
            for(int j=0;j<s.size();++j){
                if((i>>j)&1){
                    cnt*=a[s[j]];
                    cnt%=MOD;
                }
            }
            c.PB(cnt);
        }
        for(int i=0;i<(1<<m-13);++i){
            ll cnt=1;
            for(int j=0;j<m-13;++j){
                if((i>>j)&1){
                    cnt*=a[s[j+13]];
                    cnt%=MOD;
                }
            }
            d.PB(cnt);
        }
        rep(i,c.size()){
            rep(j,d.size()){
                ans+=c[i]*d[j];
                ans%=MOD;
            }
        }
    }
    cout<<ans%MOD<<endl;
}