#[allow(dead_code)] fn getline() -> String { let mut res = String::new(); std::io::stdin().read_line(&mut res).ok(); res } #[allow(unused_macros)] macro_rules! readl { ($t: ty) => { { let s = getline(); s.trim().parse::<$t>().unwrap() } }; ($( $t: ty),+ ) => { { let s = getline(); let mut iter = s.trim().split(' '); ($(iter.next().unwrap().parse::<$t>().unwrap(),)*) } }; } #[allow(unused_macros)] macro_rules! readlvec { ($t: ty) => { { let s = getline(); let iter = s.trim().split(' '); iter.map(|x| x.parse().unwrap()).collect::>() } } } #[allow(unused_macros)] // macro_rules! debug { ($x: expr) => { println!("{}: {:?}", stringify!($x), $x) } } macro_rules! debug { ($x: expr) => () } #[allow(dead_code)] fn show(iter: T) -> String where T: Iterator, T::Item: std::fmt::Display { let mut res = iter.fold(String::new(), |sum, e| sum + &format!("{} ", e)); res.pop(); res } #[allow(unused_imports)] use std::cmp::{max, min}; #[allow(unused_imports)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; #[allow(unused_imports)] use std::collections::btree_map::Entry::{Occupied, Vacant}; fn main() { use std::io::Write; let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); } macro_rules! printfln { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); } let dx = [-1, -1, 0, 1, 1, 0, -1]; let dy = [-1, 0, 1, 1, 0, -1, -1]; let (n, k, p) = readl!(usize, usize, i64); let mut qu = VecDeque::new(); let mut dist: Vec<_> = (0..n).map(|i| vec![-1; i+1]).collect(); for _ in 0..k { let (x, y) = readl!(usize, usize); qu.push_back((x-1, y-1, 0)); dist[x-1][y-1] = 0; } let check = |x, y| 0 <= x && x < n as i32 && 0 <= y && y <= x; while let Some((x, y, d)) = qu.pop_front() { for k in 0..dx.len() { let nx = x as i32 + dx[k]; let ny = y as i32 + dy[k]; if check(nx, ny) && dist[nx as usize][ny as usize] == -1 { dist[nx as usize][ny as usize] = d+1; qu.push_back((nx as usize, ny as usize, d+1)); } } } let mut csumu: Vec<_> = (0..n+1).map(|i| vec![0; n+1]).collect(); for i in 0..n { for j in 0..i+1 { // csumu[i+1][j] = dist[i][j] + csumu[i][j]; csumu[j][i+1] = dist[i][j] + csumu[j][i]; } } let csumu = csumu; let mut csuml: Vec<_> = (0..n).map(|i| vec![0; i+2]).collect(); for i in 0..n { for j in 0..i+1 { csuml[i][j+1] = dist[i][j] + csuml[i][j]; } } let csuml = csuml; let mut dp: Vec<_> = (0..n).map(|i| vec![0; i+1]).collect(); let mut vt: Vec<_> = (0..n).map(|i| vec![0; i+1]).collect(); for (i, e) in dp[n-1].iter_mut().enumerate() { if dist[n-1][i] < p { *e = n; vt[n-1][i] = dist[n-1][i]; } else { *e = n-1; vt[n-1][i] = 0; } } for i in (0..n-1).rev() { for j in 0..dist[i].len() { let mut r = dp[i+1][j+1]; let mut val = vt[i+1][j+1] + (csumu[j][r] - csumu[j][i]); while i < r && val >= p { let len = r-i; val -= csuml[r-1][j + len] - csuml[r-1][j]; r -= 1; } dp[i][j] = r; vt[i][j] = val; } } let mut ans = 0; for row in &dp { for &e in row { ans += n-e; } } printfln!("{}", ans); }