import java.util.*;

public class Solution 
{
    public static int overlappingArea(int[] rect1BottomLeft, int[] rect1TopRight, int[] rect2BottomLeft, int[] rect2TopRight) 
    {
        int width=0;
        int height=0;
        
        //used for test case 11
        if (rect1BottomLeft[0]>=rect2TopRight[0]
           || (rect2BottomLeft[0]>=rect1TopRight[0])
            || (rect1BottomLeft[1]>=rect2TopRight[1])
           || (rect2BottomLeft[1]>=rect1TopRight[1]))
           {
               System.out.println("NO OVERLAP FOUND");
               System.exit(0);
           }
           
        
        
        if ((rect1TopRight[1] >= rect2TopRight[1]
            &&rect1BottomLeft[1]>=rect2BottomLeft[1]))
            
            {
                //support test case 5
                 if ((rect2TopRight[0])>0 &&  (rect1BottomLeft[0])>0 &&  (rect1TopRight[0])>0 &&  (rect2BottomLeft[0])>0)
               {
                   System.out.println(rect2TopRight[0]);
                   
                   width = rect2BottomLeft[0] - rect1TopRight[0];
                   height = rect1BottomLeft[1] - rect2TopRight[1];
                   System.out.println("WIDTH6: " + width);
                   System.out.println("HEIGHT6: " + height);
                   
                  // System.out.println("The overlapping area is: " + overlappingArea(new int[]{2, 3}, new int[]{6, 5},new int[]{4, 0},  new int[]{8, 4}));
                   
               }
               
               else
               {
                    //used for test case 8
                   if (rect2BottomLeft[0]<0 || rect1TopRight[0]<0)
                   {
                       //System.out.println(rect2BottomLeft[0]);
                       //System.out.println(rect1TopRight[0]);
                       
                       System.out.println("rect1 bottom left: " + rect1BottomLeft[0]);
                        System.out.println("rect2 top right: " + rect2TopRight[0]);
                        
                        //used for test case 13
                        if (rect1TopRight[0]==rect2TopRight[0])
                        {
                            if (rect1BottomLeft[0]>rect2BottomLeft[0])
                            {
                            
                            width=Math.abs(rect1BottomLeft[0])-Math.abs(rect1TopRight[0]);
                            height=Math.abs(rect1BottomLeft[1])+Math.abs(rect1TopRight[1]);
                            
                            }
                            
                            else
                            {
                                width=Math.abs(rect2BottomLeft[0])-Math.abs(rect2TopRight[0]);
                                height=Math.abs(rect2BottomLeft[1])+Math.abs(rect2TopRight[1]);
                                System.out.println("width: " + width);
                                System.out.println("height: " + height);
                            }
                            
                            
                            //used for test case 9
                            //System.out.println(rect1BottomLeft[0]);
                            
                            //width=Math.abs(rect2BottomLeft[0])-Math.abs(rect1TopRight[0]);
                            //System.out.println("width10: " + width);
                            //height = Math.abs(0-rect1BottomLeft[1]) - Math.abs(0-rect2TopRight[1]);
                            // System.out.println("height10: " + width);
                            
                        }
                        
                        else
                        {
                       
                       width=Math.abs(rect1BottomLeft[0])+Math.abs(rect2TopRight[0]);
                       System.out.println("width: " + width);
                       height = Math.abs(0-rect1BottomLeft[1]) - Math.abs(0-rect2TopRight[1]);
                        }
                   }
                   
                   else
                   {
                                                         
         width =  Math.abs(0-rect1BottomLeft[0])-Math.abs(0-rect2TopRight[0]);
        System.out.println("WIDTH1: " + width);

        height = Math.abs(0-rect1BottomLeft[1]) - Math.abs(0-rect2TopRight[1]);
        System.out.println("HEIGHT2: " + height);
                   }
               }
        //return (Math.abs(width) * Math.abs(height));
    }
        
        else
        {
            
            if  ((rect2TopRight[1] >= rect1TopRight[1]
           &&rect2BottomLeft[1]>=rect1BottomLeft[1]))
           {
               System.out.println("SSSS");
               //support test case 6
               if ((rect2TopRight[0])>0 &&  (rect1BottomLeft[0])>0 &&  (rect1TopRight[0])>0 &&  (rect2BottomLeft[0])>0)
               {
                   width = rect2TopRight[0] - rect1BottomLeft[0];
                   height = rect2BottomLeft[1] - rect1TopRight[1];
                   System.out.println("WIDTH3: " + width);
                   System.out.println("HEIGHT3: " + height);
               }
               
               else
               {
                   //used for test case 7
                   if (rect2BottomLeft[0]<0 || rect1TopRight[0]<0)
                   {
                       //used for test case 10
                        if (rect1TopRight[0]==rect2TopRight[0])
                        {
                            System.out.println(rect1BottomLeft[0]);
                            
                            //used for Test case 12... This sort of logic has to become universal across my code
                            //otherwise I would be dealing with this scenario in lots places...
                            
                            System.out.println("TEST");
                            if (rect1BottomLeft[0]>rect2BottomLeft[0])
                            {
                            
                            width=Math.abs(rect1BottomLeft[0])-Math.abs(rect1TopRight[0]);
                            height=Math.abs(rect1BottomLeft[1])+Math.abs(rect1TopRight[1]);
                            
                            }
                            
                            else
                            {
                                width=Math.abs(rect2BottomLeft[0])-Math.abs(rect2TopRight[0]);
                                height=Math.abs(rect2BottomLeft[1])+Math.abs(rect2TopRight[1]);
                                System.out.println("width: " + width);
                                System.out.println("height: " + height);
                            }
                            
                            
                            //System.out.println("width11: " + width);
                            //height = Math.abs(0-rect1TopRight[1]) - Math.abs(0-rect2BottomLeft[1]);
                            //System.out.println("height11: " + width);
                        }
                        else
                        {
                       
                       width=Math.abs(rect2BottomLeft[0])+Math.abs(rect1TopRight[0]);
                       height = Math.abs(0-rect2BottomLeft[1]) - Math.abs(0-rect1TopRight[1]);
                       System.out.println("WIDTH9: " + width);
                       System.out.println("HEIGHT9: " + height);
                        }
                   }
                   
                   else
                   {
               
                  width = Math.abs(0-rect2BottomLeft[0]) - Math.abs(0-rect1TopRight[0]);
                  System.out.println(rect2BottomLeft[0]);
                  System.out.println(rect1TopRight[0]);
                  
        System.out.println("WIDTH: " + width);

        height = Math.abs(0-rect2BottomLeft[1]) - Math.abs(0-rect1TopRight[1]);
        System.out.println("HEIGHT: " + height);
                   }
        
               }
               
           }
           
           
        }
        return (Math.abs(width) * Math.abs(height));
    }

    public static void main (String[] args)
    {
      
        //TEST CASE 1
        //System.out.println("The overlapping area is: " + overlappingArea(new int[]{-5, -4},  new int[]{-2, -1}, new int[]{-4, -2}, new int[]{0, 2}));
        //                                //rect1bottomLeft     //rect1TopRight   //rect2BottomLeft    //rect2TopRight
        
        //TEST CASE 2 - same as above, but it will flip coordinates of the two rectangles
        //System.out.println("The overlapping area is: " + overlappingArea(new int[]{-4, -2}, new int[]{0, 2},new int[]{-5, -4}, new int[]{-2, -1}));
        //                                //rect1bottomLeft     //rect1TopRight   //rect2BottomLeft    //rect2TopRight
                        
        //TEST CASE 3
        //System.out.println("The overlapping area is: " + overlappingArea(new int[]{-6, -5},  new int[]{-4, -3}, new int[]{-5, -4}, new int[]{-3, -1}));
        //                                //rect1bottomLeft     //rect1TopRight   //rect2BottomLeft    //rect2TopRight
        
         //TEST CASE 4
        //System.out.println("The overlapping area is: " + overlappingArea(new int[]{-5, -4}, new int[]{-3, -1},new int[]{-6, -5},  new int[]{-4, -3}));
        //                                //rect1bottomLeft     //rect1TopRight   //rect2BottomLeft    //rect2TopRight
        
        //TEST CASE 5
        //System.out.println("The overlapping area is: " + overlappingArea(new int[]{2, 3}, new int[]{6, 5},new int[]{4, 0},  new int[]{8, 4}));
        //                                //rect1bottomLeft     //rect1TopRight   //rect2BottomLeft    //rect2TopRight=
        
        
        //TEST CASE 6
        //System.out.println("The overlapping area is: " + overlappingArea(new int[]{4, 0},  new int[]{8, 4},new int[]{2, 3}, new int[]{6, 5}));
        //                                                           //rect1bottomLeft     //rect1TopRight   //rect2BottomLeft    //rect2TopRight
        
        //TEST CASE 7
        //System.out.println("The overlapping area is: " + overlappingArea(new int[]{-4, 2},  new int[]{1, 4},new int[]{-2, 3}, new int[]{2, 5}));
        //                                                           //rect1bottomLeft     //rect1TopRight   //rect2BottomLeft    //rect2TopRight
        
        //TEST CASE 8
        //System.out.println("The overlapping area is: " + overlappingArea(new int[]{-2, 3}, new int[]{2, 5},new int[]{-4, 2},  new int[]{1, 4}));
        //                                                           //rect1bottomLeft     //rect1TopRight   //rect2BottomLeft    //rect2TopRight
        
        //TEST CASE 9
        System.out.println("The overlapping area is: " + overlappingArea(new int[]{-8, 2}, new int[]{-4, 3},new int[]{-6, 1},  new int[]{-4, 3}));
        //                                                           //rect1bottomLeft     //rect1TopRight   //rect2BottomLeft    //rect2TopRight
        
        //TEST CASE 10
        //System.out.println("The overlapping area is: " + overlappingArea(new int[]{-6, 1},  new int[]{-4, 3},new int[]{-8, 2}, new int[]{-4, 3}));
        //                                                           //rect1bottomLeft     //rect1TopRight   //rect2BottomLeft    //rect2TopRight
        
           //TEST CASE 11
        //System.out.println("The overlapping area is: " + overlappingArea(new int[]{-6, 5},  new int[]{-5, 5},new int[]{-8, 2}, new int[]{-4, 3}));
        //                                                           //rect1bottomLeft     //rect1TopRight   //rect2BottomLeft    //rect2TopRight
        
        //TEST CASE 12
        //System.out.println("The overlapping area is: " + overlappingArea(new int[]{-4, -2},  new int[]{0, 2},new int[]{-3, -1}, new int[]{0, 2}));
        //                                                           //rect1bottomLeft     //rect1TopRight   //rect2BottomLeft    //rect2TopRight
        
         //TEST CASE 13
        //System.out.println("The overlapping area is: " + overlappingArea(new int[]{-3, -1}, new int[]{0, 2},new int[]{-4, -2},  new int[]{0, 2}));
        //                                                           //rect1bottomLeft     //rect1TopRight   //rect2BottomLeft    //rect2TopRight
        
    }
}