int a[20], sp[20]; unordered_map<int, ll> dp[50010]; voidsolve(){ int n = read(), k = read(); if (k == 1) {cout << 1; return;} for (int i = 1; i <= k; i++) a[i] = read(); for (int i = 1; i <= k; i++) sp[a[i]] = i; dp[0][0] = 1; for (int b = 0; b < (1 << n); b++) { int fst = k + 1; for (int i = 1; i <= k; i++) if (!((b >> (a[i] - 1)) & 1)) fst = min(fst, i); for (auto &it : dp[b]) { int sb = it.first; ll val = it.second; for (int i = 1; i <= n; i++) { if ((b >> (i - 1)) & 1) continue; if (sp[i] && i != a[fst]) continue; int bit = 1 << (i - 1); int nb = b | bit, nsb = sb | bit; int tr = sb & (~((1 << i) - 1)); if (tr) { int j = __builtin_ctz(tr) + 1; int dl = (1 << n) - 1 - (1 << (j - 1)); nsb &= dl; } dp[nb][nsb] += val; } } } ll ans = 0; for (auto &it : dp[(1 << n) - 1]) if (__builtin_popcount(it.first) == k) ans += it.second; cout << ans; }