#!ruby -pal00F\n
def f a,i,j;a[i][j]=z=?0;[[1,0],[0,1],[-1,0],[0,-1]].map{|c,d|(a[i+c][j+d]||z)>z&&f(a,i+c,j+d)}end
a=[[z=?0]*13]+$F.map{|l|[z]+l.chars}+[[]]
$_=0
x=(1..12)
x.map{|i|x.map{|j|a[i][j]>z&&($_+=1;f a,i,j)}}