#include <cstdio>
#include <algorithm>
//sort pairs of coordinates by value
void sbv(double &x1, double &x2, double &y1, double &y2)
{
if( x1 > x2 ) std::swap( x1 , x2 );
if( y1 > y2 ) std::swap( y1 , y2 );
}
//find whether the rectangles intersect
bool intersect( double b1, double e1, double b2, double e2 )
{
//"b" for "beginning", "e" for "end" (imagine the line segments on the coordinate axis)
if( b2 >= e1 || e2 <= b1 ) return false;
return true;
}
int main()
{
double a, b, c, d; //meaningful coodinates of rectangle sides
int n; scanf( "%d", &n );
scanf( "%lg %lg %lg %lg", &a, &b, &c, &d );
double x1 = a, x2 = b, y1 = c, y2 = d; //"x" and "y" pairs are for rectangle of common area
for( int i=1; i<n; i++ )
{
scanf( "%lg %lg %lg %lg", &a, &b, &c, &d ); //refresh the coords.
if( intersect( x1, x2, a, b ) && intersect( y1, y2, c, d ) ) //if they intersect
{
sbv( a, x1, x2, b ); //sort again to find the inner points
sbv( c, y1, y2, d ); //(image is attached)
printf("Common area of %d rectangles S = %lg\n", i+1, (y2-y1)*(x2-x1) );
}
else
{
printf("System of rectangles has no common area.\n");
break;
}
}
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGFsZ29yaXRobT4KLy9zb3J0IHBhaXJzIG9mIGNvb3JkaW5hdGVzIGJ5IHZhbHVlCnZvaWQgc2J2KGRvdWJsZSAmeDEsIGRvdWJsZSAmeDIsIGRvdWJsZSAmeTEsIGRvdWJsZSAmeTIpCnsKICAgIGlmKCB4MSA+IHgyICkgc3RkOjpzd2FwKCB4MSAsIHgyICk7CiAgICBpZiggeTEgPiB5MiApIHN0ZDo6c3dhcCggeTEgLCB5MiApOwp9Ci8vZmluZCB3aGV0aGVyIHRoZSByZWN0YW5nbGVzIGludGVyc2VjdApib29sIGludGVyc2VjdCggZG91YmxlIGIxLCBkb3VibGUgZTEsIGRvdWJsZSBiMiwgZG91YmxlIGUyICkKewogICAgLy8iYiIgZm9yICJiZWdpbm5pbmciLCAiZSIgZm9yICJlbm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