#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n);  for(auto& a : v) init(a, x, m...); }

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    int n, t;
    cin >> n >> t;
    vector<vector<int>> T;
    init(T, 0, n, n);
    FOR(i, n) FOR(j, n) cin >> T[i][j];

    int cnt = 0;
    vector<int> v(n);
    iota(v.begin(), v.end(), 0);
    do{
        if (v[0] != 0) break;
        ll time = 0;
        FOR(i, n-1)
            time += T[v[i]][v[i+1]];
        time += T[v[n-1]][0];
        cnt += time == t;
    }while(next_permutation(v.begin(), v.end()));
    cout << cnt << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll 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.at(i).at(j);
		}
	}
	vector<int> perm(N - 1);
	ll count = 0;
	ll time;
	for(int i = 0; i < N - 1; i++){
	       	perm.at(i) = i + 1;
	}
	do{
		time = T.at(0).at(perm.at(0));
		for(int i = 0; i < N - 2; i++){
			time += T.at(perm.at(i)).at(perm.at(i + 1));
		}
		time += T.at(perm.at(N - 2)).at(0);
		if(time == K) count++;
	}while(next_permutation(perm.begin(),perm.end()));
	cout << count << endl;
}
