#include #include #include using namespace std; using lint = long long; void solve() { int n, t; cin >> n >> t; map dp{{t, 0}}; while (n--) { lint x; cin >> x; map ndp; for (auto [t, c] : dp) { { auto nt = t & x; auto nc = c + abs(t - nt); ndp[nt] = max(ndp[nt], nc); } { auto nt = t | x; auto nc = c + abs(t - nt); ndp[nt] = max(ndp[nt], nc); } } swap(dp, ndp); } lint ans = 0; for (auto [t, c] : dp) ans = max(ans, c); cout << ans << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }