Problem p03095 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 100000000000;
const long long int Mod = 1000000007;
using ll = long long int; // long long int は64bit
using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
using pii = pair<int, int>;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rep(i, N) for (int i = 0; i < N; i++)
#define np nullptr
template <class T> bool chmax(T &former, const T &b) {
  if (former <= b) {
    former = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &former, const T &b) {
  if (b < former) {
    former = b;
    return true;
  }
  return false;
}
template <class T> T sqar(T x) { return x * x; } // sqrt(x)は平方根;
#define Sort(v)                                                                \
  std::sort(v.begin(), v.end(),                                                \
            std::greater<decltype(v[0])>()) // 降順でVをソート
#define fill(x, num) memset(x, num, sizeof(x));
typedef vector<vector<ll>> matrix;
//       cin.tie(0);ios::sync_with_stdio(false);
void cinit() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
//////////////////////////^^ *Emile
///^^^//////////////////////////////////////////////////////

ll n;
string s;
ll moji[27] = {0};

int main() {
  cin >> n >> s;
  rep(i, n) { moji[s[i] - 'a']++; }
  ll ans = 0;
  ll tmp = 0;
  for (ll mask = 1; mask < (1 << 26); mask++) {
    tmp = 1;
    rep(i, 26) {
      if (mask & (1 << i)) {
        if (tmp == 0)
          break;
        tmp *= moji[i];
        tmp %= Mod;
      }
    }
    ans += tmp;
    ans %= Mod;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 100000000000;
const long long int Mod = 1000000007;
using ll = long long int; // long long int は64bit
using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
using pii = pair<int, int>;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rep(i, N) for (int i = 0; i < N; i++)
#define np nullptr
template <class T> bool chmax(T &former, const T &b) {
  if (former <= b) {
    former = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &former, const T &b) {
  if (b < former) {
    former = b;
    return true;
  }
  return false;
}
template <class T> T sqar(T x) { return x * x; } // sqrt(x)は平方根;
#define Sort(v)                                                                \
  std::sort(v.begin(), v.end(),                                                \
            std::greater<decltype(v[0])>()) // 降順でVをソート
#define fill(x, num) memset(x, num, sizeof(x));
typedef vector<vector<ll>> matrix;
//       cin.tie(0);ios::sync_with_stdio(false);
void cinit() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
//////////////////////////^^ *Emile
///^^^//////////////////////////////////////////////////////

ll n;
string s;
ll moji[27] = {0};

int main() {
  cin >> n >> s;
  rep(i, n) { moji[s[i] - 'a']++; }
  ll ans = 0;
  rep(i, 26) {
    ans += moji[i] * (ans + 1);
    ans %= Mod;
  }
  cout << ans << endl;
  return 0;
}