#include <bits/stdc++.h>
using namespace ::std;
pair<int, int> la[1005];
int la1;
int a, b;
char c[105][105];
int main() {
  int i, j, k, l, o, p, sum;
  bool ch;
  scanf("%d %d", &a, &b);
  for (i = 1; i <= a; i++) scanf("%s", &c[i][1]);
  for (i = 1; i <= a; i++)
    for (j = 1; j <= b; j++)
      if (a % i == 0 && b % j == 0) {
        ch = true;
        for (k = a / i - 1; k >= 0 && ch; --k)
          for (l = b / j - 1; l >= 0 && ch; --l)
            for (o = a / i - 1; o >= 0; --o)
              for (p = l; p >= 0; --p) {
                if (o != k || p != l) {
                  sum = 0;
                  for (int i1 = 1; i1 <= i; i1++)
                    for (int j1 = 1; j1 <= j; j1++)
                      if (c[k * i + i1][l * j + j1] !=
                          c[o * i + i1][p * j + j1]) {
                        sum++;
                        break;
                      }
                  if (sum == 0) ch = false;
                  sum = 0;
                  for (int i1 = 1; i1 <= i; i1++)
                    for (int j1 = 1; j1 <= j; j1++)
                      if (c[k * i + i - i1 + 1][l * j + j - j1 + 1] !=
                          c[o * i + i1][p * j + j1]) {
                        sum++;
                        break;
                      }
                  if (sum == 0) ch = false;
                  if (i == j) {
                    sum = 0;
                    for (int i1 = 1; i1 <= i; i1++)
                      for (int j1 = 1; j1 <= j; j1++)
                        if (c[k * i + j1][l * j + i - i1 + 1] !=
                            c[o * i + i1][p * j + j1]) {
                          sum++;
                          break;
                        }
                    if (sum == 0) ch = false;
                    sum = 0;
                    for (int i1 = 1; i1 <= i; i1++)
                      for (int j1 = 1; j1 <= j; j1++)
                        if (c[k * i + j - j1 + 1][l * j + i1] !=
                            c[o * i + i1][p * j + j1]) {
                          sum++;
                          break;
                        }
                    if (sum == 0) ch = false;
                  }
                }
              }
        if (ch) la[++la1].first = i * j, la[la1].second = i;
      }
  sort(la + 1, la + la1 + 1);
  printf("%d\n%d %d", la1, la[1].second, la[1].first / la[1].second);
  return 0;
}
