int power(int a, int n) { int tp = 1; while (n) { if (n & 1) tp = 1ll * tp * a % mod; a = 1ll * a * a % mod, n >>= 1; } return tp; }