#include <bits/stdc++.h>
using namespace std;
int xx, yy, ans, ansX = 10000, ansY = 100000;
char c[100][100];
bool correct;
map<string, bool> mark;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> yy >> xx;
  for (__typeof(yy - 1) y = (0); y <= (yy - 1); y++)
    for (__typeof(xx - 1) x = (0); x <= (xx - 1); x++) cin >> c[x][y];
  string s1, s2, s3, s4;
  for (__typeof(yy) y = (1); y <= (yy); y++) {
    if (yy % y == 0)
      for (__typeof(xx) x = (1); x <= (xx); x++)
        if (xx % x == 0) {
          bool correct = true;
          mark.clear();
          int pX = xx / x;
          int pY = yy / y;
          for (__typeof(pY - 1) y2 = (0); y2 <= (pY - 1); y2++)
            for (__typeof(pX - 1) x2 = (0); x2 <= (pX - 1); x2++) {
              s1 = s2 = s3 = s4 = "";
              for (__typeof(y - 1) i = (0); i <= (y - 1); i++)
                for (__typeof(x - 1) j = (0); j <= (x - 1); j++)
                  s1 += c[x * x2 + j][y * y2 + i];
              if (x == y)
                for (__typeof(x - 1) j = (x - 1); j >= (0); j--)
                  for (__typeof(y - 1) i = (0); i <= (y - 1); i++)
                    s2 += c[x * x2 + j][y * y2 + i];
              s3 = s1;
              s4 = s2;
              reverse((s3).begin(), (s3).end());
              reverse((s4).begin(), (s4).end());
              if (mark[s1]) {
                correct = false;
                break;
              }
              if (x == y && mark[s2]) {
                correct = false;
                break;
              }
              if (mark[s3]) {
                correct = false;
                break;
              }
              if (x == y && mark[s4]) {
                correct = false;
                break;
              }
              mark[s1] = true;
              mark[s2] = true;
              mark[s3] = true;
              mark[s4] = true;
            }
          if (correct) {
            ans++;
            if (x * y < ansX * ansY) {
              ansX = x;
              ansY = y;
            } else if (ansX * ansY == x * y && y < ansY) {
              ansX = x;
              ansY = y;
            }
          }
        }
  }
  cout << ans << endl;
  cout << ansY << " " << ansX << endl;
  return 0;
}
