Non-crossing X's and crossing non-X's You should write a program or function which given a text as input outputs or returns the sum of the following three integers:


Number of lowercase x's which are not part of a cross-formation.
Number of uppercase X's which are not part of a cross-formation.
Number of cross-formations which are made of neither x nor X.


A cross-formation is 5 copy of the same character positioned to each other in the following manner:

  A A
   A
  A A


Cross-formations can overlap with each other.

Detailed example

Input:
x-x+x+X++
-x-x+x++asd
x-x+x+X+

Info:
There is 1 x and 2 X's not in cross-formation and 
there are 2 cross-formations of +'s as shown here:
   + +X+ 
    +x+    
   + +X+

Output:
5


Input


A string containing only printable ascii characters (codepoint 32-126) and newlines. 
The string will contain at least one printable character.


Output


A single positive integer, the sum of the number of occurrences for the three property.


Examples

After each output the values of the 3 properties (x's, X's and crosses) are provided in parens but note that those are not part of the output.

Input:
a
Output:
0 (0,0,0)

Input:
x xxx
 X x
x xxx
Output:
5 (4,1,0)

Input:
########
#####
########
Output:
4 (0,0,4)

Input:
a-a-a
0a0a
a-a-axXxX
0a0a
a-a-a
Output:
9 (2,2,5)

Input:
a c efghi
ab defgh
a c e ghij
abcd fgh
abc e g
Output:
2 (0,0,2)

Input:
/\/\/\/\/\/\/\
\/\/\/\/\/\/\/
#####x-x+x+X++
#####-x-x+x++###XX
#####x-x+x+X+
/\/\/\/\/\/\/\
\/\/\/\/\/\/\/
Output:
10 (1,4,5)

Input:
xxxxxxxxxx   
xxxxxxxXX
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxx
Output:
5 (3,2,0)


This is code-golf so the shortest entry wins.
JavaScript (ES6) 234 246

Longer than I expected ... 

Run snippet to test (in Firefox)



// Golfed

F=t=&gt;t.split('\n').map((r,j,t)=&gt;(
  [...r].map((c,i)=&gt;(
    f=c==r[i+2]&amp;c==u[i+1]&amp;c==v[i]&amp;c==v[i+2],
    c!='x'&amp;c!='X'?z+=f
    :(++z,f?k[j+[,i]]=k[2+j+[,i]]=k[1+j+[,i+1]]=k[j+[,i+2]]=k[2+j+[,i+2]]=1:0)
  )),v=u,u=r),
k={},u=v=z=0)&amp;&amp;z-Object.keys(k).length

// Ungolfed 

U=t=&gt;{
  var k={}, u=0,v=0,z=0, t=t.split('\n')
  t.forEach((r,j)=&gt; {
    [...r].forEach((c,i)=&gt; {
      x = c=='x'|c=='X' // is any X
      f = c==r[i+2] &amp; c==u[i+1] &amp; c==v[i] &amp; c==v[i+2] // is in a formation
      if (x) 
      {
        ++z
        if (f)
        { // remember the position of X involved in a formation, avoid counting duplicates more tha once
          k[j+[,i]]=k[2+j+[,i]]=k[1+j+[,i+1]]=k[j+[,i+2]]=k[2+j+[,i+2]]=1 
        }
      }
      else
      {
        z+=f 
      }                                                  
    })
    v=u,u=r
  })
  return z-Object.keys(k).length
}

// TEST

Out=s=&gt;OUT.innerHTML=OUT.innerHTML + s;

['a','a a\n a\na a','x xxx\n X x\nx xxx', 'x-x+x+X++\n-x-x+x++asd\nx-x+x+X+'
,'########\n#####\n########','a-a-a\n0a0a\na-a-axXxX\n0a0a\na-a-a'
,'a c efghi\nab defgh\na c e ghij\nabcd fgh\nabc e g'
,'/\\/\\/\\/\\/\\/\\/\\\n\\/\\/\\/\\/\\/\\/\\/\n#####x-x+x+X++\n#####-x-x+x++###XX\n#####x-x+x+X+\n/\\/\\/\\/\\/\\/\\/\\\n\\/\\/\\/\\/\\/\\/\\/'
,'xxxxxxxxxx\nxxxxxxxXX\nxxxxxxxxxx\nxxxxxxxxxx\nxxxxxxxxxx\nxxxxxxxx']
.forEach(t=&gt;Out(t+'\n&lt;b&gt;'+F(t)+'&lt;/b&gt;\n\n'))
b { color: #00f }
&lt;pre id=OUT&gt;&lt;/pre&gt;