Calculate the No. of possible ways two chess pieces can be placed [closed]

This was one of the questions asked in a mock test. If any one has seen this problem somewhere else or know the solution, please help me out.

A famous chess grandmaster was analyzing one of his games in his head and… he suddenly forgot the positions of two important pieces.

However, he is sure about some facts:

  • the location of the first piece on the board is (x1; y1) and xl1 <=
    x1 <= xr1, yl1 <= y1 <= yr1.
  • the location of the second piece on the board is (x2; y2) and xl2
    <= x2 <= xr2, yl2 <= y2 <= yr2.
  • the chessboard cells corresponding to the pieces are of the same
    color.

In other words, he doesn’t remember the exact positions of the pieces, however, for every piece, he is sure about the part of the board where it can be. Part of the board here is just a rectangular submatrix described by 4 coordinates.

Note: obviously, two pieces can’t be in the same location.

Now the grandmaster is wondering, how many placements of this two pieces are possible if he remembers everything correctly?

Input Format:

  • The first line contains an integer, x1, denoting the minimum possible
    row of the first piece.
  • The next line contains an integer xr1, denoting the maximum possible
    row of the first piece
  • The next line contains an integer, yl1, denoting the minimum possible
    column of first piece
  • The next line contains an integer yr1, denoting the maximum possible
    column of the first piece.
  • The next line contains an integer, xl2, denoting the minimum possible
    row of the second piece.
  • The next line contains an integer, xr2, denoting the maximum possible
    row of the second piece.
  • The next line contains an integer, y12, denoting the minimum or
    possible the second piece.
  • The next line contains an integer, yr2, denoting the maximum possible
    column of the second piece.

Sample Input:
Image with sample input and output

Thanks