#include <bits/stdc++.h>
using namespace std;
double x[100010], y[100010], r[100010];
pair<double, double> bound[100010];
double sqr(double x) { return x * x; }
int main() {
  double x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%lf%lf%lf", &x[i], &y[i], &r[i]);
  double mx = (x1 + x2) / 2, my = (y1 + y2) / 2;
  double p = sqrt(sqr(x1 - mx) + sqr(y1 - my));
  double a = x2 - mx, b = y2 - my;
  a /= p;
  b /= p;
  for (int i = 0; i < n; i++) {
    double lb = -(1e12), rb = (1e12), t, t1, t2;
    if (sqrt(rb * rb + p * p) + r[i] <=
        sqrt(sqr(mx + rb * b - x[i]) + sqr(my - rb * a - y[i]))) {
      while (rb - lb > 1e-7) {
        t = (lb + rb) / 2;
        if (sqrt(t * t + p * p) + r[i] <=
            sqrt(sqr(mx + t * b - x[i]) + sqr(my - t * a - y[i])))
          rb = t;
        else
          lb = t;
      }
      t2 = (lb + rb) / 2;
      lb = -(1e12);
      rb = (1e12);
      while (rb - lb > 1e-7) {
        t = (lb + rb) / 2;
        if (sqrt(t * t + p * p) - r[i] >=
            sqrt(sqr(mx + t * b - x[i]) + sqr(my - t * a - y[i])))
          lb = t;
        else
          rb = t;
      }
      t1 = (lb + rb) / 2;
    } else {
      while (rb - lb > 1e-7) {
        t = (lb + rb) / 2;
        if (sqrt(t * t + p * p) + r[i] <=
            sqrt(sqr(mx + t * b - x[i]) + sqr(my - t * a - y[i])))
          lb = t;
        else
          rb = t;
      }
      t1 = (lb + rb) / 2;
      lb = -(1e12);
      rb = (1e12);
      while (rb - lb > 1e-7) {
        t = (lb + rb) / 2;
        if (sqrt(t * t + p * p) - r[i] >=
            sqrt(sqr(mx + t * b - x[i]) + sqr(my - t * a - y[i])))
          rb = t;
        else
          lb = t;
      }
      t2 = (lb + rb) / 2;
    }
    bound[i] = pair<double, double>(t1, t2);
  }
  sort(bound, bound + n);
  double minabst = 1e13, forbid = -(1e12);
  for (int i = 0; i < n; i++) {
    double t1 = bound[i].first, t2 = bound[i].second;
    if (forbid <= 0 && t1 >= 0) {
      minabst = 0;
      break;
    }
    if (t2 <= forbid) continue;
    if (t1 >= forbid + 1e-8) minabst = min(min(minabst, abs(t1)), abs(forbid));
    forbid = max(t2, forbid);
  }
  minabst = min(minabst, abs(forbid));
  printf("%.10lf\n", sqrt(minabst * minabst + p * p));
}
