Problem:
Problem G:
Let There Be Light
Suppose that there are some light sources and many spherical balloons. All light sources have sizes small enough to be modeled as point light sources, and they emit light in all directions. The surfaces of the balloons absorb light and do not reflect light. Surprisingly in this world, balloons may overlap.
You want the total illumination intensity at an objective point as high as possible. For this purpose, some of the balloons obstructing lights can be removed. Because of the removal costs, however, there is a certain limit on the number of balloons to be removed. Thus, you would like to remove an appropriate set of balloons so as to maximize the illumination intensity at the objective point.
The following figure illustrates the configuration specified in the first dataset of the sample input given below. The figure shows the
xy
-plane, which is enough because, in this dataset, the
z
-coordinates of all the light sources, balloon centers, and the objective point are zero. In the figure, light sources are shown as stars and balloons as circles. The objective point is at the origin, and you may remove up to 4 balloons. In this case, the dashed circles in the figure correspond to the balloons to be removed.
Figure G.1: First dataset of the sample input.
Input
The input is a sequence of datasets. Each dataset is formatted as follows.
N M R
S
1
x
S
1
y
S
1
z
S
1
r
...
S
Nx
S
Ny
S
Nz
S
Nr
T
1
x
T
1
y
T
1
z
T
1
b
...
T
Mx
T
My
T
Mz
T
Mb
E
x
E
y
E
z
The first line of a dataset contains three positive integers,
N
,
M
and
R
, separated by a single space.
N
means the number of balloons that does not exceed 2000.
M
means the number of light sources that does not exceed 15.
R
means the number of balloons that may be removed, which does not exceed
N
.
Each of the
N
lines following the first line contains four integers separated by a single space. (
S
ix
,
S
iy
,
S
iz
) means the center position of the
i
-th balloon and
S
ir
means its radius.
Each of the following
M
lines contains four integers separated by a single space. (
T
jx
,
T
jy
,
T
jz
) means the position of the
j
-th light source and
T
jb
means its brightness.
The last line of a dataset contains three integers separated by a single space. (
E
x
,
E
y
,
E
z
) means the position of the objective point.
S
ix
,
S
iy
,
S
iz
,
T
jx
,
T
jy
,
T
jz
,
E
x
,
E
y
and
E
z
are greater than -500, and less than 500.
S
ir
is greater than 0, and less than 500.
T
jb
is greater than 0, and less than 80000.
At the objective point, the intensity of the light from the
j
-th light source is in inverse proportion to the square of the distance, namely
T
jb
/ { (
T
jx
−
E
x
)
2
+ (
T
jy
−
E
y
)
2
+ (
T
jz
−
E
z
)
2
},
if there is no balloon interrupting the light. The total illumination intensity is the sum of the above.
You may assume the following.
The distance between the objective point and any light source is not less than 1.
For every
i
and
j
, even if
S
ir
changes by ε (|ε| < 0.01), whether
...(truncated)

Submitted solutions:

code_snippet: #include <cstdio>
#include <set>
#include <cmath>
using namespace std;
struct Point
{
    double x;
    double y;
    double z;
    void read()
    {
        scanf("%lf %lf %lf",&x,&y,&z);
    }
    Point(double x=0,double y=0,double z=0):x(x),y(y),z(z){}
    Point operator +(const Point &ano)
    {
        return Point(x+ano.x,y+ano.y,z+ano.z);
    }
    Point operator -(const Point &ano)
    {
        return Point(x-ano.x,y-ano.y,z-ano.z);
    }
    Point operator *(double p)
    {
        return Point(x*p,y*p,z*p);
    }
    Point operator /(double p)
    {
        return Point(x/p,y/p,z/p);
    }
    void print()
    {
        printf("%f %f %f\n",x,y,z);
    }
}E;
struct S
{
    double x;
    double y;
    double z;
    double r;
    void read()
    {
        scanf("%lf %lf %lf %lf",&x,&y,&z,&r);
    }
    Point get()
    {
        return Point(x,y,z);
    }
}s[2100];
typedef Point Vector;
struct T
{
    double x;
    double y;
    double z;
    double b;
    void read()
    {
        scanf("%lf %lf %lf %lf",&x,&y,&z,&b);
    }
    Point get()
    {
        return Point(x,y,z);
    }
}t[20];
Vector Cross(Vector a,Vector b)
{
    return Vector(a.y*b.z - a.z*b.y,a.z*b.x -a.x * b.z,a.x*b.y-a.y*b.x);
}
const double eps=1e-3;
double Dot(Vector a,Vector b)
{
    return a.x*b.x + a.y*b.y +a.z *b.z;
}
double Length(Vector a)
{
    return sqrt(Dot(a,a));
}
double distanceToLine(Point p,Point a,Point b)
{
    Vector v1=b-a;
    Vector v2=p-a;
    return Length(Cross(v1,v2))/Length(v1);
}
int dcmp(double p)
{
    if(fabs(p)<eps)
    return 0;
    return p<0?-1:1;
}
bool Intersect(Point a,Point b,S s)
{
    int a1=dcmp(Length(a-s.get())-s.r);
    int a2=dcmp(Length(b-s.get())-s.r);
    if(a1 * a2<0)
        return true;
    if(a1<=0 && a2<=0)
        return false;
    double dis = distanceToLine(s.get(),a,b);
    if(dcmp(dis-s.r)>=0)
    return false;
    double d1=Length(b-s.get());
    double d2=Length(a-s.get());
    double x1=d1*d1-dis*dis;
    double x2=d2*d2-dis*dis;
    x1=sqrt(x1);
    x2=sqrt(x2);
    if(dcmp(x1+x2-Length(b-a))==0)
    return true;
    if(dcmp(fabs(x1-x2)-Length(b-a))==0)
    return false;
    1/0;
}
set<int> p[3000];
int main()
{
    int n,m,r;
    while(~scanf("%d %d %d",&n,&m,&r))
    {
        if(n+m+r==0)
        break;
        for(int i=0;i<n;i++)
        p[i].clear();
        for(int i=0;i<n;i++)
        s[i].read();
        for(int i=0;i<m;i++)
        t[i].read();
        E.read();
        for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
        {
            if(Intersect(t[j].get(),E,s[i]))
            p[i].insert(j);
        }
        double ans=0;
        for(int i=0;i<(1<<m);i++)
        {
            double sum=0;
            for(int j=0;j<m;j++)
            if(i&(1<<j))
            sum+=t[j].b/(Dot(t[j].get()-E,t[j].get()-E));
            if(sum<ans)
            continue;
            int t=0;
            for(int k=0;k<n;k++)
            for(int j=0;j<m;j++)
            {
                if(i&(1<<j) && p[k].count(j))
                {
                    t++;
                    break;
                }
            }
            if(t>r)
                    continue;
            if(sum>ans)
            ans=sum;
        }
        printf("%lf\n",ans);
    }
    return 0;
}
accuracy: 1
time_ms: 540
memory_kb: 3612
final_rank: 10

code_snippet: #include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const double eps = 1e-9;
struct point
{
    double x,y,z;
    //不吃參數的建構子跟吃參數的建構子QQ
    point():x(0),y(0),z(0){}
    point(double _x,double _y,double _z):x(_x),y(_y),z(_z){}

    point operator+(const point &p) const{ return point(x+p.x, y+p.y, z+p.z);}
    point operator-(const point &p) const{ return point(x-p.x, y-p.y, z-p.z);}
    point operator*(const double &d) const{ return point(x*d, y*d, z*d);}
    point operator/(const double &d) const{ return point(x/d, y/d, z/d);}
};
struct sphere
{
    point p;
    double r;
    sphere(point _p,double _r):p(_p),r(_r){}
};
struct line
{
    point a,b;
    line(point _a,point _b):a(_a),b(_b){}
};

int n,m,r;
point obj;//objective point ;
vector <sphere> bal;
vector <point> light;
double bright[16];  //brightness
vector <int> rmv[16]; //rmv these balloons to get the light

point start(0.0,0.0,0.0);
double length2(point a,point b)
{
    double ans=(a.x-b.x)*(a.x-b.x);
    ans+=(a.y-b.y)*(a.y-b.y);
    ans+=(a.z-b.z)*(a.z-b.z);
    return ans;
}
/*
inline double norm(const point &a){ return a.x*a.x+a.y*a.y+a.z*a.z;}
inline double abs(const point &a){ return sqrt(norm(a));}
inline double dot(const point &a, const point &b){ return a.x*b.x+a.y*b.y+a.z*b.z;}
point proj(const line &l, const point &p){
    double t = dot(p-l.a, l.a-l.b) / norm(l.a-l.b);
    return l.a+(l.a-l.b)*t;
}
bool corss(const line &l, const sphere &s){
    point a = l.a-s.p, b = l.b-s.p, c = proj(l,s.p)-s.p;
    if(abs(a) < s.r-eps and abs(b) < s.r-eps and abs(c) < s.r-eps)
	{
		return 0; // contain
	}
    if(abs(c) > s.r+eps) return 0; // far
    if(abs(a) < s.r-eps or abs(b) < s.r-eps) return 1; // intersect
    if(abs(a-c)+abs(b-c)<abs(a-b)+eps) return 1; // intersect
    return 0;
}
*/
//12312312313
double abs(point a)
{
	return sqrt(length2(a,start));
}

bool corss(line ln,sphere sph)
{
	point a=ln.a;
	point b=ln.b;
	bool flag1=0,flag2=0;
	if(sqrt(length2(a,sph.p))<sph.r-eps) flag1=1;
	if(sqrt(length2(b,sph.p))<sph.r-eps) flag2=1;
	if(flag1&&flag2)
	{
		return 0;
		//printf("A");
	}
	else if(flag1||flag2) return 1;
	//now to consider two point are outside of the sphere
	// ( ap X ab ) / length(ab)   = lenth(line,sphere)
	point ap(sph.p.x-a.x,sph.p.y-a.y,sph.p.z-a.z);
	point ab(b.x-a.x,b.y-a.y,b.z-a.z);
	point ba(a.x-b.x,a.y-b.y,a.z-b.z);
	point tmp(ap.y*ab.z-ap.z*ab.y,ap.z*ab.x-ap.x*ab.z,ap.x*ab.y-ap.y*ab.x);
	
	double len1=sqrt(tmp.x*tmp.x+tmp.y*tmp.y+tmp.z*tmp.z);
	double len2=sqrt(length2(a,b));
	if((len1/len2)>(sph.r-eps)) return 0;
	else
	{
		point bp(sph.p.x-b.x,sph.p.y-b.y,sph.p.z-b.z);
		// ap． bp <0   return 1;
		//there're still some details to consider
		//printf("%lf\n",(ap.x*bp.x)+(ap.y*bp.y)+(ap.z*bp.z));
		if((ap.x*bp.x)+(ap.y*bp.y)+(ap.z*bp.z)<0.0) return 1;
		if((ab.x*ap.x)+(ab.y*ap.y)+(ab.z*ap.z)<0.0) return 0;
		if((ba.x*bp.x)+(ba.y*bp.y)+(ba.z*bp.z)<0.0) return 0;
		return 1; 
	}
}
//1231321313223
void solve()
{
    int i,j,k;
    for(i=0;i<m;i++) rmv[i].clear();
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        {
            if(corss(line(light[i],obj),bal[j]))
			{
				rmv[i].push_back(j);
			}
        }
    }
    double ans=0.0;
    for(k=0;k<(1<<m);k++)
    {
       bool rmvv[2048]={};  //balloons<2000
       int cnt=0;
       double sum=0.0;
       for(i=0;i<m;i++)
       {
           if((k>>i)&1)
           {
               for(j=0;j<rmv[i].size();j++)
               {
                   if(!rmvv[rmv[i][j]]) //rmb[i][j] is the index of the balloon
                   {//if this balloon is not removed yet
                       rmvv[rmv[i][j]]=1;
                       cnt++;
                   }
               }
               sum+=bright[i]/length2(light[i],obj);
           }
       }
		
       if(cnt<=r) ans=max(ans,sum);
    }
    printf("%lf\n",ans);
}

bool input()
{
    scanf("%d %d %d",&n,&m,&r);
    if(n+m+r==0) return 0;

    int x,y,z,r;
    bal.clear();
    light.clear();
    for(int i=0;i<n;i++)
    {//eat the ballons
        scanf("%d %d %d %d",&x,&y,&z,&r);
        bal.push_back(sphere(point(x,y,z),r));
    }
    for(int i=0;i<m;i++)
    {//eat the light sources
        scanf("%d %d %d %d",&x,&y,&z,&r);
        light.push_back(point(x,y,z));
        bright[i]=r;
    }
    //eat the objective point
    scanf("%d %d %d",&x,&y,&z);
    obj=point(x,y,z);

    return 1;
}

int main()
{
    while(input()) solve();
    return 0;
}
accuracy: 1
time_ms: 1470
memory_kb: 3080
final_rank: 1

code_snippet: #include<bits/stdc++.h>
#define pb push_back
#define db double
using namespace std;
db sqr(db x){return x*x;}
struct B{
	db x, y, z, r;
};
struct L{
	db x, y, z, b;
	db val;
};
struct P{
	db x, y, z;
	P(db x, db y, db z):x(x), y(y), z(z){}
	P(B &bl):x(bl.x), y(bl.y), z(bl.z){}
	P(L &ls):x(ls.x), y(ls.y), z(ls.z){}
	P(){}
	db dis(P &p){return sqr(p.x-x)+sqr(p.y-y)+sqr(p.z-z);}
};
struct V{
	db x, y, z;
	V(){}
	V(P &p1, P &p2):x(p2.x-p1.x), y(p2.y-p1.y), z(p2.z-p1.z){}
	V(V &a, V &b):x(a.y*b.z-a.z*b.y), y(a.x*b.z-a.z*b.x), z(a.x*b.y-a.y*b.x){}
	db dot(V &v){return x*v.x+y*v.y+z*v.z;}
	db mod(){return x*x+y*y+z*z;}
};
db dis(P &p, P &p1, P &p2){
	V v1(p1, p), v2(p1, p2), v3(p2, p), v4(p2, p1), v5(v2, v1);
	if(v1.dot(v2)<0) return p.dis(p1);
	if(v3.dot(v4)<0) return p.dis(p2);
	return (db)v5.mod()/(db)v2.mod();
}
const int MAX_N=2e3+50, MAX_M=1000;
bool vis[MAX_N];
bool block[MAX_M][MAX_N];
B bl[MAX_N];
L ls[MAX_M];
int N, M, R;
P obj;
bool is_block(int i, int j){
	P a(ls[i]), b(bl[j]);
	if(b.dis(a)<sqr(bl[j].r)&&b.dis(obj)<sqr(bl[j].r)) return false;
	return dis(b, a, obj)<(db)sqr(bl[j].r);
}
bool ok(int x){
	int cnt=0;
	memset(vis, 0, sizeof(vis));
	for(int i=0; i<M; i++){
		if(!(x&1<<i)) continue;
		for(int j=0; j<N; j++)
			if(block[i][j]&&!vis[j]) vis[j]=true, cnt++;
		if(cnt>R) return false;
	}
	return true;
}
db calc(int x){
	db ans=0;
	for(int i=0; i<M; i++){
		if(!(x&1<<i)) continue;
		ans+=ls[i].val;
	}
	return ans;
}
void solve(){
	double ans=0;
	for(int i=0; i<(1<<M); i++){
		if(ok(i)) ans=max(ans, calc(i));
	}
	printf("%.9f\n", ans);
}
int main(){
	//freopen("in", "r", stdin);
	while(~scanf("%d%d%d", &N, &M, &R)){
		if(N||M||R){
			for(int i=0; i<N; i++)
				scanf("%lf%lf%lf%lf", &bl[i].x, &bl[i].y, &bl[i].z, &bl[i].r);
			for(int i=0; i<M; i++){
				scanf("%lf%lf%lf%lf", &ls[i].x, &ls[i].y, &ls[i].z, &ls[i].b);
			}
			scanf("%lf%lf%lf", &obj.x, &obj.y, &obj.z);
			for(int i=0; i<N; i++){
				P p(ls[i]);
				ls[i].val=(db)ls[i].b/(db)obj.dis(p);
			}
			for(int i=0; i<M; i++)
				for(int j=0; j<N; j++)
					block[i][j]=is_block(i, j);
			solve();
		}
	}
	return 0;
}
accuracy: 1
time_ms: 6490
memory_kb: 3664
final_rank: 19

code_snippet: #include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#define eps 1.0e-9
using namespace std;
int n,m;
double r[2333],w[20];
bool vis[555],g[20][555];
struct point
{
    double x,y,z;
}p[2333],q[20],e;
double sgn(double f)
{
    if(fabs(f)<eps) return 0;
    else return f<0?-1:1;
}
double dis(point a,point b) {return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z);}
int check(point p,point c,double r)
{
    int d=dis(p,c);
    if(d<r*r) return -1;
    else if(d==r*r) return 0;
         else return 1;
}
bool cal(double a,double b,double c)
{
    double delt=b*b-4*a*c;
    if(delt<=0) return false;
    else
    {
        delt=sqrt(delt);
        double x1=(-b+delt)/(2*a),x2=(-b-delt)/(2*a);
        if((sgn(x1)>0&&sgn(x1-1)<0)||(sgn(x2)>0&&sgn(x2-1)<0)) return true;
        else return false;
    }
}
void init()
{
    memset(g,0,sizeof(g));
    for(int i=0;i<m;i++)
    {
        if(e.x==q[i].x&&e.y==q[i].y&&e.z==q[i].z) continue;
        for(int j=0;j<n;j++)
        {
            int a=check(e,p[j],r[j]),b=check(q[i],p[j],r[j]);
            //if(a==0||b==0) continue;
            double ka,kb,kc;
            ka=dis(e,q[i]);
            kb=2*((e.x-p[j].x)*(q[i].x-e.x)+(e.y-p[j].y)*(q[i].y-e.y)+(e.z-p[j].z)*(q[i].z-e.z));
            kc=dis(e,p[j])-r[j]*r[j];
            if(cal(ka,kb,kc)) g[i][j]=1;
        }
    }
}
int main()
{
    int N;
    while(scanf("%d%d%d",&n,&m,&N)==3)
    {
        if(n==0&&m==0&&N==0) break;
        for(int i=0;i<n;i++) scanf("%lf%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z,&r[i]);
        for(int i=0;i<m;i++) scanf("%lf%lf%lf%lf",&q[i].x,&q[i].y,&q[i].z,&w[i]);
        scanf("%lf%lf%lf",&e.x,&e.y,&e.z);
        init();
        int M=1<<m;
        double ans=0,tb[20];
        for(int i=0;i<m;i++) tb[i]=w[i]/dis(e,q[i]);
        for(int i=1;i<M;i++)
        {
            memset(vis,0,sizeof(vis));
            int cnt=0;
            bool ok=true;
            double tp=0;
            for(int j=0;j<m;j++)
            {
                if((i&(1<<j))==0) continue;
                for(int k=0;k<n;k++)
                {
                    if(vis[k]) continue;
                    if(g[j][k])
                    {
                        vis[k]=true;
                        cnt++;
                        if(cnt>N)
                        {
                            ok=false;
                            break;
                        }
                    }
                }
                if(!ok) break;
                tp+=tb[j];
            }
            if(ok) ans=max(ans,tp);
        }
        printf("%.10f\n",ans);
    }
    return 0;
}
accuracy: 1
time_ms: 5360
memory_kb: 3404
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
struct vec {
	T x, y, z;
	vec(const T &x, const T &y, const T &z) : x(x), y(y), z(z) {}
	vec() : x(0), y(0), z(0) {}
	vec operator-(const vec &rhs) const {
		return {x - rhs.x, y - rhs.y, z - rhs.z};
	}
	vec<ld> operator/(const ld &rhs) const {
		return {x / rhs, y / rhs, z / rhs};
	}
	vec operator*(const ld &rhs) const {
		return {x * rhs, y * rhs, z * rhs};
	}
	vec<ld> unit() const { return (*this) / (*this).norm(); }
	T norm2() const { return x * x + y * y + z * z; }
	ld norm() const { return sqrtl((*this).norm2()); }
	T dot(const vec &rhs) const { return x * rhs.x + y * rhs.y + z * rhs.z; }
	// vec cross(vec rhs) const { return {y * rhs.z - z * rhs.y, z * rhs.x - x * rhs.z, x * rhs.y - y * rhs.x}; }
};
struct sph {
	vec<int> p;
	int r;
};
bool isBlock(const vec<int> &from, const vec<int> &to, const sph &s) {
	auto isIn = [&](const vec<int> &p) {
		return (s.p - p).norm2() <= s.r * s.r;
	};
	if (isIn(from) && isIn(to)) return false;
	if (isIn(from) ^ isIn(to)) return true;
	vec<int> dif = to - from;
	vec<int> v = s.p - from;
	if (dif.dot(v) < 0 || (from - to).dot(s.p - to) < 0) return false;
	auto convd = [&](const vec<int> &v) {
		return vec<ld>(v.x, v.y, v.z);
	};
	vec<ld> uni = dif.unit();
	vec<ld> shaw = uni * (uni.dot(convd(v)));
	if ((convd(v) - shaw).norm2() <= s.r * s.r) {
		return true;
	} else {
		return false;
	}
}
int main() {
	while (1) {
		int n, m, r;
		scanf("%d%d%d", &n, &m, &r);
		if (n == 0 && m == 0 && r == 0) break;
		// printf("%d %d %d\n", n, m, r);
		vector<sph> s(n);
		for (int i = 0; i < n; i++) {
			scanf("%d %d %d %d", &s[i].p.x, &s[i].p.y, &s[i].p.z, &s[i].r);
		}
		vector<vec<int>> lightp(m);
		vector<int> bright(m);
		for (int i = 0; i < m; i++) {
			scanf("%d %d %d %d", &lightp[i].x, &lightp[i].y, &lightp[i].z, &bright[i]);
		}
		vec<int> pto;
		scanf("%d %d %d", &pto.x, &pto.y, &pto.z);
		// cerr << "ok" << endl;
		ld ans = 0;
		const int M = 2010;
		vector<bitset<M>> isBlkb(m);
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				if (isBlock(lightp[i], pto, s[j])) {
					isBlkb[i].set(j, 1);
				}
			}
		}
		for (int bit = 0; bit < (1 << m); bit++) {
			bitset<M> dels;
			int cnt = 0;
			ld tot = 0;
			for (int i = 0; i < m; i++) {
				if ((bit >> i) & 1) {
					tot += (ld)bright[i] / (lightp[i] - pto).norm2();
					dels |= isBlkb[i];
				}
			}
			if (dels.count() > r) continue;
			// cerr << "bit: " << bit << endl;
			// cerr << "tot: " << tot << endl;
			ans = max(ans, tot);
		}
		printf("%.10Lf\n", ans);
	}
	return 0;
}
accuracy: 1
time_ms: 270
memory_kb: 3292
final_rank: 3

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

bool solve(){
	int N, M, R;
	cin >> N >> M >> R;

	if(N == 0 && M == 0 && R == 0) return false;

	vector<tuple<ll, ll, ll, ll>> S(N), T(M);
	for(auto&[x, y, z, r] : S) cin >> x >> y >> z >> r;
	for(auto&[x, y, z, r] : T) cin >> x >> y >> z >> r;
	ll X, Y, Z; cin >> X >> Y >> Z;

	for(auto&[x, y, z, r] : S) x -= X, y -= Y, z -= Z;
	for(auto&[x, y, z, r] : T) x -= X, y -= Y, z -= Z;

	auto judge = [&](int bl, int li){
		auto[xb, yb, zb, rb] = S[bl];
		auto[xl, yl, zl, rl] = T[li];

		bool both_outside = false;
		//両方内側
		{
			ll dist1 = (xb-xl)*(xb-xl) + (yb-yl)*(yb-yl) + (zb-zl)*(zb-zl);
			ll dist2 = xb*xb + yb*yb + zb*zb;
			if(dist1 <= rb*rb && dist2 <= rb*rb) return true;
			if(dist1 >= rb*rb && dist2 >= rb*rb) both_outside = true;
		}

		//内外が違う
		if(!both_outside) return false;

		//B:ライト, A:風船
		ll A = xb*xb + yb*yb + zb*zb;
		ll B = xl*xl + yl*yl + zl*zl;
		ll dot = xb*xl + yb*yl + zb*zl;
		ll r = rb*rb;
		//風船がライトとの直線に干渉しない
		if(r*B <= A*B-dot*dot) return true;

		//ライトと風船が反対側
		if(dot<0) return true;

		return B<=A;
	};

	vector<vector<int>> rem(M);
	for(int i = 0; i < M; i++){
		for(int j = 0; j < N; j++){
			if(!judge(j, i)) rem[i].push_back(j);
		}
	}

	/*for(int i = 0; i < M; i++){
		cout << "rem" << i+1 << ' ';
		for(int j : rem[i]) cout << j+1 << ' ';
		cout << endl;
	}*/

	double ans = 0;
	for(int bt = 0; bt < 1<<M; bt++){
		vector<bool> removed(N, false);
		double res = 0;
		for(int i = 0; i < M; i++){
			if(bt >> i & 1){
				for(int j : rem[i]) removed[j] = true;
				auto[xl, yl, zl, rl] = T[i];
				double val = 1.0*rl / (xl*xl + yl*yl + zl*zl);
				res += val;
			}
		}
		int cnt = 0;
		for(int i = 0; i < N; i++) if(removed[i]) cnt++;
		//cout << "cnt:" << cnt << endl;
		if(cnt <= R) ans = max(ans, res);
	}

	printf("%.10lf\n", ans);
	return true;
}

int main(){
	while(solve());
}
accuracy: 1
time_ms: 1450
memory_kb: 3536
final_rank: 11

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

struct Balloon {
    ll X, Y, Z, R;
    Balloon(ll x, ll y, ll z, ll r) : X(x), Y(y), Z(z), R(r) {};
};

struct Light {
    ll X, Y, Z, B;
    Light(ll x, ll y, ll z, ll b) : X(x), Y(y), Z(z), B(b) {};
};

bool isin(Balloon S, ll X, ll Y, ll Z) {
    return ((X-S.X)*(X-S.X)+(Y-S.Y)*(Y-S.Y)+(Z-S.Z)*(Z-S.Z) < S.R*S.R);
}

ll Dot(ll X1, ll Y1, ll Z1, ll X2, ll Y2, ll Z2) {
    return X1*X2+Y1*Y2+Z1*Z2;
}

int isCross(Balloon S, Light T) {
    if (isin(S,T.X,T.Y,T.Z) && isin(S,0,0,0)) return false;
    if (isin(S,T.X,T.Y,T.Z) && !isin(S,0,0,0)) return true;
    if (!isin(S,T.X,T.Y,T.Z) && isin(S,0,0,0)) return true;
    if (Dot(S.X,S.Y,S.Z,T.X,T.Y,T.Z) <= 0) return false;
    if (Dot(S.X-T.X,S.Y-T.Y,S.Z-T.Z,-T.X,-T.Y,-T.Z) <= 0) return false;
    return (S.Y*T.Z-S.Z*T.Y)*(S.Y*T.Z-S.Z*T.Y)+
           (S.Z*T.X-S.X*T.Z)*(S.Z*T.X-S.X*T.Z)+
           (S.X*T.Y-S.Y*T.X)*(S.X*T.Y-S.Y*T.X) <= S.R * S.R * (T.X*T.X+T.Y*T.Y+T.Z*T.Z);
}

int main() {
    while(1) {
    int N, M, K;
    cin >> N >> M >> K;
    if (N == 0) return 0;
    vector<Balloon> S;
    vector<Light> T;
    rep(i,0,N) {
        ll x, y, z, r;
        cin >> x >> y >> z >> r;
        S.push_back(Balloon(x,y,z,r));
    }
    rep(i,0,M) {
        ll x, y, z, b;
        cin >> x >> y >> z >> b;
        T.push_back(Light(x,y,z,b));
    }
    ll EX, EY, EZ;
    cin >> EX >> EY >> EZ;
    rep(i,0,N) S[i].X -= EX, S[i].Y -= EY, S[i].Z -= EZ;
    rep(i,0,M) T[i].X -= EX, T[i].Y -= EY, T[i].Z -= EZ;
    vector<bitset<2000>> C(M);
    rep(i,0,N) {
        rep(j,0,M) {
            if(isCross(S[i],T[j])) C[j].set(i,1);
        }
    }
    double ANS = 0.0;
    rep(i,0,1<<M) {
        double SUM = 0.0;
        bitset<2000> B;
        rep(j,0,M) {
            if (i&(1<<j)) {
                SUM += (double)T[j].B / (double)(T[j].X*T[j].X+T[j].Y*T[j].Y+T[j].Z*T[j].Z);
                B |= C[j];
            }
        }
        if (B.count() <= K) chmax(ANS,SUM);
    }
    printf("%.12f\n",ANS);
}
}
accuracy: 1
time_ms: 260
memory_kb: 3608
final_rank: 8

code_snippet: #line 2 "cp-library/src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull  = unsigned long long;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template < class T, class U > T ceil (T x, U y) { return (x > 0 ? (x + y - 1) / y :           x / y); }
template < class T, class U > T floor(T x, U y) { return (x > 0 ?           x / y : (x - y + 1) / y); }
int popcnt(i32 x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }

#line 2 "cp-library/src/utility/rep_itr.hpp"
template < class T > struct itr_rep {
    T i, d;
    constexpr itr_rep(const T i) noexcept : i(i), d(1) {}
    constexpr itr_rep(const T i, const T d) noexcept : i(i), d(d) {}
    void operator++() noexcept { i += d; }
    constexpr int operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr_rep x) const noexcept { return d > 0 ? i < x.i : i > x.i; }
};

template < class T > struct rep {
    const itr_rep< T > s, t;
    constexpr rep(const T t) noexcept : s(0), t(t) {}
    constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
    constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};

template < class T > struct revrep {
    const itr_rep < T > s, t;
    constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
    constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
    constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};
#line 3 "cp-library/src/utility/io.hpp"

/* 128bit integer */
istream& operator>>(istream& is, i128& x) {
    std::string s; is >> s;
    int pm = (s[0] == '-');
    x = 0;
    for(int i : rep(pm, int(s.size()))) x = x * 10 + (s[i] - '0');
    if(pm) x *= -1;
    return is;
}
ostream& operator<<(ostream& os, const i128& x) {
    if(x == 0) return os << '0';
    i128 y = x;
    if(y < 0) { os << '-'; y *= -1; }
    std::vector<int> ny;
    while(y > 0) { ny.push_back(y % 10); y /= 10; }
    for(int i : revrep(ny.size())) os << ny[i];
    return os;
}

template < class S, class T > istream& operator>>(istream& is,       std::pair< S, T >& x) { is >> x.first        >> x.second; return is; }
template < class S, class T > ostream& operator<<(ostream& os, const std::pair< S, T >& x) { os << x.first << " " << x.second; return os; }

namespace scanner {
    struct sca {
        template < class T > operator T() {
            T s; std::cin >> s; return s;
        }
    };
    struct vec {
        int n;
        vec(int n) : n(n) {}
        template < class T > operator std::vector< T >() {
            std::vector< T > v(n);
            for(T& x : v) std::cin >> x;
            return v;
        }
    };
    struct mat {
        int h, w;
        mat(int h, int w) : h(h), w(w) {}
        template < class T > operator std::vector< std::vector< T > >() {
            std::vector m(h, std::vector< T >(w));
            for(std::vector< T >& v : m) for(T& x : v) std::cin >> x;
            return m;
        }
    };
    struct speedup {
        speedup() {
            std::cin.tie(0);
            std::ios::sync_with_stdio(0);
        }
    } speedup_instance;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }

namespace printer {
    void precision(int d) { std::cout << std::fixed << std::setprecision(d); }
    void flush() { std::cout.flush(); }
}

template < class T >
ostream& operator<<(ostream& os, const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) { os << a[i]; if(i != n - 1) os << ' '; }
    return os;
}

int print() { std::cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
    std::cout << h; if(sizeof...(tail)) std::cout << ' ';
    return print(std::forward<tail>(t)...);
}
template < class T > int print_n(const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) std::cout << a[i] << "\n";
    return 0;
}


#line 2 "cp-library/src/utility/key_val.hpp"

template < class K, class V >
struct key_val {
    K key; V val;
    key_val() {}
    key_val(K key, V val) : key(key), val(val) {}
    template < std::size_t Index >
    std::tuple_element_t< Index, key_val >& get() {
        if constexpr (Index == 0) return key;
        if constexpr (Index == 1) return val;
    }
};

namespace std {

template < class K, class V > struct tuple_size < key_val< K, V > > : integral_constant< size_t, 2 > {};
template < class K, class V > struct tuple_element < 0, key_val< K, V > > { using type = K; };
template < class K, class V > struct tuple_element < 1, key_val< K, V > > { using type = V; };

}
#line 2 "cp-library/src/utility/vec_op.hpp"
template < class T > key_val< int, T > max_of(const vector< T >& a) {
    int i = std::max_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class T > key_val< int, T > min_of(const vector< T >& a) {
    int i = std::min_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class S, class T > S sum_of(const vector< T >& a) {
    S sum = 0;
    for(const T x : a) sum += x;
    return sum;
}
template < class S, class T > vector< S > freq_of(const vector< T >& a, T L, T R) {
    vector< S > res(R - L, S(0));
    for(const T x : a) res[x - L] += 1;
    return res;
}
template < class S, class T > struct prefix_sum {
    vector< S > s;
    prefix_sum(const vector< T >& a) : s(a) {
        s.insert(s.begin(), S(0));
        for(int i : rep(a.size())) s[i + 1] += s[i];
    }
    // [L, R)
    S sum(int L, int R) { return s[R] - s[L]; }
};
#line 3 "cp-library/src/utility/heap.hpp"

template < class T > using heap_min = std::priority_queue< T, std::vector< T >, std::greater< T > >;
template < class T > using heap_max = std::priority_queue< T, std::vector< T >, std::less< T > >;

#line 27 "cp-library/src/cp-template.hpp"

#line 1 "cp-library/src/algorithm/bin_search.hpp"
template < class T, class F >
T bin_search(T ok, T ng, F f) {
    while(abs(ng - ok) > 1) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

template < class T, class F >
T bin_search_real(T ok, T ng, F f, int step = 80) {
    while(step--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
#line 2 "cp-library/src/algorithm/argsort.hpp"

template < class T > std::vector< int > argsort(const std::vector< T > &a) {
    std::vector< int > ids((int)a.size());
    std::iota(ids.begin(), ids.end(), 0);
    std::sort(ids.begin(), ids.end(), [&](int i, int j) {
        return a[i] < a[j] || (a[i] == a[j] && i < j);
    });
    return ids;
}
#line 1 "macro.hpp"
namespace macro {

using size_type = int;
template < class container > void  sort(container& a) { std::sort(std:: begin(a), std:: end(a)); }
template < class container > void rsort(container& a) { std::sort(std::rbegin(a), std::rend(a)); }
template < class container > void reverse(container& a) { std::reverse(std::begin(a), std::end(a)); }
template < class container > void unique(container& a) {
    std::sort(std::begin(a), std::end(a));
    a.erase(std::unique(std::begin(a), std::end(a)), std::end(a));
}
template < class container > container  sorted(const container& a) { container b = a;  sort(b); return std::move(b); }
template < class container > container rsorted(const container& a) { container b = a; rsort(b); return std::move(b); }
template < class container, class compare > void sort(container& a, const compare& cmp) { std::sort(std::begin(a), std::end(a), cmp); }
template < class container, class compare > container sorted(const container& a, const compare& cmp) { container b = a; sort(b, cmp); return std::move(b); }
template < class container, class value > size_type lower_bound(const container& a, const value& x) { return std::lower_bound(std::begin(a), std::end(a), x) - std::begin(a); }
template < class container, class value > size_type upper_bound(const container& a, const value& x) { return std::upper_bound(std::begin(a), std::end(a), x) - std::begin(a); }

const std::vector<std::pair<size_type, size_type>> dir4 = { {+1,  0}, {-1,  0}, { 0, +1}, { 0, -1} };
const std::vector<std::pair<size_type, size_type>> dir8 = { {-1, -1}, {-1,  0}, {-1, +1}, { 0, -1}, { 0, +1}, {+1, -1}, {+1,  0}, {+1, +1} };

#ifdef _DEBUG
#define debug(x) std::cout << "[" << __LINE__ << "] " << #x << ": " << x << std::endl
#else
#define debug(x)
#endif

template < class container > void concat(container& a, const container& b) {
    a.insert(std::end(a), std::begin(b), std::end(b));
}
std::vector<size_type> iota(const size_type n) {
    std::vector<size_type> I(n);
    std::iota(std::begin(I), std::end(I), 0);
    return I;
}
template < class container > std::vector<size_type> sort_idx(const container& a) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return a[i] < a[j] or (a[i] == a[j] and i < j); });
    return I;
}
template < class container, class compare > std::vector<size_type> sort_idx(const container& a, const compare& cmp) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return cmp(a[i], a[j]) or (a[i] == a[j] and i < j); });
    return std::move(I);
}

struct grid {
    using size_type = int;
    size_type H, W;
    grid(const size_type H, const size_type W) : H(H), W(W) {}
    bool contains(const size_type i, const size_type j) {
        return 0 <= i and i < H and 0 <= j and j < W;
    }
};

using f64 = long double;

} // namespace macro

using namespace macro;
#line 3 "A.cpp"


#define EPS (1e-7)
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point3d {
  public:
    double x, y, z;

    Point3d(double x = 0, double y = 0, double z = 0) : x(x), y(y), z(z) {}

    Point3d operator+(const Point3d& a) {
        return Point3d(x + a.x, y + a.y, z + a.z);
    }
    Point3d operator-(const Point3d& a) {
        return Point3d(x - a.x, y - a.y, z - a.z);
    }
    Point3d operator*(const double& d) {
        return Point3d(x * d, y * d, z * d);
    }
    Point3d operator/(const double& d) {
        return Point3d(x / d, y / d, z / d);
    }

    bool operator<(const Point3d& p) const {
        if (!equals(x, p.x)) return x < p.x;
        if (!equals(y, p.y)) return y < p.y;
        if (!equals(z, p.z)) return z < p.z;
        return false;
    }

    bool operator==(const Point3d& p) const {
        return equals(x, p.x) && equals(y, p.y) && equals(z, p.z);
    }
};

struct Segment3d {
    Point3d p[2];
    Segment3d(Point3d p1 = Point3d(), Point3d p2 = Point3d()) {
        p[0] = p1, p[1] = p2;
    }
    bool operator==(const Segment3d& seg) const {
        return (p[0] == seg.p[0] && p[1] == seg.p[1]) || (p[0] == seg.p[1] && p[1] == seg.p[0]);
    }
};

using Line3d = Segment3d;
using Vector3d = Point3d;

ostream& operator<<(ostream& os, const Point3d& p) {
    return os << "(" << p.x << "," << p.y << "," << p.z << ")";
}

ostream& operator<<(ostream& os, const Segment3d& seg) {
    return os << "(" << seg.p[0] << "," << seg.p[1] << ")";
}

double dot(const Point3d& a, const Point3d& b) {
    return a.x * b.x + a.y * b.y + a.z * b.z;
}

Vector3d cross(const Point3d& a, const Point3d& b) {
    return Vector3d(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
}

inline double norm(const Point3d& p) {
    return p.x * p.x + p.y * p.y + p.z * p.z;
}

inline double abs(const Point3d& p) {
    return sqrt(norm(p));
}

inline double toRad(double theta) {
    return theta * M_PI / 180.0;
}

double distanceLP(Line3d line, Point3d p) {
    return abs(cross(line.p[1] - line.p[0], p - line.p[0])) / abs(line.p[1] - line.p[0]);
}

Point3d project(Segment3d seg, Point3d p) {
    Vector3d base = seg.p[1] - seg.p[0];
    double t = dot(p - seg.p[0], base) / norm(base);
    return seg.p[0] + base * t;
}

Point3d reflect(Segment3d seg, Point3d p) {
    return p + (project(seg, p) - p) * 2.0;
}

bool on_line3d(Line3d line, Point3d p) {
    return equals(abs(cross(line.p[1] - p, line.p[0] - p)), 0);
}

bool on_segment3d(Segment3d seg, Point3d p) {
    if (!on_line3d(seg, p)) return false;
    double dist[3] = {abs(seg.p[1] - seg.p[0]), abs(p - seg.p[0]), abs(p - seg.p[1])};
    return on_line3d(seg, p) && equals(dist[0], dist[1] + dist[2]);
}

double distanceSP(Segment3d seg, Point3d p) {
    Point3d r = project(seg, p);
    if (on_segment3d(seg, r)) return abs(p - r);
    return min(abs(seg.p[0] - p), abs(seg.p[1] - p));
}

double solve(int N, int M, int R) {
    vector<Point3d> Sp(N);
    vector<double> Sr(N);
    for(int i : rep(N)) Sp[i].x = in(), Sp[i].y = in(), Sp[i].z = in(), Sr[i] = in();
    vector<Point3d> Tp(M);
    vector<double> Tb(M);
    for(int i : rep(M)) Tp[i].x = in(), Tp[i].y = in(), Tp[i].z = in(), Tb[i] = in();
    Point3d E;
    E.x = in(), E.y = in(), E.z = in();

    const int MAX_N = 2000;
    vector<bitset<MAX_N>> erase(M);
    for(int i : rep(M)) {
        for(int j : rep(N)) {
            bool touch = [&] {
                if(abs(E - Sp[j]) <= Sr[j] and abs(Tp[i] - Sp[j]) <= Sr[j]) return false;
                return distanceSP(Segment3d(E, Tp[i]), Sp[j]) <= Sr[j];
            }();

            erase[i][j] = touch;
        }
    }

    double ans = 0;
    for(int set : rep(1 << M)) {
        bitset<MAX_N> need;
        double score = 0;
        for(int i : rep(M)) if(set & (1 << i)) {
            need |= erase[i];
            score += Tb[i] / norm(Tp[i] - E);
        }
        if(need.count() <= R) chmax(ans, score);
    }
    return ans;
}

int main() {
    while(true) {
        int N = in(), M = in(), R = in();
        if(make_tuple(N, M, R) == make_tuple(0, 0, 0)) return 0;
        printer::precision(20);
        print(solve(N, M, R));
    }
}
accuracy: 1
time_ms: 270
memory_kb: 3588
final_rank: 6

code_snippet: #include<bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define per(i, n) for(int i = (n)-1; i >= 0; i--)
#define rep2(i, l, r) for(int i = (l); i < (r); i++)
#define per2(i, l, r) for(int i = (r)-1; i >= (l); i--)
#define each(e, x) for(auto &e : x)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define eb emplace_back
#define MM << ' ' <<
#define TT template<typename T>
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

TT bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; }

TT bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; }

TT using minheap = priority_queue<T, vector<T>, greater<T>>;
TT using maxheap = priority_queue<T>;

TT void print(vector<T> v, T x = 0) {
    int n = sz(v);
    rep(i, n) cout << v[i] + x << (i == n - 1 ? '\n' : ' ');
    if (n == 0) cout << '\n';
}

TT void printn(vector<T> v, T x = 0) {
    int n = sz(v);
    rep(i, n) cout << v[i] + x << '\n';
}

TT void rearrange(vector<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), end(v));
}

TT int lb(vector<T> &v, T x) { return lower_bound(all(v), x) - begin(v); }

TT int ub(vector<T> &v, T x) { return upper_bound(all(v), x) - begin(v); }

const int inf = (1 << 30) - 1;
const ll INF = (1LL << 60) - 1;

struct io_setup {
    io_setup() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

struct P {
    double x, y, z;
    P() {}
    P(double x, double y, double z) : x(x), y(y), z(z) {}
};

P operator+(P p, P q) {
    return P(p.x + q.x, p.y + q.y, p.z + q.z);
}

P operator-(P p, P q) {
    return P(p.x - q.x, p.y - q.y, p.z - q.z);
}

double p2(double x) {
    return x * x;
}

double dist(P p, P q) {
    return p2(p.x - q.x) + p2(p.y - q.y) + p2(p.z - q.z);
}

double dot(P p, P q) {
    return p.x * q.x + p.y * q.y + p.z * q.z;
}

P proj(P a, P b, P p) {
    P dap = p - a, dab = b - a;
    double t = dot(dap, dab) / dist(dab, P(0, 0, 0));
    return a + P(dab.x * t, dab.y * t, dab.z * t);
}

double dist(P a, P b, P p) {
    P h = proj(a, b, p);
    if (dot(h - a, b - a) < 0)
        return dist(a, p);
    if (dot(h - b, a - b) < 0)
        return dist(b, p);
    return dist(h, p);
}

int main() {
    while (1) {
        int n, m, r;
        cin >> n >> m >> r;
        if (!n)
            break;
        vector<int> xs(n), ys(n), zs(n), rs(n);
        rep(i, n) cin >> xs[i] >> ys[i] >> zs[i] >> rs[i];
        vector<P> ps(n);
        rep(i, n) ps[i] = P(xs[i], ys[i], zs[i]);
        vector<int> xt(m), yt(m), zt(m), bt(m);
        rep(i, m) cin >> xt[i] >> yt[i] >> zt[i] >> bt[i];
        vector<P> pt(m);
        rep(i, m) pt[i] = P(xt[i], yt[i], zt[i]);
        int x0, y0, z0;
        cin >> x0 >> y0 >> z0;
        P p0(x0, y0, z0);
        vector<vector<bool>> inter(n, vector<bool>(m));
        rep(i, n) rep(j, m) {
            double d0 = dist(p0, ps[i]), dj = dist(pt[j], ps[i]);
            if (max(d0, dj) < p2(rs[i]))
                inter[i][j] = false;
            else inter[i][j] = (dist(p0, pt[j], ps[i]) < p2(rs[i]));
        }
        vector<int> ng(n, 0);
        rep(i, n) rep(j, m) if (inter[i][j]) ng[i] |= 1 << j;
        double ans = 0;
        rep(t, 1 << m) {
            int cnt = 0;
            rep(i, n) if (ng[i] & t) cnt++;
            if (cnt > r)
                continue;
            double val = 0;
            rep(i, m) if (t >> i & 1) val += bt[i] / dist(p0, pt[i]);
            chmax(ans, val);
        }
        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 260
memory_kb: 3632
final_rank: 9

code_snippet: #include<bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define per(i, n) for(int i = (n)-1; i >= 0; i--)
#define rep2(i, l, r) for(int i = (l); i < (r); i++)
#define per2(i, l, r) for(int i = (r)-1; i >= (l); i--)
#define each(e, x) for(auto &e : x)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define eb emplace_back
#define MM << ' ' <<
#define TT template<typename T>
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

TT bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; }

TT bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; }

TT using minheap = priority_queue<T, vector<T>, greater<T>>;
TT using maxheap = priority_queue<T>;

TT void print(vector<T> v, T x = 0) {
    int n = sz(v);
    rep(i, n) cout << v[i] + x << (i == n - 1 ? '\n' : ' ');
    if (n == 0) cout << '\n';
}

TT void printn(vector<T> v, T x = 0) {
    int n = sz(v);
    rep(i, n) cout << v[i] + x << '\n';
}

TT void rearrange(vector<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), end(v));
}

TT int lb(vector<T> &v, T x) { return lower_bound(all(v), x) - begin(v); }

TT int ub(vector<T> &v, T x) { return upper_bound(all(v), x) - begin(v); }

const int inf = (1 << 30) - 1;
const ll INF = (1LL << 60) - 1;

struct io_setup {
    io_setup() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

struct P {
    double x, y, z;
    P() {}
    P(double x, double y, double z) : x(x), y(y), z(z) {}
};

P operator+(P p, P q) {
    return P(p.x + q.x, p.y + q.y, p.z + q.z);
}

P operator-(P p, P q) {
    return P(p.x - q.x, p.y - q.y, p.z - q.z);
}

double p2(double x) {
    return x * x;
}

double dist(P p, P q) {
    return p2(p.x - q.x) + p2(p.y - q.y) + p2(p.z - q.z);
}

double dot(P p, P q) {
    return p.x * q.x + p.y * q.y + p.z * q.z;
}

P proj(P a, P b, P p) {
    P dap = p - a, dab = b - a;
    double t = dot(dap, dab) / dist(dab, P(0, 0, 0));
    return a + P(dab.x * t, dab.y * t, dab.z * t);
}

double dist(P a, P b, P p) {
    P h = proj(a, b, p);
    if (dot(h - a, b - a) < 0)
        return dist(a, p);
    if (dot(h - b, a - b) < 0)
        return dist(b, p);
    return dist(h, p);
}

int main() {
    while (1) {
        int n, m, r;
        cin >> n >> m >> r;
        if (!n)
            break;
        vector<int> xs(n), ys(n), zs(n), rs(n);
        rep(i, n) cin >> xs[i] >> ys[i] >> zs[i] >> rs[i];
        vector<P> ps(n);
        rep(i, n) ps[i] = P(xs[i], ys[i], zs[i]);
        vector<int> xt(m), yt(m), zt(m), bt(m);
        rep(i, m) cin >> xt[i] >> yt[i] >> zt[i] >> bt[i];
        vector<P> pt(m);
        rep(i, m) pt[i] = P(xt[i], yt[i], zt[i]);
        int x0, y0, z0;
        cin >> x0 >> y0 >> z0;
        P p0(x0, y0, z0);
        vector<vector<bool>> inter(n, vector<bool>(m));
        rep(i, n) rep(j, m) {
            double d0 = dist(p0, ps[i]), dj = dist(pt[j], ps[i]);
            if (max(d0, dj) < p2(rs[i]))
                inter[i][j] = false;
            else inter[i][j] = (dist(p0, pt[j], ps[i]) < p2(rs[i]));
        }
        double ans = 0;
        rep(t, 1 << m) {
            vector<int> f(n, 0);
            double val = 0;
            rep(i, m) {
                if (t >> i & 1) {
                    rep(j, n) if (inter[j][i]) f[j] = 1;
                    val += bt[i] / dist(p0, pt[i]);
                }
            }
            if (accumulate(all(f), 0) > r)
                continue;
            chmax(ans, val);
        }
        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 7330
memory_kb: 3648
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define foa(c, v) for (auto &c : v)
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) int(size(v))
template <class T>
bool chmin(T &a, T b)
{
    return a > b ? (a = b, 1) : 0;
}

template <class T>
bool chmax(T &a, T b)
{
    return a < b ? (a = b, 1) : 0;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec)
{
    os << "{ ";
    foa(c, vec)
    {
        os << c << ", ";
    }
    os << "}";
    return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<vector<T>> &vv)
{
    os << "{ ";
    foa(v, vv)
    {
        os << "\n\t" << v << ", ";
    }
    os << "\n}";
    return os;
}

#ifdef LOCAL
#define debug(x) cerr << __LINE__ << ", " << #x << ": " << x << endl;
#else
#define debug(x) void(0)
#endif

using R = long double;
constexpr int dim = 3;
using point = array<R, dim>;

point operator+(point a, point b)
{
    point c;
    rep(i, dim) c[i] = a[i] + b[i];
    return c;
}

point operator-(point a, point b)
{
    point c;
    rep(i, dim) c[i] = a[i] - b[i];
    return c;
}

R dot(point a, point b)
{
    R res = 0;
    rep(i, dim) res += a[i] * b[i];
    return res;
}

R dsq(point a, point b)
{
    R res = 0;
    rep(i, dim) res += pow(a[i] - b[i], 2);
    return res;
}

R distance(point a, point b)
{
    return sqrt(dsq(a, b));
}

R dist_from_center(point a)
{
    R res = 0;
    rep(i, dim) res += pow(a[i], 2);
    return sqrt(res);
}

R angle(point a, point b, point c)
{
    a = a - b;
    c = c - b;
    return acos(dot(a, c) / (dist_from_center(a) * dist_from_center(c)));
}

istream &operator>>(istream &is, point &c)
{
    rep(i, dim) is >> c[i];
    return is;
}

ostream &operator<<(ostream &os, const point &c)
{
    os << "(";
    rep(i, dim) os << c[i] << ", ";
    os << ")";
    return os;
}

using points = vector<point>;

int bnum;
void solve()
{
    int lnum, remove_limit;
    cin >> lnum >> remove_limit;

    vector<point> balloons(bnum), lights(lnum);
    vector<R> radii(bnum), bright(lnum);

    rep(i, bnum)
    {
        cin >> balloons[i];
        cin >> radii[i];
    }

    rep(j, lnum)
    {
        cin >> lights[j] >> bright[j];
    }

    point goal;
    cin >> goal;

    debug(balloons);
    debug(goal);

    rep(j, lnum)
        bright[j] /= dsq(goal, lights[j]);

    vector<bitset<2123>> barricade(lnum);

    auto inside = [&](int bid, point p) -> bool
    {
        return distance(balloons[bid], p) < radii[bid];
    };

    auto absorbed = [&](int bid, int lid) -> bool
    {
        const point &light = lights[lid], bcenter = balloons[bid];
        R dl = distance(goal, light), db = distance(goal, bcenter), r = radii[bid];

        if (inside(bid, goal))
            return !inside(bid, light);

        if (inside(bid, light))
            return true;

        assert(db > r);
        R tang = sqrt(db * db - r * r);

        if (tang > dl)
            return false;

        return angle(light, goal, bcenter) < asin(r / db);
    };

    rep(bid, bnum)
    {
        rep(lid, lnum)
        {
            if (absorbed(bid, lid))
            {
                barricade[lid].set(bid, 1);
            }
        }
    }

    R ans = 0;

    rep(bits, (1 << lnum))
    {
        bitset<2123> b;
        R res = 0;
        rep(lid, lnum) if ((1 << lid) & bits)
        {
            b |= barricade[lid];
            res += bright[lid];
        }
        if (int(b.count()) > remove_limit)
            continue;
        chmax(ans, res);
    }

    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    while (cin >> bnum && bnum)
        solve();

    return 0;
}
accuracy: 1
time_ms: 370
memory_kb: 3708
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;

using ld = long double;
using point = tuple<ld,ld,ld>;

bool cross(point balloon, ld radius, point light) {
    auto [lx, ly, lz] = light;
    auto [bx, by, bz] = balloon;

    if(hypot(bx, by, bz) <= radius) {
        return hypot(lx - bx, ly - by, lz - bz) > radius;
    }

    ld low = 0.0l;
    ld high = 1.0l;

    while(high - low >= 1e-7) {
        ld c1 = (low * 2.0l + high) / 3.0l;
        ld c2 = (low + high * 2.0l) / 3.0l;

        ld x1 = c1 * lx, y1 = c1 * ly, z1 = c1 * lz;
        ld x2 = c2 * lx, y2 = c2 * ly, z2 = c2 * lz;

        ld f1 = hypot(x1 - bx, y1 - by, z1 - bz);
        ld f2 = hypot(x2 - bx, y2 - by, z2 - bz);

        if(f1 > f2) low = c1;
        else high = c2;
    }

    ld x = low * lx, y = low * ly, z = low * lz;
    return hypot(x - bx, y - by, z - bz) <= radius;
}

void solve(int N, int M, int R) {
    point balloons[N];
    ld radiuses[N];

    for (int i = 0; i < N; i++) {
        ld x,y,z;
        cin >> x >> y >> z >> radiuses[i];
        balloons[i] = {x,y,z};
    }

    point lights[N];
    ld T[N];
    for (int i = 0; i < M; i++) {
        ld x,y,z;
        cin >> x >> y >> z >> T[i];
        lights[i] = {x,y,z};
    }

    ld Ex, Ey, Ez;
    cin >> Ex >> Ey >> Ez;
    for (int i = 0; i < N; i++) {
        auto [x, y, z] = balloons[i];
        balloons[i] = {x - Ex, y - Ey, z - Ez};
    }
    for (int i = 0; i < M; i++) {
        auto [x, y, z] = lights[i];
        lights[i] = {x - Ex, y - Ey, z - Ez};
    }

    bitset<2000> obstacles[M];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            if(cross(balloons[i], radiuses[i], lights[j])) {
                obstacles[j].set(i, true);
            }
        }
    }

    ld ans = numeric_limits<ld>::min();

    for (int bits = 0; bits < (1 << M); bits++) {
        bitset<2000> obs;
        for (int i = 0; i < M; i++) {
            if(bits & (1 << i)) obs |= obstacles[i];
        }
        if(obs.count() > R) continue;

        ld score = 0;

        for (int i = 0; i < M; i++) {
            if(bits & (1 << i)) {
                auto [x, y, z] = lights[i];
                score += T[i] / powl(hypot(x, y, z), 2.0l);
            }
        }

        ans = max(ans, score);
    }

    cout << fixed << setprecision(10) << ans << endl;
}

int main() {
    int N, M, R;

    while(true) {
        cin >> N >> M >> R;
        if(N == 0 && M == 0 && R == 0) break;
        solve(N, M, R);
    }
}
accuracy: 1
time_ms: 610
memory_kb: 3712
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define revrep(i, t, s) for (int i = (int)(t)-1; i >= (int)(s); --i)
#define all(x) begin(x), end(x)
template <typename T> bool chmax(T& a, const T& b) { return a < b ? (a = b, 1) : 0; }
template <typename T> bool chmin(T& a, const T& b) { return a > b ? (a = b, 1) : 0; }

using T = double;
constexpr T eps = 1e-12;
inline bool eq(T a, T b) { return std::abs(a - b) < eps; }
inline bool lt(T a, T b) { return a < b - eps; }
inline bool leq(T a, T b) { return a < b + eps; }

struct Vec {
    T x, y, z;
    Vec() = default;
    constexpr Vec(T x, T y, T z) : x(x), y(y), z(z) {}
    constexpr Vec& operator+=(const Vec& r) { x += r.x; y += r.y; z += r.z; return *this; }
    constexpr Vec& operator-=(const Vec& r) { x -= r.x; y -= r.y; z -= r.z; return *this; }
    constexpr Vec& operator*=(T r) { x *= r; y *= r; z *= r; return *this; }
    constexpr Vec& operator/=(T r) { x /= r; y /= r; z /= r; return *this; }
    constexpr Vec operator-() const { return Vec(-x, -y, -z); }
    constexpr Vec operator+(const Vec& r) const { return Vec(*this) += r; }
    constexpr Vec operator-(const Vec& r) const { return Vec(*this) -= r; }
    constexpr Vec operator*(T r) const { return Vec(*this) *= r; }
    constexpr Vec operator/(T r) const { return Vec(*this) /= r; }
    friend constexpr Vec operator*(T r, const Vec& v) { return v * r; }
};

std::istream& operator>>(std::istream& is, Vec& p) {
    T x, y, z;
    is >> x >> y >> z;
    p = {x, y, z};
    return is;
}

T dot(const Vec& a, const Vec& b) {
    return a.x*b.x + a.y*b.y + a.z*b.z;
}

Vec cross(const Vec& a, const Vec& b) {
    return Vec(a.y*b.z-a.z*b.y, a.z*b.x-a.x*b.z, a.x*b.y-a.y*b.x);
}

namespace std {
T norm(const Vec& a) { return dot(a, a); }
T abs(const Vec& a) { return std::sqrt(std::norm(a)); }
}

struct Segment {
    Vec p1, p2;
    Segment() = default;
    Segment(const Vec& p1, const Vec& p2) : p1(p1), p2(p2) {}
    Vec dir() const { return p2 - p1; }
};

T dist(const Segment& s, const Vec& p) {
    if (lt(dot(p - s.p1, s.dir()), 0)) return std::abs(p - s.p1);
    if (lt(dot(p - s.p2, -s.dir()), 0)) return std::abs(p - s.p2);
    return std::abs(cross(p - s.p1, s.dir())) / std::abs(s.dir());
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (int i = 0; i < (int) v.size(); ++i) os << v[i] << " ";
    return os;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    while (true) {
        int N, M, R;
        cin >> N >> M >> R;
        if (N == 0 && M == 0 && R == 0) break;
        vector<Vec> S(N), T(M);
        vector<double> r(N), b(M);
        rep(i,0,N) cin >> S[i] >> r[i];
        rep(i,0,M) cin >> T[i] >> b[i];
        Vec E;
        cin >> E;
        vector<double> score(M);
        rep(j,0,M) score[j] = b[j] / norm(T[j] - E);
        vector<int> interrupt(N);
        rep(i,0,N) rep(j,0,M) {
            if (lt(abs(E-S[i]), r[i]) && lt(abs(T[j]-S[i]), r[i])) continue;
            if (lt(dist(Segment(E, T[j]), S[i]), r[i])) {
                interrupt[i] |= 1<<j;
            }
        }
        double ans = 0;
        for (int B = 0; B < 1 << M; ++B) {
            int cnt = 0;
            rep(i,0,N) {
                if (interrupt[i] & B) ++cnt;
            }
            if (cnt > R) continue;
            double c = 0;
            rep(j,0,M) if (B>>j&1) c += score[j];
            chmax(ans, c);
        }
        cout << ans << "\n";
    }
}
accuracy: 1
time_ms: 400
memory_kb: 3584
final_rank: 7

code_snippet: #include <algorithm>
#include<bits/stdc++.h>
#include <new>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using vvvvector = vvector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
    ll modpow(ll x, ll b,ll mod=MOD){
        ll res = 1;
        while(b){
            if(b&1)res = res * x % mod;
            x = x * x % mod;
            b>>=1;
        }
        return res;
    }

    ll modinv(ll x){
        return modpow(x, MOD-2);
    }

    bool was_output = false;

    void print();
    template <class t> void print(const vector<t> &);
    template <class t, class u> void print(const pair<t, u> &);
    template <class t> void print(const t&);
    template <class Head, class... Tail> void print(const Head&, const Tail&...);

    template <class t> void println(const vector<vector<t>>&);
    template <class t> void println(const vector<t>&);
    template <class t> void println(const t&);
    template <class Head, class... Tail> void println(const Head&, const Tail&...);
    void println();
    void newline();

    void print(){
        return;
    }

    template <class t>
    void print(const vector<t>&x){
        for(const t&i:x)print(i);
    }
    template <class t, class u>
    void print(const pair<t,u>&p){
        print(p.first);
        print(p.second);
    }
    template <class t>
    void print(const t&x){
        if(was_output)cout<<" ";
        cout<<x;
        was_output = true;
    }
    template <class Head, class... Tail>
    void print(const Head&head,const Tail&...tail){
        print(head);
        print(tail...);
    }

    template<class t>
    void println(const vector<vector<t>>&x){
        for(vector<t> i:x)println(i);
    }
    template<class t>
    void println(const vector<t>&x){
        for(const t&i:x)print(i);
        println();
    }
    template <class t>
    void println(const t&x){
        print(x);
        println();
    }
    void println(){
        if(was_output){
            cout << endl;
            was_output = false;
        }
    }
    template <class Head, class... Tail>
    void println(const Head&head,const Tail&...tail){
        print(head);
        println(tail...);
    }

    void newline(){
        was_output = true;
        println();
    }

    template<class t>
    istream& operator>>(istream&is, vector<t>&x){
        for(auto &i:x)is >> i;
        return is;
    }

    template<class t, class u>
    istream& operator>>(istream&is, pair<t, u>&x){
        is >> x.first >> x.second;
        return is;
    }

    template<class t>
    ostream& operator<<(ostream&os, vector<t> &v){
        os << "{";
        for(t &i:v){
            os << i << ", ";
        }
        os << "}";
        return os;
    }

    template<class t = long long>
    t in(){
        t res; cin >> res; return res;
    }

    template<class t>
    vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
        sort(line.begin(),line.end(),comp);
        return line;
    }

    template<class t>
    vector<t> reversed(vector<t> line){
        reverse(line.begin(),line.end());
        return line;
    }
    string reversed(string str){
        reverse(str.begin(),str.end());
        return str;
    }

    long long gcd(long long a,long long b){
        while(b){
            a %= b;
            swap(a,b);
        }
        return a;
    }

    long long lcm(long long a,long long b){
        return a / gcd(a,b) * b;
    }

    class output_initializer{
    public:
        output_initializer(){
            ios::sync_with_stdio(false);
            cin.tie(nullptr);
            cout << setprecision(20);
        }
    };output_initializer OUTPUT_INITIALIZER_INSTANCE = output_initializer();
}

using namespace templates;

string twoChar(int n){
    if(n<10)return "0" + to_string(n);
    return to_string(n);
}

string toString(int h,int m,int s){
    return twoChar(h)+":"+twoChar(m)+":"+twoChar(s);
}

string toString(vector<int> line){
    return toString(line[0],line[1],line[2]);
}

vector<int> toTimes(int n){
    return {n/3600,n%3600/60,n%60};
}

vector<int> expectedTimes(vector<int> times){
    set<int> expected;
    sort(all(times));
    do{
        rep(rotate,60){
            vector<int> adds;
            foreach(i,times)adds.emplace_back((i+rotate)%60);
            int hour = adds[0];
            int minutes = adds[1];
            int secs = adds[2];
            if(hour%5!=minutes/12)continue;
            expected.emplace(hour/5*3600+minutes*60+secs);
        }
    }while(next_permutation(all(times)));
    vector<int> res(all(expected));
    return res;
}

string func(int n){
    vvector<int> line(n,vector<int>(3));
    foreach(i,line)foreach(j,i)j=in();
    vector<queue<int>> oks;
    foreach(i,line){
        queue<int> adds;
        foreach(j,expectedTimes(i)){
            adds.emplace(j);
        }
        oks.emplace_back(adds);
    }
    int mint = INF;
    int maxt = 0;
    int dist = INF;
    while(true){
        {
            bool flag = false;
            foreach(i,oks)if(i.empty())flag=true;
            if(flag)break;
        }
        int mins = INF;
        int maxs = 0;
        foreach(i,oks){
            chmax(maxs,i.front());
            chmin(mins,i.front());
        }
        if(chmin(dist,maxs-mins)){
            mint = mins;
            maxt = maxs;
        }
        foreach(i,oks)if(i.front()==mins)i.pop();
    }
    return toString(toTimes(mint)) + " " + toString(toTimes(maxt));
}


template<class t>
class Vector3{
	public:
		t x;
		t y;
		t z;
		Vector3():x(0), y(0), z(0){}
		Vector3(t a, t b, t c):x(a), y(b), z(c){}
		Vector3(const Vector3 &o):x(o.x), y(o.y), z(o.z){}

		Vector3& operator+=(Vector3 o){x+=o.x;y+=o.y;z+=o.z;return *this;}
		Vector3& operator-=(Vector3 o){x-=o.x;y-=o.y;z-=o.z;return *this;}
		Vector3& operator*=(t o){x*=o;y*=o;z*=o;return *this;}
		Vector3& operator/=(t o){x/=o;y/=o;z/=o;return *this;}

		Vector3 operator+(Vector3 o){return Vector3(*this)+=o;}
		Vector3 operator-(Vector3 o){return Vector3(*this)-=o;}
		Vector3 operator*(t o){return Vector3(*this)*=o;}
		Vector3 operator/(t o){return Vector3(*this)/=o;}
};

template<class t>
double abs(Vector3<t> x){
	return sqrt(x.x * x.x + x.y * x.y + x.z * x.z);
}

template<class t>
double dot(Vector3<t> x, Vector3<t> y){
	return x.x * y.x + x.y * y.y + x.z * y.z;
}

template<class t>
Vector3<t> cross(Vector3<t> x, Vector3<t> y){
	t rx = x.y * y.z - x.z * y.y;
	t ry = x.z * y.x - x.x * y.z;
	t rz = x.x * y.y - x.y * y.x;
	return Vector3<t>(rx, ry, rz); 
}
using vector3=  Vector3<double>;

class Sphere{
public:
    vector3 p;
    double r;
    Sphere(vector3 p,double r):p(p),r(r){}
};

class Light{
public:
    vector3 p;
    double i;
    Light(vector3 p,double i):p(p),i(i){}
};

bool isIn(Sphere s,vector3 p){
    return abs(s.p - p) < s.r;
}

bool isTouch(Sphere s,vector3 from,vector3 to){
    if(isIn(s,from) and isIn(s,to))return false;
    vector3 v1 = to - from;
    vector3 v2 = s.p - from;
    vector3 n = v1 / abs(v1);
    double k = dot(n,v2);
    if(0 < k){
        v2 = v2 - n * min(k,abs(v1));
    }
    return abs(v2) < s.r;
}

double func(int n,int m,int r){
    vector<Sphere> baloons;
    vector<Light> lights;
    rep(_,n){
        int x = in();
        int y = in();
        int z = in();
        int r = in();
        baloons.emplace_back(vector3(x,y,z),r);
    }
    rep(_,m){
        int x = in();
        int y = in();
        int z = in();
        int i = in();
        lights.emplace_back(vector3(x,y,z),i);
    }
    vector3 object = (lambda(vector3){
            int x = in();
            int y = in();
            int z = in();
            return vector3(x,y,z);
        })();
    vvector<int> brokens;
    foreach(light,lights){
        vector<int> broken;
        foreach(baloon,baloons){
            if(isTouch(baloon,object,light.p)){
                broken.emplace_back(1);
            }else{
                broken.emplace_back(0);
            }
        }
        brokens.emplace_back(broken);
    }

    vector<int> broken(n,0);

    method(rec,double,int p,double sum){
        if(p==m){
            int cnt = 0;
            foreach(i,broken)cnt += i != 0;
            if(cnt > r)return 0;
            return sum;
        }
        double res = 0;
        chmax(res,rec(p+1,sum));
        rep(i,n){
            broken[i] += brokens[p][i];
        }
        chmax(res,rec(p+1,sum + lights[p].i / pow(abs(object-lights[p].p),2)));
        rep(i,n){
            broken[i] -= brokens[p][i];
        }
        return res;
    };
    return rec(0,0);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    while(true){
        int n = in();
        int m = in();
        int r = in();
        if(n==0)break;
        println(func(n,m,r));
    }

    return 0;
}
accuracy: 1
time_ms: 760
memory_kb: 3660
final_rank: 14

code_snippet: #include "bits/stdc++.h"
using namespace std;

typedef string::const_iterator State;
#define eps 1e-8L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
#define REP(a, b) for (long long(a) = 0; (a) < (b); ++(a))
#define ALL(x) (x).begin(), (x).end()

#define int long long
ld dist(tuple<ld, ld, ld> a, tuple<ld, ld, ld> b)
{
  return pow(get<0>(a) - get<0>(b), 2.0) + pow(get<1>(a) - get<1>(b), 2.0) + pow(get<2>(a) - get<2>(b), 2.0);
}

void solve()
{
  int n, m, r;
  cin >> n >> m >> r;
  if (n == 0)
    exit(0);
  vector<pair<tuple<ld, ld, ld>, ld>> Balloon;
  REP(i, n)
  {
    ld a, b, c, d;
    cin >> a >> b >> c >> d;
    Balloon.push_back({{a, b, c}, d});
  }
  vector<pair<tuple<ld, ld, ld>, ld>> lights;
  REP(i, m)
  {
    ld a, b, c, d;
    cin >> a >> b >> c >> d;
    lights.push_back({{a, b, c}, d});
  }
  tuple<ld, ld, ld> e;
  cin >> get<0>(e) >> get<1>(e) >> get<2>(e);

  vector<int> light_target(n, 0);
  REP(i, m)
  {
    lights[i].second /= dist(e, lights[i].first);
    REP(q, n)
    {
      if (max(dist(e, Balloon[q].first), dist(lights[i].first, Balloon[q].first)) <= Balloon[q].second * Balloon[q].second + eps)
      {
        continue;
      }
      ld bot = 0;
      ld top = 1;
      ld now_min_dist = 1e18;
      REP(t, 100)
      {
        ld botter = (bot + bot + top) / 3.0;
        ld topper = (bot + top + top) / 3.0;
        tuple<ld, ld, ld> target = e;
        get<0>(target) *= botter;
        get<1>(target) *= botter;
        get<2>(target) *= botter;

        get<0>(target) += (1.0L - botter) * get<0>(lights[i].first);
        get<1>(target) += (1.0L - botter) * get<1>(lights[i].first);
        get<2>(target) += (1.0L - botter) * get<2>(lights[i].first);

        ld dis[2] = {};
        dis[0] = dist(target, Balloon[q].first);

        target = e;
        get<0>(target) *= topper;
        get<1>(target) *= topper;
        get<2>(target) *= topper;

        get<0>(target) += (1.0L - topper) * get<0>(lights[i].first);
        get<1>(target) += (1.0L - topper) * get<1>(lights[i].first);
        get<2>(target) += (1.0L - topper) * get<2>(lights[i].first);

        dis[1] = dist(target, Balloon[q].first);
        if (dis[0] < dis[1])
        {
          top = topper;
        }
        else
        {
          bot = botter;
        }

        now_min_dist = min({now_min_dist, dis[0], dis[1]});
      }
      if (now_min_dist <= Balloon[q].second * Balloon[q].second + eps)
      {
        light_target[q] |= (1 << i);
      }
    }
  }
  ld ans = 0;
  REP(i, (1 << m))
  {
    ld now = 0;
    int cnt = 0;
    REP(q, m)
    {
      if ((1 << q) & i)
        now += lights[q].second;
    }
    REP(q, n)
    {
      if (i & light_target[q])
      {
        cnt++;
      }
    }
    if (cnt <= r)
    {
      ans = max(ans, now);
    }
  }
  cout << ans << endl;
}
#undef int

// generated by oj-template v4.7.2
// (https://github.com/online-judge-tools/template-generator)
int main()
{
  // Fasterize input/output script
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(100);
  // scanf/printf user should delete this fasterize input/output script

  int t = 10000;
  // cin >> t; // comment out if solving multi testcase
  for (int testCase = 1; testCase <= t; ++testCase)
  {
    solve();
  }
  return 0;
}
accuracy: 1
time_ms: 890
memory_kb: 3632
final_rank: 13

code_snippet: #include<iostream>
#include<ostream>
#include<cmath>
#include<cstdio>
#include<cassert>
#include<bitset>

using namespace std;

#define EPS (1e-7)
#define equals(a,b) (fabs((a)-(b))<EPS)

class Point3d{
public:
  double x,y,z;
  
  Point3d(double x=0,double y=0,double z=0):x(x),y(y),z(z){}
 
  Point3d operator + (const Point3d& a){
    return Point3d(x+a.x,y+a.y,z+a.z);
  }
  Point3d operator - (const Point3d& a){
    return Point3d(x-a.x,y-a.y,z-a.z);
  }
  Point3d operator * (const double& d){
    return Point3d(x*d,y*d,z*d);
  }
  Point3d operator / (const double& d){
    return Point3d(x/d,y/d,z/d);
  }
 
  bool operator < (const Point3d& p)const { return !equals(x,p.x)?x<p.x:((!equals(y,p.y))?y<p.y:(!equals(z,p.z)&&z<p.z)); }
 
  bool operator == (const Point3d& p)const{
    return equals(x,p.x) && equals(y,p.y) && equals(z,p.z);
  }
 
};
 
struct Segment3d{
  Point3d p[2];
  Segment3d(Point3d p1=Point3d(),Point3d p2=Point3d()){
    p[0] = p1, p[1] = p2;
  }
 bool operator == (const Segment3d& seg)const{
    return ( p[0] == seg.p[0] && p[1] == seg.p[1] ) || ( p[0] == seg.p[1] && p[1] == seg.p[0] );
 }
};
 
typedef Point3d Vector3d;
typedef Segment3d Line3d;
  
ostream& operator << (ostream& os,const Point3d& p){
  return os << "(" << p.x << "," << p.y << "," << p.z << ")";
}
 
ostream& operator << (ostream& os,const Segment3d& seg){
  return os << "(" << seg.p[0] << "," << seg.p[1] << ")";
}
 
double dot(const Point3d& a,const Point3d& b){
  return a.x*b.x + a.y*b.y + a.z*b.z;
}
 
Vector3d cross(const Point3d& a,const Point3d& b){
  return Vector3d(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x);
}
 
inline double norm(const Point3d &p){
  return p.x*p.x + p.y*p.y + p.z*p.z;
}
 
inline double abs(const Point3d &p){
  return sqrt(norm(p));
}
 
inline double toRad(double theta){
  return theta * M_PI / 180.0;
}

double distanceLP(Line3d line,Point3d p){
  return abs(cross(line.p[1]-line.p[0],p-line.p[0])) / abs(line.p[1]-line.p[0]);
}
 
Point3d project(Segment3d seg,Point3d p){
  Vector3d base = seg.p[1] - seg.p[0];
  double t = dot(p-seg.p[0],base) / norm(base);
  return seg.p[0] + base * t;
}
 
Point3d reflect(Segment3d seg,Point3d p){
  return p + (project(seg,p)-p) * 2.0;
}

bool on_line3d(Line3d line,Point3d p){
  return equals(abs(cross(line.p[1]-p,line.p[0]-p)),0);
}
 
bool on_segment3d(Segment3d seg,Point3d p){
  if( !on_line3d(seg,p) ) return false;
  double dist[3] = { abs(seg.p[1]-seg.p[0]), abs(p-seg.p[0]), abs(p-seg.p[1]) };  
  return on_line3d(seg,p) && equals(dist[0],dist[1]+dist[2]);
}

double distanceSP(Segment3d seg,Point3d p){
  Point3d r = project(seg,p);
  if( on_segment3d(seg,r) ) return abs(p-r);
  return min(abs(seg.p[0]-p),abs(seg.p[1]-p));
}

using namespace std;

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)


bool LT(double x, double y){ return !equals(x,y) && x < y; }
bool LTE(double x, double y){ return equals(x,y) || x < y; }

class Point3DwithWeight {
public:
  Point3d p;
  double weight;
};

const int MAX_N = 2100;
const int MAX_M = 20;
int N,M,R;
bitset<2100> remove_cost[MAX_M];
Point3DwithWeight S[MAX_N],T[MAX_M];
Point3DwithWeight E;

int getType(double a,double b){
  if( LT(a,b) ) return -1;
  return 1;
}

void init(){
  rep(i,M) remove_cost[i] = 0; 
  rep(i,M) {
    rep(j,N){
      int type[2] = { getType(abs(E.p-S[j].p),S[j].weight), getType(abs(T[i].p-S[j].p),S[j].weight) };
      if( type[0] == type[1] && type[0] == -1 ) continue;
      double dist = distanceSP(Segment3d(E.p,T[i].p),S[j].p);
      if( LTE(dist,S[j].weight) ) remove_cost[i][j] = 1;
    }
  }
}

#define pow2(a) ((a)*(a))
void compute(){
  init();
  double maxi = 0;
  rep(bitmask,(1<<M)){
    bitset<2100> BIT(0);
    rep(i,M) if( (bitmask>>i) & 1 ) BIT |= remove_cost[i];
    if( BIT.count() <= R ) {
      double cost = 0;
      rep(i,M) if( (bitmask>>i) & 1 ) cost += T[i].weight / ( pow2(T[i].p.x-E.p.x) + pow2(T[i].p.y-E.p.y) + pow2(T[i].p.z-E.p.z) );
      maxi = max(maxi,cost);
    }
  }
  printf("%.10lf\n",maxi);
}

int main(){
  while( cin >> N >> M >> R, N|M|R ){
    assert( N <= 2000);
    rep(i,N) cin >> S[i].p.x >> S[i].p.y >> S[i].p.z >> S[i].weight;
    rep(i,M) cin >> T[i].p.x >> T[i].p.y >> T[i].p.z >> T[i].weight;
    cin >> E.p.x >> E.p.y >> E.p.z;
    compute();
  }
  return 0;
}
accuracy: 1
time_ms: 400
memory_kb: 3284
final_rank: 4

code_snippet: #include <bits/stdc++.h>

#include <bits/stdc++.h>
using namespace std;

#define EPS (1e-7)
#define equals(a,b) (fabs((a)-(b))<EPS)

class Point3d{
public:
  double x,y,z;
  
  Point3d(double x=0,double y=0,double z=0):x(x),y(y),z(z){}
 
  Point3d operator + (const Point3d& a){
    return Point3d(x+a.x,y+a.y,z+a.z);
  }
  Point3d operator - (const Point3d& a){
    return Point3d(x-a.x,y-a.y,z-a.z);
  }
  Point3d operator * (const double& d){
    return Point3d(x*d,y*d,z*d);
  }
  Point3d operator / (const double& d){
    return Point3d(x/d,y/d,z/d);
  }
 
  bool operator < (const Point3d& p)const { return !equals(x,p.x)?x<p.x:((!equals(y,p.y))?y<p.y:(!equals(z,p.z)&&z<p.z)); }
 
  bool operator == (const Point3d& p)const{
    return equals(x,p.x) && equals(y,p.y) && equals(z,p.z);
  }
 
};
 
struct Segment3d{
  Point3d p[2];
  Segment3d(Point3d p1=Point3d(),Point3d p2=Point3d()){
    p[0] = p1, p[1] = p2;
  }
 bool operator == (const Segment3d& seg)const{
    return ( p[0] == seg.p[0] && p[1] == seg.p[1] ) || ( p[0] == seg.p[1] && p[1] == seg.p[0] );
 }
};
 
typedef Point3d Vector3d;
typedef Segment3d Line3d;
  
ostream& operator << (ostream& os,const Point3d& p){
  return os << "(" << p.x << "," << p.y << "," << p.z << ")";
}
 
ostream& operator << (ostream& os,const Segment3d& seg){
  return os << "(" << seg.p[0] << "," << seg.p[1] << ")";
}
 
double dot(const Point3d& a,const Point3d& b){
  return a.x*b.x + a.y*b.y + a.z*b.z;
}
 
Vector3d cross(const Point3d& a,const Point3d& b){
  return Vector3d(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x);
}
 
inline double norm(const Point3d &p){
  return p.x*p.x + p.y*p.y + p.z*p.z;
}
 
inline double abs(const Point3d &p){
  return sqrt(norm(p));
}
 
inline double toRad(double theta){
  return theta * M_PI / 180.0;
}

double distanceLP(Line3d line,Point3d p){
  return abs(cross(line.p[1]-line.p[0],p-line.p[0])) / abs(line.p[1]-line.p[0]);
}
 
Point3d project(Segment3d seg,Point3d p){
  Vector3d base = seg.p[1] - seg.p[0];
  double t = dot(p-seg.p[0],base) / norm(base);
  return seg.p[0] + base * t;
}
 
Point3d reflect(Segment3d seg,Point3d p){
  return p + (project(seg,p)-p) * 2.0;
}

bool on_line3d(Line3d line,Point3d p){
  return equals(abs(cross(line.p[1]-p,line.p[0]-p)),0);
}
 
bool on_segment3d(Segment3d seg,Point3d p){
  if( !on_line3d(seg,p) ) return false;
  double dist[3] = { abs(seg.p[1]-seg.p[0]), abs(p-seg.p[0]), abs(p-seg.p[1]) };  
  return on_line3d(seg,p) && equals(dist[0],dist[1]+dist[2]);
}

double distanceSP(Segment3d seg,Point3d p){
  Point3d r = project(seg,p);
  if( on_segment3d(seg,r) ) return abs(p-r);
  return min(abs(seg.p[0]-p),abs(seg.p[1]-p));
}

using namespace std;

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)


bool LT(double x, double y){ return !equals(x,y) && x < y; }
bool LTE(double x, double y){ return equals(x,y) || x < y; }

class Point3DwithWeight {
public:
  Point3d p;
  double weight;
};

const int MAX_N = 2100;
const int MAX_M = 20;
int N,M,R;
bitset<2100> remove_cost[MAX_M];
Point3DwithWeight S[MAX_N],T[MAX_M];
Point3DwithWeight E;

int getType(double a,double b){
  if( LT(a,b) ) return -1;
  return 1;
}

void init(){
  rep(i,M) remove_cost[i] = 0; 
  rep(i,M) {
    rep(j,N){
      int type[2] = { getType(abs(E.p-S[j].p),S[j].weight), getType(abs(T[i].p-S[j].p),S[j].weight) };
      if( type[0] == type[1] && type[0] == -1 ) continue;
      double dist = distanceSP(Segment3d(E.p,T[i].p),S[j].p);
      if( LTE(dist,S[j].weight) ) remove_cost[i][j] = 1;
    }
  }
}

#define pow2(a) ((a)*(a))
void compute(){
  init();
  double maxi = 0;
  rep(bitmask,(1<<M)){
    bitset<2100> BIT(0);
    rep(i,M) if( (bitmask>>i) & 1 ) BIT |= remove_cost[i];
    if( BIT.count() <= R ) {
      double cost = 0;
      rep(i,M) if( (bitmask>>i) & 1 ) cost += T[i].weight / ( pow2(T[i].p.x-E.p.x) + pow2(T[i].p.y-E.p.y) + pow2(T[i].p.z-E.p.z) );
      maxi = max(maxi,cost);
    }
  }
  printf("%.10lf\n",maxi);
}

int main(){
  while( cin >> N >> M >> R, N|M|R ){
    assert( N <= 2000);
    rep(i,N) cin >> S[i].p.x >> S[i].p.y >> S[i].p.z >> S[i].weight;
    rep(i,M) cin >> T[i].p.x >> T[i].p.y >> T[i].p.z >> T[i].weight;
    cin >> E.p.x >> E.p.y >> E.p.z;
    compute();
  }
  return 0;
}
accuracy: 1
time_ms: 400
memory_kb: 3368
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define EPS (1e-7)
#define equals(a,b) (fabs((a)-(b))<EPS)

class Point3d{
public:
  double x,y,z;
  
  Point3d(double x=0,double y=0,double z=0):x(x),y(y),z(z){}
 
  Point3d operator + (const Point3d& a){
    return Point3d(x+a.x,y+a.y,z+a.z);
  }
  Point3d operator - (const Point3d& a){
    return Point3d(x-a.x,y-a.y,z-a.z);
  }
  Point3d operator * (const double& d){
    return Point3d(x*d,y*d,z*d);
  }
  Point3d operator / (const double& d){
    return Point3d(x/d,y/d,z/d);
  }
 
  bool operator < (const Point3d& p)const { return !equals(x,p.x)?x<p.x:((!equals(y,p.y))?y<p.y:(!equals(z,p.z)&&z<p.z)); }
 
  bool operator == (const Point3d& p)const{
    return equals(x,p.x) && equals(y,p.y) && equals(z,p.z);
  }
 
};
 
struct Segment3d{
  Point3d p[2];
  Segment3d(Point3d p1=Point3d(),Point3d p2=Point3d()){
    p[0] = p1, p[1] = p2;
  }
 bool operator == (const Segment3d& seg)const{
    return ( p[0] == seg.p[0] && p[1] == seg.p[1] ) || ( p[0] == seg.p[1] && p[1] == seg.p[0] );
 }
};
 
typedef Point3d Vector3d;
typedef Segment3d Line3d;
  
ostream& operator << (ostream& os,const Point3d& p){
  return os << "(" << p.x << "," << p.y << "," << p.z << ")";
}
 
ostream& operator << (ostream& os,const Segment3d& seg){
  return os << "(" << seg.p[0] << "," << seg.p[1] << ")";
}
 
double dot(const Point3d& a,const Point3d& b){
  return a.x*b.x + a.y*b.y + a.z*b.z;
}
 
Vector3d cross(const Point3d& a,const Point3d& b){
  return Vector3d(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x);
}
 
inline double norm(const Point3d &p){
  return p.x*p.x + p.y*p.y + p.z*p.z;
}
 
inline double abs(const Point3d &p){
  return sqrt(norm(p));
}
 
inline double toRad(double theta){
  return theta * M_PI / 180.0;
}

double distanceLP(Line3d line,Point3d p){
  return abs(cross(line.p[1]-line.p[0],p-line.p[0])) / abs(line.p[1]-line.p[0]);
}
 
Point3d project(Segment3d seg,Point3d p){
  Vector3d base = seg.p[1] - seg.p[0];
  double t = dot(p-seg.p[0],base) / norm(base);
  return seg.p[0] + base * t;
}
 
Point3d reflect(Segment3d seg,Point3d p){
  return p + (project(seg,p)-p) * 2.0;
}

bool on_line3d(Line3d line,Point3d p){
  return equals(abs(cross(line.p[1]-p,line.p[0]-p)),0);
}
 
bool on_segment3d(Segment3d seg,Point3d p){
  if( !on_line3d(seg,p) ) return false;
  double dist[3] = { abs(seg.p[1]-seg.p[0]), abs(p-seg.p[0]), abs(p-seg.p[1]) };  
  return on_line3d(seg,p) && equals(dist[0],dist[1]+dist[2]);
}

double distanceSP(Segment3d seg,Point3d p){
  Point3d r = project(seg,p);
  if( on_segment3d(seg,r) ) return abs(p-r);
  return min(abs(seg.p[0]-p),abs(seg.p[1]-p));
}
 

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

bool LT(double x, double y){ return !equals(x,y) && x < y; }
bool LTE(double x, double y){ return equals(x,y) || x < y; }

class Point3DwithWeight {
public:
  Point3d p;
  double weight;
};

const int MAX_N = 2100;
const int MAX_M = 20;
int N,M,R;
bitset<2100> remove_cost[MAX_M];
Point3DwithWeight S[MAX_N],T[MAX_M];
Point3DwithWeight E;

int getType(double a,double b){
  if( LT(a,b) ) return -1;
  return 1;
}

void init(){
  rep(i,M) remove_cost[i] = 0; 
  rep(i,M) {
    rep(j,N){
      int type[2] = { getType(abs(E.p-S[j].p),S[j].weight), getType(abs(T[i].p-S[j].p),S[j].weight) };
      if( type[0] == type[1] && type[0] == -1 ) continue;
      double dist = distanceSP(Segment3d(E.p,T[i].p),S[j].p);
      if( LTE(dist,S[j].weight) ) remove_cost[i][j] = 1;
    }
  }
}

#define pow2(a) ((a)*(a))
void compute(){
  init();
  double maxi = 0;
  rep(bitmask,(1<<M)){
    bitset<2100> BIT(0);
    rep(i,M) if( (bitmask>>i) & 1 ) BIT |= remove_cost[i];
    if( BIT.count() <= R ) {
      double cost = 0;
      rep(i,M) if( (bitmask>>i) & 1 ) cost += T[i].weight / ( pow2(T[i].p.x-E.p.x) + pow2(T[i].p.y-E.p.y) + pow2(T[i].p.z-E.p.z) );
      maxi = max(maxi,cost);
    }
  }
  printf("%.10lf\n",maxi);
}

int main(){
  while( cin >> N >> M >> R, N|M|R ){
    assert( N <= 2000);
    rep(i,N) cin >> S[i].p.x >> S[i].p.y >> S[i].p.z >> S[i].weight;
    rep(i,M) cin >> T[i].p.x >> T[i].p.y >> T[i].p.z >> T[i].weight;
    cin >> E.p.x >> E.p.y >> E.p.z;
    compute();
  }
  return 0;
}
accuracy: 1
time_ms: 400
memory_kb: 3232
final_rank: 2

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

// 3D points
// AOJ 1331
struct _3Dpoint{
    double x,y,z;
    _3Dpoint(){}
    _3Dpoint(double x,double y,double z):x(x),y(y),z(z){}
    _3Dpoint& operator-=(const _3Dpoint &p){
        x -= p.x; y -= p.y; z -= p.z;
        return *this;
    }
    _3Dpoint& operator+=(const _3Dpoint &p){
        x += p.x; y += p.y; z += p.z;
        return *this;
    }
    _3Dpoint& operator*=(double d){
        x *= d; y *= d; z *= d;
        return *this;
    }
    _3Dpoint& operator/=(double d){
        x /= d; y /= d; z /= d;
        return *this;
    }
    const _3Dpoint operator+ (const _3Dpoint& p) const;
    const _3Dpoint operator- (const _3Dpoint& p) const;
    const _3Dpoint operator* (double d) const;
    const _3Dpoint operator/ (double d) const;
};
const _3Dpoint _3Dpoint::operator+ (const _3Dpoint& p) const{
    _3Dpoint res(*this); return res += p;
}
const _3Dpoint _3Dpoint::operator- (const _3Dpoint& p) const{
    _3Dpoint res(*this); return res -= p;
}
const _3Dpoint _3Dpoint::operator* (double d) const{
    _3Dpoint res(*this); return res *= d;
}
const _3Dpoint _3Dpoint::operator/ (double d) const{
    _3Dpoint res(*this); return res /= d;
}
struct _3Dline{
    _3Dpoint A,B;
    _3Dline(_3Dpoint A,_3Dpoint B):A(A),B(B){}
};
// A to B
_3Dpoint vec(_3Dline L){
    return L.B-L.A;
}
double abs(_3Dpoint P){
    return sqrt(P.x*P.x+P.y*P.y+P.z*P.z);
}
double dist(_3Dpoint A,_3Dpoint B){
    return abs(A-B);
}
double dot(_3Dpoint A,_3Dpoint B){
    return A.x*B.x+A.y*B.y+A.z*B.z;
}
_3Dpoint cross(_3Dpoint A,_3Dpoint B){
    return _3Dpoint(A.x*B.y-B.x*A.y, A.y*B.z-B.y*A.z, A.z*B.x-B.z*A.x);
}
// 点と直線の距離
double Point_line_distance(_3Dpoint P,_3Dline L){
    return abs(cross(P-L.A,vec(L)))/abs(vec(L));
}
// 点と線分の距離
double Point_segment_distance(_3Dpoint P,_3Dline L){
    if(dot(P-L.A,vec(L))<0) return dist(P,L.A);
    else if(dot(P-L.B,vec(L))>0) return dist(P,L.B);
    else return Point_line_distance(P,L);
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N,M,R;
    while(cin >> N >> M >> R,N){
        vector<_3Dpoint> s(N);
        vector<double> r(N);
        for(int i=0;i<N;i++){
            cin >> s[i].x >> s[i].y >> s[i].z >> r[i];
        }
        vector<_3Dpoint> t(M);
        vector<double> b(M);
        for(int i=0;i<M;i++){
            cin >> t[i].x >> t[i].y >> t[i].z >> b[i];
        }
        _3Dpoint E;
        cin >> E.x >> E.y >> E.z;
        double res=0.0;
        vector<vector<int>> cover(M);
        for(int i=0;i<M;i++){
            _3Dline L(E,t[i]);
            for(int j=0;j<N;j++){
                if(dist(t[i],s[j])<r[j] and dist(E,s[j])<r[j])continue;
                if(Point_segment_distance(s[j],L)<r[j]){
                    cover[i].push_back(j);
                }
            }
        }
        vector<int> flg(N);
        for(int i=0;i<(1<<M);i++){
            fill(flg.begin(), flg.end(),0);
            int cnt=0;
            for(int j=0;j<M;j++){
                if((1<<j)&i){
                    for(int k:cover[j]){
                        if(!flg[k])cnt++;
                        flg[k]=1;
                    }
                }
            }
            if(cnt<=R){
                double sum=0.0;
                for(int j=0;j<M;j++){
                    if((1<<j)&i){
                        sum+=b[j]/dist(E,t[j])/dist(E,t[j]);
                    }
                }
                res=max(res,sum);
            }
        }
        printf("%.10f\n",res);
    }
}
accuracy: 1
time_ms: 680
memory_kb: 3620
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;

const double EPS = 1e-8;
inline bool EQ(double a, double b) { return fabs(b - a) < EPS; }

struct Point {
    double x, y, z;
    Point() {}
    Point(double x, double y, double z) : x(x), y(y), z(z) {}
    Point operator-() const { return Point(-x, -y, -z); }
    Point operator+(const Point& p) const { return Point(x + p.x, y + p.y, z + p.z); }
    Point operator-(const Point& p) const { return Point(x - p.x, y - p.y, z - p.z); }
    Point operator*(const double& t) const { return Point(x * t, y * t, z * t); }
    Point operator/(const double& t) const { return Point(x / t, y / t, z / t); }
};
struct Line {
    Point a, b;
    Line() {}
    Line(Point a, Point b) : a(a), b(b) {}
};
struct Segment : Line {
    Segment() {}
    Segment(Point a, Point b) : Line(a, b) {}
};
struct Sphere {
    Point c;
    double r;
    Sphere(Point c, double r) : c(c), r(r) {}
};

double dot(const Point& a, const Point& b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
double norm(const Point& p) { return p.x * p.x + p.y * p.y + p.z * p.z; }
double abs(const Point& p) { return sqrt(norm(p)); }

Point projection(const Line& l, const Point& p) {
    double t = dot(p - l.a, l.b - l.a) / norm(l.b - l.a);
    return l.a + (l.b - l.a) * t;
}

int intersect(const Sphere& c, const Segment& s) {
    Point h = projection(s, c.c);
    double d1 = abs(c.c - s.a), d2 = abs(c.c - s.b);
    if (norm(h - c.c) - c.r * c.r > EPS) return 0;
    if (d1 < c.r + EPS && d2 < c.r + EPS) return 0;
    if ((d1 < c.r - EPS && d2 > c.r + EPS) || (d1 > c.r + EPS && d2 < c.r - EPS)) return 1;
    if (dot(s.a - h, s.b - h) < 0) return 2;
    return 0;
}

void solve(int N, int M, int R) {
    vector<Sphere> B;
    for (int i = 0; i < N; i++) {
        int x, y, z, r;
        cin >> x >> y >> z >> r;
        B.emplace_back(Point(x, y, z), r);
    }
    vector<Point> L;
    vector<double> b(M);
    for (int i = 0; i < M; i++) {
        int x, y, z;
        cin >> x >> y >> z >> b[i];
        L.emplace_back(x, y, z);
    }
    Point t;
    {
        int x, y, z;
        cin >> x >> y >> z;
        t = Point(x, y, z);
    }

    for (int i = 0; i < M; i++) {
        Point p = L[i];
        b[i] /= norm(p - t);
    }
    vector<vector<int>> interupt(M, vector<int>(N));
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < N; j++) {
            Segment s(L[i], t);
            int cross = intersect(B[j], s);
            interupt[i][j] = (cross > 0);
        }
    }

    double ans = 0;
    for (int mask = 0; mask < (1 << M); mask++) {
        vector<int> check(N, false);
        double res = 0;
        for (int i = 0; i < M; i++) {
            if (!(mask >> i & 1)) continue;
            res += b[i];
            for (int j = 0; j < N; j++) check[j] |= interupt[i][j];
        }
        int sum = accumulate(check.begin(), check.end(), 0);
        if (sum > R) continue;
        ans = max(ans, res);
    }

    cout << ans << '\n';
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int N, M, R;
    while (cin >> N >> M >> R, N && M && R) solve(N, M, R);
    return 0;
}
accuracy: 1
time_ms: 2180
memory_kb: 3632
final_rank: 17