Problem p00242 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, string> duo;

#define TT template <typename T>
#define TTF template <typename T, typename F>
#define ET(T) typename T::value_type
TT inline T sq(T x) { return x * x; }
TT inline T In() {
  T x;
  cin >> x;
  return x;
}
TT inline void Out(T &x) { cout << x; }
TT inline void sort(T &v) { sort(begin(v), end(v)); }
TT inline void revs(T &v) { reverse(begin(v), end(v)); }
TT inline void uniq(T &v) {
  sort(v);
  v.erase(unique(begin(v), end(v)), end(v));
}
TT inline int ubnd(T &v, ET(T) & x) {
  return upper_bound(begin(v), end(v), x) - begin(v);
}
TT inline int lbnd(T &v, ET(T) & x) {
  return lower_bound(begin(v), end(v), x) - begin(v);
}
TTF inline void inpt(T &v, int n, F f) {
  for (v.reserve(n); n--; v.emplace_back(f()))
    ;
}
TTF inline void show(T &v, F f, string d = " ", string e = "\\n") {
  int i = 0;
  for (auto &x : v)
    i++ && (cout << d), f(x);
  cout << e;
}
#undef TT
#undef TTF
#undef ET

inline void fast_io() {
  ios::sync_with_stdio(0);
  cin.tie(0);
}
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
inline ll pow_mod(ll a, ll k, ll m) {
  ll r = 1;
  for (; k > 0; a = a * a % m, k >>= 1)
    if (k & 1)
      r = r * a % m;
  return r;
}
inline ll mod_inv(ll a, ll p) { return pow_mod(a, p - 2, p); }

const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000;

int main() {
  int n;
  while (cin >> n, n) {
    map<string, int> cnt;
    cin.ignore();
    for (int i = 0; i < n; i++) {
      string line;
      getline(cin, line);
      stringstream ss(line);
      for (string tkn; getline(ss, tkn, ' '); cnt[tkn]++)
        ;
    }
    string c = In<string>();
    vector<duo> out;
    for (const auto &si : cnt) {
      if (si.first[0] == c[0]) {
        out.push_back(duo(-si.second, si.first));
      }
    }
    if (!out.size())
      puts("NA");
    else {
      sort(out);
      for (int i = 0; i < (int)out.size() && i < 5; i++) {
        if (i)
          cout << " ";
        cout << get<1>(out[i]);
      }
      cout << "\\n";
    }
  }
  return (0);
}
// priority_queue queue deque front stringstream max_element min_element insert
// count make_tuple

Error: 0
among:1
and:1
are:1
bananas:2
because:1
ben:1
best:1
cheap:1
fruits:1
likes:1
many:1
sweet:1
the:1
aizu:2
and:2
as:1
friends:1
get:1
make:1
many:1
of:1
the:1
to:1
university:1
visit:1
well:1
winners:1
about:1
alex:1
android:1
answer:1
apps:1
ask:1
for:1
he:1
on:1
ssignment:1
the:1
:1
an:1
and:1
both:1
intellectual:1
is:1
programming:1
puzzle:1
sport:1


Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, string> duo;

#define TT template <typename T>
#define TTF template <typename T, typename F>
#define ET(T) typename T::value_type
TT inline T sq(T x) { return x * x; }
TT inline T In() {
  T x;
  cin >> x;
  return x;
}
TT inline void Out(T &x) { cout << x; }
TT inline void sort(T &v) { sort(begin(v), end(v)); }
TT inline void revs(T &v) { reverse(begin(v), end(v)); }
TT inline void uniq(T &v) {
  sort(v);
  v.erase(unique(begin(v), end(v)), end(v));
}
TT inline int ubnd(T &v, ET(T) & x) {
  return upper_bound(begin(v), end(v), x) - begin(v);
}
TT inline int lbnd(T &v, ET(T) & x) {
  return lower_bound(begin(v), end(v), x) - begin(v);
}
TTF inline void inpt(T &v, int n, F f) {
  for (v.reserve(n); n--; v.emplace_back(f()))
    ;
}
TTF inline void show(T &v, F f, string d = " ", string e = "\\n") {
  int i = 0;
  for (auto &x : v)
    i++ && (cout << d), f(x);
  cout << e;
}
#undef TT
#undef TTF
#undef ET

inline void fast_io() {
  ios::sync_with_stdio(0);
  cin.tie(0);
}
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
inline ll pow_mod(ll a, ll k, ll m) {
  ll r = 1;
  for (; k > 0; a = a * a % m, k >>= 1)
    if (k & 1)
      r = r * a % m;
  return r;
}
inline ll mod_inv(ll a, ll p) { return pow_mod(a, p - 2, p); }

const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000;

int main() {
  int n;
  while (cin >> n, n) {
    map<string, int> cnt;
    for (int i = 0; i < n; i++) {
      string line;
      cin.ignore();
      getline(cin, line);
      stringstream ss(line);
      for (string tkn; getline(ss, tkn, ' '); cnt[tkn]++)
        ;
    }
    string c = In<string>();
    vector<duo> out;
    for (const auto &si : cnt) {
      if (si.first[0] == c[0]) {
        out.push_back(duo(-si.second, si.first));
      }
      cerr << si.first << ":" << si.second << endl;
    }
    if (!out.size())
      puts("NA");
    else {
      sort(out);
      for (int i = 0; i < (int)out.size() && i < 5; i++) {
        if (i)
          cout << " ";
        cout << get<1>(out[i]);
      }
      cout << "\\n";
    }
  }
  return (0);
}
// priority_queue queue deque front stringstream max_element min_element insert
// count make_tuple