#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T begin, T end) {
  for (T i = begin; i != end; ++i) cout << *i << " ";
  cout << endl;
}
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
struct Line : public vector<complex<double> > {
  Line() { ; }
  Line(complex<double> a, complex<double> b) {
    push_back(a);
    push_back(b);
  }
};
inline double cross(const complex<double> &a, const complex<double> &b) {
  return imag(conj(a) * b);
}
inline double dot(const complex<double> &a, const complex<double> &b) {
  return real(conj(a) * b);
}
int ccw(complex<double> a, complex<double> b, complex<double> c) {
  b -= a;
  c -= a;
  double len = abs(b) * abs(c);
  if (cross(b, c) > +EPS * len) return +1;
  if (cross(b, c) < -EPS * len) return -1;
  if (dot(b, c) < 0) return +2;
  if (norm(b) < norm(c)) return -2;
  return 0;
}
bool intersectSS(const Line &s, const Line &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool intersectSP(const Line &s, const complex<double> &p) {
  return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < EPS;
}
complex<double> projection(const Line &l, const complex<double> &p) {
  double t = dot(p - l[0], l[0] - l[1]) / norm(l[0] - l[1]);
  return l[0] + t * (l[0] - l[1]);
}
double distanceSP(const Line &s, const complex<double> &p) {
  const complex<double> r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const Line &s, const Line &t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
int main() {
  int N, M, L;
  while (cin >> N >> M >> L && N) {
    M--;
    L--;
    double x[100], y[100], a[100], r[100];
    for (int i = (0); i < (int)N; ++i) {
      cin >> x[i] >> y[i] >> a[i] >> r[i];
    }
    vector<Line> lines(N * 5);
    for (int i = (0); i < (int)N; ++i) {
      complex<double> ps[5];
      for (int j = (0); j < (int)5; ++j)
        ps[j] = complex<double>(
            x[i] + r[i] * cos(M_PI * (90.0 + a[i] + 72 * j) / 180.0),
            y[i] + r[i] * sin(M_PI * (90.0 + a[i] + 72 * j) / 180));
      for (int j = (0); j < (int)5; ++j)
        lines[5 * i + j] = Line(ps[j], ps[(j + 2) % 5]);
    }
    vector<double> dist(N * 5, INF);
    queue<int> que;
    for (int i = (0); i < (int)5; ++i) {
      dist[5 * M + i] = 0;
      que.push(5 * M + i);
    }
    while (!que.empty()) {
      int u = que.front();
      que.pop();
      for (int i = (0); i < (int)N * 5; ++i) {
        double next = dist[u] + distanceSS(lines[u], lines[i]);
        if (next < dist[i]) {
          dist[i] = next;
          que.push(i);
        }
      }
    }
    printf("%.10f\n", dist[5 * L]);
  }
  return 0;
}
