Problem:
Problem E: Light Source
Problem
二次元平面上に
n
個の円状の光源が配置されている。ある光源が光を受けると、下図のようにその光源の中心点から扇状に光が放出される。
光源の中心点は(
x
,
y
)、半径は
r
で表される。
光となる扇形は角
β
を中心に-
θ
/2, +
θ
/2の方向へ対称に広がり、その半径は
α
である。
光源の円が扇型の光に完全に覆われるとき、光源はその光を受けたとみなされる。光源から放出される光の強さは、受けた光の強さの合計となる。ただし、放出される光の強さには上限があり、上限を超えた場合、光の強さは上限値と同じになる。なお、ある光や光源によって光が遮られることはない。
ある地点に存在する光源を目的光源とする。目的光源では光が放出されず、受ける光の強さに制限はない。
あなたは座標(0,0)から、ある強さの扇形の光を、任意の方向に１度だけ放出することができる。目的光源が受ける光の強さの合計の最大値を求めるプログラムを作成せよ。ただし、全ての光源において、放出された光が元の光源に戻るような入力データは与えられないと仮定してよい。また、この問題では、領域の境界からの距離が0.000001以内の場合、領域上とみなすことにする。
Input
n
θ
0
α
0
power
x
1
y
1
r
1
θ
1
α
1
β
1
maxpower
1
.
.
x
n
y
n
r
n
θ
n
α
n
β
n
maxpower
n
x
n+1
y
n+1
r
n+1
1行目には目的光源を除く光源の数
n
が与えられる。
2行目に最初に光を放出する座標(0,0)の情報、3行目からn+2行目に目的でない光源の情報、n+3行目に目的光源の情報がそれぞれ空白区切りで与えられる。
各情報に対して、
x
i
,
y
i
は光源の中心点の座標、
r
i
は光源の半径、
θ
i
は光が広がる角度、
α
i
は光の半径、
β
i
は光が向かう方向を表す。2行目の
power
は最初に放出される光の強さ、3行目からn+2行目の
maxpower
i
は放出される光の上限を表す。
光の方向
β
i
はx軸の正の向きから反時計回りに回転し、各角度の単位は度とする。
Constraints
入力は以下の条件を満たす。
入力は全て整数からなる
1 ≤
n
≤ 100
-1000 ≤
x
i
,
y
i
≤ 1000
1 ≤
r
i
≤ 1000
1 ≤
θ
i
≤ 180
1 ≤
α
i
≤ 1000
0 ≤
β
i
< 360
0 ≤
power
,
maxpower
i
≤ 1000
Output
目的光源を全て囲うような光の強さの合計の最大値を1行に出力せよ。
Sample Input 1
1
90 10 20
3 3 1 90 10 315 10
6 0 1
Sample Output 1
30
Sample Input 2
2
90 10 10
-3 0 1 45 10 90 10
-6 0 2 30 3 180 10
-9 0 1
Sample Output 2
10

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
#define PI M_PI
#define EPS 1e-10
using namespace std;
typedef long long ll;
typedef complex<double> P;

struct light {
  P pos;
  double r, t, a, b;
  ll p;
};

double cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }
double distance(P a, P b) { return abs(a - b); }

vector<vector<ll>> construct(const vector<light>& v) {
  vector<vector<ll>> graph(v.size());
  for (ll i = 0; i < v.size() - 1; i++) {
    for (ll j = 1; j < v.size(); j++) {
      double d = distance(v[i].pos, v[j].pos);
      if (d < v[j].r) continue;
      double w = asin(v[j].r / d);
      assert(-EPS < w && w < PI / 2 + EPS);
      P i1 = polar(1.0, arg(v[j].pos - v[i].pos) - w);
      P i2 = polar(1.0, arg(v[j].pos - v[i].pos) + w);
      P o1 = polar(1.0, v[i].b - v[i].t / 2);
      P o2 = polar(1.0, v[i].b + v[i].t / 2);
      if (d + v[j].r <= v[i].a + EPS && cross(o1, i1) >= -EPS && cross(i2, o2) >= -EPS) {
        graph[i].push_back(j);
      }
    }
  }
  return graph;
}

int main() {
  ll n;
  cin >> n;
  vector<light> v(n + 2);
  cin >> v[0].t >> v[0].a >> v[0].p;
  for (ll i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y >> v[i + 1].r >> v[i + 1].t >> v[i + 1].a >> v[i + 1].b >> v[i + 1].p;
    v[i + 1].pos = P(x, y);
  }

  {
    ll x, y;
    cin >> x >> y >> v[n + 1].r;
    v[n + 1].pos = P(x, y);
    v[n + 1].p = 1e9;
  }

  for (auto& e : v) {
    e.t = e.t / 180.0 * PI;
    e.b = e.b / 180.0 * PI;
  }

  ll answer = 0;
  for (ll i = 1; i < n + 2; i++) {
    for(ll z = -1; z < 2; z++) if(z != 0) {
      v[0].b = arg(v[i].pos) + (abs(asin(v[i].r / abs(v[i].pos))) - v[0].t / 2) * z;
      // assert(-EPS < asin(v[i].r / abs(v[i].pos)) && asin(v[i].r / abs(v[i].pos)) < PI / 2 + EPS);
      auto graph = construct(v);
      vector<ll> k(graph.size());
      for (auto edges : graph) {
        for (auto e : edges) {
          k[e]++;
        }
      }

      vector<ll> dp(graph.size());
      dp[0] = v[0].p;
      stack<ll> s;
      for (ll i = 0; i < k.size(); i++) {
        if (k[i] == 0) {
          s.push(i);
        }
      }
      while (!s.empty()) {
        ll t = s.top();
        s.pop();
        dp[t] = min(v[t].p, dp[t]);
        for(auto e : graph[t]) {
          dp[e] += dp[t];
          if(--k[e] == 0) {
            s.push(e);
          }
        }
      }
      answer = max(answer, dp[n + 1]);
    }
  }

  cout << answer << endl;
}
accuracy: 0.4444444444444444
time_ms: 380
memory_kb: 3728
final_rank: 18

code_snippet: #include <bits/stdc++.h>
#define PI M_PI
#define EPS 1e-10
using namespace std;
typedef long long ll;
typedef complex<double> P;

struct light {
  P pos;
  double r, t, a, b;
  ll p;
};

double cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }
double distance(P a, P b) { return abs(a - b); }

vector<vector<ll>> construct(const vector<light>& v) {
  vector<vector<ll>> graph(v.size());
  for (ll i = 0; i < v.size() - 1; i++) {
    for (ll j = 1; j < v.size(); j++) {
      double d = distance(v[i].pos, v[j].pos);
      if (d < v[j].r) continue;
      double w = asin(v[j].r / d);
      assert(-EPS < w && w < PI / 2 + EPS);
      P i1 = polar(1.0, arg(v[j].pos - v[i].pos) - w);
      P i2 = polar(1.0, arg(v[j].pos - v[i].pos) + w);
      P o1 = polar(1.0, v[i].b - v[i].t / 2);
      P o2 = polar(1.0, v[i].b + v[i].t / 2);
      if (d + v[j].r <= v[i].a + EPS && cross(o1, i1) >= -EPS && cross(i2, o2) >= -EPS) {
        graph[i].push_back(j);
      }
    }
  }
  return graph;
}

int main() {
  ll n;
  cin >> n;
  vector<light> v(n + 2);
  cin >> v[0].t >> v[0].a >> v[0].p;
  for (ll i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y >> v[i + 1].r >> v[i + 1].t >> v[i + 1].a >> v[i + 1].b >> v[i + 1].p;
    v[i + 1].pos = P(x, y);
  }

  {
    ll x, y;
    cin >> x >> y >> v[n + 1].r;
    v[n + 1].pos = P(x, y);
    v[n + 1].p = 1e9;
  }

  for (auto& e : v) {
    e.t = e.t / 180.0 * PI;
    e.b = e.b / 180.0 * PI;
  }

  ll answer = 0;
  for (ll i = 1; i < n + 2; i++) {
    for(ll z = -1; z < 2; z++) if(z != 0) {
      v[0].b = arg(v[i].pos) + (asin(v[i].r / abs(v[i].pos)) - v[0].t / 2) * z;
      // assert(-EPS < asin(v[i].r / abs(v[i].pos)) && asin(v[i].r / abs(v[i].pos)) < PI / 2 + EPS);
      auto graph = construct(v);
      vector<ll> k(graph.size());
      for (auto edges : graph) {
        for (auto e : edges) {
          k[e]++;
        }
      }

      vector<ll> dp(graph.size());
      dp[0] = v[0].p;
      stack<ll> s;
      for (ll i = 0; i < k.size(); i++) {
        if (k[i] == 0) {
          s.push(i);
        }
      }
      while (!s.empty()) {
        ll t = s.top();
        s.pop();
        dp[t] = min(v[t].p, dp[t]);
        for(auto e : graph[t]) {
          dp[e] += dp[t];
          if(--k[e] == 0) {
            s.push(e);
          }
        }
      }
      answer = max(answer, dp[n + 1]);
    }
  }

  cout << answer << endl;
}
accuracy: 0.4444444444444444
time_ms: 390
memory_kb: 3732
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef complex<double> Point;
typedef pair<Point,Point> Line;
typedef vector<Point> VP;
const double EPS = 1e-6;
const double INF = 1e9;
#define X real()
#define Y imag()

#define LE(n,m) ((n)-(m) < EPS)
#define GE(n,m) (EPS > (m)-(n))
#define EQ(n,m) (abs((n)-(m)) < EPS)

const double PI = acos(-1);

namespace std {
    bool operator<(const Point a, const Point b){
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

double dot(Point a, Point b){
    return a.X*b.X + a.Y*b.Y;
}

double cross(Point a, Point b){
    return a.X*b.Y - a.Y*b.X;
}

int ccw(Point a, Point b ,Point c){
    b -= a; c -= a;
    if(cross(b,c) >  EPS) return +1;
    if(cross(b,c) < -EPS) return -1;
    if(dot(b,c)   < -EPS) return +2;
    if(norm(b) < norm(c)) return -2;
    return 0;
}

Point proj(Point a1, Point a2, Point p){
    return a1 + dot(a2-a1, p-a1)/norm(a2-a1) * (a2-a1);
}

VP tangentPoints(Point a, double ar, Point p){
    VP ps;
    double sin = ar / abs(p-a);
    if( !LE(sin,1) ) return ps;
    double t = PI/2 - asin(min(sin, 1.0));
    ps.push_back( a+(p-a)*polar(sin,t) );
    if(!EQ(sin,1)) ps.push_back( a+(p-a)*polar(sin,-t) );
    return ps;
}

VP crosspointLC(Point a1, Point a2, Point c, double r){
    VP ps;
    Point ft = proj(a1,a2,c);
    if(!GE(r*r,norm(ft-c))) return ps;
    Point dir = sqrt(max(r*r-norm(ft-c),0.0)) / abs(a2-a1) * (a2-a1);
    ps.pb(ft+dir);
    if(!EQ(r*r,norm(ft-c))) ps.pb(ft-dir);
    return ps;
}

Point READ_P(){
    int x,y;
    cin >>x >>y;
    return Point(x,y);
}

double ang_to_rad(double a){
    return a/360*2*PI;
}

int V;
vector<vector<int>> gg;

vector<int> tlist;
vector<bool> vis;
void dfs(int x){
    if(vis[x]) return;
    vis[x] = true;
    for(int e:gg[x]) dfs(e);
    tlist.pb(x);
}

bool covered(Point c, double a, double lt, double rt, Point to, double tor){
    Point v(to.X-c.X, to.Y-c.Y);

    double dir = acos(v.X / hypot(v.X,v.Y));
    if(v.Y<0) dir = dir + 2*(PI-dir);

    // 半径内に入っている
    if( LE(abs(v)+tor, a) ){
        // 角度チェック
        Point pl = c + polar(a,lt), pr = c + polar(a,rt);

        bool angle_ok = false;
        for(int i=-1; i<=1; ++i){
            angle_ok |= (LE(lt+i*2*PI,dir)&&LE(dir,rt+i*2*PI));
        }
        if( angle_ok ){
            for(Point tt:{pl,pr}){
                Point h = proj(c,tt,to);
                if(GE(abs(to-h), tor)) continue;

                for(Point cp:crosspointLC(c,tt,to,tor)){
                    if(ccw(c,tt,cp) == 0) return false;
                }
            }
            return true;
        }
    }
    return false;
}

int main(){
    int n;
    cin >>n;

    V = n+2;

    double ts,as;
    int ps;
    cin >>ts >>as >>ps;
    ts = ang_to_rad(ts);

    VP c(n);
    vector<double> r(n),t(n),a(n),b(n);
    vector<int> p(n);
    rep(i,n){
        c[i] = READ_P();
        cin >>r[i] >>t[i] >>a[i] >>b[i] >>p[i];

        t[i] = ang_to_rad(t[i]);
        b[i] = ang_to_rad(b[i]);
    }

    Point goal;
    double gr;
    goal = READ_P();
    cin >>gr;

    int S = n, G = n+1;
    vector<vector<int>> g(n+2);

    rep(i,n)rep(j,n){
        if(i==j) continue;
        double lt = b[i]-t[i]/2, rt = b[i]+t[i]/2;
        if(covered(c[i],a[i],lt,rt,c[j],r[j])) g[i].pb(j);
    }

    // to goal
    rep(i,n){
        double lt = b[i]-t[i]/2, rt = b[i]+t[i]/2;
        if(covered(c[i],a[i],lt,rt,goal,gr)) g[i].pb(G);
    }

    Point ZERO(0,0);
    vector<double> cand;
    rep(i,n){
        if( LE(abs(c[i]-ZERO),0) ) continue;

        for(Point tp:tangentPoints(c[i],r[i],ZERO)){
            double dir = acos(tp.X / hypot(tp.X,tp.Y));
            if(tp.Y<0) dir = dir + 2*(PI-dir);

            for(double sub:vector<double>({0,-ts})){
                double add = dir+sub;
                if(add<0) add += 2*PI;
                cand.pb(add);
            }
        }
    }
    if( !LE(abs(goal-ZERO),0) ) {
        for(Point tp:tangentPoints(goal,gr,ZERO)){
            double dir = acos(tp.X / hypot(tp.X,tp.Y));
            if(tp.Y<0) dir = dir + 2*(PI-dir);

            for(double sub:vector<double>({0,-ts})){
                double add = dir+sub;
                if(add<0) add += 2*PI;
                cand.pb(add);
            }
        }
    }

    int ans = 0;
    for(double rad:cand){
        gg = g;

        double lt = rad, rt = rad+ts;
        rep(i,n){
            if(covered(ZERO,as,lt,rt,c[i],r[i])) gg[S].pb(i);
        }
        if(covered(ZERO,as,lt,rt,goal,gr)) gg[S].pb(G);


        tlist.clear();
        vis = vector<bool>(V,false);
        rep(i,V) dfs(i);

        reverse(all(tlist));
        vector<int> dp(V);
        dp[S] = ps;
        for(int i:tlist){
            if(i<n) dp[i] = min(dp[i], p[i]);
            for(int e:gg[i]) dp[e] += dp[i];
        }

        ans = max(ans, dp[G]);
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3660
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#define PI M_PI
#define EPS 1e-10
using namespace std;
typedef long long ll;
typedef complex<double> P;

struct light {
  P pos;
  double r, t, a, b;
  ll p;
};

double cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }
double distance(P a, P b) { return abs(a - b); }

vector<vector<ll>> construct(const vector<light>& v) {
  vector<vector<ll>> graph(v.size());
  for (ll i = 0; i < v.size() - 1; i++) {
    for (ll j = 1; j < v.size(); j++) {
      double d = distance(v[i].pos, v[j].pos);
      if (d < v[j].r) continue;
      double w = asin(v[j].r / d);
      P i1 = polar(1.0, arg(v[j].pos - v[i].pos) - w);
      P i2 = polar(1.0, arg(v[j].pos - v[i].pos) + w);
      P o1 = polar(1.0, v[i].b - v[i].t / 2);
      P o2 = polar(1.0, v[i].b + v[i].t / 2);
      if (d + v[j].r <= v[i].a + EPS && cross(o1, i1) >= -EPS && cross(i2, o2) >= -EPS) {
        graph[i].push_back(j);
      }
    }
  }
  return graph;
}

int main() {
  ll n;
  cin >> n;
  vector<light> v(n + 2);
  cin >> v[0].t >> v[0].a >> v[0].p;
  for (ll i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y >> v[i + 1].r >> v[i + 1].t >> v[i + 1].a >> v[i + 1].b >> v[i + 1].p;
    v[i + 1].pos = P(x, y);
  }

  {
    ll x, y;
    cin >> x >> y >> v[n + 1].r;
    v[n + 1].pos = P(x, y);
    v[n + 1].p = 1e9;
  }

  for (auto& e : v) {
    e.r -= EPS;
    e.t = e.t / 180.0 * PI;
    e.b = e.b / 180.0 * PI;
  }

  ll answer = 0;
  for (ll i = 1; i < n + 2; i++) {
    for(ll z = -1; z < 2; z++) if(z != 0) {
      v[0].b = arg(v[i].pos) + (-asin(v[i].r / abs(v[i].pos)) + v[0].t / 2) * z;
      auto graph = construct(v);
      vector<ll> k(graph.size());
      for (auto edges : graph) {
        for (auto e : edges) {
          k[e]++;
        }
      }

      vector<ll> dp(graph.size());
      dp[0] = v[0].p;
      stack<ll> s;
      for (ll i = 0; i < k.size(); i++) {
        if (k[i] == 0) {
          s.push(i);
        }
      }
      while (!s.empty()) {
        ll t = s.top();
        s.pop();
        dp[t] = min(v[t].p, dp[t]);
        for (auto e : graph[t]) {
          dp[e] += dp[t];
          if (k[e]-- == 1) {
            s.push(e);
          }
        }
      }
      /*
         for (auto e : dp) {
         cerr << e << " ";
         }
         cerr << endl;
         */
      answer = max(answer, dp[n + 1]);
    }
  }

  cout << answer << endl;
}
accuracy: 0.4444444444444444
time_ms: 380
memory_kb: 3768
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
#define EPS 1e-12

typedef complex<double> P;

double cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }

double distance(P a, P b) { return abs(a - b); }

struct light {
  P pos;
  double r, t, a, b;
  int p;
};

vector<vector<int>> construct(const vector<light>& v) {
  vector<vector<int>> graph(v.size());
  for (int i = 0; i < v.size() - 1; i++) {
    for (int j = 1; j < v.size(); j++) {
      double d = distance(v[i].pos, v[j].pos);
      if (d < v[j].r) continue;
      double w = asin(v[j].r / d);
      P i1 = polar(1.0, arg(v[j].pos - v[i].pos) - w);
      P i2 = polar(1.0, arg(v[j].pos - v[i].pos) + w);
      P o1 = polar(1.0, v[i].b - v[i].t / 2);
      P o2 = polar(1.0, v[i].b + v[i].t / 2);
      if (d + v[j].r <= v[i].a + EPS && cross(o1, i1) >= -EPS && cross(i2, o2) >= -EPS) {
        graph[i].push_back(j);
      }
    }
  }
  /*
  for (int i = 0; i < graph.size(); i++) {
    cerr << i << ": ";
    for (auto e : graph[i]) {
      cerr << e << " ";
    }
    cerr << endl;
  }
  */
  return graph;
}

int main() {
  int n;
  cin >> n;
  vector<light> v(n + 2);
  cin >> v[0].t >> v[0].a >> v[0].p;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y >> v[i + 1].r >> v[i + 1].t >> v[i + 1].a >> v[i + 1].b >> v[i + 1].p;
    v[i + 1].pos = P(x, y);
  }
  {
    int x, y;
    cin >> x >> y >> v[n + 1].r;
    v[n + 1].pos = P(x, y);
    v[n + 1].p = 1e9;
  }
  for (auto& e : v) {
    e.r -= EPS;
    e.t = e.t / 180.0 * PI;
    e.b = e.b / 180.0 * PI;
  }
  /*
  for (auto e : v) {
    cerr << e.pos.real() << " " << e.pos.imag() << " " << e.r << " " << e.t << " " << e.a << " " << e.b << " " << e.p
         << endl;
  }
  */

  int answer = 0;
  for (int i = 1; i < n + 2; i++) {
    for(int z = -1; z < 2; z++) if(z != 0) {
      v[0].b = arg(v[i].pos) + (-asin(v[i].r / abs(v[i].pos)) + v[0].t / 2) * z;
      // cerr << v[0].b / PI * 180 << endl;
      auto graph = construct(v);
      vector<int> k(graph.size());
      for (auto edges : graph) {
        for (auto e : edges) {
          k[e]++;
        }
      }

      vector<int> dp(graph.size());
      dp[0] = v[0].p;
      stack<int> s;
      for (int i = 0; i < k.size(); i++) {
        if (k[i] == 0) {
          s.push(i);
        }
      }
      while (!s.empty()) {
        int t = s.top();
        s.pop();
        dp[t] = min(v[t].p, dp[t]);
        for (auto e : graph[t]) {
          dp[e] += dp[t];
          if (k[e]-- == 1) {
            s.push(e);
          }
        }
      }
      /*
         for (auto e : dp) {
         cerr << e << " ";
         }
         cerr << endl;
         */
      answer = max(answer, dp[n + 1]);
    }
  }

  cout << answer << endl;
}
accuracy: 0.4444444444444444
time_ms: 380
memory_kb: 3712
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
#define EPS 1e-12

typedef complex<double> P;

double cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }

double distance(P a, P b) { return abs(a - b); }

struct light {
  P pos;
  double r, t, a, b;
  int p;
};

vector<vector<int>> construct(const vector<light>& v) {
  vector<vector<int>> graph(v.size());
  for (int i = 0; i < v.size() - 1; i++) {
    for (int j = 1; j < v.size(); j++) {
      double d = distance(v[i].pos, v[j].pos);
      if (d < v[j].r) continue;
      double w = asin(v[j].r / d);
      P i1 = polar(1.0, arg(v[j].pos - v[i].pos) - w);
      P i2 = polar(1.0, arg(v[j].pos - v[i].pos) + w);
      P o1 = polar(1.0, v[i].b - v[i].t / 2);
      P o2 = polar(1.0, v[i].b + v[i].t / 2);
      if (d + v[j].r <= v[i].a && cross(o1, i1) >= -EPS && cross(i2, o2) >= -EPS) {
        graph[i].push_back(j);
      }
    }
  }
  /*
  for (int i = 0; i < graph.size(); i++) {
    cerr << i << ": ";
    for (auto e : graph[i]) {
      cerr << e << " ";
    }
    cerr << endl;
  }
  */
  return graph;
}

int main() {
  int n;
  cin >> n;
  vector<light> v(n + 2);
  cin >> v[0].t >> v[0].a >> v[0].p;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y >> v[i + 1].r >> v[i + 1].t >> v[i + 1].a >> v[i + 1].b >> v[i + 1].p;
    v[i + 1].pos = P(x, y);
  }
  {
    int x, y;
    cin >> x >> y >> v[n + 1].r;
    v[n + 1].pos = P(x, y);
    v[n + 1].p = 1e9;
  }
  for (auto& e : v) {
    e.r -= EPS;
    e.t = e.t / 180.0 * PI;
    e.b = e.b / 180.0 * PI;
  }
  /*
  for (auto e : v) {
    cerr << e.pos.real() << " " << e.pos.imag() << " " << e.r << " " << e.t << " " << e.a << " " << e.b << " " << e.p
         << endl;
  }
  */

  int answer = 0;
  for (int i = 1; i < n + 2; i++) {
    for(int z = -1; z < 2; z++) if(z != 0) {
      v[0].b = arg(v[i].pos) + (-asin(v[i].r / abs(v[i].pos)) + v[0].t / 2) * z;
      // cerr << v[0].b / PI * 180 << endl;
      auto graph = construct(v);
      vector<int> k(graph.size());
      for (auto edges : graph) {
        for (auto e : edges) {
          k[e]++;
        }
      }

      vector<int> dp(graph.size());
      dp[0] = v[0].p;
      stack<int> s;
      for (int i = 0; i < k.size(); i++) {
        if (k[i] == 0) {
          s.push(i);
        }
      }
      while (!s.empty()) {
        int t = s.top();
        s.pop();
        dp[t] = min(v[t].p, dp[t]);
        for (auto e : graph[t]) {
          dp[e] += dp[t];
          if (k[e]-- == 1) {
            s.push(e);
          }
        }
      }
      /*
         for (auto e : dp) {
         cerr << e << " ";
         }
         cerr << endl;
         */
      answer = max(answer, dp[n + 1]);
    }
  }

  cout << answer << endl;
}
accuracy: 0.4444444444444444
time_ms: 380
memory_kb: 3712
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
#define EPS 1e-6

typedef complex<double> P;

double cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }

double distance(P a, P b) { return abs(a - b); }

struct light {
  P pos;
  double r, t, a, b;
  int p;
};

vector<vector<int>> construct(const vector<light>& v) {
  vector<vector<int>> graph(v.size());
  for (int i = 0; i < v.size() - 1; i++) {
    for (int j = 1; j < v.size(); j++) {
      double d = distance(v[i].pos, v[j].pos);
      if (d < v[j].r) continue;
      double w = asin(v[j].r / d);
      P i1 = polar(1.0, arg(v[j].pos - v[i].pos) - w);
      P i2 = polar(1.0, arg(v[j].pos - v[i].pos) + w);
      P o1 = polar(1.0, v[i].b - v[i].t / 2);
      P o2 = polar(1.0, v[i].b + v[i].t / 2);
      if (d + v[j].r <= v[i].a && cross(o1, i1) >= -EPS && cross(i2, o2) >= -EPS) {
        graph[i].push_back(j);
      }
    }
  }
  /*
  for (int i = 0; i < graph.size(); i++) {
    cerr << i << ": ";
    for (auto e : graph[i]) {
      cerr << e << " ";
    }
    cerr << endl;
  }
  */
  return graph;
}

int main() {
  int n;
  cin >> n;
  vector<light> v(n + 2);
  cin >> v[0].t >> v[0].a >> v[0].p;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y >> v[i + 1].r >> v[i + 1].t >> v[i + 1].a >> v[i + 1].b >> v[i + 1].p;
    v[i + 1].pos = P(x, y);
  }
  {
    int x, y;
    cin >> x >> y >> v[n + 1].r;
    v[n + 1].pos = P(x, y);
    v[n + 1].p = 1e9;
  }
  for (auto& e : v) {
    e.r -= EPS;
    e.t = e.t / 180.0 * PI;
    e.b = e.b / 180.0 * PI;
  }
  /*
  for (auto e : v) {
    cerr << e.pos.real() << " " << e.pos.imag() << " " << e.r << " " << e.t << " " << e.a << " " << e.b << " " << e.p
         << endl;
  }
  */

  int answer = 0;
  for (int i = 1; i < n + 2; i++) {
    v[0].b = arg(v[i].pos) - asin(v[i].r / abs(v[i].pos)) + v[0].t / 2;
    // cerr << v[0].b / PI * 180 << endl;
    auto graph = construct(v);
    vector<int> k(graph.size());
    for (auto edges : graph) {
      for (auto e : edges) {
        k[e]++;
      }
    }

    vector<int> dp(graph.size());
    dp[0] = v[0].p;
    stack<int> s;
    for (int i = 0; i < k.size(); i++) {
      if (k[i] == 0) {
        s.push(i);
      }
    }
    while (!s.empty()) {
      int t = s.top();
      s.pop();
      dp[t] = min(v[t].p, dp[t]);
      for (auto e : graph[t]) {
        dp[e] += dp[t];
        if (k[e]-- == 1) {
          s.push(e);
        }
      }
    }
    /*
    for (auto e : dp) {
      cerr << e << " ";
    }
    cerr << endl;
    */
    answer = max(answer, dp[n + 1]);
  }

  cout << answer << endl;
}
accuracy: 0.4444444444444444
time_ms: 190
memory_kb: 3704
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
#define EPS 1e-6

typedef complex<double> P;

double cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }

double distance(P a, P b) { return abs(a - b); }

struct light {
  P pos;
  double r, t, a, b;
  int p;
};

vector<vector<int>> construct(const vector<light>& v) {
  vector<vector<int>> graph(v.size());
  for (int i = 0; i < v.size() - 1; i++) {
    for (int j = 1; j < v.size(); j++) {
      double d = distance(v[i].pos, v[j].pos);
      if (d < v[j].r) continue;
      double w = asin(v[j].r / d);
      P i1 = polar(1.0, arg(v[j].pos - v[i].pos) - w);
      P i2 = polar(1.0, arg(v[j].pos - v[i].pos) + w);
      P o1 = polar(1.0, v[i].b - v[i].t / 2);
      P o2 = polar(1.0, v[i].b + v[i].t / 2);
      if (d + v[j].r <= v[i].a && cross(o1, i1) >= -EPS && cross(i2, o2) >= -EPS) {
        graph[i].push_back(j);
      }
    }
  }
  /*
  for (int i = 0; i < graph.size(); i++) {
    cerr << i << ": ";
    for (auto e : graph[i]) {
      cerr << e << " ";
    }
    cerr << endl;
  }
  */
  return graph;
}

int main() {
  int n;
  cin >> n;
  vector<light> v(n + 2);
  cin >> v[0].t >> v[0].a >> v[0].p;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y >> v[i + 1].r >> v[i + 1].t >> v[i + 1].a >> v[i + 1].b >> v[i + 1].p;
    v[i + 1].pos = P(x, y);
  }
  {
    int x, y;
    cin >> x >> y >> v[n + 1].r;
    v[n + 1].pos = P(x, y);
    v[n + 1].p = 1e9;
  }
  for (auto& e : v) {
    e.r -= EPS;
    e.t = e.t / 180.0 * PI;
    e.b = e.b / 180.0 * PI;
  }
  /*
  for (auto e : v) {
    cerr << e.pos.real() << " " << e.pos.imag() << " " << e.r << " " << e.t << " " << e.a << " " << e.b << " " << e.p
         << endl;
  }
  */

  int answer = 0;
  for (int i = 1; i < n + 2; i++) {
    v[0].b = arg(v[i].pos) - asin(v[i].r / abs(v[i].pos)) + v[0].t / 2;
    // cerr << v[0].b / PI * 180 << endl;
    auto graph = construct(v);
    vector<int> k(graph.size());
    for (auto edges : graph) {
      for (auto e : edges) {
        k[e]++;
      }
    }

    vector<int> dp(graph.size());
    dp[0] = v[0].p;
    stack<int> s;
    for (int i = 0; i < k.size(); i++) {
      if (k[i] == 0) {
        s.push(i);
      }
    }
    while (!s.empty()) {
      int t = s.top();
      s.pop();
      dp[t] = min(v[t].p, dp[t]);
      for (auto e : graph[t]) {
        dp[e] += dp[t];
        k[e]--;
        if (k[e] == 0) {
          s.push(e);
        }
      }
    }
    /*
    for (auto e : dp) {
      cerr << e << " ";
    }
    cerr << endl;
    */
    answer = max(answer, dp[n + 1]);
  }

  cout << answer << endl;
}
accuracy: 0.4444444444444444
time_ms: 210
memory_kb: 3716
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
#define EPS 1e-6

typedef complex<double> P;

double cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }

double distance(P a, P b) { return abs(a - b); }

struct light {
  P pos;
  double r, t, a, b;
  int p;
};

vector<vector<int>> construct(const vector<light>& v) {
  vector<vector<int>> graph(v.size());
  for (int i = 0; i < v.size() - 1; i++) {
    for (int j = 1; j < v.size(); j++) {
      double d = distance(v[i].pos, v[j].pos);
      if (d < v[j].r) continue;
      double w = asin(v[j].r / d);
      P i1 = polar(1.0, arg(v[j].pos - v[i].pos) - w);
      P i2 = polar(1.0, arg(v[j].pos - v[i].pos) + w);
      P o1 = polar(1.0, v[i].b - v[i].t / 2 - EPS);
      P o2 = polar(1.0, v[i].b + v[i].t / 2 + EPS);
      if (d + v[j].r <= v[i].a + EPS && cross(o1, i1) >= -EPS && cross(i2, o2) >= -EPS) {
        graph[i].push_back(j);
      }
    }
  }
  /*
  for (int i = 0; i < graph.size(); i++) {
    cerr << i << ": ";
    for (auto e : graph[i]) {
      cerr << e << " ";
    }
    cerr << endl;
  }
  */
  return graph;
}

int main() {
  int n;
  cin >> n;
  vector<light> v(n + 2);
  cin >> v[0].t >> v[0].a >> v[0].p;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y >> v[i + 1].r >> v[i + 1].t >> v[i + 1].a >> v[i + 1].b >> v[i + 1].p;
    v[i + 1].pos = P(x, y);
  }
  {
    int x, y;
    cin >> x >> y >> v[n + 1].r;
    v[n + 1].pos = P(x, y);
    v[n + 1].p = 1e9;
  }
  for (auto& e : v) {
    e.t = e.t / 180.0 * PI;
    e.b = e.b / 180.0 * PI;
  }
  /*
  for (auto e : v) {
    cerr << e.pos.real() << " " << e.pos.imag() << " " << e.r << " " << e.t << " " << e.a << " " << e.b << " " << e.p
         << endl;
  }
  */

  int answer = 0;
  for (int i = 1; i < n + 2; i++) {
    v[0].b = arg(v[i].pos) - asin(v[i].r / abs(v[i].pos)) + v[0].t / 2;
    // cerr << v[0].b / PI * 180 << endl;
    auto graph = construct(v);
    vector<int> k(graph.size());
    for (auto edges : graph) {
      for (auto e : edges) {
        k[e]++;
      }
    }

    vector<int> dp(graph.size());
    dp[0] = v[0].p;
    stack<int> s;
    for (int i = 0; i < k.size(); i++) {
      if (k[i] == 0) {
        s.push(i);
      }
    }
    while (!s.empty()) {
      int t = s.top();
      s.pop();
      dp[t] = min(v[t].p, dp[t]);
      for (auto e : graph[t]) {
        dp[e] += dp[t];
        k[e]--;
        if (k[e] == 0) {
          s.push(e);
        }
      }
    }
    /*
    for (auto e : dp) {
      cerr << e << " ";
    }
    cerr << endl;
    */
    answer = max(answer, dp[n + 1]);
  }

  cout << answer << endl;
}
accuracy: 0.4444444444444444
time_ms: 220
memory_kb: 3688
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
#define EPS 1e-7

typedef complex<double> P;

double cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }

double distance(P a, P b) { return abs(a - b); }

struct light {
  P pos;
  double r, t, a, b;
  int p;
};

vector<vector<int>> construct(const vector<light>& v) {
  vector<vector<int>> graph(v.size());
  for (int i = 0; i < v.size() - 1; i++) {
    for (int j = 1; j < v.size(); j++) {
      double d = distance(v[i].pos, v[j].pos);
      if (d < v[j].r) continue;
      double w = asin(v[j].r / d);
      P i1 = polar(1.0, arg(v[j].pos - v[i].pos) - w);
      P i2 = polar(1.0, arg(v[j].pos - v[i].pos) + w);
      P o1 = polar(1.0, v[i].b - v[i].t / 2);
      P o2 = polar(1.0, v[i].b + v[i].t / 2);
      if (d + v[j].r <= v[i].a + EPS && cross(o1, i1) >= -EPS && cross(i2, o2) >= -EPS) {
        graph[i].push_back(j);
      }
    }
  }
  /*
  for (int i = 0; i < graph.size(); i++) {
    cerr << i << ": ";
    for (auto e : graph[i]) {
      cerr << e << " ";
    }
    cerr << endl;
  }
  */
  return graph;
}

int main() {
  int n;
  cin >> n;
  vector<light> v(n + 2);
  cin >> v[0].t >> v[0].a >> v[0].p;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y >> v[i + 1].r >> v[i + 1].t >> v[i + 1].a >> v[i + 1].b >> v[i + 1].p;
    v[i + 1].pos = P(x, y);
  }
  {
    int x, y;
    cin >> x >> y >> v[n + 1].r;
    v[n + 1].pos = P(x, y);
    v[n + 1].p = 1e9;
  }
  for (auto& e : v) {
    e.t = e.t / 180.0 * PI;
    e.b = e.b / 180.0 * PI;
  }
  /*
  for (auto e : v) {
    cerr << e.pos.real() << " " << e.pos.imag() << " " << e.r << " " << e.t << " " << e.a << " " << e.b << " " << e.p
         << endl;
  }
  */

  int answer = 0;
  for (int i = 1; i < n + 2; i++) {
    v[0].b = arg(v[i].pos) - asin(v[i].r / abs(v[i].pos)) + v[0].t / 2;
    // cerr << v[0].b / PI * 180 << endl;
    auto graph = construct(v);
    vector<int> k(graph.size());
    for (auto edges : graph) {
      for (auto e : edges) {
        k[e]++;
      }
    }

    vector<int> dp(graph.size());
    dp[0] = v[0].p;
    stack<int> s;
    for (int i = 0; i < k.size(); i++) {
      if (k[i] == 0) {
        s.push(i);
      }
    }
    while (!s.empty()) {
      int t = s.top();
      s.pop();
      dp[t] = min(v[t].p, dp[t]);
      for (auto e : graph[t]) {
        dp[e] += dp[t];
        k[e]--;
        if (k[e] == 0) {
          s.push(e);
        }
      }
    }
    /*
    for (auto e : dp) {
      cerr << e << " ";
    }
    cerr << endl;
    */
    answer = max(answer, dp[n + 1]);
  }

  cout << answer << endl;
}
accuracy: 0.4444444444444444
time_ms: 200
memory_kb: 3712
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
#define EPS 1e-12

typedef complex<double> P;

double cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }

double distance(P a, P b) { return abs(a - b); }

struct light {
  P pos;
  double r, t, a, b;
  int p;
};

vector<vector<int>> construct(const vector<light>& v) {
  vector<vector<int>> graph(v.size());
  for (int i = 0; i < v.size() - 1; i++) {
    for (int j = 1; j < v.size(); j++) {
      double d = distance(v[i].pos, v[j].pos);
      if (d < v[j].r) continue;
      double w = asin(v[j].r / d);
      P i1 = polar(1.0, arg(v[j].pos - v[i].pos) - w);
      P i2 = polar(1.0, arg(v[j].pos - v[i].pos) + w);
      P o1 = polar(1.0, v[i].b - v[i].t / 2);
      P o2 = polar(1.0, v[i].b + v[i].t / 2);
      if (d + v[j].r <= v[i].a + EPS && cross(o1, i1) >= -EPS && cross(i2, o2) >= -EPS) {
        graph[i].push_back(j);
      }
    }
  }
  /*
  for (int i = 0; i < graph.size(); i++) {
    cerr << i << ": ";
    for (auto e : graph[i]) {
      cerr << e << " ";
    }
    cerr << endl;
  }
  */
  return graph;
}

int main() {
  int n;
  cin >> n;
  vector<light> v(n + 2);
  cin >> v[0].t >> v[0].a >> v[0].p;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y >> v[i + 1].r >> v[i + 1].t >> v[i + 1].a >> v[i + 1].b >> v[i + 1].p;
    v[i + 1].pos = P(x, y);
  }
  {
    int x, y;
    cin >> x >> y >> v[n + 1].r;
    v[n + 1].pos = P(x, y);
    v[n + 1].p = 1e9;
  }
  for (auto& e : v) {
    e.t = e.t / 180.0 * PI;
    e.b = e.b / 180.0 * PI;
  }
  /*
  for (auto e : v) {
    cerr << e.pos.real() << " " << e.pos.imag() << " " << e.r << " " << e.t << " " << e.a << " " << e.b << " " << e.p
         << endl;
  }
  */

  int answer = 0;
  for (int i = 1; i < n + 2; i++) {
    v[0].b = arg(v[i].pos) - asin(v[i].r / abs(v[i].pos)) + v[0].t / 2;
    // cerr << v[0].b / PI * 180 << endl;
    auto graph = construct(v);
    vector<int> k(graph.size());
    for (auto edges : graph) {
      for (auto e : edges) {
        k[e]++;
      }
    }

    vector<int> dp(graph.size());
    dp[0] = v[0].p;
    stack<int> s;
    for (int i = 0; i < k.size(); i++) {
      if (k[i] == 0) {
        s.push(i);
      }
    }
    while (!s.empty()) {
      int t = s.top();
      s.pop();
      dp[t] = min(v[t].p, dp[t]);
      for (auto e : graph[t]) {
        dp[e] += dp[t];
        k[e]--;
        if (k[e] == 0) {
          s.push(e);
        }
      }
    }
    /*
    for (auto e : dp) {
      cerr << e << " ";
    }
    cerr << endl;
    */
    answer = max(answer, dp[n + 1]);
  }

  cout << answer << endl;
}
accuracy: 0.4444444444444444
time_ms: 190
memory_kb: 3708
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
#define EPS 1e-1

typedef complex<double> P;

double cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }

double distance(P a, P b) { return abs(a - b); }

struct light {
  P pos;
  double r, t, a, b;
  int p;
};

vector<vector<int>> construct(const vector<light>& v) {
  vector<vector<int>> graph(v.size());
  for (int i = 0; i < v.size() - 1; i++) {
    for (int j = 1; j < v.size(); j++) {
      double d = distance(v[i].pos, v[j].pos);
      if (d < v[j].r) continue;
      double w = asin(v[j].r / d);
      P i1 = polar(1.0, arg(v[j].pos - v[i].pos) - w);
      P i2 = polar(1.0, arg(v[j].pos - v[i].pos) + w);
      P o1 = polar(1.0, v[i].b - v[i].t / 2);
      P o2 = polar(1.0, v[i].b + v[i].t / 2);
      if (d + v[j].r <= v[i].a + EPS && cross(o1, i1) >= -EPS && cross(i2, o2) >= -EPS) {
        graph[i].push_back(j);
      }
    }
  }
  /*
  for (int i = 0; i < graph.size(); i++) {
    cerr << i << ": ";
    for (auto e : graph[i]) {
      cerr << e << " ";
    }
    cerr << endl;
  }
  */
  return graph;
}

int main() {
  int n;
  cin >> n;
  vector<light> v(n + 2);
  cin >> v[0].t >> v[0].a >> v[0].p;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y >> v[i + 1].r >> v[i + 1].t >> v[i + 1].a >> v[i + 1].b >> v[i + 1].p;
    v[i + 1].pos = P(x, y);
  }
  {
    int x, y;
    cin >> x >> y >> v[n + 1].r;
    v[n + 1].pos = P(x, y);
    v[n + 1].p = 1e9;
  }
  for (auto& e : v) {
    e.t = e.t / 180.0 * PI;
    e.b = e.b / 180.0 * PI;
  }
  /*
  for (auto e : v) {
    cerr << e.pos.real() << " " << e.pos.imag() << " " << e.r << " " << e.t << " " << e.a << " " << e.b << " " << e.p
         << endl;
  }
  */

  int answer = 0;
  for (int i = 1; i < n + 2; i++) {
    v[0].b = arg(v[i].pos) - asin(v[i].r / abs(v[i].pos)) + v[0].t / 2;
    // cerr << v[0].b / PI * 180 << endl;
    auto graph = construct(v);
    vector<int> k(graph.size());
    for (auto edges : graph) {
      for (auto e : edges) {
        k[e]++;
      }
    }

    vector<int> dp(graph.size());
    dp[0] = v[0].p;
    stack<int> s;
    for (int i = 0; i < k.size(); i++) {
      if (k[i] == 0) {
        s.push(i);
      }
    }
    while (!s.empty()) {
      int t = s.top();
      s.pop();
      dp[t] = min(v[t].p, dp[t]);
      for (auto e : graph[t]) {
        dp[e] += dp[t];
        k[e]--;
        if (k[e] == 0) {
          s.push(e);
        }
      }
    }
    /*
    for (auto e : dp) {
      cerr << e << " ";
    }
    cerr << endl;
    */
    answer = max(answer, dp[n + 1]);
  }

  cout << answer << endl;
}
accuracy: 0.4444444444444444
time_ms: 190
memory_kb: 3716
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef complex<double> Point;
typedef pair<Point,Point> Line;
typedef vector<Point> VP;
const double EPS = 1e-8;
const double INF = 1e9;
#define X real()
#define Y imag()

#define LE(n,m) ((n)-(m) < EPS)
#define GE(n,m) (EPS > (m)-(n))
#define EQ(n,m) (abs((n)-(m)) < EPS)

const double PI = acos(-1);

namespace std {
    bool operator<(const Point a, const Point b){
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

double dot(Point a, Point b){
    return a.X*b.X + a.Y*b.Y;
}

double cross(Point a, Point b){
    return a.X*b.Y - a.Y*b.X;
}

int ccw(Point a, Point b ,Point c){
    b -= a; c -= a;
    if(cross(b,c) >  EPS) return +1;
    if(cross(b,c) < -EPS) return -1;
    if(dot(b,c)   < -EPS) return +2;
    if(norm(b) < norm(c)) return -2;
    return 0;
}

Point proj(Point a1, Point a2, Point p){
    return a1 + dot(a2-a1, p-a1)/norm(a2-a1) * (a2-a1);
}

VP tangentPoints(Point a, double ar, Point p){
    VP ps;
    double sin = ar / abs(p-a);
    if( !LE(sin,1) ) return ps;
    double t = PI/2 - asin(min(sin, 1.0));
    ps.push_back( a+(p-a)*polar(sin,t) );
    if(!EQ(sin,1)) ps.push_back( a+(p-a)*polar(sin,-t) );
    return ps;
}

VP crosspointLC(Point a1, Point a2, Point c, double r){
    VP ps;
    Point ft = proj(a1,a2,c);
    if(!GE(r*r,norm(ft-c))) return ps;
    Point dir = sqrt(max(r*r-norm(ft-c),0.0)) / abs(a2-a1) * (a2-a1);
    ps.pb(ft+dir);
    if(!EQ(r*r,norm(ft-c))) ps.pb(ft-dir);
    return ps;
}






Point READ_P(){
    int x,y;
    cin >>x >>y;
    return Point(x,y);
}

double ang_to_rad(double a){
    return a/360*2*PI;
}

int V;
vector<vector<int>> gg;

vector<int> tlist;
vector<bool> vis;
void dfs(int x){
    vis[x] = true;
    for(int e:gg[x]){
        if(!vis[e]) dfs(e);
    }
    tlist.pb(x);
}


bool covered(Point c, double a, double lt, double rt, Point to, double tor){
    Point v(to.X-c.X, to.Y-c.Y);

    double dir = acos(v.X / hypot(v.X,v.Y));
    if(v.Y<0) dir = dir + 2*(PI-dir);
    // printf(" dir %f\n", dir);

    // printf(" %f ~ %f\n", lt-2*PI,rt-2*PI);

    // 半径内に入っている
    if( LE(abs(v)+tor, a) ){
        // 角度チェック
        Point pl = c + polar(a,lt), pr = c + polar(a,rt);
        if( (LE(lt,dir)&&LE(dir,rt)) || (LE(lt-2*PI,dir)&&LE(dir,rt-2*PI)) ){
            for(Point tt:{pl,pr}){

                Point h = proj(c,tt,to);
                if(EQ(abs(to-h), tor)) continue;

                for(Point cp:crosspointLC(c,tt,to,tor)){
                    if(ccw(c,tt,cp) == 0) return false;
                }
            }
            return true;
        }
    }
    return false;
}

int main(){
    int n;
    cin >>n;

    V = n+2;

    double ts,as,ps;
    cin >>ts >>as >>ps;
    ts = ang_to_rad(ts);

    VP c(n);
    vector<double> r(n),t(n),a(n),b(n);
    vector<int> p(n);
    rep(i,n){
        c[i] = READ_P();
        cin >>r[i] >>t[i] >>a[i] >>b[i] >>p[i];

        t[i] = ang_to_rad(t[i]);
        // a[i] = ang_to_rad(a[i]);
        b[i] = ang_to_rad(b[i]);
    }

    Point goal;
    double gr;
    goal = READ_P();
    cin >>gr;

    int S = n, G = n+1;

    vector<vector<int>> g(n+2);

    rep(i,n)rep(j,n){
        if(i==j) continue;

        double lt = b[i]-t[i]/2, rt = b[i]+t[i]/2;
        if(covered(c[i],a[i],lt,rt,c[j],r[j])){
            // printf(" ADD EDGE %d -> %d\n",i,j);
            g[i].pb(j);
        }
    }

    // to goal
    rep(i,n){
        double lt = b[i]-t[i]/2, rt = b[i]+t[i]/2;
        if(covered(c[i],a[i],lt,rt,goal,gr)){
            // printf(" ADD EDGE %d -> G\n",i);
            g[i].pb(G);
        }
    }

    Point ZERO(0,0);
    vector<double> cand;
    rep(i,n){
        if( LE(abs(c[i]-ZERO),0) ) continue;

        for(Point tp:tangentPoints(c[i],r[i],ZERO)){
            double dir = acos(tp.X / hypot(tp.X,tp.Y));
            if(tp.Y<0) dir = dir + 2*(PI-dir);

            for(double sub:vector<double>({0,-ts})){
                double add = dir+sub;
                if(add<0) add += 2*PI;
                cand.pb(add);
            }
        }
    }
    if( !LE(abs(goal-ZERO),0) ) {
        for(Point tp:tangentPoints(goal,gr,ZERO)){
            double dir = acos(tp.X / hypot(tp.X,tp.Y));
            if(tp.Y<0) dir = dir + 2*(PI-dir);

            for(double sub:vector<double>({0,-ts})){
                double add = dir+sub;
                if(add<0) add += 2*PI;
                cand.pb(add);
            }
        }
    }

    int ans = 0;
    for(double rad:cand){
        // printf(" --- %f\n",rad);

        gg = g;

        double lt = rad, rt = rad+ts;
        // printf(" lt rt %f %f\n", lt, rt);
        rep(i,n){
            if(covered(ZERO,as,lt,rt,c[i],r[i])){
                // printf(" ADD EDGE S -> %d\n",i);
                gg[S].pb(i);
            }
        }
        if(covered(ZERO,as,lt,rt,goal,gr)){
            // printf(" ADD EDGE S -> G\n");
            gg[S].pb(G);
        }

        tlist.clear();
        vis = vector<bool>(V,false);
        rep(i,V) dfs(i);

        reverse(all(tlist));
        vector<int> dp(V);
        dp[S] = ps;
        for(int i:tlist){

            if(i<n) dp[i] = min(dp[i], p[i]);
            for(int e:gg[i]){
                dp[e] += dp[i];
            }
        }
        ans = max(ans, dp[G]);
    }
    cout << ans << endl;
    return 0;
}
accuracy: 0.5
time_ms: 10
memory_kb: 3648
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
#define EPS 1e-6

typedef complex<double> P;

double cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }

double distance(P a, P b) { return abs(a - b); }

struct light {
  P pos;
  double r, t, a, b;
  int p;
};

vector<vector<int>> construct(const vector<light>& v) {
  vector<vector<int>> graph(v.size());
  for (int i = 0; i < v.size() - 1; i++) {
    for (int j = 1; j < v.size(); j++) {
      double d = distance(v[i].pos, v[j].pos);
      if (d < v[j].r) continue;
      double w = asin(v[j].r / d);
      P i1 = polar(1.0, arg(v[j].pos - v[i].pos) - w);
      P i2 = polar(1.0, arg(v[j].pos - v[i].pos) + w);
      P o1 = polar(1.0, v[i].b - v[i].t / 2);
      P o2 = polar(1.0, v[i].b + v[i].t / 2);
      if (d + v[j].r <= v[i].a + EPS && cross(o1, i1) >= -EPS && cross(i2, o2) >= -EPS) {
        graph[i].push_back(j);
      }
    }
  }
  /*
  for (int i = 0; i < graph.size(); i++) {
    cerr << i << ": ";
    for (auto e : graph[i]) {
      cerr << e << " ";
    }
    cerr << endl;
  }
  */
  return graph;
}

int main() {
  int n;
  cin >> n;
  vector<light> v(n + 2);
  cin >> v[0].t >> v[0].a >> v[0].p;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y >> v[i + 1].r >> v[i + 1].t >> v[i + 1].a >> v[i + 1].b >> v[i + 1].p;
    v[i + 1].pos = P(x, y);
  }
  {
    int x, y;
    cin >> x >> y >> v[n + 1].r;
    v[n + 1].pos = P(x, y);
    v[n + 1].p = 1e9;
  }
  for (auto& e : v) {
    e.t = e.t / 180.0 * PI;
    e.b = e.b / 180.0 * PI;
  }
  /*
  for (auto e : v) {
    cerr << e.pos.real() << " " << e.pos.imag() << " " << e.r << " " << e.t << " " << e.a << " " << e.b << " " << e.p
         << endl;
  }
  */

  int answer = 0;
  for (int i = 1; i < n + 2; i++) {
    v[0].b = arg(v[i].pos) - asin(v[i].r / abs(v[i].pos)) + v[0].t / 2;
    // cerr << v[0].b / PI * 180 << endl;
    auto graph = construct(v);
    vector<int> k(graph.size());
    for (auto edges : graph) {
      for (auto e : edges) {
        k[e]++;
      }
    }

    vector<int> dp(graph.size());
    dp[0] = v[0].p;
    stack<int> s;
    for (int i = 0; i < k.size(); i++) {
      if (k[i] == 0) {
        s.push(i);
      }
    }
    while (!s.empty()) {
      int t = s.top();
      s.pop();
      dp[t] = min(v[t].p, dp[t]);
      for (auto e : graph[t]) {
        dp[e] += dp[t];
        k[e]--;
        if (k[e] == 0) {
          s.push(e);
        }
      }
    }
    /*
    for (auto e : dp) {
      cerr << e << " ";
    }
    cerr << endl;
    */
    answer = max(answer, dp[n + 1]);
  }

  cout << answer << endl;
}
accuracy: 0.4444444444444444
time_ms: 190
memory_kb: 3768
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
#define EPS 1e-6

typedef complex<double> P;

double cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }

double distance(P a, P b) { return abs(a - b); }

struct light {
  P pos;
  double r, t, a, b;
  int p;
};

vector<vector<int>> construct(const vector<light>& v) {
  vector<vector<int>> graph(v.size());
  for (int i = 0; i < v.size() - 1; i++) {
    for (int j = 1; j < v.size(); j++) {
      if (i == j) continue;
      double d = distance(v[i].pos, v[j].pos);
      double w = asin(v[j].r / d);
      P i1 = polar(1.0, arg(v[j].pos - v[i].pos) - w);
      P i2 = polar(1.0, arg(v[j].pos - v[i].pos) + w);
      P o1 = polar(1.0, v[i].b - v[i].t / 2);
      P o2 = polar(1.0, v[i].b + v[i].t / 2);
      if (d + v[j].r <= v[i].a + EPS && cross(o1, i1) >= -EPS && cross(i2, o2) >= -EPS) {
        graph[i].push_back(j);
      }
    }
  }
  /*
  for (int i = 0; i < graph.size(); i++) {
    cerr << i << ": ";
    for (auto e : graph[i]) {
      cerr << e << " ";
    }
    cerr << endl;
  }
  */
  return graph;
}

int main() {
  int n;
  cin >> n;
  vector<light> v(n + 2);
  cin >> v[0].t >> v[0].a >> v[0].p;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y >> v[i + 1].r >> v[i + 1].t >> v[i + 1].a >> v[i + 1].b >> v[i + 1].p;
    v[i + 1].pos = P(x, y);
  }
  {
    int x, y;
    cin >> x >> y >> v[n + 1].r;
    v[n + 1].pos = P(x, y);
    v[n + 1].p = 1e9;
  }
  for (auto& e : v) {
    e.t = e.t / 180.0 * PI;
    e.b = e.b / 180.0 * PI;
  }
  /*
  for (auto e : v) {
    cerr << e.pos.real() << " " << e.pos.imag() << " " << e.r << " " << e.t << " " << e.a << " " << e.b << " " << e.p
         << endl;
  }
  */

  int answer = 0;
  for (int i = 1; i < n + 2; i++) {
    v[0].b = arg(v[i].pos) - asin(v[i].r / abs(v[i].pos)) + v[0].t / 2;
    // cerr << v[0].b / PI * 180 << endl;
    auto graph = construct(v);
    vector<int> k(graph.size());
    for (auto edges : graph) {
      for (auto e : edges) {
        k[e]++;
      }
    }

    vector<int> dp(graph.size());
    dp[0] = v[0].p;
    stack<int> s;
    for (int i = 0; i < k.size(); i++) {
      if (k[i] == 0) {
        s.push(i);
      }
    }
    while (!s.empty()) {
      int t = s.top();
      s.pop();
      dp[t] = min(v[t].p, dp[t]);
      for (auto e : graph[t]) {
        dp[e] += dp[t];
        k[e]--;
        if (k[e] == 0) {
          s.push(e);
        }
      }
    }
    /*
    for (auto e : dp) {
      cerr << e << " ";
    }
    cerr << endl;
    */
    answer = max(answer, dp[n + 1]);
  }

  cout << answer << endl;
}
accuracy: 0.4444444444444444
time_ms: 190
memory_kb: 3720
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
#define EPS 1e-3

typedef complex<double> P;

double cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }

double distance(P a, P b) { return abs(a - b); }

struct light {
  P pos;
  double r, t, a, b;
  int p;
};

vector<vector<int>> construct(const vector<light>& v) {
  vector<vector<int>> graph(v.size());
  for (int i = 0; i < v.size() - 1; i++) {
    for (int j = 1; j < v.size(); j++) {
      double d = distance(v[i].pos, v[j].pos);
      double w = asin(v[j].r / d);
      P i1 = polar(1.0, arg(v[j].pos - v[i].pos) - w);
      P i2 = polar(1.0, arg(v[j].pos - v[i].pos) + w);
      P o1 = polar(1.0, v[i].b - v[i].t / 2);
      P o2 = polar(1.0, v[i].b + v[i].t / 2);
      if (d + v[j].r <= v[i].a + EPS && cross(o1, i1) >= -EPS && cross(i2, o2) >= -EPS) {
        graph[i].push_back(j);
      }
    }
  }
  /*
  for (int i = 0; i < graph.size(); i++) {
    cerr << i << ": ";
    for (auto e : graph[i]) {
      cerr << e << " ";
    }
    cerr << endl;
  }
  */
  return graph;
}

int main() {
  int n;
  cin >> n;
  vector<light> v(n + 2);
  cin >> v[0].t >> v[0].a >> v[0].p;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y >> v[i + 1].r >> v[i + 1].t >> v[i + 1].a >> v[i + 1].b >> v[i + 1].p;
    v[i + 1].pos = P(x, y);
  }
  {
    int x, y;
    cin >> x >> y >> v[n + 1].r;
    v[n + 1].pos = P(x, y);
    v[n + 1].p = 1e9;
  }
  for (auto& e : v) {
    e.t = e.t / 180.0 * PI;
    e.b = e.b / 180.0 * PI;
  }
  /*
  for (auto e : v) {
    cerr << e.pos.real() << " " << e.pos.imag() << " " << e.r << " " << e.t << " " << e.a << " " << e.b << " " << e.p
         << endl;
  }
  */

  int answer = 0;
  for (int i = 1; i < n + 2; i++) {
    v[0].b = arg(v[i].pos) - asin(v[i].r / abs(v[i].pos)) + v[0].t / 2;
    // cerr << v[0].b / PI * 180 << endl;
    auto graph = construct(v);
    vector<int> k(graph.size());
    for (auto edges : graph) {
      for (auto e : edges) {
        k[e]++;
      }
    }

    vector<int> dp(graph.size());
    dp[0] = v[0].p;
    stack<int> s;
    for (int i = 0; i < k.size(); i++) {
      if (k[i] == 0) {
        s.push(i);
      }
    }
    while (!s.empty()) {
      int t = s.top();
      s.pop();
      dp[t] = min(v[t].p, dp[t]);
      for (auto e : graph[t]) {
        dp[e] += dp[t];
        k[e]--;
        if (k[e] == 0) {
          s.push(e);
        }
      }
    }
    /*
    for (auto e : dp) {
      cerr << e << " ";
    }
    cerr << endl;
    */
    answer = max(answer, dp[n + 1]);
  }

  cout << answer << endl;
}
accuracy: 0.4444444444444444
time_ms: 190
memory_kb: 3720
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
#define EPS 1e-9
typedef long long ll;

typedef complex<double> P;

double cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }

double distance(P a, P b) { return abs(a - b); }

struct light {
  P pos;
  double r, t, a, b;
  int p;
};

vector<vector<int>> construct(const vector<light>& v) {
  vector<vector<int>> graph(v.size());
  for (int i = 0; i < v.size() - 1; i++) {
    for (int j = 1; j < v.size(); j++) {
      double d = distance(v[i].pos, v[j].pos);
      double w = asin(v[j].r / d);
      P i1 = polar(1.0, arg(v[j].pos - v[i].pos) - w);
      P i2 = polar(1.0, arg(v[j].pos - v[i].pos) + w);
      P o1 = polar(1.0, v[i].b - v[i].t / 2);
      P o2 = polar(1.0, v[i].b + v[i].t / 2);
      if (d + v[j].r <= v[i].a + EPS && cross(o1, i1) >= -EPS && cross(i2, o2) >= -EPS) {
        graph[i].push_back(j);
      }
    }
  }
  /*
  for (int i = 0; i < graph.size(); i++) {
    cerr << i << ": ";
    for (auto e : graph[i]) {
      cerr << e << " ";
    }
    cerr << endl;
  }
  */
  return graph;
}

int main() {
  int n;
  cin >> n;
  vector<light> v(n + 2);
  cin >> v[0].t >> v[0].a >> v[0].p;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y >> v[i + 1].r >> v[i + 1].t >> v[i + 1].a >> v[i + 1].b >> v[i + 1].p;
    v[i + 1].pos = P(x, y);
  }
  {
    int x, y;
    cin >> x >> y >> v[n + 1].r;
    v[n + 1].pos = P(x, y);
    v[n + 1].p = 1e9;
  }
  for (auto& e : v) {
    e.t = e.t / 180.0 * PI;
    e.b = e.b / 180.0 * PI;
  }
  /*
  for (auto e : v) {
    cerr << e.pos.real() << " " << e.pos.imag() << " " << e.r << " " << e.t << " " << e.a << " " << e.b << " " << e.p
         << endl;
  }
  */

  ll answer = 0;
  for (int i = 1; i < n + 2; i++) {
    v[0].b = arg(v[i].pos) - asin(v[i].r / abs(v[i].pos)) + v[0].t / 2;
    // cerr << v[0].b / PI * 180 << endl;
    auto graph = construct(v);
    vector<int> k(graph.size());
    for (auto edges : graph) {
      for (auto e : edges) {
        k[e]++;
      }
    }

    vector<ll> dp(graph.size());
    dp[0] = v[0].p;
    stack<int> s;
    for (int i = 0; i < k.size(); i++) {
      if (k[i] == 0) {
        s.push(i);
      }
    }
    while (!s.empty()) {
      int t = s.top();
      s.pop();
      dp[t] = min((ll)v[t].p, dp[t]);
      for (auto e : graph[t]) {
        dp[e] += dp[t];
        k[e]--;
        if (k[e] == 0) {
          s.push(e);
        }
      }
    }
    /*
    for (auto e : dp) {
      cerr << e << " ";
    }
    cerr << endl;
    */
    answer = max(answer, dp[n + 1]);
  }

  cout << answer << endl;
}
accuracy: 0.4444444444444444
time_ms: 190
memory_kb: 3708
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
#define EPS 1e-9

typedef complex<double> P;

double cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }

double distance(P a, P b) { return abs(a - b); }

struct light {
  P pos;
  double r, t, a, b;
  int p;
};

vector<vector<int>> construct(const vector<light>& v) {
  vector<vector<int>> graph(v.size());
  for (int i = 0; i < v.size() - 1; i++) {
    for (int j = 1; j < v.size(); j++) {
      double d = distance(v[i].pos, v[j].pos);
      double w = asin(v[j].r / d);
      P i1 = polar(1.0, arg(v[j].pos - v[i].pos) - w);
      P i2 = polar(1.0, arg(v[j].pos - v[i].pos) + w);
      P o1 = polar(1.0, v[i].b - v[i].t / 2);
      P o2 = polar(1.0, v[i].b + v[i].t / 2);
      if (d + v[j].r - v[i].a <= EPS && cross(o1, i1) >= -EPS && cross(i2, o2) >= -EPS) {
        graph[i].push_back(j);
      }
    }
  }
  /*
  for (int i = 0; i < graph.size(); i++) {
    cerr << i << ": ";
    for (auto e : graph[i]) {
      cerr << e << " ";
    }
    cerr << endl;
  }
  */
  return graph;
}

int main() {
  int n;
  cin >> n;
  vector<light> v(n + 2);
  cin >> v[0].t >> v[0].a >> v[0].p;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y >> v[i + 1].r >> v[i + 1].t >> v[i + 1].a >> v[i + 1].b >> v[i + 1].p;
    v[i + 1].pos = P(x, y);
  }
  {
    int x, y;
    cin >> x >> y >> v[n + 1].r;
    v[n + 1].pos = P(x, y);
    v[n + 1].p = 1e9;
  }
  for (auto& e : v) {
    e.t = e.t / 180.0 * PI;
    e.b = e.b / 180.0 * PI;
  }
  /*
  for (auto e : v) {
    cerr << e.pos.real() << " " << e.pos.imag() << " " << e.r << " " << e.t << " " << e.a << " " << e.b << " " << e.p
         << endl;
  }
  */

  int answer = 0;
  for (int i = 1; i < n + 2; i++) {
    v[0].b = arg(v[i].pos) - asin(v[i].r / abs(v[i].pos)) + v[0].t / 2;
    // cerr << v[0].b / PI * 180 << endl;
    auto graph = construct(v);
    vector<int> k(graph.size());
    for (auto edges : graph) {
      for (auto e : edges) {
        k[e]++;
      }
    }

    vector<int> dp(graph.size());
    dp[0] = v[0].p;
    stack<int> s;
    for (int i = 0; i < k.size(); i++) {
      if (k[i] == 0) {
        s.push(i);
      }
    }
    while (!s.empty()) {
      int t = s.top();
      s.pop();
      dp[t] = min(v[t].p, dp[t]);
      for (auto e : graph[t]) {
        dp[e] += dp[t];
        k[e]--;
        if (k[e] == 0) {
          s.push(e);
        }
      }
    }
    /*
    for (auto e : dp) {
      cerr << e << " ";
    }
    cerr << endl;
    */
    answer = max(answer, dp[n + 1]);
  }

  cout << answer << endl;
}
accuracy: 0.4444444444444444
time_ms: 200
memory_kb: 3720
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
#define EPS 1e-6

typedef complex<double> P;

double cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }

double distance(P a, P b) { return abs(a - b); }

struct light {
  P pos;
  double r, t, a, b;
  int p;
};

vector<vector<int>> construct(const vector<light>& v) {
  vector<vector<int>> graph(v.size());
  for (int i = 0; i < v.size() - 1; i++) {
    for (int j = 1; j < v.size(); j++) {
      double d = distance(v[i].pos, v[j].pos);
      double w = asin(v[j].r / d);
      P i1 = polar(1.0, arg(v[j].pos - v[i].pos) - w);
      P i2 = polar(1.0, arg(v[j].pos - v[i].pos) + w);
      P o1 = polar(1.0, v[i].b - v[i].t / 2);
      P o2 = polar(1.0, v[i].b + v[i].t / 2);
      if (d + v[j].r <= v[i].a + EPS && cross(o1, i1) >= -EPS && cross(i2, o2) >= -EPS) {
        graph[i].push_back(j);
      }
    }
  }
  /*
  for (int i = 0; i < graph.size(); i++) {
    cerr << i << ": ";
    for (auto e : graph[i]) {
      cerr << e << " ";
    }
    cerr << endl;
  }
  */
  return graph;
}

int main() {
  int n;
  cin >> n;
  vector<light> v(n + 2);
  cin >> v[0].t >> v[0].a >> v[0].p;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y >> v[i + 1].r >> v[i + 1].t >> v[i + 1].a >> v[i + 1].b >> v[i + 1].p;
    v[i + 1].pos = P(x, y);
  }
  {
    int x, y;
    cin >> x >> y >> v[n + 1].r;
    v[n + 1].pos = P(x, y);
    v[n + 1].p = 1e9;
  }
  for (auto& e : v) {
    e.t = e.t / 180.0 * PI;
    e.b = e.b / 180.0 * PI;
  }
  /*
  for (auto e : v) {
    cerr << e.pos.real() << " " << e.pos.imag() << " " << e.r << " " << e.t << " " << e.a << " " << e.b << " " << e.p
         << endl;
  }
  */

  int answer = 0;
  for (int i = 1; i < n + 2; i++) {
    v[0].b = arg(v[i].pos) - asin(v[i].r / abs(v[i].pos)) + v[0].t / 2;
    // cerr << v[0].b / PI * 180 << endl;
    auto graph = construct(v);
    vector<int> k(graph.size());
    for (auto edges : graph) {
      for (auto e : edges) {
        k[e]++;
      }
    }

    vector<int> dp(graph.size());
    dp[0] = v[0].p;
    stack<int> s;
    for (int i = 0; i < k.size(); i++) {
      if (k[i] == 0) {
        s.push(i);
      }
    }
    while (!s.empty()) {
      int t = s.top();
      s.pop();
      dp[t] = min(v[t].p, dp[t]);
      for (auto e : graph[t]) {
        dp[e] += dp[t];
        k[e]--;
        if (k[e] == 0) {
          s.push(e);
        }
      }
    }
    /*
    for (auto e : dp) {
      cerr << e << " ";
    }
    cerr << endl;
    */
    answer = max(answer, dp[n + 1]);
  }

  cout << answer << endl;
}
accuracy: 0.4444444444444444
time_ms: 210
memory_kb: 3696
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
#define EPS 1e-6

typedef complex<double> P;

double cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }

double distance(P a, P b) { return abs(a - b); }

struct light {
  P pos;
  double r, t, a, b;
  int p;
};

vector<vector<int>> construct(const vector<light>& v) {
  vector<vector<int>> graph(v.size());
  for (int i = 0; i < v.size() - 1; i++) {
    for (int j = 1; j < v.size(); j++) {
      double d = distance(v[i].pos, v[j].pos);
      double w = asin(v[j].r / d);
      P i1 = polar(1.0, arg(v[j].pos - v[i].pos) - w);
      P i2 = polar(1.0, arg(v[j].pos - v[i].pos) + w);
      P o1 = polar(1.0, v[i].b - v[i].t / 2);
      P o2 = polar(1.0, v[i].b + v[i].t / 2);
      if (d + v[j].r <= v[i].a && cross(o1, i1) >= -EPS && cross(i2, o2) >= -EPS) {
        graph[i].push_back(j);
      }
    }
  }
  /*
  for (int i = 0; i < graph.size(); i++) {
    cerr << i << ": ";
    for (auto e : graph[i]) {
      cerr << e << " ";
    }
    cerr << endl;
  }
  */
  return graph;
}

int main() {
  int n;
  cin >> n;
  vector<light> v(n + 2);
  cin >> v[0].t >> v[0].a >> v[0].p;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y >> v[i + 1].r >> v[i + 1].t >> v[i + 1].a >> v[i + 1].b >> v[i + 1].p;
    v[i + 1].pos = P(x, y);
  }
  {
    int x, y;
    cin >> x >> y >> v[n + 1].r;
    v[n + 1].pos = P(x, y);
    v[n + 1].p = 1e9;
  }
  for (auto& e : v) {
    e.t = e.t / 180.0 * PI;
    e.b = e.b / 180.0 * PI;
  }
  /*
  for (auto e : v) {
    cerr << e.pos.real() << " " << e.pos.imag() << " " << e.r << " " << e.t << " " << e.a << " " << e.b << " " << e.p
         << endl;
  }
  */

  int answer = 0;
  for (int i = 1; i < n + 2; i++) {
    v[0].b = arg(v[i].pos) - asin(v[i].r / abs(v[i].pos)) + v[0].t / 2;
    // cerr << v[0].b / PI * 180 << endl;
    auto graph = construct(v);
    vector<int> k(graph.size());
    for (auto edges : graph) {
      for (auto e : edges) {
        k[e]++;
      }
    }

    vector<int> dp(graph.size());
    dp[0] = v[0].p;
    stack<int> s;
    for (int i = 0; i < k.size(); i++) {
      if (k[i] == 0) {
        s.push(i);
      }
    }
    while (!s.empty()) {
      int t = s.top();
      s.pop();
      dp[t] = min(v[t].p, dp[t]);
      for (auto e : graph[t]) {
        dp[e] += dp[t];
        k[e]--;
        if (k[e] == 0) {
          s.push(e);
        }
      }
    }
    /*
    for (auto e : dp) {
      cerr << e << " ";
    }
    cerr << endl;
    */
    answer = max(answer, dp[n + 1]);
  }

  cout << answer << endl;
}
accuracy: 0.4444444444444444
time_ms: 230
memory_kb: 3768
final_rank: 17