#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long LL;
typedef complex<double> pt;
bool byY( pt a, pt b )
{
if( a.imag() == b.imag() )
return a.real() < b.real();
return a.imag() < b.imag();
}
bool byArg( pt a, pt b )
{
return arg(a) < arg(b);
}
bool isRight( pt a, pt b, pt c )
{
return arg((c-b) / (b-a)) < 0;
}
vector<pt> convex_hull( vector<pt> p )
{
vector<pt>::iterator it = min_element( p.begin(), p.end(), byY );
pt o = *it;
p.erase(it);
for(int i=0; i<p.size(); ++i)
p[i] -= o;
sort( p.begin(), p.end(), byArg );
vector<pt> q;
q.push_back( pt(0,0) );
q.push_back( p[0] );
for(int i=1; i<p.size(); ++i) {
while( isRight(q[q.size()-2], q[q.size()-1], p[i]) )
q.pop_back();
q.push_back( p[i] );
}
for(int i=0; i<q.size(); ++i)
q[i] += o;
return q;
}
double outer_prod( pt a, pt b )
{
return (a.real()*b.imag() - b.real()*a.imag())/2;
}
double area( const vector<pt>& q )
{
double a = 0.0;
pt o = q[0];
for(int i=1; i+1<q.size(); ++i)
a += outer_prod(q[i]-o, q[i+1]-o);
return abs(a);
}
class Shadow
{
public:
double area(vector <int> tree, vector <int> light)
{
double x1 = min(tree[0], tree[3]);
double x2 = max(tree[0], tree[3]);
double y1 = min(tree[1], tree[4]);
double y2 = max(tree[1], tree[4]);
double z1 = min(tree[2], tree[5]);
double z2 = max(tree[2], tree[5]);
double x = light[0];
double y = light[1];
double z = light[2];
if(x1==x2 && y1==y2 || y1==y2 && z1==z2 || z1==z2 && x1==x2 )
return 0; // line
if(x1==x2 && x==x1 || y1==y2 && y==y1 || z1==z2 && z==z1 )
return 0; // seen as a line
if( y1 >= y )
return 0; // tree above light
if( y2 >= y )
return -1; // infinite
// otherwise project all vertices two y=0 plain
vector<pt> p;
for(int i=0; i<8; ++i)
{
double X=(i&1 ? x1 : x2);
double Y=(i&2 ? y1 : y2);
double Z=(i&4 ? z1 : z2);
// (Xp-X) : (x-X) = (0-Y) : (y-Y)
double Xp = (X-x)*Y/(y-Y) + X;
double Zp = (Z-z)*Y/(y-Y) + Z;
p.push_back( pt(Xp,Zp) );
}
// calc convex hull and its area
p = convex_hull(p);
return ::area(p);
}
// BEGIN CUT HERE
public:
void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); }
private:
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
void verify_case(int Case, const double &Expected, const double &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
void test_case_0() { int Arr0[] = {1,1,1, 10,1,1}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {5,5,5}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); double Arg2 = 0.0; verify_case(0, Arg2, area(Arg0, Arg1)); }
void test_case_1() { int Arr0[] = {1,3,1, 10,1,1}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {2,2,2}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); double Arg2 = -1.0; verify_case(1, Arg2, area(Arg0, Arg1)); }
void test_case_2() { int Arr0[] = {1,1,1, 2,2,2}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {3,3,3}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); double Arg2 = 15.75; verify_case(2, Arg2, area(Arg0, Arg1)); }
void test_case_3() { int Arr0[] = {1,1,1, 3,3,3} ; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {2,2,2}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); double Arg2 = -1.0; verify_case(3, Arg2, area(Arg0, Arg1)); }
// END CUT HERE
};
// BEGIN CUT HERE
int main() { Shadow().run_test(-1); }
// END CUT HERE