prithivMLmods/Coder-Stat huggingface dataset:
Problem p03093 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define LL long long
#define fgx cerr << "--------------" << endl;
#define dgx cerr << "==============" << endl;

inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = x * 10 + c - '0';
  return x * f;
}
const int MAXN = 100010;
const int INF = 2147483600;

int N, M;
int a[MAXN + 1];

inline bool check(int x) {
  for (int i = 1; i <= N - x; i++) {
    if (a[i + x] + a[N - i + 1] < M)
      return 0;
  }
  return 1;
}
inline int calc(int x) {
  int ans = 0;
  for (int i = 1; i <= x; i++) {
    if (a[i] + a[x - i + 1] >= M)
      return INF;
    ans = max(ans, a[i] + a[x - i + 1]);
  }
  for (int i = 1; i <= N - x; i++) {
    if (a[x + i] + a[N - i + 1] < M)
      return INF;
    ans = max(ans, a[x + i] + a[N - i + 1] - M);
  }
  return ans;
}

int main() {
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  N = read();
  M = read();
  N <<= 1;
  for (int i = 1; i <= N; i++)
    a[i] = read();
  sort(a + 1, a + N + 1);
  int l = 0, r = N / 2, pos = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid * 2))
      pos = mid * 2, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\n", min(calc(pos), min(calc(0), calc(N))));
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define LL long long
#define fgx cerr << "--------------" << endl;
#define dgx cerr << "==============" << endl;

inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = x * 10 + c - '0';
  return x * f;
}
const int MAXN = 300010;
const int INF = 2147483600;

int N, M;
int a[MAXN + 1];

inline bool check(int x) {
  for (int i = 1; i <= N - x; i++) {
    if (a[i + x] + a[N - i + 1] < M)
      return 0;
  }
  return 1;
}
inline int calc(int x) {
  int ans = 0;
  for (int i = 1; i <= x; i++) {
    if (a[i] + a[x - i + 1] >= M)
      return INF;
    ans = max(ans, a[i] + a[x - i + 1]);
  }
  for (int i = 1; i <= N - x; i++) {
    if (a[x + i] + a[N - i + 1] < M)
      return INF;
    ans = max(ans, a[x + i] + a[N - i + 1] - M);
  }
  return ans;
}

int main() {
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  N = read();
  M = read();
  N <<= 1;
  for (int i = 1; i <= N; i++)
    a[i] = read();
  sort(a + 1, a + N + 1);
  int l = 0, r = N / 2, pos = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid * 2))
      pos = mid * 2, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\n", min(calc(pos), min(calc(0), calc(N))));
  return 0;
}
Problem p03093 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#define FOF(i, a, b) for (int i = a; i < b; i++)
using namespace std;
const int N = 100100;
int n, m, w, T, L, R, mi, mx, a[N];
int cal(int x, int y) { return a[x] - (x >= y) * m; }
bool chk(int x) {
  int y = x + n;
  x <<= 1;
  mx = 0;
  mi = m;
  FOF(i, 0, T) {
    w = cal(i, y) + cal((x - 1 - i + T) % T, y);
    mx = max(mx, w);
    mi = min(mi, w);
  }
  return mi >= 0;
}
int main() {
  // freopen("1.in","r",stdin);
  scanf("%d%d", &n, &m);
  T = n << 1;
  FOF(i, 0, T) scanf("%d", &a[i]);
  sort(a, a + T);
  L = 0, R = n;
  while (L < R) {
    int md = (L + R) >> 1;
    chk(md) ? R = md : L = md + 1;
  }
  chk(L);
  cout << mx << '\n';
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#define FOF(i, a, b) for (int i = a; i < b; i++)
using namespace std;
const int N = 200200;
int n, m, w, T, L, R, mi, mx, a[N];
int cal(int x, int y) { return a[x] - (x >= y) * m; }
bool chk(int x) {
  int y = x + n;
  x <<= 1;
  mx = 0;
  mi = m;
  FOF(i, 0, T) {
    w = cal(i, y) + cal((x - 1 - i + T) % T, y);
    mx = max(mx, w);
    mi = min(mi, w);
  }
  return mi >= 0;
}
int main() {
  // freopen("1.in","r",stdin);
  scanf("%d%d", &n, &m);
  T = n << 1;
  FOF(i, 0, T) scanf("%d", &a[i]);
  sort(a, a + T);
  L = 0, R = n;
  while (L < R) {
    int md = (L + R) >> 1;
    chk(md) ? R = md : L = md + 1;
  }
  chk(L);
  cout << mx << '\n';
}
Problem p03093 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
using namespace std;
const int N = 100005, INF = 0X3F3F3F3F;
int n, P, a[N], b[N], ans = INF;
bool chk(int mid) {
  rep(i, 1, n) b[i] = a[i] - (i >= n - mid + 1) * P;
  inplace_merge(b + 1, b + n - mid + 1, b + 1 + n);
  int mx = 0;
  rep(i, 1, (n + 1) / 2) {
    if (b[i] + b[n + 1 - i] < 0)
      return 0;
    mx = max(mx, b[i] + b[n + 1 - i]);
  }
  /*printf("%d:",mid);
  rep(i,1,n)printf("%d ",b[i]);
  puts("");*/
  ans = min(ans, mx);
  return 1;
}
int main() {
  scanf("%d%d", &n, &P);
  n *= 2;
  rep(i, 1, n) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  int l = 0, r = n;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (chk(mid))
      l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
using namespace std;
const int N = 200005, INF = 0X3F3F3F3F;
int n, P, a[N], b[N], ans = INF;
bool chk(int mid) {
  rep(i, 1, n) b[i] = a[i] - (i >= n - mid + 1) * P;
  inplace_merge(b + 1, b + n - mid + 1, b + 1 + n);
  int mx = 0;
  rep(i, 1, (n + 1) / 2) {
    if (b[i] + b[n + 1 - i] < 0)
      return 0;
    mx = max(mx, b[i] + b[n + 1 - i]);
  }
  /*printf("%d:",mid);
  rep(i,1,n)printf("%d ",b[i]);
  puts("");*/
  ans = min(ans, mx);
  return 1;
}
int main() {
  scanf("%d%d", &n, &P);
  n *= 2;
  rep(i, 1, n) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  int l = 0, r = n;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (chk(mid))
      l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%d\n", ans);
  return 0;
}
Problem p03093 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int N, M;
int a[500005];
bool check1(int Now) {
  int L = 1, R = Now;
  while (a[L] + a[R] < M && L < R)
    L++, R--;
  if (a[L] + a[R] >= M)
    return false;
  return true;
}
bool check2(int Now) {
  int L = Now + 1, R = N;
  while (a[L] + a[R] >= M && L < R)
    L++, R--;
  if (a[L] + a[R] < M)
    return false;
  return true;
}
int main() {
  scanf("%d%d", &N, &M);
  N *= 2;
  for (int i = 1; i <= N; i++)
    scanf("%d", &a[i]);
  sort(a + 1, a + N + 1);
  int l = 0, r = N, ans;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check2(mid) && check1(mid))
      r = mid - 1, ans = mid;
    else if (!check1(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  if (ans % 2)
    ans++;
  int L = ans + 1, R = N, anss = 0;
  while (L <= R)
    anss = max((a[L] + a[R]) % M, anss), L++, R--;
  L = 1, R = anss;
  while (L <= R)
    anss = max((a[L] + a[R]) % M, anss), L++, R--;
  printf("%d", anss);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int N, M;
int a[500005];
bool check1(int Now) {
  int L = 1, R = Now;
  while (a[L] + a[R] < M && L < R)
    L++, R--;
  if (a[L] + a[R] >= M)
    return false;
  return true;
}
bool check2(int Now) {
  int L = Now + 1, R = N;
  while (a[L] + a[R] >= M && L < R)
    L++, R--;
  if (a[L] + a[R] < M)
    return false;
  return true;
}
int main() {
  scanf("%d%d", &N, &M);
  N *= 2;
  for (int i = 1; i <= N; i++)
    scanf("%d", &a[i]);
  sort(a + 1, a + N + 1);
  int l = 0, r = N, ans;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check2(mid) && check1(mid))
      r = mid - 1, ans = mid;
    else if (!check1(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  if (ans % 2)
    ans++;
  int L = ans + 1, R = N, anss = 0;
  while (L <= R)
    anss = max((a[L] + a[R]) % M, anss), L++, R--;
  L = 1, R = ans;
  while (L <= R)
    anss = max((a[L] + a[R]) % M, anss), L++, R--;
  printf("%d", anss);
  return 0;
}
Problem p03093 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <stdio.h>
#define maxn 100005
using namespace std;
int n, m, a[maxn];
int judge(int x) {
  for (int i = 2 * x + 1, j = 1; i <= 2 * n; i++, j++)
    if (a[i] + a[2 * n - j + 1] < m)
      return 0;
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= 2 * n; i++)
    scanf("%d", &a[i]);
  sort(a + 1, a + 2 * n + 1);
  int l = 0, r = n, pos;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (judge(mid))
      pos = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  int ans = 0;
  for (int i = 1; i <= pos; i++)
    ans = max(ans, a[i] + a[2 * pos - i + 1]);
  for (int i = 2 * pos + 1, j = 1; i <= 2 * n; i++, j++)
    ans = max(ans, a[i] + a[2 * n - j + 1] - m);
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <stdio.h>
#define maxn 200005
using namespace std;
int n, m, a[maxn];
int judge(int x) {
  for (int i = 2 * x + 1, j = 1; i <= 2 * n; i++, j++)
    if (a[i] + a[2 * n - j + 1] < m)
      return 0;
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= 2 * n; i++)
    scanf("%d", &a[i]);
  sort(a + 1, a + 2 * n + 1);
  int l = 0, r = n, pos;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (judge(mid))
      pos = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  int ans = 0;
  for (int i = 1; i <= pos; i++)
    ans = max(ans, a[i] + a[2 * pos - i + 1]);
  for (int i = 2 * pos + 1, j = 1; i <= 2 * n; i++, j++)
    ans = max(ans, a[i] + a[2 * n - j + 1] - m);
  printf("%d\n", ans);
  return 0;
}
Problem p03093 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 10;

int n, mod, a[N];

int calcmin(int l, int r) {
  int Min = mod << 1;
  for (int _l = l, _r = r; _l <= _r; _l++, _r--) {
    //		printf("__ %d %d %d [%d\n",_l,_r,a[_l]+a[_r],Min);
    Min = min(Min, a[_l] + a[_r]);
  }
  return Min;
}
int main() {
  scanf("%d%d", &n, &mod);
  n <<= 1;

  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  sort(a + 1, a + 1 + n);

  int l = 0, r = (n >> 1) - 1, pos = n << 1 | 1; // pos - n

  while (l <= r) {
    int mid = l + r >> 1;
    //		printf("[] %d %d\n",mid<<1|1,calcmin(mid<<1|1,n));
    if (calcmin(mid << 1 | 1, n) >= mod) {
      pos = mid << 1 | 1;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  //	printf("__ %d\n",pos);

  int res = 0;
  for (int i = 1; i <= pos - 1; i++) {
    res = max(res, a[i] + a[pos - i]);
  }

  for (int i = pos; i <= n; i++) {
    //		printf("%d %d %d\n",n+pos,i,n+pos-i);
    res = max(res, (a[i] + a[n + pos - i]) % mod);
  }

  cout << res;
  return 0;
}

/*

3 10
0 2 3 4 5 9

*/

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 10;

int n, mod, a[N];

int calcmin(int l, int r) {
  int Min = mod << 1;
  for (int _l = l, _r = r; _l <= _r; _l++, _r--) {
    //		printf("__ %d %d %d [%d\n",_l,_r,a[_l]+a[_r],Min);
    Min = min(Min, a[_l] + a[_r]);
  }
  return Min;
}
int main() {
  scanf("%d%d", &n, &mod);
  n <<= 1;

  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  sort(a + 1, a + 1 + n);

  int l = 0, r = (n >> 1) - 1, pos = n | 1; // pos - n

  while (l <= r) {
    int mid = l + r >> 1;
    //		printf("[] %d %d\n",mid<<1|1,calcmin(mid<<1|1,n));
    if (calcmin(mid << 1 | 1, n) >= mod) {
      pos = mid << 1 | 1;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  //	printf("__ %d\n",pos);

  int res = 0;
  for (int i = 1; i <= pos - 1; i++) {
    res = max(res, a[i] + a[pos - i]);
  }

  for (int i = pos; i <= n; i++) {
    //		printf("%d %d %d\n",n+pos,i,n+pos-i);
    res = max(res, (a[i] + a[n + pos - i]) % mod);
  }

  cout << res;
  return 0;
}

/*

3 10
0 2 3 4 5 9

*/
Problem p03093 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>

const int MN = 100005;

int N, M, A[MN], Ans;

inline bool check(int pos) {
  int Now = 0;
  for (int i = 1; i <= pos; ++i)
    Now = std::max(Now, A[i] + A[2 * pos - i + 1]);
  for (int i = 1; i <= N - pos; ++i) {
    int v = A[2 * pos + i] + A[2 * N - i + 1];
    if (v < M)
      return 0;
    Now = std::max(Now, v - M);
  }
  Ans = std::min(Ans, Now);
  return 1;
}

int main() {
  scanf("%d%d", &N, &M), Ans = M;
  for (int i = 1; i <= 2 * N; ++i)
    scanf("%d", &A[i]);
  std::sort(A + 1, A + 2 * N + 1);
  int l = 0, r = N, mid;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\n", Ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>

const int MN = 200005;

int N, M, A[MN], Ans;

inline bool check(int pos) {
  int Now = 0;
  for (int i = 1; i <= pos; ++i)
    Now = std::max(Now, A[i] + A[2 * pos - i + 1]);
  for (int i = 1; i <= N - pos; ++i) {
    int v = A[2 * pos + i] + A[2 * N - i + 1];
    if (v < M)
      return 0;
    Now = std::max(Now, v - M);
  }
  Ans = std::min(Ans, Now);
  return 1;
}

int main() {
  scanf("%d%d", &N, &M), Ans = M;
  for (int i = 1; i <= 2 * N; ++i)
    scanf("%d", &A[i]);
  std::sort(A + 1, A + 2 * N + 1);
  int l = 0, r = N, mid;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\n", Ans);
  return 0;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  string S;
  int count[26] = {};

  cin >> N;
  cin >> S;

  for (int i = 0; i < N; i++) {
    count[S[i] - 'a']++;
  }

  long long int ans = 1;
  for (int i = 0; i < N; i++) {
    ans *= count[i] + 1;
    ans %= 1000000007;
  }
  cout << ans - 1 << endl;
  return 0;
}

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

int main() {
  int N;
  string S;
  int count[26] = {};

  cin >> N;
  cin >> S;

  for (int i = 0; i < N; i++) {
    count[S[i] - 'a']++;
  }

  long long int ans = 1;
  for (int i = 0; i < 26; i++) {
    ans *= count[i] + 1;
    ans %= 1000000007;
  }
  cout << ans - 1 << endl;
  return 0;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const long long mod = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n; i++)
#define rep2(i, x, n) for (int i = x; i < n; i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first
#define S second
#define PB push_back
#define MP make_pair
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<long long>;
using vvl = vector<vl>;
using vp = vector<pair<int, int>>;

typedef pair<int, int> P;
string s;
int k;
ll INF = 10000000000000000;

int main() {
  int N;
  string S;
  cin >> N >> S;
  vi abc(26, 0);
  rep(i, N) { abc[S[i] - 'a']++; }
  ll ans = 1;
  rep(i, N) {
    ans = ans * (abc[i] + 1);
    ans %= mod;
  }
  cout << ans - 1 << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const long long mod = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n; i++)
#define rep2(i, x, n) for (int i = x; i < n; i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first
#define S second
#define PB push_back
#define MP make_pair
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<long long>;
using vvl = vector<vl>;
using vp = vector<pair<int, int>>;

typedef pair<int, int> P;
string s;
int k;
ll INF = 10000000000000000;

int main() {
  int N;
  string S;
  cin >> N >> S;
  vi abc(26, 0);
  rep(i, N) { abc[S[i] - 'a']++; }
  ll ans = 1;
  rep(i, 26) {
    ans *= abc[i] + 1;
    ans %= mod;
  }
  cout << ans - 1 << endl;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;

int main() {
  int n;
  string s;
  cin >> n >> s;
  ll ans = 1;
  vector<ll> al(26, 0);
  for (int i = 0; i < n; i++) {
    al[s[i] - 'a']++;
  }
  for (int i = 0; i < n; i++) {
    ans *= (al[i] + 1);
    ans %= MOD;
  }
  cout << ans - 1 << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;

int main() {
  int n;
  string s;
  cin >> n >> s;
  ll ans = 1;
  vector<ll> al(26, 0);
  for (int i = 0; i < n; i++) {
    al[s[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    ans *= (al[i] + 1);
    ans %= MOD;
  }
  cout << ans - 1 << endl;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
  int N;
  string S;

  cin >> N >> S;

  vector<int> count(26);

  for (int i = 0; i < N; i++) {
    count.at((int)(S.at(i) - 'a'))++;
  }

  ll ans = 1;
  int div = 1000000007;

  for (int i = 0; i < N; i++) {
    ans *= count.at(i) + 1;
    ans %= div;
  }

  cout << ans - 1 << endl;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
  int N;
  string S;

  cin >> N >> S;

  vector<int> count(26);

  for (int i = 0; i < N; i++) {
    count.at((int)(S.at(i) - 'a'))++;
  }

  ll ans = 1;
  int div = 1000000007;

  for (int i = 0; i < 26; i++) {
    ans *= count.at(i) + 1;
    ans %= div;
  }

  cout << ans - 1 << endl;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const ll Mod = 1e9 + 7;

ll Cnt[26];

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

  for (ll i = 0; i < n; i++)
    Cnt[s[i] - 'a']++;

  ll Ans = 1;

  for (ll i = 0; i < n; i++)
    Ans = (Ans * (Cnt[i] + 1)) % Mod;

  cout << (Ans - 1 + Mod) % Mod;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const ll Mod = 1e9 + 7;

ll Cnt[26];

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

  for (ll i = 0; i < n; i++)
    Cnt[s[i] - 'a']++;

  ll Ans = 1;

  for (ll i = 0; i < 26; i++)
    Ans = (Ans * (Cnt[i] + 1)) % Mod;

  cout << (Ans - 1 + Mod) % Mod;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define riterator reverse_iterator
using namespace std;

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar()) {
    if (ch == '-')
      f = -1;
  }
  for (; isdigit(ch); ch = getchar()) {
    x = x * 10 + ch - 48;
  }
  return x * f;
}

const int N = 1e5;
const int S = 26;
const int P = 1e9 + 7;
char a[N + 3];
int cnt[S + 3];
int n;

int main() {
  scanf("%d%s", &n, a + 1);
  for (int i = 1; i <= n; i++)
    cnt[a[i] - 96]++;
  llong ans = 1ll;
  for (int i = 1; i <= n; i++)
    ans = ans * (cnt[i] + 1ll) % P;
  ans = (ans - 1 + P) % P;
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define riterator reverse_iterator
using namespace std;

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar()) {
    if (ch == '-')
      f = -1;
  }
  for (; isdigit(ch); ch = getchar()) {
    x = x * 10 + ch - 48;
  }
  return x * f;
}

const int N = 1e5;
const int S = 26;
const int P = 1e9 + 7;
char a[N + 3];
int cnt[S + 3];
int n;

int main() {
  scanf("%d%s", &n, a + 1);
  for (int i = 1; i <= n; i++)
    cnt[a[i] - 96]++;
  llong ans = 1ll;
  for (int i = 1; i <= S; i++)
    ans = ans * (cnt[i] + 1ll) % P;
  ans = (ans - 1 + P) % P;
  printf("%lld\n", ans);
  return 0;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
long long co[30] = {0};
long long ans = 1;
int main() {
  int n;
  string s;
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    co[int(s[i] - 'a')]++;
  }
  for (int i = 0; i < n; i++) {
    ans = ans * (co[i] + 1) % 1000000007;
  }
  ans--;
  if (ans < 0) {
    ans += 1000000007;
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
long long co[30] = {0};
long long ans = 1;
int main() {
  int n;
  string s;
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    co[int(s[i] - 'a')]++;
  }
  for (int i = 0; i < 26; i++) {
    ans = ans * (co[i] + 1) % 1000000007;
  }
  ans--;
  if (ans < 0) {
    ans += 1000000007;
  }
  cout << ans << endl;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int mod = 1'000'000'007;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> num(26, 0);
  for (int i = 0; i < n; i++)
    num[s[i] - 'a']++;
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    ans *= num[i] + 1;
    ans %= mod;
  }
  cout << (ans + mod - 1) % mod << endl;
}

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

int mod = 1'000'000'007;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> num(26, 0);
  for (int i = 0; i < n; i++)
    num[s[i] - 'a']++;
  long long ans = 1;
  for (int i = 0; i < 26; i++) {
    ans *= num[i] + 1;
    ans %= mod;
  }
  cout << (ans + mod - 1) % mod << endl;
}
Problem p03095 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int64_t n, mod = 1000000007;
  string s;
  cin >> n >> s;

  vector<int64_t> cnt(26, 0);
  for (auto &c : s) {
    cnt[c - 'a']++;
  }

  int64_t ans = 0;

  for (int i = 1; i < (1 << 26); i++) {
    int64_t tmp = 0;
    for (int j = 0; j < 26; j++) {
      if ((i >> j) & 1) {
        if (tmp == 0) {
          tmp = cnt[j];
        } else {
          (tmp *= cnt[j]) %= mod;
        }
      }
    }
    (ans += tmp) %= mod;
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
  int64_t n, mod = 1000000007;
  string s;
  cin >> n >> s;

  vector<int64_t> cnt(26, 0);
  for (auto &c : s) {
    cnt[c - 'a']++;
  }

  int64_t ans = 0;

  for (int i = 0; i < 26; i++) {
    int64_t tmp = cnt[i];
    for (int j = i + 1; j < 26; j++) {
      (tmp *= cnt[j] + 1) %= mod;
    }
    (ans += tmp) %= mod;
  }

  cout << ans << endl;

  return 0;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
  int64_t N, ans = 1;
  string S;
  cin >> N >> S;
  vector<int64_t> A(26);
  for (int i = 0; i < N; i++) {
    A.at(S.at(i) - 'a')++;
  }

  for (int i = 0; i < N; i++) {
    ans = ans * (A.at(i) + 1) % 1000000007;
  }
  cout << ans - 1 << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
  int64_t N, ans = 1;
  string S;
  cin >> N >> S;
  vector<int64_t> A(26);
  for (int i = 0; i < N; i++) {
    A.at(S.at(i) - 'a')++;
  }

  for (int i = 0; i < 26; i++) {
    ans = ans * (A.at(i) + 1) % 1000000007;
  }
  cout << ans - 1 << endl;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int a[300005];
char s[100005];
int cnt[30];
ll mod = 1e9 + 7;
int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin >> n;
  cin >> s;
  int len = strlen(s);
  ll ans = 1;
  for (int i = 0; i < len; i++)
    cnt[s[i] - 'a']++;
  for (int i = 0; i <= 25; i++) {
    ans = (ans * (cnt[i] + 1)) % mod;
  }
  ans = (ans - 1 + mod) % mod;
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int a[300005];
char s[100005];
int cnt[30];
ll mod = 1e9 + 7;
int main() {
#ifndef ONLINE_JUDGE
  // freopen("in.txt","r",stdin);
#endif
  ios::sync_with_stdio(false);
  cin >> n;
  cin >> s;
  int len = strlen(s);
  ll ans = 1;
  for (int i = 0; i < len; i++)
    cnt[s[i] - 'a']++;
  for (int i = 0; i <= 25; i++) {
    ans = (ans * (cnt[i] + 1)) % mod;
  }
  ans = (ans - 1 + mod) % mod;
  cout << ans << endl;

  return 0;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
// Miss Me??
#include <bits/stdc++.h>
using namespace std;

#define boost                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define int long long int
#define pb push_back
#define endl "\n"
#define ff first
#define ss second
#define N 200009
#define mod 1000000007
#define cn continue
#define bre break
#define pr pair<int, int>

int n;
string s;
int see[26];

signed main() {
  boost;
  cin >> n >> s;
  for (int i = 0; i < 26; i++) {
    see[i] = 1;
  }
  for (int i = 0; i < s.length(); i++) {
    see[s[i] - 'a']++;
  }
  int ans = 1;
  for (int i = 0; i < n; i++) {
    ans *= see[i];
    ans %= mod;
  }
  cout << ((ans - 1) + mod) % mod << endl;
}

Fixed submission:
// Miss Me??
#include <bits/stdc++.h>
using namespace std;

#define boost                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define int long long int
#define pb push_back
#define endl "\n"
#define ff first
#define ss second
#define N 200009
#define mod 1000000007
#define cn continue
#define bre break
#define pr pair<int, int>

int n;
string s;
int see[26];

signed main() {
  boost;
  cin >> n >> s;
  for (int i = 0; i < 26; i++) {
    see[i] = 1;
  }
  for (int i = 0; i < s.length(); i++) {
    see[s[i] - 'a']++;
  }
  int ans = 1;
  for (int i = 0; i < 26; i++) {
    ans *= see[i];
    ans %= mod;
  }
  cout << ((ans - 1) + mod) % mod << endl;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
using vc = vector<char>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, t) for (int i = s; i < t; i++)
#define RNG(i, s, t, u) for (int i = s; i < t; i += u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<long> cnt(26, 0);
  rep(i, n) { cnt.at(s.at(i) - '0')++; }
  long ans = 1;
  rep(i, 26) {
    ans *= cnt.at(i) + 1;
    ans %= MOD;
  }
  cout << (ans + MOD - 1) % MOD << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
using vc = vector<char>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, t) for (int i = s; i < t; i++)
#define RNG(i, s, t, u) for (int i = s; i < t; i += u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<long> cnt(26, 0);
  rep(i, n) { cnt.at(s.at(i) - 'a')++; }
  long ans = 1;
  rep(i, 26) {
    ans *= cnt.at(i) + 1;
    ans %= MOD;
  }
  cout << (ans + MOD - 1) % MOD << endl;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

int c[26];
const long long MOD = 1e9 + 7;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int n;
  cin >> n;
  string s;
  cin >> s;

  for (int i = 0; i < n; i++) {
    c[s[i] - 'a']++;
  }
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    ans *= (c[i] + 1);
    ans %= MOD;
  }
  cout << ans - 1 << '\n';

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int c[26];
const long long MOD = 1e9 + 7;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int n;
  cin >> n;
  string s;
  cin >> s;

  for (int i = 0; i < n; i++) {
    c[s[i] - 'a']++;
  }
  long long ans = 1;
  for (int i = 0; i < 26; i++) {
    ans *= (c[i] + 1LL);
    ans %= MOD;
  }
  cout << ans - 1 << '\n';

  return 0;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
#define int long long
#define MOD 1000000007
using namespace std;

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n;
  cin >> n;
  string s;
  cin >> s;
  int v[26] = {};
  for (int i = 0; i < n; i++) {
    ++v[s[i] - 'a'];
  }
  vector<int> p;
  for (int i = 0; i < 26; i++) {
    if (v[i] != 0)
      p.push_back(v[i]);
  }
  int ans = 0, prev = 0;
  for (auto i : p) {
    ans = (ans + (i * ((1 + prev) % MOD)) % MOD) % MOD;
    prev = ans;
  }
  cout << ans << '\n';
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
#define int long long
#define MOD 1000000007
using namespace std;

int32_t main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int v[26] = {};
  for (int i = 0; i < n; i++) {
    ++v[s[i] - 'a'];
  }
  vector<int> p;
  for (int i = 0; i < 26; i++) {
    if (v[i] != 0)
      p.push_back(v[i]);
  }
  int ans = 0, prev = 0;
  for (auto i : p) {
    ans = (ans + (i * ((1 + prev) % MOD)) % MOD) % MOD;
    prev = ans;
  }
  cout << ans << '\n';
  return 0;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
// finish date: 2019/2/28

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int(i) = a; (i) < (b); (i)++)
#define rep(i, n) FOR(i, 0, n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;

// 足し算
int add(int a, int b) { return (int)(((ll)a + b + bigmod) % bigmod); }

// 引き算
int sub(int a, int b) { return (int)(((ll)a - b + bigmod) % bigmod); }

// 掛け算
int mul(int a, int b) {
  return (int)(((ll)(a % bigmod) * (b % bigmod)) % bigmod);
}

int main() {
  int N;
  string S;
  cin >> N >> S;
  vi cnt(26, 0);
  rep(i, N) { cnt[S[i] - 'a']++; }

  int ans = 0;
  rep(i, N) {
    if (cnt[i] == 0)
      continue;
    ans = add(ans, mul(ans, cnt[i]));
    ans = add(ans, cnt[i]);
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
// finish date: 2019/2/28

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int(i) = a; (i) < (b); (i)++)
#define rep(i, n) FOR(i, 0, n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;

// 足し算
int add(int a, int b) { return (int)(((ll)a + b + bigmod) % bigmod); }

// 引き算
int sub(int a, int b) { return (int)(((ll)a - b + bigmod) % bigmod); }

// 掛け算
int mul(int a, int b) {
  return (int)(((ll)(a % bigmod) * (b % bigmod)) % bigmod);
}

int main() {
  int N;
  string S;
  cin >> N >> S;
  vi cnt(26, 0);
  rep(i, N) { cnt[S[i] - 'a']++; }

  int ans = 0;
  rep(i, 26) {
    if (cnt[i] == 0)
      continue;
    ans = add(ans, mul(ans, cnt[i]));
    ans = add(ans, cnt[i]);
  }
  cout << ans << endl;

  return 0;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
  ll mod = 1e9 + 7;
  int n;
  string s;
  string a = "abcdefghijklmnopqrstuvwxyz";
  cin >> n >> s;
  ll ans = 1;
  ll vec[26] = {};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      if (s[i] == a[j]) {
        vec[j]++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    ans *= vec[i] + 1;
    ans %= mod;
  }
  cout << ans - 1 << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
  ll mod = 1e9 + 7;
  int n;
  string s;
  string a = "abcdefghijklmnopqrstuvwxyz";
  cin >> n >> s;
  ll ans = 1;
  ll vec[26] = {};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      if (s[i] == a[j]) {
        vec[j]++;
      }
    }
  }
  for (int i = 0; i < 26; i++) {
    ans *= vec[i] + 1;
    ans %= mod;
  }
  cout << ans - 1 << endl;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF (((ll)1 << 31) - 1)
#define eps LDBL_EPSILON
#define moder (1000000007)
#define pie 3.141592653589793238462643383279
#define P std::pair<int, int>
#define prique priority_queue
#define ggr                                                                    \
  getchar();                                                                   \
  getchar();                                                                   \
  return 0;
using namespace std;
int n;
string s;
int a[26];
int dp[26];
signed main() {
  cin >> n >> s;
  rep(i, n) { a[s[i] - 'a']++; }
  int ans = 1;
  rep(i, n) {
    ans *= (a[i] + 1);
    ans %= moder;
  }
  cout << ans - 1 << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF (((ll)1 << 31) - 1)
#define eps LDBL_EPSILON
#define moder (1000000007)
#define pie 3.141592653589793238462643383279
#define P std::pair<int, int>
#define prique priority_queue
#define ggr                                                                    \
  getchar();                                                                   \
  getchar();                                                                   \
  return 0;
using namespace std;
int n;
string s;
int a[26];
int dp[26];
signed main() {
  cin >> n >> s;
  rep(i, n) { a[s[i] - 'a']++; }
  int ans = 1;
  rep(i, 26) {
    ans *= (a[i] + 1);
    ans %= moder;
  }
  cout << ans - 1 << endl;
  return 0;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int cnt[256];
void solve() {
  int n;
  string s;
  cin >> n >> s;
  for (int i = 0; i < n; i++)
    cnt[s[i]]++;
  ll ret = 1;
  for (int i = 0; i < 256; i++) {
    ret *= ++s[i];
    ret %= 1000000007;
  }
  ret--;
  cout << ret << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int cnt[256];
void solve() {
  int n;
  string s;
  cin >> n >> s;
  for (int i = 0; i < n; i++)
    cnt[s[i]]++;
  ll ret = 1;
  for (int i = 0; i < 256; i++) {
    ret *= ++cnt[i];
    ret %= 1000000007;
  }
  ret--;
  cout << ret << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
// スタックサイズ: 100MB

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) (v).begin(), (v).end()

// mod演算ライブラリ (factset以降に関しては, modは素数限定)
ll mod = 1000000007;

ll mul_mod(ll a, ll b) { // a * b
  return ((a % mod) * (b % mod)) % mod;
}

int main() {

  ll N;
  string S;
  cin >> N;
  cin >> S;
  vll alfa(26, 0);
  rep(i, N) { alfa[S[i] - 'a'] += 1; }

  ll ans = 1;
  rep(i, N) { ans = mul_mod(alfa[i] + 1, ans); }
  cout << ans - 1 << endl;
}

Fixed submission:
// スタックサイズ: 100MB

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) (v).begin(), (v).end()

// mod演算ライブラリ (factset以降に関しては, modは素数限定)
ll mod = 1000000007;

ll mul_mod(ll a, ll b) { // a * b
  return ((a % mod) * (b % mod)) % mod;
}

int main() {

  ll N;
  string S;
  cin >> N;
  cin >> S;
  vll alfa(26, 0);
  rep(i, N) { alfa[S[i] - 'a'] += 1; }

  ll ans = 1;
  rep(i, 26) { ans = mul_mod(alfa[i] + 1, ans); }
  cout << ans - 1 << endl;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define rep(i, s, n) for (int i = s; i < n; i++)
#define MOD 1000000007;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  ll ans = 1;
  vector<int> count(26, 0);

  for (int i = 0; i < n; i++) {
    count[s[i] - 'a']++;
  }

  rep(i, 0, n) {
    if (count[i] == 0) {
      continue;
    }
    ans *= count[i] + 1;
    ans %= MOD;
  }
  cout << ans - 1 << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define rep(i, s, n) for (int i = s; i < n; i++)
#define MOD 1000000007;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  ll ans = 1;
  vector<int> count(26, 0);

  for (int i = 0; i < n; i++) {
    count[s[i] - 'a']++;
  }

  rep(i, 0, count.size()) {
    if (count[i] == 0) {
      continue;
    }
    ans *= count[i] + 1;
    ans %= MOD;
  }
  cout << ans - 1 << endl;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

ll cnt[30];

ll pow_2(ll x) {
  ll ret = 1;
  for (int i = 0; i < x; i++) {
    ret = ret * 2 % 1000000007;
  }
  return ret;
}

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

  for (int i = 0; i < n; i++) {
    cnt[s[i] - 'a']++;
  }

  ll cnt2 = 0;
  ll ans = 1;
  for (int i = 0; i < n; i++) {
    if (cnt[i] == 1) {
      cnt2++;
    } else if (cnt[i] > 1) {
      ans *= 1 + cnt[i];
    }
    ans %= 1000000007;
  }
  if (cnt2 == n)
    cout << pow_2(cnt2) - 1 << endl;
  else
    cout << pow_2(cnt2) * ans % 1000000007 - 1 << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

ll cnt[30];

ll pow_2(ll x) {
  ll ret = 1;
  for (int i = 0; i < x; i++) {
    ret = ret * 2 % 1000000007;
  }
  return ret;
}

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

  for (int i = 0; i < n; i++) {
    cnt[s[i] - 'a']++;
  }

  ll cnt2 = 0;
  ll ans = 1;
  for (int i = 0; i < 26; i++) {
    if (cnt[i] == 1) {
      cnt2++;
    } else if (cnt[i] > 1) {
      ans *= 1 + cnt[i];
    }
    ans %= 1000000007;
  }
  if (cnt2 == n)
    cout << pow_2(cnt2) - 1 << endl;
  else
    cout << pow_2(cnt2) * ans % 1000000007 - 1 << endl;
  return 0;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
  ll N;
  string S;
  cin >> N >> S;
  vector<ll> count(26, 0);
  rep(i, N) {
    char s = S[i];
    int num = (int)(s - 'a');
    count[num]++;
  }
  ll ans = 1;
  rep(i, N) {
    ans *= (count[i] + 1);
    ans %= 1000000007;
  }
  if (ans == 0) {
    cout << 1000000006 << endl;
  } else {
    cout << ans - 1 << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
  ll N;
  string S;
  cin >> N >> S;
  vector<ll> count(26, 0);
  rep(i, N) {
    char s = S[i];
    int num = (int)(s - 'a');
    count[num]++;
  }
  ll ans = 1;
  rep(i, 26) {
    ans *= (count[i] + 1);
    ans %= 1000000007;
  }
  if (ans == 0) {
    cout << 1000000006 << endl;
  } else {
    cout << ans - 1 << endl;
  }
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;
  string str;
  cin >> str;
  ll cnt[26];
  for (int i = 0; i < 26; i++)
    cnt[i] = 0;
  for (int i = 0; i < n; i++) {
    cnt[str[i] - 'a']++;
  }
  ll ans = 1;
  for (int i = 0; i < n; i++) {
    ans = (ans * (cnt[i] + 1)) % MOD;
  }
  cout << ans - 1 << endl;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;
  string str;
  cin >> str;
  ll cnt[26];
  for (int i = 0; i < 26; i++)
    cnt[i] = 0;
  for (int i = 0; i < n; i++) {
    cnt[str[i] - 'a']++;
  }
  ll ans = 1;
  for (int i = 0; i < 26; i++) {
    ans = (ans * (cnt[i] + 1)) % MOD;
  }
  cout << ans - 1 << endl;
}
Problem p03095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define repi(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;

  vector<ll> l(26, 0);
  rep(i, n) l.at(s.at(i) - 'a')++;
  ll ans = 1;
  rep(i, n) {
    ans *= (l.at(i) + 1);
    ans %= 1000000007;
  }
  cout << ans - 1 << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define repi(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;

  vector<ll> l(26, 0);
  rep(i, n) l.at(s.at(i) - 'a')++;
  ll ans = 1;
  rep(i, 26) {
    ans *= (l.at(i) + 1);
    ans %= 1000000007;
  }
  cout << ans - 1 << endl;
}
Problem p03095 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

#define ll long long
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define LAST(x) (x)[(x).size() - 1]

using namespace std;

string to_hex(int x) {
  stringstream ss;
  ss << hex << x;
  return ss.str();
}

string to_string(string s) { return s; }

template <class T> string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(LAST(v));
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << " " << to_string(head);
  debug(tail...);
}

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int list[26] = {};
  FOR(i, S.size()) { list[S[i] - 'a']++; }
  int sm = 0;
  for (int i = 1; i < (1 << 26); ++i) {
    ll t = 1;
    int x;
    x = 32 - __builtin_clz(i);
    for (int j = 0; j < x; ++j) {
      // debug(i,j,t,i&(1<<j),list[j]);
      if ((i & (1 << j)) != 0) {
        t = (t * list[j]);
        if (t == 0)
          break;
      }
    }
    sm = (sm + t % 1000000007) % 1000000007;
  }
  cout << sm << endl;
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

#define ll long long
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define LAST(x) (x)[(x).size() - 1]

using namespace std;

string to_hex(int x) {
  stringstream ss;
  ss << hex << x;
  return ss.str();
}

string to_string(string s) { return s; }

template <class T> string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(LAST(v));
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << " " << to_string(head);
  debug(tail...);
}

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int list[26] = {};
  FOR(i, S.size()) { list[S[i] - 'a']++; }
  ll sm = 0;
  FOR(i, 26) {
    if (list[i] > 0)
      sm = (sm + list[i] * sm + list[i]) % 1000000007;
  }
  cout << sm << endl;
  return 0;
}