typedef long long LL; LL mul( LL a, LL k, LL p ) { LL res = 0; while( k ) { if ( k & 1 ) res = ( res + a ) % p; a = a * 2 % p; k >>= 1; } return res; }