Problem p02732 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("O3")
#pragma GCC target("avx")
// #include<bits/stdc++.h>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
  if (ci - cn == cm) {
    fread_unlocked(cn, 1, cm, stdin);
    ci = cn;
  }
  return *ci++;
}
inline int getint() {
  int A = 0;
  if (ci - cn + 16 > cm)
    while ((ct = getcha()) >= '0')
      A = A * 10 + ct - '0';
  else
    while ((ct = *ci++) >= '0')
      A = A * 10 + ct - '0';
  return A;
}

char dn[2400000], *di = dn;
const int MAX = 200000;
class shuturyoku_unko {
public:
  char C[MAX * 6 + 10];
  char *K[MAX + 10];
  constexpr shuturyoku_unko() : C(), K() {
    auto di = C + 1;
    C[0] = '0';
    K[1] = di;
    rep1(i, MAX) {
      int X = i;
      int keta = 0;
      char c[10] = {};
      while (X) {
        *(c + keta) = '0' + X % 10;
        X /= 10;
        keta++;
      }
      for (int j = keta - 1; j >= 0; j--)
        *di++ = (*(c + j));
      K[i + 1] = di;
    }
  }
} f;
inline void putint(ll X) {
  int ue = X / 100000;
  if (ue) {
    for (auto i = f.K[ue]; i < f.K[ue + 1]; i++)
      *di++ = *i;
    int sita = X - ue * 100000ll;
    rep(i, 5 - (f.K[sita + 1] - f.K[sita])) *di++ = '0';
    for (auto i = f.K[sita]; i < f.K[sita + 1]; i++)
      *di++ = *i;
  } else
    for (auto i = f.K[X]; i < f.K[X + 1]; i++)
      *di++ = *i;
  *di++ = '\n';
}

int A[200000];
int B[200010];

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

  int N = getint();
  ll kotae = 0;
  rep(i, N) kotae += B[(A[i] = getint())]++;
  rep(i, N) putint(kotae - B[A[i]] + 1);
  fwrite(dn, 1, di - dn, stdout);

  Would you please return 0;
}

Fixed submission:
#pragma GCC optimize("O3")
#pragma GCC target("avx")
// #include<bits/stdc++.h>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
  if (ci - cn == cm) {
    fread_unlocked(cn, 1, cm, stdin);
    ci = cn;
  }
  return *ci++;
}
inline int getint() {
  int A = 0;
  if (ci - cn + 16 > cm)
    while ((ct = getcha()) >= '0')
      A = A * 10 + ct - '0';
  else
    while ((ct = *ci++) >= '0')
      A = A * 10 + ct - '0';
  return A;
}

char dn[2400000], *di = dn;
const int MAX = 200000;
class shuturyoku_unko {
public:
  char C[MAX * 6 + 10];
  char *K[MAX + 10];
  constexpr shuturyoku_unko() : C(), K() {
    auto di = C + 1;
    C[0] = '0';
    K[0] = C;
    K[1] = di;
    rep1(i, MAX) {
      int X = i;
      int keta = 0;
      char c[10] = {};
      while (X) {
        *(c + keta) = '0' + X % 10;
        X /= 10;
        keta++;
      }
      for (int j = keta - 1; j >= 0; j--)
        *di++ = (*(c + j));
      K[i + 1] = di;
    }
  }
} f;
inline void putint(ll X) {
  int ue = X / 100000;
  if (ue) {
    for (auto i = f.K[ue]; i < f.K[ue + 1]; i++)
      *di++ = *i;
    int sita = X - ue * 100000ll;
    rep(i, 5 - (f.K[sita + 1] - f.K[sita])) *di++ = '0';
    for (auto i = f.K[sita]; i < f.K[sita + 1]; i++)
      *di++ = *i;
  } else
    for (auto i = f.K[X]; i < f.K[X + 1]; i++)
      *di++ = *i;
  *di++ = '\n';
}

int A[200000];
int B[200010];

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

  int N = getint();
  ll kotae = 0;
  rep(i, N) kotae += B[(A[i] = getint())]++;
  rep(i, N) putint(kotae - B[A[i]] + 1);
  fwrite(dn, 1, di - dn, stdout);

  Would you please return 0;
}