Find the haystack in the needles In a twist on finding a needle in a haystack, you need to find the largest contiguous haystack containing exactly one needle. Note that you cannot connect cells on diagonals, only left/right/up/down.

Input

An array (or a number of user input lines, your pick) of 'N' (needles) and '#' (hay) characters. Input only contains those two characters, and must contain at least one of each. For example:

N#N#N
#NN##
###N#
N##N#


Output

The size of the largest possible valid haystack. For our example, we would output 11 (there are 11 pieces of hay, and one needle). 

   # 
#  ##
###N#
 ## #


This is code-golf, so shortest code wins.  Standard loophole restrictions apply.

Test Cases

Input on left, possible maximal haystack on right

Case 1: 4

N##    ##
NN#     #
#NN     N
#N#     #


Case 2: 7

###   ###
N#N    # 
NNN    N 
###   ###


Case 3: 10

N###N    ### 
#N#N#   #N#  
#N#N#   # #  
N###N    ###


Case 4: 10

N#N#N        
#N#N#   # # #
##N##   ##N##
#N#N#   # # #
N#N#N        


Case 5: 1

NN#NN        
NNNNN         
#NNN#   #N    
NN#NN
Ruby, 207
-&gt;a{d=-&gt;b{0...b.size}
f=c=s=-&gt;y,x{(d[a]===y&amp;&amp;d[a[0]]===x&amp;&amp;!f[y][x]&amp;&amp;a[y][x]==c)?(c,f[y][x]=?#,1
1+s[y,x-1]+s[y,x+1]+s[y-1,x]+s[y+1,x]):0}
d[a].map{|y|d[y].map{|x|f,c=a.map{|b|b.map{p}},?N
s[y,x]}.max}.max-1}

This is an anonymous function that takes in the input as an array of arrays. Usage:
f=-&gt;a{......}

f[&quot;
N##
NN#
#NN
#N#
&quot;.strip.split.map(&amp;:chars)] # =&gt; 4

The proc named s recursively finds the size of the haystack with needle at specific coordinates and is called on each needle in the haystack.