import java.util.*;

public class Solution 
{
    public static int overlappingArea(int[] rect1BottomLeft, int[] rect1TopRight, int[] rect2BottomLeft, int[] rect2TopRight) 
    {
        int width;
        int height;
        
        if ((rect1TopRight[1] >= rect2TopRight[1]
            &&rect1BottomLeft[1]>=rect2BottomLeft[1]))
            
            {
                 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
               {
                                                         
         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]))
           {
               
               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
               {
               
                  width = Math.abs(0-rect2BottomLeft[0]) - Math.abs(0-rect1TopRight[0]);
        System.out.println("WIDTH: " + width);

        height = Math.abs(0-rect2BottomLeft[1]) - Math.abs(0-rect1TopRight[1]);
        System.out.println("HEIGHT: " + height);
        
               }
               
           }
           else
           {
            
            System.out.println("NO OVERLAP FOUND");
            return 0;
           }
           
        }
        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
        
        
        
    }
}