const INF: isize = 1isize << 60; fn main() { let mut nma = String::new(); std::io::stdin().read_line(&mut nma).ok(); let nma: Vec = nma.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nma[0]; let m = nma[1]; let a = nma[2] as isize; let mut lines = (0..m).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); (temp[0]-1, temp[1], temp[2] as isize) }) .collect::>(); lines.sort(); let mut dp = vec![vec![-INF; 2]; n+1]; for i in 0..=n { dp[i][0] = 0; } dp[0][1] = 0; let mut lidx = 0usize; for &(l, r, p) in lines.iter() { while lidx < l { lidx += 1; dp[lidx][0] = dp[lidx][0].max(dp[lidx-1][0]).max(dp[lidx-1][1]); } let lcost = if l == 0 { 0 } else { a }; let rcost = if r == n { 0 } else { a }; dp[r][1] = dp[r][1].max(dp[l][0] + p - lcost - rcost).max(dp[l][1] + p - rcost); } println!("{}", dp.iter().map(|v| v.iter().max().unwrap()).max().unwrap()); }