#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
//作者:中国江苏南京丁天行
using namespace std;
int n,m,a[60][60],r[60],c[60],p[5],ans;
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                    scanf("%d",&a[i][j]);
                    r[i]+=a[i][j];
                    c[j]+=a[i][j];
            }
    }
    for(int i=2;i<=n;i++)r[i]+=r[i-1];
    for(int i=2;i<=m;i++)c[i]+=c[i-1];
    scanf("%d%d%d",p+1,p+2,p+3);
    sort(p+1,p+4);
    if(p[1]+p[2]+p[3]==r[n]){
                             printf("0\n");
                             return 0;
    }
    do{
          for(int r1=1;r1<=n-2;r1++){
                  for(int r2=r1+1;r2<=n-1;r2++){
                          if(r[r1]==p[1]&&r[r2]-r[r1]==p[2]) ans++;
                  }
          }
          for(int c1=1;c1<=m-2;c1++){
                  for(int c2=c1+1;c2<=m-1;c2++){
                          if(c[c1]==p[1]&&c[c2]-c[c1]==p[2]) ans++;
                  }
          }
    }while(next_permutation(p+1,p+4));
    printf("%d\n",ans);
    //system("pause");
    return 0;
}


#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
//作者:中国江苏南京丁天行
using namespace std;
int n,m,a[60][60],r[60],c[60],p[5],ans;
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                    scanf("%d",&a[i][j]);
                    r[i]+=a[i][j];
                    c[j]+=a[i][j];
            }
    }
    scanf("%d%d%d",p+1,p+2,p+3);
    sort(p+1,p+4);
    do{
          for(int r1=1;r1<=n-2;r1++){
                  for(int r2=r1+1;r2<=n-1;r2++){
                          int s1=0,s2=0;
                          for(int i=1;i<=r1;i++)s1+=r[i];
                          for(int i=r1+1;i<=r2;i++)s2+=r[i];
                          if(s1==p[1]&&s2==p[2]) ans++;
                  }
          }
          for(int c1=1;c1<=m-2;c1++){
                  for(int c2=c1+1;c2<=m-1;c2++){
                          int s1=0,s2=0;
                          for(int i=1;i<=c1;i++)s1+=c[i];
                          for(int i=c1+1;i<=c2;i++)s2+=c[i];
                          if(s1==p[1]&&s2==p[2]) ans++;
                  }
          }
    }while(next_permutation(p+1,p+4));
    printf("%d\n",ans);
    //system("pause");
    return 0;
}


#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
//作者:中国江苏南京丁天行
using namespace std;
int n,m,a[60][60],r[60],c[60],p[5],ans;
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                    scanf("%d",&a[i][j]);
                    r[i]+=a[i][j];
                    c[j]+=a[i][j];
            }
    }
    for(int i=2;i<=n;i++)r[i]+=r[i-1];
    for(int i=2;i<=m;i++)c[i]+=c[i-1];
    scanf("%d%d%d",p+1,p+2,p+3);
    sort(p+1,p+4);
    do{
          for(int r1=1;r1<=n-2;r1++){
                  for(int r2=r1+1;r2<=n-1;r2++){
                          if(r[r1]==p[1]&&r[r2]-r[r1]==p[2]) ans++;
                  }
          }
          for(int c1=1;c1<=m-2;c1++){
                  for(int c2=c1+1;c2<=m-1;c2++){
                          if(c[c1]==p[1]&&c[c2]-c[c1]==p[2]) ans++;
                  }
          }
    }while(next_permutation(p+1,p+4));
    printf("%d\n",ans);
  //  system("pause");
    return 0;
}


#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
//作者:中国江苏南京丁天行
using namespace std;
int n,m,a[60][60],r[60],c[60],p[5],ans;
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                    scanf("%d",&a[i][j]);
                    r[i]+=a[i][j];
                    c[j]+=a[i][j];
            }
    }
    for(int i=2;i<=n;i++)r[i]+=r[i-1];
    for(int i=2;i<=m;i++)c[i]+=c[i-1];
    scanf("%d%d%d",p+1,p+2,p+3);
    sort(p+1,p+4);
    do{
          for(int r1=1;r1<=n-2;r1++){
                  for(int r2=r1+1;r2<=n-1;r2++){
                          if(r[r1]==p[1]&&r[r2]-r[r1]==p[2]&&r[n]-r[r2]==p[3]) ans++;
                  }
          }
          for(int c1=1;c1<=m-2;c1++){
                  for(int c2=c1+1;c2<=m-1;c2++){
                          if(c[c1]==p[1]&&c[c2]-c[c1]==p[2]&&c[m]-c[c2]==p[3]) ans++;
                  }
          }
    }while(next_permutation(p+1,p+4));
    printf("%d\n",ans);
  //  system("pause");
    return 0;
}


#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
//作者:中国江苏南京丁天行
using namespace std;
int n,m,a[60][60],r[60],c[60],p[5],ans;
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                    scanf("%d",&a[i][j]);
                    r[i]+=a[i][j];
                    c[j]+=a[i][j];
            }
    }
    for(int i=2;i<=n;i++)r[i]+=r[i-1];
    for(int i=2;i<=m;i++)c[i]+=c[i-1];
    scanf("%d%d%d",p+1,p+2,p+3);
    sort(p+1,p+4);
    do{
          for(int r1=1;r1<=n-2;r1++){
                  for(int r2=r1+1;r2<=n-1;r2++){
                          if(r[r1]==p[1]&&r[r2]-r[r1]==p[2]&&r[n]-r[r2]==p[3]) ans++;
                  }
          }
          for(int c1=1;c1<=m-2;c1++){
                  for(int c2=c1+1;c2<=m-1;c2++){
                          if(c[c1]==p[1]&&c[c2]-c[c1]==p[2]&&c[n]-c[r2]==p[3]) ans++;
                  }
          }
    }while(next_permutation(p+1,p+4));
    printf("%d\n",ans);
    //system("pause");
    return 0;
}


//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <stack>
#include <map>
#include <vector>
#include <set>
#include <bitset>
#include <string>
#include <queue>
using namespace std;
#define rep(i,l,r) for(i = l; i <= r; i++)
#define red(i,l,r) for(i=(l);i>=(r);i--)
#define u_long unsigned long long
#define fff(i, u) for(i = head[u]; i != -1; i = nxt[i])
#define fin() freopen("in.txt", "r", stdin)
#define fout() freopen("out.txt", "w", stdout)
#define clr(vis, a) memset(vis, a, sizeof(vis))
#define LL long long
#define ls id << 1
#define rs id << 1 | 1
#define lson id << 1, l, mid
#define rson id << 1 | 1, mid + 1, r
#define mid ( (l + r) >> 1 )
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define eps 1e-9
#define pi acos(-1)
const int maxn = 60;
const int maxm = maxn * 4 + 10;
const int inf = 1e9;
const LL mod = 1000000009;
int getint() {
    char c;
    while((c = getchar()) && !(c >= '0' && c <= '9') && c != '-');
    int ret = c - '0', sgn = 0;
    if(c == '-') sgn = 1, ret = 0;
    while((c = getchar()) && c >= '0' && c <= '9')
        ret = ret * 10 + c - '0';
    if(sgn) ret = -ret;
    return ret;
}
int a[maxn][maxn], c[maxn], r[maxn], f[3], g[3];
int main(){
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n, m;
	while(scanf("%d%d", &n, &m) == 2){
        int A, B, C;
        clr(c, 0);
        clr(r, 0);
        for(int i = 1; i <= n; i ++){
            for(int j = 1; j <= m; j ++){
                scanf("%d", &a[i][j]);
                r[i] += a[i][j];
                c[j] += a[i][j];
            }
        }
        for(int i = 2; i <= n; i ++) r[i] += r[i-1];
        for(int i = 2; i <= m; i ++) c[i] += c[i-1];
        for(int i = 0; i < 3; i ++) g[i] = getint();
        sort(g, g + 3);
        int ans = 0;
        for(int i = 1; i <= n; i ++){
            for(int j = i + 1; j <= n; j ++){
                f[0] = r[i];
                f[1] = r[j] - r[i];
                f[2] = r[n] - r[j];
                sort(f, f + 3);
                int flag = 1;
                for(int x = 0; x < 3; x ++){
                    if(f[x] != g[x]){
                        flag = 0;
                        break;
                    }
                }
                if(flag) ans ++;
            }
        }
        for(int i = 1; i <= m; i ++){
            for(int j = i + 1; j <= m; j ++){
                f[0] = c[i];
                f[1] = c[j] - c[i];
                f[2] = c[m] - c[j];
                sort(f, f + 3);
                int flag = 1;
                for(int x = 0; x < 3; x ++){
                    if(f[x] != g[x]){
                        flag = 0;
                        break;
                    }
                }
                if(flag) ans ++;
            }
        }
        cout << ans << endl;
	}
    return 0;
}


//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <stack>
#include <map>
#include <vector>
#include <set>
#include <bitset>
#include <string>
#include <queue>
using namespace std;
#define rep(i,l,r) for(i = l; i <= r; i++)
#define red(i,l,r) for(i=(l);i>=(r);i--)
#define u_long unsigned long long
#define fff(i, u) for(i = head[u]; i != -1; i = nxt[i])
#define fin() freopen("in.txt", "r", stdin)
#define fout() freopen("out.txt", "w", stdout)
#define clr(vis, a) memset(vis, a, sizeof(vis))
#define LL long long
#define ls id << 1
#define rs id << 1 | 1
#define lson id << 1, l, mid
#define rson id << 1 | 1, mid + 1, r
#define mid ( (l + r) >> 1 )
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define eps 1e-9
#define pi acos(-1)
const int maxn = 60;
const int maxm = maxn * 4 + 10;
const int inf = 1e9;
const LL mod = 1000000009;
int getint() {
    char c;
    while((c = getchar()) && !(c >= '0' && c <= '9') && c != '-');
    int ret = c - '0', sgn = 0;
    if(c == '-') sgn = 1, ret = 0;
    while((c = getchar()) && c >= '0' && c <= '9')
        ret = ret * 10 + c - '0';
    if(sgn) ret = -ret;
    return ret;
}
int a[maxn][maxn], c[maxn], r[maxn], f[3], g[3];
int main(){
    freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	int n, m;
	while(scanf("%d%d", &n, &m) == 2){
        int A, B, C;
        sort(g, g + 3);
        clr(c, 0);
        clr(r, 0);
        for(int i = 1; i <= n; i ++){
            for(int j = 1; j <= m; j ++){
                scanf("%d", &a[i][j]);
                r[i] += a[i][j];
                c[j] += a[i][j];
            }
        }
        for(int i = 2; i <= n; i ++) r[i] += r[i-1];
        for(int i = 2; i <= m; i ++) c[i] += c[i-1];
        for(int i = 0; i < 3; i ++) g[i] = getint();
        int ans = 0;
        for(int i = 1; i <= n; i ++){
            for(int j = i + 1; j <= n; j ++){
                f[0] = r[i];
                f[1] = r[j] - r[i];
                f[2] = r[n] - r[j];
                sort(f, f + 3);
                int flag = 1;
                for(int x = 0; x < 3; x ++){
                    if(f[x] != g[x]){
                        flag = 0;
                        break;
                    }
                }
                if(flag) ans ++;
            }
        }
        for(int i = 1; i <= m; i ++){
            for(int j = i + 1; j <= m; j ++){
                f[0] = c[i];
                f[1] = c[j] - c[i];
                f[2] = c[m] - c[j];
                sort(f, f + 3);
                int flag = 1;
                for(int x = 0; x < 3; x ++){
                    if(f[x] != g[x]){
                        flag = 0;
                        break;
                    }
                }
                if(flag) ans ++;
            }
        }
        cout << ans << endl;
	}
    return 0;
}


//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <stack>
#include <map>
#include <vector>
#include <set>
#include <bitset>
#include <string>
#include <queue>
using namespace std;
#define rep(i,l,r) for(i = l; i <= r; i++)
#define red(i,l,r) for(i=(l);i>=(r);i--)
#define u_long unsigned long long
#define fff(i, u) for(i = head[u]; i != -1; i = nxt[i])
#define fin() freopen("in.txt", "r", stdin)
#define fout() freopen("out.txt", "w", stdout)
#define clr(vis, a) memset(vis, a, sizeof(vis))
#define LL long long
#define ls id << 1
#define rs id << 1 | 1
#define lson id << 1, l, mid
#define rson id << 1 | 1, mid + 1, r
#define mid ( (l + r) >> 1 )
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define eps 1e-9
#define pi acos(-1)
const int maxn = 60;
const int maxm = maxn * 4 + 10;
const int inf = 1e9;
const LL mod = 1000000009;
int getint() {
    char c;
    while((c = getchar()) && !(c >= '0' && c <= '9') && c != '-');
    int ret = c - '0', sgn = 0;
    if(c == '-') sgn = 1, ret = 0;
    while((c = getchar()) && c >= '0' && c <= '9')
        ret = ret * 10 + c - '0';
    if(sgn) ret = -ret;
    return ret;
}
int a[maxn][maxn], c[maxn], r[maxn], f[3], g[3];
int main(){
    freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	int n, m;
	while(scanf("%d%d", &n, &m) == 2){
        int A, B, C;
        clr(c, 0);
        clr(r, 0);
        for(int i = 1; i <= n; i ++){
            for(int j = 1; j <= m; j ++){
                scanf("%d", &a[i][j]);
                r[i] += a[i][j];
                c[j] += a[i][j];
            }
        }
        for(int i = 2; i <= n; i ++) r[i] += r[i-1];
        for(int i = 2; i <= m; i ++) c[i] += c[i-1];
        for(int i = 0; i < 3; i ++) g[i] = getint();
        sort(g, g + 3);
        int ans = 0;
        for(int i = 1; i <= n; i ++){
            for(int j = i + 1; j <= n; j ++){
                f[0] = r[i];
                f[1] = r[j] - r[i];
                f[2] = r[n] - r[j];
                sort(f, f + 3);
                int flag = 1;
                for(int x = 0; x < 3; x ++){
                    if(f[x] != g[x]){
                        flag = 0;
                        break;
                    }
                }
                if(flag) ans ++;
            }
        }
        for(int i = 1; i <= m; i ++){
            for(int j = i + 1; j <= m; j ++){
                f[0] = c[i];
                f[1] = c[j] - c[i];
                f[2] = c[m] - c[j];
                sort(f, f + 3);
                int flag = 1;
                for(int x = 0; x < 3; x ++){
                    if(f[x] != g[x]){
                        flag = 0;
                        break;
                    }
                }
                if(flag) ans ++;
            }
        }
        cout << ans << endl;
	}
    return 0;
}


//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <stack>
#include <map>
#include <vector>
#include <set>
#include <bitset>
#include <string>
#include <queue>
using namespace std;
#define rep(i,l,r) for(i = l; i <= r; i++)
#define red(i,l,r) for(i=(l);i>=(r);i--)
#define u_long unsigned long long
#define fff(i, u) for(i = head[u]; i != -1; i = nxt[i])
#define fin() freopen("in.txt", "r", stdin)
#define fout() freopen("out.txt", "w", stdout)
#define clr(vis, a) memset(vis, a, sizeof(vis))
#define LL long long
#define ls id << 1
#define rs id << 1 | 1
#define lson id << 1, l, mid
#define rson id << 1 | 1, mid + 1, r
#define mid ( (l + r) >> 1 )
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define eps 1e-9
#define pi acos(-1)
const int maxn = 60;
const int maxm = maxn * 4 + 10;
const int inf = 1e9;
const LL mod = 1000000009;
int getint() {
    char c;
    while((c = getchar()) && !(c >= '0' && c <= '9') && c != '-');
    int ret = c - '0', sgn = 0;
    if(c == '-') sgn = 1, ret = 0;
    while((c = getchar()) && c >= '0' && c <= '9')
        ret = ret * 10 + c - '0';
    if(sgn) ret = -ret;
    return ret;
}
int a[maxn][maxn], c[maxn], r[maxn], f[3], g[3];
int main(){
    freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	int n, m;
	while(scanf("%d%d", &n, &m) == 2){
        int A, B, C;
        clr(c, 0);
        clr(r, 0);
        for(int i = 1; i <= n; i ++){
            for(int j = 1; j <= m; j ++){
                scanf("%d", &a[i][j]);
                r[i] += a[i][j];
                c[j] += a[i][j];
            }
        }
        for(int i = 2; i <= n; i ++) r[i] += r[i-1];
        for(int i = 2; i <= m; i ++) c[i] += c[i-1];
        for(int i = 0; i < 3; i ++) g[i] = getint();
        sort(g, g + 3);
        int ans = 0;
        for(int i = 1; i <= n; i ++){
            for(int j = i + 1; j < n; j ++){
                f[0] = r[i];
                f[1] = r[j] - r[i];
                f[2] = r[n] - r[j];
                sort(f, f + 3);
                int flag = 1;
                for(int x = 0; x < 3; x ++){
                    if(f[x] != g[x]){
                        flag = 0;
                        break;
                    }
                }
                if(flag) ans ++;
            }
        }
        for(int i = 1; i <= m; i ++){
            for(int j = i + 1; j < m; j ++){
                f[0] = c[i];
                f[1] = c[j] - c[i];
                f[2] = c[m] - c[j];
                sort(f, f + 3);
                int flag = 1;
                for(int x = 0; x < 3; x ++){
                    if(f[x] != g[x]){
                        flag = 0;
                        break;
                    }
                }
                if(flag) ans ++;
            }
        }
        cout << ans << endl;
	}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 55;

int n, m;
int r[N], c[N];

bool check(int* r, int* a, int n) {
  int i = 0, j = -1;
  while (r[i] < a[0] && i < n) {
    ++i;
  }
  if (r[i] != a[0]) {
    return false;
  }
  j = i++;
  while (r[i] - r[j] < a[1] && i < n) {
    ++i;
  }
  if (r[i] - r[j] != a[1]) {
    return false;
  }
  j = i++;
  while (r[i] - r[j] < a[2] && i < n) {
    ++i;
  }
  if (r[i] - r[j] != a[2]) {
    return false;
  }
  return i == n - 1;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int x;
      cin >> x;
      r[i] += x;
      c[j] += x;
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    r[i + 1] += r[i];
  }
  for (int j = 0; j < m - 1; ++j) {
    c[j + 1] += c[j];
  }
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  int b[3] = {-1, -1, -1};
  int ans = 0;
  do {
    if (a[0] == b[0] && a[1] == b[1] && a[2] == b[2]) {
      continue;
    }
    ans += check(r, a, n);
    ans += check(c, a, m);
    copy(a, a + 3, b);
  } while (next_permutation(a, a + 3));
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 55;

int n, m;
int r[N], c[N];
int x, y, z;

int calc(int* w, int n) {
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n - 1; ++j) {
      int s1 = w[i];
      int s2 = w[j] - w[i];
      int s3 = w[n - 1] - w[j];
      if (s1 > s2) swap(s1, s2);
      if (s2 > s3) swap(s2, s3);
      if (s1 > s2) swap(s1, s2);
      if (s1 == x && s2 == y && s3 == z) {
        ret++;
      }
    }
  }
  return ret;
}

int main() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int x;
      scanf("%d", &x);
      r[i] += x;
      c[j] += x;
    }
  }
  scanf("%d %d %d", &x, &y, &z);
  if (x > y) swap(x, y);
  if (y > z) swap(y, z);
  if (x > y) swap(x, y);
  for (int i = 0; i < n - 1; ++i) {
    r[i + 1] += r[i];
  }
  for (int j = 0; j < m - 1; ++j) {
    c[j + 1] += c[j];
  }
  printf("%d\n", calc(r, n) + calc(c, m));
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 55;

int n, m;
int r[N], c[N];

bool check(int* r, int* a, int n) {
  int i = 0, j = -1;
  while (r[i] < a[0] && i < n) {
    ++i;
  }
  if (r[i] != a[0]) {
    return false;
  }
  j = i++;
  while (r[i] - r[j] < a[1] && i < n) {
    ++i;
  }
  if (r[i] - r[j] != a[1]) {
    return false;
  }
  j = i++;
  while (r[i] - r[j] < a[2] && i < n) {
    ++i;
  }
  if (r[i] - r[j] != a[2]) {
    return false;
  }
  return i == n - 1;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int x;
      cin >> x;
      r[i] += x;
      c[j] += x;
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    r[i + 1] += r[i];
  }
  for (int j = 0; j < m - 1; ++j) {
    c[j + 1] += c[j];
  }
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  int b[3] = {-1, -1, -1};
  int ans = 0;
  do {
    if (a[0] == b[0] && a[1] == b[1] && a[2] == b[2]) {
      continue;
    }
    ans += check(r, a, n);
    ans += check(c, a, m);
    copy(a, a + 3, b);
  } while (next_permutation(a, a + 3));
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 55;

int n, m;
int r[N], c[N];

bool check(int* r, int* a, int n) {
  int i = 0, j = -1;
  while (r[i] < a[0] && i < n) {
    ++i;
  }
  if (r[i] != a[0]) {
    return false;
  }
  j = i++;
  while (r[i] - r[j] < a[1] && i < n) {
    ++i;
  }
  if (r[i] - r[j] != a[1]) {
    return false;
  }
  j = i++;
  while (r[i] - r[j] < a[2] && i < n) {
    ++i;
  }
  if (r[i] - r[j] != a[2]) {
    return false;
  }
  return i == n - 1;
}

int main() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int x;
      scanf("%d", &x);
      r[i] += x;
      c[j] += x;
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    r[i + 1] += r[i];
  }
  for (int j = 0; j < m - 1; ++j) {
    c[j + 1] += c[j];
  }
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  int b[3] = {-1, -1, -1};
  int ans = 0;
  do {
    if (a[0] == b[0] && a[1] == b[1] && a[2] == b[2]) {
      continue;
    }
    ans += check(r, a, n);
    ans += check(c, a, m);
    copy(a, a + 3, b);
  } while (next_permutation(a, a + 3));
  printf("%d\n", ans);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 55;

int n, m;
int r[N], c[N];
int x, y, z;

int calc(int* w, int n) {
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int s1 = w[i];
      int s2 = w[j] - w[i];
      int s3 = w[n - 1] - w[j];
      if (s1 > s2) swap(s1, s2);
      if (s2 > s3) swap(s2, s3);
      if (s1 > s2) swap(s1, s2);
      if (s1 == x && s2 == y && s3 == z) {
        ret++;
      }
    }
  }
  return ret;
}

int main() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int x;
      scanf("%d", &x);
      r[i] += x;
      c[j] += x;
    }
  }
  scanf("%d %d %d", &x, &y, &z);
  if (x > y) swap(x, y);
  if (y > z) swap(y, z);
  if (x > y) swap(x, y);
  for (int i = 0; i < n - 1; ++i) {
    r[i + 1] += r[i];
  }
  for (int j = 0; j < m - 1; ++j) {
    c[j + 1] += c[j];
  }
  printf("%d\n", calc(r, n) + calc(c, m));
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 55;

int n, m;
int r[N], c[N];

bool check(int* r, int* a, int n) {
  for (int i = 0; i < n; ++i) {
    for (int j = i; j < n; ++j) {
      if (r[i] == a[0] && r[j] - r[i] == a[1] && r[n - 1] - r[j] == a[2]) {
        return true;
      }
    }
  }
  return false;
}

int main() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int x;
      scanf("%d", &x);
      r[i] += x;
      c[j] += x;
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    r[i + 1] += r[i];
  }
  for (int j = 0; j < m - 1; ++j) {
    c[j + 1] += c[j];
  }
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  int b[3] = {-1, -1, -1};
  int ans = 0;
  do {
    // a[] == b[]
    if (a[0] == b[0] && a[1] == b[1] && a[2] == b[2]) {
      continue;
    }
    ans += check(r, a, n);
    ans += check(c, a, m);
    copy(a, a + 3, b);
  } while (next_permutation(a, a + 3));
  printf("%d\n", ans);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 55;

int n, m;
int r[N], c[N];

int check(int* r, int* a, int n) {
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n - 1; ++j) {
      if (r[i] == a[0] && r[j] - r[i] == a[1] && r[n - 1] - r[j] == a[2]) {
        ret++;
      }
    }
  }
  return ret;
}

int main() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int x;
      scanf("%d", &x);
      r[i] += x;
      c[j] += x;
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    r[i + 1] += r[i];
  }
  for (int j = 0; j < m - 1; ++j) {
    c[j + 1] += c[j];
  }
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  int b[3] = {-1, -1, -1};
  int ans = 0;
  do {
    // a[] == b[]
    if (a[0] == b[0] && a[1] == b[1] && a[2] == b[2]) {
      continue;
    }
    ans += check(r, a, n);
    ans += check(c, a, m);
    copy(a, a + 3, b);
  } while (next_permutation(a, a + 3));
  printf("%d\n", ans);
  return 0;
}


#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <fstream>

using namespace std;

#define REP(i,s,e) for(int i = s;i < e;i++)
#define rep(i,e) REP(i,0,e)
#define ll long long
#define INF 1 << 30
int grows[50][50];
int suns[3];
int n; // num_of_column
int m; // num of row
int column_sums[50];
int row_sums[50];
int tmp[3];

int calcurate_column_grow_sum(int start, int end){
    int ans = 0;
    REP(i,start,end) ans += column_sums[i];
    return ans;
}

int calcurate_row_grow_sum(int start, int end){
    int ans = 0;
    REP(i,start,end) ans += row_sums[i];
    return ans;
}

bool check_column(int* tmp, int line_1, int line_2){
    int A = calcurate_column_grow_sum(0,line_1);
    int B = calcurate_column_grow_sum(line_1, line_2);
    int C = calcurate_column_grow_sum(line_2, n);
    if(A != *(tmp)) return false;
    if(B != *(tmp+1)) return false;
    if(C != *(tmp+2)) return false;
}

bool check_rows(int* tmp, int line_1, int line_2){
    int A = calcurate_row_grow_sum(0,line_1);
    int B = calcurate_row_grow_sum(line_1, line_2);
    int C = calcurate_row_grow_sum(line_2, m);
    if(A != *(tmp)) return false;
    if(B != *(tmp+1)) return false;
    if(C != *(tmp+2)) return false;

}

int main(){
    ifstream input("input.txt");
    ofstream output("output.txt");
    input >> n >> m;
    rep(i,n) rep(j,m) input >> grows[i][j];
    rep(i,3) input >> suns[i];
    sort(suns, suns+3);
    memset(row_sums, 0, sizeof(row_sums));
    memset(column_sums, 0, sizeof(column_sums));
    rep(i,n) rep(j,m) column_sums[i] += grows[i][j];
    rep(i,m) rep(j,n) row_sums[i] += grows[j][i];
    int patterns = 0;
    // column check
    if(n > 2) do{
    REP(i,1,n-1) REP(j,i+1,n) if( check_column(suns,i,j)) patterns++;
    }while(next_permutation(suns, suns+3));
    sort(suns, suns+3);
    // row check
    if(m > 2) do{
    REP(i,1,m-1) REP(j,i+1,m) if(check_rows(suns,i,j)) patterns++;
    }while(next_permutation(suns, suns+3));
    output << patterns << endl;
}


#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <fstream>

using namespace std;

#define REP(i,s,e) for(int i = s;i < e;i++)
#define rep(i,e) REP(i,0,e)
#define ll long long
#define INF 1 << 30
int grows[50][50];
int suns[3];
int n; // num_of_column
int m; // num of row
int column_sums[50];
int row_sums[50];
int tmp[3];

int calcurate_column_grow_sum(int start, int end){
    int ans = 0;
    REP(i,start,end) ans += column_sums[i];
    return ans;
}

int calcurate_row_grow_sum(int start, int end){
    int ans = 0;
    REP(i,start,end) ans += row_sums[i];
    return ans;
}

bool check_column(int start, int* tmp, int count){
    bool ok = false;
    int sum = 0;
    if(count == 2){
    sum = calcurate_column_grow_sum(start,n);
    if(sum == *(tmp+count)) return true;
    return false;
    }
    REP(i,start,n-(2 - count)){
    sum = 0;
    sum = calcurate_column_grow_sum(start,i+1);
    if(sum != *(tmp+count)) continue; else return check_column(i+1, tmp, count+1);
    }
    }
    return false;
}

bool check_rows(int start, int* tmp, int count){
    cout << "Check rows" << endl;
    int sum;
    bool ok = false;
    rep(i,3) cout << tmp[i] << endl;
    if(count == 2){
    sum = calcurate_row_grow_sum(start,m);
    if(sum == *(tmp+count)){
        cout << "OK Passed" << endl;
        return true;
    }
    return false;
    }
    REP(i,start,m-(2-count)){
    sum = 0;
    sum = calcurate_row_grow_sum(start,i+1);
    cout << "Compare " << sum << " with " << *(tmp+count) << endl;
    if(sum != *(tmp+count)) continue; else return check_rows(i+1, tmp, count+1);
    }
    return false;
}

int main(){
    ifstream input("input.txt");
    ofstream output("output.txt");
    input >> n >> m;
    rep(i,n) rep(j,m) input >> grows[i][j];
    rep(i,3) input >> suns[i];
    sort(suns, suns+2);
    memset(row_sums, 0, sizeof(row_sums));
    memset(column_sums, 0, sizeof(column_sums));
    rep(i,n) rep(j,m) column_sums[i] += grows[i][j];
    rep(i,m) rep(j,n) row_sums[i] += grows[j][i];
    rep(i,m) cout << row_sums[i] << endl;
    int patterns = 0;
    // column check
    if(n > 2) do{
    memcpy(tmp, suns, sizeof(suns));
    if( check_column(0,tmp,0)) patterns++;
    }while(next_permutation(suns, suns+3));
    sort(suns, suns+2);
    // row check
    if(m > 2) do{
    memcpy(tmp, suns,sizeof(suns));
    if(check_rows(0,tmp,0)) patterns++;
    }while(next_permutation(suns, suns+3));
    output << patterns << endl;
}


#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <fstream>

using namespace std;

#define REP(i,s,e) for(int i = s;i < e;i++)
#define rep(i,e) REP(i,0,e)
#define ll long long
#define INF 1 << 30
int grows[50][50];
int suns[3];
int n; // num_of_column
int m; // num of row
int column_sums[50];
int row_sums[50];
int tmp[3];

int calcurate_column_grow_sum(int start, int end){
    int ans = 0;
    REP(i,start,end) ans += column_sums[i];
    return ans;
}

int calcurate_row_grow_sum(int start, int end){
    int ans = 0;
    REP(i,start,end) ans += row_sums[i];
    return ans;
}

bool check_column(int start, int* tmp, int count){
    bool ok = false;
    int sum = 0;
    if(count == 2){
    sum = calcurate_column_grow_sum(start,n);
    if(sum == *(tmp+count)) return true;
    return false;
    }
    REP(i,start,n-(2 - count)){
    sum = 0;
    sum = calcurate_column_grow_sum(start,i+1);
    if(sum != *(tmp+count)) continue; else return check_column(i+1, tmp, count+1);
    }
    return false;
}

bool check_rows(int start, int* tmp, int count){
    cout << "Check rows" << endl;
    int sum;
    bool ok = false;
    rep(i,3) cout << tmp[i] << endl;
    if(count == 2){
    sum = calcurate_row_grow_sum(start,m);
    if(sum == *(tmp+count)){
        cout << "OK Passed" << endl;
        return true;
    }
    return false;
    }
    REP(i,start,m-(2-count)){
    sum = 0;
    sum = calcurate_row_grow_sum(start,i+1);
    cout << "Compare " << sum << " with " << *(tmp+count) << endl;
    if(sum != *(tmp+count)) continue; else return check_rows(i+1, tmp, count+1);
    }
    return false;
}

int main(){
    ifstream input("input.txt");
    ofstream output("output.txt");
    input >> n >> m;
    rep(i,n) rep(j,m) input >> grows[i][j];
    rep(i,3) input >> suns[i];
    sort(suns, suns+2);
    memset(row_sums, 0, sizeof(row_sums));
    memset(column_sums, 0, sizeof(column_sums));
    rep(i,n) rep(j,m) column_sums[i] += grows[i][j];
    rep(i,m) rep(j,n) row_sums[i] += grows[j][i];
    rep(i,m) cout << row_sums[i] << endl;
    int patterns = 0;
    // column check
    if(n > 2) do{
    memcpy(tmp, suns, sizeof(suns));
    if( check_column(0,tmp,0)) patterns++;
    }while(next_permutation(suns, suns+3));
    sort(suns, suns+2);
    // row check
    if(m > 2) do{
    memcpy(tmp, suns,sizeof(suns));
    if(check_rows(0,tmp,0)) patterns++;
    }while(next_permutation(suns, suns+3));
    output << patterns << endl;
}


#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <fstream>

using namespace std;

#define REP(i,s,e) for(int i = s;i < e;i++)
#define rep(i,e) REP(i,0,e)
#define ll long long
#define INF 1 << 30
int grows[50][50];
int suns[3];
int n; // num_of_column
int m; // num of row
int column_sums[50];
int row_sums[50];
int tmp[3];

int calcurate_column_grow_sum(int start, int end){
    int ans = 0;
    REP(i,start,end) ans += column_sums[i];
    return ans;
}

int calcurate_row_grow_sum(int start, int end){
    int ans = 0;
    REP(i,start,end) ans += row_sums[i];
    return ans;
}

bool check_column(int* tmp, int line_1, int line_2){
    int A = calcurate_column_grow_sum(0,line_1);
    int B = calcurate_column_grow_sum(line_1, line_2);
    int C = calcurate_column_grow_sum(line_2, n);
    if(A != *(tmp)) return false;
    if(B != *(tmp+1)) return false;
    if(C != *(tmp+2)) return false;
}

bool check_rows(int* tmp, int line_1, int line_2){
    int A = calcurate_row_grow_sum(0,line_1);
    int B = calcurate_row_grow_sum(line_1, line_2);
    int C = calcurate_row_grow_sum(line_2, m);
    if(A != *(tmp)) return false;
    if(B != *(tmp+1)) return false;
    if(C != *(tmp+2)) return false;

}

int main(){
    ifstream input("input.txt");
    ofstream output("output.txt");
    input >> n >> m;
    rep(i,n) rep(j,m) input >> grows[i][j];
    rep(i,3) input >> suns[i];
    sort(suns, suns+2);
    memset(row_sums, 0, sizeof(row_sums));
    memset(column_sums, 0, sizeof(column_sums));
    rep(i,n) rep(j,m) column_sums[i] += grows[i][j];
    rep(i,m) rep(j,n) row_sums[i] += grows[j][i];
    int patterns = 0;
    // column check
    if(n > 2) do{
    REP(i,1,n-1) REP(j,i+1,n) if( check_column(suns,i,j)) patterns++;
    }while(next_permutation(suns, suns+3));
    sort(suns, suns+2);
    // row check
    if(m > 2) do{
    REP(i,1,m-1) REP(j,i+1,m) if(check_rows(suns,i,j)) patterns++;
    }while(next_permutation(suns, suns+3));
    output << patterns << endl;
}


#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <fstream>

using namespace std;

#define REP(i,s,e) for(int i = s;i < e;i++)
#define rep(i,e) REP(i,0,e)
#define ll long long
#define INF 1 << 30

int grows[50][50];
int suns[3];
int n; // num_of_column
int m; // num of row
int column_sums[50];
int row_sums[50];

int calcurate_column_grow_sum(int start, int end){
    int ans = 0;
    REP(i,start,end) ans += column_sums[i];
    return ans;
}

int calcurate_row_grow_sum(int start, int end){
    int ans = 0;
    REP(i,start,end) ans += row_sums[i];
    return ans;
}

bool check_column(int* tmp, int line_1, int line_2){
    int A = calcurate_column_grow_sum(0,line_1);
    int B = calcurate_column_grow_sum(line_1, line_2);
    int C = calcurate_column_grow_sum(line_2, n);
    if(A != *(tmp)) return false;
    if(B != *(tmp+1)) return false;
    if(C != *(tmp+2)) return false;
    return true;
}

bool check_row(int* tmp, int line_1, int line_2){
    int A = calcurate_row_grow_sum(0,line_1);
    int B = calcurate_row_grow_sum(line_1, line_2);
    int C = calcurate_row_grow_sum(line_2, m);
    if(A != *(tmp)) return false;
    if(B != *(tmp+1)) return false;
    if(C != *(tmp+2)) return false;
    return true;
}

int main(){
    ifstream input("input.txt");
    ofstream output("output.txt");
    input >> n >> m;
    rep(i,n) rep(j,m) input >> grows[i][j];
    rep(i,3) input >> suns[i];
    sort(suns, suns+3);
    memset(row_sums, 0, sizeof(row_sums));
    memset(column_sums, 0, sizeof(column_sums));
    rep(i,n) rep(j,m) column_sums[i] += grows[i][j];
    rep(i,m) rep(j,n) row_sums[i] += grows[j][i];
    int patterns = 0;
    // column check
    if(n > 2) do{
    REP(i,1,n) REP(j,i+1,n) if(check_column(suns,i,j)) patterns++;
    }while(next_permutation(suns, suns+3));
    sort(suns, suns+3);
    // row check
    if(m > 2) do{
    REP(i,1,m) REP(j,i+1,m) if(check_row(suns,i,j)) patterns++;
    }while(next_permutation(suns, suns+3));
    output << patterns << endl;
    return 0;
}


#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <fstream>

using namespace std;

#define REP(i,s,e) for(int i = s;i < e;i++)
#define rep(i,e) REP(i,0,e)
#define ll long long
#define INF 1 << 30
int grows[50][50];
int suns[3];
int n; // num_of_column
int m; // num of row
int column_sums[50];
int row_sums[50];
int tmp[3];

int calcurate_column_grow_sum(int start, int end){
    int ans = 0;
    REP(i,start,end) ans += column_sums[i];
    return ans;
}

int calcurate_row_grow_sum(int start, int end){
    int ans = 0;
    REP(i,start,end) ans += row_sums[i];
    return ans;
}

bool check_column(int start, int* tmp, int count){
    bool ok = false;
    int sum = 0;
    if(count == 2){
    sum = calcurate_column_grow_sum(start,n);
    if(sum == *(tmp+count)) return true;
    return false;
    }
    REP(i,start,n-(2 - count)){
    sum = 0;
    sum = calcurate_column_grow_sum(start,i+1);
    if(sum == *(tmp+count)){
        ok = true;
        cout << "OK, try next loop" << endl;
        *(tmp + count) = -1;
    }
    if(!ok) continue;
    else{
        if(count == 2) return true;
        else{
        return check_column(i+1, tmp, count+1);
        }
    }
    }
    return false;
}

bool check_rows(int start, int* tmp, int count){
    cout << "Check rows" << endl;
    int sum;
    bool ok = false;
    rep(i,3) cout << tmp[i] << endl;
    if(count == 2){
    sum = calcurate_row_grow_sum(start,m);
    if(sum == *(tmp+count)){
        cout << "OK Passed" << endl;
        return true;
    }
    return false;
    }
    REP(i,start,m-(2-count)){
    sum = 0;
    sum = calcurate_row_grow_sum(start,i+1);
    cout << "Compare " << sum << " with " << *(tmp+count) << endl;
    if(sum == *(tmp+count)){
        ok = true;
        *(tmp+count) = -1;
        cout << "OK, try next loop" << endl;
    }
    if(!ok) continue; else return check_rows(i+1, tmp, count+1);
    }
    return false;
}

int main(){
    ifstream input("input.txt");
    ofstream output("output.txt");
    input >> n >> m;
    rep(i,n) rep(j,m) input >> grows[i][j];
    rep(i,3) input >> suns[i];
    sort(suns, suns+2);
    memset(row_sums, 0, sizeof(row_sums));
    memset(column_sums, 0, sizeof(column_sums));
    rep(i,n) rep(j,m) column_sums[i] += grows[i][j];
    rep(i,m) rep(j,n) row_sums[i] += grows[j][i];
    rep(i,m) cout << row_sums[i] << endl;
    int patterns = 0;
    // column check
    if(n > 2) do{
    memcpy(tmp, suns, sizeof(suns));
    if( check_column(0,tmp,0)) patterns++;
    }while(next_permutation(suns, suns+3));
    // row check
    if(m > 2) do{
    memcpy(tmp, suns,sizeof(suns));
    if(check_rows(0,tmp,0)) patterns++;
    }while(next_permutation(suns, suns+3));
    output << patterns << endl;
}


#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

#define lowbit(x) (x&(-x))
#define Max(a,b) a>b?a:b;
#define LL long long
#define maxn 1000000
#define mod1 112233
#define CC(m,what) memset(m,what,sizeof(m))
#define L(i) (1<<i)
#define R(i) (1>>i)
#define check(a,i) ((a & L(i-1))
#define inf 0x7fffffff
#define eps 1e-7
#define FF(i,n) for (i = 0 ; i < n ; i ++)

int save[100][100];
int lsum[100];
int rsum[100];
int s[3];
int main()
{
    int n,k,i,j,m;
    int s1[3];
    int a1,b1,c1;
    int cnt;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    CC(lsum,0);
    CC(rsum,0);
    cnt=0;
    cin>>n>>m;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
        {
            cin>>save[i][j];
            lsum[j]+=save[i][j];
            rsum[i]+=save[i][j];
        }

    cin>>s[0]>>s[1]>>s[2];
    sort(s,s+3);
    for(i=2;i<=n;i++)
        rsum[i]+=rsum[i-1];

    for(j=2;j<=m;j++)
        lsum[j]+=lsum[j-1];

/*
    for(i=1;i<=n;i++)
       cout<<rsum[i]<<endl;
    cout<<"~~~~~~~~"<<endl;
    for(i=1;i<=m;i++)
        cout<<lsum[i]<<endl;
*/
    for(i=1;i<=n;i++)
        for(j=i+1;j<n;j++)
        {
            s1[0]=rsum[i];
            s1[1]=rsum[j]-rsum[i];
            s1[2]=rsum[n]-rsum[j];

            sort(s1,s1+3);
            for(k=0;k<3;k++)
                if(s1[k]!=s[k])break;
                if(k==3)cnt++;
        }
    for(i=1;i<=m;i++)
        for(j=i+1;j<m;j++)
        {
            s1[0]=lsum[i];
            s1[1]=lsum[j]-lsum[i];
            s1[2]=lsum[m]-lsum[j];
            sort(s1,s1+3);
            //cout<<"s1="<<s1[0]<<" "<<s1[1]<<" "<<s1[2]<<endl;
            for(k=0;k<3;k++)
            if(s1[k]!=s[k])break;
                if(k==3)cnt++;
        }
    cout<<cnt<<endl;
}


#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

#define lowbit(x) (x&(-x))
#define Max(a,b) a>b?a:b;
#define LL long long
#define maxn 1000000
#define mod1 112233
#define CC(m,what) memset(m,what,sizeof(m))
#define L(i) (1<<i)
#define R(i) (1>>i)
#define check(a,i) ((a & L(i-1))
#define inf 0x7fffffff
#define eps 1e-7
#define FF(i,n) for (i = 0 ; i < n ; i ++)

int save[100][100];
int lsum[100];
int rsum[100];
int s[3];
int main()
{
    int n,k,i,j,m;
    int s1[3];
    int a1,b1,c1;
    int cnt;
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    CC(lsum,0);
    CC(rsum,0);
    cnt=0;
    cin>>n>>m;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
        {
            cin>>save[i][j];
            lsum[j]+=save[i][j];
            rsum[i]+=save[i][j];
        }

    cin>>s[0]>>s[1]>>s[2];
    sort(s,s+3);
    for(i=2;i<=n;i++)
        rsum[i]+=rsum[i-1];
    for(j=2;j<=m;j++)
        lsum[j]+=lsum[j-1];
   // for(i=1;i<=n;i++)
     //   cout<<rsum[i]<<endl;
   // cout<<"~~~~~~~~"<<endl;
   // for(i=1;i<=m;i++)
   //     cout<<lsum[i]<<endl;
    for(i=1;i<=n;i++)
        for(j=i+1;j<=n;j++)
        {
            s1[0]=rsum[i];
            s1[1]=rsum[j]-rsum[i];
            s1[2]=rsum[n]-rsum[j];

            sort(s1,s1+3);
            for(k=0;k<3;k++)
                if(s1[k]!=s[k])break;
                if(k==3)cnt++;
        }
    for(i=1;i<=m;i++)
        for(j=i+1;j<=m;j++)
        {
            s1[0]=lsum[i];
            s1[1]=lsum[j]-lsum[i];
            s1[2]=lsum[m]-lsum[j];
            sort(s1,s1+3);
            //cout<<"s1="<<s1[0]<<" "<<s1[1]<<" "<<s1[2]<<endl;
            for(k=0;k<3;k++)
            if(s1[k]!=s[k])break;
                if(k==3)cnt++;
        }
    cout<<cnt<<endl;
}


#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

#define lowbit(x) (x&(-x))
#define Max(a,b) a>b?a:b;
#define LL long long
#define maxn 1000000
#define mod1 112233
#define CC(m,what) memset(m,what,sizeof(m))
#define L(i) (1<<i)
#define R(i) (1>>i)
#define check(a,i) ((a & L(i-1))
#define inf 0x7fffffff
#define eps 1e-7
#define FF(i,n) for (i = 0 ; i < n ; i ++)

int save[100][100];
int lsum[100];
int rsum[100];
int s[3];
int main()
{
    int n,k,i,j,m;
    int s1[3];
    int a1,b1,c1;
    int cnt;
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    CC(lsum,0);
    CC(rsum,0);
    cnt=0;
    cin>>n>>m;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
        {
            cin>>save[i][j];
            lsum[j]+=save[i][j];
            rsum[i]+=save[i][j];
        }

    cin>>s[0]>>s[1]>>s[2];
    sort(s,s+3);
    for(i=2;i<=n;i++)
        rsum[i]+=rsum[i-1];

    for(j=2;j<=m;j++)
        lsum[j]+=lsum[j-1];

/*
    for(i=1;i<=n;i++)
       cout<<rsum[i]<<endl;
    cout<<"~~~~~~~~"<<endl;
    for(i=1;i<=m;i++)
        cout<<lsum[i]<<endl;
*/
    for(i=1;i<=n;i++)
        for(j=i;j<=n;j++)
        {
            s1[0]=rsum[i];
            s1[1]=rsum[j]-rsum[i];
            s1[2]=rsum[n]-rsum[j];

            sort(s1,s1+3);
            for(k=0;k<3;k++)
                if(s1[k]!=s[k])break;
                if(k==3)cnt++;
        }
    for(i=1;i<=m;i++)
        for(j=i;j<=m;j++)
        {
            s1[0]=lsum[i];
            s1[1]=lsum[j]-lsum[i];
            s1[2]=lsum[m]-lsum[j];
            sort(s1,s1+3);
            //cout<<"s1="<<s1[0]<<" "<<s1[1]<<" "<<s1[2]<<endl;
            for(k=0;k<3;k++)
            if(s1[k]!=s[k])break;
                if(k==3)cnt++;
        }
    cout<<cnt<<endl;
}


#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

#define lowbit(x) (x&(-x))
#define Max(a,b) a>b?a:b;
#define LL long long
#define maxn 1000000
#define mod1 112233
#define CC(m,what) memset(m,what,sizeof(m))
#define L(i) (1<<i)
#define R(i) (1>>i)
#define check(a,i) ((a & L(i-1))
#define inf 0x7fffffff
#define eps 1e-7
#define FF(i,n) for (i = 0 ; i < n ; i ++)

int save[100][100];
int lsum[100];
int rsum[100];
int s[3];
int main()
{
    int n,k,i,j,m;
    int s1[3];
    int a1,b1,c1;
    int cnt;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    CC(lsum,0);
    CC(rsum,0);
    cnt=0;
    cin>>n>>m;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
        {
            cin>>save[i][j];
            lsum[j]+=save[i][j];
            rsum[i]+=save[i][j];
        }

    cin>>s[0]>>s[1]>>s[2];
    sort(s,s+3);
    for(i=2;i<=n;i++)
        rsum[i]+=rsum[i-1];

    for(j=2;j<=m;j++)
        lsum[j]+=lsum[j-1];

/*
    for(i=1;i<=n;i++)
       cout<<rsum[i]<<endl;
    cout<<"~~~~~~~~"<<endl;
    for(i=1;i<=m;i++)
        cout<<lsum[i]<<endl;
*/
    for(i=1;i<=n;i++)
        for(j=i;j<=n;j++)
        {
            s1[0]=rsum[i];
            s1[1]=rsum[j]-rsum[i];
            s1[2]=rsum[n]-rsum[j];

            sort(s1,s1+3);
            for(k=0;k<3;k++)
                if(s1[k]!=s[k])break;
                if(k==3)cnt++;
        }
    for(i=1;i<=m;i++)
        for(j=i;j<=m;j++)
        {
            s1[0]=lsum[i];
            s1[1]=lsum[j]-lsum[i];
            s1[2]=lsum[m]-lsum[j];
            sort(s1,s1+3);
            //cout<<"s1="<<s1[0]<<" "<<s1[1]<<" "<<s1[2]<<endl;
            for(k=0;k<3;k++)
            if(s1[k]!=s[k])break;
                if(k==3)cnt++;
        }
    cout<<cnt<<endl;
}


#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

#define lowbit(x) (x&(-x))
#define Max(a,b) a>b?a:b;
#define LL long long
#define maxn 1000000
#define mod1 112233
#define CC(m,what) memset(m,what,sizeof(m))
#define L(i) (1<<i)
#define R(i) (1>>i)
#define check(a,i) ((a & L(i-1))
#define inf 0x7fffffff
#define eps 1e-7
#define FF(i,n) for (i = 0 ; i < n ; i ++)

int save[100][100];
int lsum[100];
int rsum[100];
int s[3];
int main()
{
    int n,k,i,j,m;
    int s1[3];
    int a1,b1,c1;
    int cnt;
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    CC(lsum,0);
    CC(rsum,0);
    cnt=0;
    cin>>n>>m;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
        {
            cin>>save[i][j];
            lsum[j]+=save[i][j];
            rsum[i]+=save[i][j];
        }

    cin>>s[0]>>s[1]>>s[2];
    sort(s,s+3);
    for(i=2;i<=n;i++)
        rsum[i]+=rsum[i-1];

    for(j=2;j<=m;j++)
        lsum[j]+=lsum[j-1];

/*
    for(i=1;i<=n;i++)
       cout<<rsum[i]<<endl;
    cout<<"~~~~~~~~"<<endl;
    for(i=1;i<=m;i++)
        cout<<lsum[i]<<endl;
*/
    for(i=1;i<=n;i++)
        for(j=i+1;j<n;j++)
        {
            s1[0]=rsum[i];
            s1[1]=rsum[j]-rsum[i];
            s1[2]=rsum[n]-rsum[j];

            sort(s1,s1+3);
            for(k=0;k<3;k++)
                if(s1[k]!=s[k])break;
                if(k==3)cnt++;
        }
    for(i=1;i<=m;i++)
        for(j=i+1;j<m;j++)
        {
            s1[0]=lsum[i];
            s1[1]=lsum[j]-lsum[i];
            s1[2]=lsum[m]-lsum[j];
            sort(s1,s1+3);
            //cout<<"s1="<<s1[0]<<" "<<s1[1]<<" "<<s1[2]<<endl;
            for(k=0;k<3;k++)
            if(s1[k]!=s[k])break;
                if(k==3)cnt++;
        }
    cout<<cnt<<endl;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int row[55],line[55],num,A[3],ot[5][2],lvl;
void op(int ii[])
{
	int a[3];
	memset(a,0,sizeof(a));
	for(int i=0;i<3;i++)
	{
		for(int j=ot[i][0];j<=ot[i][1];j++)
			a[i]+=ii[j];
	}
	sort(a,a+3);
//	printf("%d %d %d      ",a[0],a[1],a[2]);
	for(int i=0;i<3;i++)
		if(a[i]!=A[i])return;
	num++;
	return ;
}
void oo(int ii[])
{int k=0;
	for(int i=0;i<3;i++)
	{
		for(int j=ot[i][0];j<=ot[i][1];j++)
		{
			k+=ii[j];
		}
		printf("%d ",k);k=0;
	}
	printf("\n");
	return;
}
void dfs(int now,int lvl,int len,int ii[])
{
	if(lvl==2&&now<len)
	{
		ot[lvl][0]=now;
		ot[lvl][1]=len-1;
		op(ii);
	//	oo(ii);
		return;
	}
	for(int i=now;i<len;i++)
	{
		ot[lvl][0]=now;
		ot[lvl][1]=i;
		dfs(i+1,lvl+1,len,ii);
	}
}
int main()
{
	int m,n;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(row,0,sizeof(row));
		memset(line,0,sizeof(line));
		num=0;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				int p;
				scanf("%d",&p);
				row[i]+=p;
				line[j]+=p;
			}
		}
		for(int i=0;i<3;i++)
			scanf("%d",&A[i]);
					//	for(int i=0;i<m;i++)
					//		printf("%d ",line[i]);
					//	for(int j=0;j<n;j++)
					//		printf("%d ",row[j]);
		dfs(0,0,n,row);
		dfs(0,0,m,line);
		printf("%d\n",num);
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int row[55],line[55],num,A[3],ot[5][2],lvl;
void op(int ii[])
{
	int a[3];
	memset(a,0,sizeof(a));
	for(int i=0;i<3;i++)
	{
		for(int j=ot[i][0];j<=ot[i][1];j++)
			a[i]+=ii[j];
	}
	sort(a,a+3);
	for(int i=0;i<3;i++)
		if(a[i]!=A[i])return;
	num++;
	return ;
}

void dfs(int now,int lvl,int len,int ii[])
{
	if(lvl==2&&now<len)
	{
		ot[lvl][0]=now;
		ot[lvl][1]=len-1;
		op(ii);
		return;
	}
	for(int i=now;i<len;i++)
	{
		ot[lvl][0]=now;
		ot[lvl][1]=i;
		dfs(i+1,lvl+1,len,ii);
	}
}
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	int m,n;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(row,0,sizeof(row));
		memset(line,0,sizeof(line));
		num=0;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				int p;
				scanf("%d",&p);
				row[i]+=p;
				line[j]+=p;
			}
		}
		for(int i=0;i<3;i++)
			scanf("%d",&A[i]);
		dfs(0,0,n,row);
		dfs(0,0,m,line);
		printf("%d\n",num);
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int row[55],line[55],num,A[3],ot[5][2],lvl;
void op(int ii[])
{
	int a[3];
	memset(a,0,sizeof(a));
	for(int i=0;i<3;i++)
	{
		for(int j=ot[i][0];j<=ot[i][1];j++)
			a[i]+=ii[j];
	}
	sort(a,a+3);
	for(int i=0;i<3;i++)
		if(a[i]!=A[i])return;
	num++;
	return ;
}

void dfs(int now,int lvl,int len,int ii[])
{
	if(lvl==2&&now<len)
	{
		ot[lvl][0]=now;
		ot[lvl][1]=len-1;
		op(ii);
		return;
	}
	for(int i=now;i<len;i++)
	{
		ot[lvl][0]=now;
		ot[lvl][1]=i;
		dfs(i+1,lvl+1,len,ii);
	}
}
int main()
{
	int m,n;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(row,0,sizeof(row));
		memset(line,0,sizeof(line));
		num=0;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				int p;
				scanf("%d",&p);
				row[i]+=p;
				line[j]+=p;
			}
		}
		for(int i=0;i<3;i++)
			scanf("%d",&A[i]);
		dfs(0,0,n,row);
		dfs(0,0,m,line);
		printf("%d\n",num);
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int row[55],line[55],num,A[3],ot[5][2],lvl;
void op(int ii[])
{
	int a[3];
	memset(a,0,sizeof(a));
	for(int i=0;i<3;i++)
	{
		for(int j=ot[i][0];j<=ot[i][1];j++)
			a[i]+=ii[j];
	}
	sort(a,a+3);
	for(int i=0;i<3;i++)
		if(a[i]!=A[i])return;
	num++;
	return ;
}

void dfs(int now,int lvl,int len,int ii[])
{
	if(lvl==2&&now<len)
	{
		ot[lvl][0]=now;
		ot[lvl][1]=len-1;
		op(ii);
		return;
	}
	for(int i=now;i<len;i++)
	{
		ot[lvl][0]=now;
		ot[lvl][1]=i;
		dfs(i+1,lvl+1,len,ii);
	}
}
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	int m,n;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(row,0,sizeof(row));
		memset(line,0,sizeof(line));
		num=0;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				int p;
				scanf("%d",&p);
				row[i]+=p;
				line[j]+=p;
			}
		}
		for(int i=0;i<3;i++)
			scanf("%d",&A[i]);
		sort(A,A+3);
		dfs(0,0,n,row);
		dfs(0,0,m,line);
		printf("%d\n",num);
	}
	return 0;
}


#include<stdio.h>
int a[60][60];
int run=0;
int row[60],col[60],sumcol[60],sumrow[60];
int main()
{
    FILE *fin,*fout;
    //printf("yeah");
    fin=fopen("input.txt","r+");
    fout = fopen("output.txt","w+");
    int n,m,A,B,C,x,y,z,count=0,all=0,sum;
    fscanf(fin,"%d %d",&n,&m);
    //fprintf(fout,"%d %d",n,m);
    //printf("dsfdsf");
    for(int i=0;i<n;i++) for(int j=0;j<m;j++) fscanf(fin,"%d",&a[i][j]);
    //printf("dfdf");
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++) col[i]+=a[j][i];
        all+=col[i];
        sumcol[i+1]=sumcol[i]+col[i];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++) row[i]+=a[i][j];
        sumrow[i+1]=sumrow[i]+row[i];
    }
    //printf("yeaj");
    fscanf(fin,"%d %d %d",&A,&B,&C);
    if(all!=A+B+C)
    {
        fprintf(fout,"0\n");
        return 0;
    }
    x=A;y=B;z=C;
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(sumrow[i]==x&&sumrow[j]-sumrow[i]==y) count++;
        }
    }
    for(int i=1;i<m;i++) for(int j=i+1;j<m;j++) if(sumcol[i]==x&&sumcol[j]-sumcol[i]==y) count++;
    x=A;y=C;z=B;
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(sumrow[i]==x&&sumrow[j]-sumrow[i]==y) count++;
        }
    }
    for(int i=1;i<m;i++) for(int j=i+1;j<m;j++) if(sumcol[i]==x&&sumcol[j]-sumcol[i]==y) count++;
    x=B;y=A;z=C;
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(sumrow[i]==x&&sumrow[j]-sumrow[i]==y) count++;
        }
    }
    for(int i=1;i<m;i++) for(int j=i+1;j<m;j++) if(sumcol[i]==x&&sumcol[j]-sumcol[i]==y) count++;
    x=B;y=C;z=A;
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(sumrow[i]==x&&sumrow[j]-sumrow[i]==y) count++;
        }
    }
    for(int i=1;i<m;i++) for(int j=i+1;j<m;j++) if(sumcol[i]==x&&sumcol[j]-sumcol[i]==y) count++;
    x=C;y=A;z=B;
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(sumrow[i]==x&&sumrow[j]-sumrow[i]==y) count++;
        }
    }
    for(int i=1;i<m;i++) for(int j=i+1;j<m;j++) if(sumcol[i]==x&&sumcol[j]-sumcol[i]==y) count++;
    x=C;y=B;z=A;
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(sumrow[i]==x&&sumrow[j]-sumrow[i]==y) count++;
        }
    }
    for(int i=1;i<m;i++) for(int j=i+1;j<m;j++) if(sumcol[i]==x&&sumcol[j]-sumcol[i]==y) count++;
    if(x!=y&&y!=z&&z!=x)fprintf(fout,"%d\n",count);
    else if(x==y&&y==z) fprintf(fout,"%d\n",count/6);
    else fprintf(fout,"%d\n",count/2);

    //printf("yeah");
    //for(;;);
    return 0;
}


#include<stdio.h>
int a[60][60];
int run=0;
int row[60],col[60];
int main()
{
    FILE *fin,*fout;
    fin=fopen("input.txt","r+");
    fout = fopen("output.txt","w+");
    int n,m,A,B,C,x,y,z,count=0,all=0,sum;
    fscanf(fin,"%d %d",&n,&m);
    for(int i=0;i<n;i++) for(int j=0;j<m;j++) fscanf(fin,"%d",&a[i][j]);
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++) col[i]+=a[j][i];
        all+=col[i];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++) row[i]+=a[i][j];
    }
    fscanf(fin,"%d %d %d",&A,&B,&C);
    if(all!=A+B+C)
    {
        fprintf(fout,"0\n");
        return 0;
    }
    x=A;y=B;z=C;
    sum=0;run=0;
    while(sum<x)
    {
        sum+=col[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=col[run++];
        }
        if(sum==y)
        {
            count++;
        }
    }
    sum=0;run=0;
    while(sum<x)
    {
        sum+=row[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=row[run++];
        }
        if(sum==y)
        {
            count++;
        }
    }
    x=A;y=C;z=B;
    sum=0;run=0;
    while(sum<x)
    {
        sum+=col[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=col[run++];
        }
        if(sum==y)
        {
            count++;
        }
    }
    sum=0;run=0;
    while(sum<x)
    {
        sum+=row[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=row[run++];
        }
        if(sum==y)
        {
            count++;
        }
    }
    x=B;y=A;z=C;
    sum=0;run=0;
    while(sum<x)
    {
        sum+=col[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=col[run++];
        }
        if(sum==y)
        {
            count++;
        }
    }
    sum=0;run=0;
    while(sum<x)
    {
        sum+=row[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=row[run++];
        }
        if(sum==y)
        {
            count++;
        }
    }
    x=B;y=C;z=A;
    sum=0;run=0;
    while(sum<x)
    {
        sum+=col[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=col[run++];
        }
        if(sum==y)
        {
            count++;
        }
    }
    sum=0;run=0;
    while(sum<x)
    {
        sum+=row[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=row[run++];
        }
        if(sum==y)
        {
            count++;
        }
    }
    x=C;y=A;z=B;
    sum=0;run=0;
    while(sum<x)
    {
        sum+=col[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=col[run++];
        }
        if(sum==y)
        {
            count++;
        }
    }
    sum=0;run=0;
    while(sum<x)
    {
        sum+=row[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=row[run++];
        }
        if(sum==y)
        {
            count++;
        }
    }
    x=C;y=B;z=A;
    sum=0;run=0;
    while(sum<x)
    {
        sum+=col[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=col[run++];
        }
        if(sum==y)
        {
            count++;
        }
    }
    sum=0;run=0;
    while(sum<x)
    {
        sum+=row[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=row[run++];
        }
        if(sum==y)
        {
            count++;
        }
    }
    fprintf(fout,"%d\n",count);

    //printf("yeah");
    //for(;;);
    return 0;
}


#include<stdio.h>
int a[60][60];
int run=0;
int row[60],col[60],sumcol[60],sumrow[60];
int main()
{
    FILE *fin,*fout;
    //printf("yeah");
    fin=fopen("input.txt","r+");
    fout = fopen("output.txt","w+");
    int n,m,A,B,C,x,y,z,count=0,all=0,sum;
    fscanf(fin,"%d %d",&n,&m);
    //fprintf(fout,"%d %d",n,m);
    //printf("dsfdsf");
    for(int i=0;i<n;i++) for(int j=0;j<m;j++) fscanf(fin,"%d",&a[i][j]);
    //printf("dfdf");
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++) col[i]+=a[j][i];
        all+=col[i];
        sumcol[i+1]=sumcol[i]+col[i];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++) row[i]+=a[i][j];
        sumrow[i+1]=sumrow[i]+row[i];
    }
    //printf("yeaj");
    fscanf(fin,"%d %d %d",&A,&B,&C);
    if(all!=A+B+C)
    {
        fprintf(fout,"0\n");
        return 0;
    }
    x=A;y=B;z=C;
    for(int i=0;i<=n;i++)
    {
        for(int j=i;j<=n;j++)
        {
            if(sumrow[i]==x&&sumrow[j]-sumrow[i]==y) count++;
        }
    }
    for(int i=0;i<=m;i++) for(int j=i;j<=m;j++) if(sumcol[i]==x&&sumcol[j]-sumcol[i]==y) count++;
    x=A;y=C;z=B;
    for(int i=0;i<=n;i++)
    {
        for(int j=i;j<=n;j++)
        {
            if(sumrow[i]==x&&sumrow[j]-sumrow[i]==y) count++;
        }
    }
    for(int i=0;i<=m;i++) for(int j=i;j<=m;j++) if(sumcol[i]==x&&sumcol[j]-sumcol[i]==y) count++;
    x=B;y=A;z=C;
    for(int i=0;i<=n;i++)
    {
        for(int j=i;j<=n;j++)
        {
            if(sumrow[i]==x&&sumrow[j]-sumrow[i]==y) count++;
        }
    }
    for(int i=0;i<=m;i++) for(int j=i;j<=m;j++) if(sumcol[i]==x&&sumcol[j]-sumcol[i]==y) count++;
    x=B;y=C;z=A;
    for(int i=0;i<=n;i++)
    {
        for(int j=i;j<=n;j++)
        {
            if(sumrow[i]==x&&sumrow[j]-sumrow[i]==y) count++;
        }
    }
    for(int i=0;i<=m;i++) for(int j=i;j<=m;j++) if(sumcol[i]==x&&sumcol[j]-sumcol[i]==y) count++;
    x=C;y=A;z=B;
    for(int i=0;i<=n;i++)
    {
        for(int j=i;j<=n;j++)
        {
            if(sumrow[i]==x&&sumrow[j]-sumrow[i]==y) count++;
        }
    }
    for(int i=0;i<=m;i++) for(int j=i;j<=m;j++) if(sumcol[i]==x&&sumcol[j]-sumcol[i]==y) count++;
    x=C;y=B;z=A;
    for(int i=0;i<=n;i++)
    {
        for(int j=i;j<=n;j++)
        {
            if(sumrow[i]==x&&sumrow[j]-sumrow[i]==y) count++;
        }
    }
    for(int i=0;i<=m;i++) for(int j=i;j<=m;j++) if(sumcol[i]==x&&sumcol[j]-sumcol[i]==y) count++;
    if(x!=y&&y!=z&&z!=x)fprintf(fout,"%d\n",count);
    else if(x==y&&y==z) fprintf(fout,"%d\n",count/6);
    else fprintf(fout,"%d\n",count/2);

    //printf("yeah");
    //for(;;);
    return 0;
}


#include<stdio.h>
int a[60][60];
int run=0;
int row[60],col[60];
int main()
{
    FILE *fin,*fout;
    //printf("yeah");
    fin=fopen("input.txt","r+");
    fout = fopen("output.txt","w+");
    int n,m,A,B,C,x,y,z,count=0,all=0,sum;
    fscanf(fin,"%d %d",&n,&m);
    //fprintf(fout,"%d %d",n,m);
    //printf("dsfdsf");
    for(int i=0;i<n;i++) for(int j=0;j<m;j++) fscanf(fin,"%d",&a[i][j]);
    //printf("dfdf");
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++) col[i]+=a[j][i];
        all+=col[i];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++) row[i]+=a[i][j];
    }
    //printf("yeaj");
    fscanf(fin,"%d %d %d",&A,&B,&C);
    if(all!=A+B+C)
    {
        fprintf(fout,"0\n");
        return 0;
    }
    x=A;y=B;z=C;
    sum=0;run=0;
    while(sum<x)
    {
        sum+=col[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=col[run++];
        }
        if(sum==y)
        {
            //printf("a");
            count++;
        }
    }
    sum=0;run=0;
    while(sum<x)
    {
        sum+=row[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=row[run++];
        }
        if(sum==y)
        {
           //printf("b");
            count++;
        }
    }
    x=A;y=C;z=B;
    sum=0;run=0;
    while(sum<x)
    {
        sum+=col[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=col[run++];
        }
        if(sum==y)
        {
            //printf("c");
            count++;
        }
    }
    sum=0;run=0;
    while(sum<x)
    {
        sum+=row[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=row[run++];
        }
        if(sum==y)
        {
            //printf("d");
            count++;
        }
    }
    x=B;y=A;z=C;
    sum=0;run=0;
    while(sum<x)
    {
        sum+=col[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=col[run++];
        }
        if(sum==y)
        {
            //printf("e");
            count++;
        }
    }
    sum=0;run=0;
    while(sum<x)
    {
        sum+=row[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=row[run++];
        }
        if(sum==y)
        {
            //printf("f");
            count++;
        }
    }
    x=B;y=C;z=A;
    sum=0;run=0;
    while(sum<x)
    {
        sum+=col[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=col[run++];
        }
        if(sum==y)
        {
            //printf("g");
            count++;
        }
    }
    sum=0;run=0;
    while(sum<x)
    {
        sum+=row[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=row[run++];
        }
        if(sum==y)
        {
            //printf("h");
            count++;
        }
    }
    x=C;y=A;z=B;
    sum=0;run=0;
    while(sum<x)
    {
        sum+=col[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=col[run++];
        }
        if(sum==y)
        {
            //printf("i");
            count++;
        }
    }
    sum=0;run=0;
    while(sum<x)
    {
        sum+=row[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=row[run++];
        }
        if(sum==y)
        {
            //printf("j");
            count++;
        }
    }
    x=C;y=B;z=A;
    sum=0;run=0;
    while(sum<x)
    {
        sum+=col[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=col[run++];
        }
        if(sum==y)
        {
            //printf("k");
            count++;
        }
    }
    sum=0;run=0;
    while(sum<x)
    {
        sum+=row[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=row[run++];
        }
        if(sum==y)
        {
            //printf("l");
            count++;
        }
    }
    if(x!=y&&y!=z&&z!=x)fprintf(fout,"%d\n",count);
    else if(x==y&&y==z) fprintf(fout,"%d\n",count/6);
    else fprintf(fout,"%d\n",count/2);

    //printf("yeah");
    //for(;;);
    return 0;
}


#include<stdio.h>
int a[60][60];
int run=0;
int row[60],col[60];
int main()
{
    FILE *fin,*fout;
    //printf("yeah");
    fin=fopen("input.txt","r+");
    fout = fopen("output.txt","w+");
    int n,m,A,B,C,x,y,z,count=0,all=0,sum;
    fscanf(fin,"%d %d",&n,&m);
    //fprintf(fout,"%d %d",n,m);
    //printf("dsfdsf");
    for(int i=0;i<n;i++) for(int j=0;j<m;j++) fscanf(fin,"%d",&a[i][j]);
    //printf("dfdf");
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++) col[i]+=a[j][i];
        all+=col[i];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++) row[i]+=a[i][j];
    }
    //printf("yeaj");
    fscanf(fin,"%d %d %d",&A,&B,&C);
    if(all!=A+B+C)
    {
        fprintf(fout,"0\n");
        return 0;
    }
    x=A;y=B;z=C;
    sum=0;run=0;
    while(sum<x)
    {
        sum+=col[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=col[run++];
        }
        if(sum==y)
        {
            //printf("a");
            count++;
        }
    }
    sum=0;run=0;
    while(sum<x)
    {
        sum+=row[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=row[run++];
        }
        if(sum==y)
        {
           //printf("b");
            count++;
        }
    }
    x=A;y=C;z=B;
    sum=0;run=0;
    while(sum<x)
    {
        sum+=col[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=col[run++];
        }
        if(sum==y)
        {
            //printf("c");
            count++;
        }
    }
    sum=0;run=0;
    while(sum<x)
    {
        sum+=row[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=row[run++];
        }
        if(sum==y)
        {
            //printf("d");
            count++;
        }
    }
    x=B;y=A;z=C;
    sum=0;run=0;
    while(sum<x)
    {
        sum+=col[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=col[run++];
        }
        if(sum==y)
        {
            //printf("e");
            count++;
        }
    }
    sum=0;run=0;
    while(sum<x)
    {
        sum+=row[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=row[run++];
        }
        if(sum==y)
        {
            //printf("f");
            count++;
        }
    }
    x=B;y=C;z=A;
    sum=0;run=0;
    while(sum<x)
    {
        sum+=col[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=col[run++];
        }
        if(sum==y)
        {
            //printf("g");
            count++;
        }
    }
    sum=0;run=0;
    while(sum<x)
    {
        sum+=row[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=row[run++];
        }
        if(sum==y)
        {
            //printf("h");
            count++;
        }
    }
    x=C;y=A;z=B;
    sum=0;run=0;
    while(sum<x)
    {
        sum+=col[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=col[run++];
        }
        if(sum==y)
        {
            //printf("i");
            count++;
        }
    }
    sum=0;run=0;
    while(sum<x)
    {
        sum+=row[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=row[run++];
        }
        if(sum==y)
        {
            //printf("j");
            count++;
        }
    }
    x=C;y=B;z=A;
    sum=0;run=0;
    while(sum<x)
    {
        sum+=col[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=col[run++];
        }
        if(sum==y)
        {
            //printf("k");
            count++;
        }
    }
    sum=0;run=0;
    while(sum<x)
    {
        sum+=row[run++];
    }
    if(sum==x)
    {
        sum=0;
        while(sum<y)
        {
            sum+=row[run++];
        }
        if(sum==y)
        {
            //printf("l");
            count++;
        }
    }
    if(x!=y&&y!=z&&z!=x)fprintf(fout,"%d\n",count);
    else if(x==y&&y==z) fprintf(fout,"%d\n",count/6);
    else fprintf(fout,"%d\n",count/3);

    //printf("yeah");
    //for(;;);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<fstream>
#define inf 1000000000
using namespace std;
int ho[51];
int ve[51];
int sm[51];
int vs[51];
int main()
{
    int n,m;
    int a,b,c;
    int aa,bb,cc;
    scanf("%d %d",&n,&m);
    int i,j,jj;
    int ans=0;
    int x;
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            scanf("%d",&x);
            ho[j]+=x;
            ve[i]+=x;
        }
    vs[0]=ve[0];
    sm[0]=ho[0];
    for(i=1;i<n;i++)vs[i]=vs[i-1]+ve[i];
    for(i=1;i<m;i++)sm[i]=sm[i-1]+ho[i];
    scanf("%d %d %d",&a,&b,&c);
    int af,bf,cf;
    af=min(a,min(b,c));
    bf=max(a,max(b,c));
     cf=a+b+c-min(a,min(b,c))-max(a,max(b,c));
    for(i=1;i<n;i++)
        for(j=i+1;j<n;j++)
        {
           aa=vs[i-1]; bb=vs[j-1]-vs[i-1]; cc=vs[n-1]-vs[j-1];
       if(af==min(aa,min(bb,cc))&&bf==max(aa,max(bb,cc))&&cf==vs[n-1]-min(aa,min(bb,cc))-max(aa,max(bb,cc)))ans++;
        }
    for(i=1;i<m;i++)
        for(j=i+1;j<m;j++)
        {
            aa=sm[i-1]; bb=sm[j-1]-sm[i-1]; cc=sm[m-1]-sm[j-1];
        if(af==min(aa,min(bb,cc))&&bf==max(aa,max(bb,cc))&&cf==vs[n-1]-min(aa,min(bb,cc))-max(aa,max(bb,cc)))ans++;
        }
    printf("%d\n",ans);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<fstream>
#define inf 1000000000
using namespace std;
int ho[105];
int ve[105];
int sm[105];
int vs[105];
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int n,m;
    int a,b,c;
    int aa,bb,cc;
    scanf("%d %d",&n,&m);
    int i,j,jj;
    int ans=0;
    int x;
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            scanf("%d",&x);
            ho[j]+=x;
            ve[i]+=x;
        }
    vs[0]=ve[0];
    sm[0]=ho[0];
    for(i=1;i<n;i++)vs[i]=vs[i-1]+ve[i];
    for(i=1;i<m;i++)sm[i]=sm[i-1]+ho[i];
    scanf("%d %d %d",&a,&b,&c);
    for(i=1;i<n;i++)
        for(j=i+1;j<n;j++)
        {
           aa=vs[i-1]; bb=vs[j-1]-vs[i-1]; cc=vs[n-1]-vs[j-1];
       if(min(a,min(b,c))==min(aa,min(bb,cc))&&max(a,max(b,c))==max(aa,max(bb,cc))&&a+b+c-min(a,min(b,c))-max(a,max(b,c))==vs[n-1]-min(aa,min(bb,cc))-max(aa,max(bb,cc)))ans++;
        }
    for(i=1;i<m;i++)
        for(j=i+1;j<m;j++)
        {
            aa=sm[i-1]; bb=sm[j-1]-sm[i-1]; cc=sm[m-1]-sm[j-1];
        if(min(a,min(b,c))==min(aa,min(bb,cc))&&max(a,max(b,c))==max(aa,max(bb,cc))&&a+b+c-min(a,min(b,c))-max(a,max(b,c))==vs[n-1]-min(aa,min(bb,cc))-max(aa,max(bb,cc)))ans++;
        }
    printf("%d\n",ans);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<fstream>
#define inf 1000000000
using namespace std;
int ho[105];
int ve[105];
int sm[105];
int vs[105];
int main()
{
    int n,m;
    int a,b,c;
    int aa,bb,cc;
    scanf("%d %d",&n,&m);
    int i,j,jj;
    int ans=0;
    int x;
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            scanf("%d",&x);
            ho[j]+=x;
            ve[i]+=x;
        }
    vs[0]=ve[0];
    sm[0]=ho[0];
    for(i=1;i<n;i++)vs[i]=vs[i-1]+ve[i];
    for(i=1;i<m;i++)sm[i]=sm[i-1]+ho[i];
    scanf("%d %d %d",&a,&b,&c);
    int af,bf,cf;
    af=min(a,min(b,c));
    bf=max(a,max(b,c));
     cf=a+b+c-min(a,min(b,c))-max(a,max(b,c));
    for(i=1;i<n;i++)
        for(j=i+1;j<n;j++)
        {
           aa=vs[i-1]; bb=vs[j-1]-vs[i-1]; cc=vs[n-1]-vs[j-1];
       if(af==min(aa,min(bb,cc))&&bf==max(aa,max(bb,cc))&&cf==vs[n-1]-min(aa,min(bb,cc))-max(aa,max(bb,cc)))ans++;
        }
    for(i=1;i<m;i++)
        for(j=i+1;j<m;j++)
        {
            aa=sm[i-1]; bb=sm[j-1]-sm[i-1]; cc=sm[m-1]-sm[j-1];
        if(af==min(aa,min(bb,cc))&&bf==max(aa,max(bb,cc))&&cf==vs[n-1]-min(aa,min(bb,cc))-max(aa,max(bb,cc)))ans++;
        }
    printf("%d\n",ans);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<fstream>
#define inf 1000000000
using namespace std;
int ho[51];
int ve[51];
int sm[51];
int vs[51];
int main()
{
    int n,m;
    int a,b,c;
    int aa,bb,cc;
    scanf("%d %d",&n,&m);
    int i,j,jj;
    int ans=0;
    int x;
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            scanf("%d",&x);
            ho[j]+=x;
            ve[i]+=x;
        }
    vs[0]=ve[0];
    sm[0]=ho[0];
    for(i=1;i<n;i++)vs[i]=vs[i-1]+ve[i];
    for(i=1;i<m;i++)sm[i]=sm[i-1]+ho[i];
    scanf("%d %d %d",&a,&b,&c);
    int ac,bc,cc;
    af=min(a,min(b,c));
    bf=max(a,max(b,c));
     cf=a+b+c-min(a,min(b,c))-max(a,max(b,c));
    for(i=1;i<n;i++)
        for(j=i+1;j<n;j++)
        {
           aa=vs[i-1]; bb=vs[j-1]-vs[i-1]; cc=vs[n-1]-vs[j-1];
       if(af==min(aa,min(bb,cc))&&bf==max(aa,max(bb,cc))&&cf==vs[n-1]-min(aa,min(bb,cc))-max(aa,max(bb,cc)))ans++;
        }
    for(i=1;i<m;i++)
        for(j=i+1;j<m;j++)
        {
            aa=sm[i-1]; bb=sm[j-1]-sm[i-1]; cc=sm[m-1]-sm[j-1];
        if(af==min(aa,min(bb,cc))&&bf==max(aa,max(bb,cc))&&cf==vs[n-1]-min(aa,min(bb,cc))-max(aa,max(bb,cc)))ans++;
        }
    printf("%d\n",ans);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<fstream>
#define inf 1000000000
using namespace std;
int ho[105];
int ve[105];
int sm[105];
int vs[105];
int main()
{
    int n,m;
    int a,b,c;
    int aa,bb,cc;
    scanf("%d %d",&n,&m);
    int i,j,jj;
    int ans=0;
    int x;
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            scanf("%d",&x);
            ho[j]+=x;
            ve[i]+=x;
        }
    vs[0]=ve[0];
    sm[0]=ho[0];
    for(i=1;i<n;i++)vs[i]=vs[i-1]+ve[i];
    for(i=1;i<m;i++)sm[i]=sm[i-1]+ho[i];
    scanf("%d %d %d",&a,&b,&c);
    for(i=1;i<n;i++)
        for(j=i+1;j<n;j++)
        {
           aa=vs[i-1]; bb=vs[j-1]-vs[i-1]; cc=vs[n-1]-vs[j-1];
       if(min(a,min(b,c))==min(aa,min(bb,cc))&&max(a,max(b,c))==max(aa,max(bb,cc))&&a+b+c-min(a,min(b,c))-max(a,max(b,c))==vs[n-1]-min(aa,min(bb,cc))-max(aa,max(bb,cc)))ans++;
        }
    for(i=1;i<m;i++)
        for(j=i+1;j<m;j++)
        {
            aa=sm[i-1]; bb=sm[j-1]-sm[i-1]; cc=sm[m-1]-sm[j-1];
        if(min(a,min(b,c))==min(aa,min(bb,cc))&&max(a,max(b,c))==max(aa,max(bb,cc))&&a+b+c-min(a,min(b,c))-max(a,max(b,c))==vs[n-1]-min(aa,min(bb,cc))-max(aa,max(bb,cc)))ans++;
        }
    printf("%d\n",ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <map>

using namespace std;

int n, m;
int a[100][100];

int u, v, p;

int h[100], w[100];

int sumcol(int num) {

    int sum = 0;
    for (int i = 0; i < n; i++)
        sum += a[i][num];

    return sum;

}

int sumrow(int num) {

    int sum = 0;
    for (int i = 0; i < n; i++)
        sum += a[num][i];

    return sum;

}

int main() {

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }

    cin >> u >> v >> p;

    h[0] = sumcol(0);
    for (int i = 1; i < m; i++) {
        h[i] = h[i - 1] + sumcol(i);
    }
    if (h[m - 1] != u + v + p) {
        cout << 0;
        return 0;
    }

    w[0] = sumrow(0);
    for (int i = 1; i < n; i++) {
        w[i] = w[i - 1] + sumrow(i);
    }

    int cnt = 0;
    for (int i = 0; i < n - 2; i++)
        for (int j = i + 1; j < n - 1; j++) {
            if (w[i] == u && w[j] == u + v)
                cnt++;
            if (w[i] == u && w[j] == u + p)
                cnt++;
            if (w[i] == v && w[j] == u + v)
                cnt++;
            if (w[i] == v && w[j] == v + p)
                cnt++;
            if (w[i] == p && w[j] == u + p)
                cnt++;
            if (w[i] == p && w[j] == v + p)
                cnt++;
        }

    for (int i = 0; i < m - 2; i++)
        for (int j = i + 1; j < m - 1; j++) {
            if (h[i] == u && h[j] == u + v)
                cnt++;
            if (h[i] == u && h[j] == u + p)
                cnt++;
            if (h[i] == v && h[j] == u + v)
                cnt++;
            if (h[i] == v && h[j] == v + p)
                cnt++;
            if (h[i] == p && h[j] == u + p)
                cnt++;
            if (h[i] == p && h[j] == v + p)
                cnt++;
        }

    cout << cnt << endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <map>

using namespace std;

int n, m;
int a[100][100];

int u, v, p;

int h[100], w[100];

int sumcol(int num) {

    int sum = 0;
    for (int i = 0; i < n; i++)
        sum += a[i][num];

    return sum;

}

int sumrow(int num) {

    int sum = 0;
    for (int i = 0; i < n; i++)
        sum += a[num][i];

    return sum;

}

int main() {

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }

    cin >> u >> v >> p;

    h[0] = sumcol(0);
    for (int i = 1; i < m; i++) {
        h[i] = h[i - 1] + sumcol(i);
    }
    if (h[n - 1] != u + v + p) {
        cout << 0;
        return 0;
    }

    w[0] = sumrow(0);
    for (int i = 1; i < n; i++) {
        w[i] = w[i - 1] + sumrow(i);
    }

    int cnt = 0;
    for (int i = 0; i < n - 2; i++)
        for (int j = i + 1; j < n - 1; j++) {
            if ((w[i] == u && w[j] == u + v) || (w[i] == u && w[j] == u + p) || (w[i] == v && w[j] == u + v) || (w[i] == v && w[j] == v + p) || (w[i] == p && w[j] == u + p) || (w[i] == p && w[j] == v + p))
                cnt++;
        }

    for (int i = 0; i < m - 2; i++)
        for (int j = i + 1; j < m - 1; j++) {
            if ((h[i] == u && h[j] == u + v) || (h[i] == u && h[j] == u + p) || (h[i] == v && h[j] == u + v) || (h[i] == v && h[j] == v + p) || (h[i] == p && h[j] == u + p) || (h[i] == p && h[j] == v + p))
                cnt++;
        }

    cout << cnt << endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <map>

using namespace std;

int n, m;
int a[100][100];

int u, v, p;

int h[100], w[100];

int sumcol(int num) {

    int sum = 0;
    for (int i = 0; i < n; i++)
        sum += a[i][num];

    return sum;

}

int sumrow(int num) {

    int sum = 0;
    for (int i = 0; i < n; i++)
        sum += a[num][i];

    return sum;

}

int main() {

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }

    cin >> u >> v >> p;

    h[0] = sumcol(0);
    for (int i = 1; i < m; i++) {
        h[i] = h[i - 1] + sumcol(i);
    }
    if (h[m - 1] != u + v + p) {
        cout << 0;
        return 0;
    }

    w[0] = sumrow(0);
    for (int i = 1; i < n; i++) {
        w[i] = w[i - 1] + sumrow(i);
    }

    int cnt = 0;
    for (int i = 0; i < n - 2; i++)
        for (int j = i + 1; j < n - 1; j++) {
            if ((w[i] == u && w[j] == u + v) || (w[i] == u && w[j] == u + p) || (w[i] == v && w[j] == u + v) || (w[i] == v && w[j] == v + p) || (w[i] == p && w[j] == u + p) || (w[i] == p && w[j] == v + p))
                cnt++;
        }

    for (int i = 0; i < m - 2; i++)
        for (int j = i + 1; j < m - 1; j++) {
            if ((h[i] == u && h[j] == u + v) || (h[i] == u && h[j] == u + p) || (h[i] == v && h[j] == u + v) || (h[i] == v && h[j] == v + p) || (h[i] == p && h[j] == u + p) || (h[i] == p && h[j] == v + p))
                cnt++;
        }

    cout << cnt << endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <map>

using namespace std;

int n, m;
int a[100][100];

int u, v, p;

int h[100], w[100];

int sumcol(int num) {

    int sum = 0;
    for (int i = 0; i < n; i++)
        sum += a[i][num];

    return sum;

}

int sumrow(int num) {

    int sum = 0;
    for (int i = 0; i < n; i++)
        sum += a[num][i];

    return sum;

}

int main() {

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }

    cin >> u >> v >> p;

    h[0] = sumcol(0);
    for (int i = 1; i < m; i++) {
        h[i] = h[i - 1] + sumcol(i);
    }

    w[0] = sumrow(0);
    for (int i = 1; i < n; i++) {
        w[i] = w[i - 1] + sumrow(i);
    }

    int cnt = 0;
    for (int i = 0; i < n - 1; i++)
        for (int j = i + 1; j < n - 1; j++) {
            if ((w[i] == u && w[j] == u + v) || (w[i] == u && w[j] == u + p) || (w[i] == v && w[j] == u + v) || (w[i] == v && w[j] == v + p) || (w[i] == p && w[j] == u + p) || (w[i] == p && w[j] == v + p))
                cnt++;
        }

    for (int i = 0; i < m - 1; i++)
        for (int j = i + 1; j < m - 1; j++) {
            if ((h[i] == u && h[j] == u + v) || (h[i] == u && h[j] == u + p) || (h[i] == v && h[j] == u + v) || (h[i] == v && h[j] == v + p) || (h[i] == p && h[j] == u + p) || (h[i] == p && h[j] == v + p))
                cnt++;
        }

    cout << cnt << endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <map>

using namespace std;

int n, m;
long long a[500][500];

long long u, v, p;

long long h[100], w[100];

long long sumcol(int num) {

    long long sum = 0;
    for (int i = 0; i < n; i++)
        sum += a[i][num];

    return sum;

}

long long sumrow(int num) {

    long long sum = 0;
    for (int i = 0; i < m; i++)
        sum += a[num][i];

    return sum;

}

int main() {

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }

    cin >> u >> v >> p;

    h[0] = sumcol(0);
    for (int i = 1; i < m; i++) {
        h[i] = h[i - 1] + sumcol(i);
    }
    if (h[m - 1] != u + v + p) {
        cout << 0;
        return 0;
    }

    w[0] = sumrow(0);
    for (int i = 1; i < n; i++) {
        w[i] = w[i - 1] + sumrow(i);
    }

    int cnt = 0;
    for (int i = 0; i < n - 2; i++)
        for (int j = i + 1; j < n - 1; j++) {
            if ((w[i] == u && w[j] == u + v) || (w[i] == u && w[j] == u + p) || (w[i] == v && w[j] == u + v) || (w[i] == v && w[j] == v + p) || (w[i] == p && w[j] == u + p) || (w[i] == p && w[j] == v + p))
                cnt++;
        }

    for (int i = 0; i < m - 2; i++)
        for (int j = i + 1; j < m - 1; j++) {
            if ((h[i] == u && h[j] == u + v) || (h[i] == u && h[j] == u + p) || (h[i] == v && h[j] == u + v) || (h[i] == v && h[j] == v + p) || (h[i] == p && h[j] == u + p) || (h[i] == p && h[j] == v + p))
                cnt++;
        }

    cout << cnt << endl;

    return 0;
}


#include<iostream>
#include<fstream>
#include<string>
using namespace std;

int Cutsecond(int Div[],int i,int n,int k1,int k2)
{
    int temp=0,s=0;
    while(i<n)
    {
        temp+=Div[i];
        if(temp==k1)
        {
            if(i!=n-1)
            s++;
        }
        if(temp==k2 && k1!=k2)
        {
            if(i!=n-1)
            s++;
        }
        if(temp>k2)break;
        i++;
    }
    return s;
}
int Cutfirst(int Div[],int n,int ton[])
{
    int temp=0,s=0;
    for(int i=0;i<n;i++)
    {
        temp+=Div[i];
        if(temp==ton[0])
        {s+=Cutsecond(Div,i+1,n,ton[1],ton[2]);}
        if(temp==ton[1] && ton[0]!=ton[1])
        {s+=Cutsecond(Div,i+1,n,ton[0],ton[2]);}
        if(temp==ton[2] && ton[2]!=ton[1] && ton[2]!=ton[0])
        {s+=Cutsecond(Div,i+1,n,ton[0],ton[1]);}
        if(temp>ton[2])break;
    }
    return s;
}
int Cut(int Row[],int n,int Clo[],int m,int ton[])
{
    int s;
    s=Cutfirst(Row,n,ton)+Cutfirst(Clo,m,ton);
    return s;
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int n,m;
    cin>>n>>m;
    int k;
    int Row[50],Clo[50];
    memset(Row,0,sizeof(Row));
    memset(Clo,0,sizeof(Clo));
    int i,j;
    for(i=0;i<n;i++)
    for(j=0;j<m;j++)
    {
        cin>>k;
        Row[i]+=k;
        Clo[j]+=k;
    }

    int ton[3];
    cin>>ton[0]>>ton[1]>>ton[2];
    for(i=0;i<3;i++)
    for(j=i+1;j<3;j++)
    {
        if(ton[i]>ton[j])
        {
            k=ton[i];
            ton[i]=ton[j];
            ton[j]=k;
        }
    }
    int s;

    s=Cut(Row,n,Clo,m,ton);
    cout<<s<<endl;
    return 0;
}


#include<iostream>
#include<fstream>
#include<cstring>
using namespace std;

int Cutsecond(double Div[],int i,int n,int k1,int k2)
{
    int s=0;
    double temp=0;
    while(i<n)
    {
        temp+=Div[i];
        if(temp==k1)
        {
            if(i!=n-1)
            s++;
        }
        if(temp==k2 && k1!=k2)
        {
            if(i!=n-1)
            s++;
        }
        if(temp>k2)break;
        i++;
    }
    return s;
}
int Cutfirst(double Div[],int n,int ton[])
{
    int s=0;
    double temp=0;
    for(int i=0;i<n;i++)
    {
        temp+=Div[i];
        if(temp==ton[0])
        {s+=Cutsecond(Div,i+1,n,ton[1],ton[2]);}
        if(temp==ton[1] && ton[0]!=ton[1])
        {s+=Cutsecond(Div,i+1,n,ton[0],ton[2]);}
        if(temp==ton[2] && ton[2]!=ton[1] && ton[2]!=ton[0])
        {s+=Cutsecond(Div,i+1,n,ton[0],ton[1]);}
        if(temp>ton[2])break;
    }
    return s;
}
int Cut(double Row[],int n,double Clo[],int m,int ton[])
{
    int s;
    s=Cutfirst(Row,n,ton)+Cutfirst(Clo,m,ton);
    return s;
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int n,m;
    cin>>n>>m;
    int k;
    double Row[50],Clo[50];
    memset(Row,0,sizeof(Row));
    memset(Clo,0,sizeof(Clo));
    int i,j;
    for(i=0;i<n;i++)
    for(j=0;j<m;j++)
    {
        cin>>k;
        Row[i]+=k;
        Clo[j]+=k;
    }

    int ton[3];
    cin>>ton[0]>>ton[1]>>ton[2];
    for(i=0;i<3;i++)
    for(j=i+1;j<3;j++)
    {
        if(ton[i]>ton[j])
        {
            k=ton[i];
            ton[i]=ton[j];
            ton[j]=k;
        }
    }
    int s;

    s=Cut(Row,n,Clo,m,ton);
    cout<<s<<endl;
    return 0;
}


#include<iostream>
#include<fstream>
#include<cstring>
using namespace std;

int Cutsecond(double Div[],int i,int n,int k1,int k2)
{
    int s=0;
    double temp=0;
    while(i<n)
    {
        temp+=Div[i];
        if(temp==k1)
        {
            double temp1=0;
            for(int j=i+1;j<n;j++)
            {temp1+=Div[j];}
            if(temp1==k2);
            s++;
        }
        if(temp==k2 && k1!=k2)
        {
            double temp1=0;
            for(int j=i+1;j<n;j++)
            {temp1+=Div[j];}
            if(temp1==k1);
            s++;
        }
        if(temp>k2)break;
        i++;
    }
    return s;
}
int Cutfirst(double Div[],int n,int ton[])
{
    int s=0;
    double temp=0;
    for(int i=0;i<n;i++)
    {
        temp+=Div[i];
        if(temp==ton[0])
        {s+=Cutsecond(Div,i+1,n,ton[1],ton[2]);}
        if(temp==ton[1] && ton[0]!=ton[1])
        {s+=Cutsecond(Div,i+1,n,ton[0],ton[2]);}
        if(temp==ton[2] && ton[2]!=ton[1] && ton[2]!=ton[0])
        {s+=Cutsecond(Div,i+1,n,ton[0],ton[1]);}
        if(temp>ton[2])break;
    }
    return s;
}
int Cut(double Row[],int n,double Clo[],int m,int ton[])
{
    int s;
    s=Cutfirst(Row,n,ton)+Cutfirst(Clo,m,ton);
    return s;
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int n,m;
    cin>>n>>m;
    int k;
    double Row[50],Clo[50];
    memset(Row,0,sizeof(Row));
    memset(Clo,0,sizeof(Clo));
    int i,j;
    for(i=0;i<n;i++)
    for(j=0;j<m;j++)
    {
        cin>>k;
        Row[i]+=k;
        Clo[j]+=k;
    }

    int ton[3];
    cin>>ton[0]>>ton[1]>>ton[2];
    for(i=0;i<3;i++)
    for(j=i+1;j<3;j++)
    {
        if(ton[i]>ton[j])
        {
            k=ton[i];
            ton[i]=ton[j];
            ton[j]=k;
        }
    }
    int s;

    s=Cut(Row,n,Clo,m,ton);
    cout<<s<<endl;
    return 0;
}


#include <iostream>
#include<fstream>
using namespace std;

int Cut(int Div[],int n,int ton[])
{
    if(n<3)return 0;
    int s=0,temp=0,temp1;
    for(int i=0;i<n;i++)
    {
        temp+=Div[i];
        if(temp==ton[0])
        {
            temp1=0;
            for(int j=i+1;j<n;j++)
            {
                temp1+=Div[j];
                if(temp1==ton[1])
                {
                    if(j<n-1)
                    s++;
                }
                if(temp1==ton[2] && ton[1]!=ton[2])
                {if(j<n-1)s++;break;}
                if(temp1>=ton[2])break;
            }
        }
        if(temp==ton[1] && ton[0]!=ton[1])
        {
            temp1=0;
            for(int j=i+1;j<n;j++)
            {
                temp1+=Div[j];
                if(temp1==ton[0])if(j<n-1)s++;
                if(temp1==ton[2]){if(j<n-1)s++;break;}
                if(temp1>=ton[2])break;
            }
        }
        if(temp==ton[2] && ton[2]!=ton[1])
        {
            temp1=0;
            for(int j=i+1;j<n;j++)
            {
                temp1+=Div[j];
                if(temp1==ton[0])if(j<n-1)s++;
                if(temp1==ton[1]&& ton[1]!=ton[0]){if(j<n-1)s++;break;}
                if(temp1>=ton[1])break;
            }
        }
        if(temp>=ton[2])break;
    }
    return s;
}
int main()
{
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
    int n,m,i,j,k;
    int*Row;
    int*Clo;
    cin>>n>>m;
    Row=new int[n];
    Clo=new int[m];
    for(i=0;i<n;i++)
        Row[i]=0;
    for(i=0;i<m;i++)
        Clo[i]=0;
    for(i=0;i<n;i++)
    {
    for(j=0;j<m;j++)
    {
        cin>>k;
        Row[i]+=k;
        Clo[j]+=k;
    }
    }
    int ton[3];
    cin>>ton[0]>>ton[1]>>ton[2];
    for(i=0;i<3;i++)
    {
        for(j=i+1;j<3;j++)
        {
            if(ton[i]>ton[j])
            {
                k=ton[i];
                ton[i]=ton[j];
                ton[j]=k;
            }
        }
    }
    int s=Cut(Row,n,ton)+Cut(Clo,m,ton);
    cout<<s<<endl;
    return 0;
}


#include<iostream>
#include<fstream>
#include<cstring>
using namespace std;

int Cutsecond(int Div[],int i,int n,int k1,int k2)
{
    int temp=0,s=0;
    while(i<n)
    {
        temp+=Div[i];
        if(temp==k1)
        {
            if(i!=n-1)
            s++;
        }
        if(temp==k2 && k1!=k2)
        {
            if(i!=n-1)
            s++;
        }
        if(temp>k2)break;
        i++;
    }
    return s;
}
int Cutfirst(int Div[],int n,int ton[])
{
    int temp=0,s=0;
    for(int i=0;i<n;i++)
    {
        temp+=Div[i];
        if(temp==ton[0])
        {s+=Cutsecond(Div,i+1,n,ton[1],ton[2]);}
        if(temp==ton[1] && ton[0]!=ton[1])
        {s+=Cutsecond(Div,i+1,n,ton[0],ton[2]);}
        if(temp==ton[2] && ton[2]!=ton[1] && ton[2]!=ton[0])
        {s+=Cutsecond(Div,i+1,n,ton[0],ton[1]);}
        if(temp>ton[2])break;
    }
    return s;
}
int Cut(int Row[],int n,int Clo[],int m,int ton[])
{
    int s;
    s=Cutfirst(Row,n,ton)+Cutfirst(Clo,m,ton);
    return s;
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int n,m;
    cin>>n>>m;
    int k;
    int Row[50],Clo[50];
    memset(Row,0,sizeof(Row));
    memset(Clo,0,sizeof(Clo));
    int i,j;
    for(i=0;i<n;i++)
    for(j=0;j<m;j++)
    {
        cin>>k;
        Row[i]+=k;
        Clo[j]+=k;
    }

    int ton[3];
    cin>>ton[0]>>ton[1]>>ton[2];
    for(i=0;i<3;i++)
    for(j=i+1;j<3;j++)
    {
        if(ton[i]>ton[j])
        {
            k=ton[i];
            ton[i]=ton[j];
            ton[j]=k;
        }
    }
    int s;

    s=Cut(Row,n,Clo,m,ton);
    cout<<s<<endl;
    return 0;
}