Count the crossing words Consider the following standard 15&times;15 crossword puzzle grid.



We can represent this in ASCII art by using # for blocks and  (space) for white squares.

     #    #    
     #    #    
          #    
   #   #       
###     ##   ##

     ##   #    
   #       #   
    #   ##     

##   ##     ###
       #   #   
    #          
    #    #     
    #    #     


Given a crossword grid in the ASCII art format above, determine how many words it holds. (The above grid has 78 words. It happens to be last Monday's New York Times puzzle.)

A word is a group of two or more consecutive spaces running vertically or horizontally. A word starts and ends with either a block or the edge of the grid and always runs top to bottom or left to right, never diagonally or backwards. Note that words can span the whole width of the puzzle, as in the sixth row of the puzzle above. A word does not have to be connected to another word.

Details


Input will always be a rectangle containing the characters # or  (space), with rows separated by a newline (\n). You can assume the grid is made of any 2 distinct printable ASCII characters instead of # and .
You may assume there is an optional trailing newline. Trailing space characters DO count, as they affect the number of words.
The grid will not always be symmetrical, and it may be all spaces or all blocks.
Your program should theoretically be able to work on a grid of any size, but for this challenge it will never be larger than 21&times;21.
You may take the grid itself as input or the name of a file containing the grid.
Take input from stdin or command line arguments and output to stdout.
If you prefer, you may use a named function instead of a program, taking the grid as a string argument and outputting an integer or string via stdout or function return.


Test cases


Input:

    #
    #
    #


Output: 7 (There are four spaces before each #. The result would be the same if each number sign were removed, but Markdown strips spaces from otherwise empty lines.)
Input:

##
 #
##


Output: 0 (One-letter words don't count.)
Input:

######
#    #
  ####
# ## #
# ## #
#### #


Output: 4
Input: (May 10's Sunday NY Times puzzle)

   #    ##   #       
   #    #    #       
   #         #       
       #     ###   ##
    #       #        
##   #   #           
        #       ##   
      #   ##         
   #        ##      #
         #   ###   ##
#   ##         ##   #
##   ###   #         
#      ##        #   
         ##   #      
   ##       #        
           #   #   ##
        #       #    
##   ###     #       
       #         #   
       #    #    #   
       #   ##    #   


Output: 140


Scoring

Shortest code in bytes wins. Tiebreaker is oldest post.
Slip, 18 + 3 = 21 bytes

&gt;? ( +(X|$^)&lt;&lt;){2}


Run with the flags no (hence the +3), and uses space/X instead of space/#. Annoyingly this is longer than CJam/Pyth, but I guess Slip wasn't designed to be particular golfy...

Try it online. Note that the first example is missing spaces on a few lines.

Explanation

&gt;?           Optionally turn right, hence matching either horizontally or vertically
[space]      Match a space
(    ){2}    Group, twice:
[space]+       Match 1+ spaces
(X|$^)         Either an X or the boundary of the grid
&lt;&lt;             Reverse the match pointer by turning left twice


The n flag makes output print the number of matches, and the o flag enables overlapping matches starting from the same square. The reason for the back-and-forth is because Slip tries matches starting from every square, and we want to make sure we only match a full row rather than a partial one. Slip only returns unique matches, even if they started from different positions.

Note: Originally I had &gt;?(  +(X|$^)&lt;&lt;){2}, with the first space on the inside. This would miss some cases with 2 space long words at the edge, since the pointer would go like this:

XXX       XXX       XXX       XXX
X&gt;        X &gt;       X&lt;        &lt;
XXX       XXX       XXX       XXX

[sp]    [sp]+$^    &lt;&lt;[sp]    [sp]+   (uh oh match fails)