#include <bits/stdc++.h>
using namespace std;
const long double INF = 1e12, epsilon = 1e-8;
long double Y_AXIS, res = INF;
vector<pair<long double, bool> > forbid;
inline long double sqr(long double x) { return x * x; }
inline long double dist(long double x1, long double y1, long double x2 = 0,
                        long double y2 = 0) {
  return sqr(x1 - x2) + sqr(y1 - y2);
}
inline long double area(long double x1, long double y1, long double x2,
                        long double y2, long double x3, long double y3) {
  return (x1 - x2) * (y1 - y3) - (x1 - x3) * (y1 - y2);
}
inline void mini(long double &a, long double b) {
  if (a > b) a = b;
}
long double binsearch(long double x, long double y, int r) {
  long double L = -INF, R = INF, mid;
  while (L + epsilon < R) {
    mid = (L + R) / 2;
    (sqrt(dist(x, y, mid)) + r < sqrt(dist(mid, Y_AXIS)) ^ x < 0 ? R : L) = mid;
  }
  return mid;
}
bool check_zero() {
  int cnt = 0;
  for (pair<long double, bool> info : forbid)
    if (abs(++cnt -= (info.first > 0 ^ info.second) << 1) > 1) return false;
  return true;
}
int main() {
  int x1, y1, x2, y2, n;
  scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &n);
  Y_AXIS = sqrt(dist(x1, y1, x2, y2)) / 2;
  for (int i = 0; i < n; ++i) {
    int x, y, r;
    scanf("%d%d%d", &x, &y, &r);
    long double xx = area(x, y, x1, y1, x2, y2) / Y_AXIS / 2;
    long double yy =
        sqrt(dist(x, y, (x1 + x2) / 2.0, (y1 + y2) / 2.0) - sqr(xx));
    forbid.push_back(make_pair(binsearch(xx, yy, r), xx > 0));
    forbid.push_back(make_pair(binsearch(xx, yy, -r), xx < 0));
  }
  if (check_zero()) {
    printf("%.9Lf", Y_AXIS);
    return 0;
  }
  sort(forbid.begin(), forbid.end());
  int cnt = 0;
  for (pair<long double, bool> info : forbid)
    if (info.second && !--cnt || !info.second && !cnt++)
      mini(res, sqrt(dist(info.first, Y_AXIS)));
  printf("%.9Lf", res);
  return 0;
}
