#include <bits/stdc++.h>
using namespace std;
const int MN = 100010;
double dist(pair<double, double> a, pair<double, double> b) {
  double dx = a.first - b.first;
  double dy = a.second - b.second;
  return sqrt(dx * dx + dy * dy);
}
pair<double, double> rotate(pair<double, double> a, double t) {
  return {a.first * cos(t) - a.second * sin(t),
          a.first * sin(t) + a.second * cos(t)};
}
double X1, Y1, X2, Y2;
int N;
struct Circle {
  double x, y, r;
};
Circle C[MN];
pair<double, double> seg[MN];
vector<pair<double, double> > rem;
bool intersect(Circle a, Circle b) {
  return dist({a.x, a.y}, {b.x, b.y}) <= a.r + b.r + 1e-9;
}
bool inside(Circle a, Circle b) {
  return dist({a.x, a.y}, {b.x, b.y}) + b.r <= a.r + 1e-9;
}
int main() {
  std::ios::sync_with_stdio(false);
  cout << fixed;
  cout.precision(20);
  cin >> X1 >> Y1 >> X2 >> Y2 >> N;
  X2 -= X1;
  Y2 -= Y1;
  for (int i = 0; i < N; i++) {
    cin >> C[i].x >> C[i].y >> C[i].r;
    C[i].x -= X1;
    C[i].y -= Y1;
  }
  X1 = 0;
  Y1 = 0;
  double t = -atan2(Y2, X2);
  pair<double, double> tmp = rotate({X2, Y2}, t);
  X2 = tmp.first;
  Y2 = tmp.second;
  for (int i = 0; i < N; i++) {
    pair<double, double> tmp = rotate({C[i].x, C[i].y}, t);
    C[i].x = tmp.first;
    C[i].y = tmp.second;
  }
  double dx = X2 / 2;
  X1 -= dx;
  X2 -= dx;
  for (int i = 0; i < N; i++) {
    C[i].x -= dx;
  }
  for (int i = 0; i < N; i++) {
    if (C[i].y > 0) {
      double s = -1e12, e = 1e12;
      for (int n = 0; n < 70; n++) {
        double m = (s + e) / 2;
        if (intersect({0, m, dist({0, m}, {X2, 0})}, C[i]))
          e = m;
        else
          s = m;
      }
      seg[i].first = e;
      s = -1e12, e = 1e12;
      for (int n = 0; n < 70; n++) {
        double m = (s + e) / 2;
        if (inside({0, m, dist({0, m}, {X2, 0})}, C[i]))
          e = m;
        else
          s = m;
      }
      seg[i].second = e;
    } else {
      double s = -1e12, e = 1e12;
      for (int n = 0; n < 70; n++) {
        double m = (s + e) / 2;
        if (intersect({0, m, dist({0, m}, {X2, 0})}, C[i]))
          s = m;
        else
          e = m;
      }
      seg[i].second = s;
      s = -1e12, e = 1e12;
      for (int n = 0; n < 70; n++) {
        double m = (s + e) / 2;
        if (inside({0, m, dist({0, m}, {X2, 0})}, C[i]))
          s = m;
        else
          e = m;
      }
      seg[i].first = s;
    }
  }
  sort(seg, seg + N);
  for (int i = 0; i < N; i++) {
    if (rem.size() && rem.back().second + 1e-9 >= seg[i].second) continue;
    rem.push_back(seg[i]);
  }
  double ans = 1e12;
  double la = -1e12;
  for (int i = 0; i < rem.size(); i++) {
    if (la + 1e-9 < rem[i].first) {
      if (la <= 1e-9 && 0 <= rem[i].first + 1e-9) {
        ans = min(ans, dist({0, 0}, {X2, 0}));
      }
      ans = min(ans, dist({0, la}, {X2, 0}));
      ans = min(ans, dist({0, rem[i].first}, {X2, 0}));
    }
    la = max(la, rem[i].second);
  }
  ans = min(ans, dist({0, la}, {X2, 0}));
  if (la <= 1e-9) ans = min(ans, dist({0, 0}, {X2, 0}));
  cout << ans;
}
