#include <bits/stdc++.h>
using namespace std;
struct Vector {
  long double x, y;
  Vector operator-(const Vector& ot) const { return {x - ot.x, y - ot.y}; }
};
struct Circle {
  Vector c;
  long double r;
};
vector<Circle> C;
long double ccw(Vector a, Vector b) { return a.x * b.y - b.x * a.y; }
long double dis(Vector a, Vector b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
int main() {
  Vector p1, p2, p3;
  scanf("%Lf %Lf %Lf %Lf", &p1.x, &p1.y, &p2.x, &p2.y);
  if (p1.x > p2.x) swap(p1, p2);
  p3 = {(p1.x + p2.x) / 2.0, (p1.y + p2.y) / 2.0};
  long double L = dis(p1, p3);
  int N;
  scanf("%d", &N);
  C.resize(N + 1);
  for (int i = 1; i <= N; i++) {
    scanf("%Lf %Lf %Lf", &C[i].c.x, &C[i].c.y, &C[i].r);
  }
  vector<pair<long double, long double> > bound(N + 1);
  Vector d = {(p2.x - p3.x) / L, (p2.y - p3.y) / L};
  for (int i = 1; i <= N; i++) {
    long double s, e, bs, be;
    if (ccw(p2 - p1, C[i].c - p1) >= 0) {
      s = -1e12, e = 1e12;
      for (int j = 1; j <= 100; j++) {
        long double m = (s + e) / 2.0;
        Vector p4 = {p3.x + d.y * m, p3.y - d.x * m};
        if (dis(p4, p2) + C[i].r <= dis(p4, C[i].c))
          e = m;
        else
          s = m;
      }
      be = s;
      s = -1e12, e = 1e12;
      for (int j = 1; j <= 100; j++) {
        long double m = (s + e) / 2.0;
        Vector p4 = {p3.x + d.y * m, p3.y - d.x * m};
        if (dis(p4, p2) - C[i].r >= dis(p4, C[i].c))
          s = m;
        else
          e = m;
      }
      bs = s;
    } else {
      s = -1e12, e = 1e12;
      for (int j = 1; j <= 100; j++) {
        long double m = (s + e) / 2.0;
        Vector p4 = {p3.x + d.y * m, p3.y - d.x * m};
        if (dis(p4, p2) + C[i].r <= dis(p4, C[i].c))
          s = m;
        else
          e = m;
      }
      bs = s;
      s = -1e12, e = 1e12;
      for (int j = 1; j <= 100; j++) {
        long double m = (s + e) / 2.0;
        Vector p4 = {p3.x + d.y * m, p3.y - d.x * m};
        if (dis(p4, p2) - C[i].r >= dis(p4, C[i].c))
          e = m;
        else
          s = m;
      }
      be = s;
    }
    bound[i] = {bs, be};
  }
  sort(bound.begin() + 1, bound.end());
  long double mn = 1e12, last = -1e12;
  for (int i = 1; i <= N; i++) {
    long double bs = bound[i].first, be = bound[i].second;
    if (last <= 0 && bs >= 0) {
      printf("%.10Lf", L);
      return 0;
    }
    if (be <= last) continue;
    if (bs >= last + 1e-9) mn = min({mn, abs(bs), abs(last)});
    last = max(last, be);
  }
  mn = min(mn, abs(last));
  printf("%.10Lf", sqrt(mn * mn + L * L));
  return 0;
}
