import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int m = Integer.parseInt(sa[1]); int a = Integer.parseInt(sa[2]); Map> map = new HashMap<>(); for (int i = 0; i < m; i++) { sa = br.readLine().split(" "); Area area = new Area(); area.l = Integer.parseInt(sa[0]); area.r = Integer.parseInt(sa[1]); area.p = Integer.parseInt(sa[2]); List list = map.get(area.r); if (list == null) { list = new ArrayList<>(); map.put(area.r, list); } list.add(area); } br.close(); long[] dp = new long[n + 1]; long max = 0; for (int i = 1; i < n; i++) { List list = map.get(i); if (list == null) { dp[i] = max - a; } else { long max1 = Long.MIN_VALUE; for (Area area : list) { long val = dp[area.l - 1] + area.p; max1 = Math.max(max1, val); } dp[i] = max1 - a; } max = Math.max(max, dp[i]); } List list = map.get(n); if (list != null) { long max1 = Long.MIN_VALUE; for (Area area : list) { long val = dp[area.l - 1] + area.p; max1 = Math.max(max1, val); } dp[n] = max1; max = Math.max(max, dp[n]); } System.out.println(max); } static class Area { int l, r, p; } }