Problem: A crop circle suddenly appeared on the vast agricultural land of Argentina. A total of n crop circles were confirmed, including overlapping, popping, large, and small ones.

When a mystery hunter tried to capture the whole picture of a crop circle from the air, he found it difficult to show the beautiful pattern in the image because the outline of each circle was not clear.

Therefore, the mystery hunter proposed to emphasize the contour by installing a string of special material along the contour.

The part where the string is installed is the part on the circumference of one crop circle that is not included in any other crop circle.

The film crew asked you to create a program to measure the required string length. Enter the center coordinates and radius of each crop circle and create a program to report the length of the string to be installed.

For reference, the first and second cases of the input / output examples are shown in FIGS. 1 and 2, respectively. The part of the string is shown by a thick line.


<image>


Figure 1



<image>


Figure 2



Constraints

* n ≤ 100
* -1000 ≤ xi, yi ≤ 1000
* 0 <ri ≤ 100

Input

Multiple datasets are given as input. Each dataset is given in the following format:

n (number of crop circles: integer)
x1 y1 r1 (center coordinates and radius of the first circle: real numbers separated by blanks)
x2 y2 r2 (center coordinates and radius of the second circle: real numbers separated by blanks)
..
..
xn yn rn (center coordinates and radius of the nth circle: real numbers separated by blanks)


When n is 0, it indicates the end of input.

Output

Output the string length on one line for each dataset. The output may contain an error of 0.000001 or less.

Example

Input

4
6 4 2
4 7 3
7 10 3
13 6 1
4
7 4 2
4 7 3
7 10 3
11 6 3
0


Output

39.664699289572
45.627024663706

Solution (in CPP):

Solution:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

const double PI=acos(-1);

struct Point{
	double x,y;
	Point(){}
	Point(double x,double y):x(x),y(y){}
};
bool operator==(Point a,Point b){
	return abs(a.x-b.x)<EPS && abs(a.y-b.y)<EPS;
}
bool operator!=(Point a,Point b){
	return !(a==b);
}
Point operator+(Point a,Point b){
	return Point(a.x+b.x,a.y+b.y);
}
Point operator-(Point a,Point b){
	return Point(a.x-b.x,a.y-b.y);
}
Point operator*(double c,Point p){
	return Point(c*p.x,c*p.y);
}
Point operator/(Point p,double c){
	return Point(p.x/c,p.y/c);
}
double Abs(Point p){
	return sqrt(p.x*p.x+p.y*p.y);
}
double Abs2(Point p){
	return p.x*p.x+p.y*p.y;
}
double Arg(Point p){
	return atan2(p.y,p.x);
}
Point Rot(Point p,double t){
	return Point(cos(t)*p.x-sin(t)*p.y,sin(t)*p.x+cos(t)*p.y);
}

struct Circle{
	Point center;
	double radius;
	Circle(){}
	Circle(Point c,double r):center(c),radius(r){}
	Circle(double x,double y,double r):center(x,y),radius(r){}
};
bool operator==(Circle a,Circle b){
	return a.center==b.center && abs(a.radius-b.radius)<EPS;
}
bool operator!=(Circle a,Circle b){
	return !(a==b);
}

int CountInterCC(Circle c1,Circle c2){
	if(c1==c2)
		return INFTY;
	double r1=c1.radius,r2=c2.radius,d=Abs(c1.center-c2.center);
	if(d>r1+r2+EPS || d<abs(r1-r2)-EPS)
		return 0;
	if(abs(d-(r1+r2))<EPS || abs(d-abs(r1-r2))<EPS)
		return 1;
	return 2;
}

pair<Point,Point> InterCC(Circle c1,Circle c2){
	Point p1=c1.center,p2=c2.center;
	double r1=c1.radius,r2=c2.radius;
	
	double d=Abs(p1-p2);
	double a=(d*d+r1*r1-r2*r2)/(2*d);
	double s=sqrt(r1*r1-a*a);
	
	return mp(p1+a/d*(p2-p1)+s*Rot((p2-p1)/d,PI/2),
			  p1+a/d*(p2-p1)-s*Rot((p2-p1)/d,PI/2));
}

int main()
{
	for(int n;cin>>n,n;){
		vector<Circle> cs(n);
		rep(i,n) cin>>cs[i].center.x>>cs[i].center.y>>cs[i].radius;
		
		{
			vector<Circle> ts;
			rep(i,n){
				if(count(cs.begin(),cs.begin()+i,cs[i])) // 同じ円は最初の1個だけ
					continue;
				bool in=false;
				rep(j,n) if(cs[i]!=cs[j]){
					double d=Abs(cs[i].center-cs[j].center);
					if(d+cs[i].radius<cs[j].radius+EPS)
						in=true;
				}
				if(!in) ts.push_back(cs[i]);
			}
			swap(cs,ts);
			n=cs.size();
		}
		
		vector<vector<pdd> > as(n);
		double res=0;
		rep(i,n){
			rep(j,n) if(CountInterCC(cs[i],cs[j])==2){
				Point p1,p2; { pair<Point,Point> p=InterCC(cs[i],cs[j]); p1=p.first,p2=p.second; }
				double r1=Arg(p1-cs[i].center),r2=Arg(p2-cs[i].center);
				if(r1>r2) swap(p1,p2),swap(r1,r2);
				
				Point q=cs[i].center+Rot(Point(cs[i].radius,0),(r1+r2)/2);
				if(Abs(q-cs[j].center)<cs[j].radius-EPS)
					as[i].push_back(pdd(r1,r2));
				else{
					as[i].push_back(pdd(r2,PI));
					as[i].push_back(pdd(-PI,r1));
				}
			}
			sort(all(as[i]));
			double a=2*PI;
			double le=-PI,ri=-PI;
			rep(j,as[i].size()){
				le=max(le,as[i][j].first);
				ri=max(ri,as[i][j].second);
				a-=ri-le;
				le=ri;
			}
			res+=a*cs[i].radius;
		}
		printf("%.12f\n",res);
	}
	
	return 0;
}