#include <bits/stdc++.h>
using namespace std;
int n, m;
bool contain(set<vector<string> > &s, vector<string> v) {
  for (int d = 0; d < 4; d++) {
    if (s.count(v)) return 1;
    vector<string> nxt(v[0].size(), string(v.size(), ' '));
    for (int i = 0; i < v[0].size(); i++)
      for (int j = 0; j < v.size(); j++) nxt[i][j] = v[v.size() - j - 1][i];
    v = nxt;
  }
  return 0;
}
void run() {
  cin >> n >> m;
  int x = n, y = m, cnt = 0;
  vector<string> in(n);
  for (int i = 0; i < n; i++) cin >> in[i];
  for (int a = 1; a <= n; a++)
    for (int b = 1; b <= m; b++) {
      if (n % a || m % b) continue;
      set<vector<string> > s;
      for (int i = 0; i < n / a; i++)
        for (int j = 0; j < m / b; j++) {
          vector<string> v(a);
          for (int k = 0; k < a; k++)
            for (int l = 0; l < b; l++)
              v[k].push_back(in[a * i + k][b * j + l]);
          if (contain(s, v)) goto FAIL;
          s.insert(v);
        }
      cnt++;
      if (x * y > a * b || x * y == a * b && x > a) x = a, y = b;
    FAIL:;
    }
  cout << cnt << endl;
  cout << x << " " << y << endl;
}
int main() {
  run();
  return 0;
}
