Function to compute a ^ n % mod
function power ( a , n ) { if ( n == 0 ) return 1 ; let p = power ( a , parseInt ( n / 2 , 10 ) ) % mod ; p = ( p * p ) % mod ; if ( ( n & 1 ) == 1 ) p = ( p * a ) % mod ; return p ; }