#include <bits/stdc++.h>
using namespace std;
const double inf = 1e13;
const double eps = 1e-9;
int Sgn(double k) { return fabs(k) < eps ? 0 : (k < 0 ? -1 : 1); }
int Cmp(double k1, double k2) { return Sgn(k1 - k2); }
struct Point {
  double x, y;
};
Point operator-(Point k1, Point k2) {
  return (Point){k1.x - k2.x, k1.y - k2.y};
}
Point operator+(Point k1, Point k2) {
  return (Point){k1.x + k2.x, k1.y + k2.y};
}
double operator*(Point k1, Point k2) { return k1.x * k2.x + k1.y * k2.y; }
double operator^(Point k1, Point k2) { return k1.x * k2.y - k1.y * k2.x; }
Point operator*(Point k1, double k2) { return (Point){k1.x * k2, k1.y * k2}; }
Point operator/(Point k1, double k2) { return (Point){k1.x / k2, k1.y / k2}; }
double GetLen(Point k) { return sqrt(k * k); }
double GetDisPointToPoint(Point k1, Point k2) {
  return sqrt((k2 - k1) * (k2 - k1));
}
Point Rotate(Point k, double ang) {
  return (Point){k.x * cos(ang) - k.y * sin(ang),
                 k.x * sin(ang) + k.y * cos(ang)};
}
Point Rotate90(Point k) { return (Point){k.y, -k.x}; }
struct Circle {
  Point o;
  double r;
};
bool IsInside(Circle k1, Circle k2) {
  double dis = GetDisPointToPoint(k1.o, k2.o);
  if (Cmp(k1.r - k2.r, dis) >= 0 || Cmp(k2.r - k1.r, dis) >= 0) return true;
  return false;
}
bool IsOutside(Circle k1, Circle k2) {
  double dis = GetDisPointToPoint(k1.o, k2.o);
  if (Cmp(dis, k1.r + k2.r) > 0) return true;
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed << setprecision(10);
  Point s, t;
  cin >> s.x >> s.y >> t.x >> t.y;
  int n;
  cin >> n;
  vector<Circle> c(n);
  for (auto &it : c) cin >> it.o.x >> it.o.y >> it.r;
  Point mid_point = (s + t) / 2.0;
  Point dir = Rotate90(t - s) / GetLen(t - s);
  double dis_div2 = GetDisPointToPoint(s, mid_point);
  bool ans_flag = true;
  for (auto &it : c) {
    Circle cur = (Circle){mid_point, dis_div2};
    if (!IsInside(cur, it) && !IsOutside(cur, it)) {
      ans_flag = false;
      break;
    }
  }
  if (ans_flag) {
    cout << dis_div2 << endl;
    return 0;
  }
  vector<pair<double, double>> record;
  for (auto &it : c) {
    bool dir_flag;
    if (Sgn((it.o - mid_point) * dir) > 0)
      dir_flag = true;
    else
      dir_flag = false;
    double inside_record, outside_record;
    Circle binary_search_cur;
    int binary_search_cnt = 0;
    double binary_search_left = -inf, binary_search_right = inf;
    while (Cmp(binary_search_left, binary_search_right) &&
           binary_search_cnt++ < 100) {
      double binary_search_mid =
          (binary_search_left + binary_search_right) / 2.0;
      binary_search_cur.o = dir * binary_search_mid + mid_point;
      binary_search_cur.r =
          sqrt(binary_search_mid * binary_search_mid + dis_div2 * dis_div2);
      if (IsInside(binary_search_cur, it)) {
        inside_record = binary_search_mid;
        if (dir_flag)
          binary_search_right = binary_search_mid;
        else
          binary_search_left = binary_search_mid;
      } else {
        if (dir_flag)
          binary_search_left = binary_search_mid;
        else
          binary_search_right = binary_search_mid;
      }
    }
    binary_search_cnt = 0;
    binary_search_left = -inf, binary_search_right = inf;
    while (Cmp(binary_search_left, binary_search_right) &&
           binary_search_cnt++ < 100) {
      double binary_search_mid =
          (binary_search_left + binary_search_right) / 2.0;
      binary_search_cur.o = dir * binary_search_mid + mid_point;
      binary_search_cur.r =
          sqrt(binary_search_mid * binary_search_mid + dis_div2 * dis_div2);
      if (IsOutside(binary_search_cur, it)) {
        outside_record = binary_search_mid;
        if (dir_flag)
          binary_search_left = binary_search_mid;
        else
          binary_search_right = binary_search_mid;
      } else {
        if (dir_flag)
          binary_search_right = binary_search_mid;
        else
          binary_search_left = binary_search_mid;
      }
    }
    if (Cmp(inside_record, outside_record) > 0)
      swap(inside_record, outside_record);
    record.push_back(make_pair(inside_record, outside_record));
  }
  sort(record.begin(), record.end(),
       [&](pair<double, double> k1, pair<double, double> k2) {
         return Cmp(k1.first, k2.first) < 0;
       });
  double ans = Cmp(-record[0].first, 0.0) > 0 ? -record[0].first : 0.0;
  double fi = record[0].first, se = record[0].second;
  for (int i = 1; i < record.size(); ++i) {
    if (Cmp(se, record[i].first) < 0) {
      if (Cmp(ans, fabs(se)) > 0) ans = fabs(se);
      if (Cmp(ans, fabs(record[i].first)) > 0) ans = fabs(record[i].first);
      fi = record[i].first;
    }
    if (Cmp(record[i].second, se) > 0) se = record[i].second;
  }
  if (Cmp(ans, fabs(se)) > 0) ans = fabs(se);
  cout << sqrt(ans * ans + dis_div2 * dis_div2) << endl;
  return 0;
}
