Problem: Convex polygon pillar industrial city

The Industrial Convex Pillar City (ICPC) is a city of buildings in the shape of several convex polygonal columns. You are about to walk through this city from your current location S to your destination T. The sun is strong today, so I want to go to my destination without passing through the sun as much as possible. If the building is on a straight line connecting the point where you are standing and the sun, you are behind the building and will not be exposed to the sun. Also, since all the outer circumferences of the buildings in this city have eaves, while walking along the outer circumference of the buildings, even if you walk along the edge of the sun, you will not receive the sunlight. You are free to walk around the city anywhere except inside the building.

Create a program that outputs the walking distance of Hinata when walking from the current location to the destination so as not to receive the sun.

<image>

Figure E1: For the first input

<image>

Figure E2: For the second input

<image>

Figure E3: For the third input

Input

The input consists of multiple datasets. The maximum number of data sets does not exceed 30. Each dataset is represented in the following format.

> N
> NV1 H1 X1,1 Y1,1 X1,2 Y1,2 ... X1, NV1 Y1, NV1
> ...
> NVN HN XN, 1 YN, 1 XN, 2 YN, 2 ... XN, NVN YN, NVN
> θ φ
> Sx Sy Tx Ty
>

N in the first line represents the number of buildings. The following N lines specify the shape of each building. NVi represents the number of vertices of the polygon when the i-th building is viewed from above, and Hi represents the height of the i-th building. Xi, j and Yi, j represent the x-coordinate and y-coordinate of the j-th vertex of the polygon when the i-th building is viewed from above. The vertices are given in counterclockwise order. All buildings are convex polygons when viewed from above, and there are no other buildings inside the building, and the vertices and sides do not overlap with other polygons. The following lines are given θ and φ, which represent the direction of the sun, θ represents the direction of the sun as a counterclockwise angle from the positive direction of x, and φ is the elevation angle of the sun from the horizon, that is, looking up at the sun. It represents the angle between the direction of the line of sight and the ground surface. However, the sun is at infinity and does not change its position during movement. The following lines are given the coordinates of the current location and destination, (Sx, Sy) and (Tx, Ty).

> All the numerical values ​​given by the input are integers and satisfy the following conditions.

> 1 ≤ N ≤ 100
> 3 ≤ NVi ≤ 12
> 1 ≤ Hi ≤ 1,000
> 0 ≤ θ <360
> 0 <φ <90

All coordinates are -1,000 or more and 1,000 or less. The current location and the destination are different, and neither exists inside or outside the building.

> The end of the input is represented by a single zero line.

> ### Output

For each dataset, output the shortest walking distance in Hinata on one line. The output must not have an absolute error greater than 0.001.

> ### Sample Input


2
4 1 0 0 1 0 1 1 0 1
4 2 2 2 3 2 3 3 2 3
60 45
-1 -1 4 4
Four
4 1 0 0 3 1 1 2 0 1
3 2 10 7 8 2 12 4
6 8 7 12 8 13 9 15 10 19 11 24 10 25
5 4 16 2 16 4 12 8 14 2 15 0
167 38
3 3 15 21
12
4 3 -8 -3 -9 -3 -9 -5 -8 -6
4 5 -4 -5 -7 -5 -7 -6 -5 -6
4 2 -4 1 -5 1 -5 -4 -4 -4 -4
4 1 -1 1 -2 1 -2 -4 -1 -3
4 2 2 3 -1 3 -2 2 3 2
4 1 3 1 2 1 2 -3 3 -4
4 7 1 0 0 0 0 -1 1 -1
4 4 9 5 7 5 7 4 10 4
4 3 6 5 5 4 5 0 6 0
4 5 8 -1 5 -1 6 -2 8 -2
4 1 10 0 9 0 9 -2 10 -1
4 6 10 2 8 2 8 1 10 1
131 78
-10 10 10 -10
0


Output for Sample Input


1.93185
7.87174
20.86840





Example

Input

2
4 1 0 0 1 0 1 1 0 1
4 2 2 2 3 2 3 3 2 3
60 45
-1 -1 4 4
4
4 1 0 0 3 1 1 2 0 1
3 2 10 7 8 2 12 4
6 8 7 12 8 13 9 15 10 19 11 24 10 25
5 4 16 2 16 4 12 8 14 2 15 0
167 38
3 3 15 21
12
4 3 -8 -3 -9 -3 -9 -5 -8 -6
4 5 -4 -5 -7 -5 -7 -6 -5 -6
4 2 -4 1 -5 1 -5 -4 -4 -4
4 1 -1 1 -2 1 -2 -4 -1 -3
4 2 2 3 -1 3 -2 2 3 2
4 1 3 1 2 1 2 -3 3 -4
4 7 1 0 0 0 0 -1 1 -1
4 4 9 5 7 5 7 4 10 4
4 3 6 5 5 4 5 0 6 0
4 5 8 -1 5 -1 6 -2 8 -2
4 1 10 0 9 0 9 -2 10 -1
4 6 10 2 8 2 8 1 10 1
131 78
-10 10 10 -10
0


Output

1.93185
7.87174
20.86840

Solution (in CPP):

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

using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

using D = double;
const D PI = acos(D(-1)), EPS = 1e-10;

struct Pt2 {
    D x, y;
    Pt2() {}
    Pt2(D _x, D _y) : x(_x), y(_y) {}
    Pt2 operator+(const Pt2 &r) const { return Pt2(x+r.x, y+r.y); }
    Pt2 operator-(const Pt2 &r) const { return Pt2(x-r.x, y-r.y); }
    Pt2 operator*(const Pt2 &r) const { return Pt2(x*r.x - y*r.y, x*r.y + y*r.x); }
    Pt2& operator+=(const Pt2 &r) { return *this=*this+r; }
    Pt2& operator-=(const Pt2 &r) { return *this=*this-r; }
    Pt2 operator-() const { return Pt2(-x, -y); }

    D abs() const { return sqrt(x*x + y*y); }
    D rabs() const { return max(::abs(x), ::abs(y)); }

    static Pt2 polar(D le, D th) { return Pt2(le * cos(th), le * sin(th)); }
};
ostream& operator<<(ostream& os, const Pt2 &p) {
    os << "(" << p.x << ", " << p.y << ")";
    return os;
}
using P = Pt2;
struct L {
    P s, t;
    L() {}
    L(P _s, P _t) : s(_s), t(_t) {}
    P vec() const { return t-s; }
    D abs() const { return vec().abs(); }
};
using Pol = V<P>;

int sgn(D a) {
    if (abs(a) <= EPS) return 0;
    return (a < 0) ? -1 : 1;
}
int rsgn(D a, D f) {
    if (abs(a) <= f*EPS) return 0;
    return (a < 0) ? -1 : 1;
}
bool near(P a, P b) { return !sgn((a-b).abs()); }

bool lessP(P l, P r) {
    if (sgn(r.x-l.x)) return l.x < r.x;
    if (sgn(r.y-l.y)) return l.y < r.y;
    return false;
}

D cross(P a, P b) { return a.x*b.y - a.y*b.x; }
D dot(P a, P b) { return a.x*b.x + a.y*b.y; }

int ccw(P b, P c) {
    int s = rsgn(cross(b, c), b.rabs());
    if (s) return s;
    if (!sgn(c.rabs()) || !sgn((c-b).rabs())) return 0;
    if (dot(b, c) < 0) return 2;
    if (dot(-b, c-b) < 0) return -2;
    return 0;
}
int ccw(P a, P b, P c) { return ccw(b-a, c-a); }
int ccw(L l, P p) { return ccw(l.s, l.t, p); }

bool insSS(const L &s, const L &t) {
    int a = ccw(s, t.s), b = ccw(s, t.t);
    int c = ccw(t, s.s), d = ccw(t, s.t);
    if (a*b <= 0 && c*d <= 0) return true;
    return false;
}

D distLP(const L &l, const P &p) {
    return abs(cross(l.vec(), p-l.s)) / l.abs();
}

D distSP(const L &s, const P &p) {
    P s2 = s.vec() * P(0, 1);
    if (ccw(s.s, s.s+s2, p) == 1) return (s.s-p).abs();
    if (ccw(s.t, s.t+s2, p) == -1) return (s.t-p).abs();
    return distLP(s, p);
}

D distSS(const L &s, const L &t) {
    if (insSS(s, t)) return 0;
    return min({distSP(s, t.s), distSP(s, t.t), distSP(t, s.s), distSP(t, s.t)});
}

const P& c_at(const Pol &pol, int i) {
    int n = int(pol.size());
    assert(0 <= i && i < 2*n);
    return pol[(i<n) ? i : i-n];
}

int contains(const Pol &pol, P p) {
    int in = -1;
    for (int i = 0; i < int(pol.size()); i++) {
        P a = pol[i], b = c_at(pol, i+1);
        if (ccw(a, b, p) == 0) {
            return 1;
        }
        if (a.y > b.y) swap(a, b);
        if (!(a.y <= p.y && p.y < b.y)) continue;
        if (sgn(a.y - p.y) ? (cross(a-p, b-p) > 0) : (a.x > p.x)) in *= -1;
    }
    return in + 1;
}

Pol convex(Pol p) {
    sort(begin(p), end(p), lessP);
    p.erase(unique(begin(p), end(p), near), end(p));
    Pol up, down;
    for (P d: p) {
        while (up.size() > 1 && ccw(up[up.size()-2], up[up.size()-1], d) == 1) up.pop_back();
        up.push_back(d);
    }
    reverse(begin(up), end(up));
    for (P d: p) {
        while (down.size() > 1 && ccw(down[down.size()-2], down[down.size()-1], d) == -1) down.pop_back();
        down.push_back(d);
    }
    down.insert(begin(down), begin(up) + 1, end(up) - 1);
    return down;
}

const D INF = 1e100;

bool solve() {
    int n;
    cin >> n;
    if (n == 0) return false;
    P s, t;
    V<D> h(n);
    V<Pol> pols;
    for (int i = 0; i < n; i++) {
        int m;
        cin >> m >> h[i];
        Pol pol;
        for (int j = 0; j < m; j++) {
            D x, y;
            cin >> x >> y;
            P p = P(x, y);
            pol.push_back(p);
        }
        pols.push_back(pol);
    }
    D th, ph;
    cin >> th >> ph;
    th = (th / 360.0) * 2 * PI;
    ph = (ph / 360.0) * 2 * PI;
    {
        D x, y;
        cin >> x >> y;
        s = P(x, y);
        cin >> x >> y;
        t = P(x, y);
    }

    for (int i = 0; i < n; i++) {
        int m = int(pols[i].size());
        for (int j = 0; j < m; j++) {
            P p = pols[i][j];
            pols[i].push_back(p + P::polar(h[i] / tan(ph), PI + th));
        }
        pols[i] = convex(pols[i]);
    }

    VV<D> di(n+2, V<D>(n+2, INF));
    auto adde = [&](int a, int b, D x) {
        di[a][b] = min(di[a][b], x);
        di[b][a] = min(di[b][a], x);
    };
    for (int i = 0; i < n+2; i++) {
        adde(i, i, 0);
    }
    adde(n, n+1, (s-t).abs());

    for (int i = 0; i < n; i++) {
        if (contains(pols[i], s)) adde(i, n, 0);
        if (contains(pols[i], t)) adde(i, n+1, 0);

        int m = int(pols[i].size());
        for (int j = 0; j < m; j++) {
            P a = pols[i][j], b = c_at(pols[i], j+1);
            L l = L(a, b);
            adde(i, n, distSP(l, s));
            adde(i, n+1, distSP(l, t));
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            const Pol& lp = pols[i];
            const Pol& rp = pols[j];
            if (contains(lp, rp[0]) || contains(rp, lp[0])) adde(i, j, 0);
            int m1 = int(lp.size()), m2 = int(rp.size());
            for (int k1 = 0; k1 < m1; k1++) {
                for (int k2 = 0; k2 < m2; k2++) {
                    L l1 = L(lp[k1], c_at(lp, k1+1));
                    L l2 = L(rp[k2], c_at(rp, k2+1));
                    adde(i, j, distSS(l1, l2));
                }
            }
        }
    }


    for (int k = 0; k < n+2; k++) {
        for (int i = 0; i < n+2; i++) {
            for (int j = 0; j < n+2; j++) {
                di[i][j] = min(di[i][j], di[i][k] + di[k][j]);
            }
        }
    }

    cout << di[n][n+1] << endl;
    return true;
}

int main() {
    cout << setprecision(20);
    while (solve()) {}
    return 0;
}