#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll t[100][100] ; ll RAM ;
ll k  ;
void printArr(ll a[], ll n)
{
    vector <ll> ye ; 
    ye.push_back(1);
	for (ll i = 0; i < n; i++)
	{ye.push_back(a[i]);
	//	cout << a[i] << " ";
	}
	ye.push_back(1);
	//printf("\n");
	ll cost = 0 ;
	ll p = ye.size() ; 
	ll i = 0 ; 
	while(i<=p-2)
	{
	    ll x = ye[i] ; 
	    ll y = ye[i+1] ; 
	    cost = cost + t[x][y] ; 
	    i++;
	}
	
	if(cost==k)
	{
	    RAM++;
	}
	
	
}

// Generating permutation using Heap Algorithm
void heapPermutation(ll a[], ll size, ll n)
{
	// if size becomes 1 then prints the obtained
	// permutation
	if (size == 1) 
	{
		printArr(a, n);
		return;
	}

	for (ll i = 0; i < size; i++) 
	{
		heapPermutation(a, size - 1, n);

		// if size is odd, swap 0th i.e (first) and 
		// (size-1)th i.e (last) element
		if (size % 2 == 1)
			swap(a[0], a[size - 1]);

		// If size is even, swap ith and 
		// (size-1)th i.e (last) element
		else
			swap(a[i], a[size - 1]);
	}
}

int main()
{
    ll n ; 
    cin>>n; cin>>k ;
    ll a[n] ; 
    ll i = 0 ;
    while(i<=n-1)
    {
        a[i]=i+2;
        
i++;        
    }
    
    ll j ; 
    i=1;
    while(i<=n)
    {
        j=1;
        while(j<=n)
        {
            cin>>t[i][j]  ;
            j++;
        }
        
        i++;
    }
	heapPermutation(a, n-1, n-1);
	cout<<RAM ; 
	return 0;
}

#include<bits/stdc++.h>

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;


int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int n,k;
    cin>>n>>k;
    vector<vector<int>> t(n,vector<int>(n));
    for(int i=0;i<n;++i)for(int j=0;j<n;++j){
        cin>>t[i][j];
    }
    vector<int> route(n-1);
    for(int i=0;i<n-1;++i)route[i] = i+1;
    int ret = 0;
    do{
        ll sum = 0;
        sum += t[0][route[0]];
        for(int i=0;i<n-2;++i){
            sum += t[route[i]][route[i+1]];
        }
        sum += t[route[n-2]][0];
        if(sum == k){
            ret ++;
        }
    }while(next_permutation(route.begin(),route.end()));
    cout << ret << endl;
    return 0;
    
}