Language: C++

#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));
      }
    }
    if (!out.size()) puts("NA");
    else {
      sort(out);
      if (out.size() > 5u) out.erase(begin(out) + 5, end(out));
      for (int i = 0; i < (int)out.size(); i++){
        printf("%s%c", get<1>(out).c_str(), " \n"[i == (int)out.size() - 1]);
      }
    }
  }
  return (0);
}
// priority_queue queue deque front stringstream max_element min_element insert count make_tuple

Compiler output:
a.cc: In function 'int main()':
a.cc:59:30: error: no matching function for call to 'get<1>(std::vector<std::tuple<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)'
   59 |         printf("%s%c", get<1>(out).c_str(), " \n"[i == (int)out.size() - 1]);
      |                        ~~~~~~^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_pair.h:1250:5: note: candidate: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(pair<_Tp1, _Tp2>&)'
 1250 |     get(pair<_Tp1, _Tp2>& __in) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1250:5: note:   template argument deduction/substitution failed:
a.cc:59:30: note:   'std::vector<std::tuple<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >' is not derived from 'std::pair<_Tp1, _Tp2>'
   59 |         printf("%s%c", get<1>(out).c_str(), " \n"[i == (int)out.size() - 1]);
      |                        ~~~~~~^~~~~
/usr/include/c++/14/bits/stl_pair.h:1255:5: note: candidate: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&& std::get(pair<_Tp1, _Tp2>&&)'
 1255 |     get(pair<_Tp1, _Tp2>&& __in) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1255:5: note:   template argument deduction/substitution failed:
a.cc:59:30: note:   'std::vector<std::tuple<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >' is not derived from 'std::pair<_Tp1, _Tp2>'
   59 |         printf("%s%c", get<1>(out).c_str(), " \n"[i == (int)out.size() - 1]);
      |                        ~~~~~~^~~~~
/usr/include/c++/14/bits/stl_pair.h:1260:5: note: candidate: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr const typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(const pair<_Tp1, _Tp2>&)'
 1260 |     get(const pair<_Tp1, _Tp2>& __in) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1260:5: note:   template argument deduction/substitution failed:
a.cc:59:30: note:   'std::vector<std::tuple<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >' is not derived from 'const std::pair<_Tp1, _Tp2>'
   59 |         printf("%s%c", get<1>(out).c_str(), " \n"[i == (int)out.size() - 1]);
      |                        ~~~~~~^~~~~
/usr/include/c++/14/bits/stl_pair.h:1265:5: note: candidate: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr const typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&& std::get(const pair<_Tp1, _Tp2>&&)'
 1265 |     get(const pair<_Tp1, _Tp2>&& __in) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1265:5: note:   template argument deduction/substitution failed:
a.cc:59:30: note:   'std::vector<std::tuple<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >' is not derived from 'const std::pair<_Tp1, _Tp2>'
   59 |         printf("%s%c", get<1>(out).c_str(), " \n"[i == (int)out.size() - 1]);
      |                        ~~~~~~^~~~~
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/tuple:2445:5: note: candidate: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >& std::get(tuple<_Elements ...>&)'
 2445 |     get(tuple<_Elements...>& __t) noexcept
      |     ^~~
/usr/include/c++/14/tuple:2445:5: note:   template argument deduction/substitution failed:
a.cc:59:30: note:   'std::vector<std::tuple<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >' is not derived from 'std::tuple<_Elements ...>'
   59 |         printf("%s%c", get<1>(out).c_str(), " \n"[i == (int)out.size() - 1]);
      |                        ~~~~~~^~~~~
/usr/include/c++/14/tuple:2451:5: note: candidate: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >& std::get(const tuple<_Elements ...>&)'
 2451 |     get(const tuple<_Elements...>& __t) noexcept
      |     ^~~
/usr/include/c++/14/tuple:2451:5: note:   template argument deduction/substitution failed:
a.cc:59:30: note:   'std::vector<std::tuple<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >' is not derived from 'const std::tuple<_Elements ...>'
   59 |         printf("%s%c", get<1>(out).c_str(), " \n"[i == (int)out.size() - 1]);
      |                        ~~~~~~^~~~~
/usr/include/c++/14/tuple:2457:5: note: candidate: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >&& std::get(tuple<_Elements ...>&&)'
 2457 |     get(tuple<_Elements...>&& __t) noexcept
      |     ^~~
/usr/include/c++/14/tuple:2457:5: note:   template argument deduction/substitution failed:
a.cc:59:30: note:   'std::vector<std::tuple<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >' is not derived from 'std::tuple<_Elements ...>'
   59 |         printf("%s%c", get<1>(out).c_str(), " \n"[i == (int)out.size() - 1]);
      |                        ~~~~~~^~~~~
/usr/include/c++/14/tuple:2466:5: note: candidate: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >&& std::get(const tuple<_Elements ...>&&)'
 2466 |     get(const tuple<_Elements...>&& __t) noexcept
      |     ^~~
/usr/include/c++/14/tuple:2466:5: note:   template argument deduction/substitution failed:
a.cc:59:30: note:   'std::vector<std::tuple<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >' is not derived from 'const std::tuple<_Elements ...>'
   59 |         printf("%s%c", get<1>(out).c_str(), " \n"[i == (int)out.size() - 1]);
      |                        ~~~~~~^~~~~
In file included from /usr/include/c++/14/functional:65,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/array:390:5: note: candidate: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp& std::get(array<_Tp, _Nm>&)'
  390 |     get(array<_Tp, _Nm>& __arr) noexcept
      |     ^~~
/usr/include/c++/14/array:390:5: note:   template argument deduction/substitution failed:
a.cc:59:30: note:   'std::vector<std::tuple<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >' is not derived from 'std::array<_Tp, _Nm>'
   59 |         printf("%s%c", get<1>(out).c_str(), " \n"[i == (int)out.size() - 1]);
      |                        ~~~~~~^~~~~
/usr/include/c++/14/array:399:5: note: candidate: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp&& std::get(array<_Tp, _Nm>&&)'
  399 |     get(array<_Tp, _Nm>&& __arr) noexcept
      |     ^~~
/usr/include/c++/14/array:399:5: note:   template argument deduction/substitution failed:
a.cc:59:30: note:   'std::vector<std::tuple<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >' is not derived from 'std::array<_Tp, _Nm>'
   59 |         printf("%s%c", get<1>(out).c_str(), " \n"[i == (int)out.size() - 1]);
      |                        ~~~~~~^~~~~
/usr/include/c++/14/array:408:5: note: candidate: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr const _Tp& std::get(const array<_Tp, _Nm>&)'
  408 |     get(const array<_Tp, _Nm>& __arr) noexcept
      |     ^~~
/usr/include/c++/14/array:408:5: note:   template argument deduction/substitution failed:
a.cc:59:30: note:   'std::vector<std::tuple<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >' is not derived from 'const std::array<_Tp, _Nm>'
   59 |         printf("%s%c", get<1>(out).c_str(), " \n"[i == (int)out.size() - 1]);
      |                        ~~~~~~^~~~~
/usr/include/c++/14/array:417:5: note: candidate: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr const _Tp&& std::get(const array<_Tp, _Nm>&&)'
  417 |     get(const array<_Tp, _Nm>&& __arr) noexcept
      |     ^~~
/usr/include/c++/14/array:417:5: note:   template argument deduction/substitution failed:
a.cc:59:30: note:   'std::vector<std::tuple<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >' is not derived from 'const std::array<_Tp, _Nm>'
   59 |         printf("%s%c", get<1>(out).c_str(), " \n"[i == (int)out.size() - 1]);
      |                        ~~~~~~^~~~~
/usr/include/c++/14/bits/stl_pair.h:1272:5: note: candidate: 'template<class _Tp, class _Up> constexpr _Tp& std::get(pair<_T1, _T2>&)'
 1272 |     get(pair<_Tp, _Up>& __p) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1272:5: note:   template argument deduction/substitution failed:
a.cc:59:30: error: type/value mismatch at argument 1 in template parameter list for 'template<class _Tp, class _Up> constexpr _Tp& std::get(pair<_T1, _T2>&)'
   59 |         printf("%s%c", get<1>(out).c_str(), " \n"[i == (int)out.size() - 1]);
      |                        ~~~~~~^~~~~
a.cc:59:30: note:   expected a type, got '1'
/usr/include/c++/14/bits/stl_pair.h:1277:5: note: candidate: 'template<class _Tp, class _Up> constexpr const _Tp& std::get(const pair<_T1, _T2>&)'
 1277 |     get(const pair<_Tp, _Up>& __p) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1277:5: note:   template argument deduction/substitution failed:
a.cc:59:30: error: type/value mismatch at argument 1 in template parameter list for 'template<class _Tp, class _Up> constexpr const _Tp& std::get(const pair<_T1, _T2>&)'
   59 |         printf("%s%c", get<1>(out).c_str(), " \n