gets p (1while(sub /\A(.*)!/,'\1 ';sub! /(.)(.{8})!/m,'!\2\1');$.+=1)while"#$_".scan(/\w/){h={};(f=proc{|i|h[i]||$&!=$_[i,1]?h:(f[h[i]=i-1];f[i+9];f[i+1])})[$`.size].size>3&&h.map{|j,|$_[j]=?!}}&&/!/ puts"#$_ #{$.-1} chains"
Note that non-ascii characters in the above source code will be escaped (such as \x9f).