gets;t=0;$<.each{|a|i=-1;t+=1while i=$_.index(a.chop,i+1)};p t