// #pragma GCC optimise ("O1")
#include<bits/stdc++.h>
using namespace std;
#define ll           int
#define rep(i,j,n)   for(ll i=j;i<n;i++)
#define scn(a)       scanf("%d",&a)
#define scns(a,b)    scanf("%d %d",&a,&b)
#define print(a)     printf("%0.10lf",a)
#define vec          vector<ll>
#define pb           push_back    
#define pairs        pair<ll,ll>
#define f            first
#define s            second
#define all(v)       v.begin(),v.end()
#define srt(v)       sort(v.begin(),v.end())
#define read(a)       for(auto &it:a) cin>>it;
#define write(a)       for(auto it:a) cout<<it<<" ";
#define mem(a,b)     memset(a,b,sizeof(a))
#define nl           printf("\n")
#define inf          1e9
#define zer          INT_MIN
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int N=2e3+5;


int main()
{
  int t=1; 
  // cin>>t;
  while(t--)
  {
    int n,k; scns(n,k);
    int cost[n+5][n+5];

    rep(i,1,n+1)
    rep(j,1,n+1)
    scn(cost[i][j]);

    vec v;
    int cnt=0;
    rep(i,2,n+1)
    v.pb(i);

    do
    {
      int amt=0;
      amt+=cost[1][v[0]];

      // for(auto it:v)
      // cout<<it<<" ";
      // cout<<endl;

      rep(i,1,v.size())
      amt+=(cost[v[i-1]][v[i]]);
      amt+=cost[v[v.size() - 1]][1];

      // cout<<amt<<" ";

      if(amt==k)
      cnt++;
    } while(next_permutation(all(v)));

    cout<<cnt;
  }
}

//Luka Mitrovic
#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;




int main() {

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int array[9][9];
	int s_arr[9];
	int n,k;
	int ans = 0, sum = 0;

	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		s_arr[i] = i;
		for (int j = 0; j < n; j++) {
			cin >> array[i][j];
		}
	}

	for (int i = 0; i < n; i++) {
		sum += array[s_arr[i]][s_arr[(i+1)%n]];
	}
	if (sum == k) ans++;
	//cout << sum;

	for (int z = 0; z < 10000; z++) {
		bool f = false;
		sum = 0;
		for (int i = n-2; i > 0; i--) {
			if (f) break;
			if (s_arr[i] < s_arr[i+1]) {  // i = 1

				for (int j = n-1; j > i; j--) {  // i = 3, j = 4
					if (s_arr[j] > s_arr[i]) { // j = 3
						int a = s_arr[j];
						s_arr[j] = s_arr[i];
						s_arr[i] = a;

						if (i < n-2) {        // i = 3, j = 4  .. 
							int start = i+1; // start = 4
							int end = start + (n-i)/2;  // end = 4 + (5-3)/2 = 4 + 1 = 5
							for (int s = start, l = 1; s < end; s++,l++) {
								int b = s_arr[s];       // s = 2,3
								s_arr[s] = s_arr[n-l];    // arr[2] <-> arr[3]
								s_arr[n-l] = b;          // arr[3] <-> arr[2]
							}
						}
						for (int s = 0; s < n; s++) {
							sum += array[s_arr[s]][s_arr[(s+1)%n]];
						}
						if (sum == k) ans++;
						f = true;
						break;
					}
				}
			}
		}
	}
	cout << ans << endl;
}