Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	x := make([]int, 100)
	y := make([]int, 100)
	r := make([]int, 100)
	for scanner.Scan() {
		a, _ := strconv.Atoi(scanner.Text())
		if a == 0 {
			break
		}
		for i := 0; i < a; i++ {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			tmpx, _ := strconv.Atoi(input[0])
			tmpy, _ := strconv.Atoi(input[1])
			tmpr, _ := strconv.Atoi(input[2])
			x[i], y[i], r[i] = tmpx, tmpy, tmpr
		}
		scanner.Scan()
		b, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < b; i++ {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			c, _ := strconv.Atoi(input[0])
			d, _ := strconv.Atoi(input[1])
			e, _ := strconv.Atoi(input[2])
			f, _ := strconv.Atoi(input[3])
			ok := false
			for j := 0; j < a; j++ {
				if (c-x[j])*(c-x[j])+(d-y[j])*(d-y[j]) >= r[j]*r[j] || (e-x[j])*(e-x[j])+(f-y[j])*(f-y[j]) >= r[j]*r[j] {
					if (e-c)*(x[j]-c)+(f-d)*(y[j]-d) < 0 {
						if (x[j]-c)*(x[j]-c)+(y[j]-d)*(y[j]-d) <= r[j]*r[j] {
							ok = true
						}
					} else {
						if (e-c)*(x[j]-c)+(f-d)*(y[j]-d)>(e-c)*(e-c)+(f-d)*(f-d) {
							if (x[j]-e)*(x[j]-e)+(y[j]-f)*(y[j]-f)<=r[j]*r[j] {
								ok = true
							}
						} else {
							if (x[j]-c)*(x[j]-c)+(y[j]-d)*(y[j]-d)-((e-c)*(x[j]-c)+(f-d)*(y[j]-d))*((e-c)*(x[j]-c)+(f-d)*(y[j]-d))/((e-c)*(e-c)+(f-d)*(f-d))<=r[j]*r[j] {
								ok = true
							}
						}
					}

				}
			}
			if ok {
				fmt.Println("Safe")
			} else {
				fmt.Println("Danger")
			}
		}
	}
}

C++: #include <iostream>
#include <cmath>
#include <complex>
using namespace std;

typedef complex<double> P;

#define EPS (1e-10)

double dot(P a,P b){
	return (a.real() * b.real() + a.imag() * b.imag());
}

double cross(P a,P b){
	return (a.real() * b.imag() - a.imag() * b.real());
}

double distance_ls_p(P a,P b,P c){
	if(dot(b-a,c-a) < EPS) return abs(c-a);
	if(dot(a-b,c-b) < EPS) return abs(c-b);
	return abs(cross(b-a,c-a)) / abs(b-a);
}

bool intersected(P a,P b,P o,double r){
	double ao = abs(a-o);
	double bo = abs(b-o);

	if( (ao < r + EPS && r < bo + EPS || r < ao + EPS && bo < r + EPS) ||
			(r < ao + EPS && r < bo + EPS && distance_ls_p(a,b,o) < r + EPS) )
		return true;

	return false;
}

int main(void){
	int n,m;

	while(cin>>n && n){
		P o[n];
		double r[n];

		for(int i=0;i<n;i++){
			cin>>o[i].real()>>o[i].imag()>>r[i];
		}

		cin>>m;
		while(m--){
			P taro,oni;
			cin>>taro.real()>>taro.imag()>>oni.real()>>oni.imag();

			bool flg = true;
			for(int i=0;i<n;i++){
				if(intersected(taro,oni,o[i],r[i])){
					flg = false;
					break;
				}
			}

			if(flg) cout<<"Danger\n";
			else cout<<"Safe\n";
		}
	}

	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

double const EPS = 1.0e-10;

class Point
{
public:
    double y, x;
    Point(){
        y = x = 0.0;
    }
    Point(double y0, double x0){
        y = y0;
        x = x0;
    }
    double dot(const Point& p) const{
        return y * p.y + x * p.x; // |a|*|b|*cosÆ
    }
    double cross(const Point& p) const{
        return x * p.y - y * p.x; // |a|*|b|*sinÆ
    }
    Point operator+(const Point& p) const{
        return Point(y + p.y, x + p.x);
    }
    Point operator-(const Point& p) const{
        return Point(y - p.y, x - p.x);
    }
    Point operator*(double a) const{
        return Point(y * a, x * a);
    }
    Point operator/(double a) const{
        return Point(y / a, x / a);
    }
};

class Line
{
public:
    double a, b, c; // a*x + b*y + c = 0
    Line(double a0, double b0, double c0){
        a = a0;
        b = b0;
        c = c0;
    }
    Line(const Point& p1, const Point& p2){
        double dy = p2.y - p1.y;
        double dx = p2.x - p1.x;
        if(abs(dy / dx) < EPS){
            a = 0.0;
            b = 1.0;
            c = -p1.y;
        }else if(abs(dx / dy) < EPS){
            a = 1.0;
            b = 0.0;
            c = -p1.x;
        }else{
            a = - dy / dx;
            b = 1.0;
            c = dy / dx * p1.x - p1.y;
        }
    }
};

int circleLineIntersection(const Point& p, double r, const Line& l, vector<Point>& intersection)
{
    double s = l.a * p.x + l.b * p.y + l.c;
    double t = (l.a*l.a + l.b*l.b) * r*r - s*s;

    if(t < -EPS){
        intersection.resize(0);
        return 0;
    }
    if(t < EPS){
        intersection.assign(1, Point(l.b, l.a) * (-s / (l.a*l.a + l.b*l.b)) + p);
        return 1;
    }

    intersection.assign(2, Point(l.a, -l.b) * sqrt(t));
    intersection[1] = intersection[1] * -1;
    for(int i=0; i<2; ++i)
        intersection[i] = (intersection[i] - Point(l.b, l.a) * s) / (l.a*l.a + l.b*l.b) + p;
    return 2;
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<Point> center(n);
        vector<double> r(n);
        for(int i=0; i<n; ++i)
            cin >> center[i].x >> center[i].y >> r[i];

        int m;
        cin >> m;

        while(--m >= 0){
            Point p1, p2;
            cin >> p1.x >> p1.y >> p2.x >> p2.y;
            Line l(p1, p2);

            bool safe = false;
            for(int i=0; i<n; ++i){
                vector<Point> p;
                circleLineIntersection(center[i], r[i], l, p);
                for(unsigned j=0; j<p.size(); ++j){
                    if(min(p1.y, p2.y) - EPS < p[j].y && p[j].y < max(p1.y, p2.y) + EPS
                           && min(p1.x, p2.x) - EPS < p[j].x && p[j].x < max(p1.x, p2.x) + EPS)
                        safe = true;
                }
            }

            if(safe)
                cout << "Safe" << endl;
            else
                cout << "Danger" << endl;
        }
    }
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <utility>
using namespace std;

#define EPS 1e-8
#define sqr(x) ((x)*(x))
#define fi first
#define se second

class circle {
	public:
		int x, y, r;
		circle(int x, int y, int r) {
			this->x = x;
			this->y = y;
			this->r = r;
		}

		bool is_cross(int x1, int y1, int x2, int y2) {
			pair<int,int> range;
			int x0 = x, y0 = y;
			if(x1 == x2 && y1 == y2) {
				return false;
			}
			if(x1 == x2) {
				swap(x1, y1);
				swap(x2, y2);
				swap(x0, y0);
			}

			range.fi = min(x1, x2);
			range.se = max(x1, x2);

			double a, b;
			a = (double)(y2 - y1) / (x2 - x1);
			b = y1 - a * x1;

			double d;
			d = sqr(x0 - a * (b - y0)) - (1 + sqr(a)) * (sqr(x0) + sqr(b - y0) - sqr(r));

			if(d < 0)
				return false;

			double z, zz;
			z  = (x0 - a * (b - y0) - sqrt(d)) / (1 + sqr(a));
			zz = (x0 - a * (b - y0) + sqrt(d)) / (1 + sqr(a));

			if((range.fi <= z && z <= range.se) || (range.fi <= zz && zz <= range.se))
				return true;
			return false;
		}
};

int main(void) {
	int n, m;
	vector<circle> v;

	cin >> n;
	for(int i = 0; i < n; i++) {
		int x, y, r;
		cin >> x >> y >> r;
		v.push_back(circle(x,y,r));
	}
	cin >> m;
	for(int i = 0; i < m; i++) {
		int x1, y1, x2, y2;
		bool flag = false;
		cin >> x1 >> y1 >> x2 >> y2;
		for(int j = 0; j < v.size(); j++) {
			if(v[j].is_cross(x1, y1, x2, y2))
				flag = true;
		}
		if(flag)
			cout << "Safe" << endl;
		else
			cout << "Danger" << endl;
	}

	return 0;
}