#include <bits/stdc++.h>

using namespace std;
#define set_precision(ans,l) cout << fixed << setprecision(l)<<ans;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define vi vector<int>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define vpi vector<pair<int,int>>
#define seti set<int>
#define setl set<ll>
#define dseti set<int, greater<int>>
#define dsetl set<ll, greater<ll>>
#define mseti multiset<int>
#define msetl multiset<ll>
#define dmseti multiset<int, greater<int>>
#define dmsetl multiset<ll, greater<ll>>
#define sortA(arr) sort(arr.begin(), arr.end())
#define dsortA(arr) sort(arr.begin(), arr.end(), greater<ll>())
#define ssort(arr) stable_sort(arr.begin(), arr.end())
#define nth(v,n) nth_element(v.begin,v.begin+n-1,v.end())
#define dnth(v,n) nth_element(v.begin,v.begin+n-1,v.end(), greater<ll>())
#define init(a)  memset((a),0,sizeof(a))
#define pi pair<int,int>
#define pb push_back
#define pl pair<ll,ll>
#define ll long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 998244353
long double EPS = 1e-9;

/*struct comp {
  bool operator() (const int& lhs, const int& rhs) const
  {return lhs<rhs;}
};*/

ll cel(ll a,ll b){return((a-1)/b+1);} 
ll gcd(ll a, ll b){
    if (a < b)swap(a, b);
    return (b == 0)? a: gcd(b, a % b);
}
ll MIN(ll a,int b){ll ans;(a>=b)?ans=b:ans=a;return ans;}
ll MAX(ll a,int b){ll ans;(a>=b)?ans=a:ans=b;return ans;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll po(ll x,ll y){
    ll ans=1;
    while(y){
        if(y&1){ans=(ans*x)%mod;}
        y>>=1;x=(x*x)%mod;
    }
    return ans;
}
ll fac(ll x){
    if(x==0)return 1;
    ll ans=1;
    rep(i,1,x+1){
        ans=(ans*i)%mod;
    }
    return ans%mod;
}
vi adj[51],adj1[51],vis(51,0),vis1(51,0);
void dfs(int u,ll& l){
    vis[u]=1;l++;
    for(int t:adj[u]){
        if(vis[t]){continue;}
        dfs(t,l);
    }
}
void dfs1(int u,ll& l){
    vis1[u]=1;l++;
    for(int t:adj1[u]){
        if(vis1[t]){continue;}
        dfs1(t,l);
    }
}
int main()
{
    FIO;
    ll n,t,x,y,m,s;
    cin>>n>>s;
    int A[n][n];x=0;y=0;
    rep(i,0,n){
        rep(j,0,n){
            cin>>A[i][j];
        }
    }
    rep(i,0,n){
        rep(j,0,n){
            if(j==i)continue;
            bool ok=true;
            rep(k,0,n){
                if(A[i][k]+A[j][k]>s){ok=false;break;}
            }
            if(ok){adj[i].pb(j);}
        }
    }
    rep(i,0,n){
        rep(j,0,n){
            if(j==i)continue;
            bool ok=true;
            rep(k,0,n){
                if(A[k][i]+A[k][j]>s){ok=false;break;}
            }
            if(ok){adj1[i].pb(j);}
        }
    }
    ll ans=1;
    rep(i,0,n){
        if(vis[i])continue;
        x=0;
        dfs(i,x);
        ans=(ans*fac(x))%mod;
        //cout<<i<<" "<<x<<" "<<ans<<"\n";
    }
    rep(i,0,n){
        if(vis1[i])continue;
        x=0;
        dfs1(i,x);
        ans=(ans*fac(x))%mod;
        //cout<<x<<" "<<ans<<"\n";
    }
    cout<<ans;
    return 0;
}
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

class CARCWrecker2 {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        vector<int> A(N);
        REP(i, N) cin >> A[i];

        REP(i, N) {
            if (i % 2 == 1) A[i] *= -1;
        }

        int cur = 0;
        map<int, int> m;
        int res = 0;
        m[0]++;
        REP(i, N) {
            cur += A[i];
            res += m[cur];
            m[cur]++;
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CARCWrecker2 solver;
    solver.solve(in, out);
    return 0;
}
