#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using T = tuple<int,int,int>;
using P = pair<int,int>;

int main(){
    int n, k;
    cin >> n >> k;
    vvi field(n, vi(n));
    rep(i,n)rep(j,n) cin >> field[i][j];
    vi num(n-1);
    rep(i,n-1){
        num[i] = i+1;
    }

    // for (auto ele : num){
    //     printf("%d ",ele);
    // }
    // cout << endl;

    int ans = 0;
    do {
        ll sum = field[0][num[0]];
        int pre = num[0];
        rep(i,n-1){
            sum += field[pre][num[i]];
            pre = num[i];
        }
        sum += field[num[n-2]][0];
        if (sum == k) ans++;
    } while(next_permutation(num.begin(), num.end()));
    
    cout << ans << endl;
}

#include <iostream>
#include <string>
#define ll long long
using namespace std;
const int N = 2e5+10;
int cnt[N][26];
int main() {
	string s; cin >> s;
	int n = s.size();
	ll ans = 0;
	for(int i = n - 1; i >= 0; --i) {
		for(int x = 0; x < 26; ++x) {
			cnt[i][x] = cnt[i+1][x];
		}
		++cnt[i][s[i] - 'a'];
	}
	int prev = n;
	for(int i = n - 1; i >= 0; --i) {
		int j = i;
		while(j >= 0 && s[i] == s[j]) --j; ++j;  
		if(i - j + 1 >= 2) {
			for(int x = i; x < prev; ++x) {
				if(s[i] != s[x]) ++ans;
			}
			if(prev < n && s[prev] != s[i]) {
				ans += n - prev;
			}
			prev = j;
		}
		i = j;
	}
	cout << ans << '\n';
}