// Задача "Большие скачки"
// Шестая Интернет-олимпиада сезона 2009-2010, усложненный уровень
// Автор задачи: Федор Царев, tsarev@rain.ifmo.ru
// Автор решения: Сергей Поромов, poromov@rain.ifmo.ru

import java.io.*;
import java.util.*;

public class horseraces_sp implements Runnable {

	public static void main(String[] args) {
		new Thread(new horseraces_sp()).start();
	}

	public void run() {
		try {
			Locale.setDefault(Locale.US);
			br = new BufferedReader(new FileReader(FILENAME + ".in"));
			out = new PrintWriter(FILENAME + ".out");
			solve();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return "0";
			}
		}
		return st.nextToken();
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	void myAssert(boolean e, String s) {
		if (!e) {
			throw new Error("Assertion failure " + s);
		}
	}

	private static final String FILENAME = "horseraces";
	
	double eps = 1e-9;
	
	class Point implements Comparable<Point> {
		public Point(double x2, double y2) {
			x = x2;
			y = y2;
		}

		double x, y;

		@Override
		public int compareTo(Point p) {
			if (Math.abs(x - p.x) < eps) {
				if (y < p.y - eps) return -1;
				if (y > p.y + eps) return 1;
				return 0;
			}
			if (x < p.x) return -1;
			if (x > p.x) return 1;
			return 0;
		}
		
		double dist(Point p) {
			return Math.sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
		}
	}
	
	class Line {
		double a, b, c;
		
		Line(Point p1, Point p2) {
			a = p2.y - p1.y;
			b = p1.x - p2.x;
			double t = Math.sqrt(a * a + b * b);
			a /= t;
			b /= t;
			c = -a * p1.x - b * p1.y;
		}
		
		double dist(Point p) {
			return a * p.x + b * p.y + c;
		}
	}
	
	class Event extends Point {
		
		public Event(double x2, double y2) {
			super(x2, y2);
		}

		int type;
	}
	
	int MAXCoord = (int) 1e7;
	int MAXN = 100000;

	public void solve() {
		int x1 = nextInt();
		myAssert(Math.abs(x1) <= MAXCoord, "Wrond x1");
		int y1 = nextInt();
		myAssert(Math.abs(y1) <= MAXCoord, "Wrond y1");
		int x2 = nextInt();
		myAssert(Math.abs(x2) <= MAXCoord, "Wrond x2");
		int y2 = nextInt();
		myAssert(Math.abs(y2) <= MAXCoord, "Wrond y2");
		Point p1 = new Point(x1, y1);
		Point p2 = new Point(x2, y2);
		Line l = new Line(p1, p2);
		int n = nextInt();
		myAssert((1 <= n) && (n <= MAXN), "Wrong n");
		ArrayList<Event> al = new ArrayList<Event>();
		for (int i = 0; i < n; i++) {
			int x = nextInt();
			myAssert(Math.abs(x) <= MAXCoord, "Wrond x coord of circle number " + (i + 1));
			int y = nextInt();
			myAssert(Math.abs(y) <= MAXCoord, "Wrond y coord of circle number " + (i + 1));
			int r = nextInt();
			myAssert(Math.abs(r) <= MAXCoord, "Wrond radius of circle number " + (i + 1));
			Point c = new Point(x, y);
			double d = l.dist(c);
			if (Math.abs(d) < r) {
				double xx = x - l.a * d; 
				double yy = y - l.b * d;
				double rd = Math.sqrt(1.0 * r * r - d * d);
				Event e1 = new Event(xx + l.b * rd, yy - l.a * rd);
				Event e2 = new Event(xx - l.b * rd, yy + l.a * rd);
				if (e1.compareTo(e2) > 0) {
					Event te = e1;
					e1 = e2;
					e2 = te;
				}
				e1.type = 1;
				e2.type = -1;
				al.add(e1);
				al.add(e2);
			}
		}
		Collections.sort(al);
		double ans = 0;
		int h = 0;
		for (int i = 0; i < al.size() - 1; i++) {
			h += al.get(i).type;
			if (h > 0) {
				ans += al.get(i).dist(al.get(i + 1));
			}
		}
		out.println(ans);
	}
}
