#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;
int count1(int a, int b){
    int ans11; ans11= a/b;
    if (a%b!=0) ans11++;
    return ans11;


}
int main()
{
    cin.tie(0);
    freopen("video.in","r",stdin);
    freopen ("video.out","w",stdout);
    int n,m;
    char c1;
    int ans;
    int ans1=0;
    int ans2=0;
    int i,j;
    scanf("%d %d/n",&n,&m);
    for (i=0;i<n;++i){
        for(j=0;j<m;++j){
            cin>>c1;

            if (c1=='2') {
                    ans2++;
            }
             else {
                    ans1++;
             }
        }
    }
    if (ans1<ans2) swap(ans1,ans2);
    int x2, x3;
    x2=min(n,m);
    x3=max(n,m);
    int q1;int q2=0;
    cout<<ans1<<" "<<ans2<<endl;
    if (ans2==0) {cout<<(n-1)*(m-1);return 0;}
    int l1,r1;
    l1=1;
    q1=0;
    for (l1=1;l1<x2;l1++){
        r1=count1(ans2,l1);
        if (r1>x3) {l1++;continue;}
        if (r1<x3){
        q2=n*m-n-m-l1-r1+2;} else {
            if (ans2%l1==0){q2=n*m-n-m-x2+2;} else {q2=n*m-n-m-x2+1;}
        }
        q1=max(q1,q2);
        //cout<<q1<<" "<<l1<<endl;
    }
        if (ans2%x2!=0){q2=n*m-n-m-x2+1;} else {q2=n*m-n-m-x2+2;}

        q1=max(q1,q2);
    for (l1=1;l1<x3;l1++){
        r1=count1(ans2,l1);
        if (r1>x2) {l1++;continue;}
        if (r1<x2){
        q2=n*m-n-m-l1-r1+2;} else {
            if (ans2%l1==0){q2=n*m-n-m-x3+2;} else {q2=n*m-n-m-x3+1;}
        }
        q1=max(q1,q2);
       // cout<<q1<<" "<<l1<<endl;
    }
        if (ans2%x3!=0){q2=n*m-n-m-x3+1;} else {q2=n*m-n-m-x3+2;}

        q1=max(q1,q2);
    cout<<q1;
    return 0;
}
