By Fermat 's theorem
x = ( ( x + ( f [ n - i - 1 ] [ m - j ] * f [ i ] [ j - 1 ] ) % ( p - 1 ) ) % ( p - 1 ) ) NEW_LINE ans = ( ( ans * power ( arr [ i ] , x , p ) ) % p ) NEW_LINE print ( ans ) NEW_LINE