#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, ll> PIL;
typedef pair<ll, int> PLI;
typedef pair<ll, ll> PLL;
typedef bitset<16> BS;
struct edge {
    int to, cost, id;
};
const double PI = 3.14159265358979323846;
const double EPS = 1E-09;
const ll MOD = 1E+09 + 7; // =998244353;
const ll INFL = 1E18;
const int INFI = 1E09;
const int MAX_N = 20;

struct unionfind {
    vector<int> par, t_rank, siz;
    vector<bool> cyc;
    unionfind(int n) //n要素で初期化(1-indexed)
        : par(n + 1)
        , t_rank(n + 1)
        , siz(n + 1)
    {
        // n要素で初期化
        // 1-indexedになっているので0-indexedで使いたいときは注意
        for (int i = 1; i <= n; i++) {
            par[i] = i;
            siz[i] = 1;
            t_rank[i] = 0;
        }
    }

    // 木の根を求める
    int find(int x)
    {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;

        if (t_rank[x] < t_rank[y]) {
            par[x] = y;
            siz[y] += siz[x];
        } else {
            par[y] = x;
            siz[x] += siz[y];
            if (t_rank[x] == t_rank[y])
                t_rank[x]++;
        }
    }

    // xとyが同じ集合に属するか否か
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }

    // xの属するグループのサイズを求める
    int size(int x)
    {
        return siz[find(x)];
    }
};

ll dx[4] = { -1, 1, 0, 0 }, dy[4] = { 0, 0, -1, 1 };

int N, M;

vector<int> G[MAX_N + 1];

bool used[MAX_N + 1], check[MAX_N + 1];
int C[MAX_N + 1];

void dfs(int v, vector<int>& vec);
ll paint(int i, int c, vector<int>& vec);

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> M;

    auto uft = unionfind(N);

    fill(C + 1, C + N + 1, -1);

    for (int i = 1; i <= M; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
        uft.unite(a, b);
    }

    ll ans = 1;
    for (int i = 1; i <= N; i++) {
        if (!used[uft.find(i)]) {
            vector<int> vec = { i };
            dfs(i, vec);
            // for (auto v : vec) {
            //     cout << v << " ";
            // }
            // cout << "\n";
            ans *= 3 * paint(0, 0, vec);
            used[uft.find(i)] = true;
        }
    }

    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */

    cout << ans << "\n";

    return 0;
}

void dfs(int v, vector<int>& vec)
{
    check[v] = true;
    for (auto to : G[v]) {
        if (!check[to]) {
            vec.push_back(to);
            dfs(to, vec);
        }
    }
}

ll paint(int i, int c, vector<int>& vec)
{
    if (i + 1 == vec.size())
        return 1;

    ll res = 0;
    bool usedc[3];
    fill(usedc, usedc + 3, false);
    int v = vec[i], w = vec[i + 1];
    C[v] = c;
    for (auto to : G[w]) {
        if (C[to] != -1)
            usedc[C[to]] = true;
    }
    for (int _c = 0; _c < 3; _c++) {
        if (!usedc[_c])
            res += paint(i + 1, _c, vec);
    }
    C[v] = -1;
    return res;
}

#include <bits/stdc++.h>
using namespace std;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T> using Graph = vector<vector<T>>;
template<typename T> using Spacial = vector<vector<vector<T>>>;
template<typename T> using greater_priority_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr int MOD = 1e9+7;
constexpr int MOD2 = 998244353;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
char interval[2] = {' ', '\n'};

template<typename T> struct is_plural : false_type{};
template<typename T1, typename T2> struct is_plural<pair<T1, T2>> : true_type{};
template<typename T> struct is_plural<vector<T>> : true_type{};
template<typename T> struct is_plural<complex<T>> : true_type{};
template<> struct is_plural<string> : true_type{};

template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second; }
template<typename T> istream &operator>>(istream &is, vector<T> &vec) { for(auto itr = vec.begin(); itr != vec.end(); ++itr) is >> *itr; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { if(vec.empty()) return os; bool pl = is_plural<T>(); os << vec.front(); for(auto itr = ++vec.begin(); itr != vec.end(); ++itr) os << interval[pl] << *itr; return os; }
template<typename T> istream &operator>>(istream &is, complex<T> &x) { T a, b; is >> a >> b; x = complex<T>(a, b); return is; }
template<typename T> ostream &operator<<(ostream &os, complex<T> &x) { return os << x.real() << ' ' << x.imag(); }

bool CoutYN(bool a, string y = "Yes", string n = "No") { cout << (a ? y : n) << '\n'; return a; }

template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

/* -------- <templates end> -------- */

void solve() {
  ll a, b; cin >> a >> b;

  vector<int> prime = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71 };
  vector<int> pos(72, -1);
  for(int i=0; i<20; ++i) pos[prime[i]] = i;

  vector<ll> dp(1<<20, 0);
  dp[0] = 1;

  for(ll x=a; x<=b; ++x) {
    bitset<20> bs(0);
    for(int i=0; i<20; ++i) {
      bs.set(i, x % prime[i] == 0);
    }

    for(int i=(1<<20)-1; i>=0; --i) {
      if(!dp[i]) continue;
      bitset<20> now(i);
      auto d = now & bs;
      if(d.none()) {
        d = now | bs;
        dp[d.to_ullong()] += dp[i];
      }
    }
  }

  cout << accumulate(ALL(dp), 0LL) << endl;
}

/* -------- <programs end> -------- */

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<cmath>
#define SYNC ios::sync_with_stdio(0),cin.tie(0)
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define EPS 1e-6
#define endl '\n'
using namespace std;
const int MAXN = 11450;
int N;
int A[MAXN];
int L[MAXN], R[MAXN];
void solve(){
	cin >> N;
	A[0] = A[N+1] = -INF;
	for(int i = 1; i <= N; ++i)
		L[i] = R[i] = 0;
	for(int i = 1; i <= N; ++i)
		cin >> A[i];
	for(int i = 1; i <= N; ++i){
		int now_min = A[i];
		int nowl = i - 1;
		while(now_min <= A[nowl])
			nowl = L[nowl] - 1;
		L[i] = nowl + 1;
	}
	for(int i = N; i >= 1; --i){
		int now_min = A[i];
		int nowr = i + 1;
		while(now_min <= A[nowr])
			nowr = R[nowr] + 1;
		R[i] = nowr - 1;
	}
	int ans = -INF;
	for(int i = 1; i <= N; ++i){
		int now_ans = A[i] * (R[i] - L[i] + 1);
		ans = max(ans, now_ans);
	}
	cout << ans << endl;
}
int main(){
	SYNC;
	solve();
}

#include <bits/stdc++.h>
#include <unordered_set> // 重複排除した集合
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll N;
  cin >> N;
  vector<ll> dp(N);
  vector<ll> A(N);
  // vector<Pair<int, int> > B(N);
  rep(i,N){
    cin >> A[i];
  }

  long long ans = 0;
  rep(left,N){
    ll right = left; // [left, right) の総和が x 以下となる最大の right を求める
    ll min_a = A[left];

    /* sum に a[right] を加えても大丈夫なら right を動かす */
    while (right < N) {
        min_a = min(min_a,A[right]);
        ans = max(ans, min_a*(right-left+1));
        ++right;
    }

    /* break した状態で right は条件を満たす最大 */
    // dp[left] = ans;
    // cout << sum << endl;
  }

  cout << ans;
}


#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, n, m) for(int i = (int)(n); i < (int)(m); i++)
using namespace std;

int main() {
  double A, B;
  cin >> A >> B;

  double ans = (1 - B/A)*100;
  cout << fixed << setprecision(10) << ans << endl;
}

//#include<bits/stdc++.h>
//typedef long long ll;
//const ll mod=1e9+7;
//const ll inf=0x3f3f3f3f;
//const int N=2e5+5;
//using namespace std;
//
//ll a[N],b[N],c[N];
//int main()
//{
//    int n;
//    cin>>n;
//    for(int i=0;i<n;i++)
//    {
//        cin>>a[i]>>b[i]>>c[i];
//    }
//    int ans=inf;
//    for(int i=0;i<n;i++)
//        {
//            if(a[i]<c[i]) ans=min(ans,b[i]);
//        }
//    if(ans==inf) ans=-1;
//    cout<<ans<<endl;
//    return 0;
//}
#include<bits/stdc++.h>
typedef long long ll;
const ll mod=1e9+7;
const ll inf=0x3f3f3f3f;
const int N=2e5+5;
using namespace std;
int main()
{
    double a,b;cin>>a>>b;
    cout<<(a-b)/a*100<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vl = vector<ll>;
using vl2 = vector<vector<ll>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9+1;
const ll LINF = 1e18+1;
const long double LPI = acos(-1.0);
const  double PI = acos(-1.0);
const int mod = 1000000007;

#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(ll i=1;i<=(int)(x);i++)
#define RREP(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(ll i=((int)(x));i>0;i--)

#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SORT(v) sort(ALL(v));
#define RSORT(v) sort(RALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;

#define HOGE COUT("HOGE")

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
template<typename T> T gcd(T a,T b){if(b==0){return a;}else{return gcd(b, a%b);}}
template<typename T> T lcm(T a,T b){return a*b/gcd(a, b);}
template<typename T> bool isPrime(T a){if(a<=1){return false;}
    for(T i=2;i*i<=a;i++){if (a%i==0) {return false;}}return true;}
template<typename T> T ord(T p,T n){T ans=0;while(true){if(n%p==0){n/=p;ans++;}else{break;}}return ans;}

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    IN(ll, n);
    set<ll> s;
    REP(i, n){
        ll k;
        cin >> k;
        s.insert(k);
    }
    while (true) {
        if (s.size()==1) {
            break;
        }
        auto ei = s.end();
        ei--;
        ll k = *ei;
        s.erase(ei);
        s.insert(k-*s.begin());
    }
    COUT(*s.begin());
}


#include <bits/stdc++.h>
#include <random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;++i)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;--i)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
#define fi first
#define se second
struct fast_ios { fast_ios() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_;
template<class T> auto add = [](T a, T b) -> T { return a + b; };
template<class T> auto f_max = [](T a, T b) -> T { return max(a, b); };
template<class T> auto f_min = [](T a, T b) -> T { return min(a, b); };
template<class T> using V = vector<T>;
using Vl = V<lint>; using VVl = V<Vl>;
template< typename T > ostream& operator<<(ostream& os, const vector< T >& v) {
	for (int i = 0; i < (int)v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : "");
	return os;
}
template< typename T >istream& operator>>(istream& is, vector< T >& v) {
	for (T& in : v) is >> in;
	return is;
}
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
lint gcd(lint a, lint b) { if (b == 0) return a; else return gcd(b, a % b); }
lint ceil(lint a, lint b) { return (a + b - 1) / b; }
lint digit(lint a) { return (lint)log10(a); }
lint e_dist(plint a, plint b) { return abs(a.fi - b.fi) * abs(a.fi - b.fi) + abs(a.se - b.se) * abs(a.se - b.se); }
lint m_dist(plint a, plint b) { return abs(a.fi - b.fi) + abs(a.se - b.se); }
void Worshall_Floyd(VVl& g) { REP(k, SZ(g)) REP(i, SZ(g)) REP(j, SZ(g)) chmin(g[i][j], g[i][k] + g[k][j]); }
const lint MOD = 1e9 + 7, INF = LLONG_MAX;
lint dx[8] = { 1, 0, -1, 0, 1, -1, 1, -1 }, dy[8] = { 0, 1, 0, -1, -1, -1, 1, 1 };
bool YN(bool flag) { cout << (flag ? "YES" : "NO") << endk; return flag; } bool yn(bool flag) { cout << (flag ? "Yes" : "No") << endk; return flag; }
struct Edge {
	lint from, to;
	lint cost;
	Edge(lint u, lint v, lint c) {
		cost = c;
		from = u;
		to = v;
	}
	bool operator<(const Edge& e) const {
		return cost < e.cost;
	}
};
struct WeightedEdge {
	lint to;
	lint cost;
	WeightedEdge(lint v, lint c = 1) {
		to = v;
		cost = c;
	}
	bool operator<(const WeightedEdge& e) const {
		return cost < e.cost;
	}
};
using WeightedGraph = V<V<WeightedEdge>>;
typedef pair<plint, lint> tlint;
typedef pair<plint, plint> qlint;
typedef pair<string, lint> valstring;

lint N, M, K;
int main() {
	cin >> N >> M >> K;
	Vl arr(K);
	cin >> arr;
	long double initok = 1;
	lint cnt = 1;
	if (M == 1 && K == 1) {
		cout << -1 << endk;
		return 0;
	}
	REP(i, K - 1) {
		if (arr[i] + 1 == arr[i + 1]) cnt++;
		else cnt = 1;
		if (cnt >= M) {
			cout << -1 << endk;
			return 0;
		}
	}
	auto check = [&](long double e0) {
		V<long double> dp(N + M + 1, 0);
		REP(i, K) dp[arr[i]] = -1;
		long double sum = M;
		IREP(i, N) {
			if (dp[i + M + 1] == -1) {
				sum -= e0 + 1;
			}
			else sum -= (dp[i + M + 1] + 1);
			if (dp[i + 1] == -1) {
				sum += e0 + 1;
			}
			else sum += (dp[i + 1] + 1);
			if(dp[i] != -1) dp[i] = sum / M;
		}
		return dp[0] <= e0;
	};

	long double ok = INF, ng = -1;
	REP(_, 100) {
		long double mid = (ok + ng) / 2;
		if (check(mid)) ok = mid;
		else ng = mid;
	}
	cout << ok << endk;
}

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

// 'R' = 0, 'P' = 1, 'S' = 2 と対応させる

ll f(ll x, ll y) {
    if(x == y) {
        return x;
    }
    if(x+y == 1) {
        return 1;
    }
    else if(x+y == 2) {
        return 0;
    }
    else if(x+y == 3) {
        return 2;
    }
}

int main() {
    ll n, k;
    string s;
    cin >> n >> k >> s;

    vl two(k);  // two[i] : 2^i(mod.n)
    two[0] = 1;
    rep(i, k-1) {
        two[i+1] = 2*two[i]%n;
    }

    vvl dp(k+1, vl(n));  // dp[i][j] : i回戦で、区間の左端がjのときの勝者の手
    rep(j, n) {
        rep(x, 3) {
            if(s[j] == "RPS"[x]) {
                dp[0][j] = x;
            }
        }
    }
    rep(i, k) {
        rep(j, n) {
            dp[i+1][j] = f(dp[i][j], dp[i][(j + two[i])%n]);
        }
    }

    out("RPS"[dp[k][0]]);
    re0;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
#define pow(n,m) powl(n,m)
#define sqrt(n) sqrtl(n)
const ll MAX = 5000000000000000000;
const ll MOD = 0;
random_device rd;
mt19937 mt(rd());
int main(){
    ll N,M;
    cin >> N >> M;
    vector<string> S(M),ans(N),T;
    map<string,ll> ss;
    ll m = MAX;
    for(ll i = 0;i < M;i++) cin >> S[i];
    for(ll i = 0;i < M;i++) ss[S[i]] = i + 1;
    for(ll i = 0;i < M;i++) m = min(m,(ll)S[i].size());
    for(ll t = 0;t < 4000;t++){
        string a = S[mt() % M];
        for(ll i = 0;i < 10;i++){
            string b = S[mt() % M];
            for(ll j = min(a.size(),b.size());j >= 0;j--){
                ll ok = 1;
                for(ll k = 0;k < j;k++){
                    if(a[a.size() - j + k] != b[j]) ok = 0;
                }
                if(ok){
                    ll k = j;
                    while(a.size() < N && k < b.size()){
                        a += b[k];
                        k++;
                    }
                    break;
                }
            }
            if(a.size() + b.size() <= N){
                a += b;
            }
        }
        while(a.size() < N) a += (char)('A' + (mt() % 8));
        T.emplace_back(a);
    }
    for(ll i = 0;i < N;i++){
        ll C = 0;
        string A = "____________________";
        for(ll j = 0;j < T.size();j++){
            ll c = 0;
            string a = T[j] + T[j];
            for(ll k = 0;k < N;k++){
                for(ll l = m;l < m + 5;l++){
                    if(ss[a.substr(k,l)] != 0) c++;
                }
            }
            if(C < c){
                C = c;
                A = T[j];
            }
        }
        string a = A + A;
        for(ll k = 0;k < N;k++){
            for(ll l = m;l < m + 5;l++){
                if(ss[a.substr(k,l)] != 0) ss[a.substr(k,l)] = 0;
            }
        }
        ans[i] = A;
    }
    for(ll i = 0;i < N;i++) cout << ans[i] << endl;
}

#include <iostream>
#include <chrono>
#include <string>
#include <vector>
#include <algorithm>
class DNA {
	private:
		char base[20][20];
	public:
		void inputV(const int& i, const int& j, const std::string& s) {
			for (int k = 0; k < (int)s.size(); k++) {
				if (i + k < 20) base[i + k][j] = s[k];
				else base[i + k - 20][j] = s[k];
			}
		}
		void inputH(const int& i, const int& j, const std::string& s) {
			for (int k = 0; k < (int)s.size(); k++) {
				if (j + k < 20) base[i][j + k] = s[k];
				else base[i][j + k - 20] = s[k];
			}

		}
		void output() {
			for (int i = 0; i < 20; i++) {
				for (int j = 0; j < 20; j++) {
					std::cout << base[i][j];
				}
				std::cout << std::endl;
			}
		}
		//constructor
		DNA() {
			for (int i = 0; i < 20; i++) {
				for (int j = 0; j < 20; j++) {
					base[i][j] = '.';
				}
			}
		}
};
int main() {
	DNA alien;
	int m;
	std::cin >> m >> m;
	std::vector<std::pair<int, std::string>> sequences(m, { 0, "" });
	for (int i = 0; i < m; i++) {
		std::cin >> sequences[i].second;
		sequences[i].first = (int)sequences[i].second.size();
	}
	sort(sequences.begin(), sequences.end());
	int now = 0;;
	int k = 0;
	while(now < 20) {
		for (int i = 0; i < 20; i++) {
			alien.inputH(i, now + 1, sequences[i].second);
		}
		k++;
		now += sequences[k * 20 - 1].first;
	}
	alien.output();

	return 0;

}


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 2010,INF = 0x3f3f3f3f;

string s;
int n,m,tmp,p,ans,sum,minn = INF;
int a[N][N];

int main()
{
	cin >> n >> m;
	for(int i = 0;i < n;i++)
	{
		for(int j = 0;j < m;j++)
		{
			cin >> a[i][j];
			minn = min(minn,a[i][j]);
		}
	}
	for(int i = 0;i < n;i++)
	{
		for(int j = 0;j < m;j++)
		{
			sum += a[i][j]-minn;
		}
	}
	cout << sum << endl;

	return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("no-stack-protector")

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ld long double
#define ll long long
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
// SOME BITMASK KNOWLEDGE
// 1)x & (x - 1):sets the last one bit of x to zero
// power of two exactly when x & (x − 1) = 0.
// 2)x & -x:sets all the one bits to zero, except last one bit
// 3)x | (x - 1):inverts all the bits after the last one bit
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
typedef tree<string,null_type,less<string>,rb_tree_tag,tree_order_statistics_node_update> indexed_set2;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);

ll power(ll a,ll n){
	if(n == 0) return 1;
	ll s = power(a,n/2);
	s = (s * s);
	if(n % 2) s = (s * a);
	return s;
}

struct Service {
	ll l,c,f;
};

bool compare(Service a,Service b){
	if(a.l == b.l){
		return a.f > b.f;
	}
	return a.l < b.l;
}
int main()
{
	i_os;
	ll n,C;
	cin>>n>>C;
	vector<Service> v;
	REP(i,0,n){
		ll x,y,z;
		cin>>x>>y>>z;
		Service s1,s2;
		s1.l = x; s1.c = z; s1.f = 0;
		s2.l = y+1; s2.c = z; s2.f = 1;
		v.push_back(s1);
		v.push_back(s2);
	}
	sort(v.begin(),v.end(),compare);
	ll sum = 0;
	ll ans = 0;
	ll in = 0;
	ll st = 1;
	for(Service s:v){
		// cout<<s.l<<" "<<s.f<<" "<<s.c<<endl;
		if(s.f){
			ans += min(C,sum)*(s.l-1-st+1);
			st = s.l;
			sum -= s.c;
			in--;
		}
		else {
			if(in != 0){
				ans += min(C,sum)*(s.l-1-st+1);
			}
			st = s.l;
			sum += s.c;
			in++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


//#define _GLIBCXX_DEBUG
//#include "atcoder/all"
//using namespace atcoder;
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define Dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) (((n) >> (k)) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = true;
}  // namespace mydef
using namespace mydef;
#define pb push_back
//#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

int N;

void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int ans = INF;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int A, P, X;
        cin >> A >> P >> X;
        X -= A;
        if (X > 0)
            chmin(ans, P);
    }
    cout << (ans == INF ? -1 : ans) << endl;

    solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;

int main()
{
	// freopen("1.in", "r", stdin);
	int n;
	scanf("%d", &n);
	int res = INF;
	for(int i = 1; i <= n; ++ i)
	{
		int a, p, x; scanf("%d%d%d", &a, &p, &x);
		if(a < x) res = min(p, res);
	}
	if(res < INF) printf("%d\n", res);
	else puts("-1");
	return 0;
}


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <list>
#include <cassert>
#include <climits>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define PB push_back
#define MP make_pair
#define SZ(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)
#define FORSZ(i,a,v) FOR(i,a,SZ(v))
#define REPSZ(i,v) REP(i,SZ(v))
std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

const int MAXN = 500000;

int n;
char s[MAXN + 1];
char t[MAXN + 1];

int solve() {
	vector<int> szero; REP(i, n) if (s[i] == '0') szero.PB(i);
	vector<int> tzero; REP(i, n) if (t[i] == '0') tzero.PB(i);
	if (SZ(szero) != SZ(tzero)) return -1;
	int ret = 0;
	REPSZ(i, szero) if (szero[i] != tzero[i]) ++ret;
	return ret;
}

void run() {
	scanf("%d", &n);
	scanf("%s", s);
	scanf("%s", t);
	printf("%d\n", solve());
}

int main() {
	run();
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll n, ans, s[500050], t[500050], f[2];
vector<int> vs, ts;

int main() {
    scanf("%lld", &n);
    for(int i = 0; i < n; i++) {
        scanf("%1lld", &s[i]);
        f[s[i]]++;
        if(!s[i]) vs.push_back(i);
    }
    for(int i = 0; i < n; i++) {
        scanf("%1lld", &t[i]);
        f[t[i]]--;
        if(!t[i]) ts.push_back(i);
    }
    if(f[0] || f[1]) puts("-1");
    else {
        for(int i = 0; i < vs.size(); i++)
            ans += (vs[i] != ts[i]);
        printf("%lld\n", ans);
    }
    return 0;
}


#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define INF INT_MAX / 2
#define INFL 1LL << 60
#define MOD 1000000007
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3)                                                 \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << endl
#define debug_4(x1, x2, x3, x4)                                             \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5)                                         \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

using namespace std;
using ll = long long;

int main() {
    double a, b;
    cin >> a >> b;

    double ans = (b / 100) * a;
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long
//using mint = atcoder::modint;

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long A, long long B, long long W){
    W *= 1000;
    int minCnt = INT_MAX, maxCnt = -1;
    rep(i,1,1000001) {
        if (i * A <= W && W <= i * B) {
            minCnt = min<int>(i, minCnt);
            maxCnt = max<int>(i, maxCnt);
        }
    }
    if (minCnt == INT_MAX) {
        cout << "UNSATISFIABLE" << endl;
    } else {
        cout << minCnt << " " << maxCnt << endl;
    }
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long W;
    scanf("%lld",&W);
    solve(A, B, W);
    return 0;
}


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {

  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  int t;
  cin >> t;

  rep(i, t) {
    ll n, a, b;
    cin >> n >> a >> b;
    int e = n-a-b;
    mint ans, x1, x2, x3, x4;
    if (e < 0) x4 = 0;
    else x4 = (mint)(e+2) * (e+1) / 2;
    x3 = (mint)2 * x4;
    x2 = (mint)(n-a+1) * (n-b+1) - x3;
    x1 = x2 * x2;
    ans = (mint)((n-a+1)*(n-a+1))*(mint)((n-b+1)*(n-b+1)) - x1;
    cout << ans << endl;
  }

  return 0;
}

// Coded By : Aj Style
// Problem: C - ORXOR
// Contest: AtCoder - AtCoder Beginner Contest 197（Sponsored by Panasonic）
// URL: https://atcoder.jp/contests/abc197/tasks/abc197_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms

#include <bits/stdc++.h>
#define ll long long int
#define ii int
#define du double
#define jmp "\n"
#define vl vector<ll>
#define vvl vector<vl>
#define pb push_back
#define pq_max priority_queue<ll>
#define pq_min priority_queue<ll, vi, greater<ll>>
#define printv(v)         \
    for (auto x : v)      \
        cout << x << " "; \
    cout << jmp;
#define vi vector<int>
#define vb vector<bool>
#define ump unordered_map
#define SORT(v) sort(v.begin(), v.end())
#define REV(x) reverse(x.begin(), x.end())
#define all(x) x.begin(), x.end()
#define SET(x, a) memset(x, a, sizeof(x))
#define si(x) (ll) x.size()
#define ff first
#define ss second
#define I(a)          \
    for (auto &x : a) \
        cin >> x;
#define iin insert
#define log(args...)                             \
    {                                            \
        string _s = #args;                       \
        replace(_s.begin(), _s.end(), ',', ' '); \
        stringstream _ss(_s);                    \
        istream_iterator<string> _it(_ss);       \
        err(_it, args);                          \
    }
#define logarr(arr, a, b)            \
    for (int z = (a); z <= (b); z++) \
        cout << (arr[z]) << " ";     \
    cout << endl;                    \
    using namespace std;
using namespace std;

// vs tokenizer(string str,char ch) {std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;}

void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cout << *it << " = " << a << endl;
    err(++it, args...);
}
const ll nax = 1e5 + 5;
vl a;
ll n;
ll mn;
void r(ll x, ll o, ll i)
{
    if (i == n)
    {
        // if (o)
        x ^= o;
        mn = min(mn, x);
        return;
    }
    r(((x ^ o)), a[i], i + 1);
    r(x, (o | a[i]), i + 1);
    return;
}
void solve()
{
    // ll n;
    cin >> n;
    a = vl(n);
    I(a);
    mn = LLONG_MAX;
    r(0, 0, 0);
    cout << mn << jmp;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define MOD 1000000007
#define F first
#define S second
#define cn(a, n)               \
    for (ll i = 0; i < n; i++) \
        cin >> a[i];
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

int main()
{
    fastio();
    int A, B;
    cin >> A >> B;
    if (A + B >= 15 and B >= 8)
    {
        cout << "1";
    }
    else if (A + B >= 10 and B >= 3)
    {
        cout << "2";
    }
    else if (A + B >= 3)
    {
        cout << "3";
    }
    else
    {
        cout << "4";
    }
}

#include <bits/stdc++.h>
using namespace std;

const char BLUE = '+';
const int INF = INT_MAX >> 1;

int main(void) {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int h, w;
	cin >> h >> w;
	vector<string> a(h);
	for (int i = 0; i < h; i++) {
		cin >> a[i];
	}
	vector<vector<int>> dp(h, vector<int>(w));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			dp[i][j] = (1 & (i + j)) ? INF : -INF;
		}
	}
	dp[h - 1][w - 1] = 0;
	for (int i = h - 1; i >= 0; i--) {
		for (int j = w - 1; j >= 0; j--) {
			if (1 & (i + j)) // akoi
			{
				if (i > 0) {
					dp[i - 1][j] = max(dp[i - 1][j], dp[i][j] + ((BLUE == a[i][j]) ? 1 : -1));
				}
				if (j > 0) {
					dp[i][j - 1] = max(dp[i][j - 1], dp[i][j] + ((BLUE == a[i][j]) ? 1 : -1));
				}
			}
			else // takashi
			 {
				if (i > 0) {
					dp[i - 1][j] = min(dp[i - 1][j], dp[i][j] - ((BLUE == a[i][j]) ? 1 : -1));
				}
				if (j > 0) {
					dp[i][j - 1] = min(dp[i][j - 1], dp[i][j] - ((BLUE == a[i][j]) ? 1 : -1));
				}
			}
		}
	}
	cout << ((0 == dp[0][0]) ? "Draw" : ((dp[0][0] > 0) ? "Takahashi" : "Aoki")) << endl;
	return 0;
}


#include <bits/stdc++.h>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
using ll = long long;
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll n) {
    ll res = 1, a = 2;
    while (n > 0) {
        if (n & 1) res = res * a % 1000000007;
        a = a * a % 1000000007;
        n >>= 1;
    }
    if(res == 0) res = 1000000006;
    else res -= 1;
    return res;
}
ll yaku(ll x){
    ll cnt = 0;
    for(int i = 1; i * i <= x; i++){
        if(x % i == 0){
            if(i == x % i) cnt++;
            else cnt += 2;
        }
    }
    return cnt;
}

int main(){
    string X;
    ll M, ma = -1, ans = 0, cnt;
    cin >> X >> M;
    ll siz = X.size();
    vector<ll> x(siz);
    for(int i = 0; i < siz; i++) x.at(i) = X.at(i) - 48;
    for(int i = 0; i < siz; i++) ma = max(x.at(i), ma);
    cnt = ma + 1;
    if(siz == 1){
        if(x.at(0) > M) cout << 0 << endl;
        else cout << 1 << endl;
        return 0;
    }else if(siz == 2){
        ll m = M;
        m -= x.at(1);
        cout << m / x.at(0) - ma << endl;
        return 0;
    }else if(siz == 3){
        while(1){
            if(cnt * (cnt * x.at(0) + x.at(1)) + x.at(2) > M) break;
            cnt++;
            ans++;
        }
        cout << ans << endl;
    }else{
        reverse(x.begin(), x.end());
        while(1){
            ll a = 1, s = 0;
            for(int i = 0; i < siz; i++){
                s += a * x.at(i);
                if(s > M || a > M) break;
                if(i != siz - 1) a *= cnt;
            }
            if(s > M || a > M) break;
            ans++;
            cnt++;
        }
        cout << ans << endl;
        return 0;
    }

}

//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <queue>

using namespace std;

#define rep(i,n) for (int i = 0; i < (n); i++)
#define vi vector<int>
#define vll vector<long long>
#define vb vector<bool>
#define vs vector<string>
#define all(x) x.begin() , x.end()
#define pb push_back
#define eb emplace_back
#define chmax(x,y) (x) = max((x) , (y))
#define chmin(x,y) (x) = min((x) , (y))
#define fi first
#define se second

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

//const int MOD = int(1e9) + 7;
//const int MOD = 998244353;
//const ll MOD = ll(1e9) + 7;
const ll MOD = 998244353;
const ld PI = 3.1415926535897932384626;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
const int MX = 220000;

ll modpow (ll x , ll p) {
    ll ret = 1;
    while (p) {
        if (p % 2 == 1) {
            ret *= x;
            ret %= MOD;
        }
        x *= x;
        x %= MOD;
        p /= 2;
    }
    return ret;
}

vll fact(MX);
vll factinv(MX);
void init_fact () {
    fact[0] = 1;
    for (int i = 1; i < MX; i++) {
        fact[i] = 1LL * i * fact[i - 1] % MOD;
    }
    for (int i = 0; i < MX; i++) {
        factinv[i] = modpow(fact[i] , MOD - 2);
    }
}

bool is_prime (int x) {
    if (x == 2 || x == 3 || x == 5 || x == 7) {
        return true;
    }
    for (ll i = 2; i*i <= x; i++) {
        if (x % i == 0) {
            return false;
        }
    }
    return true;
}

vb prime_table(MX , true);
void init_prime() {
    for (int i = 2; i < MX; i++) {
        for (int j = i + i; j < MX; j += i) {
            prime_table[j] = false;
        }
    }
    return;
}

map<ll, int> factrization(ll x) {
    map<ll, int> ret;
    for (int i = 2; i*i <= x; i++) {
        while (x % i == 0) {
            ret[i]++;
            x /= i;
        }
    }
    if (x > 1) ret[x]++;
    return ret;
}

ll moddiv (ll a , ll b) { return a * modpow(b , MOD - 2) % MOD; }
ll modsub (ll a , ll b) { if (a >= b) return (a - b) % MOD; else return (MOD - a + b); }
ll nCk (ll n , ll k) { return ((fact[n] * factinv[k] % MOD) * factinv[n - k] % MOD); }
ll nHk (ll n , ll k) { return nCk(n - 1 + k , k); } // 仕切り- 1 + boll を並べる組み合わせ
ll gcd (ll a , ll b) { if (a < b) swap(a , b); if (a % b == 0) return b; else return gcd(b , a % b); }
ll lcm (ll a , ll b) { return a / gcd(a , b) * b; }
ll lin() { ll x; scanf("%lld" , &x); return x; }
int in() { int x; scanf("%d" , &x); return x; }
bool is_palindrome (string s) { string t = s; reverse(all(t)); return (s == t); }
void io_setup() { cout << fixed << setprecision(20); }

void solve () {
    int n , m;
    cin >> n >> m;
    map<int , int> mp1 , mp2;
    rep(i,n) {
        int a = in();
        mp1[a]++;
    }
    rep(i,m) {
        int a = in();
        mp2[a]++;
    }
    vi ans;
    for (auto i : mp1) {
        if (mp2[i.fi] == 0) ans.pb(i.fi);
    }
    for (auto i : mp2) {
        if (mp1[i.fi] == 0) ans.pb(i.fi);
    }
    sort(all(ans));
    int SZ = ans.size();
    rep(i,SZ) {
        cout << ans[i];
        if (i != SZ - 1) cout << " ";
        else cout << endl;
    }
    return;
}

int main() {
    io_setup();
    //init_fact();
    //init_prime();
    solve();
    return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;

const int inf  = 1e18+9;
const int mod  = 1e9+7;
const int maxn = 2e5+8;

int n, m;

void solve() {
    int i, j;
    map<int, int> mp;
    cin >> n;
    for (int x = 3, i = 1; x < n; i++, x *= 3) mp[x] = i;
    for (int x = 5, i = 1; x < n; i++, x *= 5) if (mp.find(n - x) != mp.end()) return (void)(cout << mp[n - x] << " " << i << endl);
    cout << -1 << endl;
}

signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); //cout << fixed << setprecision(15);
    int t = 1; //cin >> t;
    while (t--) solve();
    return 0;
}

#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int check(int a, int b, ll n)
{

    ll cur = 1;
    rep(i, a)
    {
        cur *= 3;
        if (cur > n) {
            return -1;
        }
    }
    ll tmp = 1;
    rep(j, b)
    {
        tmp *= 5;
        if (tmp > n) {
            return -1;
        }
    }
    cur += tmp;
    assert(cur > 0);
    if (cur > n) {
        return -1;
    }
    if (cur == n) {
        return 1;
    } else {
        return 0;
    }
}

int main()
{

    ll n;
    cin >> n;
    rep(i, 1, 100)
    {
        rep(j, 1, 100)
        {
            ll ret = check(i, j, n);
            if (ret == -1) {
                break;
            }

            if (ret == 1) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
    return 0;
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
#define rep(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
const int INF = 1'000'000'000;
const ll llINF = 1'000'000'000'000'000'000;

int main() {
    int N;
    cin >> N;

    cout << (1<<N) - 1 << endl;
    if (N == 1) {
        cout << "AB" << endl;
        return 0;
    }

    vector<vector<int>> had2 = {{1,1},{1,-1}};
    vector<vector<int>> prev = had2, ans = had2;
    rep(k,2,N+1) {
        ans = vector<vector<int>>(1<<k,vector<int>(1<<k));
        rep(i,0,1<<k) rep(j,0,1<<k) {
            //cout << i << " " << j << endl;
            ans[i][j] = prev[i & ~(1<<k-1)][j & ~(1<<k-1)];
        }
        rep(i,1<<k-1,1<<k) rep(j,1<<k-1,1<<k) {
            ans[i][j] *= -1;
        }
        prev = ans;
    }

    rep(i,1,1<<N) {
        rep(j,0,1<<N) {
            cout << (ans[i][j] == 1 ? 'A' : 'B');
        }
        cout << endl;
    }
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define li long long
#define pii pair<int, int>
#define vi vector<int>
#define li long long

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fore(i, b, e) for (int i = (int)b; i <= (int)e; i++)

const int MAXN = 2005;

bool visited[MAXN];
vi edges[MAXN];
int n, m;

void dfs(int v) {
	visited[v] = true;
	for (int u : edges[v]) {
		if (!visited[u])
			dfs(u);
	}
}

void add_edge(int row, int col) {
	edges[row].pb(col + n);
	edges[col + n].pb(row);
}

int main() {
	scanf("%d%d", &n, &m);
	forn(i, n) {
		string s;
		cin >> s;
		forn(j, m) {
			if (s[j] == '#') {
				add_edge(i, j);
			}
		}
	}
	/*forn(i, n) {
		add_edge(i, 0);
		add_edge(i, m - 1);
	}
	forn(j, m) {
		add_edge(0, j);
		add_edge(n - 1, j);
	}*/
	add_edge(0, 0);
	add_edge(0, m);
	add_edge(n - 1, 0);
	add_edge(n - 1, m - 1);
	int row_comp = 0;
	forn(i, n) {
		if (!visited[i]) {
			++row_comp;
			dfs(i);
		}
	}
	memset(visited, false, sizeof(visited));
	int col_comp = 0;
	fore(i, n, n + m - 1) {
		if (!visited[i]) {
			++col_comp;
			dfs(i);
		}
	}
	//cerr << row_comp << " " << col_comp << endl;
	printf("%d", min(row_comp - 1, col_comp - 1));
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) begin(v), end(v)
#define sz(v) v.size()
#define INF 1000000000000000000 //10^17
#define EPSILON 0.00000000000001 // 10^-14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

ll llpow(ll x, ll y){
  if(y == 0){
    return 1;
  }
  if(y % 2 == 0){
    ll a = llpow(x, y / 2);
    return a * a;
  }
  else{
    ll a = llpow(x, y / 2);
    return a * a * x;
  }
}

//浮動小数点はなるべく使うな、powも気をつけろ
int main()
{
    string X;
    ll M;
    cin >> X >> M;
    if(sz(X) == 1){
        if(stoll(X) <= M){
            cout << 1 << '\n';
            return 0;
        }
        else{
            cout << 0 << '\n';
            return 0;
        }
    }
    ll d = 0;
    rep(i, sz(X)){
        chmax(d, ll(X.at(i)-'0'));
    }
    ll bound = powl(M, 1.0/(sz(X)-1)) + EPSILON;
    if(sz(X) == 2){
        ll x0 = X.at(0) - '0';
        ll x1 = X.at(1) - '0';
        ll b = (M-x1) / x0;
        if(b < d+1){
            cout << 0 << '\n';
            return 0;
        }
        else{
            cout << b - (d+1) + 1 << '\n';
            return 0;
        }
    }
    if(sz(X) == 3){
        ll x0 = X.at(0) - '0';
        ll x1 = X.at(1) - '0';
        ll x2 = X.at(2) - '0';
        long double r = pow(x1*x1-4*x0*(x0-M), 0.5);
        long double s = (-x1 + r) / (2*x0) + EPSILON;
        ll b = s;
        if(b < d+1){
            cout << 0 << '\n';
            return 0;
        }
        else{
            cout << b - (d+1) + 1 << '\n';
            return 0;
        }
    }
    vector<ll> digit(sz(X));
    rep(i, sz(X)){
        digit.at(i) = X.at(i) - '0';
    }
    ll ans = 0;
    rep2(i, d+1, bound+1){
        ll val = 0;
        rep(j, sz(X)){
            val += llpow(i, sz(X)-1-j) * digit.at(j);
        }
        if(val <= M){
            ans++;
        }
    }
    cout << ans << '\n';
}

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

// bool xd=any_of(a.begin(),a.end(),[&](int x){return x==9;});
// all_of, none_of
// int cnt=count(a.begin(),a.end(),x);
// bool found=binary_search(a.begin(),a.end(),x); true if x in sorted array
// int xd=*max_element(a.begin(),a.end());
// min_element

typedef long long ll;
typedef long double ld;

ll m,n;
vector<int>x;

bool getbase(ll b){
	ll res=0;
	for(auto c:x){
		if(res>(m-c)/b)return 0;
		else res=res*b+c;
		assert(res<=m);
	}
	return 1;
}

main(){
	cin.tie(0);ios::sync_with_stdio(0);
	string tmp;cin>>tmp>>m;n=x.size();
	for(auto c:tmp)x.push_back(c-'0');
	if(x.size()==1){
		if(m>=x[0])cout<<1<<endl;
		else cout<<0<<endl;
		return 0;
	}
	else{
		ll mxc=*max_element(x.begin(),x.end());
		ll l=mxc+1,r=m+1;
		while(l<r){
			ll m=(l+r)/2;
			if(getbase(m))l=m+1;
			else r=m;
		}
		cout<<l-1-mxc<<endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <chrono>
#include <random>
#include <unordered_set>

using namespace std;

typedef long long ll;

void solve() {
    ll a, b;
    cin >> a >> b;
    int n = 73;
    vector<int> s(n);
    vector<int> prime;
    for (int i = 2; i < n; i++) {
        if (s[i] == 0) {
            s[i] = i;
            prime.emplace_back(i);
            for (int j = i; j < n; j += i) {
                s[j] = i;
            }
        }
    }

    int m = b - a + 1;
    n = prime.size();
    vector<int> mask(m);

    for (int i = 0; i < m; i++) {
        ll x = a + i;
        for (int j = 0; j < n; j++) {
            if (x % prime[j] == 0) {
                mask[i] ^= (1 << j);
            }
        }
    }

    vector<ll> dp(1 << n);
    dp[0] = 1;

    for (int i = 0; i < m; i++) {
        vector<ll> dp2(1 << n);
        for (int j = 0; j < (1 << n); j++) {
            if (dp[j] == 0)
                continue;
            dp2[j] += dp[j];
            if ((mask[i] & j) == 0)
                dp2[mask[i] ^ j] += dp[j];
        }
        dp.swap(dp2);
    }

    ll ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        ans += dp[i];
    }

    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#if defined(_DEBUG)
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int q = 1;
    //cin >> q;
    for (; q > 0; q--) {
        solve();
        //cout << endl;
    }
}

#include<bits/stdc++.h>

#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define sc(a) scanf("%c",&a)
#define ss(a) scanf("%s",a)
#define pi(a) printf("%d\n",a)
#define pl(a) printf("%lld\n",a)
#define pc(a) putchar(a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i, a, b) for(register int i=a;i<=b;++i)
#define repd(i, a, b) for(register int i=a;i>=b;--i)
#define reps(s) for(register int i=head[s];i;i=Next[i])
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pii pair<int,int>
#define mii unordered_map<int,int>
#define msi unordered_map<string,int>
#define lowbit(x) ((x)&(-(x)))
#define ce(i, r) i==r?'\n':' '
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;

inline int qr() {
    int f = 0, fu = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-')fu = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        f = (f << 3) + (f << 1) + c - 48;
        c = getchar();
    }
    return f * fu;
}

const int N = 1e3 + 10;
int n, m;
int a[N], b[N];
int f[N][N];

int main() {
    n = qr(), m = qr();
    repi(i, 1, n)a[i] = qr();
    repi(i, 1, m)b[i] = qr();
    memset(f, 0x3f, sizeof(f));
    f[0][0] = 0;
    int ans = INF;
    repi(i, 0, m)f[0][i] = i;
    repi(i, 0, n)f[i][0] = i;
    repi(i, 1, n)
        repi(j, 1, m) {
            if (a[i] != b[j]) {
                f[i][j] = min({f[i][j], f[i - 1][j - 1] + 1, f[i][j - 1] + 1, f[i - 1][j] + 1});
            } else {
                f[i][j] = min({f[i][j], f[i - 1][j - 1], f[i][j - 1] + 1, f[i - 1][j] + 1});
            }
        }
    repi(i, 1, n)repi(j, 1, m)ans = min(ans, f[i][j] + n - i + m - j);
    pi(ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define F first
#define S second
ll MOD = 998244353;

ll power(ll base, ll n){
	if (n == 0) return 1;
	if (n == 1) return base;
	ll halfn = power(base, n/2);
	if (n % 2 == 0) return (halfn * halfn) % MOD;
	return (((halfn * halfn) % MOD) * base) % MOD;
}

ll inverse(ll n){
	return power(n, MOD-2);
}

ll add(ll a, ll b){
	return (a+b) % MOD;
}

ll mul(ll a, ll b){
	return (a*b) % MOD;
}

ll gcd(ll a, ll b){
	if (a == 0) return b;
	if (a == 1) return 1;
	return gcd(b%a, a);
}

int main(){
	ios::sync_with_stdio(false);
	int v, t, s, d; cin >> v >> t >> s >> d;
	if (v * t > d || v * s < d){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}
	return 0;
}

/*
    ->->->->-> Vora Mahammasasim <-<-<-<-<-
*/
#include<bits/stdc++.h>
#define Quick std :: ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define pb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define MOD 1000000007
using namespace std;

void solve(){

    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<a*d-b*c<<'\n';

}
signed main(){

    Quick;

    int tt = 1;
    //cin>>tt;
    while(tt--){
        solve();
    }
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
	string a;
	cin >> a;
	if(a.find('.') != string::npos)
	{
		cout << a.substr(0 , a.find('.'));
	}
	else
	{
		cout << a;
	}
	return 0;
 }

#include <bits/stdc++.h>
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

char s;

int main(){
	while(cin >> s){
		if(s=='.') break;
		cout << s;
	}
}


#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define vii vector<pii>
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y)
{
    if (y < x)
        x = y;
}
template<typename T, typename U> static inline void amax(T &x, U y)
{
    if (x < y)
        x = y;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;}

const int N = 4e5+10;
vi adj[N];
bool vis[N];
int vert;
bool tree = 1;
void dfs(int v,int p){
    vert++;
    vis[v]=1;
    for(auto i:adj[v]){
        if(i!=p){
            if(vis[i])
                tree=0;
            else
                dfs(i,v);
        }
    }
}
int solve(){

    int n;cin>>n;
    int a,b;
    rep0(n){
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    int ans=0;
    for(int i=1;i<=N;i++){
        if(!vis[i]){
            tree = 1;
            vert=0;
            dfs(i,-1);

            if(tree){
                ans+=vert-1;
            }
            else ans+=vert;
        }
    }
    cout<<ans<<endl;

    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;

struct int_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct pair_hash {
    size_t operator()(pair<int, int> x) const {
        return int_hash{}(x.first) ^ (int_hash{}(x.second) << 16);
    }
};

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e7;
const int MX = 100001; //check the limits, dummy

pair<int, bool> dfs(int a, int prev, unordered_set<int> &s,
    unordered_map<int, vector<int>> &mp) {
        if(s.count(a)) {
            return {0, false};
        }
        pair<int, bool> res{1, true};
        s.insert(a);
        for(int next : mp[a]) {
            if(next != prev) {
                auto [ret_cnt, ret_cycle] = dfs(next, a, s, mp);
                res.first += ret_cnt;
                res.second &= ret_cycle;
            }
        }
        return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n; cin >> n;
    unordered_map<int, vector<int>> g;
    for(int i = 0, a, b; i < n; i++) {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    unordered_set<int> vis;
    int res = 0;
    for(const auto &[a, b] : g) {
        const auto [num, cyc] = dfs(a, -1, vis, g);
        res += num - cyc;
    }

    cout << res << endl;
}


#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define endl "\n"
using namespace std;

const int max_n = 1e5+100;
const int max_len = 631441 + 100000;
const int max_sum = 1e7+100;
const int offset = 1e5+10;
const int inf = 1e18;

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int a,b,c;
    cin>>a>>b>>c;
    if(a>b){
    	cout<<"Takahashi"<<endl;
    }else if(b>a){
    	cout<<"Aoki"<<endl;
    }else{
    	if(c==1){
    		cout<<"Takahashi"<<endl;
    	}else{
    		cout<<"Aoki"<<endl;
    	}
    }

}

/*
Author: Hrujul Thumar
*/
#include <bits/stdc++.h>
#define int         long long
#define MOD         100000007
#define endl        '\n'
#define fastio       ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define pi          3.141592653589793238
#define op(a)        cout << (a ? "Takahashi" : "Aoki") << '\n';
const long long MAX_SIZE = 1000000000;
using namespace std;

int visited[1000000];
int a[10000000];
vector<int> v[1000000];
int diff=-1000000000;
int mx=0;
void dfs(int l)
{
        mx=max(mx,a[l]);
        visited[l]=1;
        for(auto &i:v[l])
        {
            dfs(i);
        }
}
signed main()
{
    fastio;
    int t=1;
    //cin>>t;
    while(t--)
    {
        int a,b,c;
        cin>>a>>b>>c;
        while(a && b){
            if(c)
            {
                b--;
            }
            else a--;
            c++;
            c%=2;
        }
        if(a && !c)op(1)
        else if(b && c)op(0)
        else if(!a && !c)op(0)
        else if(!b && c)op(1)
        else if(a && c)op(1)
        else if(b && !c)op(0)

    }
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

#define N 200100
#define MOD 1000000007  //998244353
#define ll long long
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep2(i, a, b) for(int i = a; i <= b; ++i)
#define rep3(i, a, b) for(int i = a; i >= b; --i)
#define eb emplace_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
struct Setup_io {
	Setup_io() {
		ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
		cout << fixed << setprecision(15);
	}
} setup_io;

int main() {
	vi a;
	int n,nn;
	cin >> n;
    nn=n;
	n -= 3;
	a.pb(6);
	a.pb(10);
	a.pb(15);
	if (n > 0)a.pb(12);
	n--;
	rep2(i, 16, 10000) {
		if (n <= 0)break;
		if (i % 6 == 0) {
			a.pb(i);
			n--;
		}
		else if (i % 10 == 0) {
			a.pb(i);
			n--;
		}
		else if (i % 15 == 0) {
			a.pb(i);
			n--;
		}
	}
	//cout << a.size() << endl;
	rep(i, nn - 1)cout << a[i] << " ";
	cout << a[nn - 1] << endl;
	return 0;
}

#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
#define mp make_pair
#define pb push_back
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define First(n) cout << ((n) ? "First" : "Second"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define vl vector<ll>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

int main(){
    SS(ll,N,K)
    ll ans=0;
    ll ans2=0;
    ll R,L;
    for(R=2;R<=2*N;R++){
        L=R-K;
        if(L>=2&&L<=2*N){
            //cout<<R<<" "<<L<<endl;
            ll tempL,tempR;
            if(L==2*N)tempL=1;
            else tempL=L-1;
            if(tempL>N)tempL-=(tempL-N)*2;

            if(R==2*N)tempR=1;
            else tempR=R-1;
            if(tempR>N)tempR-=(tempR-N)*2;

            ans+=tempR*tempL;
        }
    }
    p(ans);
}


//   *    Author :   Debapriya010   :  DEBAPRIYA CHANDRA
//   *    Jalpaiguri  Government  Engineering  College

#include<algorithm>
#include<bits/stdc++.h>
#define ll  long long int
#define dbl long double
#define loop(i,n) for(int i=0;i<n;i++)
#define rloop(i,n) for(int i=n-1;i>=0;i--)
#define test(t) int t;cin>>t;while(t--)
#define debo ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define vi vector<ll>
#define sz size()
#define iss is_sorted
#define bs binary_search
#define mod 1000000007
#define c1_Bin  __builtin_popcountll
#define yos cout<<"YES"<<endl
#define nos cout<<"NO"<<endl
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define vep vector<pair<ll,ll>>
#define mp map<ll,ll>
#define all(v) v.begin(),v.end()
#define tos to_string

using namespace std;

bool isPrime(ll  n)
{
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
}
bool IsPalindrome( string  str)
{
    if (str.empty())
        return false;

    ll i = 0;                // first characters
    ll j = str.length() - 1; // last character

    while (i < j)
    {
        if (str[i] != str[j])
        {
            return false;
        }
        i++;
        j--;
    }
    return true;
}

// Binary Exponentiation fun to calculate pow in 0(logN)
ll binpow(ll a, ll b) {
    if (b == 0)
        return 1;
    ll res = binpow(a, b / 2);
    if (b % 2)
        return (res * res * a)%mod;

        return (res * res)%mod;
}

 signed main(){
     debo;

   // test(t){
   ll a,b,c,d;
   cin>>a>>b>>c>>d;
   int df1=a+b-c*d;
   ll df2=a+b+b-2*c*d;
   if(df2<df1)
   {
     ll c0=0;
     ll te=0;
     while(1)
     {
         ++c0;
         a+=b;
         te+=c;
         if(a<=te*d)break;
     }
     cout<<c0;
   }
   else
   {
       cout<<-1;
   }

  cout<<endl;
   // }
     return 0;
 }

#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    LL A, B, C, D;
    cin >> A >> B >> C >> D;
    if (D * C - B > 0) {
        cout << A / (D * C - B) + (A % (D * C - B) ? 1 : 0) << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=998244353;
char str[20];
int n,a[20],f[1200005],ans=-1;
int main(){
	cin>>str+1;
	n=strlen(str+1);
	for(int i=1;i<=n;i++)a[i]=str[i]-'0';
	for(int i=1;i<=n;i++){
		f[1<<i-1]=a[i];
		if(f[i]%3==0)ans=max(ans,1);
	}
	for(int i=1;i<(1<<n);i++){
		if(__builtin_popcount(i)==1)continue;
		f[i]=f[i&-i]+f[i-(i&-i)];
		if(f[i]%3==0)ans=max(ans,__builtin_popcount(i));
	}
	if(ans==-1)cout<<ans;
	else cout<<n-ans;
    return 0;
}

#include <bits/stdc++.h>
#define rep(i, n)	for(ll i=0;i<(ll)(n);i++)
#define ALL(a)	(a).begin(),(a).end()
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;

ll pow2(ll n, ll a){
    ll res=1;
    rep(i,a) res*=n;
    return res;
}

int main(){
    ll n;
    cin>>n;
    ll s=1e18;
    for(ll a=1;pow2(3,a)<=s;a++){
        for(ll b=1;pow2(5,b)<=s;b++){
            if(pow2(3,a)+pow2(5,b)==n){
                cout<<a<<" "<<b<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<endl;
}


#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <random>
#include <numeric>
#include <cmath>
#include <complex>
#include <stack>
#include <memory>
#include <cstdio>
#include <iomanip>

using namespace std;
using ll = long long;

#define FOR(i,a,b)  for(ll i=ll(a); i<ll(b); i++)//  a<=i<b i++ のforの開始
#define FOR_(i,b,a) for(ll i=ll(b); ll(a)<i; --i)// b =>i>a i-- のforの開始
#define EACH(e,a) for(auto &(e):(a))//集合aの各要素eを当たる forの開始
#define FIND(e,a,i) vector<ll>::iterator itr=find((a).begin(),(a).end(),e);\
 if(itr!=(a).end()){i=itr-(a).begin();} else{i=-1;}//vector aの中に要素eはあるのかあるならindexをiに，なければiは-1
#define ALL(a) (a).begin(),(a).end()
#define MAX(a,i) vector<ll>::iterator itr0=max_element((a).begin(),(a).end());\
 i=(ll)(itr0-(a).begin());// vector<ll>の最大値の足をiに返す
#define MIN(a,i) vector<ll>::iterator itr1=min_element((a).begin(),(a).end());\
 i=(ll)(itr1-(a).begin());// vector<ll>の最小値の足をiに返す
#define ERASE(a,i) (a).erase((a).begin()+i);//iは0始まり
#define ERASES(a,i,j) (a).erase((a).begin()+i,(a).begin()+j);//i,jは0始まり i<= u <jの範囲を消す i!=j
#define SORT(a)  sort(begin(a),end(a))//小さい順にsort 1,2,3
#define SORT_(a) sort(begin(a),end(a),greater<ll>{})//大きい順にsort 5,4,3
#define OI(s) cout<<(s)<<endl
#define OI2(s0,s1) cout<<(s0)<<" "<<(s1)<<endl
#define OI3(s0,s1,s2) cout<<(s0)<<" "<<(s1)<<" "<<(s2)<<endl
#define OI4(s0,s1,s2,s3) cout<<(s0)<<" "<<(s1)<<" "<<(s2)<<" "<<(s3)<<endl
#define OIV(a) FOR(i,0,(a).size()){cout<<a[i]<<" ";} cout<<""<<endl;
#define OIVV(a) FOR(i,0,(a).size()){FOR(j,0,(a[i]).size()){cout<<a[i][j]<<" ";}cout<<" "<<endl;}
// vector<vector<ll>> A(5,vector<ll>(3,0));

int main()
{
    string S;
    cin >>S;
    ll ls;
    ls = S.size();
    vector<string> A(ls);
    //OIV(A);

    FOR(i,0,ls)
    {
        string s;
        s = S[ls-1-i];
        if(s=="0") A[i] = "0";
        else if(s=="1") A[i] = "1";
        else if (s=="6") A[i] ="9";
        else if(s=="8") A[i] ="8";
        else if(s=="9") A[i] = "6";

    }
    //OIV(A);

    FOR(i,0,ls)
    {
        cout<<A[i];
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
const long double pi = acos(-1);

// g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o

int main(){
//  ios_base::sync_with_stdio(false);
//  cin.tie(NULL);
 string s;
 cin>>s;
 int cnt=0;
 for(int i=0;i<(int)s.length();i++){
  if(s.substr(i,4)=="ZONe")cnt++;
 }
 cout<<cnt<<"\n";
 return 0;
}

// ALWAYS TAKE INITITAL MIN AS 2E18 AND INITITAL MAX AS -2E18
// ALWAYS TAKE INITIAL MAX AS 2E18 AND INITIAL MIN AS -2E18
// TAKE ALL INT VARIABLES AS LONG LONG INT
// READ WHEN WRITING BINARY SEARCH -
//    take care of the left and right limits while writing code for binary search -
//    l should be lower than min. possible ans, and r should be higher than max. possible ans
//    (MAX. POSSIBLE ANS CAN BE MORE THAN 1e18!!)


#include <bits/stdc++.h>
using namespace std;

typedef long long int lld;
#define all(m) m.begin(),m.end()
#define sz(m) lld(m.size())
#define pb push_back
#define mod 1000000007
#define st first
#define nd second
#define endl "\n"

#ifdef LOCAL
	#define debug(...) debug_out(#__VA_ARGS__, __VA_ARGS__)
	#define debug2(v,a,b) debug2_out(#v,v,a,b)
#else
	#define debug(...)
	#define debug2(v,a,b)
#endif

const int N=1e6+100;
void swagWaalaFunction()
{
	lld l,r,ans=0;
	cin>>l>>r;

	vector<lld> nfac(N);
	// Counts number of factors
	// stores -ve value if it is of form a1^x1 * a2^x2 ...., where a1,a2 are primes and some xi%2==0
	// Used to calculate mobius

	for(lld i=2;i<=r;i++)
	{
		if(nfac[i])
			continue;
		for(lld j=i;j<=r;j+=i)
			nfac[j]++;
		for(lld j=i*i;j<=r;j+=i*i)
			nfac[j]=-1e18;
	}

	// MOBIOUS MAGICCCC !!!
	for(lld i=2;i<=r;i++)
	{
		if(nfac[i]<0)
			continue;

		lld cnt=r/i-(l-1)/i;
		lld pairs=cnt*(cnt-1)/2;
		if(nfac[i]%2)
			ans+=pairs;
		else
			ans-=pairs;
	}

	// Remove multiples
	for(lld i=max(2LL,l);i<=r;i++)
		ans-=(r/i-1);

	ans*=2; // x,y and y,x are different
	cout<<ans<<endl;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);

	lld tc=1;
	//cin>>tc;

	for(int i=0;i<tc;i++)
	{
		// cout<<"Case #"<<i+1<<": ";
		swagWaalaFunction();
	}
	return 0;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ff                  first
#define ss                  second
#define pb                  push_back
#define eb                  emplace_back
#define mp                  make_pair
#define lb                  lower_bound
#define ub                  upper_bound
#define setbits(x)          __builtin_popcountll(x)
#define zrobits(x)          __builtin_ctzll(x)
#define sz(v)               (int)v.size()
#define ps(y)               cout << fixed << setprecision(y)
#define ms(arr, v)          memset(arr, v, sizeof(arr))
#define all(v)              v.begin(), v.end()
#define rall(v)             v.rbegin(), v.rend()
#define trav(x, v)          for(auto &x: v)
#define w(t)                int t; cin >> t; while(t--)
#define rep0(i, n)          for(int i = 0; i < n; i++)
#define rrep0(i, n)         for(int i = n - 1; i >= 0; i--)
#define rep1(i, n)          for(int i = 1; i <= n; i++)
#define rrep1(i, n)         for(int i = n; i > 0; i--)
#define inp(arr, n)         rep0(i, n) cin >> arr[i];
#define rep(i, a, b)        for(int i = a; i <= b; i++)
#define rrep(i, a, b)       for(int i = a; i >= b; i--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef map<ll, ll> mii;
typedef map<char, ll> mci;
typedef priority_queue<ll> pq_mx;
typedef priority_queue<ll, vi, greater<>> pq_mn;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> pbds;
/*
 * find_by_order(i) -> returns an iterator to the element at ith position (0 based)
 * order_of_key(i)  -> returns the position of element i (0 based)
 */

const int N = 2e6 + 5;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll inf = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void fio() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
}

const int M = 1e7 + 5;
ll spf[M], mobius[M];
vi primes;

void sieve() {
    rep(x, 2, 1e7) {
        if (spf[x] == 0) spf[x] = x, primes.pb(x);
        for (int y = 0; y < sz(primes) and primes[y] <= spf[x] and x * primes[y] <= 1e7; y++)
            spf[x * primes[y]] = primes[y];
    }
}

void Mobius() {
    /*
     * mobius[x] =  1 => x is a square-free +ve int with even no. of prime factors
     * mobius[x] = -1 => x is a square-free +ve int with odd no. of prime factors
     * mobius[x] =  0 => x has a squared prime factor
     */

    rep1(x, 1e7) {
        if (x == 1) mobius[x] = 1;
        else {
            if (spf[x] == spf[x / spf[x]]) mobius[x] = 0;
            else mobius[x] = -mobius[x / spf[x]];
        }
    }
}

int main() {
    fio();
    sieve();
    Mobius();

    ll l, r;
    cin >> l >> r;

    ll res = (r - l + 1) * (r - l + 1);
    rep(x, 1, r) {
        ll cur = r / x - (l - 1) / x;
        res -= cur * cur * mobius[x];
    }
//    cout << res << endl;
    rep(x, max(l, 2ll), r) {
        --res;
        for (int y = 2 * x; y <= r; y += x) res -= 2;
    }
    cout << res;

    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;

int ans;
char s[12];

void read(int &s)
{
	s = 0; bool pd = false; char c = getchar();
	while (c < '0' || c > '9')
	{
		if (c == '-') pd = true;
		c = getchar();
	}
	while (c >= '0' && c <= '9')
	{
		s = (s << 3) + (s << 1) + (c ^ 48);
		c = getchar();
	}
	if (pd) s = -s;
	return;
}

int main()
{
	scanf("%s", s);
	for (int i = 0; i <= 11; i++)
		if (s[i] == 'Z' && s[i + 1] == 'O' && s[i + 2] == 'N' && s[i + 3] == 'e')
			ans++, i += 3;
	printf("%d", ans);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main(){
    string S;
    cin >> S;
    int flagZ = 0, flagO = 0, flagN = 0, flage = 0;
    int count = 0;
    for(int i = 0; i < 12; i++){
        if(S.at(i) == 'Z'){
            flagZ = 1;
            continue;
        }
        if(S.at(i) == 'O' && flagZ == 1){
            flagO = 1;
            continue;
        }
        if(S.at(i) == 'N' && flagO == 1){
            flagN = 1;
            continue;
        }
        if(S.at(i) == 'e' && flagN == 1){
            count++;
            flagZ = 0;
            flagO = 0;
            flagN = 0;
            continue;
        }

        flagZ = 0;
        flagO = 0;
        flagN = 0;
    }
    cout << count << endl;
}


#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll r,x,y;

int main(void){
	scanf("%lld%lld%lld",&r,&x,&y);
	ll gg=r*r;
	ll dist=x*x+y*y;
	if(gg==dist){
		printf("%lld\n",1LL);
	}else if(gg>dist){
		printf("%lld\n",2LL);
	}else{
		ll l=0;
		ll rr=(x+y)/r+10LL;
		while(l+1LL<rr){
			ll mid=(l+rr)/2LL;
			ll ggg=gg*mid*mid;
			if(ggg>=dist){
				rr=mid;
			}else{
				l=mid;
			}
		}
		printf("%lld\n",rr);
	}
	return 0;
}


#include<bits/stdc++.h>
#define pb push_back
using namespace std;
#define G getchar()
int read()
{
	int x=0; bool flg=false; char ch=G;
	for (;!isdigit(ch);ch=G) if (ch=='-') flg=true;
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return flg?-x:x;
}
#undef G
#define fi first
#define se second
typedef long long ll;
/*const int mod=;
inline int upd(const int &x){return x+(x>>31&mod);}
inline void add(int &x,const int &y){x=upd(x+y-mod);}
inline void iadd(int &x,const int &y){x=upd(x-y);}
int qpow(int x,int y){
	int res=1;
	for (;y;y>>=1,x=1LL*x*x%mod)
		if (y&1) res=1LL*res*x%mod;
	return res;
}*/
#define rep(i,l,r) for (int i(l);i<=(r);i++)
#define per(i,l,r) for (int i(r);i>=(l);i--)

int n;
void solve(){
	n=read();
	rep(i,0,n-1){
		int x=i*2%n,y=(x+1)%n;
		printf("%d %d\n",x+1,y+1);
	}
}
int main()
{
	for (int T=1;T--;) solve();
}

using namespace std;
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#define w(x) int x;cin>>x;while(x--)
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define lld long double
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long int
int mod = 1e9 + 7;

void abc()
{
	FIO;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
}

int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}

	return gcd(b, a % b);
}

int po(int a, int b) {
	int res = 1;
	for (int i = 0; i < 32; i++) {
		if (b >> i & 1) {
			res = (res * a) % mod;
		}
		a = (a * a) % mod;
	}
	return res;
}

int fun(int n) {
	int res = 0;
	while (n) {
		res += n % 10;
		n /= 10;
	}
	return res;
}

void solve() {

	int a, b;
	cin >> a >> b;
	int res = max(fun(a), fun(b));
	cout << res;

}

signed main()
{
	abc();
	int tt   ;
	//cin >> tt;
	tt = 1;
	while (tt--) {
		solve();
	}
}


#include<bits/stdc++.h>

using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< mod >;

int main() {
  int N, P;
  cin >> N >> P;
  cout << modint(P - 1) * modint(P - 2).pow(N - 1) << "\n";
}

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

const ll mod = 1000000007;
//const ll mod = 998244353;

const int MAX_N = 100010;
ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N];

ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

void init(int x) {
    fact[0] = 1;fact[1] = 1;
    for (int i = 2;i <= x;++i) fact[i] = fact[i-1]*i%mod;
    fact_inv[x] = pow_mod(fact[x],-1);
    for (int i = x;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod;
    for (int i = 1;i <= x;++i) inv[i] = fact_inv[i]*fact[i-1]%mod;
}

ll combi(ll a, ll b) {
    return fact[a]*fact_inv[b]%mod*fact_inv[a-b]%mod;
}

int main() {
    ll n,p;
    cin >> n >> p;
    cout << pow_mod(p-2,n-1)*(p-1)%mod << newl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = (1<<30)-1;
const ll LINF = (1LL<<60)-1;

#define rep(i, n) for (int i = 0; i < n; i++)
#define sz(a) (int)(a.size())

template<class T>
bool chmax(T &a, T b) {if (a < b) {a = b;return true;}else return false;}

template<class T>
bool chmin(T &a, T b) {if (a > b) {a = b;return true;}else return false;}

ll mod_pow(ll a, ll n, ll p) {
    ll  ans = 1, tmp = a % p;
    while (n > 0) {
        if (n & 1)
            ans = ans * tmp % p;
        tmp = tmp * tmp % p;
        n = (n>>1);
    }
    return ans;
}

//コーナーケースに気をつけろ！
int main() {
    ll n, m, mod = 998244353, ans = 0, tmp = 0;    cin >> n >> m;
    ans = n * mod_pow(m, n, mod) % mod;

    for (ll l = 1; l <= n-1; l++) {
        for (ll x = 1; x <= m; x++) {
            tmp = (tmp + (n-l) * mod_pow(m, n-l-1, mod) % mod * mod_pow(m-x, l-1, mod) % mod) % mod;
        }
    }
    cout << (ans + mod - tmp) % mod << endl;
    return 0;
}

//小数点精度
//cout << fixed << std::setprecision(15) << y << endl;

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

struct UnionFind{
   vector<int> par; int n;
   UnionFind(){}
   UnionFind(int _n):par(_n,-1),n(_n){}
   int root(int x){return par[x]<0?x:par[x]=root(par[x]);}
   bool same(int x,int y){return root(x)==root(y);}
   int size(int x){return -par[root(x)];}
   bool unite(int x,int y){
      x=root(x),y=root(y); if(x==y)return false;
      if(size(x)>size(y))swap(x,y);
      par[y]+=par[x]; par[x]=y; n--; return true;
   }
};

template<unsigned mod=998244353>struct fp {
   using uint=unsigned; uint v;
   static uint get_mod(){return mod;}
   int inv() const{
      int tmp,a=v,b=mod,x=1,y=0;
      while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
      if(x<0){x+=mod;} return x;
   }
   fp(ll x=0){init(x%mod+mod);}
   fp& init(uint x){v=(x<mod?x:x-mod); return *this;}
   fp operator-()const{return fp()-*this;}
   fp pow(ll t){fp res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;} return res;}
   fp& operator+=(const fp& x){return init(v+x.v);}
   fp& operator-=(const fp& x){return init(v+mod-x.v);}
   fp& operator*=(const fp& x){v=ll(v)*x.v%mod; return *this;}
   fp& operator/=(const fp& x){v=ll(v)*x.inv()%mod; return *this;}
   fp operator+(const fp& x)const{return fp(*this)+=x;}
   fp operator-(const fp& x)const{return fp(*this)-=x;}
   fp operator*(const fp& x)const{return fp(*this)*=x;}
   fp operator/(const fp& x)const{return fp(*this)/=x;}
   bool operator==(const fp& x)const{return v==x.v;}
   bool operator!=(const fp& x)const{return v!=x.v;}
   friend istream& operator>>(istream& is,fp& x){is>>x.v; return is;}
   friend ostream& operator<<(ostream& os,fp& x){os<<x.v; return os;}
}; using Fp=fp<>;
template<typename T>struct factorial {
   vector<T> Fact,Finv,Inv;
   factorial(int maxx){
      Fact.resize(maxx); Finv.resize(maxx); Inv.resize(maxx);
      Fact[0]=Fact[1]=Finv[0]=Finv[1]=Inv[1]=1;
      rep(i,2,maxx){Fact[i]=Fact[i-1]*i;} Finv[maxx-1]=Fact[maxx-1].inv();
      for(int i=maxx-1;i>=2;i--){Finv[i-1]=Finv[i]*i; Inv[i]=Finv[i]*Fact[i-1];}
   }
   T fact(int n,bool inv=0){if(n<0)return 0; return (inv?Finv[n]:Fact[n]);}
   T inv(int n){if(n<0)return 0; return Inv[n];}
   T nPr(int n,int r,bool inv=0){if(n<0||n<r||r<0)return 0; return fact(n,inv)*fact(n-r,inv^1);}
   T nCr(int n,int r,bool inv=0){if(n<0||n<r||r<0)return 0; return fact(n,inv)*fact(r,inv^1)*fact(n-r,inv^1);}
};

Fp pre[5010][5010];

int main(){
   int n,m;
   cin>>n>>m;
   rep(x,1,5005){
      pre[x][0]=1;
      rep(t,0,5005)pre[x][t+1]=pre[x][t]*x;
   }

   Fp res;
   rep(len,1,n+1)rep(v,1,m+1){
      if(len==n){
         res+=(pre[m-v+1][n]-pre[m-v][n]);
         continue;
      }
      res+=(pre[m-v+1][len]-pre[m-v][len])*(v-1)*pre[m][max(0,n-len-1)]*2;
      res+=(pre[m-v+1][len]-pre[m-v][len])*(v-1)*(v-1)*pre[m][max(0,n-len-2)]*max(0,n-len-1);
   }
   cout<<res<<'\n';
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define A(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define int int64_t
void _read();
int mod;
inline int inv(int a) {
  	a %= mod;
  	if (a < 0) a += mod;
  	int b = mod, u = 0, v = 1;
  	while (a) {
  		int t = b / a;
  		b -= t * a; swap(a, b);
  		u -= t * v; swap(u, v);
  	}
  	assert(b == 1);
  	if (u < 0) u += mod;
  	return u;
}
void test() {
	int n,s,k;
	cin >> n >> s >> k;
	mod = n;
	// kx == s;
	int d = __gcd(k,n);
	if(s % d) {
		cout << -1 << '\n';
		return;
	}
	k /= d;
	s /= d;
	n /= d;
	mod = n;
	s %= mod;
	k %= mod;
	int y = inv(k);
	int ans = (s * y) % mod;
	cout << mod - ans << '\n';
}
main () { _read();

	int tc;
	cin >> tc;
	while(tc--) test();
	return 0;
};

void _read() {
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef LOCAL
	freopen("input.txt","r",stdin);
	#endif
}

#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define ll long long int
#define f first
#define s second
using namespace  std;
ll mod=1e9+7;
struct gcd_type
{
    ll x,y,g;
};
gcd_type ext_gcd(ll a,ll b)
{
    if(b==0) return{1,0,a};
    gcd_type p= ext_gcd(b,a%b);
    return {p.y,p.x-a/b*p.y,p.g};
}
ll shift(ll a,ll add)
{
    ll l=0,r=(abs(a)/add)+5,ans;
    while(l<=r)
    {
        ll mid=(l+r)/2;
        if(mid*add>-a)ans=mid,r=mid-1;
        else l=mid+1;
    }
    a+=ans*add;
    //cout<<ans<<">>>"<<endl;
    return a;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        ll n,s,k;
        cin>>n>>s>>k;
        gcd_type q=ext_gcd(k,n);
        if(s%q.g!=0)cout<<"-1"<<endl;
        else
        {
            q.x*=s/q.g,q.y*=s/q.g;
            ll x=q.x,y=q.y,g=q.g,lcm=(n*k)/g;
            ll num=(((y%(k/g))*(n%lcm)-s%lcm)%lcm+lcm);
           //cout<<x<<" "<<y<<" "<<num<<"::::"<<endl;
            cout<<(num%lcm)/k<<endl;
        }
    }
    return 0;
}


//#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
ll H[200001],W[200001];
ll saleft[200001],saright[200001];
int main(){
	int N,M;
	scan(N>>M);
	rep(i,N) scan(H[i]);
	rep(j,M) scan(W[j]);
	sort(H,H+N);
	sort(W,W+M);
	rep(i,N/2){
		saleft[i+1]=saleft[i]+abs(H[2*i]-H[2*i+1]);
	}
	brep1(i,N/2){
		saright[i-1]=saright[i]+abs(H[2*i]-H[2*i-1]);
	}
	ll ans=INFl;
	rep(j,M){
		int soeji=lower_bound(H,H+N,W[j])-H;
		int iti=soeji/2;
		int taisho=iti*2;
		debug(j,W[j],soeji,iti,taisho);
		debug(H[taisho]);
		ll sum=saleft[iti]+saright[iti]+abs(H[taisho]-W[j]);
		chmin(ans,sum);
	}
	prin(ans);
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
static int IN(void)
{
  int x=0,f=1,c;while(c=getchar(),c<48||c>57){if(c==45)f=-f;}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f*x;
}
static void OUT(long x){if(x<0){putchar('-'),x=-x;}if(x>=10){OUT(x/10);}putchar(x-x/10*10+48);}
typedef struct List{int nx,v,c,d;}edge;
int hsz=0;long minHeap[200001][2],output[2];
static void PUSH(int id,long key)
{
  int i=++hsz,j=i>>1;long sw[2];
  minHeap[i][0]=id,minHeap[i][1]=key;
  while(j)
  {
    if(minHeap[i][1]<minHeap[j][1])
    {
      sw[0]=minHeap[j][0],sw[1]=minHeap[j][1];
      minHeap[j][0]=minHeap[i][0],minHeap[j][1]=minHeap[i][1];
      minHeap[i][0]=sw[0],minHeap[i][1]=sw[1];
      i=j;j>>=1;
    }else break;
  }
}
static void POP(void)
{
  int i=1,j=i+1;long sw[2];
  output[0]=minHeap[i][0],output[1]=minHeap[i][1];
  minHeap[i][0]=minHeap[hsz][0],minHeap[i][1]=minHeap[hsz--][1];
  while(j<=hsz)
  {
    if(j<hsz&&minHeap[j^1][1]<minHeap[j][1]){j^=1;}
    if(minHeap[j][1]<minHeap[i][1])
    {
      sw[0]=minHeap[j][0],sw[1]=minHeap[j][1];
      minHeap[j][0]=minHeap[i][0],minHeap[j][1]=minHeap[i][1];
      minHeap[i][0]=sw[0],minHeap[i][1]=sw[1];
      i=j;j=i<<1;
    }else break;
  }
  return;
}
int main(void)
{
  int N=IN(),M=IN(),vis[100000],esz=0,adj[100000];
  long dist[100000];edge e[200000];
  rep(i,N){dist[i]=9e18;}
  rep(i,M)
  {
    int A=IN(),B=IN(),C=IN(),D=IN();
    e[2*i].nx=adj[A-1];adj[A-1]=2*i+1;
    e[2*i].v=B;e[2*i].c=C;e[2*i].d=D;
    e[2*i+1].nx=adj[B-1];adj[B-1]=2*i+2;
    e[2*i+1].v=A;e[2*i+1].c=C;e[2*i+1].d=D;
  }
  dist[0]=0l;
  PUSH(1,0l);
  while(hsz)
  {
    POP();
    int u=output[0]-1;long v=output[1];
    if(vis[u]){continue;}
    for(int i=adj[u];i;i=e[i-1].nx)
    {
      int c=e[i-1].c,d=e[i-1].d,to=e[i-1].v;long len=0l;
      if(d)
      {
        int x=sqrt(d)-1;
        if(d/(x+1)>1+d/(x+2)){x++;}
        if(d/(x+1)>1+d/(x+2)){x++;}
        if(v>1l*x){len=1l*c+1l*d/(v+1l);}
        else{len=1l*c+1l*x-v+1l*d/(1l*x+1l);}
      }else{len=1l*c;}
      if(dist[to-1]>v+len){dist[to-1]=v+len;PUSH(to,v+len);}
    }
    vis[u]=1;
  }
  if(dist[N-1]==9e18){puts("-1");}else OUT(dist[N-1]);
}


#define _DEBUG
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const ll INF=1e+18;
const int MOD=1e+9+7;

//デバッグ
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug1(x1) cout<<#x1<<": "<<x1<<endl
#define debug2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug5,debug4,debug3,debug2,debug1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//省略
using vi  = vector<int>;
using vii = vector<vector<int>>;
using vl  = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
    ll N,K;
    cin>>N>>K;
    vl a(N-1,0);
    REP(i,N-1){
        a[i]=i+1;
    }

    vll G(N,vl(N,0));
    REP(i,N){
        REP(j,N){
            cin>>G[i][j];
        }
    }
    ll ans=0;
    sort(a.begin(),a.end());
    do{
        vl b(N);
        REP(i,N-1){
            b[i]=a[i];
        }
        b[N-1]=0;
        ll tmp=0;
        ll cur=0;
        REP(i,N){
            tmp+=G[cur][b[i]];
            cur=b[i];
        }
        if(tmp==K) ans++;
    }while(next_permutation(a.begin(),a.end()));
    cout<<ans<<endl;

}

#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define int long long int
#define ld long double
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
#define endl '\n'
#define setbits(x) (__builtin_popcount(x))
int mod=1000000007;
int INF64=mod*mod+1;

void solve(){
	int n,k;
	cin>>n>>k;
	vector<vector<int>> d(n,vector<int> (n));

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

	int ans=0;
	vector<int> perm(n-1);
	iota(all(perm),1);
	do{
		int curr=d[0][perm[0]]+d[0][perm.back()];
		for(int i=0;i<n-2;i++)
			curr+=d[perm[i]][perm[i+1]];
		ans+=(curr==k);
	}while(next_permutation(all(perm)));

	cout<<ans<<endl;
}

int32_t main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);

	int T=1;
	// cin>>T;
	for(int i=1;i<=T;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
}