import java.util.*;

public class Solution 
{
    public static int overlappingArea(int[] rect1BottomLeft, int[] rect1TopRight, int[] rect2BottomLeft, int[] rect2TopRight) 
    {
        //since rect1 and rect2 have not been identified, it has
        //to be examined from both perspectives...

        //if X co-ordinate (rect1BottomLeft) is greater than or equal to (rect2TopRight), there can NOT be an overlap.

        //principle holds if dealing with squares in positive or negative axis
        
        if ((rect1BottomLeft[0]>=rect2TopRight[0]) || (rect2BottomLeft[0]>=rect1TopRight[0])) 
        {
            return 0;
        }

        //now we do not need to validate X coordinate since the above has confirmed guarantee to be overlap.
        //only exception would be if one of the squares has no width or height... But am assuming this will never be case....
        //however need to consider this...

        //width has to be considered difference X and Y direction for both squares
        // 4 outcomes


        else
        {
            if  (((rect1BottomLeft[0]) == (rect1TopRight[0]))  || 
                ((rect2BottomLeft[0]) == (rect2TopRight[0])) ||
                ((rect1BottomLeft[1]) == (rect1TopRight[1])) ||
                ((rect1BottomLeft[1]) == (rect1TopRight[1])))
                
                {
                    System.out.println("One or more squares are dimensionless.. No overlap/area calculation possible");

                    return 0;
                }

        }
        
        //overlap occurs when comparing Y co-ordintes bottom left (rect1BottomLeft) with top right (rect2TopRight)
        //check if rect1BottomLeft is less than rect2TopRight
        //irrespective of which rectangle is which, if we take absolute
        //it will guarantee a positive area....
    

        //We know there is definitely overlap, so it can be calculated as follows:

        //Multiplication (Difference in X and Y coordinates between:)
        //       rect1TopRight - rect2BottomLeft  (width)   
        //   X   rect1TopRight - rect2BottomLeft  (height) 

        int width = Math.abs(0-rect1TopRight[0]) - Math.abs(0-rect2BottomLeft[0]);

        int height = Math.abs(0-rect1TopRight[1]) - Math.abs(0-rect2BottomLeft[1]);

        return (Math.abs(width) * Math.abs(height));           

        //Test cases 2 and 3 fail.
        //both have all negative coordinates.
        //I need firstly understand the effects if
        //rect1BottomLeft is negative and
        //rect2TopRight is positive
        //will taking absolute or performing   - (-) = + 
        //have an effect on the outcome?

        //Test case 2 scenario
    
        /*
        {-6, -6}   =  rect1BottomLeft
        {-5, -5}   =  rect1TopRight
        {-7, -7}   =  rect2BottomLeft
        {-4, -4}   =  rect2TopRight

        rect1TopRight[0] - rect2BottomLeft[0]
        -5               -  (-7)   =  -5 + 7 =   2

        rect1TopRight[0] -  rect2BottomLeft[1]
        -5               -  (-7)  =   2  

        =4

        However my code was giving  -4 as output.
        I am unsure why given that i had taken absolutes..

        Correct answer is:   1
        //I realised straight away that if rect1 bottom left is in a negative coordinate (-1) and rect 2 top right is in positive coordinate (3)... We expect a difference of 4
        //only way to generate this is 3 - (-1).
        //but then we need to interrogate which is positive and which is negative...
        //There are discrepencies...


        //if both are positive, issues do not arise.
        //we can equally adapt this revised logic below:

        if rect1BottomLeft is 2 and rect2TopRight=3
        //we can examine their difference from 0
        (2-0) = 2    and   (3-0)=3
        //we expect both numbers to be positive...
        //if we subtract in either direction  
        //Math.abs(3-2)  or  Math.abs(2-3)
        //We will always get a positive number

        //Now if I take this logic to 
        //rect1 bottom left is in a negative coordinate (-1) and rect 2 top right is in positive coordinate (3)

        Math.abs (-1-0)  =1
        Math.abs (3-0) = 3

        So performing:
        Math.abs(3-1) = 2
        OR
        Math.abs(1-3) = 2
        //Both scenarios are NOW correct 

        //in my previous calculations I would have either calculated
        Math.abs (3 - -1) = 2    or Math.abs(-1 -3) = 4
    */

    /*
    //The above adjustment is not in relation to my test case failing...

    //I have drawn out the overlaps and it appears the challenge is /presenting an incorrect solution..

    //I am now contemplating if it presented the X and Y values in wrong order in array. But it clearly does not matter since both values are the same...

    //I will try the following now:


    //Test case 3 scenario

    {-8, -8}   //rect1bottomLeft
    {-4, -4}   //rect1TopRight
    {-9, -9}   //rect2BottomLeft 
    {-3, -3}   //rect2TopRight

    //expected answer  = 16

    //My answer 25

    //My calculation:

    int width = Math.abs(rect1TopRight[0]-0) - Math.abs(rect2BottomLeft[0]-0) =    Math.abs(-4) -  Math.abs(-9) = 5


    int height = Math.abs(rect1TopRight[1]-0) - Math.abs(rect2BottomLeft[1]-0);
    = Math.abs(-4) -  Math.abs(-9) = 5
    area = 16..

*/
        
    }
}