#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long hashboard[100][100];
string pic[100];
long long A, B, ans = 0, ax = 100, ay = 100;
map<char, long long> value;
vector<long long> divsa, divsb;
set<long long> dd;
void INIT() {
  for (char c = 'A'; c <= 'Z'; c++) value[c] = c * 50000;
  for (int i = 1; i <= A; i++)
    if (A % i == 0) divsa.push_back(i);
  for (int i = 1; i <= B; i++)
    if (B % i == 0) divsb.push_back(i);
}
pair<pair<long long, long long>, pair<long long, long long> > GetHash(
    int i1, int i2, int j1, int j2, int x, int y) {
  long long gh = 0, gh2 = 0, gh3 = 0, gh4 = 0;
  for (long long insi1 = i1, insi2 = 0, insi3 = x - 1; insi1 <= i2;
       insi1++, insi2++, insi3--)
    for (long long insj1 = j1, insj2 = 0, insj3 = y - 1; insj1 <= j2;
         insj1++, insj2++, insj3--) {
      gh += hashboard[insi2][insj2] * value[pic[insi1][insj1]];
      if (x == y) gh2 += hashboard[insj2][insi3] * value[pic[insi1][insj1]];
      gh3 += hashboard[insi3][insj3] * value[pic[insi1][insj1]];
      if (x == y) gh4 += hashboard[insj3][insi2] * value[pic[insi1][insj1]];
    }
  return {{gh, gh2}, {gh3, gh4}};
}
int main() {
  srand((int)time(0));
  cin >> A >> B;
  INIT();
  for (int i = 0; i < A; i++) cin >> pic[i];
  for (long long ii = 0, x = divsa[0]; ii < divsa.size();
       ii++, x = (ii < divsa.size() ? divsa[ii] : 0))
    for (long long jj = 0, y = divsb[0]; jj < divsb.size();
         jj++, y = (jj < divsb.size() ? divsb[jj] : 0)) {
      memset(hashboard, 0, sizeof(hashboard));
      long long num = 1;
      map<long long, bool> used;
      for (int i = 0; i < x; i++) {
        for (int j = 0; j < y; j++) {
          while (used[num]) num = rand() % MOD;
          used[num] = true;
          hashboard[i][j] = num;
        }
      }
      dd.clear();
      long long dec = 0;
      for (long long i1 = 0, i2 = i1 + x - 1; i2 < A;
           i1 = i2 + 1, i2 = i1 + x - 1) {
        for (long long j1 = 0, j2 = j1 + y - 1; j2 < B;
             j1 = j2 + 1, j2 = j1 + y - 1) {
          pair<pair<long long, long long>, pair<long long, long long> > tmp =
              GetHash(i1, i2, j1, j2, x, y);
          set<long long> tt;
          tt.insert(tmp.first.first);
          tt.insert(tmp.first.second);
          tt.insert(tmp.second.first);
          tt.insert(tmp.second.second);
          for (set<long long>::iterator it = tt.begin(); it != tt.end(); it++) {
            if (*it == 0) continue;
            dd.insert(*it);
            dec++;
          }
        }
      }
      if (dd.size() == dec) {
        ans++;
        if (x * y < ax * ay)
          ax = x, ay = y;
        else {
          if (x * y == ax * ay && x < ax) ax = x, ay = y;
        }
      }
    }
  cout << ans << endl << ax << ' ' << ay << endl;
  return 0;
}
