#include <bits/stdc++.h>
using namespace std;
struct Point {
  double x, y;
  Point(double x = 0, double y = 0) : x(x), y(y) {}
  Point operator+(Point b) { return Point(x + b.x, y + b.y); }
  Point operator-(Point b) { return Point(x - b.x, y - b.y); }
  double operator^(Point b) { return x * b.y - y * b.x; }
  Point operator*(double b) { return Point(x * b, y * b); }
  double operator*(Point b) { return x * b.x + y * b.y; }
  inline double dis() { return sqrt(*this * *this); }
};
struct tcurts {
  double r;
  int type;
  bool operator<(const tcurts &b) const { return r < b.r; }
} q[100010 * 2];
int main() {
  Point A, B, C;
  scanf("%lf%lf%lf%lf", &A.x, &A.y, &B.x, &B.y), C = (A + B) * 0.5;
  Point normal = (B - A) * (1 / (B - A).dis());
  normal = Point(-normal.y, normal.x);
  int n, top = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    Point p;
    double R;
    scanf("%lf%lf%lf", &p.x, &p.y, &R);
    int flag = ((p - A) ^ (B - A)) > 0;
    double l = -1e12, r = 1e12;
    for (int times = 1; times <= 80; times++) {
      double mid = (l + r) / 2;
      Point O = C + normal * mid;
      if ((O - A).dis() + R < (p - O).dis())
        (flag ? r : l) = mid;
      else
        (flag ? l : r) = mid;
    }
    q[++top] = (tcurts){l, flag ? -1 : 1}, l = -1e12, r = 1e12;
    for (int times = 1; times <= 80; times++) {
      double mid = (l + r) / 2;
      Point O = C + normal * mid;
      if ((O - A).dis() - R > (p - O).dis())
        (flag ? l : r) = mid;
      else
        (flag ? r : l) = mid;
    }
    q[++top] = (tcurts){l, flag ? 1 : -1};
  }
  q[++top] = (tcurts){-1e12, 0}, q[++top] = (tcurts){1e12, 0},
  q[++top] = (tcurts){0, 0}, sort(q + 1, q + top + 1);
  double res = 1e12;
  bool flag = false;
  for (int i = 1, s = 0; i <= top; i++) {
    if (!s) res = min(res, fabs(q[i].r)), flag = true;
    s += q[i].type;
    if (!s) res = min(res, fabs(q[i].r)), flag = true;
  }
  if (!flag)
    puts("-1");
  else
    printf("%.10lf\n", (C + normal * res - A).dis());
}
