Returns the total ways to form arrays such that every consecutive element is different and each element except the first and last can take values from 1 to M
< ? php function totalWays ( $ N , $ M , $ X ) {