#if __INCLUDE_LEVEL__ == 0 #include __BASE_FILE__ void Solve() { int n; int64_t x; IN(n, x); vector> v; while (n--) { int c; IN(c); if (x >> c & 1) { continue; } int64_t y = x; y >>= c + 1; y <<= c + 1; v.emplace_back(y == 0 ? -INF64 : y - 1, y | INT64_C(1) << c); } ranges::sort(v); int64_t ans = INF64; int64_t mx = 0; for (auto [y, z] : v) { SetMin(ans, x - y + mx); SetMax(mx, z - x); } SetMin(ans, mx); OUT(2 * ans); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; IN(t); while (t--) { Solve(); } } #elif __INCLUDE_LEVEL__ == 1 #include template concept Range = std::ranges::range && !std::convertible_to; template concept Tuple = std::__is_tuple_like::value && !Range; namespace std { istream& operator>>(istream& is, Range auto&& r) { for (auto&& e : r) is >> e; return is; } istream& operator>>(istream& is, Tuple auto&& t) { apply([&](auto&... xs) { (is >> ... >> xs); }, t); return is; } ostream& operator<<(ostream& os, Range auto&& r) { auto sep = ""; for (auto&& e : r) os << exchange(sep, " ") << e; return os; } ostream& operator<<(ostream& os, Tuple auto&& t) { auto sep = ""; apply([&](auto&... xs) { ((os << exchange(sep, " ") << xs), ...); }, t); return os; } } // namespace std using namespace std; #define LAMBDA2(x, y, ...) [&](auto&& x, auto&& y) -> decltype(auto) { return __VA_ARGS__; } #define SetMin(...) LAMBDA2(x, y, y < x && (x = y, 1))(__VA_ARGS__) #define SetMax(...) LAMBDA2(x, y, x < y && (x = y, 1))(__VA_ARGS__) #define INF64 (INT64_MAX / 2) #define IN(...) cin >> forward_as_tuple(__VA_ARGS__) #define OUT(...) cout << forward_as_tuple(__VA_ARGS__) << '\n' #endif // __INCLUDE_LEVEL__ == 1