local n, m, a = io.read("*n", "*n", "*n") local t = {} for i = 1, m do t[i] = {} t[i].l, t[i].r, t[i].p = io.read("*n", "*n", "*n") end table.sort(t, function(x, y) if x.r ~= y.r then return x.r < y.r else return x.l < y.l end end) local mma = math.max local ret = {} local inf = -100000000000000 for i = 1, n do ret[i] = inf end for i = 1, m do local l, r, p = t[i].l, t[i].r, t[i].p local cost = r == n and 0 or a if l == 1 then ret[r] = mma(ret[r], p - cost) else if ret[l - 1] == inf then ret[l - 1] = -a end ret[r] = mma(ret[r], ret[l - 1] + p - cost) end end local tot = 0 for i = 1, n do tot = mma(tot, ret[i]) end print(tot)