Given the chessboard dimensions. Find out the number of ways we can place a black and a white Knight on this chessboard such that they cannot attack each other.
The knights have to be placed on different squares. A knight can move two squares horizontally and one square vertically (L shaped), or two squares vertically and one square horizontally (L shaped). The knights attack each other if one can reach the other in one move.
Input: N = 2,M = 2 Output: 12
Input: N = 2,M = 3 Output: 26
Your task is to complete the function solve () which takes the chessboard dimension N and M as inputs and returns the number of ways we can place 2 Knights on this chessboard such that they cannot attack each other. Since this number can be very large, return it modulo 109+7.
Expected Time Complexity: O(N*M).
Expected Auxiliary Space: O(1).
1 <= N * M <= 105
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes