///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           node(a,b,c)                 mp(mp(a,b),c)
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=12;
int a[M][M];
 main()

{
    fast
    int n,k;
    cin>>n>>k;
    f(i,1,n)
    {
        f(j,1,n)
        {
            cin>>a[i][j];
        }
    }
    int ses=0;
    vector<int>vec;
    f(i,2,n)vec.pb(i);
    sort(vec.begin(),vec.end());
    do
    {
       int tym=a[1][vec[0]]+a[vec[n-2]][1];
       int sz=n-1;
       for(int i=1;i<sz;i++)
       {
           int x=vec[i-1];
           int y=vec[i];
           tym+=(a[x][y]);
       }

       if(tym==k)ses++;

    }while(next_permutation(vec.begin(),vec.end()));

    cout<<ses<<"\n";
    return 0;

}




































#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;

int main() {
    int N,K; cin>>N>>K;
    vector<vector<ll>> T(N,vector<ll>(N));
    for (int i = 0; i < N; i++){
        for (int j = 0; j < N; j++){
            cin>>T[i][j];
        }
    }
    vi v;
    for (int i = 1; i < N; i++)v.push_back(i);
    int ans=0;
    do{
        ll tmp=0;
        tmp+=T[0][v[0]];
        for (int i = 0; i < N-2; i++){
            tmp+=T[v[i]][v[i+1]];
        }
        tmp+=T[v[N-2]][0];
        if(tmp==K)ans++;
    }while(next_permutation(v.begin(),v.end()));
    cout<<ans<<endl;
}