def rec(m,i,j)
  m[i][j]=0
  rec(m,i,j+1) if j<11 and m[i][j+1]==1
  rec(m,i,j-1) if j>0 and m[i][j-1]==1
  rec(m,i+1,j) if i<11 and m[i+1][j]==1
  return m
end
loop do
  m,c=[],0
  12.times do
    m<<gets.split("").map(&:to_i)
  end
  12.times do |i|
    12.times do |j|
      if m[i][j]==1
        m=rec(m,i,j)
        c+=1
      end
    end
  end
  p c
  break if !gets
end