#include <bits/stdc++.h>
using namespace std;
void copy(const vector<vector<char> >& src, vector<vector<char> >& dst, int x,
          int y, int w, int h) {
  for (int i = y, j = 0; i < y + h; i++, j++) {
    for (int k = x, l = 0; k < x + w; k++, l++) {
      dst[j][l] = src[i][k];
    }
  }
}
void rotate180(vector<vector<char> >& v) {
  int w, h;
  h = v.size() - 1;
  w = v[0].size() - 1;
  vector<vector<char> > t = v;
  for (int y = 0; y <= h; y++) {
    for (int x = 0; x <= w; x++) {
      v[y][x] = t[h - y][w - x];
    }
  }
}
void rotate90(vector<vector<char> >& v) {
  int s;
  s = v.size() - 1;
  vector<vector<char> > t = v;
  for (int y = 0; y <= s; y++) {
    for (int x = 0; x <= s; x++) {
      v[y][x] = t[s - x][y];
    }
  }
}
int main() {
  int A, B, X = 0, Y = 0, ans = 0;
  cin >> A >> B;
  vector<vector<char> > image(A, vector<char>(B, ' '));
  for (int h = 0; h < A; h++) {
    for (int w = 0; w < B; w++) {
      char c;
      cin >> c;
      image[h][w] = c;
    }
  }
  int min = 1 << 30;
  for (int y = 1; y <= A; y++) {
    if (A % y != 0) continue;
    for (int x = 1; x <= B; x++) {
      if (B % x != 0) continue;
      vector<vector<char> > temp(y, vector<char>(x));
      vector<vector<vector<char> > > list;
      bool f = true;
      for (int i = 0; i < A / y && f; i++) {
        for (int j = 0; j < B / x && f; j++) {
          copy(image, temp, j * x, i * y, x, y);
          for (int i = 0; i < list.size(); i++) {
            if (list[i] == temp) {
              f = false;
              break;
            }
          }
          if (f) {
            list.push_back(temp);
            rotate180(temp);
            list.push_back(temp);
            if (x == y) {
              rotate90(temp);
              list.push_back(temp);
              rotate180(temp);
              list.push_back(temp);
            }
          }
        }
      }
      if (f) {
        ans++;
        if (min > x * y) {
          min = x * y;
          X = x;
          Y = y;
        }
      }
    }
  }
  cout << ans << endl << Y << " " << X << endl;
  return 0;
}
