#include #define rep(i,a,b) for(int i=a;i=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> que; rep(i, 0, K) { int x, y; cin >> y >> x; x--; y--; A[y][x] = 0; que.push({ x, y }); } while (!que.empty()) { auto q = que.front(); que.pop(); int x, y; tie(x, y) = q; rep(d, 0, 6) { int xx = x + dx[d]; int yy = y + dy[d]; if (0 <= yy and yy < N and 0 <= xx and xx <= yy) { if (A[yy][xx] == inf) { A[yy][xx] = A[y][x] + 1; que.push({ xx, yy }); } } } } } //--------------------------------------------------------------------------------------------------- ll B[4040][4040], C[4040][4040]; void pre() { rep(y, 0, N) rep(x, 0, y + 1) B[y][x] = A[y][x]; rrep(y, N - 1, 0) rep(x, 0, y + 1) { if (x) B[y][x] += B[y][x - 1]; if (y < N - 1) B[y][x] += B[y + 1][x]; if (x and y < N - 1) B[y][x] -= B[y + 1][x - 1]; } rep(y, 0, N) rep(x, 0, y + 1) C[y][x] = A[y][x]; rrep(y, N - 2, 0) rep(x, 0, y + 1) { C[y][x] += C[y + 1][x + 1]; C[y][x] += B[y + 1][x]; if (x) C[y][x] -= B[y + 1][x - 1]; } } ll get(int x, int y, int k) { ll res = C[y][x]; int yy = y + k; if (N <= yy) return res; res -= C[y + k][x + k]; res -= B[y + k][x + k - 1]; if (x) res += B[y + k][x - 1]; return res; } //--------------------------------------------------------------------------------------------------- void _main() { cin >> N >> K >> P; bfs(); pre(); ll ans = 0; rep(y, 0, N) rep(x, 0, y + 1) { int KK = (N - y); if (P <= get(x, y, 1)) ans += KK; else { int ng = 1, ok = KK + 1; while (ng + 1 != ok) { int md = (ng + ok) / 2; if (P <= get(x, y, md)) ok = md; else ng = md; } ans += KK - ok + 1; } } cout << ans << endl; }