gets d=[0]*123 p$<.map{_1.chop.bytes}.sort.map{|s|s.sort!=s ?0:d[l=s[-1]]=[d[l],d[..s[0]].max+s.size].max}.max