N,W,D = map(int,input().split(' ')) stones=[] for i in range(N): stone={} t,w,v = map(int,input().split(' ')) stone['t']=t stone['w']=w stone['v']=v stones.append(stone) max_v = 0 for i in range(pow(2,N)): choice = format(i,'0'+str(N)+'b') W0=0 W1=0 W01=0 V=0 flag = True for j in range(N): if choice[j]=='1': if stones[j]['t']==0: W0+=stones[j]['w'] else: W1+=stones[j]['w'] W01+=stones[j]['w'] V+=stones[j]['v'] if ((abs(W0-W1)<=D) and (W01 <= W)): if max_v < V: max_v=V print(max_v)