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>

using namespace std;

#define NMAX 100

struct S1{
	int wx, wy, r;
};

/*点と円 true->点は円の内部*/
bool po_cr(int cx, int cy, int cr, int px, int py){
	return pow((cx - px), 2.0) + pow((cy - py), 2.0) <= pow(cr, 2.0);
}

/*円と線 true->接している*/
bool li_cr(int cx, int cy, int cr,int lx1, int ly1, int lx2, int ly2){

	double A, B, C, CA, AS, BS;
	double d;

	A = pow(cx - lx1, 2.0) + pow(cy - ly1, 2.0);
	B = pow(cx - lx2, 2.0) + pow(cy - ly2, 2.0);
	C = pow(lx1 - lx2, 2.0) + pow(ly1 - ly2, 2.0);
	CA = (lx2 - lx1) * (cy - ly1) - (cx - lx1) * (ly2 - ly1);
	AS = (cx - lx1) * (lx2 - lx1) + (cy - ly1) * (ly2 - ly1);
	BS = (cx - lx2) * (lx2 - lx1) + (cy - ly2) * (ly2 - ly1);

	if(C != 0) d = pow(CA, 2.0) / C;
	else d = 0;

	if(d <= pow(cr, 2.0)){
		if(AS * BS <= 0){
			return 1;
		}
		else if(pow(cr, 2.0) > A || pow(cr, 2.0) > B){
			return 1;
		}
	}
	return 0;
}

int main(){

	int n, m;
	S1 wall[NMAX];
	int tx, ty, sx, sy;
	bool f;

	while(1){

		cin >> n;
		if(n == 0) break;

		for(int i = 0; i < n; i++){
			cin >> wall[i].wx >> wall[i].wy >> wall[i].r;
		}

		cin >> m;

		for(int i = 0; i < m; i++){

			cin >> tx >> ty >> sx >> sy;

			f = true;
			for(int j = 0; j < n; j++){
				if(!po_cr(wall[j].wx, wall[j].wy, wall[j].r, sx, sy)){
					if(li_cr(wall[j].wx, wall[j].wy, wall[j].r, tx, ty, sx, sy)){
						f =  false;
					}
				}
				else if(!po_cr(wall[j].wx, wall[j].wy, wall[j].r, tx, ty)){
					f = false;
				}
			}

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

}

C++: #include <tuple>
#include <vector>
#include <complex>
#include <cstdio>
using namespace std;
typedef complex<double> P;
typedef tuple<double,double,double> tddd;
double dot(const P& a, const P& b) {
	return real(conj(a)*b);
}
int main(){
	int N,M;
	for(;scanf("%d",&N),N;){
		vector<tddd> v(N);
		for(int i=0;i<N;i++){
			double x,y,r;
			scanf("%lf%lf%lf",&x,&y,&r);
			v[i]=make_tuple(x,y,r);
		}
		for(scanf("%d",&M);M--;){
			double x1,y1,x2,y2;
			scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
			P A(x1,y1),B(x2,y2);
			double a=y2-y1;
			double b=-x2+x1;
			double c=-y1*b-x1*a;
			for(auto &e:v){
				double d=a*get<0>(e)+b*get<1>(e)+c;
				double x=sqrt(get<2>(e)*get<2>(e)*(a*a+b*b)-d*d);
				P X(get<0>(e) + (-a*d+b*x)/(a*a+b*b),get<1>(e) + (-b*d-a*x)/(a*a+b*b));
				P Y(get<0>(e) + (-a*d-b*x)/(a*a+b*b),get<1>(e) + (-b*d+a*x)/(a*a+b*b));
				if((dot(X-A,B-A)>0&&dot(X-B,A-B)>0) || (dot(Y-A,B-A)>0&&dot(Y-B,A-B)>0)){
					puts("Safe");
					goto NEXT;
				}
			}
			puts("Danger");
			NEXT:;
		}
	}
}