Language: C++

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
const double pi = acos(-1);
const double EPS = 1e-8;

int cross(pii c,pii d){
  return c.first * d.second - d.first * c.second;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pii> a(n);
  REP(i,n) {
    cin >> a[i].first >> a[i].second;
  }
  sort(ALL(a));
  vi low;
  pii lineab, lineac;
  REP(i,n){
    if (i>1) {
      lineab.first = a[i-1].first - a[i-2].first;
      lineac.first = a[i].first - a[i-2].first;
      lineab.second = a[i-1].second - a[i-2].second;
      lineac.second = a[i].second - a[i-2].second;
      if (cross(lineab,lineac) < 0) {
        low.pop_back();
        low.pb(i);
      }
    }else{
      low.pb(i);
    }
  }
  vi high;
  REP(i,n){
    if (i>1) {
      lineab.first = a[i-1].first - a[i-2].first;
      lineac.first = a[i].first - a[i-2].first;
      lineab.second = a[i-1].second - a[i-2].second;
      lineac.second = a[i].second - a[i-2].second;
      if (cross(lineab,lineac) < 0) {
        high.pop_back();
        high.pb(i);
      }
    }else{
      high.pb(i);
    }
  }
  high.pop_back();
  reverse(ALL(high));
  high.pop_back();
  vi ans;
  ans = low;
  FOR(i,0,(int)high.size()-1) ans.pb(high[i]);
  int sz = (int)ans.size();
  REP(i,sz) ans.pb(ans[i]);
  vector<pair<pii,int>> b(n);
  REP(i,n){
    b[i] = make_pair(make_pair(a[i].second,a[i].first),i);
  }
  sort(ALL(b));
  auto itr = find(ALL(ans),b[0]);
  itr -= ans.begin();
  int itri = (int)itr;
  cout << ans.size() << endl;
  FOR(i,itri,(int)ans.size() + itri) cout << a[ans[i]].first << " " << a[ans[i]].second << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:75:7: error: no match for 'operator-=' (operand types are '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' and 'std::vector<int>::iterator')
   75 |   itr -= ans.begin();
      |   ~~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:67,
                 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_iterator.h:1143:7: note: candidate: '__gnu_cxx::__normal_iterator<_Iterator, _Container>& __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator-=(difference_type) [with _Iterator = int*; _Container = std::vector<int>; difference_type = long int]'
 1143 |       operator-=(difference_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1143:34: note:   no known conversion for argument 1 from 'std::vector<int>::iterator' to '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'}
 1143 |       operator-=(difference_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~~~~~~~^~~
a.cc:76:14: error: invalid cast from type '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' to type 'int'
   76 |   int itri = (int)itr;
      |              ^~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:71:
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_equals_val<_Value>::operator()(_Iterator) [with _Iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Value = const std::pair<std::pair<int, int>, int>]':
/usr/include/c++/14/bits/stl_algobase.h:2107:14:   required from '_RandomAccessIterator std::__find_if(_RandomAccessIterator, _RandomAccessIterator, _Predicate, random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<int*, vector<int> >; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const pair<pair<int, int>, int> >]'
 2107 |           if (__pred(__first))
      |               ~~~~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:2152:23:   required from '_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = __gnu_cxx::__normal_iterator<int*, vector<int> >; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const pair<pair<int, int>, int> >]'
 2152 |       return __find_if(__first, __last, __pred,
      |              ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
 2153 |                        std::__iterator_category(__first));
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:3850:28:   required from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = __gnu_cxx::__normal_iterator<int*, vector<int> >; _Tp = pair<pair<int, int>, int>]'
 3850 |       return std::__find_if(__first, __last,
      |              ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
 3851 |                             __gnu_cxx::__ops::__iter_equals_val(__val));
      |                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:74:18:   required from here
   74 |   auto itr = find(ALL(ans),b[0]);
      |              ~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:270:24: error: no match for 'operator==' (operand types are 'int' and 'const std::pair<std::pair<int, int>, int>')
  270 |         { return *__it == _M_value; }
      |                  ~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1208:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator==(const __normal_iterator<_IteratorL, _Container>&, const __normal_iterator<_IteratorR, _Container>&)'
 1208 |     operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1208:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:270:24: note:   mismatched types 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>' and 'int'
  270 |         { return *__it == _M_value; }
      |                  ~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1216:5: note: candidate: 'template<class _Iterator, class _Container> bool __gnu_cxx::operator==(const __normal_iterator<_Iterator, _Container>&, const __normal_iterator<_Iterator, _Container>&)'
 1216 |     operator==(const __normal_iterator<_Iterator, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1216:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:270:24: note:   mismatched types 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>' and 'int'
  270 |         { return *__it == _M_value; }
      |                  ~~~~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/regex:68,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181:
/usr/include/c++/14/bits/regex.h:1103:5: note: candidate: 'template<class _BiIter> bool std::__cxx11::operator==(const sub_match<_BiIter>&, const sub_match<_BiIter>&)'
 1103 |     operator==(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1103:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:270:24: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'int'
  270 |         { return *__it == _M_value; }
      |                  ~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:1199:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator==(__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const sub_match<_BiIter>&)'
 1199 |     operator==(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1199:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:270:24: note:   mismatched types 'std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>' and 'int'
  270 |         { return *__it == _M_value; }
      |                  ~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:1274:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator==(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)'
 1274 |     operator==(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1274:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:270:24: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'int'
  270 |         { return *__it == _M_value; }
      |                  ~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:1366:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const typename std::iterator_traits<_Iter>::value_type*, const sub_match<_BiIter>&)'
 1366 |     operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1366:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:270:24: note:   'const std::pair<std::pair<int, int>, int>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
  270 |         { return *__it == _M_value; }
      |                  ~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:1441:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)'
 1441 |     operator==(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1441:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:270:24: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'int'
  270 |         { return *__it == _M_value; }
      |                  ~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:1534:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const typename std::iterator_traits<_Iter>::value_type&, const sub_match<_BiIter>&)'
 1534 |     operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1534:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:270:24: note:   'const std::pair<std::pair<int, int>, int>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
  270 |         { return *__it == _M_value; }
      |                  ~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:1613:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)'
 1613 |     operator==(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1613:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:270:24: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'int'
  270 |         { return *__it == _M_value; }
      |                  ~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/regex.h:2186:5: note: candidate: 'template<class _Bi_iter, class _Alloc> bool std::__cxx11::operator==(const match_results<_BiIter, _Alloc>&, const match_results<_BiIter, _Alloc>&)'
 2186 |     operator==(const match_results<_Bi_iter, _Alloc>& __m1,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:2186:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:270:24: note:   mismatched types 'const std::__cxx11::match_results<_BiIter, _Alloc>' and 'int'
  270 |         { return *__it == _M_value; }
      |                  ~~~~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64:
/usr/include/c++/14/bits/stl_pair.h:1033:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator==(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1033 |     operator==(const pair<_T1, _