gets;`dd`.split.each{|a|i=-1;$.+=1while i=$_.index(a,i+1)};p$.