#include <bits/stdc++.h>
const long long MOD = 1000000007;
using namespace std;
struct pt {
  double x, y;
  pt() {}
  pt(double x1, double y1) { x = x1, y = y1; }
  pt operator-(pt nxt) const { return pt(x - nxt.x, y - nxt.y); }
  pt operator+(pt nxt) const { return pt(x + nxt.x, y + nxt.y); }
  pt operator/(double val) const { return pt(x / val, y / val); }
  pt operator*(double val) const { return pt(x * val, y * val); }
  double len() { return sqrt(x * x + y * y); }
  double squareLen() { return x * x + y * y; }
  pt norm(double val) const {
    double tmp = pt(x, y).len();
    return pt(x * val / tmp, y * val / tmp);
  }
  double operator%(pt nxt) const { return x * nxt.y - y * nxt.x; }
};
pt a, b;
int n;
pair<pt, int> q[500007];
bool cross(pt a, double r1, pt b, double r2) {
  if (r1 < r2) swap(r1, r2);
  if ((a - b).squareLen() < r1 * r1) {
    if ((a - b).squareLen() > (r1 - r2) * (r1 - r2)) return 1;
  } else {
    if ((a - b).squareLen() < (r1 + r2) * (r1 + r2)) return 1;
  }
  return 0;
}
bool in(pt a, double r1, pt b, double r2) {
  if (r1 > r2) return 0;
  return (a - b).len() + r1 <= r2;
}
int sign(double val) {
  if (val < 0) return -1;
  return 1;
}
double solve(pt v) {
  vector<pair<double, int> > t;
  pt sr = a + (b - a) / 2;
  bool crossStart = 0;
  for (int i = 0; i < n; i++) {
    double l, r;
    if (sign((b - a) % (q[i].first - a)) == sign((b - a) % ((sr + v) - a))) {
      if (in(q[i].first, q[i].second, sr, ((b - a) / 2).len())) continue;
      if (cross(sr, ((a - b) / 2).len(), q[i].first, q[i].second))
        crossStart = 1, l = 0;
      else {
        double vl = 0, vr = 1e12;
        for (int it = 0; it < 100; it++) {
          double vm = (vl + vr) / (double)2;
          pt s2 = a + (b - a) / 2 + v.norm(vm);
          double r2 = sqrt(vm * vm + ((a - b) / 2).squareLen());
          if (cross(q[i].first, q[i].second, s2, r2) ||
              in(q[i].first, q[i].second, s2, r2))
            vr = vm;
          else
            vl = vm;
        }
        l = vl;
      }
      double vl = 0, vr = 1e12;
      for (int it = 0; it < 100; it++) {
        double vm = (vl + vr) / (double)2;
        pt s2 = a + (b - a) / 2 + v.norm(vm);
        double r2 = sqrt(vm * vm + ((a - b) / 2).squareLen());
        if (in(q[i].first, q[i].second, s2, r2))
          vr = vm;
        else
          vl = vm;
      }
      r = vr;
    } else {
      if (!in(q[i].first, q[i].second, sr, ((b - a) / 2).len()) &&
          !cross(sr, ((a - b) / 2).len(), q[i].first, q[i].second))
        continue;
      if (cross(sr, ((a - b) / 2).len(), q[i].first, q[i].second))
        crossStart = 1, l = 0;
      else {
        double vl = 0, vr = 1e12;
        for (int it = 0; it < 100; it++) {
          double vm = (vl + vr) / (double)2;
          pt s2 = a + (b - a) / 2 + v.norm(vm);
          double r2 = sqrt(vm * vm + ((a - b) / 2).squareLen());
          if (in(q[i].first, q[i].second, s2, r2))
            vl = vm;
          else
            vr = vm;
        }
        l = vl;
      }
      double vl = 0, vr = 1e12;
      for (int it = 0; it < 100; it++) {
        double vm = (vl + vr) / (double)2;
        pt s2 = a + (b - a) / 2 + v.norm(vm);
        double r2 = sqrt(vm * vm + ((a - b) / 2).squareLen());
        if (cross(q[i].first, q[i].second, s2, r2) ||
            in(q[i].first, q[i].second, s2, r2))
          vl = vm;
        else
          vr = vm;
      }
      r = vr;
    }
    t.push_back(make_pair(l, -1));
    t.push_back(make_pair(r, 1));
  }
  sort(t.begin(), t.end());
  double val = 0;
  if (crossStart) {
    int bal = 0;
    for (int i = 0; i < t.size(); i++) {
      bal += t[i].second;
      if (bal == 0) {
        val = t[i].first;
        break;
      }
    }
  }
  return sqrt(val * val + ((a - b) / 2).squareLen());
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> a.x >> a.y >> b.x >> b.y >> n;
  for (int i = 0; i < n; i++)
    cin >> q[i].first.x >> q[i].first.y >> q[i].second;
  pt w = pt(-(a - b).y, (a - b).x);
  cout.precision(10);
  cout << fixed << (double)min(solve(w), solve(pt(0, 0) - w)) << endl;
}
