#include <bits/stdc++.h>
using namespace std;
long double sadsadhskaksdj, sjakdsajkldsa, fjsdakjldsjakldjskla, dasjakldhsaio;
long double dskjlajkldsajkl, dwuiqoduowqu;
int n;
struct o {
  long double x, y, r;
  o() {}
};
o a[100010];
const long double eps = 1e-16;
long double dist(long double sadsadhskaksdj, long double sjakdsajkldsa,
                 long double fjsdakjldsjakldjskla, long double dasjakldhsaio) {
  return sqrt((sadsadhskaksdj - fjsdakjldsjakldjskla) *
                  (sadsadhskaksdj - fjsdakjldsjakldjskla) +
              (sjakdsajkldsa - dasjakldhsaio) *
                  (sjakdsajkldsa - dasjakldhsaio));
}
bool cmp(const pair<long double, int> &lhs, const pair<long double, int> &rhs) {
  if (abs(lhs.first - rhs.first) > eps) return lhs.first < rhs.first;
  return lhs.second < rhs.second;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> sadsadhskaksdj >> sjakdsajkldsa >> fjsdakjldsjakldjskla >>
      dasjakldhsaio;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i].x >> a[i].y >> a[i].r;
  }
  long double A = dasjakldhsaio - sjakdsajkldsa,
              B = sadsadhskaksdj - fjsdakjldsjakldjskla;
  long double mx = max(abs(A), abs(B));
  A /= mx, B /= mx;
  dskjlajkldsajkl = (sadsadhskaksdj + fjsdakjldsjakldjskla) / 2,
  dwuiqoduowqu = (sjakdsajkldsa + dasjakldhsaio) / 2;
  long double ans = 1e15;
  for (int te = 0; te < 2; te++) {
    vector<pair<long double, long double> > b;
    b.push_back(make_pair(0, 0));
    b.push_back(make_pair(0, 1));
    A *= -1, B *= -1;
    for (int i = 0; i < n; i++) {
      long double r =
          dist(dskjlajkldsajkl, dwuiqoduowqu, sadsadhskaksdj, sjakdsajkldsa);
      long double d = dist(dskjlajkldsajkl, dwuiqoduowqu, a[i].x, a[i].y);
      if (d > a[i].r + r) {
        long double lo = 0, hi = 1e12;
        for (int j = 0; j < 80; j++) {
          long double mi = (lo + hi) / 2;
          long double x = dskjlajkldsajkl + mi * A;
          long double y = dwuiqoduowqu + mi * B;
          long double r = dist(x, y, sadsadhskaksdj, sjakdsajkldsa);
          long double d = dist(x, y, a[i].x, a[i].y);
          if (d > r + a[i].r)
            lo = mi;
          else
            hi = mi;
        }
        long double left = lo;
        hi = 1e12;
        for (int j = 0; j < 80; j++) {
          long double mi = (lo + hi) / 2;
          long double x = dskjlajkldsajkl + mi * A;
          long double y = dwuiqoduowqu + mi * B;
          long double r = dist(x, y, sadsadhskaksdj, sjakdsajkldsa);
          long double d = dist(x, y, a[i].x, a[i].y);
          if (d + a[i].r > r)
            lo = mi;
          else
            hi = mi;
        }
        long double right = hi;
        b.push_back(make_pair(left, 0));
        b.push_back(make_pair(right, 1));
      } else if (d + a[i].r < r) {
        long double lo = 0, hi = 1e12;
        for (int j = 0; j < 80; j++) {
          long double mi = (lo + hi) / 2;
          long double x = dskjlajkldsajkl + mi * A;
          long double y = dwuiqoduowqu + mi * B;
          long double r = dist(x, y, sadsadhskaksdj, sjakdsajkldsa);
          long double d = dist(x, y, a[i].x, a[i].y);
          if (d + a[i].r < r)
            lo = mi;
          else
            hi = mi;
        }
        long double left = lo;
        hi = 1e12;
        for (int j = 0; j < 80; j++) {
          long double mi = (lo + hi) / 2;
          long double x = dskjlajkldsajkl + mi * A;
          long double y = dwuiqoduowqu + mi * B;
          long double r = dist(x, y, sadsadhskaksdj, sjakdsajkldsa);
          long double d = dist(x, y, a[i].x, a[i].y);
          if (d < a[i].r + r)
            lo = mi;
          else
            hi = mi;
        }
        long double right = hi;
        b.push_back(make_pair(left, 0));
        b.push_back(make_pair(right, 1));
      } else {
        long double left = 0;
        long double lo = 0, hi = 1e12;
        for (int j = 0; j < 80; j++) {
          long double mi = (lo + hi) / 2;
          long double x = dskjlajkldsajkl + mi * A;
          long double y = dwuiqoduowqu + mi * B;
          long double r = dist(x, y, sadsadhskaksdj, sjakdsajkldsa);
          long double d = dist(x, y, a[i].x, a[i].y);
          if (d < a[i].r + r)
            lo = mi;
          else
            hi = mi;
        }
        long double right = hi;
        lo = 0, hi = 1e12;
        for (int j = 0; j < 80; j++) {
          long double mi = (lo + hi) / 2;
          long double x = dskjlajkldsajkl + mi * A;
          long double y = dwuiqoduowqu + mi * B;
          long double r = dist(x, y, sadsadhskaksdj, sjakdsajkldsa);
          long double d = dist(x, y, a[i].x, a[i].y);
          if (d + a[i].r > r)
            lo = mi;
          else
            hi = mi;
        }
        right = min(right, hi);
        b.push_back(make_pair(left, 0));
        b.push_back(make_pair(right, 1));
      }
    }
    sort(b.begin(), b.end(), cmp);
    int c = 0;
    for (pair<long double, int> e : b) {
      if (e.second == 0)
        c++;
      else
        c--;
      if (c == 0) {
        long double x = dskjlajkldsajkl + e.first * A;
        long double y = dwuiqoduowqu + e.first * B;
        long double r = dist(x, y, sadsadhskaksdj, sjakdsajkldsa);
        ans = min(ans, r);
        break;
      }
    }
  }
  cout << fixed << setprecision(12) << ans << endl;
  return 0;
}
