from sortedcontainers import SortedDict from atcoder.segtree import SegTree import bisect n,w,d=map(int,input().split()) INF=10**10 D0=SortedDict() D1=SortedDict() D0[0]=0 D1[0]=0 for _ in range(n): t,w,v=map(int,input().split()) if t: for i,j in D1.items(): if i-w not in D1: D1[i-w]=v+j else: D1[i-w]=max(D1[i-w],v+j) else: for i,j in D0.items(): if i-w not in D0: D0[i-w]=v+j else: D0[i-w]=max(D0[i-w],v+j) WW=[] VV=[] for i,j in D1.items(): WW.append(-i) VV.append(j) WW=WW[::-1] VV=VV[::-1] st=SegTree(max,-1,VV) ans=0 for i,j in D0.items(): if -i*2-d<=w: l=bisect.bisect_left(WW,-i-d) r=bisect.bisect_right(WW,min(-i+d,w)) ans=max(st.prod(l,r)+j,ans) print(ans)