Problem:
Problem A:
How I Wonder What You Are!
One of the questions children often ask is "How many stars are there in the sky?" Under ideal conditions, even with the naked eye, nearly eight thousands are observable in the northern hemisphere. With a decent telescope, you may find many more, but, as the sight field will be
limited, you may find much less at a time.
Children may ask the same questions to their parents on a planet of some solar system billions
of light-years away from the Earth. Their telescopes are similar to ours with circular sight fields,
but alien kids have many eyes and can look into different directions at a time through many
telescopes.
Given a set of positions of stars, a set of telescopes and the directions they are looking to, your
task is to count up how many stars can be seen through these telescopes.
Input
The input consists of one or more datasets. The number of datasets is less than 50. Each dataset
describes stars and the parameters of the telescopes used.
The first line of a dataset contains a positive integer
n
not exceeding 500, meaning the number
of stars. Each of the
n
lines following it contains three decimal fractions,
s
x
,
s
y
, and
s
z
. They
give the position (
s
x
,
s
y
,
s
z
) of the star described in Euclidean coordinates. You may assume
-1000 ≤
s
x
≤ 1000, -1000 ≤
s
y
≤ 1000, -1000 ≤
s
z
≤ 1000 and (
s
x
,
s
y
,
s
z
) ≠ (0, 0, 0).
Then comes a line containing a positive integer
m
not exceeding 50, meaning the number of
telescopes. Each of the following
m
lines contains four decimal fractions,
t
x
,
t
y
,
t
z
, and
φ
, describing a telescope.
The first three numbers represent the direction of the telescope. All the telescopes are at the
origin of the coordinate system (0, 0, 0) (we ignore the size of the planet). The three numbers give
the point (
t
x
,
t
y
,
t
z
) which can be seen in the center of the sight through the telescope. You may
assume -1000 ≤
t
x
≤ 1000, -1000 ≤
t
y
≤ 1000, -1000 ≤
t
z
≤ 1000 and (
t
x
,
t
y
,
t
z
) ≠ (0, 0, 0).
The fourth number
φ
(0 ≤
φ
≤
π
/2) gives the angular radius, in radians, of the sight field of
the telescope.
Let us defie that
θ
i,j
is the angle between the direction of the
i
-th star and the center direction
of the
j
-th telescope and
φ
j
is the angular radius of the sight field of the
j
-th telescope. The
i
-th star is observable through the
j
-th telescope if and only if
θ
i,j
is less than . You may assume that |
θ
i,j
-
φ
j
| > 0.00000001 for all pairs of
i
and
j
.
Figure 1: Direction and angular radius of a telescope
The end of the input is indicated with a line containing a single zero.
Output
For each dataset, one line containing an integer meaning the number of stars observable through
the telescopes should be output. No other characters should be contained in the output. Note
that stars that can be seen through more than one telescope should not be counted twice or
more.
Sample Input
3
100 0 500
-500.243 -200.1 -300.5
0 300 200
2
1 1 1 0.65
-1 0 0 1.57
3
1 0 0
0
...(truncated)

Submitted solutions:

code_snippet: #include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
const int inf = 1 << 31 - 1;
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(void) {
    int n, m;
    while (cin >> n, n!= 0) {
        vector<ld> a(n), b(n), c(n);
        rep(i, n) cin >> a[i] >> b[i] >> c[i];
        cin >> m; vector<ld> x(m), y(m), z(m), t(m);
        rep(i, m) cin >> x[i] >> y[i] >> z[i] >> t[i];
        int ans = 0;
        rep(i, n) {
            rep(j, m) {
                ld co = a[i] * x[j] + (b[i] * y[j]) + (c[i] * z[j]);
                co /= sqrt(a[i] * a[i] + b[i] * b[i] + c[i] * c[i]) * sqrt(x[j] * x[j] + y[j] * y[j] + z[j] * z[j]);
                ld th = acos(co);
                if (th > acos(-1)) th -= acos(-1);
                if (th <= t[j]) {
                    ans++; break;
                }
            }
        }cout << ans << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3228
final_rank: 7

code_snippet: #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i,a,n) for(ll i=a;i<(ll)(n);i++)

struct point {
   double x;
   double y;
   double z;
};

int main(){
   int n;
   while(cin>>n, n){
      point s[n];
      for(int i=0; i<n; i++) cin>>s[i].x>>s[i].y>>s[i].z;

      int m; cin>>m;
      vector<bool> see(n, false);
      for(int i=0; i<m; i++){
         point t;
         double rad;
         cin>>t.x>>t.y>>t.z>>rad;
         int ans = 0;
         for(int j=0; j<n; j++){
            if(see[j])continue;
            double angle = acos((s[j].x*t.x+s[j].y*t.y+s[j].z*t.z)
                              /sqrt(s[j].x*s[j].x+s[j].y*s[j].y+s[j].z*s[j].z)
                              /sqrt(t.x*t.x+t.y*t.y+t.z*t.z));
            if(angle < rad+1e-8) see[j]=true;
         }
      }
      int ans = 0;
      for(bool s : see) if(s)ans++;
      cout << ans << endl;
   }
}
accuracy: 1
time_ms: 10
memory_kb: 3384
final_rank: 13

code_snippet: #include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;

int n,m;
double x[1000],y[1000],z[1000];
double tx,ty,tz,ar;

double dot(double ax,double ay,double az,
           double bx,double by,double bz){
  return ax*bx+ay*by+az*bz;
}

int calc(double sx,double sy,double sz){
  double S=sqrt(sx*sx+sy*sy+sz*sz);
  double T=sqrt(tx*tx+ty*ty+tz*tz);
  double Cos = dot(tx,ty,tz,sx,sy,sz)/T/S;
  double ti=acos(Cos);

  if(ti < ar + 0.00000001 ){
    return 1;
  }else{
    return 0;
  }
}
bool flg[1000];
int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      flg[i]=false;
      cin>>x[i]>>y[i]>>z[i];
    }
    cin>>m;
    for(int i=0;i<m;i++){
      cin>>tx>>ty>>tz>>ar;
      for(int j=0;j<n;j++){
        if(calc(x[j],y[j],z[j]))flg[j]=true;
      }
    }
    int ans=0;
    for(int i=0;i<n;i++)ans+=flg[i];
    cout<<ans<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3496
final_rank: 16

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* 3次元幾何 */

typedef double P_type;
typedef double G_real; //実数の戻り値(float or double or long double)
const G_real P_eps = 1e-8; //整数の時はゼロ

struct P3{
  P_type x, y, z;
  P3(P_type x = 0, P_type y = 0, P_type z = 0): x(x), y(y), z(z) {}

  P3 operator-() const {
    return P3(-x, -y, -z);
  }

  P3 operator+(const P3 &B) const {
    return P3(x + B.x, y + B.y, z + B.z);
  }

  P3 operator-(const P3 &B) const {
    return P3(x - B.x, y - B.y, z - B.z);
  }

  P3 operator*(P_type a) const {
    return P3(x * a, y * a, z * a);
  }

  P3 operator/(P_type a) const {
    return P3(x / a, y / a, z / a);
  }

  P3& operator+=(const P3 &B) {
    x += B.x; y += B.y; z += B.z;
    return *this;
  }

  P3& operator-=(const P3 &B) {
    x -= B.x; y -= B.y; z -= B.z;
    return *this;
  }

  P3& operator*=(P_type a) {
    x *= a; y *= a; z *= a;
    return *this;
  }

  P3& operator/=(P_type a) {
    x /= a; y /= a; z /= a;
    return *this;
  }

  bool operator<(const P3 &b){
    if (abs(x - b. x) > P_eps) return x + P_eps < b.x;
    if (abs(y - b. y) > P_eps) return y + P_eps < b.y;
    return z + P_eps < b.z;
  }
};

/* 3点a, b, cを通る平面 */
// TODO: 1直線上に並んでいる場合をError化
struct Plane {
  P3 a, b, c;

  Plane(P3 a, P3 b, P3 c): a(a), b(b), c(c) {}
};

P_type dot(P3 a, P3 b) {
  return a.x * b.x + a.y * b.y + a.z * b.z;
}

P3 cross(P3 a, P3 b) {
  P_type x = a.y * b.z - a.z * b.y;
  P_type y = a.z * b.x - a.x * b.z;
  P_type z = a.x * b.y - a.y * b.x;
  return P3(x, y, z);
}

P_type norm(P3 a) {
  return dot(a, a);
}

G_real abs(P3 a) {
  return sqrt(dot(a, a));
}

/* ベクトルa, bの成す角[0, pi] */
G_real arg(P3 a, P3 b) {
  return acos(dot(a, b) / abs(a) / abs(b));
}

/* 直線abと点cの距離 */
G_real distanceLP(P3 a, P3 b, P3 c) {
  return abs(cross(b-a, c-a)) / abs(b-a);
}

/* 線分abと点cの距離 */
G_real distanceSP(P3 a, P3 b, P3 c) {
  if (dot(b-a, c-a) <= P_eps) return abs(c-a);
  if (dot(a-b, c-b) <= P_eps) return abs(c-b);
  return abs(cross(b-a, c-a)) / abs(b-a);
}

/* 射影(直線abとpからの垂線との交点) */
P3 getProject(P3 a, P3 b, P3 p) {
  P3 base = b - a;
  return a + base * dot(p - a, base) / norm(base);
}

/* 直線Aと直線Bの距離 */
G_real distanceLL(P3 a1, P3 a2, P3 b1, P3 b2) {
  P3 n = cross(a2 - a1, b2 - b1);
  if (abs(n) <= P_eps) return distanceLP(a1, a2, b1); //平行
  return abs(dot(n, b1 - a1)) / abs(n);
}

/* 線分Aと線分Bの距離(未検証) */
G_real distanceSS(P3 a1, P3 a2, P3 b1, P3 b2) {
  //ねじれの位置
  P3 n = cross(a2 - a1, b2 - b1);
  if (abs(n) > P_eps) { // 平行ではない
    G_real d = distanceLL(a1, a2, b1, b2);
    P3 p = n * d / abs(n);
    P3 c1 = b1 + p, c2 = b2 + p;

    P3 va = a2 - a1, vc = c2 - c1;
    bool f1 = dot(cross(va, c1 - a1), cross(va, c2 - a1)) < -P_eps;
    bool f2 = dot(cross(vc, a1 - c1), cross(vc, a2 - c1)) < -P_eps;

    if (f1 && f2) return d;
  }

  //その他
  return min({distanceSP(a1, a2, b1), distanceSP(a1, a2, b2),
              distanceSP(b1, b2, a1), distanceSP(b1, b2, a2)});
}

/* 点と平面Plの距離 */
G_real distancePPl(P3 p, P3 pl1, P3 pl2, P3 pl3) {
  P3 n = cross(pl2 - pl1, pl3 - pl1);
  return abs(dot(p - pl1, n)) / abs(n);
}

/* 直線Aと、平面Plの交点 */
// verified: AOJ0115
vector<P3> getCrosspointLPl(P3 a1, P3 a2, P3 pl1, P3 pl2, P3 pl3) {
  P3 n = cross(pl2 - pl1, pl3 - pl1); //平面の法線ベクトル
  if (abs(dot(n, a2 - a1)) <= P_eps)
    return {}; //平面と直線が平行

  G_real s = dot(pl1 - a1, n), t = dot(a2 - pl1, n);
  P3 c = a1 + (a2 - a1) * (s / (s + t));
  return {c};
}

/* 線分Aと、平面Plの交点 */
// verified: AOJ0115
vector<P3> getCrosspointSPl(P3 a1, P3 a2, P3 pl1, P3 pl2, P3 pl3) {
  auto cps = getCrosspointLPl(a1, a2, pl1, pl2, pl3);
  if (cps.empty()) return {};
  if (norm(a1 - cps[0]) > norm(a1 - a2)) return {};
  if (norm(a2 - cps[0]) > norm(a1 - a2)) return {};
  return cps;
}

P3 scan() {
  double x, y, z;
  cin >> x >> y >> z;
  return P3(x, y, z);
}

int main(){

  while(1) {
    int N, M;
    P3 s[500], t[50];
    double phi[50];

    cin >> N;

    if (!N) break;

    for (int i=0; i<N; i++)
      s[i] = scan();

    cin >> M;

    for (int i=0; i<M; i++) {
      t[i] = scan();
      cin >> phi[i];
    }

    int ans = 0;

    for (int i=0; i<N; i++) {
      bool ok = false;
      for (int j=0; j<M; j++) {
        ok |= arg(s[i], t[j]) < phi[j] + P_eps;
      }
      ans += ok;
    }

    cout << ans << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3352
final_rank: 10

code_snippet: #include <iostream>
#include <vector>
#include <cmath>

using namespace std;

struct Point {
	double x, y, z;

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

	double abs() { return sqrt(x * x + y * y + z * z); }
};

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

int main() {
	int n, m;
	while (cin >> n, n) {
		vector<Point> s(n);
		for (int i = 0; i < n; ++i) cin >> s[i];
		cin >> m;
		vector<Point> t1(m);
		vector<double> t2(m);
		for (int i = 0; i < m; ++i) cin >> t1[i] >> t2[i];
		int ans = 0;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				if (acos(dot(s[i], t1[j]) / s[i].abs() / t1[j].abs()) <= t2[j]) {
					ans++;
					break;
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3376
final_rank: 12

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

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

    if(n==0) break;
    
    vector<double> sx(n),sy(n),sz(n);
    
    for(int i=0; i<n; i++){
      cin>>sx[i]>>sy[i]>>sz[i];
    }
    
    int m; cin>>m;
    
    vector<double> tx(m),ty(m),tz(m),kaku(m);
    
    for(int  i=0; i<m; i++){
      cin>>tx[i]>>ty[i]>>tz[i]>>kaku[i]; 
    }
    
    int count=0;
    
  set<int> s;
  
  for(int i=0; i<n; i++){
    for(int j=0; j<m; j++){
      if(s.count(i))continue;
      
      double seki = tx[j]*sx[i] + ty[j]*sy[i]+ tz[j]*sz[i];
      
      double pLong = sqrt(sx[i]*sx[i] + sy[i]*sy[i] + sz[i] * sz[i]);
      
      double kLong = sqrt(tx[j]*tx[j] + ty[j]*ty[j] + tz[j] * tz[j]);

      double theta = acos(seki / (pLong * kLong));
      
      if(theta <=kaku[j]){
        count++;
        s.insert(i);
      }
    }
  }
  cout<<count<<endl;
  }
  
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3496
final_rank: 16

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

using namespace std;

#define PI acos(-1)

struct xyz{
  double x,y,z;
};

double abs(xyz a) {
  return sqrt(a.x*a.x+a.y*a.y+a.z*a.z);
}

double product(xyz a,xyz b) {
  return a.x*b.x+a.y*b.y+a.z*b.z;
}

int main() {
  int n,m;
  while(cin >> n,n) {
    vector<xyz> s(n);
    for(auto&a:s) cin >> a.x>>a.y>>a.z;
    cin >> m;
    vector<pair<xyz,double> > t(m);
    for(auto &a:t)
      cin >> a.first.x>>a.first.y>>a.first.z >> a.second;
    int ans=0;
    for(int i=0;i<n;++i){
      for(int j=0;j<m;++j){
        double co=product(s[i],t[j].first);
        co/=abs(s[i])*abs(t[j].first);
        double theta=acos(co);
        if(theta>PI) theta-=PI;
        if(theta<=t[j].second) {
          ans++;
          break;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3424
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}

typedef pair<D,D> pd;

D dot(D a,D b,D c,D ad,D bd,D cd){return a*ad+b*bd+c*cd;}

D abs(D a,D b,D c){return sqrt(a*a+b*b+c*c);}

const D EPS=1e-9;

bool solve(){
  ll N;
  cin>>N;
  if(N==0){return false;}
  vector<pair<pd,D>> A(N);
  cin>>A;
  ll M;
  cin>>M;
  vector<pair<pd,pd>> B(M);
  cin>>B;
  for(auto &I:A){
    D uku=abs(I.F.F,I.F.S,I.S);
    I.F.F/=uku;
    I.F.S/=uku;
    I.S/=uku;
  }
  for(auto &I:B){
    D uku=abs(I.F.F,I.F.S,I.S.F);
    I.F.F/=uku;
    I.F.S/=uku;
    I.S.F/=uku;
  }
  ll cnt=0;
  for(auto &I:A){
    bool jd=false;
    for(auto &J:B){
      if(dot(I.F.F,I.F.S,I.S,J.F.F,J.F.S,J.S.F)>cos(J.S.S)-EPS){jd=true; break;}
    }
    if(jd){cnt++;}
  }
  cout<<cnt<<endl;

  return true;
}

int main(){
  while(solve());
  

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3348
final_rank: 9

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

// #define double long double

const double EPS = 1e-9;

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

int N, M;
vector<P> stars, scopes;
vector<double> angs;

double dist(P a, P b) {
  return sqrt(pow(a.x-b.x, 2)+pow(a.y-b.y, 2)+pow(a.z-b.z, 2));
}

bool contain(int a, int b) {
  double l = 0, r = 1000000;
  int cnt = 100;
  P A = stars[a];
  while ( cnt-- ) {
    double mid = (l+r)/2;
    P B = scopes[b];
    B.x *= mid; B.y *= mid; B.z *= mid;
    double dist1 = dist(A, B);
    B = scopes[b];
    B.x *= (mid+EPS); B.y *= (mid+EPS); B.z *= (mid+EPS);
    double dist2 = dist(A, B);
    if ( dist1 > dist2 ) l = mid;
    else r = mid;    
  }

  P B = scopes[b];
  B.x *= l; B.y *= l; B.z *= l;
  double dist1 = dist(P(0, 0, 0), B);
  double dist2 = dist(A, B);
  if ( dist2 < tan(angs[b])*dist1 ) return true;
  else return false;
}

int main() {
  while ( cin >> N, N ) {
    stars.resize(N);
    for ( int i = 0; i < N; i++ ) {
      cin >> stars[i].x >> stars[i].y >> stars[i].z;
    }
    
    cin >> M;
    scopes.resize(M);
    angs.resize(M);
    for ( int i = 0; i < M; i++ ) {
      cin >> scopes[i].x >> scopes[i].y >> scopes[i].z;
      cin >> angs[i];    
    }

    int ans = 0;
    for ( int i = 0; i < N; i++ ) {
      for ( int j = 0; j < M; j++ ) {
	if ( contain(i, j) ) {
	  ans++;
	  break;
	}
      }
    }

    cout << ans << endl;
  }  
  return 0;
}
accuracy: 1
time_ms: 120
memory_kb: 3480
final_rank: 20

code_snippet: #include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

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

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

bool was_output = false;
template<class t>
void output(t x){
	if(was_output)cout << " ";
	was_output = true;
	cout << x;
}

void outendl(){
	was_output = false;
	cout << endl;
}

struct vector3{
	double x;
	double y;
	double z;
	vector3(double a, double b, double c):x(a), y(b), z(c){}
	vector3(){}
	vector3 operator+(vector3 o){return vector3(x+o.x, y+o.y, z+o.z);}
	vector3 operator-(vector3 o){return vector3(x-o.x, y-o.y, z-o.z);}
	vector3 operator*(double o){return vector3(x*o, y*o, z*o);}
	vector3 operator/(double o){return vector3(x/o, y/o, z/o);}

	double magnitude(){return sqrt(x*x+y*y+z*z);}
};

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

double getangle(vector3 a, vector3 b){
	a = a / a.magnitude();
	b = b / b.magnitude();
	return acos(dot(a, b));
}

int main(){
	int n, m;
	while(cin>>n&&n){
		vector<vector3> stars(n);
		foreach(i, stars){
			double x, y, z;
			cin >> x >> y >> z;
			i = vector3(x, y, z);
		}
		cin >> m;
		vector<vector3> scopes(m);
		vector<double> angle(m);
		rep(i, m){
			double a, b, c, d;
			cin >> a >> b >> c >> d;
			scopes[i] = vector3(a, b, c);
			angle[i] = d;
		}
		int ans = 0;
		foreach(i, stars){
			rep(j, m){
				double nangle = getangle(i, scopes[j]);
				if(nangle-angle[j]<1e-8){
					++ans;
					break;
				}
			}
		}

		cout << ans << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3372
final_rank: 11

code_snippet: #include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e12;
 
struct Point{
    double x,y,z;
    Point(double x, double y, double z):x(x), y(y), z(z){}
    Point(){}
    Point &operator +=(const Point &a){ x+=a.x; y+=a.y; z+=a.z; return *this; }
    Point &operator -=(const Point &a){ x-=a.x; y-=a.y; z-=a.z; return *this; }
    Point &operator *=(const double &a){ x*=a; y*=a; z*=a; return *this; }
    Point operator +(const Point &a) const{ return Point(x+a.x, y+a.y, z+a.z); }
    Point operator -(const Point &a) const{ return Point(x-a.x, y-a.y, z-a.z); }
    Point operator *(const double &a) const{ return Point(a*x, a*y, a*z); }
    Point operator -() { return Point(-x, -y, -z); }
};

double dot(const Point &a, const Point &b){
    return a.x*b.x +a.y*b.y +a.z*b.z;
}
Point cross(const Point &a, const Point &b){
    return Point(a.y*b.z -a.z*b.y, a.z*b.x -a.x*b.z, a.x*b.y -a.y*b.x);
}
double abs(const Point &a){
    return sqrt(dot(a, a));
}
Point unit(const Point &a){
    return a *(1/abs(a));
}
bool operator ==(const Point &a, const Point &b){
    return abs(a-b) < EPS;
}
 
int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;

        vector<Point> p(n);
        for(int i=0; i<n; i++){
            cin >> p[i].x >> p[i].y >> p[i].z;
        }
        vector<bool> invalid(n, false);
        for(int i=0; i<n; i++){
            if(invalid[i]) continue;
            for(int j=i+1; j<n; j++){
                if(unit(p[i]) == unit(p[j])){
                    invalid[j] = true;
                }
            }
        }

        int m;
        cin >> m;
        int ans = 0;
        for(int i=0; i<m; i++){
            Point dir;
            double theta;
            cin >> dir.x >> dir.y >> dir.z >> theta;
            double costheta = cos(theta);
            for(int j=0; j<n; j++){
                if(invalid[j]) continue;
                if(dot(p[j], dir)/(abs(p[j])*abs(dir)) +EPS > costheta){
                    ans++;
                    invalid[j] = true;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3332
final_rank: 18

code_snippet: #include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
int d[200010],dp[1010][1010];
double w[1000],v[1000];
double box[200010];
char field[200][200];

double dot(double a,double b,double c, double x,double y,double z){
  return a * x + b * y + c * z;
}

int main(){
  double x[500],y[500],z[500];
  while(1){
    cin >> n;
    if(!n)break;
    ll ans = 0;
    clr(d,0);
    rep(i,0,n)cin >> x[i] >> y[i] >> z[i];
    cin >> m;
    rep(i,0,m){
      double a,b,c,r;
      cin >> a >> b >> c >> r;
      double abs1 = sqrt(dot(a,b,c, a,b,c));
      rep(j,0,n){
        double abs2 = sqrt(dot(x[j],y[j],z[j], x[j],y[j],z[j]));
        double Cos = dot(a,b,c, x[j],y[j],z[j]) / abs1 / abs2;
        double q = acos(Cos);
        if(q < r + 0.00000001)d[j]++;
      }
    }
    rep(i,0,n)if(d[i])ans++;
    print(ans);
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4224
final_rank: 19

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<tuple<ld, ld, ld>>stars;
		for (int i = 0; i < N; ++i) {
			ld x, y, z; cin >> x >> y >> z;
			ld dis = sqrt(x*x + y*y + z*z);
			x /= dis; y /= dis; z /= dis;
			stars.push_back(make_tuple(x, y, z));
		}
		int T; cin >> T;
		vector<tuple<ld, ld, ld, ld>>eyes;
		for (int i = 0; i < T; ++i) {
			ld x, y, z, theta; cin >> x >> y >> z >> theta;
			ld dis = sqrt(x*x + y*y + z*z);
			x /= dis; y /= dis; z /= dis;
			eyes.push_back(make_tuple(x, y, z, theta));
		}
		vector<int>cansee(N);
		for (int i = 0; i < N; ++i) {
			ld sx, sy, sz;
			tie(sx, sy, sz) = stars[i];

			for (int j = 0; j < T; ++j) {
				ld ex, ey, ez, theta;
				tie(ex, ey, ez, theta) = eyes[j];
				ld num = sx*ex + sy*ey + sz*ez;
				ld num2 = cos(theta);
				if (cos(theta)<  sx*ex + sy*ey + sz*ez)cansee[i] = true;
			}

		}
		int ans = count(cansee.begin(), cansee.end(), 1);
		cout << ans << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3340
final_rank: 8

code_snippet: #include <iostream>
#include <cmath>
#include <vector>
#include <set>

using namespace std;

#define EPS (1e-8)

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

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

double norm(const Point &p)
{
    return dot(p, p);
}

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

bool can_watch(const Point &a, const Point &b, double the)
{
    double t = acos(dot(a, b) / abs(a) / abs(b));
    return (t < the + EPS);
}

int main()
{
    int n, m;
    while (cin >> n, n) {
        vector<Point> s(n);
        for (int i = 0; i < n; i++) {
            cin >> s[i].x >> s[i].y >> s[i].z;
        }
        Point p;
        double the;
        set<int> stars;
        cin >> m;       
        for (int i = 0; i < m; i++) {
            cin >> p.x >> p.y >> p.z >> the;
            for (int j = 0; j < n; j++) {
                if (can_watch(s[j], p, the)) {
                    stars.insert(j);
                }
            }
        }
        cout << stars.size() << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3384
final_rank: 13

code_snippet: #include<bits/stdc++.h>
#define eps (1e-11)
using namespace std;

class Point3d{
public:
  double x,y,z;
  Point3d(double a=0,double b=0,double c=0):x(a),y(b),z(c){}
};

double norm(Point3d a,Point3d b){
  return pow((a.x-b.x),2)+pow((a.y-b.y),2)+pow((a.z-b.z),2);
}

double abs(Point3d a,Point3d b){ 
 return sqrt(norm(a,b));
}

int main()
{
  int n,m;
  double a,b,c,d;
    
  while(1){
    cin>>n;
    if(n==0)break;

    vector<Point3d> v;
    bool st[501]={};

    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      v.push_back(Point3d(a,b,c));
    }
    cin>>m;

    Point3d origin(0.0,0.0,0.0);
    for(int i=0;i<m;i++){
      cin>>a>>b>>c>>d;
      Point3d p3(a,b,c);
      double x,y,z,r;
      for(int j=0;j<n;j++){
        x=abs(v[j],origin);
        y=abs(p3,origin);
        z=abs(v[j],p3);
     	r=acos((x*x+y*y-z*z)/(x*y*2));
        if((r-d)<eps)st[j]=true;
      }
    }
    int ans=0;
    for(int i=0;i<n;i++)if(st[i])ans++;
    cout<<ans<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1332
final_rank: 4

code_snippet: #include <bits/stdc++.h>
#define N 500
#define M 50
using namespace std;

int main(){
  int n,m;
  double sx[N],sy[N],sz[N],tx[M],ty[M],tz[M],r[M];
  bool ans[N];
  while(1){
    cin>>n;
    if(!n) break;
    for(int i=0;i<n;i++) cin>>sx[i]>>sy[i]>>sz[i],ans[i]=false;
    cin>>m;
    for(int i=0;i<m;i++) cin>>tx[i]>>ty[i]>>tz[i]>>r[i];
    for(int i=0;i<m;i++){
      for(int j=0;j<n;j++){
	double d1=sqrt(sx[j]*sx[j]+sy[j]*sy[j]+sz[j]*sz[j]);
	double X=sqrt(tx[i]*tx[i]+ty[i]*ty[i]+tz[i]*tz[i]);
	double t=(tx[i]*sx[j]+ty[i]*sy[j]+tz[i]*sz[j])/(X*d1);
	if(acos(t)<=r[i]) ans[j]=true;
      }
    }
    int cnt=0;
    for(int i=0;i<n;i++)
      if(ans[i]) cnt++;
    cout<<cnt<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1312
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#define N 500
#define M 50
using namespace std;

int main(){
  int n,m;
  double sx[N],sy[N],sz[N],tx[M],ty[M],tz[M],r[M];
  bool ans[N];
  while(1){
    cin>>n;
    if(!n) break;
    for(int i=0;i<n;i++) cin>>sx[i]>>sy[i]>>sz[i],ans[i]=false;
    cin>>m;
    for(int i=0;i<m;i++) cin>>tx[i]>>ty[i]>>tz[i]>>r[i];
    for(int i=0;i<m;i++){
      for(int j=0;j<n;j++){
	double d1=sqrt(sx[j]*sx[j]+sy[j]*sy[j]+sz[j]*sz[j]);
	double X=sqrt(tx[i]*tx[i]+ty[i]*ty[i]+tz[i]*tz[i]);
	double Y=X*tan(r[i]);
	double t=(tx[i]*sx[j]+ty[i]*sy[j]+tz[i]*sz[j])/(X*d1);
	if(/*d1<=Y&&*/acos(t)<=r[i]) ans[j]=true;
      }
    }
    int cnt=0;
    for(int i=0;i<n;i++)
      if(ans[i]) cnt++;
    cout<<cnt<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1312
final_rank: 1

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

class Point3d{
public:
  double x,y,z;
  Point3d(double a=0,double b=0,double c=0):x(a),y(b),z(c){}
};

double norm(Point3d a,Point3d b){
  return pow((a.x-b.x),2)+pow((a.y-b.y),2)+pow((a.z-b.z),2);
}

double abs(Point3d a,Point3d b){ 
 return sqrt(norm(a,b));
}

int main()
{
  vector<Point3d> v;
  int n,m;
  int ans;
  double eps=0.000000001;
  bool st[501];

  while(1){
    cin>>n;
    if(n==0)break;
    double a,b,c,d;
    for(int i=0;i<501;i++)st[i]=false;
    v.clear();
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      v.push_back(Point3d(a,b,c));
    }
    cin>>m;

    Point3d origin(0.0,0.0,0.0);
    for(int i=0;i<m;i++){
      cin>>a>>b>>c>>d;
      Point3d p3(a,b,c);
      double x,y,z,r;
      for(int j=0;j<n;j++){
	x=abs(v[j],origin);
	y=abs(p3,origin);
	z=abs(v[j],p3);
	//	printf("%.10f %.10f %.10f\n",x,y,z);
     	r=acos((x*x+y*y-z*z)/(x*y*2));
	
	//	printf("%.10f %.10f\n",r,d);
	if((r-d)<eps)st[j]=true;
      }
    }
    ans=0;
    for(int i=0;i<n;i++)if(st[i])ans++;
    cout<<ans<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 1332
final_rank: 5

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

int n,m;
double x[1000],y[1000],z[1000];
double tx,ty,tz,ar;

double dot(double ax,double ay,double az,
           double bx,double by,double bz){
  return ax*bx+ay*by+az*bz;
}

int calc(double sx,double sy,double sz){
  double S=sqrt(sx*sx+sy*sy+sz*sz);
  double T=sqrt(tx*tx+ty*ty+tz*tz);
  double Cos = dot(tx,ty,tz,sx,sy,sz)/T/S;
  double ti=acos(Cos);

  if(ti < ar + 0.00000001 ){
    return 1;
  }else{
    return 0;
  }
}
bool flg[1000];
int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      flg[i]=false;
      cin>>x[i]>>y[i]>>z[i];
    }
    cin>>m;
    for(int i=0;i<m;i++){
      cin>>tx>>ty>>tz>>ar;
      for(int j=0;j<n;j++){
        if(calc(x[j],y[j],z[j]))flg[j]=true;
      }
    }
    int ans=0;
    for(int i=0;i<n;i++)ans+=flg[i];
    cout<<ans<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1324
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)

int main(void){
  int n;
  while(cin >> n, n){
    vector< vector<double> > s(n, vector<double>(3));
    REP(i, n){
      REP(j, 3){
        cin >> s[i][j];
      }
    }
    int m;
    cin >> m;
    vector< vector<double> > t(m, vector<double>(4));
    REP(i, m){
      REP(j, 4){
        cin >> t[i][j];
      }
    }

    int ans = 0;
    REP(i, n){
      REP(j, m){
        double sx = s[i][0];
        double sy = s[i][1];
        double sz = s[i][2];
        double tx = t[j][0];
        double ty = t[j][1];
        double tz = t[j][2];
        double tt = t[j][3];
        double len_s = pow(sx*sx + sy*sy + sz*sz,0.5);
        double len_t = pow(tx*tx + ty*ty + tz*tz,0.5);
        double costheta = (sx*tx + sy*ty + sz*tz) / (len_s * len_t);
        double theta = acos(costheta);
        if(theta < tt){
          ans++;
          break;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 1444
final_rank: 6