#include <bits/stdc++.h>
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
using namespace std;
struct point {
  double x, y;
  point() {}
  point(double _x, double _y) : x(_x), y(_y) {}
  point operator+(point rhs) const { return point(x + rhs.x, y + rhs.y); }
  point operator-(point rhs) const { return point(x - rhs.x, y - rhs.y); }
  point operator/(double a) const { return point(x / a, y / a); }
  point operator*(double a) const { return point(x * a, y * a); }
  double len() { return sqrt(x * x + y * y); }
  double llen() { return (x * x + y * y); }
  point norm(double val) const {
    double tmp = point(x, y).len();
    return point(x * val / tmp, y * val / tmp);
  }
  double operator%(point rhs) const { return x * rhs.y - y * rhs.x; }
} p1, p2;
int n;
pair<point, int> arr[MAXN];
int sgn(point a, point b) {
  double val = a % b;
  if (val < 0) return -1;
  return 1;
}
bool contains(point a, double r1, point b, double r2) {
  if (r1 > r2) return false;
  return (a - b).len() + r1 <= r2;
}
bool sect(point a, double r1, point b, double r2) {
  if (r1 < r2) swap(r1, r2);
  double l = (a - b).llen();
  if (l < r1 * r1) {
    if (l > (r1 - r2) * (r1 - r2)) return true;
  } else {
    if (l < (r1 + r2) * (r1 + r2)) return true;
  }
  return false;
}
double solve(point cur, int n) {
  vector<pair<double, int> > intrvl;
  point m = p1 + (p2 - p1) / 2;
  double val = ((p2 - p1) / 2).len();
  double val2 = ((p2 - p1) / 2).llen();
  bool fl = 0;
  for (int i = 0; i < n; i++) {
    double st, en;
    if (sgn(p2 - p1, arr[i].first - p1) == sgn(p2 - p1, (m + cur) - p1)) {
      if (contains(arr[i].first, arr[i].second, m, val)) continue;
      if (sect(m, val, arr[i].first, arr[i].second))
        fl = 1, st = 0;
      else {
        double lo = 0, hi = 1e12;
        for (int j = 0; j < 100; j++) {
          double mid = (lo + hi) / 2.;
          point nx = p1 + (p2 - p1) / 2 + cur.norm(mid);
          double r = sqrt(mid * mid + val2);
          if (sect(arr[i].first, arr[i].second, nx, r) ||
              contains(arr[i].first, arr[i].second, nx, r))
            hi = mid;
          else
            lo = mid;
        }
        st = lo;
      }
      double lo = 0, hi = 1e12;
      for (int j = 0; j < 100; j++) {
        double mid = (lo + hi) / 2.;
        point nx = p1 + (p2 - p1) / 2 + cur.norm(mid);
        double r = sqrt(mid * mid + val2);
        if (contains(arr[i].first, arr[i].second, nx, r))
          hi = mid;
        else
          lo = mid;
      }
      en = hi;
    } else {
      if (!contains(arr[i].first, arr[i].second, m, val) &&
          !sect(m, val, arr[i].first, arr[i].second))
        continue;
      if (sect(m, val, arr[i].first, arr[i].second))
        fl = 1, st = 0;
      else {
        double lo = 0, hi = 1e12;
        for (int j = 0; j < 200; j++) {
          double mid = (lo + hi) / 2.;
          point nx = p1 + (p2 - p1) / 2 + cur.norm(mid);
          double r = sqrt(mid * mid + val2);
          if (contains(arr[i].first, arr[i].second, nx, r))
            lo = mid;
          else
            hi = mid;
        }
        st = lo;
      }
      double lo = 0, hi = 1e12;
      for (int j = 0; j < 200; j++) {
        double mid = (lo + hi) / 2.;
        point nx = p1 + (p2 - p1) / 2 + cur.norm(mid);
        double r = sqrt(mid * mid + val2);
        if (sect(arr[i].first, arr[i].second, nx, r) ||
            contains(arr[i].first, arr[i].second, nx, r))
          lo = mid;
        else
          hi = mid;
      }
      en = hi;
    }
    intrvl.push_back({st, -1});
    intrvl.push_back({en, 1});
  }
  sort(intrvl.begin(), intrvl.end());
  double ret = 0;
  if (fl) {
    int cur = 0;
    for (int i = 0; i < intrvl.size(); i++) {
      cur += intrvl[i].second;
      if (cur == 0) {
        ret = intrvl[i].first;
        break;
      }
    }
  }
  return sqrt(ret * ret + val2);
}
int main() {
  scanf("%lf", &p1.x), scanf("%lf", &p1.y), scanf("%lf", &p2.x),
      scanf("%lf", &p2.y);
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%lf", &arr[i].first.x), scanf("%lf", &arr[i].first.y),
        scanf("%d", &arr[i].second);
  point ans = point(-(p1 - p2).y, (p1 - p2).x), tmp = point(0, 0);
  double val = min(solve(ans, n), solve(tmp - ans, n));
  printf("%.15f\n", val);
  return 0;
}
