from heapq import heappush, heappop N, Y, Z = map(int, input().split()) slime = [list(map(int, input().split())) for _ in range(N)] slime.sort(key=lambda x:x[1]) idx = 0 que = [] ans = 0 while Y < Z and idx < N: while idx < N and slime[idx][1] <= Y: heappush(que, (-slime[idx][2], slime[idx][0])) idx += 1 nex = Z if idx < N: nex = min(nex, slime[idx][1]) while Y < nex and que: x, c = heappop(que) x = -x if Y+x*c <= nex: Y += x*c ans += c else: diff = nex-Y nc = (diff+x-1)//x c -= nc Y += x*nc ans += nc if c: heappush(que, (-x, c)) if Y < nex: break print(ans if Z <= Y else -1)