Hi community. I was giving test for some hiring problem. The problem says given an array of size N and numbers from 1...M find number of ways to create the array with the followings restrictions. 1) a[i]≠a[i+1] 2) a[1]=a[N] (1 based index) Constraints 3<=N,M<=10^18 I was came up with formula M*(M-1)^(N-3) (M-2) n>3 and M(M-1) n==3 But it gave WA. Any suggestions. Thankyou in advance.