Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <cmath>
#include <iostream>
using namespace std;

bool isPrimeNum(ll x) { // 素数である場合 true を返す
  if (x <= 1) { // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt((double)x);
  for (int i = 2; i <= n; i++) {
    if (x % i == 0) { // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
constexpr ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
constexpr ll abs(ll a, ll b) {
  if (a >= b)
    return a - b;
  if (a < b)
    return b - a;
}
constexpr ll min(ll a, ll b) {
  if (a >= b)
    return b;
  if (a < b)
    return a;
}

constexpr ll max(ll a, ll b) {
  if (a >= b)
    return a;
  if (a < b)
    return b;
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ll N;

  cin >> N;
  string S;
  ll p[26];
  FOR(i, 0, 25) { p[i] = 1; }
  FOR(i, 0, N - 1) { cin >> S[i]; }
  FOR(i, 0, N - 1) {
    if (S[i] == 'a') {
      p[0]++;
    }
    if (S[i] == 'b') {
      p[1]++;
    }
    if (S[i] == 'c') {
      p[2]++;
    }
    if (S[i] == 'd') {
      p[3]++;
    }
    if (S[i] == 'e') {
      p[4]++;
    }
    if (S[i] == 'f') {
      p[5]++;
    }
    if (S[i] == 'g') {
      p[6]++;
    }
    if (S[i] == 'h') {
      p[7]++;
    }
    if (S[i] == 'i') {
      p[8]++;
    }
    if (S[i] == 'j') {
      p[9]++;
    }
    if (S[i] == 'k') {
      p[10]++;
    }
    if (S[i] == 'l') {
      p[11]++;
    }
    if (S[i] == 'm') {
      p[12]++;
    }
    if (S[i] == 'n') {
      p[13]++;
    }
    if (S[i] == 'o') {
      p[14]++;
    }
    if (S[i] == 'p') {
      p[15]++;
    }
    if (S[i] == 'q') {
      p[16]++;
    }
    if (S[i] == 'r') {
      p[17]++;
    }
    if (S[i] == 's') {
      p[18]++;
    }
    if (S[i] == 't') {
      p[19]++;
    }
    if (S[i] == 'u') {
      p[20]++;
    }
    if (S[i] == 'v') {
      p[21]++;
    }
    if (S[i] == 'w') {
      p[22]++;
    }
    if (S[i] == 'x') {
      p[23]++;
    }
    if (S[i] == 'y') {
      p[24]++;
    }
    if (S[i] == 'z') {
      p[25]++;
    }
  }

  ll ans = 1;

  FOR(i, 0, 25) { ans = ans * p[i] % MOD; }

  cout << ans - 1 << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <cmath>
#include <iostream>
using namespace std;

bool isPrimeNum(ll x) { // 素数である場合 true を返す
  if (x <= 1) { // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt((double)x);
  for (int i = 2; i <= n; i++) {
    if (x % i == 0) { // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
constexpr ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
constexpr ll abs(ll a, ll b) {
  if (a >= b)
    return a - b;
  if (a < b)
    return b - a;
}
constexpr ll min(ll a, ll b) {
  if (a >= b)
    return b;
  if (a < b)
    return a;
}

constexpr ll max(ll a, ll b) {
  if (a >= b)
    return a;
  if (a < b)
    return b;
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ll N;

  cin >> N;
  string S;
  ll p[26];
  FOR(i, 0, 25) { p[i] = 1; }

  cin >> S;

  FOR(i, 0, N - 1) {
    if (S[i] == 'a') {
      p[0]++;
    }
    if (S[i] == 'b') {
      p[1]++;
    }
    if (S[i] == 'c') {
      p[2]++;
    }
    if (S[i] == 'd') {
      p[3]++;
    }
    if (S[i] == 'e') {
      p[4]++;
    }
    if (S[i] == 'f') {
      p[5]++;
    }
    if (S[i] == 'g') {
      p[6]++;
    }
    if (S[i] == 'h') {
      p[7]++;
    }
    if (S[i] == 'i') {
      p[8]++;
    }
    if (S[i] == 'j') {
      p[9]++;
    }
    if (S[i] == 'k') {
      p[10]++;
    }
    if (S[i] == 'l') {
      p[11]++;
    }
    if (S[i] == 'm') {
      p[12]++;
    }
    if (S[i] == 'n') {
      p[13]++;
    }
    if (S[i] == 'o') {
      p[14]++;
    }
    if (S[i] == 'p') {
      p[15]++;
    }
    if (S[i] == 'q') {
      p[16]++;
    }
    if (S[i] == 'r') {
      p[17]++;
    }
    if (S[i] == 's') {
      p[18]++;
    }
    if (S[i] == 't') {
      p[19]++;
    }
    if (S[i] == 'u') {
      p[20]++;
    }
    if (S[i] == 'v') {
      p[21]++;
    }
    if (S[i] == 'w') {
      p[22]++;
    }
    if (S[i] == 'x') {
      p[23]++;
    }
    if (S[i] == 'y') {
      p[24]++;
    }
    if (S[i] == 'z') {
      p[25]++;
    }
  }

  ll ans = 1;

  FOR(i, 0, 25) { ans = ans * p[i] % MOD; }

  cout << ans - 1 << endl;
  return 0;
}