Language: C++

#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision

using namespace std;
using p = pair<int,int>;
int main(){
    cout << fixed << setprecision(10);
    int n; cin >> n;
    vector<vector<p>> towns(n);
    double ave;
    for (i = 0; i < n; i++)
    {
        cin >> towns[i].first >> towns[i].second; 
    }
    double sum = 0;
    do{ 
        p before = towns[0];
        p after;
        for (int i = 1; i < n; i++)
        {
            after = towns[i];
            int dx = after.first - before.first;
            int dy = after.second - before.second;
            sum += sqrt(dx*dx + dy*dy);
        }
    }while(next_permutation(towns.begin(),towns.end()));
    ave = sum/n;
    cout << ave <<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:10: error: 'i' was not declared in this scope
   16 |     for (i = 0; i < n; i++)
      |          ^
a.cc:22:27: error: conversion from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<int, int> > >, std::vector<std::pair<int, int> > >::value_type' {aka 'std::vector<std::pair<int, int> >'} to non-scalar type 'p' {aka 'std::pair<int, int>'} requested
   22 |         p before = towns[0];
      |                           ^
a.cc:26:28: error: no match for 'operator=' (operand types are 'p' {aka 'std::pair<int, int>'} and '__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<int, int> > >, std::vector<std::pair<int, int> > >::value_type' {aka 'std::vector<std::pair<int, int> >'})
   26 |             after = towns[i];
      |                            ^
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:946:9: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, const _U1&>, std::is_assignable<_T2&, const _U2&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U2 = _U1; _T1 = int; _T2 = int]'
  946 |         operator=(const pair<_U1, _U2>& __p)
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:946:9: note:   template argument deduction/substitution failed:
a.cc:26:28: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<int, int> > >, std::vector<std::pair<int, int> > >::value_type' {aka 'std::vector<std::pair<int, int> >'} is not derived from 'const std::pair<_T1, _T2>'
   26 |             after = towns[i];
      |                            ^
/usr/include/c++/14/bits/stl_pair.h:957:9: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, _U1&&>, std::is_assignable<_T2&, _U2&&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U2 = _U1; _T1 = int; _T2 = int]'
  957 |         operator=(pair<_U1, _U2>&& __p)
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:957:9: note:   template argument deduction/substitution failed:
a.cc:26:28: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<int, int> > >, std::vector<std::pair<int, int> > >::value_type' {aka 'std::vector<std::pair<int, int> >'} is not derived from 'std::pair<_T1, _T2>'
   26 |             after = towns[i];
      |                            ^
/usr/include/c++/14/bits/stl_pair.h:921:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::__conditional_t<((bool)std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value), const std::pair<_T1, _T2>&, const std::__nonesuch&>) [with _T1 = int; _T2 = int; std::__conditional_t<((bool)std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value), const std::pair<_T1, _T2>&, const std::__nonesuch&> = const std::pair<int, int>&]'
  921 |       operator=(__conditional_t<__and_<is_copy_assignable<_T1>,
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:923:65: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<int, int> > >, std::vector<std::pair<int, int> > >::value_type' {aka 'std::vector<std::pair<int, int> >'} to 'std::__conditional_t<true, const std::pair<int, int>&, const std::__nonesuch&>' {aka 'const std::pair<int, int>&'}
  921 |       operator=(__conditional_t<__and_<is_copy_assignable<_T1>,
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
  922 |                                        is_copy_assignable<_T2>>::value,
      |                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  923 |                                 const pair&, const __nonesuch&> __p)
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_pair.h:931:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::__conditional_t<((bool)std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value), std::pair<_T1, _T2>&&, std::__nonesuch&&>) [with _T1 = int; _T2 = int; std::__conditional_t<((bool)std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value), std::pair<_T1, _T2>&&, std::__nonesuch&&> = std::pair<int, int>&&]'
  931 |       operator=(__conditional_t<__and_<is_move_assignable<_T1>,
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:933:55: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<int, int> > >, std::vector<std::pair<int, int> > >::value_type' {aka 'std::vector<std::pair<int, int> >'} to 'std::__conditional_t<true, std::pair<int, int>&&, std::__nonesuch&&>' {aka 'std::pair<int, int>&&'}
  931 |       operator=(__conditional_t<__and_<is_move_assignable<_T1>,
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  932 |                                        is_move_assignable<_T2>>::value,
      |                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  933 |                                 pair&&, __nonesuch&&> __p)
      |                                 ~~~~~~~~~~~~~~~~~~~~~~^~~