#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 1 << 23;   char s[55][55];   int p[55], r[55], d[55], h[55], ans = 0;   int f[maxn], g[maxn], bit[maxn];   int ff(int x) {     if (p[x] != x) p[x] = ff(p[x]);     return p[x];   }   void funion(int x, int y) {     x = ff(x);     y = ff(y);     if (x != y) p[y] = x;   }   int main() {     int n, m, i, j;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf(  %s , s[i]);     for (i = 0; i < n; i++) p[i] = i;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if (i == j) continue;         if (s[i][j] ==  A ) funion(i, j);       }     }     for (i = 0; i < n; i++) d[ff(i)]++;     memset(h, -1, sizeof(h));     for (i = m = 0; i < n; i++) {       if (d[i] > 1) h[i] = m++;     }     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if (i == j) continue;         if (s[i][j] ==  X ) {           if (ff(i) == ff(j)) {             return puts( -1 ), 0;           }           if (d[ff(i)] > 1 && d[ff(j)] > 1) {             r[h[ff(i)]] |= 1 << h[ff(j)];             r[h[ff(j)]] |= 1 << h[ff(i)];           }         }       }     }     if (!m) {       printf( %d n , n - 1);       return 0;     }     for (i = 0; i < m; i++) r[i] ^= (1 << m) - 1;     for (i = 0; i < (1 << m); i++) {       if ((i & (-i)) == i)         f[i] = 1;       else {         j = i ^ (1 << (__builtin_ffs(i) - 1));         if (f[j] && (r[__builtin_ffs(i) - 1] & j) == j) f[i] = 1;       }       g[i] = 1;       bit[i] = (m - __builtin_popcount(i)) & 1;     }     for (i = 0; i < m; i++) {       for (j = 0; j < (1 << m); j++) {         if ((j >> i) & 1) f[j] += f[j ^ (1 << i)];       }     }     for (i = 0; i < m; i++) {       for (j = 0; j < (1 << m); j++) g[j] *= f[j];       int x = 0;       for (j = 0; j < (1 << m); j++) {         if (bit[j])           x -= g[j];         else           x += g[j];       }       if (x) break;     }     printf( %d n , n + i);     return 0;   }   