#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using Int = long long; template ostream &operator<<(ostream &os, const pair &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template ostream &operator<<(ostream &os, const vector &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; } template void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } #define COLOR(s) ("\x1b[" s "m") constexpr int DX[4] = {+1, 0, -1, 0}; constexpr int DY[4] = {0, +1, 0, -1}; constexpr int INF = 1001001001; int N; vector X, Y; int U; map, int> ids; int get(int x, int y) { const pair key(x, y); auto it = ids.find(key); if (it != ids.end()) { return it->second; } else { return ids[key] = U++; } } int main() { for (; ~scanf("%d", &N); ) { X.resize(N); Y.resize(N); for (int u = 0; u < N; ++u) { scanf("%d%d", &X[u], &Y[u]); } U = 0; ids.clear(); for (int u = 0; u < N; ++u) { ids[make_pair(X[u], Y[u])] = -1; } int qss[110][4] = {}; for (int u = 0; u < N; ++u) { for (int h = 0; h < 4; ++h) { for (const int dh : {+1, -1}) { const int hh = (h + dh) & 3; const int a = get(X[u] + 2 * DX[h] + DX[hh], Y[u] + 2 * DY[h] + DY[hh]); if (~a) { // cerr< crt(1 << N, INF); crt[0] = 0; for (int a = 0; a < U; ++a) { vector nxt = crt; for (int h = 0; h < 4; ++h) { const int q = qss[a][h]; if (q) { for (int p = q; p < 1 << N; ++p |= q) { chmin(nxt[p], crt[p - q] + 1); } } } crt.swap(nxt); } const int ans = crt.back(); printf("%d\n", (ans < INF) ? ans : -1); } return 0; }