#include<bits/stdc++.h>
using namespace std;
const int mod = 998244353;
//const long long inf = 1e15;
//const double Pi = acos(-1.0);
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define rep(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define lc cout<<"\n"
#define print2d(dp,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cerr<<dp[i][j]<<" ";cerr<<"\n";}

ll solve(ll n,ll i){
	if((i-2)<n){
		return (i-1);
	}else{
		return (2*n-i+1);
	}
}

int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	int tt=1;
	//cin>>tt;
	while(tt--){
		ll n,k;
		cin>>n>>k;
		k=abs(k);
		ll ans =0;
		rep(i,k+2,2*n+1){
			ans += solve(n,i)*solve(n,i-k);
		}
		cout<<ans;
	}
}

#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define rep(i, n) for (long long int i = 0; i < (n); i++)
#define MOD 1000000007
typedef long long ll;

typedef pair<ll, ll> P;
int INF = 100000000;
ll x[1000], y[1000], p[1000];
int main()
{
  ll n, x = 100000000, k, ans = 0, count = 0, j, i;

  ll t[8][8];
  bool found = false;

  cin >> n >> k;

  rep(i, n)
  {
    rep(j, n)
    {
      cin >> t[i][j];
    }
  }

  vector<ll> p(n);

  rep(i, n)
      p[i] = i+1;

  do
  {
    ll len = t[0][p[0]];

    rep(i, n - 2)
        len += t[p[i]][p[i + 1]];

    len += t[p[n - 2]][0];

    if (len == k)
      ans++;

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

  cout << ans << endl;

  return 0;
}