#include <bits/stdc++.h>
using namespace std;
unsigned int modtab[23][23], strmod[23];
char str[23][23], temp[23][23];
set<int> S;
void settab() {
  int i, j;
  modtab[0][0] = -109873507;
  for (i = 1; i < 23; ++i) {
    modtab[i][0] = modtab[i - 1][0] * 1000000007;
    modtab[0][i] = modtab[0][i - 1] * 1000000009;
  }
  for (i = 1; i < 23; ++i) {
    for (j = 1; j < 23; ++j) modtab[i][j] = modtab[i - 1][j] * modtab[i][j - 1];
  }
  strmod[0] = 19301;
  for (i = 1; i < 23; ++i) strmod[i] = strmod[i - 1] * 9851;
}
int calc(string &s) {
  int i, ret = 0;
  for (i = 0; i < s.length(); ++i) ret += s[i] * strmod[i + 1];
  return ret;
}
int hashval(int R, int C) {
  int ret = 0, tmp1, tmp2, tmp, ret2 = 0;
  tmp1 = tmp2 = 0;
  string rc, cr, p1, p2, pain;
  int i, j, k;
  rc = cr = "";
  for (i = 0; i < R; ++i) {
    for (j = 0; j < C; ++j) {
      rc += temp[i][j];
      cr += temp[R - i - 1][C - j - 1];
    }
  }
  if (rc < cr)
    pain = rc;
  else
    pain = cr;
  if (R == C) {
    p1 = p2 = "";
    for (j = 0; j < C; ++j) {
      for (i = 0; i < R; ++i) {
        p1 += temp[R - i - 1][j];
        p2 += temp[i][C - j - 1];
      }
    }
    if (p1 < pain) pain = p1;
    if (p2 < pain) pain = p2;
  }
  for (i = k = 0; i < R; ++i) {
    for (j = 0; j < C; ++j) temp[i][j] = pain[k++];
  }
  for (i = 0; i < R; ++i) {
    for (j = 0; j < C; ++j) {
      tmp = modtab[i][j];
      ret += temp[i][j] * tmp;
    }
  }
  return ret;
}
bool settemp(int R, int C, int r, int c) {
  int i, j, a, b, h;
  S.clear();
  for (a = 0; a < R; a += r) {
    for (b = 0; b < C; b += c) {
      memset(temp, 0, sizeof(temp));
      for (i = 0; i < r; ++i) {
        for (j = 0; j < c; ++j) temp[i][j] = str[i + a][j + b];
      }
      h = hashval(r, c);
      if (S.find(h) != S.end()) return false;
      S.insert(h);
    }
  }
  for (a = 0; a < R; a += r) {
    for (b = 0; b < C; b += c) {
      memset(temp, 0, sizeof(temp));
      for (i = 0; i < r; ++i) {
        for (j = 0; j < c; ++j) temp[i][j] = str[i + a][j + b];
      }
    }
  }
  return true;
}
int main() {
  settab();
  int R, C;
  int i, j;
  int res;
  pair<int, int> ans, temp;
  while (scanf("%d %d", &R, &C) != EOF) {
    for (i = 0; i < R; ++i) scanf("%s", str[i]);
    res = 0;
    ans = make_pair(503, 0);
    for (i = 0; i < R; ++i) {
      if (R % (i + 1)) continue;
      for (j = 0; j < C; ++j) {
        if (C % (j + 1)) continue;
        if (settemp(R, C, i + 1, j + 1)) {
          temp = make_pair((i + 1) * (j + 1), i + 1);
          if (temp < ans) ans = temp;
          ++res;
        }
      }
    }
    printf("%d\n", res);
    if (res) printf("%d %d\n", ans.second, ans.first / ans.second);
  }
  return 0;
}
