#include using namespace std; template typename enable_if::value, Ostream&>::type operator<<(Ostream& os, const Cont& v){ os << "[ "; for(auto &x : v) os << x << ' '; return os << "]"; } template Ostream& operator << (Ostream &os, const pair &p){ return os << "{" << p.first << ", " << p.second << "}"; } void dbg_cerr() { cerr << "\e[0m\n"; } template void dbg_cerr(Head H, Tail... T) { cerr << ' ' << H; dbg_cerr(T...); } #ifdef LTF #define DEBUG(...) cerr << "\e[1;31m[" #__VA_ARGS__ "]:", dbg_cerr(__VA_ARGS__) #else #define DEBUG(...) #endif void Solve() { int N; cin >> N; vector> p(N); for (auto &[x, y] : p) cin >> x >> y; map, int> mp; for (int i = 0; i < N; i++) mp[p[i]] = i; constexpr int dx[] = {2, 2, 1, -1, -2, -2, -1, 1}; constexpr int dy[] = {-1, 1, 2, 2, 1, -1, -2, -2}; set> st; vector> pos; for (auto &[x, y] : p) { for (int o = 0; o < 8; o++) { int nx = x + dx[o], ny = y + dy[o]; if (!mp.count({nx, ny}) && st.find({nx, ny}) == st.end()) { st.insert({nx, ny}); pos.emplace_back(nx, ny); } } } int M = static_cast(pos.size()); constexpr int kInf = int(1e9); vector dp(M + 1, vector(1 << N, kInf)); dp[0][0] = 0; for (int i = 0; i < M; i++) { auto [x, y] = pos[i]; for (int mask = 0; mask < (1 << N); mask++) { dp[i + 1][mask] = min(dp[i + 1][mask], dp[i][mask]); } for (int o = 0; o < 8; o += 2) { int good_mask = 0; for (int t = o; t < o + 2; t++) { int nx = x + dx[t], ny = y + dy[t]; if (mp.count({nx, ny})) good_mask ^= (1 << mp[{nx, ny}]); } for (int mask = 0; mask < (1 << N); mask++) { dp[i + 1][mask ^ good_mask] = min(dp[i + 1][mask ^ good_mask], dp[i][mask] + 1); } } } if (dp[M][(1 << N) - 1] == kInf) cout << -1 << '\n'; else cout << dp[M][(1 << N) - 1] << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T = 1; // cin >> T; while (T--) { Solve(); } return 0; }