#include <bits/stdc++.h>
using namespace std;
using namespace std;
int n, m;
const int maxn = 1e6 + 10;
vector<string> strs;
int facr[30], facl[30];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int u, v, t, A, B;
  int curx = 0, cury = 0;
  t = 1;
  while (t--) {
    cin >> A >> B;
    string tmp;
    for (int i = 0; i < A; i++) cin >> tmp, strs.push_back(tmp);
    int cntr = 0, cntl = 0;
    for (int i = 1; i <= A; i++)
      if (A % i == 0) facr[cntr++] = i;
    for (int i = 1; i <= B; i++)
      if (B % i == 0) facl[cntl++] = i;
    int ans = A * B;
    int ansa = A, ansb = B;
    int cnt = 0;
    for (int i = 0; i < cntr; i++) {
      for (int j = 0; j < cntl; j++) {
        map<pair<string, int>, int> mp;
        bool flag = 1;
        for (int k = 0; k < A / facr[i]; k++) {
          for (int h = 0; h < B / facl[j]; h++) {
            string str1, str2;
            for (int ii = 0; ii < facr[i]; ii++)
              for (int jj = 0; jj < facl[j]; jj++)
                str1.push_back(strs[k * facr[i] + ii][h * facl[j] + jj]);
            for (int i = str1.size() - 1; i >= 0; i--) str2.push_back(str1[i]);
            pair<string, int> p1 = make_pair(str1, facr[i]);
            pair<string, int> p2 = make_pair(str2, facr[i]);
            if (mp.count(p1)) flag = 0;
            if (mp.count(p2)) flag = 0;
            if (facl[j] == facr[i]) {
              string str1, str2;
              for (int ii = 0; ii < facr[i]; ii++)
                for (int jj = facl[j] - 1; jj >= 0; jj--)
                  str1.push_back(strs[k * facr[i] + jj][h * facr[i] + ii]);
              for (int i = str1.size() - 1; i >= 0; i--)
                str2.push_back(str1[i]);
              pair<string, int> p1 = make_pair(str1, facr[i]);
              pair<string, int> p2 = make_pair(str2, facr[i]);
              if (mp.count(p1)) flag = 0;
              if (mp.count(p2)) flag = 0;
            }
            mp[p1] = 1;
          }
          if (!flag) break;
        }
        if (flag) {
          if (facl[j] * facr[i] < ans)
            ans = facl[j] * facr[i], ansa = facr[i], ansb = facl[j];
          cnt++;
        }
      }
    }
    cout << cnt << endl << ansa << " " << ansb << endl;
    strs.clear();
  }
  return 0;
}
