#include <bits/stdc++.h>
using namespace std;
char a[100][100];
int n, m;
vector<pair<int, int> > all;
bool good(int x, int y) {
  map<string, bool> mark;
  mark.clear();
  for (int i = 0; i < n / x; i++) {
    for (int j = 0; j < m / y; j++) {
      string s1 = "", s2 = "", s3 = "", s4 = "";
      for (int l = 0; l < x; l++) {
        for (int k = 0; k < y; k++) {
          s1 += a[i * x + l][j * y + k];
          s2 += a[i * x + x - l - 1][j * y + y - k - 1];
          if (x == y) {
            s3 += a[i * x + x - k - 1][j * y + l];
            s4 += a[i * x + k][j * y + y - l - 1];
          }
        }
      }
      if (x == y) {
        if (mark.find(s1) != mark.end()) return false;
        if (mark.find(s2) != mark.end()) return false;
        if (mark.find(s3) != mark.end()) return false;
        if (mark.find(s4) != mark.end()) return false;
        mark[s1] = mark[s2] = mark[s3] = mark[s4] = true;
      } else {
        if (mark.find(s1) != mark.end()) return false;
        if (mark.find(s2) != mark.end()) return false;
        mark[s1] = mark[s2] = true;
      }
    }
  }
  mark.clear();
  return true;
}
bool comp(pair<int, int> x, pair<int, int> y) {
  if (x.first * x.second == y.first * y.second)
    return x.first < y.first;
  else
    return (x.first * x.second) < (y.first * y.second);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) a[i][j] = s[j];
  }
  for (int i = 1; i <= n; i++) {
    if (n % i != 0) continue;
    for (int j = 1; j <= m; j++) {
      if (m % j != 0) continue;
      if (good(n / i, m / j)) all.push_back(pair<int, int>(n / i, m / j));
    }
  }
  sort(all.begin(), all.end(), comp);
  cout << all.size() << endl;
  cout << all[0].first << " " << all[0].second << endl;
  return 0;
}
