#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
int dblcmp(double d) {
  if (fabs(d) < eps) return 0;
  return d > eps ? 1 : -1;
}
set<vector<string> > st;
vector<string> s;
set<pair<int, int> > ans;
vector<string> rot(vector<string> s1) {
  int i, j, k, n = s1.size(), m = s1[0].length();
  vector<string> t(m, string(n, ' '));
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      t[i][j] = s1[n - j - 1][i];
    }
  }
  return t;
}
bool cmp(const pair<int, int>& a, const pair<int, int>& b) {
  int a1 = a.first * a.second, b1 = b.first * b.second;
  if (a1 != b1) return a1 < b1;
  return a.first < b.first;
}
int main() {
  int i, j, k, n, m;
  cin >> n >> m;
  s.resize(n);
  for (i = 0; i < n; i++) {
    string t;
    cin >> t;
    s[i] = t;
  }
  int r, c;
  for (r = 1; r <= n; r++)
    if (n % r == 0) {
      for (c = 1; c <= m; c++)
        if (m % c == 0) {
          st.clear();
          int ok = 1;
          for (i = 0; i < n; i += r) {
            for (j = 0; j < m; j += c) {
              vector<string> s1;
              for (k = i; k < i + r; k++) {
                s1.push_back(s[k].substr(j, c));
              }
              vector<string> ss[5];
              for (k = 0; k < 4; k++) {
                ss[k] = s1;
                s1 = rot(s1);
              }
              for (k = 0; k < 4; k++) {
                if (st.find(ss[k]) != st.end()) {
                  ok = 0;
                  break;
                }
              }
              if (ok) {
                for (k = 0; k < 4; k++) {
                  st.insert(ss[k]);
                }
              }
              if (!ok) break;
            }
            if (!ok) break;
          }
          if (ok) {
            ans.insert(make_pair(r, c));
          }
        }
    }
  vector<pair<int, int> > an(ans.begin(), ans.end());
  sort(an.begin(), an.end(), cmp);
  printf("%d\n", (int)((an).size()));
  printf("%d %d\n", an[0].first, an[0].second);
  return 0;
}
