long pow(long a,long b){ long result = 1; while(b>0){ if(b%2==1) result = (result * a) % mod; b/=2; a=(a*a)%mod; } return result; }