#include <bits/stdc++.h>
using namespace std;
int nextInt() {
  int x;
  scanf("%d", &x);
  return x;
}
double nextDouble() {
  double x;
  scanf("%lf", &x);
  return x;
}
const int STRING_BUF_SIZE = 1000000;
char _stringBuf[STRING_BUF_SIZE + 1];
string nextString() {
  scanf("%s", _stringBuf);
  return _stringBuf;
}
long long getH(vector<string> &a) {
  long long res = 0;
  for (int i = 0; i < a.size(); ++i) {
    for (int j = 0; j < a[i].size(); ++j) {
      res = res * 14243 + a[i][j];
    }
  }
  return res;
}
void rotate(vector<string> &a) {
  vector<string> r(a[0].size(), string(a.size(), ' '));
  for (int i = 0; i < a.size(); ++i) {
    for (int j = 0; j < a[i].size(); ++j) {
      r[j][a.size() - 1 - i] = a[i][j];
    }
  }
  a = r;
}
long long getKey(vector<string> &a) {
  long long res = getH(a);
  for (int i = 1; i < 4; ++i) {
    rotate(a);
    long long key = getH(a);
    res = min(res, key);
  }
  return res;
}
int main() {
  int n = nextInt();
  int m = nextInt();
  vector<string> a(n);
  for (int i = 0; i < n; ++i) {
    a[i] = nextString();
  }
  vector<pair<int, int> > res;
  for (int dy = 1; dy <= n; ++dy)
    if (n % dy == 0) {
      for (int dx = 1; dx <= m; ++dx)
        if (m % dx == 0) {
          set<long long> s;
          for (int i = 0; i < n / dy; ++i) {
            for (int j = 0; j < m / dx; ++j) {
              vector<string> b(dy, string(dx, ' '));
              for (int ii = 0; ii < dy; ++ii) {
                for (int jj = 0; jj < dx; ++jj) {
                  int ni = i * dy + ii;
                  int nj = j * dx + jj;
                  b[ii][jj] = a[ni][nj];
                }
              }
              long long key = getKey(b);
              s.insert(key);
            }
          }
          if (s.size() == (n / dy) * (m / dx)) {
            res.push_back(make_pair(dy, dx));
          }
        }
    }
  cout << res.size() << endl;
  sort(res.begin(), res.end());
  int rY = m, rX = n;
  for (int i = 0; i < res.size(); ++i) {
    if (rY * rX > res[i].first * res[i].second) {
      rX = res[i].first;
      rY = res[i].second;
    }
  }
  cout << rX << " " << rY << endl;
  return 0;
}
