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 <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }

int main() {
  ull n;
  string s;
  cin >> n >> s;

  vector<uint8_t> ss;
  unordered_set<uint8_t> sss;
  each(i, n) {
    ss.push(s[i]);
    sss.emplace(s[i]);
  }

  const ull mod = 1000000007;
  ull full = pow(2, s.size());

  if (sss.size() == n) {
    cout << ((full - 1) % mod) << endl;
  } else {

    auto result = full;
    const auto sub = n - sss.size();
    vector<tuple<uint8_t, ull>> counts;
    for (auto v : sss) {
      counts.push(make_tuple(v, count(ss.begin(), ss.end(), v)));
    }

    ull same_bits = 0;
    for (auto v : counts) {
      if (get<1>(v) != 1) {
        auto subs = s.size() - get<1>(v);
        //cout << get<1>(v) << " : " << subs << endl;
        result -= pow(2, subs);
        same_bits += get<1>(v);
      }
    }

    if (same_bits > 0) {
      result += pow(2, n - same_bits);
    }

    cout << ((result - 1) % mod) << endl;

  }


  return 0;
}