
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define fast_input ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7

#define inf std::numeric_limits<int>().max()
#define ll long long

using namespace std;

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i=0; i<n; i++) {
        cin >> a[i];
    }
    for(int i=0; i<n; i++) {
        cin >> b[i];
    }
    vector<int> v(n);
    for(int i=0; i<n; i++) {
        v[i] = a[i] - b[i];
    }
    vector<pair<int, int>> x, y;
    for(int i=0; i<n; i++) {
        if (i%2) x.push_back({v[i], i});
        else y.push_back({v[i], i});
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    ll ans = 0;
    for(int i=0; i<x.size(); i++) {
        if (x[i].first + y[i].first > 0) ans += a[x[i].second] + a[y[i].second];
        else ans += b[x[i].second] + b[y[i].second];
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define Rep(i,n) for(int i=0;i<n;i++)
#define Repr(i,n) for(int i=n;i>=0;i--)
#define For(i,m,n) for(int i=m;i<n;i++)
#define Inf 1LL<<60
#define All(v) v.begin(),v.end()
#define Mod (ll)(1e9+7)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;

int main()
{
    int n,k;
    vl a{};
    cin>>n>>k;
    a.reserve(n);
    Rep(i,n-1){
        a.push_back(i+1);
    }
    //cout<<a.size()<<endl;
    ll t[n][n]={};
    Rep(i,n){
        Rep(j,n){
            cin>>t[i][j];
        }
    }
    int tmp=0,count=0;
    do{
        tmp=0;
        Rep(i,n-1){
            tmp+=t[a[i]][a[i+1]];
        }
        tmp+=t[0][a[0]];
        tmp+=t[a[n-1]][0];
        //cout<<tmp<<" ";
        if(tmp==k){
            count+=1;
            //cout<<tmp<<" ";
        }
    }while(next_permutation(a.begin(),a.end()));
    cout<<count<<endl;
    return 0;
}