use std::io::*; fn main() { const m: usize = 1002; const offset: isize = 500; let mut stg = vec![vec![0; m]; m]; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let k: usize = itr.next().unwrap().parse().unwrap(); let mut mons = Vec::<(isize, isize, isize)>::new(); for _ in 0..n { mons.push(( itr.next().unwrap().parse().unwrap(), itr.next().unwrap().parse().unwrap(), itr.next().unwrap().parse().unwrap() )); } let mut att = Vec::<(isize, isize, usize, usize, isize)>::new(); for _ in 0..k { att.push(( itr.next().unwrap().parse().unwrap(), itr.next().unwrap().parse().unwrap(), itr.next().unwrap().parse().unwrap(), itr.next().unwrap().parse().unwrap(), itr.next().unwrap().parse().unwrap(), )); } for t in att { let x = (t.0 + offset) as usize; let y = (t.1 + offset) as usize; let xw = std::cmp::min(x + t.2 + 1, m - 1); let yh = std::cmp::min(y + t.3 + 1, m - 1); let d = t.4; stg[x][y] += d; stg[xw][y] -= d; stg[x][yh] -= d; stg[xw][yh] += d; } for i in 0..m { for j in 1..m { stg[i][j] += stg[i][j - 1]; } } for i in 1..m { for j in 0..m { stg[i][j] += stg[i - 1][j]; } } let mut ans = 0; for t in mons { let x = (t.0 + offset) as usize; let y = (t.1 + offset) as usize; let h = t.2; ans += std::cmp::max(h - stg[x][y], 0); } println!("{}", ans); }