#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;
}

Measured memory_bytes: 1348