$n=<>+0;$a=<>.<>;$r=0; for$j(0..13){ $_=$a;s/\n//;pos=$j;s/\Gx{0,$n}/o x length$&/e; $x=0;$i=0; /o/?$r+=$-=++$x-$r:($x=0),$i++for/./g; } print$r