Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<cmath>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define mp         make_pair
#define pb         push_back
#define fir        first
#define sec        second
//#define double long double

typedef complex<double> P;
const double eps = 1e-09;
const double eps2= 1e-09;
const double eps3= 1e-07;
const double pi  = acos(-1);
#define EQ(a,b)    (fabs(a-b) < eps)

namespace std{
  bool operator<(const P &a,const P &b){
    if (a.real() != b.real())return a.real() < b.real();
    else return a.imag() < b.imag();
  }
}

double cross(P a,P b){
  return a.real()*b.imag()-a.imag()*b.real();
}

bool is_intersected_ll(P a1,P a2,P b1,P b2){
  return !EQ(cross(a1-a2,b1-b2),0.0);
}

P intersection_ll(P a1,P a2,P b1,P b2){
  P a=a2-a1,b=b2-b1;
  return a1+(a*cross(b,b1-a1)/cross(b,a));
}

bool isp(P a,P b,P c){
  return abs(a-c)+abs(b-c) < abs(a-b) + eps;
}

bool is_intersected_ls(P a1,P a2,P b1,P b2){
  if ( isp(a1,a2,b1))return true;
  if ( isp(a1,a2,b2))return true;
  if ( isp(b1,b2,a1))return true;
  if ( isp(b1,b2,a2))return true;
  if (  ( cross(a2-a1,b1-a1) * cross(a2-a1,b2-a1)<eps ) && //-EPS
	( cross(b2-b1,a1-b1)*cross(b2-b1,a2-b1)  <eps))return true;
  else return false;
}

P intersection_ls(P a1,P a2,P b1,P b2){
  P b = b2-b1;
  double d1=fabs(cross(b,a1-b1));//
  double d2=fabs(cross(b,a2-b1));
  double t = d1/(d1+d2);//p[^ t:1-t = d1:d2
  return a1+(a2-a1)*t;
}

double dif(P b,P a){
  double a1=arg(a),b1=arg(b);
  if (a1 < 0)a1+=2*pi;
  double ret = b1-a1;
  while(ret < 0)ret+=2*pi;
  while(ret > 2*pi)ret-=2*pi;
  return ret;
}

P norm(P a,P ori){
  P tmp=a-ori;
  swap(tmp.real(),tmp.imag());
  tmp.real()*=-1;
  return tmp+ori;
}

P rot(P ori,P a,double c,double s,double ang){
  P tmp=a-ori;
  P ret2=P(tmp.real()*c-tmp.imag()*s,tmp.real()*s+tmp.imag()*c);
  P tmp2=polar(abs(tmp),arg(tmp));
  if (abs(tmp-tmp2) <eps);
  else assert(false);
  P ret = polar(abs(tmp),ang+arg(tmp));
  assert(abs(ret-ret2)<eps);
  return ori+ret;
}

double solve(int n,P *in,P *in2,P *out){
  sort(in,in+n);
  sort(in2,in2+n);
  bool check=true;
  rep(i,n){
    if (!(abs(in2[i]-in[i])<eps))check=false;
  }
  if (check)return 0;

  vector<pair<double,P> > a;
  rep(i,n){
    if (abs(in[i]-in2[0]) < eps)continue;
    P mida=(in[i]+in2[0])/(double)2.0;
    P ta=norm(in[i],mida);
    rep(j,n){
      if (i == j)continue;
      if (abs(in[j]-in2[1]) < eps)continue;
      P midb=(in[j]+in2[1])/(double)2.0;
      P tb=norm(in[j],midb);

//       cout << in[i] <<" " << in2[0] <<" " << in[j]<<" " << in2[1] << endl;
//       cout << mida <<" " <<ta <<" " <<  midb << " " << tb << endl;
//       cout << is_intersected_ll(mida,ta,midb,tb) << endl;
//       cout << endl;
      P candi;
      if (is_intersected_ll(mida,ta,midb,tb)){
	candi=intersection_ll(mida,ta,midb,tb);
      }else if(is_intersected_ls(mida,ta,midb,tb)){
	candi=intersection_ls(mida,ta,midb,tb);
      }else continue;
      
      double da=dif(in[i]-candi,in2[0]-candi),db=dif(in[j]-candi,in2[1]-candi);

      //if (fabs(da-db)<eps)
      //if (abs(candi) < 1e-5)
      //      printf("cand (%.10lf,%.10lf) %.10lf %.10lf %.10lf\n",
      //	     candi.real(),candi.imag(),da,db,
      //	     fabs(da-db));
      //cout << "cand " << candi << " " << da <<" " << db <<" " << fabs(da-db) << endl;

      //if (fabs(da-db)<eps2)a.pb(mp(da,candi));
      a.pb(mp(da,candi));
      a.pb(mp(db,candi));
    }
  }
  
  sort(a.begin(),a.end());
  rep(i,a.size()){
    double cost=cos(a[i].fir),sint=sin(a[i].fir);
    rep(j,n){
      out[j]=rot(a[i].sec,in2[j],cost,sint,a[i].fir);
    }
    sort(out,out+n);
    //cout <<"rot " << a[i].sec <<" " << a[i].fir << endl;
    //rep(j,n)cout<<in[j]<<" " << out[j] << " " << abs(in[j]-out[j]) << endl;
    bool isok=true;
    rep(j,n){
      if (!(abs(in[j]-out[j])<eps3)){isok=false;break;}
    }
    if (isok)return a[i].fir;
  }
  return 0;
}

main(){
  int n;
  P in[1000],in2[1000],out[1000];
  while(cin>>n && n){
    rep(i,n){double x,y;cin>>x>>y;in[i]=P(x,y);}
    rep(i,n){double x,y;cin>>x>>y;in2[i]=P(x,y);}
    printf("%.11lf\n",min(solve(n,in,in2,out),solve(n,in2,in,out)));
    //printf("%.11Lf\n",min(solve(n,in,in2,out),solve(n,in2,in,out)));
    //printf("%.11lf\n",solve(n,in2,in,out));
  }
  return 0;
}

Compiler output:
a.cc: In function 'P norm(P, P)':
a.cc:75:7: error: no matching function for call to 'swap(double, double)'
   75 |   swap(tmp.real(),tmp.imag());
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/move.h:226:5: note: candidate: 'std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = double; _Require<__not_<__is_tuple_like<_Tp> >, is_move_constructible<_Tp>, is_move_assignable<_Tp> > = void]' (near match)
  226 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/14/bits/move.h:226:5: note:   conversion of argument 2 would be ill-formed:
a.cc:75:27: error: cannot bind non-const lvalue reference of type 'double&' to an rvalue of type 'double'
   75 |   swap(tmp.real(),tmp.imag());
      |                   ~~~~~~~~^~
/usr/include/c++/14/bits/exception_ptr.h:229:5: note: candidate: 'void std::__exception_ptr::swap(exception_ptr&, exception_ptr&)'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
/usr/include/c++/14/bits/exception_ptr.h:229:25: note:   no known conversion for argument 1 from 'double' to 'std::__exception_ptr::exception_ptr&'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |          ~~~~~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/14/complex:45,
                 from a.cc:4:
/usr/include/c++/14/sstream:1204:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(basic_stringbuf<_CharT, _Traits, _Alloc>&, basic_stringbuf<_CharT, _Traits, _Alloc>&)'
 1204 |     swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x,
      |     ^~~~
/usr/include/c++/14/sstream:1204:5: note:   template argument deduction/substitution failed:
a.cc:75:7: note:   mismatched types 'std::__cxx11::basic_stringbuf<_CharT, _Traits, _Alloc>' and 'double'
   75 |   swap(tmp.real(),tmp.imag());
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/sstream:1212:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(basic_istringstream<_CharT, _Traits, _Allocator>&, basic_istringstream<_CharT, _Traits, _Allocator>&)'
 1212 |     swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x,
      |     ^~~~
/usr/include/c++/14/sstream:1212:5: note:   template argument deduction/substitution failed:
a.cc:75:7: note:   mismatched types 'std::__cxx11::basic_istringstream<_CharT, _Traits, _Allocator>' and 'double'
   75 |   swap(tmp.real(),tmp.imag());
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/sstream:1219:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(basic_ostringstream<_CharT, _Traits, _Allocator>&, basic_ostringstream<_CharT, _Traits, _Allocator>&)'
 1219 |     swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x,
      |     ^~~~
/usr/include/c++/14/sstream:1219:5: note:   template argument deduction/substitution failed:
a.cc:75:7: note:   mismatched types 'std::__cxx11::basic_ostringstream<_CharT, _Traits, _Allocator>' and 'double'
   75 |   swap(tmp.real(),tmp.imag());
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/sstream:1226:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(basic_stringstream<_CharT, _Traits, _Allocator>&, basic_stringstream<_CharT, _Traits, _Allocator>&)'
 1226 |     swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x,
      |     ^~~~
/usr/include/c++/14/sstream:1226:5: note:   template argument deduction/substitution failed:
a.cc:75:7: note:   mismatched types 'std::__cxx11::basic_stringstream<_CharT, _Traits, _Allocator>' and 'double'
   75 |   swap(tmp.real(),tmp.imag());
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/move.h:250:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> std::__enable_if_t<((bool)std::__is_swappable<_Tp>::value)> std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])'
  250 |     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
      |     ^~~~
/usr/include/c++/14/bits/move.h:250:5: note:   template argument deduction/substitution failed:
a.cc:75:7: note:   mismatched types '_Tp [_Nm]' and 'double'
   75 |   swap(tmp.real(),tmp.imag());
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44:
/usr/include/c++/14/bits/stl_pair.h:1089:5: note: candidate: 'template<class _T1, class _T2> typename std::enable_if<std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value>::type std::swap(pair<_T1, _T2>&, pair<_T1, _T2>&)'
 1089 |     swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
      |     ^~~~
/usr/include/c++/14/bits/stl_pair.h:1089:5: note:   template argument deduction/substitution failed:
a.cc:75:7: note:   mismatched types 'std::pair<_T1, _T2>' and 'double'
   75 |   swap(tmp.real(),tmp.imag());
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1106:5: note: candidate: 'template<class _T1, class _T2> typename std::enable_if<(! std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value)>::type std::swap(pair<_T1, _T2>&, pair<_T1, _T2>&)' (deleted)
 1106 |     swap(pair<_T1, _T2>&, pair<_T1, _T2>&) = delete;
      |     ^~~~
/usr/include/c++/14/bits/stl_pair.h:1106:5: note:   template argument deduction/substitution failed:
a.cc:75:7: note:   mismatched types 'std::pair<_T1, _T2>' and 'double'
   75 |   swap(tmp.real(),tmp.imag());
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:54:
/usr/include/c++/14/bits/basic_string.h:4039:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> void std::swap(__cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 4039 |     swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~
/usr/include/c++/14/bits/basic_string.h:4039:5: note:   template argument deduction/substitution failed:
a.cc:75:7: note:   mismatched types 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'double'
   75 |   swap(tmp.real(),tmp.imag());
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68:
/usr/include/c++/14/tuple:2805:5: note: candidate: 'template<class ... _Elements> typename std::enable_if<std::__and_<std::__is_swappable<_Elements>...>::value>::type std::swap(tuple<_UTypes ...>&, tuple<_UTypes ...>&)'
 2805 |     swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
      |     ^~~~
/usr/include/c++/14/tuple:2805:5: note:   template argument deduction/substitution failed:
a.cc:75:7: note:   mismatched types 'std::tuple<_UTypes ...>' and 'double'
   75 |   swap(tmp.real(),tmp.imag());
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/tuple:2823:5: note: candidate: 'template<class ... _Elements> typename std::enable_if<(! std::__and_<std::__is_swappable<_Elements>...>::value)>::type std::swap(tuple<_UTypes ...>&, tuple<_UTypes ...>&)' (deleted)
 2823 |     swap(tuple<_Elements...>&, tuple<_Elements...>&) = delete;
      |     ^~~~
/usr/include/c++/14/tuple:2823:5: note:   template argument deduction/substitution failed:
a.cc:75:7: note:   mismatched types 'std::tuple<_UTypes ...>' and 'double'
   75 |   swap(tmp.real(),tmp.imag());
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h:2122:5: note: candidate: 'template<class _Tp, class _Alloc> void std::swap(vector<_Tp, _Alloc>&, vector<_Tp, _Alloc>&)'
 2122 |     swap(vector<_Tp, _Alloc>& __x, vector<_Tp, _Alloc>& __y)
      |     ^~~~
/usr/include/c++/14/bits/stl_vector.h:2122:5: note:   template argument deduction/substitution failed:
a.cc:75:7: note:   mismatched types 'std::vector<_Tp, _Alloc>' and 'double'
   75 |   swap(tmp.real(),tmp.imag());
      |   ~~~~^~~~~~~~~~~~~~~~~~~~~~~
a.cc:76:11: error: lvalue required as left operand of assignment
   76 |   tmp.real()*=-1;
      |   ~~~~~~~~^~
a.cc: In function 'P rot(P, P, double, double, double)':
a.cc:85:8: error: 'assert' was not declared in this scope
   85 |   else assert(false);
      |        ^~~~~~
a.cc:6:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
    5 | #include<cmath>
  +++ |+#include <cassert>
    6 | using namespace std;
a.cc:87:3: error: 'assert' was not declared in this scope
   87 |   assert(abs(ret-ret2)<eps);
      |   ^~~~~~
a.cc:87:3: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
a.cc: At global scope:
a.cc:155:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  155 | main(){
      | ^~~~