s=[t=l=0]*17
c=(0..99).map{|i|[i*5,i%5==1?5:2,17*(i%2)+3*(i%3)+19]}
(a,n,b=c[l];(a<=t&&(z=[*s.each_cons(n)].index{|j|j.all?{|i|i<=t}}))?(s[z,n]=[t+b]*n;c[l]=t-a;l+=1):t+=1)while c[l]
$<.map{|i|p c[i.to_i]}