Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <map>
#include <string>
#define rep(i,a) for(i=0;i<a;i++)
using namespace std;

typedef pair<string,int> card;
 
int partition(vector<card> &qs, int p, int r) {
    int i,j,x;
    x = qs[r].second;
    i = p-1;
 
    for(j=p; j <= r-1; j++) {
        if(qs[j].second <= x){
            i = i+1;
            swap(qs[i],qs[j]);
        }
    }
    swap(qs[i+1],qs[r]);
    return i+1;
}

void quicksort(vector<card> &qs, int p, int r) {
    if(p < r) {
        int q = partition();
        quicksort(qs, p, q-1);
        quicksort(qs, q+1, r);
    }
}

void merge(vector<card> &ms, int l, int m, int r){
    int n1 = m-l;
    int n2 = r-m;
    int i,j;
    vector<card> L(n1+1);
    vector<card> R(n2+2);
    rep(i,n1){
        L[i] = ms[l+i];
    }
    rep(i,n2) {
        R[i] = ms[m+i];
    }
    L[n1].second = INT_MAX;
    R[n2].second = INT_MAX;
    i = 0;
    j = 0;
    for(int k = l; k < r; k++) {
        if(L[i].second <= R[j].second) {
            ms[k] = L[i];
            i++:
        } else if(ms[k].second = R[j].second) {
            j++;
        }
    }
}

void mergesort(vector<card> &ms, int l, int r) {
    if (l+1 < r) {
        int m = (l+r)/2;
        mergesort(ms,l,m);
        mergesort(ms,m,r);
        merge(ms,l,m,r);
    }
}

bool check(vector<card> &qs, vector<card> &ms)
{
    int i;
    rep(i,n){
        if(qs[i] != ms[i]){
            return false;
        }
    }
    return true;
}
 
int main(void) {
    int n,i;
    card c1;
    vector<card> qs;
     
    cin >> n;
    rep(i,n) {
        cin >> c1.first >> c1.second;
        qs.push_back(c1);
    }
    vector<card> ms(qs.begin(),qs.end());

    quicksort(qs,0,n-1);
    mergesort(ms,0,n);

    if(check(qs,ms)) {
        cout << "Stable" << endl;
    } else {
        cout << "Not Stable" << endl;
    }

    rep(i,n) {
        cout << qs[i] << endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'void quicksort(std::vector<std::pair<std::__cxx11::basic_string<char>, int> >&, int, int)':
a.cc:29:26: error: no matching function for call to 'partition()'
   29 |         int q = partition();
      |                 ~~~~~~~~~^~
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h:4573:5: note: candidate: 'template<class _BIter, class _Predicate> _BIter std::partition(_BIter, _BIter, _Predicate)'
 4573 |     partition(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4573:5: note:   candidate expects 3 arguments, 0 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:275:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::partition(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _UnaryPredicate)'
  275 | partition(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _UnaryPredicate __pred);
      | ^~~~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:275:1: note:   candidate expects 4 arguments, 0 provided
a.cc:12:5: note: candidate: 'int partition(std::vector<std::pair<std::__cxx11::basic_string<char>, int> >&, int, int)'
   12 | int partition(vector<card> &qs, int p, int r) {
      |     ^~~~~~~~~
a.cc:12:5: note:   candidate expects 3 arguments, 0 provided
a.cc: In function 'void merge(std::vector<std::pair<std::__cxx11::basic_string<char>, int> >&, int, int, int)':
a.cc:54:16: error: expected ';' before ':' token
   54 |             i++:
      |                ^
      |                ;
a.cc: In function 'bool check(std::vector<std::pair<std::__cxx11::basic_string<char>, int> >&, std::vector<std::pair<std::__cxx11::basic_string<char>, int> >&)':
a.cc:73:11: error: 'n' was not declared in this scope
   73 |     rep(i,n){
      |           ^
a.cc:7:28: note: in definition of macro 'rep'
    7 | #define rep(i,a) for(i=0;i<a;i++)
      |                            ^
a.cc: In function 'int main()':
a.cc:103:14: error: no match for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream<char>'} and '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::__cxx11::basic_string<char>, int> >, std::pair<std::__cxx11::basic_string<char>, int> >::value_type' {aka 'std::pair<std::__cxx11::basic_string<char>, int>'})
  103 |         cout << qs[i] << endl;
In file included from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/ostream:116:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ostream_type& (*)(__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  116 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |       ^~~~~~~~
/usr/include/c++/14/ostream:116:36: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::__cxx11::basic_string<char>, int> >, std::pair<std::__cxx11::basic_string<char>, int> >::value_type' {aka 'std::pair<std::__cxx11::basic_string<char>, int>'} to 'std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&)' {aka 'std::basic_ostream<char>& (*)(std::basic_ostream<char>&)'}
  116 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |                  ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:125:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>; __ios_type = std::basic_ios<char>]'
  125 |       operator<<(__ios_type& (*__pf)(__ios_type&))
      |       ^~~~~~~~
/usr/include/c++/14/ostream:125:32: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::__cxx11::basic_string<char>, int> >, std::pair<std::__cxx11::basic_string<char>, int> >::value_type' {aka 'std::pair<std::__cxx11::basic_string<char>, int>'} to 'std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&)' {aka 'std::basic_ios<char>& (*)(std::basic_ios<char>&)'}
  125 |       operator<<(__ios_type& (*__pf)(__ios_type&))
      |                  ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:135:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  135 |       operator<<(ios_base& (*__pf) (ios_base&))
      |       ^~~~~~~~
/usr/include/c++/14/ostream:135:30: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::__cxx11::basic_string<char>, int> >, std::pair<std::__cxx11::basic_string<char>, int> >::value_type' {aka 'std::pair<std::__cxx11::basic_string<char>, int>'} to 'std::ios_base& (*)(std::ios_base&)'
  135 |       operator<<(ios_base& (*__pf) (ios_base&))
      |                  ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:174:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  174 |       operator<<(long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:174:23: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::__cxx11::basic_string<char>, int> >, std::pair<std::__cxx11::basic_string<char>, int> >::value_type' {aka 'std::pair<std::__cxx11::basic_string<char>, int>'} to 'long int'
  174 |       operator<<(long __n)
      |                  ~~~~~^~~
/usr/include/c++/14/ostream:178:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  178 |       operator<<(unsigned long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:178:32: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::__cxx11::basic_string<char>, int> >, std::pair<std::__cxx11::basic_string<char>, int> >::value_type' {aka 'std::pair<std::__cxx11::basic_string<char>, int>'} to 'long unsigned int'
  178 |       operator<<(unsigned long __n)
      |                  ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:182:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  182 |       operator<<(bool __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:182:23: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::__cxx11::basic_string<char>, int> >, std::pair<std::__cxx11::basic_string<char>, int> >::value_type' {aka 'std::pair<std::__cxx11::basic_string<char>, int>'} to 'bool'
  182 |       operator<<(bool __n)
      |                  ~~~~~^~~
In file included from /usr/include/c++/14/ostream:1022:
/usr/include/c++/14/bits/ostream.tcc:96:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]'
   96 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:97:22: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::__cxx11::basic_string<char>, int> >, std::pair<std::__cxx11::basic_string<char>, int> >::value_type' {aka 'std::pair<std::__cxx11::basic_string<char>, int>'} to 'short int'
   97 |     operator<<(short __n)
      |                ~~~~~~^~~
/usr/include/c++/14/ostream:189:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  189 |       operator<<(unsigned short __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:189:33: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::__cxx11::basic_string<char>, int> >, std::pair<std::__cxx11::basic_string<char>, int> >::value_type' {aka 'std::pair<std::__cxx11::basic_string<char>, int>'} to 'short unsigned int'
  189 |       operator<<(unsigned short __n)
      |                  ~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/ostream.tcc:110:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]'
  110 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:111:20: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::__cxx11::basic_string<char>, int> >, std::pair<std::__cxx11::basic_string<char>, int> >::value_type' {aka 'std::pair<std::__cxx11::basic_string<char>, int>'} to 'int'
  111 |     operator<<(int __n)
      |                ~~~~^~~
/usr/include/c++/14/ostream:200:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  200 |       operator<<(unsigned int __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:200:31: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::__cxx11::basic_string<char>