Language: C++

#include <algorithm>//min/max/sort(rand-access it)/merge
#include <array>
#include <bitset>
#include <climits>//INT_MAX/INT_MIN/ULLONG_MAX
#include <cmath>//fmin/fmax/fabs/sin(h)/cos(h)/tan(h)/exp/log/pow/sqrt/cbrt/ceil/floor/round/trunc
#include <cstdlib>//abs/atof/atoi/atol/atoll/strtod/strtof/..., srand/rand, calloc/malloc, exit, qsort
#include <iomanip>//setfill/setw
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific
#include <iterator>
#include <list>
#include <queue>
#include <string>//stoi/stol/stoul/stoll/stoull/stof/stod/stold/to_string/getline
#include <tuple>
#include <utility>//pair
#include <valarray>
#include <vector>

#define PRIME_SHORT 10007
#define PRIME 1000000007

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<ull, int> puli;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pllll;
typedef pair<ull, ull> pulul;
typedef pair<double, double> pdd;
typedef tuple<int, int, int> ti3;
typedef tuple<int, int, int, int> ti4;

const bool debug = false;

void rar(int n, string* a);
void rar2(int n, int m, int** a);

int ipow(int base, int exp);
int left(int current, bool swap);
int right(int current, bool swap);
int griddist(int x, int y, int s, int t);
int griddist(pii one, pii two);
double sqeucldist(double x, double y, double s, double t);
double sqeucldist(pii one, pii two);
ull modadd(ull a, ull b, int mod);
ull modmult(ull a, ull b, int mod);

int main(void) {
    ui n;
    cin >> n;
    size_t k;
    cin >> k;

    ui header_count[26];
    for (size_t i = 0; i < 26; ++i)
        header_count[i] = 0U;

    string p;
    for (size_t i = 0; i < n; ++i)
    {
        cin >> p;
        int index = p[0] - 'A';
        if (debug)
            cout << p << " " << index << endl;
        ++(header_count[index]);
    }

    list<ui> remaining;

    for (size_t i = 0; i < 26; ++i)
    {
        if (header_count[i] > 0)
            remaining.push_back(header_count[i]);
    }
    
    if (debug){
        cout << "remaining" << endl;
        for (list<int>::iterator it = remaining.begin(); it != remaining.end(); ++it)
            cout << *it << "\t";
        cout << endl;
    }

    remaining.sort(greater<ui>());
    
    if (debug) {
        cout << "remaining" << endl;
        for (list<int>::iterator it = remaining.begin(); it != remaining.end(); ++it)
            cout << *it << "\t";
        cout << endl;
    }

    ull count = 0UL;

    size_t s = remaining.size();
    while(s >= k) {
        if (debug) {
            for (list<int>::iterator it = remaining.begin(); it != remaining.end(); ++it)
                cout << *it << " ";
            cout << endl;
        }

        int i = 0;
        for (list<int>::iterator it = remaining.begin(); i < k; ++i)
        {
            --(*it);
            if (*it == 0) {
                it = remaining.erase(it);
                continue;
            }
            ++it;
        }
        ++count;
        s = remaining.size();
    }

    cout << count << endl;
    return 0;
}

void rar(int n, string* a)
{
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    return;
}

void rar2(int n, int m, int** a)
{
    for (int i = 0; i < n; ++i)
    {
        a[i] = new int[m];
        for (int j = 0; j < m; ++j)
        {
            cin >> a[i][j];
        }
    }
    return;
}



















int ipow(int base, int exp) {
    int result = 1;
    while (exp)
    {
        if (exp & 1)
            result *= base;
        exp >>= 1;
        base *= base;
    }

    return result;
}
int left(int current, bool swap = false) {
    if(swap){
        return right(current, false);
    } else {
        return 2*current + 1;
    }
}
int right(int current, bool swap = false) {
    if(swap){
        return left(current, false);
    } else {
        return 2*(current+1);
    }
}
int griddist(int x, int y, int s, int t) {
    return abs(x-s) + abs(y-t);
}
int griddist(pii one, pii two) {
    return abs(one.first - two.first) + abs(one.second - two.second);
}
double sqeucldist(double x, double y, double s, double t) {
    double a = x-s;
    double b = y-t;
    return a*a+b*b;
}
double sqeucldist(pii one, pii two) {
    double a = one.first - two.first;
    double b = one.second - two.second;
    return a*a+b*b;
}

ull modadd(ull a, ull b, int mod) {
    return (a%mod + b%mod)%mod;
}
ull modmult(ull a, ull b, int mod) {
    return ((a%mod)*(b%mod))%mod;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:81:54: error: conversion from '_List_iterator<unsigned int>' to non-scalar type '_List_iterator<int>' requested
   81 |         for (list<int>::iterator it = remaining.begin(); it != remaining.end(); ++it)
      |                                       ~~~~~~~~~~~~~~~^~
a.cc:81:61: error: no match for 'operator!=' (operand types are 'std::__cxx11::list<int>::iterator' and 'std::__cxx11::list<unsigned int>::iterator')
   81 |         for (list<int>::iterator it = remaining.begin(); it != remaining.end(); ++it)
      |                                                          ~~ ^~ ~~~~~~~~~~~~~~~
      |                                                          |                  |
      |                                                          |                  _List_iterator<unsigned int>
      |                                                          _List_iterator<int>
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_pair.h:1052:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator!=(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1052 |     operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1052:5: note:   template argument deduction/substitution failed:
a.cc:81:78: note:   'std::__cxx11::list<int>::iterator' is not derived from 'const std::pair<_T1, _T2>'
   81 |         for (list<int>::iterator it = remaining.begin(); it != remaining.end(); ++it)
      |                                                                              ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:67:
/usr/include/c++/14/bits/stl_iterator.h:455:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator!=(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  455 |     operator!=(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:455:5: note:   template argument deduction/substitution failed:
a.cc:81:78: note:   'std::__cxx11::list<int>::iterator' is not derived from 'const std::reverse_iterator<_Iterator>'
   81 |         for (list<int>::iterator it = remaining.begin(); it != remaining.end(); ++it)
      |                                                                              ^
/usr/include/c++/14/bits/stl_iterator.h:500:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator!=(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  500 |     operator!=(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:500:5: note:   template argument deduction/substitution failed:
a.cc:81:78: note:   'std::__cxx11::list<int>::iterator' is not derived from 'const std::reverse_iterator<_Iterator>'
   81 |         for (list<int>::iterator it = remaining.begin(); it != remaining.end(); ++it)
      |                                                                              ^
/usr/include/c++/14/bits/stl_iterator.h:1686:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator!=(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1686 |     operator!=(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1686:5: note:   template argument deduction/substitution failed:
a.cc:81:78: note:   'std::__cxx11::list<int>::iterator' is not derived from 'const std::move_iterator<_IteratorL>'
   81 |         for (list<int>::iterator it = remaining.begin(); it != remaining.end(); ++it)
      |                                                                              ^
/usr/include/c++/14/bits/stl_iterator.h:1753:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator!=(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1753 |     operator!=(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1753:5: note:   template argument deduction/substitution failed:
a.cc:81:78: note:   'std::__cxx11::list<int>::iterator' is not derived from 'const std::move_iterator<_IteratorL>'
   81 |         for (list<int>::iterator it = remaining.begin(); it != remaining.end(); ++it)
      |                                                                              ^
In file included from a.cc:2:
/usr/include/c++/14/array:332:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> bool std::operator!=(const array<_Tp, _Nm>&, const array<_Tp, _Nm>&)'
  332 |     operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
      |     ^~~~~~~~
/usr/include/c++/14/array:332:5: note:   template argument deduction/substitution failed:
a.cc:81:78: note:   'std::__cxx11::list<int>::iterator' is not derived from 'const std::array<_Tp, _Nm>'
   81 |         for (list<int>::iterator it = remaining.begin(); it != remaining.end(); ++it)
      |                                                                              ^
In file included from /usr/include/c++/14/bits/char_traits.h:42,
                 from /usr/include/c++/14/string:42,
                 from /usr/include/c++/14/bitset:52,
                 from a.cc:3:
/usr/include/c++/14/bits/postypes.h:197:5: note: candidate: 'template<class _StateT> bool std::operator!=(const fpos<_StateT>&, const fpos<_StateT>&)'
  197 |     operator!=(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/postypes.h:197:5: note:   template argument deduction/substitution failed:
a.cc:81:78: note:   'std::__cxx11::list<int>::iterator' is not derived from 'const std::fpos<_StateT>'
   81 |         for (list<int>::iterator it = remaining.begin(); it != remaining.end(); ++it)
      |                                                                              ^
In file included from /usr/include/c++/14/string:43:
/usr/include/c++/14/bits/allocator.h:243:5: note: candidate: 'template<class _T1, class _T2> bool std::operator!=(const allocator<_CharT>&, const allocator<_T2>&)'
  243 |     operator!=(const allocator<_T1>&, const allocator<_T2>&)
      |     ^~~~~~~~
/usr/include/c++/14/bits/allocator.h:243:5: note:   template argument deduction/substitution failed:
a.cc:81:78: note:   'std::__cxx11::list<int>::iterator' is not derived from 'const std::allocator<_CharT>'
   81 |         for (list<int>::iterator it = remaining.begin(); it != remaining.end(); ++it)
      |                                                                              ^
In file included from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54:
/usr/include/c++/14/string_view:651:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator!=(basic_string_view<_CharT, _Traits>, basic_string_view<_CharT, _Traits>)'
  651 |     operator!=(basic_string_view<_CharT, _Traits> __x,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:651:5: note:   template argument deduction/substitution failed:
a.cc:81:78: note:   'std::_List_iterator<int>' is not derived from 'std::basic_string_view<_CharT, _Traits>'
   81 |         for (list<int>::iterator it = remaining.begin(); it != remaining.end(); ++it)
      |                                                                              ^
/usr/include/c++/14/string_view:658:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator!=(basic_string_view<_CharT, _Traits>, __type_identity_t<basic_string_view<_CharT, _Traits> >)'
  658 |     operator!=(basic_string_view<_CharT, _Traits> __x,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:658:5: note:   template argument deduction/substitution failed:
a.cc:81:78: note:   'std::_List_iterator<int>' is not derived from 'std::basic_string_view<_CharT, _Traits>'
   81 |         for (list<int>::iterator it = remaining.begin(); it != remaining.end(); ++it)
      |                                                                              ^
/usr/include/c++/14/string_view:666:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator!=(__type_identity_t<basic_string_view<_CharT, _Traits> >, basic_string_view<_CharT, _Traits>)'
  666 |     operator!=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:666:5: note:   template argument deduction/substitution failed:
a.cc:81:78: note:   'std::_List_iterator<unsigned int>' is not derived from 'std::basic_string_view<_CharT, _Traits>'
   81 |         for (list<int>::iterator it = remaining.begin(); it != remaining.end(); ++it)
      |                                                                              ^
/usr/include/c++/14/bits/basic_string.h:3833:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3833 |     operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3833:5: note:   template argument deduction/substitution failed:
a.cc:81:78: note:   'std::__cxx11::list<int>::iterator' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   81 |         for (list<int>::iterator it = remaining.begin(); it != remaining.end(); ++it)
      |                                                                              ^
/usr/include/c++/14/bits/basic_string.h:3847:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3847 |     operator!=(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3847:5: note:   template argument deduction/substitution failed:
a.cc:81:78: note:   mismatched types 'const _CharT*' and 'std::_List_iterator<int>'
   81 |         for (list<int>::iterator it = r