Language: C++

#include <algorithm>
#include <queue>
#include <iostream>
#include <set>
#include <cstdio>
#include <complex>
#include <cmath>
#include <cfloat>

#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); retu
inline double getDouble(){ double s; scanf("%lf",
using namespace std;

typedef complex<double> P;

struct S{
  P p1;
  P p2;
  S(P p,P q) : p1(p), p2(q) {}
};

int ccw(P p0, P p1, P p2){
  P d1 = p1-p0;
  P d2 = p2-p0;
  double dx1 = d1.real(), dx2 = d2.real();
  double dy1 = d1.imag(), dy2 = d2.imag();

  if(dx1*dy2 > dy1*dx2) return  1;
  if(dx1*dy2 < dy1*dx2) return -1;
  if((dx1*dx2 < 0) || (dy1*dy2 < 0)) return -1;
  if((dx1*dx1+dy1*dy1) < (dx2*dx2+dy2*dy2)) retur
  return 0;
}

bool intersect(const S &s1, const S &s2){
  return ((ccw(s1.p1, s1.p2, s2.p1)
           *ccw(s1.p1, s1.p2, s2.p2)) <= 0)
    &&((ccw(s2.p1, s2.p2, s1.p1)
        *ccw(s2.p1, s2.p2, s1.p2)) <= 0);
}

#define PP(p, i, n) (p[((i)==-1 ? (n)-1 : (i))])

bool inside(P t, P *p, int N){
  int count = 0;
  S lt(t, P(DBL_MAX,t.imag() + 1e-3));

  for(int i=0; i<N; i++){
    S lp(p[i == 0 ? N - 1 : i - 1], p[i]);
    if(ccw(lt.p1, lt.p2, p[i == 0 ? N - 1 : i - 1
      if(intersect(lp,lt)) count++;
    }else{
      return false;
    }
  }
  // printf("%d ", count);
  return (count & 1) == 1;
}

struct cmpTheta{
  const P base;
  cmpTheta(P p) : base(p) {}

  bool operator () (const P &p1, const P &p2) con
    P ang1 = (p1 - base) / abs(p1 - base);
    P ang2 = (p2 - base) / abs(p2 - base);
    return (ang1 / ang2).imag() < 0;
  }
};

int grahamscan(P *p, int N){
  int min, M, i;
  for(min=0, i=0; i<N; i++)
    if(p[i].imag() < p[min].imag())
      min=i;

  for(i=0; i<N; i++)
    if(p[i].imag() == p[min].imag())
      if(p[i].real() > p[min].real())
        min = i;

  swap(p[min], p[0]);

  sort(p+1, p+N, cmpTheta(p[0]));

  for(M=2, i=3; i<N; i++){
    while(ccw(PP(p,M,N),PP(p,M-1,N),PP(p,i,N)) >=
    M++; swap(p[i], p[M]);
  }

  return M + 1;
}

int main(){
  while(const int n = getInt()){
    P dog;
    P food;
    vector<P> p(n);

    dog.real() = getDouble();
    dog.imag() = getDouble();

    const double len = std::abs(dog);
    const double EPS = 1e-8;

    food.real() = getDouble();
    food.imag() = getDouble();

    REP(i,n){
      p[i].real() = getDouble();
      p[i].imag() = getDouble();
    }

    if(len + EPS < std::abs(food)){
      puts("-1");
      continue;
    }

    const double PI = acos(0) * 2.0;

    {
      double ang = arg(dog);
      P rot = P(cos(-ang), sin(-ang));

      dog *= rot; food *= rot;
      REP(i,n) p[i] *= rot;
    }

    if(arg(food) < 0){
      food.imag() *= -1;
      REP(i,n) p[i].imag() *= -1;
    }

    vector<pair<double, int> > memo(n);
    REP(i,n){
      memo[i].first  = arg(p[i]);
      memo[i].second = i;
    }

    sort(memo.begin(), memo.end());

    vector<P> ps;

    REP(i,n){
      if(arg(dog) < memo[i].first &&
         memo[i].first < arg(food)){
        ps.push_back(p[memo[i].second]);
      }
    }

    const int m = ps.size();
    double ans = std::abs(food) + std::abs(dog);
    /*{ printf("%d: %.2f %.2f\n", -1, dog.real(),
    REP(i,m){ printf("%d: %.2f %.2f\n", i, ps[i].
    { printf("%d: %.2f %.2f\n", -2, food.real(),

    REP(i,1 << m){
      vector<P> t;
      t.push_back(P(0,0));
      t.push_back(dog);
      REP(j,m) if(i & (1 << j))
        t.push_back(ps[j]);
      t.push_back(food);

      vector<P> in;
      in.push_back(P(0,0));

      REP(j,m) if((i & (1 << j)) == 0){
        if(inside(ps[j], &t[0], t.size()))
          in.push_back(ps[j]);
      }

      in.push_back(food);

      /*{
        puts("");
        printf("%d:\n", i);
        REP(j,in.size()) printf("%.2f %.2f ", in[
        puts("");
        }*/

      const int g = in.size() != 2 ? grahamscan(&

      /*{
        printf("g: %d\n", g);
        REP(j,g) printf("%.2f %.2f ", in[j].real(
        puts("");
        }*/

      double tmp = 0.0;

      int s = 0;
      REP(j,g) if(abs(in[j] - P(0,0)) < EPS){
        s = j; break;
      }

      if(std::abs(in[(s + g - 1) % g] - food) > E
        reverse(in.begin(), in.begin() + g);
      }

      REP(j,g) if(abs(in[j] - P(0,0)) < EPS){
        s = j; break;
      }

      REP(j,g - 1)
        tmp += std::abs(in[(s + j + 1) % g] - in[


      double ret = 0.0;
      REP(j,t.size() - 2)
        ret += std::abs(t[j + 2] - t[j + 1]);

      // printf("tmp:%.2f ret:%.2f\n", tmp, ret);

      if(tmp < len)
        ans = min(ans, ret);
    }

    printf("%.8f\n", ans);
  }
  return 0;
}

Compiler output:
a.cc: In function 'int getInt()':
a.cc:12:46: error: 'retu' was not declared in this scope
   12 | inline int getInt(){ int s; scanf("%d", &s); retu
      |                                              ^~~~
a.cc:63:9: error: 'P' does not name a type; did you mean 'PP'?
   63 |   const P base;
      |         ^
      |         PP
a.cc:64:13: error: expected ')' before 'p'
   64 |   cmpTheta(P p) : base(p) {}
      |           ~ ^~
      |             )
a.cc:66:27: error: 'P' does not name a type; did you mean 'PP'?
   66 |   bool operator () (const P &p1, const P &p2) con
      |                           ^
      |                           PP
a.cc:66:40: error: 'P' does not name a type; did you mean 'PP'?
   66 |   bool operator () (const P &p1, const P &p2) con
      |                                        ^
      |                                        PP
a.cc:66:45: error: expected ';' at end of member declaration
   66 |   bool operator () (const P &p1, const P &p2) con
      |                                             ^
      |                                              ;
a.cc:66:47: error: 'con' does not name a type
   66 |   bool operator () (const P &p1, const P &p2) con
      |                                               ^~~
a.cc:68:5: error: 'P' does not name a type; did you mean 'PP'?
   68 |     P ang2 = (p2 - base) / abs(p2 - base);
      |     ^
      |     PP
a.cc:69:5: error: expected unqualified-id before 'return'
   69 |     return (ang1 / ang2).imag() < 0;
      |     ^~~~~~
a.cc:70:4: error: expected ';' after struct definition
   70 |   }
      |    ^
      |    ;
a.cc:71:1: warning: no return statement in function returning non-void [-Wreturn-type]
   71 | };
      | ^
a.cc: At global scope:
a.cc:73:16: error: 'P' was not declared in this scope; did you mean 'PP'?
   73 | int grahamscan(P *p, int N){
      |                ^
      |                PP
a.cc:73:19: error: 'p' was not declared in this scope
   73 | int grahamscan(P *p, int N){
      |                   ^
a.cc:73:22: error: expected primary-expression before 'int'
   73 | int grahamscan(P *p, int N){
      |                      ^~~
a.cc:73:27: error: expression list treated as compound expression in initializer [-fpermissive]
   73 | int grahamscan(P *p, int N){
      |                           ^
a.cc: In function 'int main()':
a.cc:98:5: error: 'P' was not declared in this scope
   98 |     P dog;
      |     ^
a.cc:99:6: error: expected ';' before 'food'
   99 |     P food;
      |      ^~~~~
      |      ;
a.cc:100:5: error: 'vector' was not declared in this scope
  100 |     vector<P> p(n);
      |     ^~~~~~
a.cc:100:5: note: suggested alternatives:
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/queue:63,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/vector:93:13: note:   'std::pmr::vector'
   93 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
a.cc:100:15: error: 'p' was not declared in this scope
  100 |     vector<P> p(n);
      |               ^
a.cc:102:5: error: 'dog' was not declared in this scope; did you mean 'log'?
  102 |     dog.real() = getDouble();
      |     ^~~
      |     log
a.cc:102:18: error: 'getDouble' was not declared in this scope; did you mean 'double'?
  102 |     dog.real() = getDouble();
      |                  ^~~~~~~~~
      |                  double
a.cc:108:5: error: 'food' was not declared in this scope; did you mean 'fmod'?
  108 |     food.real() = getDouble();
      |     ^~~~
      |     fmod
a.cc:124:20: error: 'arg' was not declared in this scope; did you mean 'std::arg'?
  124 |       double ang = arg(dog);
      |                    ^~~
      |                    std::arg
In file included from a.cc:6:
/usr/include/c++/14/complex:2435:5: note: 'std::arg' declared here
 2435 |     arg(_Tp __x)
      |     ^~~
a.cc:125:8: error: expected ';' before 'rot'
  125 |       P rot = P(cos(-ang), sin(-ang));
      |        ^~~~
      |        ;
a.cc:127:14: error: 'rot' was not declared in this scope
  127 |       dog *= rot; food *= rot;
      |              ^~~
a.cc:131:8: error: 'arg' was not declared in this scope; did you mean 'std::arg'?
  131 |     if(arg(food) < 0){
      |        ^~~
      |        std::arg
/usr/include/c++/14/complex:2435:5: note: 'std::arg' declared here
 2435 |     arg(_Tp __x)
      |     ^~~
a.cc:136:12: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
  136 |     vector<pair<double, int> > memo(n);
      |            ^~~~
      |            std::pair
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:89:12: note: 'std::pair' declared here
   89 |     struct pair;
      |            ^~~~
a.cc:136:17: error: expected primary-expression before 'double'
  136 |     vector<pair<double, int> > memo(n);
      |                 ^~~~~~
a.cc:138:7: error: 'memo' was not declared in this scope
  138 |       memo[i].first  = arg(p[i]);
      |       ^~~~
a.cc:138:24: error: 'arg' was not declared in this scope; did you mean 'std::arg'?
  138 |       memo[i].first  = arg(p[i]);
      |                        ^~~
      |                        std::arg
/usr/include/c++/14/complex:2435:5: note: 'std::arg' declared here
 2435 |     arg(_Tp __x)
      |     ^~~
a.cc:142:10: error: 'memo' was not declared in this scope
  142 |     sort(memo.begin(), memo.end());
      |          ^~~~
a.cc:142:5: error: 'sort' was not declared in this scope; did you mean 'std::sort'?
  142 |     sort(memo.begin(), memo.end());
      |     ^~~~
      |     std::sort
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note: 'std::sort' declared here
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
a.cc:144:15: error: 'ps' was not declared in this scope
  144 |     vector<P> ps;
      |               ^~
a.cc:147:10: error: 'arg' was not declared in this scope; did you mean 'std::arg'?
  147 |       if(arg(dog) < memo[i].first &&
      |          ^~~
      |          std::arg
/usr/include/c++/14/complex:2435:5: note: 'std::arg' declared here
 2435 |     arg(_Tp __x)
      |     ^~~
a.cc:184:21: error: 'in' was not declared in this scope; did you mean 'n'?
  184 |       const int g = in.size() != 2 ? grahamscan(&
      |                     ^~
      |                     n
a.cc:192:7: error: expected primary-expression before 'double'
  192 |       double tmp = 0.0;
      |       ^~~~~~
a.cc:192:23: error: expected ':' before ';' token
  192 |       double tmp = 0.0;
      |                       ^
      |                       :
a.cc:192:23: error: expected primary-expression before ';' token
a.cc:199:49: error: 'E' was not declared in this scope
  199 |       if(std::abs(in[(s + g - 1) % g] - food) > E
      |                                                 ^
a.cc:201:7: error: expected primary-expression before '}' token
  201 |       }
      |       ^
a.cc:200:45: error: expected ')' before '}' token
  200 |         reverse(in.begin(), in.begin() + g);
      |                                             ^
      |                                             )
  201 |       }
      |       ~                                      
a.cc:199:9: note: to match this '('
  199 |       if(std::abs(in[(s + g - 1) % g] - food) > E
      |         ^
a.cc:201:7: error: expected primary-expression before '}' token
  201 |       }
      |       ^
a.cc:203:13: error: 'g' was not declared in this scope
  203 |       REP(j,g) if(abs(in[j] - P(0,0)) < EPS){
      |             ^
a.cc:10:39: note: in definition of macro 'REP'
   10 | #define REP(i,n) for(int i=0; i<(int)(n); i++)
      |                                       ^
a.cc:203:23: error: 'in' was not declared in this scope; did you mean 'yn'?
  203 |       REP(j,g) if(abs(in[j] - P(0,0)) < EPS){
      |                       ^~
      |                       yn
a.cc:203:31: error: 'P' was not declared in this scope
  203 |       REP(j,g) if(abs(in[j] - P(0,0)) < EPS){
      |                               ^
a.cc:203:41: error: 'EPS' was not declared in this scope
  203 |       REP(j,g) if(abs(in[j] - P(0,0)) < EPS){
      |                                         ^~~
a.cc:204:9: error: 's' was not declared in this scope
  204 |         s = j; break;
      |         ^
a.cc:207:13: error: 'g' was not declared in this scope
  207 |       REP(j,g - 1)
      |             ^
a.cc:10:39: note: in definition of macro 'REP'
   10 | #define REP(i,n) for(int i=0; i<(int)(n); i++)
      |                                       ^
a.cc:208:9: error: 'tmp' was not declared in this scope; did you mean 'tm'?
  208 |         tmp += std::abs(in[(s + j + 1) % g] - in[
      |         ^~~
      |         tm
a.cc:208:25: error: 'in' was not declared in this scope; did you mean 'yn'?
  208 |         tmp += std::abs(in[(s + j + 1) % g] - in[
      |                         ^~
      |                         yn
a.cc:208:29: error: 's' was not declared in this scope
  208 |         tmp += std::abs(in[(s + j + 1) % g] - in[
      |                             ^
a.cc:211:7: error: expected primary-expression before 'double'
  211 |       double ret = 0.0;
      |       ^~~~~~
a.cc:208:50: error: expected ']' before 'double'
  208 |         tmp += std::abs(in[(s + j + 1) % g] - in[
      |                                                  ^
      |                                                  ]
......
  211 |       double ret = 0.0;
      |       ~~~~~~                                      
a.cc:212:13: error: 't' was not declared in this scope
  212 |       REP(j,t.size() - 2)
      |             ^
a.cc:10:39: note: in definition of macro 'REP'
   10 | #define REP(i,n) for(int i=0; i<(int)(n); i++)
      |                                       ^
a.cc:213:9: error: 'ret' was not de