Language: C++

#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    list<pair<pair<long, long>, double> > lzSortedPnt;
    {
        long n = 0;
        vector<pair<long, long> > vzPnt;
        {
            cin >> n;
            vzPnt.resize(n);
            long i = 0;
            for (i = 0; i < n; ++i) {
                cin >> vzPnt[i].second;
                cin >> vzPnt[i].first;
            }
            sort(vzPnt.begin(), vzPnt.end()); // ?????????????????§????§????????±??????? 
            if (n == 0) {
                cout << n << "\n";
                return 0;
            }
            if (n == 1) {
                cout << n << "\n";
                cout << vzPnt[0].second << " " << vzPnt[0].first << "\n";
                return 0;
            }
            for (i = 0; i < n; ++i) {
                long j = vzPnt[i].first;
                vzPnt[i].first = vzPnt[i].second;
                vzPnt[i].second = j;
            }
        }

        vector<pair<pair<double, double>, size_t> > vzValuePnt(n);
        {
            vzValuePnt[0] = pair<pair<double, double>, size_t>(pair<double, double>(0.0, 0.0), 0); // dummy 
            long i = 1;
            for (i = 1; i < n; ++i) {
                double iX = vzPnt[i].first - vzPnt[0].first;
                double iY = vzPnt[i].second - vzPnt[0].second;
                double dLenSq = (iX * iX) + (iY + iY); // ?????????????????????sqrt????????? 
                double dAngle = 0;
                if (iX > 0) {
                    dAngle = iY / iX; // 0???20000 
                } else if (iX == 0) {
                    // iY????????§??§???20000????????§????????????25000??????iX==0?????±????????¨???????????¨??????????????? 
                    dAngle = 25000;
                } else {
                    dAngle = 50000 + iY / iX; // 30000???50000
                }
                vzValuePnt[i] = pair<pair<double, double>, size_t>(pair<double, double>(dAngle, dLenSq), i);
            }
            sort(vzValuePnt.begin(), vzValuePnt.end());
        }

        long i = 0;
        for (i = 0; i < n; ++i) {
            lzSortedPnt.push_back(pair<pair<long, long>, double>(vzPnt[vzValuePnt[i].second], vzValuePnt[i].first.first));
        }

        if (false) { // test?????? 
            list<pair<pair<long, long>, double> >::iterator it = lzSortedPnt.begin();
            for ( ; it != lzSortedPnt.end(); ++it) {
                cout << it->first.first << " " << it->first.second << "\n";
            }
            return 1;
        }
    }

    list<pair<long, long> > lzResultPnt;
    {
        // ?????????2??????????????¶????§£(??\??????1?????\????????´???????????????????????±????????¨????????±??£??????????????§??????2?????\????????????) 
        lzSortedPnt.push_back(lzSortedPnt.front()); // ?????????????????????????????¨???????????¨????????? 
        lzResultPnt.push_back(lzSortedPnt.front().first);
        lzSortedPnt.pop_front();
        lzResultPnt.push_back(lzSortedPnt.front().first);
        lzSortedPnt.pop_front();
    }

    while (!lzSortedPnt.empty()) {
        list<pair<pair<long, long>, double> >::iterator it = lzSortedPnt.begin();
        vector<list<pair<pair<long, long>, double> >::iterator> vzIt;
        vzIt.push_back(it);
        ++it;
        while (it != lzSortedPnt.end()) {
            if (vzIt[0]->second != it->second) {
                break;
            }
            vzIt.push_back(it);
            ++it;
        }
        if (vzIt.size() > 1) {
            // ?????£?????????????????????????±???????????????????????????????????????????vzIt????????¢????????????????????? 
            pair<long, long> azResultLast[2] = { *(--(--(lzResultPnt.end()))), *(--(lzResultPnt.end())) };
            double aiLastResultDirRev[2] = { azResultLast[0].first - azResultLast[1].first, azResultLast[0].second - azResultLast[1].second };
            double aiNextPntDir0[2] = { vzIt[0]->first.first - azResultLast[1].first, vzIt[0]->first.second - azResultLast[1].second };
            double aiNextPntDir1[2] = { vzIt[vzIt.size() -1]->first.first - azResultLast[1].first, vzIt[vzIt.size() -1]->first.second - azResultLast[1].second };
            double dAngle0 = atan2(aiLastResultDirRev[0] * aiNextPntDir0[1] - aiLastResultDirRev[1] * aiNextPntDir0[0], aiLastResultDirRev[0] * aiNextPntDir0[0] + aiLastResultDirRev[1] * aiNextPntDir0[1]);
            double dAngle1 = atan2(aiLastResultDirRev[0] * aiNextPntDir1[1] - aiLastResultDirRev[1] * aiNextPntDir1[0], aiLastResultDirRev[0] * aiNextPntDir1[0] + aiLastResultDirRev[1] * aiNextPntDir1[1]);
            if (dAngle0 < 0.0) {
                dAngle0 += 2.0 * 3.14159265358979;
            }
            if (dAngle1 < 0.0) {
                dAngle1 += 2.0 * 3.14159265358979;
            }
            if (dAngle0 > dAngle1) {
                reverse(vzIt.begin(), vzIt.end());
            }
        }
        size_t i = 0;
        for (i = 0; i < vzIt.size(); ++i) {
            while (true) {
                pair<long, long> azResultLast[2] = { *(--(--(lzResultPnt.end()))), *(--(lzResultPnt.end())) };
                long aiLastResultDir[2] = { azResultLast[1].first - azResultLast[0].first, azResultLast[1].second - azResultLast[0].second };
                long aiNextPntDir[2] = { vzIt[i]->first.first - azResultLast[1].first, vzIt[i]->first.second - azResultLast[1].second };
                {
                    // ?§?????????¶????????????????????£???????????????????????? 
                    long iSign = aiLastResultDir[0] * aiNextPntDir[1] - aiLastResultDir[1] * aiNextPntDir[0];
                    if (iSign < 0) {
                        lzResultPnt.pop_back();
                    } else {
                        break;
                    }
                }
            }
            lzResultPnt.push_back(vzIt[i]->first);
            lzSortedPnt.erase(vzIt[i]);
        }
    }

    lzResultPnt.pop_back(); // ?????????????????????????????????????????§?????? 
    long i = 0;
    size_t n = lzResultPnt.size();
    cout << n << "\n";
    list<pair<long, long> >::iterator it = lzResultPnt.begin();
    for ( ; it != lzResultPnt.end(); ++it) {
        cout << it->first << " " << it->second << "\n";
    }

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:101:68: warning: narrowing conversion of '(azResultLast[0].std::pair<long int, long int>::first - azResultLast[1].std::pair<long int, long int>::first)' from 'long int' to 'double' [-Wnarrowing]
  101 |             double aiLastResultDirRev[2] = { azResultLast[0].first - azResultLast[1].first, azResultLast[0].second - azResultLast[1].second };
      |                                              ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
a.cc:101:116: warning: narrowing conversion of '(azResultLast[0].std::pair<long int, long int>::second - azResultLast[1].std::pair<long int, long int>::second)' from 'long int' to 'double' [-Wnarrowing]
  101 |             double aiLastResultDirRev[2] = { azResultLast[0].first - azResultLast[1].first, azResultLast[0].second - azResultLast[1].second };
      |                                                                                             ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
a.cc:102:62: warning: narrowing conversion of '((& vzIt.std::vector<std::_List_iterator<std::pair<std::pair<long int, long int>, double> > >::operator[](0))->std::_List_iterator<std::pair<std::pair<long int, long int>, double> >::operator->()->std::pair<std::pair<long int, long int>, double>::first.std::pair<long int, long int>::first - azResultLast[1].std::pair<long int, long int>::first)' from 'long int' to 'double' [-Wnarrowing]
  102 |             double aiNextPntDir0[2] = { vzIt[0]->first.first - azResultLast[1].first, vzIt[0]->first.second - azResultLast[1].second };
a.cc:102:109: warning: narrowing conversion of '((& vzIt.std::vector<std::_List_iterator<std::pair<std::pair<long int, long int>, double> > >::operator[](0))->std::_List_iterator<std::pair<std::pair<long int, long int>, double> >::operator->()->std::pair<std::pair<long int, long int>, double>::first.std::pair<long int, long int>::second - azResultLast[1].std::pair<long int, long int>::second)' from 'long int' to 'double' [-Wnarrowing]
  102 |             double aiNextPntDir0[2] = { vzIt[0]->first.first - azResultLast[1].first, vzIt[0]->first.second - azResultLast[1].second };
a.cc:103:75: warning: narrowing conversion of '((& vzIt.std::vector<std::_List_iterator<std::pair<std::pair<long int, long int>, double> > >::operator[]((vzIt.std::vector<std::_List_iterator<std::pair<std::pair<long int, long int>, double> > >::size() - 1)))->std::_List_iterator<std::pair<std::pair<long int, long int>, double> >::operator->()->std::pair<std::pair<long int, long int>, double>::first.std::pair<long int, long int>::first - azResultLast[1].std::pair<long int, long int>::first)' from 'long int' to 'double' [-Wnarrowing]
  103 |             double aiNextPntDir1[2] = { vzIt[vzIt.size() -1]->first.first - azResultLast[1].first, vzIt[vzIt.size() -1]->first.second - azResultLast[1].second };
a.cc:103:135: warning: narrowing conversion of '((& vzIt.std::vector<std::_List_iterator<std::pair<std::pair<long int, long int>, double> > >::operator[]((vzIt.std::vector<std::_List_iterator<std::pair<std::pair<long int, long int>, double> > >::size() - 1)))->std::_List_iterator<std::pair<std::pair<long int, long int>, double> >::operator->()->std::pair<std::pair<long int, long int>, double>::first.std::pair<long int, long int>::second - azResultLast[1].std::pair<long int, long int>::second)' from 'long int' to 'double' [-Wnarrowing]
  103 |             double aiNextPntDir1[2] = { vzIt[vzIt.size() -1]->first.first - azResultLast[1].first, vzIt[vzIt.size() -1]->first.second - azResultLast[1].second };
a.cc:104:30: error: 'atan2' was not declared in this scope
  104 |             double dAngle0 = atan2(aiLastResultDirRev[0] * aiNextPntDir0[1] - aiLastResultDirRev[1] * aiNextPntDir0[0], aiLastResultDirRev[0] * aiNextPntDir0[0] + aiLastResultDirRev[1] * aiNextPntDir0[1]);
      |                              ^~~~~