Problem:
西暦20XX 年，学校対抗魔法競技大会が開かれていた．大会もいよいよ，最終競技を残すのみとなった．あなたはその競技の選手の1 人である．
あなたが出場する競技は，空間内に配置された青いオブジェをすべて破壊するまでの時間を競うというものである．選手は競技用の銃の持込が許可されている．空間内には複数の青いオブジェと同じ数の赤いオブジェ，そして複数の障害物が配置されている．青いオブジェと赤いオブジェは1 対1 に対応しており，赤いオブジェが配置されている座標から青いオブジェに弾を撃つことで青いオブジェを破壊しなければならない．空間内に配置されている障害物は球状であり，少しずつ組成が異なっているが，通常の弾であれば障害物に触れると弾はその場に止まってしまう．
競技に使われる弾はMagic Bullet という特殊な弾である．この弾は魔力をため込むことができ，弾が障害物に接触した際に自動的に魔力を消費し，弾が貫通する魔法が発動する．障害物の組成の違いから，貫通するために必要な魔法やその発動のために消費する魔力の量は異なっている．このため，ある障害物に対する魔法が発動した後であっても，別の障害物を貫通するためには新たに別の魔法を発動する必要がある．また，弾が複数の障害物に同時に接触した場合は同時に魔法が発動する．弾に込められた魔力の量は魔法の発動のたびに減少する．
障害物の位置や大きさ，貫通する魔法の発動に必要な魔力の量はすでに公開されているのに対し，赤いオブジェ，青いオブジェの位置は公開されていない．しかし，過去の同一競技の情報から，ある程度オブジェの位置を予想することができた．魔力を弾にこめることは非常に体力を消耗してしまうため，あなたは魔力をできるだけ節約したいと考えた．そこで，赤いオブジェとそれに対応する青いオブジェの位置を仮定して，そのときに弾にこめるべき必要な魔力の最小量，つまり，青いオブジェに到達している時点で弾に残っている魔力が0 になる魔力の量を求めよう．
Input
入力はすべて整数である．それぞれの数は1 つの空白により区切られる．
N
Q
x
1
y
1
z
1
r
1
l
1
:
x
N
y
N
z
N
r
N
l
N
sx
1
sy
1
sz
1
dx
1
dy
1
dz
1
:
sx
Q
sy
Q
sz
Q
dx
Q
dy
Q
dz
Q
N
は障害物の個数であり，
Q
は仮定した青いオブジェと赤いオブジェの座標の組の個数である．
x
i
,
y
i
,
z
i
はそれぞれ
i
個目の障害物の中心の位置を表す
x
座標，
y
座標，
z
座標である．
r
i
は
i
個目の障害物の半径である．
l
i
は
i
個目の障害物を貫通するための魔法で消費する魔力の量である．
sx
j
,
sy
j
,
sz
j
はそれぞれ
j
番目の仮定における赤いオブジェの位置を表す
x
座標，
y
座標，
z
座標である．
dx
j
,
dy
j
,
dz
j
はそれぞれ
j
番目の仮定における青いオブジェの位置を表す
x
座標，
y
座標，
z
座標である．
Constraints
0 ≤
N
≤ 50
1 ≤
Q
≤ 50
-500 ≤
x
i
, y
i
, z
i
≤ 500
1 ≤
r
i
≤ 1,000
1 ≤
l
i
≤ 10
16
-500 ≤
sx
j
, sy
j
, sz
j
≤  500
-500 ≤
dx
j
, dy
j
, dz
j
≤ 500
障害物が他の障害物にめり込んでいることはない
オブジェの座標は障害物の内部，表面にはない
それぞれの仮定において，赤いオブジェと青いオブジェの座標は一致しない
Output
それぞれ1 組の赤いオブジェとそれに対応する青いオブジェの位置の仮定において，空間中に障害物と赤いオブジェと青いオブジェ1 対とのみがあるものとして，弾にこめるべき魔力の量を1 行に出力せよ．弾は赤いオブジェの位置から青いオブジェの位置まで一直線に飛ぶものとし，弾の大きさは非常に小さいので点として扱う．
Sample Input 1
5 1
0 10 0 5 2
0 20 0 5 12
0 30 0 5 22
0 40 0 5 32
0 50 0 5 42
0 0 0 0 60 0
Output for the Sample Input 1
110
Sample Input 2
1 1
10 5 0 5 9
0 0 0 9 12 0
Output for the Sample Input 2
9
Sample Input 3
5 5
-38 -71 -293 75 1
-158 -38 -405 66 1
-236 -303 157 266 1
316 26 411 190 1
207 -312 -27 196 1
-50 292 -375 -401 389 -389
460 278 409 -329 -303 411
215 -220 -200 309 -474 300
261 -494 -87 -300 123 -463
386 378 486 -443 -64 299
Output for the Sample Input 3
0
2
1
3
0

Submitted solutions:

code_snippet: // (⁠◕⁠ᴗ⁠◕⁠✿⁠)

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define srep(i, s, n) for (ll i = s; i < (n); i++)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using vvv = vv<vc<T>>;
using vi = vc<int>;using vvi = vv<int>; using vvvi = vv<vi>;
using ll = long long;using vl = vc<ll>;using vvl = vv<ll>; using vvvl = vv<vl>;
using ld = long double; using vld = vc<ld>; using vvld = vc<vld>; using vvvld = vc<vvld>;
using uint = unsigned int;
using ull = unsigned long long;
const ld pi = 3.141592653589793;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll mod = 1000000007;
const ll mod = 998244353;
inline bool inside(ll y, ll x, ll H, ll W) {return 0 <= (y) and (y) < (H) and 0 <= (x) and (x) < (W); }

#define debug(var)  do{std::cout << #var << " : \n";view(var);}while(0)
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vc<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vv<T>& vv){ for(const auto& v : vv){ view(v); } }

ld eps = 1e-10;
int main(){
    int N, Q; cin >> N >> Q;
    vc<tuple<int, int, int, int, ll>> object(N);
    rep(i, N){
        int x, y, z, r; ll l; cin >> x >> y >> z >> r >> l;
        object[i] = {x, y, z, r, l};
    }
    vl ans;
    auto dist = [](ld x1, ld y1, ld z1, ld x2, ld y2, ld z2){
        return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2);
    };
    auto solve = [&](int sx, int sy, int sz, int dx, int dy, int dz){
        ll ret = 0;
        for (auto [x, y, z, r, l] : object){
            ld top = 1, bottom = 0;
            rep(i, 20000){
                ld c1 = bottom + (top - bottom) / 3.0, c2 = top - (top - bottom) / 3.0;
                ld x1 = sx * (1 - c1) + dx * c1, y1 = sy * (1 - c1) + dy * c1, z1 = sz * (1 - c1) + dz * c1;
                ld x2 = sx * (1 - c2) + dx * c2, y2 = sy * (1 - c2) + dy * c2, z2 = sz * (1 - c2) + dz * c2;
                if (dist(x, y, z, x1, y1, z1) < dist(x, y, z, x2, y2, z2)){
                    top = c2;
                }else bottom = c1;
            }
            ld x1 = sx * (1 - bottom) + dx * bottom, y1 = sy * (1 - bottom) + dy * bottom, z1 = sz * (1 - bottom) + dz * bottom;
            if (dist(x, y, z, x1, y1, z1) - r * r < eps) ret += l;
        }
        return ret;
    };
    while (Q--){
        int sx, sy, sz, dx, dy, dz; cin >> sx >> sy >> sz >> dx >> dy >> dz;
        ans.push_back(solve(sx, sy, sz, dx, dy, dz));
    }
    for (auto x : ans) cout << x << endl;
}
accuracy: 1
time_ms: 580
memory_kb: 3436
final_rank: 10

code_snippet: // (⁠◕⁠ᴗ⁠◕⁠✿⁠)

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define srep(i, s, n) for (ll i = s; i < (n); i++)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using vvv = vv<vc<T>>;
using vi = vc<int>;using vvi = vv<int>; using vvvi = vv<vi>;
using ll = long long;using vl = vc<ll>;using vvl = vv<ll>; using vvvl = vv<vl>;
using ld = long double; using vld = vc<ld>; using vvld = vc<vld>; using vvvld = vc<vvld>;
using uint = unsigned int;
using ull = unsigned long long;
const ld pi = 3.141592653589793;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll mod = 1000000007;
const ll mod = 998244353;
inline bool inside(ll y, ll x, ll H, ll W) {return 0 <= (y) and (y) < (H) and 0 <= (x) and (x) < (W); }

#define debug(var)  do{std::cout << #var << " : \n";view(var);}while(0)
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vc<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vv<T>& vv){ for(const auto& v : vv){ view(v); } }

int main(){
    int N, Q; cin >> N >> Q;
    vc<tuple<int, int, int, int, ll>> object(N);
    rep(i, N){
        int x, y, z, r; ll l; cin >> x >> y >> z >> r >> l;
        object[i] = {x, y, z, r, l};
    }
    vl ans;
    auto dist = [](ld x1, ld y1, ld z1, ld x2, ld y2, ld z2){
        return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2);
    };
    auto solve = [&](int sx, int sy, int sz, int dx, int dy, int dz){
        ll ret = 0;
        for (auto [x, y, z, r, l] : object){
            ld top = 1, bottom = 0;
            rep(i, 20000){
                ld c1 = bottom + (top - bottom) / 3.0, c2 = top - (top - bottom) / 3.0;
                ld x1 = sx * (1 - c1) + dx * c1, y1 = sy * (1 - c1) + dy * c1, z1 = sz * (1 - c1) + dz * c1;
                ld x2 = sx * (1 - c2) + dx * c2, y2 = sy * (1 - c2) + dy * c2, z2 = sz * (1 - c2) + dz * c2;
                if (dist(x, y, z, x1, y1, z1) < dist(x, y, z, x2, y2, z2)){
                    top = c2;
                }else bottom = c1;
            }
            ld x1 = sx * (1 - bottom) + dx * bottom, y1 = sy * (1 - bottom) + dy * bottom, z1 = sz * (1 - bottom) + dz * bottom;
            if (dist(x, y, z, x1, y1, z1) <= r * r) ret += l;
        }
        return ret;
    };
    while (Q--){
        int sx, sy, sz, dx, dy, dz; cin >> sx >> sy >> sz >> dx >> dy >> dz;
        ans.push_back(solve(sx, sy, sz, dx, dy, dz));
    }
    for (auto x : ans) cout << x << endl;
}
accuracy: 0.9821428571428571
time_ms: 560
memory_kb: 3444
final_rank: 12

code_snippet: // (⁠◕⁠ᴗ⁠◕⁠✿⁠)

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define srep(i, s, n) for (ll i = s; i < (n); i++)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using vvv = vv<vc<T>>;
using vi = vc<int>;using vvi = vv<int>; using vvvi = vv<vi>;
using ll = long long;using vl = vc<ll>;using vvl = vv<ll>; using vvvl = vv<vl>;
using ld = long double; using vld = vc<ld>; using vvld = vc<vld>; using vvvld = vc<vvld>;
using uint = unsigned int;
using ull = unsigned long long;
const ld pi = 3.141592653589793;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll mod = 1000000007;
const ll mod = 998244353;
inline bool inside(ll y, ll x, ll H, ll W) {return 0 <= (y) and (y) < (H) and 0 <= (x) and (x) < (W); }

#define debug(var)  do{std::cout << #var << " : \n";view(var);}while(0)
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vc<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vv<T>& vv){ for(const auto& v : vv){ view(v); } }

int main(){
    int N, Q; cin >> N >> Q;
    vc<tuple<int, int, int, int, ll>> object(N);
    rep(i, N){
        int x, y, z, r; ll l; cin >> x >> y >> z >> r >> l;
        object[i] = {x, y, z, r, l};
    }
    vl ans;
    auto dist = [](ld x1, ld y1, ld z1, ld x2, ld y2, ld z2){
        return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2);
    };
    auto solve = [&](int sx, int sy, int sz, int dx, int dy, int dz){
        ll ret = 0;
        for (auto [x, y, z, r, l] : object){
            ld top = 1, bottom = 0;
            rep(i, 1000){
                ld c1 = bottom + (top - bottom) / 3.0, c2 = top - (top - bottom) / 3.0;
                ld x1 = sx * (1 - c1) + dx * c1, y1 = sy * (1 - c1) + dy * c1, z1 = sz * (1 - c1) + dz * c1;
                ld x2 = sx * (1 - c2) + dx * c2, y2 = sy * (1 - c2) + dy * c2, z2 = sz * (1 - c2) + dz * c2;
                if (dist(x, y, z, x1, y1, z1) < dist(x, y, z, x2, y2, z2)){
                    top = c2;
                }else bottom = c1;
            }
            ld x1 = sx * (1 - bottom) + dx * bottom, y1 = sy * (1 - bottom) + dy * bottom, z1 = sz * (1 - bottom) + dz * bottom;
            if (dist(x, y, z, x1, y1, z1) <= r * r) ret += l;
        }
        return ret;
    };
    while (Q--){
        int sx, sy, sz, dx, dy, dz; cin >> sx >> sy >> sz >> dx >> dy >> dz;
        ans.push_back(solve(sx, sy, sz, dx, dy, dz));
    }
    for (auto x : ans) cout << x << endl;
}
accuracy: 0.9821428571428571
time_ms: 30
memory_kb: 3436
final_rank: 11

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,s,n) for(int i=(s);i<=(n);++i)
#define all(x) begin(x), end(x)
#define Fixed fixed << setprecision(12)
#define updiv(a,b) ((a + b - 1) / b)
constexpr int32_t INF  = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7;
// constexpr int mod = 998244353;

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using max_heap = priority_queue<T>;
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class A, class B> using umap = unordered_map<A,B>;
template <class A, class B> using uset = unordered_set<A,B>;

template <class T> using Set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template <class T> inline void bye(T x) { cout << x << '\n'; exit(0); }

constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};


signed main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n, q;
    cin >> n >> q;

    vector<int> x(n), y(n), z(n), r(n);
    vector<long long> l(n);

    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i] >> z[i] >> r[i] >> l[i];
    }

    auto dist = [&](auto a, auto b, auto c, auto d, auto e, auto f) -> long double {
        return ((long double) powl(a - d, 2) + powl(b - e, 2) + powl(c - f, 2));
    };

    for (int i = 0; i < q; ++i) {
        long long res = 0;
        int sx, sy, sz, dx, dy, dz;
        cin >> sx >> sy >> sz >> dx >> dy >> dz;
        for (int j = 0; j < n; ++j) {
            long double L = 0, R = 1;
            for (int k = 0; k < 500; ++k) {
                if (L > R) break;
                long double lmid = (R - L) / 3 + L;
                long double rmid = (R - L) / 3 * 2 + L;
                long double xl = (dx - sx) * lmid + sx;
                long double yl = (dy - sy) * lmid + sy;
                long double zl = (dz - sz) * lmid + sz;
                long double xr = (dx - sx) * rmid + sx;
                long double yr = (dy - sy) * rmid + sy;
                long double zr = (dz - sz) * rmid + sz;
                if (dist(xl, yl, zl, x[j], y[j], z[j]) >= dist(xr, yr, zr, x[j], y[j], z[j])) {
                    L = lmid;
                } else {
                    R = rmid;
                }
            }
            long double xp = (dx - sx) * L + sx;
            long double yp = (dy - sy) * L + sy;
            long double zp = (dz - sz) * L + sz;
            if ((long long) dist(xp, yp, zp, x[j], y[j], z[j]) <= r[j] * r[j])  {
                res += l[j];
            }
        }
        cout << res << '\n';
    }

    return(0);
}
accuracy: 1
time_ms: 10
memory_kb: 3448
final_rank: 3

code_snippet: #pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define _overload(_1, _2, _3, _4, name, ...) name
#define _rep1(Itr, N) _rep3(Itr, 0, N, 1)
#define _rep2(Itr, a, b) _rep3(Itr, a, b, 1)
#define _rep3(Itr, a, b, step) for (i64 Itr = a; Itr < b; Itr += step)
#define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)
#define rep(...) repeat(__VA_ARGS__)

#define ALL(X) begin(X), end(X)

using namespace std;
using i64 = int64_t;
using u64 = uint64_t;

struct Point {
  long double x, y, z;
  Point(long double x, long double y, long double z) : x(x), y(y), z(z){};
  Point() : x(0), y(0), z(0){};
  Point operator+(Point rhs) const {
    Point ret(x, y, z);
    ret.x += rhs.x;
    ret.y += rhs.y;
    ret.z += rhs.z;
    return ret;
  };
  Point operator-(Point rhs) const {
    Point ret(x, y, z);
    ret.x -= rhs.x;
    ret.y -= rhs.y;
    ret.z -= rhs.z;
    return ret;
  };
  Point operator*(long double d) const {
    Point ret(x, y, z);
    ret.x *= d;
    ret.y *= d;
    ret.z *= d;
    return ret;
  }
  Point operator/(long double d) const {
    Point ret(x, y, z);
    ret.x /= d;
    ret.y /= d;
    ret.z /= d;
    return ret;
  }
  long double dist() { return sqrt(x * x + y * y + z * z); };
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  i64 n, q;
  cin >> n >> q;
  vector<Point> p(n);
  vector<i64> r(n);
  vector<i64> l(n);
  rep(i, n) {
    cin >> p[i].x >> p[i].y >> p[i].z;
    cin >> r[i] >> l[i];
  }
  vector<Point> s(q);
  vector<Point> d(q);
  rep(i, q) {
    cin >> s[i].x >> s[i].y >> s[i].z;
    cin >> d[i].x >> d[i].y >> d[i].z;
  }

  const long double delta = 1e-9;
  rep(i, q) {
    i64 ans = 0;
    Point v = (d[i] - s[i]) / (d[i] - s[i]).dist();
    long double dist = (d[i] - s[i]).dist();
    rep(j, n) {
      long double a = 0;
      long double b = dist;
      rep(_, 308) {
        long double c1 = (a * 2 + b) / 3.0;
        long double c2 = (a + b * 2) / 3.0;

        if ((p[j] - (s[i] + v * c1)).dist() >=
            (p[j] - (s[i] + v * c2)).dist()) {
          a = c1;
        } else {
          b = c2;
        }
      }

      auto tmp = s[i] + v * a;
      if ((p[j] - tmp).dist() <= r[j] + delta) {
        ans += l[j];
      }
    }
    cout << ans << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3564
final_rank: 8

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,s,n) for(int i=(s);i<=(n);++i)
#define all(x) begin(x), end(x)
#define Fixed fixed << setprecision(12)
#define updiv(a,b) ((a + b - 1) / b)
constexpr int32_t INF  = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7;
// constexpr int mod = 998244353;

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using max_heap = priority_queue<T>;
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class A, class B> using umap = unordered_map<A,B>;
template <class A, class B> using uset = unordered_set<A,B>;

template <class T> using Set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template <class T> inline void bye(T x) { cout << x << '\n'; exit(0); }

constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};


signed main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n, q;
    cin >> n >> q;

    vector<int> x(n), y(n), z(n), r(n);
    vector<long long> l(n);

    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i] >> z[i] >> r[i] >> l[i];
    }

    auto dist = [&](auto a, auto b, auto c, auto d, auto e, auto f) -> long double {
        return ((long double) powl(a - d, 2) + powl(b - e, 2) + powl(c - f, 2));
    };

    for (int i = 0; i < q; ++i) {
        long long res = 0;
        int sx, sy, sz, dx, dy, dz;
        cin >> sx >> sy >> sz >> dx >> dy >> dz;
        for (int j = 0; j < n; ++j) {
            long double L = 0, R = 1;
            for (int k = 0; k < 500; ++k) {
                if (L > R) break;
                long double lmid = (R - L) / 3 + L;
                long double rmid = (R - L) / 3 * 2 + L;
                long double xl = (dx - sx) * lmid + sx;
                long double yl = (dy - sy) * lmid + sy;
                long double zl = (dz - sz) * lmid + sz;
                long double xr = (dx - sx) * rmid + sx;
                long double yr = (dy - sy) * rmid + sy;
                long double zr = (dz - sz) * rmid + sz;
                if (dist(xl, yl, zl, x[j], y[j], z[j]) >= dist(xr, yr, zr, x[j], y[j], z[j])) {
                    L = lmid;
                } else {
                    R = rmid;
                }
            }
            long double xp = (dx - sx) * L + sx;
            long double yp = (dy - sy) * L + sy;
            long double zp = (dz - sz) * L + sz;
            if ((long long) dist(xp, yp, zp, x[j], y[j], z[j]) <= r[j] * r[j])  {
                res += l[j];
            }
        }
        cout << res << '\n';
    }

    return(0);
}
accuracy: 1
time_ms: 10
memory_kb: 3484
final_rank: 4

code_snippet: #line 2 "/home/yuruhiya/programming/library/template/template.cpp"
#include <bits/stdc++.h>
#line 6 "/home/yuruhiya/programming/library/template/constants.cpp"

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)
#define rfor(i, m, n) for (int i = (m); i >= (n); --i)
#define unless(c) if (!(c))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define range_it(a, l, r) (a).begin() + (l), (a).begin() + (r)

using namespace std;
using ll = long long;
using LD = long double;
using VB = vector<bool>;
using VVB = vector<VB>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VS = vector<string>;
using VD = vector<LD>;
using PII = pair<int, int>;
using VP = vector<PII>;
using PLL = pair<ll, ll>;
using VPL = vector<PLL>;
template <class T> using PQ = priority_queue<T>;
template <class T> using PQS = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000000;
constexpr long long inf_ll = 1000000000000000000ll, MOD = 1000000007;
constexpr long double PI = 3.14159265358979323846, EPS = 1e-12;
#line 7 "/home/yuruhiya/programming/library/template/Input.cpp"
using namespace std;

#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#define fwrite_unlocked fwrite
#define fflush_unlocked fflush
#endif
class Scanner {
	static int gc() {
		return getchar_unlocked();
	}
	static char next_char() {
		char c;
		read(c);
		return c;
	}
	template <class T> static void read(T& v) {
		cin >> v;
	}
	static void read(char& v) {
		while (isspace(v = gc()))
			;
	}
	static void read(bool& v) {
		v = next_char() != '0';
	}
	static void read(string& v) {
		v.clear();
		for (char c = next_char(); !isspace(c); c = gc()) v += c;
	}
	static void read(int& v) {
		v = 0;
		bool neg = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c); c = gc()) v = v * 10 + (c - '0');
		if (neg) v = -v;
	}
	static void read(long long& v) {
		v = 0;
		bool neg = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c); c = gc()) v = v * 10 + (c - '0');
		if (neg) v = -v;
	}
	static void read(double& v) {
		v = 0;
		double dp = 1;
		bool neg = false, after_dp = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c) || c == '.'; c = gc()) {
			if (c == '.') {
				after_dp = true;
			} else if (after_dp) {
				v += (c - '0') * (dp *= 0.1);
			} else {
				v = v * 10 + (c - '0');
			}
		}
		if (neg) v = -v;
	}
	static void read(long double& v) {
		v = 0;
		long double dp = 1;
		bool neg = false, after_dp = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c) || c == '.'; c = gc()) {
			if (c == '.') {
				after_dp = true;
			} else if (after_dp) {
				v += (c - '0') * (dp *= 0.1);
			} else {
				v = v * 10 + (c - '0');
			}
		}
		if (neg) v = -v;
	}
	template <class T, class U> static void read(pair<T, U>& v) {
		read(v.first);
		read(v.second);
	}
	template <class T> static void read(vector<T>& v) {
		for (auto& e : v) read(e);
	}
	template <size_t N = 0, class T> static void read_tuple_impl(T& v) {
		if constexpr (N < tuple_size_v<T>) {
			read(get<N>(v));
			read_tuple_impl<N + 1>(v);
		}
	}
	template <class... T> static void read(tuple<T...>& v) {
		read_tuple_impl(v);
	}
	struct ReadVectorHelper {
		size_t n;
		ReadVectorHelper(size_t _n) : n(_n) {}
		template <class T> operator vector<T>() {
			vector<T> v(n);
			read(v);
			return v;
		}
	};
	struct Read2DVectorHelper {
		size_t n, m;
		Read2DVectorHelper(const pair<size_t, size_t>& nm) : n(nm.first), m(nm.second) {}
		template <class T> operator vector<vector<T>>() {
			vector<vector<T>> v(n, vector<T>(m));
			read(v);
			return v;
		}
	};

public:
	string read_line() const {
		string v;
		for (char c = gc(); c != '\n' && c != '\0'; c = gc()) v += c;
		return v;
	}
	template <class T> T read() const {
		T v;
		read(v);
		return v;
	}
	template <class T> vector<T> read_vector(size_t n) const {
		vector<T> a(n);
		read(a);
		return a;
	}
	template <class T> operator T() const {
		return read<T>();
	}
	int operator--(int) const {
		return read<int>() - 1;
	}
	ReadVectorHelper operator[](size_t n) const {
		return ReadVectorHelper(n);
	}
	Read2DVectorHelper operator[](const pair<size_t, size_t>& nm) const {
		return Read2DVectorHelper(nm);
	}
	void operator()() const {}
	template <class H, class... T> void operator()(H&& h, T&&... t) const {
		read(h);
		operator()(forward<T>(t)...);
	}

private:
	template <template <class...> class, class...> struct Multiple;
	template <template <class...> class V, class Head, class... Tail>
	struct Multiple<V, Head, Tail...> {
		template <class... Args> using vec = V<vector<Head>, Args...>;
		using type = typename Multiple<vec, Tail...>::type;
	};
	template <template <class...> class V> struct Multiple<V> { using type = V<>; };
	template <class... T> using multiple_t = typename Multiple<tuple, T...>::type;
	template <size_t N = 0, class T> void multiple_impl(T& t) const {
		if constexpr (N < tuple_size_v<T>) {
			auto& vec = get<N>(t);
			using V = typename remove_reference_t<decltype(vec)>::value_type;
			vec.push_back(read<V>());
			multiple_impl<N + 1>(t);
		}
	}

public:
	template <class... T> auto multiple(size_t h) const {
		multiple_t<T...> result;
		while (h--) multiple_impl(result);
		return result;
	}
} in;
#define inputs(T, ...) \
	T __VA_ARGS__;     \
	in(__VA_ARGS__)
#define ini(...) inputs(int, __VA_ARGS__)
#define inl(...) inputs(long long, __VA_ARGS__)
#define ins(...) inputs(string, __VA_ARGS__)
#line 5 "/home/yuruhiya/programming/library/template/Output.cpp"
#include <string_view>
#line 8 "/home/yuruhiya/programming/library/template/Output.cpp"
#include <charconv>
#line 11 "/home/yuruhiya/programming/library/template/Output.cpp"
using namespace std;

class Printer {
public:
	struct BoolString {
		string_view t, f;
		BoolString(string_view _t, string_view _f) : t(_t), f(_f) {}
	};
	struct Separator {
		string_view div, sep, last;
		Separator(string_view _div, string_view _sep, string_view _last)
		    : div(_div), sep(_sep), last(_last) {}
	};

	inline static const BoolString Yes{"Yes", "No"}, yes{"yes", "no"}, YES{"YES", "NO"},
	    Int{"1", "0"};
	inline static const Separator space{" ", " ", "\n"}, no_space{"", "", "\n"},
	    end_line{"\n", "\n", "\n"}, comma{",", ",", "\n"}, no_endl{" ", " ", ""};

	BoolString bool_str{Yes};
	Separator separator{space};

public:
	void print(int v) const {
		char buf[12]{};
		if (auto [ptr, e] = to_chars(begin(buf), end(buf), v); e == errc{}) {
			print(string_view(buf, ptr - buf));
		} else {
			assert(false);
		}
	}
	void print(long long v) const {
		char buf[21]{};
		if (auto [ptr, e] = to_chars(begin(buf), end(buf), v); e == errc{}) {
			print(string_view(buf, ptr - buf));
		} else {
			assert(false);
		}
	}
	void print(bool v) const {
		print(v ? bool_str.t : bool_str.f);
	}
	void print(vector<bool>::reference v) const {
		print(v ? bool_str.t : bool_str.f);
	}
	void print(char v) const {
		putchar_unlocked(v);
	}
	void print(string_view v) const {
		fwrite_unlocked(v.data(), sizeof(string_view::value_type), v.size(), stdout);
	}
	void print(double v) const {
		printf("%.20f", v);
	}
	void print(long double v) const {
		printf("%.20Lf", v);
	}
	template <class T> void print(const T& v) const {
		cout << v;
	}
	template <class T, class U> void print(const pair<T, U>& v) const {
		print(v.first);
		print(separator.div);
		print(v.second);
	}
	template <class InputIterater>
	void print_range(const InputIterater& begin, const InputIterater& end) const {
		for (InputIterater i = begin; i != end; ++i) {
			if (i != begin) print(separator.div);
			print(*i);
		}
	}
	template <class T> void print(const vector<T>& v) const {
		print_range(v.begin(), v.end());
	}
	template <class T, size_t N> void print(const array<T, N>& v) const {
		print_range(v.begin(), v.end());
	}
	template <class T> void print(const vector<vector<T>>& v) const {
		for (size_t i = 0; i < v.size(); ++i) {
			if (i) print(separator.last);
			print(v[i]);
		}
	}

	Printer() = default;
	Printer(const BoolString& _bool_str, const Separator& _separator)
	    : bool_str(_bool_str), separator(_separator) {}
	Printer& operator()() {
		print(separator.last);
		return *this;
	}
	template <class Head> Printer& operator()(Head&& head) {
		print(head);
		print(separator.last);
		return *this;
	}
	template <class Head, class... Tail> Printer& operator()(Head&& head, Tail&&... tail) {
		print(head);
		print(separator.sep);
		return operator()(forward<Tail>(tail)...);
	}
	template <class... Args> Printer& flag(bool f, Args&&... args) {
		if (f) {
			return operator()(forward<Args>(args)...);
		} else {
			return *this;
		}
	}
	template <class InputIterator>
	Printer& range(const InputIterator& begin, const InputIterator& end) {
		print_range(begin, end);
		print(separator.last);
		return *this;
	}
	template <class Container> Printer& range(const Container& a) {
		range(a.begin(), a.end());
		return *this;
	}
	template <class... T> void exit(T&&... t) {
		operator()(forward<T>(t)...);
		std::exit(EXIT_SUCCESS);
	}
	Printer& flush() {
		fflush_unlocked(stdout);
		return *this;
	}
	Printer& set(const BoolString& _bool_str) {
		bool_str = _bool_str;
		return *this;
	}
	Printer& set(const Separator& _separator) {
		separator = _separator;
		return *this;
	}
	Printer& set(string_view t, string_view f) {
		bool_str = BoolString(t, f);
		return *this;
	}
} out;
#line 6 "/home/yuruhiya/programming/library/template/Step.cpp"

template <class T> class step_iterator {
public:
	using value_type = T;
	using difference_type = T;
	using iterator_category = std::random_access_iterator_tag;
	using reference = T&;
	using pointer = T*;

private:
	value_type start_m, size_m, step_m, index_m;

public:
	constexpr step_iterator()
	    : start_m(value_type()), size_m(value_type()), step_m(value_type()), index_m(0) {}
	constexpr step_iterator(value_type _start, value_type _size, value_type _step)
	    : start_m(_start), size_m(_size), step_m(_step), index_m(0) {}
	value_type operator*() const noexcept {
		return value();
	}
	step_iterator& operator++() noexcept {
		++index_m;
		return *this;
	}
	step_iterator& operator++(int) noexcept {
		auto tmp = *this;
		++*this;
		return tmp;
	}
	step_iterator& operator--() noexcept {
		--index_m;
		return *this;
	}
	step_iterator& operator--(int) noexcept {
		auto tmp = *this;
		--*this;
		return tmp;
	}
	step_iterator& operator+=(difference_type n) {
		index_m += n;
		return *this;
	}
	step_iterator operator+(difference_type n) const {
		return step_iterator(*this) += n;
	}
	friend step_iterator operator+(difference_type n, step_iterator i) {
		return i + n;
	}
	step_iterator& operator-=(difference_type n) {
		index_m -= n;
		return *this;
	}
	step_iterator operator-(difference_type n) const {
		return step_iterator(*this) -= n;
	}
	friend step_iterator operator-(difference_type n, step_iterator i) {
		return i - n;
	}
	difference_type operator-(const step_iterator& other) const {
		assert(start_m == other.start_m);
		assert(size_m == other.size_m);
		assert(step_m == other.step_m);
		return index_m - other.index_m;
	}
	bool operator==(const step_iterator& other) const noexcept {
		return value() == other.value();
	}
	bool operator!=(const step_iterator& other) const noexcept {
		return value() != other.value();
	}
	bool operator<(const step_iterator& other) const noexcept {
		return value() < other.value();
	}
	bool operator<=(const step_iterator& other) const noexcept {
		return value() <= other.value();
	}
	bool operator>(const step_iterator& other) const noexcept {
		return value() > other.value();
	}
	bool operator>=(const step_iterator& other) const noexcept {
		return value() >= other.value();
	}
	constexpr value_type value() const noexcept {
		return start_m + step_m * index_m;
	}
};

template <class T> class Step {
public:
	using value_type = T;
	using iterator = step_iterator<value_type>;

private:
	value_type start_m, size_m, step_m;

public:
	constexpr Step(value_type _start, value_type _size, value_type _step)
	    : start_m(_start), size_m(std::max<value_type>(0, _size)), step_m(_step) {}
	constexpr iterator begin() const {
		return iterator(start_m, size_m, step_m);
	}
	constexpr iterator end() const {
		return iterator(start_m, size_m, step_m) + size_m;
	}
	constexpr value_type start() const {
		return start_m;
	}
	constexpr value_type size() const {
		return size_m;
	}
	constexpr value_type step() const {
		return step_m;
	}
	constexpr value_type sum() const {
		return start() * size() + step() * (size() * (size() - 1) / 2);
	}
	operator std::vector<value_type>() const {
		return to_a();
	}
	auto to_a() const {
		std::vector<value_type> result;
		result.reserve(size());
		for (auto i : *this) {
			result.push_back(i);
		}
		return result;
	}
};
template <class T> constexpr auto upto(T from, T to) {
	return Step<T>(from, to - from + 1, 1);
}
template <class T> constexpr auto downto(T from, T to) {
	return Step<T>(from, from - to + 1, -1);
}
template <class T> constexpr auto times(T n, bool exclusive = false) {
	return Step<T>(0, n + static_cast<T>(exclusive), 1);
}
#line 8 "/home/yuruhiya/programming/library/template/Ruby.cpp"
using namespace std;

template <class F> struct Callable {
	F func;
	Callable(const F& f) : func(f) {}
};
template <class T, class F> auto operator|(const T& v, const Callable<F>& c) {
	return c.func(v);
}

struct Sort_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v), f);
			return v;
		});
	}
	template <class T> friend auto operator|(T v, [[maybe_unused]] const Sort_impl& c) {
		sort(begin(v), end(v));
		return v;
	}
} Sort;
struct SortBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v), [&](const auto& i, const auto& j) { return f(i) < f(j); });
			return v;
		});
	}
} SortBy;
struct RSort_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(rbegin(v), rend(v), f);
			return v;
		});
	}
	template <class T> friend auto operator|(T v, [[maybe_unused]] const RSort_impl& c) {
		sort(rbegin(v), rend(v));
		return v;
	}
} RSort;
struct RSortBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v), [&](const auto& i, const auto& j) { return f(i) > f(j); });
			return v;
		});
	}
} RSortBy;
struct Reverse_impl {
	template <class T> friend auto operator|(T v, const Reverse_impl& c) {
		reverse(begin(v), end(v));
		return v;
	}
} Reverse;
struct Unique_impl {
	template <class T> friend auto operator|(T v, const Unique_impl& c) {
		v.erase(unique(begin(v), end(v), end(v)));
		return v;
	}
} Unique;
struct Uniq_impl {
	template <class T> friend auto operator|(T v, const Uniq_impl& c) {
		sort(begin(v), end(v));
		v.erase(unique(begin(v), end(v)), end(v));
		return v;
	}
} Uniq;
struct Rotate_impl {
	auto operator()(int&& left) {
		return Callable([&](auto v) {
			int s = static_cast<int>(size(v));
			assert(-s <= left && left <= s);
			if (0 <= left) {
				rotate(begin(v), begin(v) + left, end(v));
			} else {
				rotate(begin(v), end(v) + left, end(v));
			}
			return v;
		});
	}
} Rotate;
struct Max_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) { return *max_element(begin(v), end(v), f); });
	}
	template <class T> friend auto operator|(T v, const Max_impl& c) {
		return *max_element(begin(v), end(v));
	}
} Max;
struct Min_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) { return *min_element(begin(v), end(v), f); });
	}
	template <class T> friend auto operator|(T v, const Min_impl& c) {
		return *min_element(begin(v), end(v));
	}
} Min;
struct MaxPos_impl {
	template <class T> friend auto operator|(T v, const MaxPos_impl& c) {
		return max_element(begin(v), end(v)) - begin(v);
	}
} MaxPos;
struct MinPos_impl {
	template <class T> friend auto operator|(T v, const MinPos_impl& c) {
		return min_element(begin(v), end(v)) - begin(v);
	}
} MinPos;
struct MaxBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto max_it = begin(v);
			auto max_val = f(*max_it);
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); max_val < val) {
					max_it = it;
					max_val = val;
				}
			}
			return *max_it;
		});
	}
} MaxBy;
struct MinBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto min_it = begin(v);
			auto min_val = f(*min_it);
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); min_val > val) {
					min_it = it;
					min_val = val;
				}
			}
			return *min_it;
		});
	}
} MinBy;
struct MaxOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto max_val = f(*begin(v));
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); max_val < val) {
					max_val = val;
				}
			}
			return max_val;
		});
	}
} MaxOf;
struct MinOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto min_val = f(*begin(v));
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); min_val > val) {
					min_val = val;
				}
			}
			return min_val;
		});
	}
} MinOf;
struct Count_impl {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) { return count(begin(v), end(v), val); });
	}
} Count;
struct CountIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) { return count_if(begin(v), end(v), f); });
	}
} CountIf;
struct Index_impl {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) -> optional<int> {
			auto result = find(begin(v), end(v), val);
			return result != end(v) ? optional(result - begin(v)) : nullopt;
		});
	}
	template <class V> auto operator()(const V& val, size_t i) {
		return Callable([&](auto v) -> optional<int> {
			auto result = find(next(begin(v), i), end(v), val);
			return result != end(v) ? optional(result - begin(v)) : nullopt;
		});
	}
} Index;
struct IndexIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) -> optional<int> {
			auto result = find_if(begin(v), end(v), f);
			return result != end(v) ? optional(result - begin(v)) : nullopt;
		});
	}
} IndexIf;
struct FindIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) -> optional<typename decltype(v)::value_type> {
			auto result = find_if(begin(v), end(v), f);
			return result != end(v) ? optional(*result) : nullopt;
		});
	}
} FindIf;
struct Sum_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			return accumulate(next(begin(v)), end(v), f(*begin(v)),
			                  [&](const auto& a, const auto& b) { return a + f(b); });
		});
	}
	template <class T> friend auto operator|(T v, [[maybe_unused]] const Sum_impl& c) {
		return accumulate(begin(v), end(v), typename T::value_type{});
	}
} Sum;
struct Includes {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) { return find(begin(v), end(v), val) != end(v); });
	}
} Includes;
struct IncludesIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) { return find_if(begin(v), end(v), f) != end(v); });
	}
} IncludesIf;
struct RemoveIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) {
			v.erase(remove_if(begin(v), end(v), f), end(v));
			return v;
		});
	}
} RemoveIf;
struct Each_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				f(i);
			}
		});
	}
} Each;
struct EachConsPair_impl {
	template <class T, class value_type = typename T::value_type>
	friend auto operator|(const T& v, EachConsPair_impl& c) {
		vector<pair<value_type, value_type>> result;
		if (size(v) >= 2) {
			result.reserve(size(v) - 1);
			for (size_t i = 0; i < size(v) - 1; ++i) {
				result.emplace_back(v[i], v[i + 1]);
			}
		}
		return result;
	}
} EachConsPair;
struct Select_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			using value_type = typename decltype(v)::value_type;
			vector<value_type> result;
			for (const auto& i : v) {
				if (f(i)) result.push_back(i);
			}
			return result;
		});
	}
} Select;
struct Map_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			using result_type = invoke_result_t<F, typename decltype(v)::value_type>;
			vector<result_type> result;
			result.reserve(size(v));
			for (const auto& i : v) {
				result.push_back(f(i));
			}
			return result;
		});
	}
} Map;
struct Indexed_impl {
	template <class T> friend auto operator|(const T& v, Indexed_impl& c) {
		using value_type = typename T::value_type;
		vector<pair<value_type, int>> result;
		result.reserve(size(v));
		int index = 0;
		for (const auto& i : v) {
			result.emplace_back(i, index++);
		}
		return result;
	}
} Indexed;
struct AllOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (!f(i)) return false;
			}
			return true;
		});
	}
} AllOf;
struct AnyOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (f(i)) return true;
			}
			return false;
		});
	}
} AnyOf;
struct NoneOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (f(i)) return false;
			}
			return true;
		});
	}
} NoneOf;

struct Tally_impl {
	template <class F> auto operator()(size_t max_val) {
		return Callable([&](auto v) {
			vector<size_t> result(max_val);
			for (const auto& i : v) {
				result[static_cast<size_t>(i)]++;
			}
			return result;
		});
	}
	template <class T, class value_type = typename T::value_type>
	friend auto operator|(const T& v, Tally_impl& c) {
		map<value_type, size_t> result;
		for (const auto& i : v) {
			result[i]++;
		}
		return result;
	}
} Tally;

template <class T> auto operator*(const vector<T>& a, size_t n) {
	T result;
	for (size_t i = 0; i < n; ++i) {
		result.insert(result.end(), a.begin(), a.end());
	}
	return result;
}
auto operator*(string a, size_t n) {
	string result;
	for (size_t i = 0; i < n; ++i) {
		result += a;
	}
	return result;
}
template <class T, class U> auto& operator<<(vector<T>& a, const U& b) {
	a.insert(a.end(), all(b));
	return a;
}
template <class T> auto& operator<<(string& a, const T& b) {
	a.insert(a.end(), all(b));
	return a;
}
template <class T, class U> auto operator+(vector<T> a, const U& b) {
	a << b;
	return a;
}
template <class T> auto operator+(string a, const T& b) {
	a << b;
	return a;
}
#line 7 "/home/yuruhiya/programming/library/template/functions.cpp"
using namespace std;

template <class T = long long> constexpr T TEN(size_t n) {
	T result = 1;
	for (size_t i = 0; i < n; ++i) result *= 10;
	return result;
}
template <class T, class U,
          enable_if_t<is_integral_v<T> && is_integral_v<U>, nullptr_t> = nullptr>
constexpr auto div_ceil(T n, U m) {
	return (n + m - 1) / m;
}
template <class T, class U> constexpr auto div_ceil2(T n, U m) {
	return div_ceil(n, m) * m;
}
template <class T> constexpr T triangle(T n) {
	return (n & 1) ? (n + 1) / 2 * n : n / 2 * (n + 1);
}
template <class T> constexpr T nC2(T n) {
	return (n & 1) ? (n - 1) / 2 * n : n / 2 * (n - 1);
}
template <class T, class U> constexpr auto middle(const T& l, const U& r) {
	return l + (r - l) / 2;
}
template <class T, class U, class V>
constexpr bool in_range(const T& v, const U& lower, const V& upper) {
	return lower <= v && v < upper;
}
template <class T, enable_if_t<is_integral_v<T>, nullptr_t> = nullptr>
constexpr bool is_square(T n) {
	T s = sqrt(n);
	return s * s == n || (s + 1) * (s + 1) == n;
}
template <class T = long long> constexpr T BIT(int b) {
	return T(1) << b;
}
template <class T> constexpr int BIT(T x, int i) {
	return (x & (T(1) << i)) ? 1 : 0;
}
template <class T> constexpr int Sgn(T x) {
	return (0 < x) - (0 > x);
}
template <class T, class U, enable_if_t<is_integral_v<U>, nullptr_t> = nullptr>
constexpr T Pow(T a, U n) {
	assert(n >= 0);
	T result = 1;
	while (n > 0) {
		if (n & 1) {
			result *= a;
			n--;
		} else {
			a *= a;
			n >>= 1;
		}
	}
	return result;
}
template <class T, class U, enable_if_t<is_integral_v<U>, nullptr_t> = nullptr>
constexpr T Powmod(T a, U n, T mod) {
	assert(n >= 0);
	if (a > mod) a %= mod;
	T result = 1;
	while (n > 0) {
		if (n & 1) {
			result = result * a % mod;
			n--;
		} else {
			a = a * a % mod;
			n >>= 1;
		}
	}
	return result;
}
template <class T> bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> int sz(const T& v) {
	return v.size();
}
template <class T, class U> int lower_index(const T& a, const U& v) {
	return lower_bound(all(a), v) - a.begin();
}
template <class T, class U> int upper_index(const T& a, const U& v) {
	return upper_bound(all(a), v) - a.begin();
}
template <class T> auto Slice(const T& v, size_t i, size_t len) {
	return i < v.size() ? T(v.begin() + i, v.begin() + min(i + len, v.size())) : T();
}
template <class T, class U = typename T::value_type> U Gcdv(const T& v) {
	return accumulate(next(v.begin()), v.end(), U(*v.begin()), gcd<U, U>);
}
template <class T, class U = typename T::value_type> U Lcmv(const T& v) {
	return accumulate(next(v.begin()), v.end(), U(*v.begin()), lcm<U, U>);
}
namespace internal {
	template <class T, size_t N> auto make_vector(vector<int>& sizes, const T& init) {
		if constexpr (N == 1) {
			return vector(sizes[0], init);
		} else {
			int size = sizes[N - 1];
			sizes.pop_back();
			return vector(size, make_vector<T, N - 1>(sizes, init));
		}
	}
}  // namespace internal
template <class T, size_t N> auto make_vector(const int (&sizes)[N], const T& init = T()) {
	vector s(rbegin(sizes), rend(sizes));
	return internal::make_vector<T, N>(s, init);
}
#line 9 "/home/yuruhiya/programming/library/template/template.cpp"
#if __has_include(<library/dump.hpp>)
#include <library/dump.hpp>
#define LOCAL
#else
#define dump(...) ((void)0)
#endif

template <class T> constexpr T oj_local(const T& oj, const T& local) {
#ifndef LOCAL
	return oj;
#else
	return local;
#endif
}
#line 2 "a.cpp"

struct Vec3 {
	LD x, y, z;
	Vec3() = default;
	Vec3(LD _x, LD _y, LD _z) : x(_x), y(_y), z(_z) {}
#define DEFINE_VEC3_OPERATOR(op)                               \
	Vec3 operator op(const Vec3& other) {                      \
		return Vec3(x op other.x, y op other.y, z op other.z); \
	}                                                          \
	Vec3 operator op(LD val) {                                 \
		return Vec3(x op val, y op val, z op val);             \
	}

	DEFINE_VEC3_OPERATOR(+);
	DEFINE_VEC3_OPERATOR(-);
	DEFINE_VEC3_OPERATOR(*);

	friend istream& operator>>(istream& is, Vec3& v) {
		return is >> v.x >> v.y >> v.z;
	}
};

LD dist(const Vec3& p1, const Vec3& p2) {
	return hypot(p1.x - p2.x, p1.y - p2.y, p1.z - p2.z);
}

Vec3 calc_point(Vec3 from, Vec3 to, LD ratio) {
	return from + (to - from) * ratio;
}

template <class F> LD TernarySearch(LD lower, LD upper, F f) {
	rep(_, 200) {
		LD c1 = lower + (upper - lower) / 3 * 1;
		LD c2 = lower + (upper - lower) / 3 * 2;
		if (f(c1) < f(c2)) {
			upper = c2;
		} else {
			lower = c1;
		}
	}
	return lower;
}

int main() {
	int n = in, q = in;
	auto [center, radius, score] = in.multiple<Vec3, LD, ll>(n);

	rep(_, q) {
		Vec3 s = in, t = in;
		ll ans = 0;
		rep(i, n) {
			LD val = TernarySearch(0, 1, [&](LD x) {
				Vec3 point = calc_point(s, t, x);
				return dist(center[i], point);
			});
			if (dist(center[i], calc_point(s, t, val)) <= radius[i]) {
				ans += score[i];
			}
		}
		out(ans);
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3524
final_rank: 7

code_snippet: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#define DIVIDE 10000.0
const int INF = 1e9;
const double EPS = 0.00001;
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    ld x[n + 1], y[n + 1], z[n + 1], r[n + 1], l[n + 1];
    for(int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i] >> z[i] >> r[i]>> l[i];
    }
    ld sx, sy, sz, dx, dy, dz;
    for(int i = 0; i < m; i++)
    {
        cin >> sx >> sy >> sz >> dx >> dy >> dz;
        ld ax = (ld)(sx - dx) / DIVIDE;
        ld ay = (ld)(sy - dy) / DIVIDE;
        ld az = (ld)(sz - dz) / DIVIDE;
 
        ld bx = sx;
        ld by = sy;
        ld bz = sz;
        bool flag[n + 1] = {};
        ll ans = 0;
        for(int j = 0; j <= DIVIDE; j++)
        {
            for(int k = 0; k < n; k++)
            {
                ld cx = bx - x[k];
                ld cy = by - y[k];
                ld cz = bz - z[k];
                ld dist = cx * cx + cy * cy + cz * cz;
                if(dist - r[k] * r[k] <= EPS)
                    flag[k] = true;
            }
            bx -= ax;
            by -= ay;
            bz -= az;
        }
        for(int j = 0; j < n; j++)
            if(flag[j])
                ans += l[j];
        cout << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3300
final_rank: 5

code_snippet: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#define DIVIDE 10000.0
const int INF = 1e9;
const double EPS = 0.00001;
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	ld x[n + 1], y[n + 1], z[n + 1], r[n + 1], l[n + 1];
	for(int i = 0; i < n; i++)
	{
		cin >> x[i] >> y[i] >> z[i] >> r[i]>> l[i];
	}
	ld sx, sy, sz, dx, dy, dz;
	for(int i = 0; i < m; i++)
	{
		cin >> sx >> sy >> sz >> dx >> dy >> dz;
		ld ax = (ld)(sx - dx) / DIVIDE;
		ld ay = (ld)(sy - dy) / DIVIDE;
		ld az = (ld)(sz - dz) / DIVIDE;

		ld bx = sx;
		ld by = sy;
		ld bz = sz;
		bool flag[n + 1] = {};
		ll ans = 0;
		for(int j = 0; j <= DIVIDE; j++)
		{
			for(int k = 0; k < n; k++)
			{
				ld cx = bx - x[k];
				ld cy = by - y[k];
				ld cz = bz - z[k];
				ld dist = cx * cx + cy * cy + cz * cz;
				if(dist - r[k] * r[k] <= EPS)
					flag[k] = true;
			}
			bx -= ax;
			by -= ay;
			bz -= az;
		}
		for(int j = 0; j < n; j++)
			if(flag[j])
				ans += l[j];
		cout << ans << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3308
final_rank: 6

code_snippet: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#define DIVIDE 10000.0
const int INF = 1e9;
const double EPS = 0.00001;
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	ld x[n + 1], y[n + 1], z[n + 1], r[n + 1], l[n + 1];
	for(int i = 0; i < n; i++)
	{
		cin >> x[i] >> y[i] >> z[i] >> r[i]>> l[i];
	}
	ld sx, sy, sz, dx, dy, dz;
	for(int i = 0; i < m; i++)
	{
		cin >> sx >> sy >> sz >> dx >> dy >> dz;
		ld ax = (ld)(sx - dx) / DIVIDE;
		ld ay = (ld)(sy - dy) / DIVIDE;
		ld az = (ld)(sz - dz) / DIVIDE;

		ld bx = sx;
		ld by = sy;
		ld bz = sz;
		bool flag[n + 1] = {};
		int ans = 0;
		for(int j = 0; j <= DIVIDE; j++)
		{
			for(int k = 0; k < n; k++)
			{
				ld cx = bx - x[k];
				ld cy = by - y[k];
				ld cz = bz - z[k];
				ld dist = cx * cx + cy * cy + cz * cz;
				if(dist - r[k] * r[k] <= EPS)
					flag[k] = true;
			}
			bx -= ax;
			by -= ay;
			bz -= az;
		}
		for(int j = 0; j < n; j++)
			if(flag[j])
				ans += l[j];
		cout << ans << endl;
	}
	return 0;
}
accuracy: 0.875
time_ms: 50
memory_kb: 3308
final_rank: 15

code_snippet: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#define DIVIDE 10000
const int INF = 1e9;
const double EPS = 0.00001;
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	ld x[n + 1], y[n + 1], z[n + 1], r[n + 1], l[n + 1];
	for(int i = 0; i < n; i++)
	{
		cin >> x[i] >> y[i] >> z[i] >> r[i]>> l[i];
	}
	ld sx, sy, sz, dx, dy, dz;
	for(int i = 0; i < m; i++)
	{
		cin >> sx >> sy >> sz >> dx >> dy >> dz;
		ld ax = (ld)(sx - dx) / DIVIDE;
		ld ay = (ld)(sy - dy) / DIVIDE;
		ld az = (ld)(sz - dz) / DIVIDE;

		ld bx = sx;
		ld by = sy;
		ld bz = sz;
		bool flag[60] = {};
		int ans = 0;
		for(int j = 0; j <= DIVIDE; j++)
		{
			for(int k = 0; k < n; k++)
			{
				ld cx = bx - x[k];
				ld cy = by - y[k];
				ld cz = bz - z[k];
				ld dist = cx * cx + cy * cy + cz * cz;
				if(dist - r[k] * r[k] <= EPS)
					flag[k] = true;
			}
			bx -= ax;
			by -= ay;
			bz -= az;
		}
		for(int j = 0; j < n; j++)
			if(flag[j])
				ans += l[j];
		cout << ans << endl;
	}
	return 0;
}
accuracy: 0.875
time_ms: 50
memory_kb: 3308
final_rank: 15

code_snippet: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#define DIVIDE 10000
const int INF = 1e9;
const double EPS = 0.00001;
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	double x[n + 1], y[n + 1], z[n + 1], r[n + 1], l[n + 1];
	for(int i = 0; i < n; i++)
	{
		cin >> x[i] >> y[i] >> z[i] >> r[i]>> l[i];
	}
	double sx, sy, sz, dx, dy, dz;
	for(int i = 0; i < m; i++)
	{
		cin >> sx >> sy >> sz >> dx >> dy >> dz;
		double ax = (double)(sx - dx) / DIVIDE;
		double ay = (double)(sy - dy) / DIVIDE;
		double az = (double)(sz - dz) / DIVIDE;

		double bx = sx;
		double by = sy;
		double bz = sz;
		bool flag[m + 1] = {};
		int ans = 0;
		for(int j = 0; j <= DIVIDE; j++)
		{
			for(int k = 0; k < n; k++)
			{
				double cx = bx - x[k];
				double cy = by - y[k];
				double cz = bz - z[k];
				double dist = cx * cx + cy * cy + cz * cz;
				if(dist - r[k] * r[k] <= EPS)
					flag[k] = true;
			}
			bx -= ax;
			by -= ay;
			bz -= az;
		}
		for(int j = 0; j < n; j++)
			if(flag[j])
				ans += l[j];
		cout << ans << endl;
	}
	return 0;
}
accuracy: 0.875
time_ms: 30
memory_kb: 3300
final_rank: 13

code_snippet: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#define DIVIDE 10000
const int INF = 1e9;
const double EPS = 0.000001;
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	while(cin >> n >> m)
	{
		double x[n + 1], y[n + 1], z[n + 1], r[n + 1], l[n + 1];
		for(int i = 0; i < n; i++)
		{
			cin >> x[i] >> y[i] >> z[i] >> r[i]>> l[i];
		}
		double sx, sy, sz, dx, dy, dz;
		for(int i = 0; i < m; i++)
		{
			cin >> sx >> sy >> sz >> dx >> dy >> dz;
			double ax = (double)(sx - dx) / DIVIDE;
			double ay = (double)(sy - dy) / DIVIDE;
			double az = (double)(sz - dz) / DIVIDE;

			double bx = sx;
			double by = sy;
			double bz = sz;
			bool flag[m + 1] = {};
			int ans = 0;
			for(int j = 0; j <= DIVIDE; j++)
			{
				for(int k = 0; k < n; k++)
				{
					double cx = bx - x[k];
					double cy = by - y[k];
					double cz = bz - z[k];
					double dist = cx * cx + cy * cy + cz * cz;
					if(dist - r[k] * r[k] <= EPS)
						flag[k] = true;
				}
				bx -= ax;
				by -= ay;
				bz -= az;
			}
			for(int j = 0; j < n; j++)
				if(flag[j])
					ans += l[j];
			cout << ans << endl;
		}
	}
	return 0;
}
accuracy: 0.875
time_ms: 30
memory_kb: 3304
final_rank: 14

code_snippet: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-8;

long long int N, M, K, H, W, L, R;

struct Enemy {
	long double x;
	long double y;
	long double z;
	long double r;
	long long int cost;
};

struct Place {
	long double sx;
	long double sy;
	long double sz;
	long double gx;
	long double gy;
	long double gz;
	long double dis;
	void Cal() {
		dis = sqrt(pow(sx - gx, 2) + pow(sy - gy, 2) + pow(sz - gz, 2));
		return;
	}
};

long double dist(long double x,long double y,long double z, Enemy e) {
	return sqrt(pow(x - e.x, 2) + pow(y - e.y, 2) + pow(z - e.z, 2));
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N >> M;
	vector<Enemy>e(N);
	for (int i = 0; i < N; i++) {
		cin >> e[i].x >> e[i].y >> e[i].z >> e[i].r >> e[i].cost;
	}
	vector<Place>p(M);
	for (int i = 0; i < M; i++) {
		cin >> p[i].sx >> p[i].sy >> p[i].sz >> p[i].gx >> p[i].gy >> p[i].gz;
		p[i].Cal();
	}
	vector<long long int>ans(M);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			long double l = 0;
			long double r = p[j].dis;
			for (int k = 0; k < 200; k++) {
				long double ml = (l + l + r) / 3;
				long double mr = (l + r + r) / 3;
				long double lx, ly, lz, rx, ry, rz;
				lx = p[j].sx + (p[j].gx - p[j].sx)*ml / p[j].dis;
				ly = p[j].sy + (p[j].gy - p[j].sy)*ml / p[j].dis;
				lz = p[j].sz + (p[j].gz - p[j].sz)*ml / p[j].dis;
				rx = p[j].sx + (p[j].gx - p[j].sx)*mr / p[j].dis;
				ry = p[j].sy + (p[j].gy - p[j].sy)*mr / p[j].dis;
				rz = p[j].sz + (p[j].gz - p[j].sz)*mr / p[j].dis;
				long double ld, rd;
				ld = dist(lx, ly, lz, e[i]);
				rd = dist(rx, ry, rz, e[i]);
				if (ld < rd) {
					r = mr;
				}
				else {
					l = ml;
				}
				if (k == 199) {
					if (min(ld,rd) - EPS <= e[i].r) {
						ans[j] += e[i].cost;
					}
				}
			}
		}
	}
	for (auto i : ans) {
		cout << i << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3280
final_rank: 2

code_snippet: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-8;

long long int N, M, K, H, W, L, R;

struct Enemy {
	long double x;
	long double y;
	long double z;
	long double r;
	long double cost;
};

struct Place {
	long double sx;
	long double sy;
	long double sz;
	long double gx;
	long double gy;
	long double gz;
	long double dis;
	void Cal() {
		dis = sqrt(pow(sx - gx, 2) + pow(sy - gy, 2) + pow(sz - gz, 2));
		return;
	}
};

long double dist(long double x,long double y,long double z, Enemy e) {
	return sqrt(pow(x - e.x, 2) + pow(y - e.y, 2) + pow(z - e.z, 2));
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N >> M;
	vector<Enemy>e(N);
	for (int i = 0; i < N; i++) {
		cin >> e[i].x >> e[i].y >> e[i].z >> e[i].r >> e[i].cost;
	}
	vector<Place>p(M);
	for (int i = 0; i < M; i++) {
		cin >> p[i].sx >> p[i].sy >> p[i].sz >> p[i].gx >> p[i].gy >> p[i].gz;
		p[i].Cal();
	}
	vector<long double>ans(M);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			long double l = 0;
			long double r = p[j].dis;
			for (int k = 0; k < 200; k++) {
				long double ml = (l + l + r) / 3;
				long double mr = (l + r + r) / 3;
				long double lx, ly, lz, rx, ry, rz;
				lx = p[j].sx + (p[j].gx - p[j].sx)*ml / p[j].dis;
				ly = p[j].sy + (p[j].gy - p[j].sy)*ml / p[j].dis;
				lz = p[j].sz + (p[j].gz - p[j].sz)*ml / p[j].dis;
				rx = p[j].sx + (p[j].gx - p[j].sx)*mr / p[j].dis;
				ry = p[j].sy + (p[j].gy - p[j].sy)*mr / p[j].dis;
				rz = p[j].sz + (p[j].gz - p[j].sz)*mr / p[j].dis;
				long double ld, rd;
				ld = dist(lx, ly, lz, e[i]);
				rd = dist(rx, ry, rz, e[i]);
				if (ld < rd) {
					r = mr;
				}
				else {
					l = ml;
				}
				if (k == 199) {
					if (min(ld,rd) - EPS <= e[i].r) {
						ans[j] += e[i].cost;
					}
				}
			}
		}
	}
	for (auto i : ans) {
		cout << i << endl;
	}
	return 0;
}
accuracy: 0.19642857142857142
time_ms: 10
memory_kb: 3280
final_rank: 17

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define EPS 1e-7
using namespace std;

int n, q;

int x[50], y[50], z[50], r[50];
long long l[50];

int main(){
	cin >> n >> q;
	rep(i,n) scanf("%d%d%d%d%lld",x+i,y+i,z+i,r+i,l+i);
	rep(i,q){
		int sx, sy, sz, dx, dy, dz;
		scanf("%d%d%d%d%d%d",&sx,&sy,&sz,&dx,&dy,&dz);
		long long ans = 0;
		rep(u,n){
			double s = 0.0, e = 1.0, smid, emid;
			double sd, ed;
			sd = sqrt(pow(sx-x[u],2.0)+pow(sy-y[u],2.0)+pow(sz-z[u],2.0));
			ed = sqrt(pow(dx-x[u],2.0)+pow(dy-y[u],2.0)+pow(dz-z[u],2.0));
			rep(j,1000){
				smid = s + (e-s)/3;
				emid = e - (e-s)/3;
				double sxx = sx + smid*(dx-sx);
				double syy = sy + smid*(dy-sy);
				double szz = sz + smid*(dz-sz);
				double exx = sx + emid*(dx-sx);
				double eyy = sy + emid*(dy-sy);
				double ezz = sz + emid*(dz-sz);
				if(sqrt(pow(sxx-x[u],2.0)+pow(syy-y[u],2.0)+pow(szz-z[u],2.0)) > sqrt(pow(exx-x[u],2.0)+pow(eyy-y[u],2.0)+pow(ezz-z[u],2.0))){
					sd = sqrt(pow(sxx-x[u],2.0)+pow(syy-y[u],2.0)+pow(szz-z[u],2.0));
					s = smid;
				} else{
					ed = sqrt(pow(exx-x[u],2.0)+pow(eyy-y[u],2.0)+pow(ezz-z[u],2.0));
					e = emid;
				}
			}
			if(sd < r[u]+EPS) ans += l[u];
		}
		cout << ans << endl;
	}
}
accuracy: 1
time_ms: 50
memory_kb: 1244
final_rank: 1

code_snippet: #include <iostream>

#pragma warning(disable : 4996)

#define STEPS 100000

using namespace std;

int N, Q, x[50], y[50], z[50], r[50], sx, sy, sz, dx, dy, dz; long long l[50]; bool used[50];

int main()
{
	scanf("%d", &N);
	scanf("%d", &Q);

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &x[i]);
		scanf("%d", &y[i]);
		scanf("%d", &z[i]);
		scanf("%d", &r[i]);

		scanf("%lld", &l[i]);
	}

	for (int i = 0; i < Q; i++)
	{
		scanf("%d", &sx);
		scanf("%d", &sy);
		scanf("%d", &sz);
		scanf("%d", &dx);
		scanf("%d", &dy);
		scanf("%d", &dz);

		long double vx = 1.0 * (sx - dx) / STEPS;
		long double vy = 1.0 * (sy - dy) / STEPS;
		long double vz = 1.0 * (sz - dz) / STEPS;

		long double tx = sx;
		long double ty = sy;
		long double tz = sz;

		for (int j = 0; j < N; j++) used[j] = false;

		for (int j = 0; j <= STEPS; j++)
		{
			for (int k = 0; k < N; k++)
			{
				long double rx = tx - x[k];
				long double ry = ty - y[k];
				long double rz = tz - z[k];

				if (rx * rx + ry * ry + rz * rz <= r[k] * r[k] + 0.00001)
				{
					used[k] = true;
				}
			}

			tx -= vx;
			ty -= vy;
			tz -= vz;
		}

		long long ret = 0;

		for (int j = 0; j < N; j++)
		{
			if (used[j])
			{
				ret += l[j];
			}
		}

		printf("%lld\n", ret);
	}

	return 0;
}
accuracy: 1
time_ms: 500
memory_kb: 3212
final_rank: 9

code_snippet: #include <iostream>

#pragma warning(disable : 4996)

#define STEPS 10000000

using namespace std;

int N, Q, x[50], y[50], z[50], r[50], sx, sy, sz, dx, dy, dz; long long l[50]; bool used[50];

int main()
{
	scanf("%d", &N);
	scanf("%d", &Q);

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &x[i]);
		scanf("%d", &y[i]);
		scanf("%d", &z[i]);
		scanf("%d", &r[i]);

		scanf("%lld", &l[i]);
	}

	for (int i = 0; i < Q; i++)
	{
		scanf("%d", &sx);
		scanf("%d", &sy);
		scanf("%d", &sz);
		scanf("%d", &dx);
		scanf("%d", &dy);
		scanf("%d", &dz);

		long double vx = 1.0 * (sx - dx) / STEPS;
		long double vy = 1.0 * (sy - dy) / STEPS;
		long double vz = 1.0 * (sz - dz) / STEPS;

		long double tx = sx;
		long double ty = sy;
		long double tz = sz;

		for (int j = 0; j < N; j++) used[j] = false;

		for (int j = 0; j <= STEPS; j++)
		{
			for (int k = 0; k < N; k++)
			{
				long double rx = tx - x[i];
				long double ry = ty - y[i];
				long double rz = tz - z[i];

				if (rx * rx + ry * ry + rz * rz <= r[i] * r[i] + 0.01)
				{
					used[k] = true;
				}
			}

			tx -= vx;
			ty -= vy;
			tz -= vz;
		}

		long long ret = 0;

		for (int j = 0; j < N; j++)
		{
			if (used[j])
			{
				ret += l[j];
			}
		}

		printf("%lld\n", ret);
	}

	return 0;
}
accuracy: 0.03571428571428571
time_ms: 350
memory_kb: 3168
final_rank: 18

code_snippet: #include <iostream>

#pragma warning(disable : 4996)

#define STEPS 10000000

using namespace std;

int N, Q, x[50], y[50], z[50], r[50], sx, sy, sz, dx, dy, dz; long long l[50]; bool used[50];

int main()
{
	scanf("%d", &N);
	scanf("%d", &Q);

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &x[i]);
		scanf("%d", &y[i]);
		scanf("%d", &z[i]);
		scanf("%d", &r[i]);

		scanf("%lld", &l[i]);
	}

	for (int i = 0; i < Q; i++)
	{
		scanf("%d", &sx);
		scanf("%d", &sy);
		scanf("%d", &sz);
		scanf("%d", &dx);
		scanf("%d", &dy);
		scanf("%d", &dz);

		long double vx = 1.0 * (sx - dx) / STEPS;
		long double vy = 1.0 * (sy - dy) / STEPS;
		long double vz = 1.0 * (sz - dz) / STEPS;

		long double tx = sx;
		long double ty = sy;
		long double tz = sz;

		for (int j = 0; j < N; j++) used[j] = false;

		for (int j = 0; j <= STEPS; j++)
		{
			for (int k = 0; k < N; k++)
			{
				long double rx = tx - x[i];
				long double ry = ty - y[i];
				long double rz = tz - z[i];

				if (rx * rx + ry * ry + rz * rz <= r[i] * r[i] + 0.0001)
				{
					used[k] = true;
				}
			}

			tx -= vx;
			ty -= vy;
			tz -= vz;
		}

		long long ret = 0;

		for (int j = 0; j < N; j++)
		{
			if (used[j])
			{
				ret += l[j];
			}
		}

		printf("%lld\n", ret);
	}

	return 0;
}
accuracy: 0.03571428571428571
time_ms: 360
memory_kb: 3212
final_rank: 20

code_snippet: #include <iostream>

#pragma warning(disable : 4996)

#define STEPS 10000000

using namespace std;

int N, Q, x[50], y[50], z[50], r[50], sx, sy, sz, dx, dy, dz; long long l[50]; bool used[50];

int main()
{
	scanf("%d", &N);
	scanf("%d", &Q);

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &x[i]);
		scanf("%d", &y[i]);
		scanf("%d", &z[i]);
		scanf("%d", &r[i]);

		scanf("%lld", &l[i]);
	}

	for (int i = 0; i < Q; i++)
	{
		scanf("%d", &sx);
		scanf("%d", &sy);
		scanf("%d", &sz);
		scanf("%d", &dx);
		scanf("%d", &dy);
		scanf("%d", &dz);

		long double vx = 1.0 * (sx - dx) / STEPS;
		long double vy = 1.0 * (sy - dy) / STEPS;
		long double vz = 1.0 * (sz - dz) / STEPS;

		long double tx = sx;
		long double ty = sy;
		long double tz = sz;

		for (int j = 0; j < N; j++) used[j] = false;

		for (int j = 0; j <= STEPS; j++)
		{
			for (int k = 0; k < N; k++)
			{
				long double rx = tx - x[i];
				long double ry = ty - y[i];
				long double rz = tz - z[i];

				if (rx * rx + ry * ry + rz * rz <= r[i] * r[i] + 0.000001)
				{
					used[k] = true;
				}
			}

			tx -= vx;
			ty -= vy;
			tz -= vz;
		}

		long long ret = 0;

		for (int j = 0; j < N; j++)
		{
			if (used[j])
			{
				ret += l[j];
			}
		}

		printf("%lld\n", ret);
	}

	return 0;
}
accuracy: 0.03571428571428571
time_ms: 350
memory_kb: 3168
final_rank: 18