// Visualizer for Hadron problem
// author: Sergey Poromov

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.util.*;

import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;

public class Visualizer {
	private static int size = 1600;
	private static int border = 20;
	private static Color pointColor = Color.BLACK;
	private static int min = 0, max = 0;

	private static int getScreenCoord(double x) {
		return (int) ((size - 2 * border) * (x - min) / (max - min)) + border;
	}

	private static int getSize(double r) {
		return (int) ((size - 2 * border) * r / (max - min));
	}

	private static void drawCircle(double x, double y, double r, Graphics g) {
		int rr = getSize(r);
//		System.err.println(y);
		int xx = getScreenCoord(x) - rr;
		int yy = getScreenCoord(y) - rr;
//		System.err.println(xx + " " + yy);
		g.drawOval(xx, yy, 2 * rr, 2 * rr);
	}

	private static void drawLine(double x1, double y1, double x2, double y2,
			Graphics g) {
		int xx1 = getScreenCoord(x1);
		int yy1 = getScreenCoord(y1);
		int xx2 = getScreenCoord(x2);
		int yy2 = getScreenCoord(y2);
		g.drawLine(xx1, yy1, xx2, yy2);
	}

	public static void main(String[] args) throws IOException {
		Locale.setDefault(Locale.US);
		Scanner in = new Scanner(new FileReader(args[0]));
		int n = in.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		int[] r = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = in.nextInt();
			y[i] = -in.nextInt();
			r[i] = in.nextInt();
			min = Math.min(min, x[i] - r[i]);
			min = Math.min(min, y[i] - r[i]);
			max = Math.max(max, x[i] + r[i]);
			max = Math.max(max, y[i] + r[i]);
		}

		double xx = 0;
		double yy = 0;
		double rr = -1;
		if (new File(args[0] + ".a").exists()) {
			in = new Scanner(new FileReader(args[0] + ".a"));
			xx = in.nextDouble();
			yy = -in.nextDouble();
			rr = in.nextDouble();
			min = Math.min(min, (int) Math.floor(xx - rr));
			min = Math.min(min, (int) Math.floor(yy - rr));
			max = Math.max(max, (int) Math.ceil(xx + rr));
			max = Math.max(max, (int) Math.ceil(yy + rr));
		}

		if (args.length > 1) {
			in = new Scanner(new FileReader(args[1]));
			xx = in.nextDouble();
			yy = -in.nextDouble();
			rr = in.nextDouble();
			min = Math.min(min, (int) Math.floor(xx - rr));
			min = Math.min(min, (int) Math.floor(yy - rr));
			max = Math.max(max, (int) Math.ceil(xx + rr));
			max = Math.max(max, (int) Math.ceil(yy + rr));
		}

		BufferedImage img = new BufferedImage(size, size,
				BufferedImage.TYPE_INT_RGB);
		Graphics g = img.getGraphics();
		g.setColor(Color.WHITE);
		g.fillRect(0, 0, size, size);
		g.setPaintMode();
		g.setColor(pointColor);
		g.drawLine(getScreenCoord(0), getScreenCoord(min), getScreenCoord(0),
				getScreenCoord(max));
		g.drawLine(getScreenCoord(min), getScreenCoord(0), getScreenCoord(max),
				getScreenCoord(0));

		for (int i = 0; i < n; i++) {
			drawCircle(x[i], y[i], r[i], g);
		}

		if (rr >= 0) {
			g.setColor(Color.RED);
			drawCircle(xx, yy, rr, g);
		}

		while (in.hasNext()) {
			g.setColor(Color.ORANGE);
			drawLine(in.nextDouble(), -in.nextDouble(), in.nextDouble(), -in
					.nextDouble(), g);
		}

		ImageWriter iw = ImageIO.getImageWritersByFormatName("png").next();
		iw.setOutput(ImageIO
				.createImageOutputStream(new File(args[0] + ".png")));
		iw.write(img);
	}
}
