1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define __builtin_ctz __builtin_ctzll
#define __builtin_clz __builtin_clzll
#define __builtin_popcount __builtin_popcountll
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

int di[] = {1, -1, 0, 0};
int dj[] = {0, 0, 1, -1};

int Go(vector<VI> life, int n, int m, bool spec) {
  RE (i, n) {
    RE (j, m) {
      assert(life[i][j] == 0 || life[i][j] == 24);
    }
  }
  VVI neis(n + 2, VI(m + 2));
  VVI t(n + 2, VI(m + 2));
  while (1) {
    int min_t = 25;
    RE (i, n) {
      RE (j, m) {
        if (!life[i][j]) { continue; }
        neis[i][j] = 0;
        REP (dir, 4) {
          int ni = i + di[dir];
          int nj = j + dj[dir];
          if (life[ni][nj]) {
            neis[i][j]++;
          }
        }
        if (neis[i][j] == 0) { continue; }
        assert(life[i][j] % neis[i][j] == 0);
        mini(min_t, life[i][j] / neis[i][j]);
      }
    }
    if (min_t == 25) {
      break;
    }
    RE (i, n) {
      RE (j, m) {
        if (!life[i][j]) { continue; }
        t[i][j] += min_t;
        life[i][j] -= min_t * neis[i][j];
      }
    }
  }
  if (spec) {
    return life[1][6];
  }
  
  int res = 0;
  RE (i, n) {
    RE (j, m) {
      res += life[i][j];
    }
  }
  return res;
}

void Print(int res, int den) {
  int g = __gcd(res, den);
  cout<<res / g<<"/"<<den / g<<endl;
  exit(0);
}

int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  
  int n, m;
  cin>>n>>m;
  vector<vector<int>> life(n + 2, VI(m + 2));
  vector<vector<char>> board(n + 3, vector<char>(m + 2));
  VPII unsure;
  int any_mod5_offender = 0;
  RE (i, n) {
    RE (j, m) {
      char c;
      cin>>c;
      board[i][j] = c;
      if (c == '?') {
        unsure.PB({i, j});
      }
      if (i * j % 5 == 0 && c != '.') {
        any_mod5_offender = 1;
      }
      life[i][j] = 24 * (c == 'O');
    }
  }
  
  if (SZ(unsure) <= 5) {
    int res = 0;
    REP (mask, 1 << SZ(unsure)) {
      REP (bit, SZ(unsure)) {
        PII q = unsure[bit];
        if (mask & (1 << bit)) {
          life[q.st][q.nd] = 24;
        } else {
          life[q.st][q.nd] = 0;
        }
      }
      int here = Go(life, n, m, false);
      //debug(here);
      res += here;
    }
    int den = 24 << SZ(unsure);
    Print(res, den);
  }
  
  if (!any_mod5_offender) {
    vector<vector<int>> small(6, VI(6));
    VPII pola;
    RE (i, 4) {
      RE (j, 4) {
        pola.PB({i, j});
      }
    }
    VI by_mask(1 << 16);
    REP (mask, 1 << 16) {
      REP (b, 16) {
        auto p = pola[b];
        if (mask & (1 << b)) {
          small[p.st][p.nd] = 24;
        } else {
          small[p.st][p.nd] = 0;
        }
      }
      by_mask[mask] = Go(small, 4, 4, false) << 16;
    }
    vector<int> p3(17);
    p3[0] = 1;
    RE (i, 16) {
      p3[i] = 3 * p3[i - 1];;
    }
    vector<int32_t> memo(p3[16]);
    function<void(int, int, int, int)> Bt = [&](int pos, int m2, int m3, int fir_unsure) {
      if (pos == 16) {
        if (fir_unsure == 16) {
          memo[m3] = by_mask[m2];
        } else {
          memo[m3] = (memo[m3 - p3[fir_unsure]] + memo[m3 - 2 * p3[fir_unsure]]) / 2;
        }
      } else {
        REP (tr, 3) {
          int n_unsure = fir_unsure;
          if (n_unsure == 16 && tr == 2) { n_unsure = pos; }
          Bt(pos + 1, m2 + (tr << pos), m3 + tr * p3[pos], n_unsure);
        }
      }
    };
    Bt(0, 0, 0, 16);
    int res = 0;
    for (int i = 1; i <= n; i += 5) {
      for (int j = 1; j <= m; j += 5) {
        int m3 = 0;
        REP (b, 16) {
          int ni = i + pola[b].st - 1;
          int nj = j + pola[b].nd - 1;
          //debug(ni, nj);
          if (ni <= n && nj <= m) {
            if (board[ni][nj] == 'O') {
              m3 += p3[b];
            } else if (board[ni][nj] == '?') {
              m3 += 2 * p3[b];
            }
          }
        }
        //debug(m3);
        res += memo[m3];
      }
    }
    Print(res, 24 << 16);
  }
  
  
  if (n <= 2) {
    n = 2;
    RE (i, m) {
      board[2][i] = '.';
    }
    vector<string> stany(49);
    stany[0]="?????.X.???????????.??????";
    stany[1]="?????.XO.??????????..?????";
    stany[2]="?????.XO.??????????.O?????";
    stany[3]="?????.XOO.?????????..?????";
    stany[4]="?????.XOOO?????????...????";
    stany[5]="?????.XOOO?????????..O????";
    stany[6]="?????.XOO??????????.O?????";
    stany[7]="????.OX.??????????..??????";
    stany[8]="????OOX.?????????...??????";
    stany[9]="???.OOX.?????????O..??????";
    stany[10]="???OOOX.?????????O..??????";
    stany[11]="????.OX.??????????O.??????";
    stany[12]="????OOX.??????????O.??????";
    stany[13]="????.OXO??????????..??????";
    stany[14]="????OOXO.?????????..??????";
    stany[15]="????OOXOO?????????...?????";
    stany[16]="????OOXOO????????...O?????";
    stany[17]="???.OOXOO????????O..O?????";
    stany[18]="???OOOXOO????????O..O?????";
    stany[19]="????.OXO.?????????O.??????";
    stany[20]="????.OXOO?????????O..?????";
    stany[21]="????.OXOO?????????O.O?????";
    stany[22]="????OOXO.?????????O..?????";
    stany[23]="????OOXO.?????????O.O?????";
    stany[24]="????OOXOO.????????O..?????";
    stany[25]="????OOXOOO????????O...????";
    stany[26]="????OOXOOO????????O..O????";
    stany[27]="????OOXOO?????????O.O?????";
    stany[28]="?????.X.??????????.O.?????";
    stany[29]="?????.X.??????????.OO?????";
    stany[30]="?????.X.??????????OO.?????";
    stany[31]="?????.X.??????????OOO?????";
    stany[32]="?????.XO.?????????.O??????";
    stany[33]="?????.XOO?????????.O.?????";
    stany[34]="?????.XOO?????????.OO.????";
    stany[35]="?????.XOO?????????.OOO????";
    stany[36]="?????.XO.?????????OO.?????";
    stany[37]="?????.XO.?????????OOO.????";
    stany[38]="?????.XO.?????????OOOO????";
    stany[39]="?????.XOO?????????OO.?????";
    stany[40]="?????.XOO?????????OOO?????";
    stany[41]="?????OX.??????????.O??????";
    stany[42]="????.OX.??????????OO.?????";
    stany[43]="????.OX.?????????.OOO?????";
    stany[44]="????.OX.?????????OOOO?????";
    stany[45]="????OOX.?????????.OO.?????";
    stany[46]="????OOX.?????????OOO.?????";
    stany[47]="????OOX.??????????OOO?????";
    stany[48]="?????OXO???????????O??????";
    
    LD control = 0;
    vector<VPII> shifts;
    vector<vector<char>> wants;
    vector<int> vals;
    for (auto stan : stany) {
      vector<vector<int>> aux(4, VI(15));
      int cnt = 0;
      for (auto x : stan) {
        if (x == '.' || x == 'O') {
          cnt++;
        }
      }
      control += 1. / (1 << cnt);
      int finger = 0;
      VPII shift;
      vector<char> want;
      REP (r, 2) {
        REP (i, 13) {
          if (stan[finger] == 'O' || stan[finger] == 'X') {
            aux[r + 1][i] = 24;
          }
          if (stan[finger] == 'O' || stan[finger] == '.') {
            shift.PB({r, i - 6});
            want.PB(stan[finger]);
          }
          finger++;
        }
      }
      shifts.PB(shift);
      wants.PB(want);
      vals.PB(Go(aux, 2, 13, 1));
    }
    //debug(vals);
    //debug(control);
    int res = 0;
    REP (tr, 2) {
      RE (j, m) {
        if (board[1][j] == '.') { continue; }
        REP (chk, 49) {
          int qs = 0;
          if (board[1][j] == '?') { qs++; }
          int ok = 1;
          //debug(shifts[chk]);
          REP (w, SZ(shifts[chk])) {
            int ni = 1 + shifts[chk][w].st;
            int nj = j + shifts[chk][w].nd;
            int outside = (nj <= 0) || (nj > m);
            if (wants[chk][w] != '.' && outside) { ok = 0; break; }
            if (outside) { continue; }
            if (board[ni][nj] == '?') { qs++; continue; }
            if (board[ni][nj] != wants[chk][w]) { ok = 0; break; }
          }
          if (ok) {
            res += vals[chk] << (20 - qs);
          }
        }
        
      }
      
      RE (i, m) {
        swap(board[1][i], board[2][i]);
      }
    }
    Print(res, 24 << 20);
  }
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  return 0;
}