#include <iostream>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <algorithm>

using ll = long long;
#define fast_io                                                                                \
    ios::sync_with_stdio(false);                                                                                \
    cin.tie(0)

using namespace std;
int dx[4] = { 0,0,1,-1 };
int dy[4] = { 1,-1,0,0 };

void solve(ll t) {
	ll n;
	cin >> n;
	vector<vector<ll>> c(n, vector<ll>(n));

	ll num = INT_MAX;
	ll x, y;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> c[i][j];
			if (c[i][j] < num) {
				num = c[i][j];
				x = i;
				y = j;
			}
		}
	}

	vector<vector<ll>> c1(c);

	vector<ll> a(n), b(n);
	vector<ll> tmp = c[x];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			c[i][j] -= tmp[j];
		}
	}

	//for (int i = 0; i < n; i++) {
	//	for (int j = 0; j < n; j++) {
	//		cout<<c[i][j]<<" ";
	//	}
	//	cout << endl;
	//}

	for (ll i = 0; i < n; i++) {
		int flag = 1;
		for (ll j = 0; j < n; j++) {
			if (c[i][j] != c[i][0]) {
				flag = 0;
				break;
			}
		}

		if (flag == 1) {
			a[i] = c[i][0];
		}
		else {
			cout << "No" << endl;
			return;
		}
	}

	c = c1;
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < n; j++) {
			c[i][j] -= a[i];
		}
	}

	for (ll j = 0; j < n; j++) {
		ll flag = 1;
		for (ll i = 0; i< n; i++) {
			if (c[i][j] != c[0][j] || c[i][j] < 0) {
				flag = 0;
				break;
			}
		}

		if (flag == 1) {
			b[j] = c[0][j];
		}
		else {
			cout << "No" << endl;
			return;
		}
	}

	cout << "Yes" << endl;
	cout << a[0];
	for (ll i = 1; i < n; i++) {
		cout << " " << a[i] ;
	}
	cout << endl;

	cout << b[0];
	for (ll i = 1; i < n; i++) {
		cout << " " << b[i] ;
	}
	cout << endl;

}

int main(void)
{
	ll t = 0;
	//cin >> t; for (ll i = 1; i <= t; i++) {solve(i);}
	solve(t);
	return 0;
}

#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
#define SZ(x) ((int)(x).size())

#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T>
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template<typename T>
inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } }
template <typename T>
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}

/*

*/

ll n,m,x,y;
vector<ll>a,b,t,k;

struct edge{
	int to,cost,mult;
};

vector<edge> g[100010];
vector<ll>dist;

void dijkstra(int s){
	priority_queue<P,vector<P>,greater<P> > pq;
	dist.resize(n,INF);
	dist[s]=0;
	pq.push({0,s});

	while(!pq.empty()){
		P p = pq.top();pq.pop();
		int v = p.second;
		if(dist[v]<p.first)continue;
		for(auto e:g[v]){
			ll time = (dist[v]+e.mult-1)/e.mult*e.mult+e.cost;
			if(dist[e.to]>time){
				dist[e.to]=time;
				pq.push({dist[e.to],e.to});
			}
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	cin >> n >> m >> x >> y;
	x--;y--;
	a.resize(m);
	b.resize(m);
	t.resize(m);
	k.resize(m);
	rep(i,m){
		cin>>a[i]>>b[i]>>t[i]>>k[i];
		a[i]--;b[i]--;
	}
	rep(i,m){
		g[a[i]].push_back({b[i],t[i],k[i]});
		g[b[i]].push_back({a[i],t[i],k[i]});
	}
	dijkstra(x);
	if(dist[y]==INF)cout<<-1<<endl;
	else cout << dist[y] << endl;
	//debug(dist);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <climits>

using namespace std;

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

#define DEBUG printf("Passing [%s] in Line %d\n" , __FUNCTION__ , __LINE__) ;
#define Fast  ios::sync_with_stdio(false);
#define REP(i, n) for (int i=0;i<n;++i)
#define FOR(i, a, b) for (int i=a;i<b;++i)
#define DWN(i, b, a) for (int i=b-1;i>=a;--i)
#define REP_1(i, n) for (int i=1;i<=n;++i)
#define FOR_1(i, a, b) for (int i=a;i<=b;++i)
#define DWN_1(i, b, a) for (int i=b;i>=a;--i)
#define CLR(a, b) memset((a),(b),sizeof((a)))

#define sz(A) int((A).size())
#define pb push_back
#define fi first
#define se second

typedef long long lli;
typedef double DB;
typedef unsigned uint;
typedef unsigned long long uLL;
typedef pair<int, int> P;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;

const int MOD = int(1e9) + 7;
const int INF = 0x3f3f3f3f;
const lli INFF = 0x3f3f3f3f3f3f3f3fLL;
const DB EPS = 1e-9;
const DB OO = 1e20;
const DB PI = acos(-1.0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const int MAXN = 50000 + 9;

inline int read() {
    char c = getchar();
    int x = 0, f = 1;
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

bool isPrime(int u) {
    for (int i = 2; i * i <= u; ++i) {
        if (u % i == 0) return false;
    }
    return true;
}

vi primes;

lli get(lli u) {
    lli val = 0;
    FOR(i, 0, sz(primes))if (u % primes[i] == 0) val += (1LL << i);
    return val;
}

lli calc(lli u) {
    lli val = 1;
    FOR(i, 0, sz(primes))if (u & (1LL << i)) val *= primes[i];
    return val;
}

int main() {
    Fast;
    FOR(i, 2, 51) if (isPrime(i)) primes.pb(i);
    lli ans = 1LL;
    for (auto it : primes) ans *= it;
    lli n;
    cin >> n;
    vi v(n);
    FOR(i, 0, n) cin >> v[i], v[i] = get(v[i]);
    lli sz = sz(primes);
    FOR(i, 1, 1LL << sz) {
        lli x = i;
        for (auto it : v) if (!(x & it)) x = 0;
        if (x > 0) ans = min(ans, calc(x));
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
#define ll long long

#define float double
#define sz 100005
#define all(a) a.begin(), a.end()
#define mod 1000000007
using namespace std;
#define vi vector<int>
#define vvi vector<vector<int>>
#define debug cout << "here" << endl;
#define f(i, n) for (int i = 0; i < n; ++i)
#define pb push_back
#define ff first
#define ss second
#define pi pair<int, int>
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define p(x) cout << x << " ";
#define pe(x) cout << x << endl;
using namespace std;

// ------------------------------linked list node------------------------
class Node
{
public:
    int val;
    Node *next;

    Node(int vale)
    {
        val = vale;
        next = NULL;
    }
};
//--------------------------------linked list class ---------------------
class LL
{
public:
    Node *head;
    Node *tail;
    LL()
    {
        head = NULL;
        tail = NULL;
    }
    void insert(int data)
    {
        // cout << data << endl;
        Node *newNode = new Node(data);
        // cout << newNode->val << endl;
        if (head == NULL)
        {
            head = newNode;
            tail = newNode;
        }
        else
        {
            tail->next = newNode;
            tail = newNode;
        }
    }
};
//----------------------------TreeNode -----------------------
class TreeNode
{
public:
    int val;
    TreeNode *left;
    TreeNode *right;

    TreeNode(int x)
    {
        val = x;
        left = NULL;
        right = NULL;
    }
};
//---------------------------fast modulo exponetion ------ ---
ll pwr(ll a, ll b)
{
    a = a % mod;
    if (a == 0)
        return 0;
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
        {
            res = (res * a) % mod;
        }
        b = b >> 1;
        a = (a * a) % mod;
    }
    return res;
}

int main()
{
    ios ::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt",
            "r", stdin);
    freopen("output.txt",
            "w", stdout);
#endif
    int t;
    // cin >> t;
    t = 1;
    while (t--)
    {
        int n;
        cin >> n;
        vector<pair<int, string>> help(n);

        for (int i = 0; i < n; ++i)
        {
            cin >> help[i].second;
            cin >> help[i].first;
        }
        sort(help.begin(), help.end());

        cout << help[help.size() - 2].second << endl;
    }

#ifndef ONLINE_JUDGE
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
#endif
}


#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
typedef long double ld;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power (int a, int b = mod - 2)
{
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

//cp-algo
int gcd(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int x1, y1;
    int d = gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

bool find_any_solution(int a, int b, int c, int &x0, int &y0, int &g) {
    g = gcd(abs(a), abs(b), x0, y0);
    if (c % g) {
        return false;
    }

    x0 *= c / g;
    y0 *= c / g;
    if (a < 0) x0 = -x0;
    if (b < 0) y0 = -y0;
    return true;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	read(t);
	while (t--)
	{
	    readc(n, s, k);
	    int x, y, g;
	    bool status = find_any_solution(n, -k, s, x, y, g);
	    if (!status) {cout << -1 << endl; continue;}

	    n /= g;
	    int z = y/n, ans = inf;
	    if (y - z*n > 0) ans = min(ans, y - z*n);
	    if (y - (z - 1)*n > 0) ans = min(ans, y - (z - 1)*n);
	    print(ans);
	}
}

// Problem: C - Squared Error
// Contest: AtCoder - AtCoder Beginner Contest 194
// URL: https://atcoder.jp/contests/abc194/tasks/abc194_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pi  3.141592653589793238462643383279
#define int long long
#define ff first
#define ss second
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define high_functioning_sociopath  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const unsigned int M = 998244353;
/*_____________________________THE GAME IS ON_____________________________*/
void solve()
{
      int n;
      cin >> n;
      vector<int>v(n);
      for(int i=0;i<n;i++) cin >> v[i];
      int suf1[n]={0};
      int suf2[n]={0};
      suf1[n-1] = v[n-1];
      suf2[n-1] = (v[n-1]*v[n-1]);
      for(int i=n-2;i>=0;i--)
      {
      	  suf1[i] = suf1[i+1] + v[i];
      	  suf2[i] = suf2[i+1] + (v[i]*v[i]);
      }
      int res = 0;
      int j = n-1;
      for(int i=0;i<n-1;i++)
      {
      	   int a = v[i]*v[i];
      	   a*=j;
      	   //cout << suf2[i+1] << " " << suf1[i+1] << endl;
      	   int b = suf2[i+1] - (2*v[i]*suf1[i+1]) + a;
      	   res+=b;
      	   j--;
      }
      cout << res ;
}
int32_t main()
{
   high_functioning_sociopath
   //pre();
   ll t=1;
  // cin>>t;
   while(t--)
   {
      solve();
   }
}


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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()

typedef long long ll;

#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)

#define fi first
#define se second

const int N = 2e5+10;

namespace diametro_space{
int n;
vector<int> *g;

void dfs(int no, int from, int dac, ll d[]){
	d[no] = dac;
	for(auto it : g[no]){
		if(it!=from) dfs(it,no,dac+1,d);
	}
}

int max_dist_glob = 0; // diametro da arvore

int get_most_dist(int no, ll d[]){
	dfs(no,-1,0,d);
	int max_dist_cur = -1;
	int no_max_dist = -1;
	fr(i,n){
		if(d[i]>max_dist_cur){
			max_dist_cur = d[i];
			no_max_dist = i;
		}
	}
	max_dist_glob = max(max_dist_glob,max_dist_cur);
	return no_max_dist;
}

vector<int> nos_diam;

int no0, no1;

//retorna diametro em numero de arestas! (ou seja, vertices -1)
ll find_diametro(vector<int> _g[N], int _n, ll vd[2][N]){
	g = _g;
	n = _n;
	max_dist_glob = 0;

	no1 = get_most_dist(0,vd[0]);
	no0 = get_most_dist(no1,vd[1]);
	get_most_dist(no0,vd[0]);

	fr(i,n){
		if(vd[0][i]+vd[1][i]==max_dist_glob) nos_diam.push_back(i);
	}

	return max_dist_glob;
}

}; //end space diametro

namespace lca_space{
int nlog;
int n;
vector<int> *g;
int pai[N], dist[N]; //pai do nó i (raiz = -1)
int st[N][25]; //sparse table - st[i][j] = pai 2^j niveis acima do nó i

void dfs(int no, int from, int dac){
	dist[no] = dac;
	for(auto it : g[no]){
		if(it==from) continue;
		pai[it] = no;
		dfs(it,no,dac+1);
	}
}

void make(vector<int> _g[N], int _n, int root){
	g = _g;
	n = _n;

	pai[root] = -1;
	dfs(root,-1,0);

	nlog = 1;
	while((1<<nlog)<n) nlog++;
	assert(nlog<25);

	fr(i,n) fr(j,nlog+1) st[i][j] = -1;
	fr(i,n) st[i][0] = pai[i];

	for(int j = 1; j<=nlog; j++){
		fr(i,n){
		    int ant_pai = st[i][j-1];
		    if(ant_pai!=-1) st[i][j] = st[ant_pai][j-1];
		}
	}
}

int lca(int p, int q){
	if(dist[p]<dist[q]) swap(p,q);
	for(int i = nlog; i>=0;i--){
		if(dist[p]-dist[q] >= (1<<i) ) p = st[p][i];
	}
	if(p==q) return p;
	for(int i = nlog; i>=0; i--){
		if(st[p][i]!=st[q][i]){
			p = st[p][i];
			q = st[q][i];
		}
	}
	return pai[q];
}

int get_dist(int u, int v){
	return dist[u]+dist[v]-2*dist[lca(u,v)];
}

};

int ehdiam[N];
vector<int> g[N];
ll vdist[2][N];

struct cmp{
bool operator()(int a, int b){
	return ehdiam[a]<ehdiam[b];
}
};

ll cor = 1;
int ultno = -1;
ll vcor[N];

void dfs(int no, int from){
	if(from!=-1){
		cor+=lca_space::get_dist(ultno,no);
	}
	vcor[no] = cor;
	ultno = no;
	for(auto &it : g[no]){
		if(it==from) continue;
		dfs(it,no);
	}

}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	fr(i,n-1){
		int a, b; cin >> a >> b; a--,b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	//prin(n);

	diametro_space::find_diametro(g,n,vdist);
	vector<int> nos_diam = diametro_space::nos_diam;
	int root = diametro_space::no0;
	for(auto &i : nos_diam) ehdiam[i] = 1;

	fr(i,n) sort(all(g[i]),cmp());

	lca_space::make(g,n,root);

	//prinv(nos_diam);

	dfs(root,-1);

	fr(i,n){
		if(i) cout << " ";
		cout << vcor[i];
	}
	cout << "\n";
}

#include <bits/stdc++.h>
using namespace std;
#define deb(k) cerr << #k << ": " << k << "\n";
#define size(a) (int)a.size()
#define fastcin cin.tie(0)->sync_with_stdio(0);
#define st first
#define nd second
#define pb push_back
#define mk make_pair
#define int long long
typedef long double ldbl;
typedef double dbl;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<double, pii> pdii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef vector<int> vint;
#define MAXN 300100
#define MAXLG 20
const int inf = 0x3f3f3f3f;
const ll mod = 1000000007;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const int N = 300100;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int d[N];
vint g[N];
int cnt = 1;
int ans[N];
int pai[N];
set<int>dia;
vint cur;

void dfs(int x, int p = -1, int u = 1){
	d[x] = u;
	pai[x] = p;
	ans[x] = cnt;
	for(auto v : g[x]){
		if(v == p) continue;
		if(dia.count(v)) continue;
		cnt++;
		dfs(v, x, u+1);
	}
	if(dia.count(x) && !cur.empty()){
		int v = cur.back();
		cur.pop_back();
		cnt++;
		dfs(v, x, u+1);
	}

	cnt++;
}

void solve(){
	int n;
	cin>>n;
	for(int i=1;i<n;i++){
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}
	dfs(1);
	int mx = 0, ind = -1;
	for(int i=1;i<=n;i++){
		if(d[i] > mx){
			mx = d[i];
			ind  = i;
		}
	}
	cnt = 1;
	int root = ind;
	dfs(root);
	mx = 0, ind = -1;
	for(int i=1;i<=n;i++){
		if(d[i] > mx){
			mx = d[i];
			ind = i;
		}
	}
	int aux = ind;
	while(aux != -1){
		cur.pb(aux);
		dia.insert(aux);
		aux = pai[aux];
	}
	cur.pop_back();
	cnt = 1;
	dfs(root);
	for(int i=1;i<=n;i++) cout<<ans[i]<<" ";
	cout<<"\n";

	// Have you read the problem again?
	// Maybe you understood the wrong problem
}

int32_t main(){
	fastcin;
	int t_ = 1;
	//cin>>t_;
	while(t_--)
		solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  if(n%2) pr("Black");
  else pr("White");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
template<typename T>void rearrange(vector<ll>&ord, vector<T>&v){
  auto tmp = v;
  for(int i=0;i<tmp.size();i++)v[i] = tmp[ord[i]];
}
template<typename Head, typename... Tail>void rearrange(vector<ll>&ord,Head&& head, Tail&&... tail){
  rearrange(ord, head);
  rearrange(ord, tail...);
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int popcount(ll x){return __builtin_popcountll(x);};
int poplow(ll x){return __builtin_ctzll(x);};
int pophigh(ll x){return 63 - __builtin_clzll(x);};

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,m;cin>>n>>m;
  struct edge{
    ll to,id,rev;
  };
  vector<vector<edge>>g(n);
  rep(i,0,m){
    ll u,v;cin>>u>>v;u--;v--;
    g[u].PB({v,i,0});
    g[v].PB({u,i,1});
  }
  vector<ll>c(n);
  rep(i,0,n)cin>>c[i];
  vector<ll>ord(n);
  iota(ALL(ord),0);
  sort(ALL(ord),[&](ll i,ll j)
    {
      return c[i]<c[j];
    }
  );
  vector<bool>used(n);
  vector<ll>ed(m,-1);
  for(auto i:ord){
    if(used[i])continue;
    auto dfs=[&](auto &&f,ll k)->void{
      used[k]=true;
      for(auto e:g[k]){
        if(ed[e.id]!=-1)continue;
        if(c[e.to]>c[i])continue;
        ed[e.id]=e.rev;
        if(used[e.to])continue;
        f(f,e.to);
      }
    };
    dfs(dfs,i);
  }
  //debug(ed,m);
  rep(i,0,m){
    ans(!ed[i],"->","<-");
  }
  return 0;
}


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

int main(){
     int n,m,x,y;
     cin>>n>>m>>x>>y;

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

     x--;
     y--;

     int ans=0;
     if(ch[x][y]=='.')ans++;
     //left
     for(int i=x+1;i<n;++i){
         if(ch[i][y]=='.')ans++;
         else break;
     }
     for(int i=x-1;i>=0;--i){
         if(ch[i][y]=='.')ans++;
         else break;
     }

     for(int i=y+1;i<m;++i){
         if(ch[x][i]=='.')ans++;
         else break;
     }

     for(int i=y-1;i>=0;--i){
         if(ch[x][i]=='.')ans++;
         else break;
     }

     cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define Turnoff std::ios::sync_with_stdio(false)
const int Max=3e5+5;
const ll Mod=1e9+7;
/*
2 6
AGCTAG
CTAGCT
*/
int mp[105][105];

int main(){
    Turnoff;
    int n,m;cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            char temp;
            cin>>temp;
            if(temp=='.')mp[i][j]=1;
            else mp[i][j]=0;
        }
    }
    int cnt=0;
    for(int i=1;i<=n-1;i++){
        for(int j=1;j<=m;j++){
            if(mp[i][j]==mp[i+1][j]&&mp[i][j])cnt++;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m-1;j++){
            if(mp[i][j]==mp[i][j+1]&&mp[i][j])cnt++;
        }
    }
    cout<<cnt<<endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tree<iii, null_type, greater<iii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int N, K, ans = LLONG_MAX, A[805][805], P[805][805];
ordered_set S;

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> K;
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= N; j++) cin >> A[i][j];
	int lo = 0, hi = 1e9, ans = -1;
	int calc = K * K - ((K * K) / 2 + 1) + 1;
	while (lo <= hi) {
		int mid = (lo + hi) / 2;
		bool yes = 0;
		for (int i = 1; i <= N; i++)
			for (int j = 1; j <= N; j++) {
				P[i][j] = (A[i][j] <= mid);
				P[i][j] += P[i - 1][j] + P[i][j - 1] - P[i - 1][j - 1];
			}
		for (int i = 1; i <= N; i++)
			for (int j = 1; j <= N; j++) {
				if (i >= K && j >= K) {
					int tmp = P[i][j] - P[i - K][j] - P[i][j - K] + P[i - K][j - K];
					if (tmp >= calc) yes = 1;
				}
			}
		if (yes) ans = mid, hi = mid - 1;
		else lo = mid + 1;
	}
	cout << ans << '\n';
}

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

#define rep(i, a, b) for(int i=a; i<=b; i++)
#define trav(x, a) for(auto &x:a)
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_bacl
#define nl '\n'
#define f first
#define s second
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

template <ll Mod>
struct ModInt {
  ll n;

  ModInt(const ll x = 0) : n(x) {
    while (n < 0) n += Mod;
    n %= Mod;
  }
  explicit operator int() const { return n; }
  inline constexpr ModInt operator+(const ModInt r) const noexcept { return ModInt(*this) += r; }
  inline constexpr ModInt operator-(const ModInt r) const noexcept { return ModInt(*this) -= r; }
  inline constexpr ModInt operator*(const ModInt r) const noexcept { return ModInt(*this) *= r; }
  inline constexpr ModInt operator/(const ModInt r) const noexcept { return ModInt(*this) /= r; }
  inline constexpr ModInt &operator+=(const ModInt r) noexcept {
    n += r.n;
    if (n >= Mod) n -= Mod;
    return *this;
  }
  inline constexpr ModInt &operator-=(const ModInt r) noexcept {
    if (n < r.n) n += Mod;
    n -= r.n;
    return *this;
  }
  inline constexpr ModInt &operator*=(const ModInt r) noexcept {
    n = n * r.n % Mod;
    return *this;
  }
  inline constexpr ModInt &operator/=(const ModInt r) noexcept { return *this *= r.inv(); }

  inline constexpr ModInt pow(ll x) const noexcept {
    ModInt<Mod> ret(1), tmp(*this);
    while (x) {
      if (x&1) ret *= tmp;
      tmp *= tmp;
      x >>= 1;
    }
    return ret;
  }
  inline constexpr ModInt inv() const noexcept { return pow(Mod-2); }

  friend ostream& operator<<(ostream& os, const ModInt& obj) { return os << obj.n; }
  friend istream& operator>>(istream& is, ModInt& obj) {
    ll t;
    is >> t;
    obj = ModInt(t);
    return is;
  }
};

constexpr ll mod = 998244353; //check!
using mint = ModInt<mod>;
mint operator"" _mi(unsigned long long n) { return mint(n); }

int n;
int a[101];
mint dp[101][10001];
mint fac[101];

int main(){
	cin.tie(0)->sync_with_stdio(0);
	// freopen("input.txt", "r", stdin);

	cin >> n;
	int tot=0;
	rep(i, 1, n) cin >> a[i], tot+=a[i];
	if(tot&1){
		cout << 0; return 0;
	}

	fac[0]=1;
	rep(i, 1, n) fac[i]=fac[i-1]*i;

	dp[0][0]=1;
	rep(i, 1, n){
		for(int k=i; k>=1; k--) {
			for(int s=100*n; s>=0; s--) {
				if(a[i]<=s) dp[k][s]+=dp[k-1][s-a[i]];
			}
		}
	}

	mint ans=0;
	rep(i, 1, n-1){
		ans+=dp[i][tot/2]*fac[i]*fac[n-i];
		// cout << "added " << dp[i][tot/2] << "*" << fac[i] << "*" << fac[n-i] << nl;
	}
	cout << ans;
}
// w_i > tot/2 -> 0
// step 1: # ways to make sum tot/2
// step 2: each contributes 2*n1!*n2! cuz they force

// dp[k][s] = # ways to have k elements sum to s


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <numeric>
#include <functional>
#include <chrono>
#include <utility>
#include <iomanip>
#include <assert.h>

using namespace std;

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

#define rng_init mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define rng_seed(x) mt19937 rng(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
// #define int long long

const int MXN = 2e5 + 5, INF = 1e9 + 5;
vector<int> g[MXN], level[MXN];
int timer;
int tin[MXN], tout[MXN];

void dfs(int u, int p, int depth) {
    tin[u] = timer++;
    level[depth].push_back(tin[u]);

    for (const auto &v : g[u]) {
        if (v == p) continue;
        dfs(v, u, depth + 1);
    }

    tout[u] = timer - 1;
}

void solve() {
    int N;
    cin >> N;

    for (int i = 1; i < N; i++) {
        int p;
        cin >> p;
        p--;

        g[i].push_back(p);
        g[p].push_back(i);
    }

    dfs(0, -1, 0);

    int Q;
    cin >> Q;

    while (Q--) {
        int u, d;
        cin >> u >> d;
        u--;

        auto l = lower_bound(all(level[d]), tin[u]);
        auto r = upper_bound(all(level[d]), tout[u]);

        cout << r - l << "\n";
    }
}

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

    int TC = 1;
    // cin >> TC;
    while (TC--) solve();
}

#include <bits/stdc++.h>

using namespace std;

// using mint = long double;
// using mint = modint998244353;
// using mint = modint1000000007;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;
typedef pair<ll, vector<ll>> Pd;

const ll INF = 1e18;
const ll fact_table = 320000;

priority_queue<ll> pql;
priority_queue<P> pqp;
// big priority queue
priority_queue<ll, vector<ll>, greater<ll>> pqls;
priority_queue<P, vector<P>, greater<P>> pqps;

// small priority queue
// top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
//↓,→,↑,←

/*
#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif
*/

#define p(x) cout << x << "\n";
#define el cout << endl;
#define pe(x) cout << x << " ";
#define ps(x) cout << fixed << setprecision(25) << x << endl;
#define pu(x) cout << (x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = a; i <= (b); i++)
#define rep3(i, a, b) for (ll i = a; i >= (b); i--)
#define all(c) begin(c), end(c)
#define sorti(v) sort(all(v))
#define sortd(v)                                                               \
    sort(all(v));                                                              \
    reverse(all(v));
#define SUM(v) accumulate(all(v), 0LL)
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

// vec v(n) -> 長さnのベクトルを宣言
// mat dp(h, vec(w)) -> h * w の行列を宣言

const ll mod = 998244353ll;

ll mypow(ll a, ll b, ll m = mod) {
    ll x = 1;
    while (b) {
        while (!(b & 1)) {
            (a *= a) %= m;
            b >>= 1;
        }
        (x *= a) %= m;
        b--;
    }
    return x;
}
vec rv(ll read) {
    vec res(read);
    for (int i = 0; i < read; i++) {
        cin >> res[i];
    }
    return res;
}
/*
ll fact[fact_table + 5], rfact[fact_table + 5];

void c3_init() {
    fact[0] = rfact[0] = 1;
    for (ll i = 1; i <= fact_table; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
    for (ll i = fact_table; i >= 1; i--) {
        rfact[i - 1] = rfact[i] * i;
        rfact[i - 1] %= mod;
    }
    return;
}

ll c3(ll n, ll r) {
    return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod;
}
*/
bool icpc = false;
bool multicase = false;

ll n, m, k, a, b, c;
string s;
ll x[500005], y[500005], z[500005];

bool solve() {
    ll ans = 0;
    cin >> s;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) {
                for (int l = 0; l < 10; l++) {
                    set<ll> st;
                    st.insert(i);
                    st.insert(j);
                    st.insert(k);
                    st.insert(l);
                    bool ok = true;
                    for (int i = 0; i < 10; i++) {
                        if (s[i] == 'o' && !st.count(i)) ok = false;
                        if (s[i] == 'x' && st.count(i)) ok = false;
                    }
                    if (ok) ans++;
                }
            }
        }
    }
    p(ans);
    return true;
}

/*

*/

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

    if (icpc) {
        while (solve())
            ;
        return 0;
    }
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // cout << "Case #" << testcase << ": ";
        solve();
        testcase++;
    }

    // solve();
    return 0;
}


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

#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout if (false) cout
#define debug() if (false)
#define dvout(v) if(false) vout(v)
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vecll(v, n) vector<ll> v(n, 0);
#define vecvec(v,n,m) vector<vector<int>> v(n, vector<int>(m));
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力

#define mod (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"

//	LLONG_MAX 9.2*1e18	9223372036854775807LL = (2^63)-1
//	INT_MAX 2.1*1e9 2147483647 = (2^31)-1
//	O(1e8) 1.2sec
void test(ull,ull,ull);

void Main()
{
	char S,T;
	cin>>S>>T;
	if(S=='Y'){
		T+='A'-'a';
	}

	cout<<T<<endl;
}

void test(ull N,ull X, ull M){
 ull ans=0;
	int t=X;
	rep(i,N){
		ans+=t;
		t=(t*t)%M;
	}
	dout<<"testans"<<ans<<_n<<_n;
}
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve(int num = 0) {
  ll i, j, n, m, ans = 0;
	cin >> n;

	i = 1000;
	int counter = 1;
	while(n/i) {
		ans += n%i + 1;
		ans +=(n/i - 1)*i;
		i *= 1000;
	}

	cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1, cr = 0;
    // cin >> t;
    while(t--) {
      solve(cr++);
    }

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
    u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}


#include <bits/stdc++.h>

using namespace std;

#define dump(x) cerr << "~ " << #x << " = " << x << endl

int main() {

    ios_base::sync_with_stdio(false); cin.tie(NULL);

    int n;
    string s,mat[5];
    long long len = 3e10;

    cin >> n;
    cin >> s;

    if(n == 1) {
        cout << len/3 + (s[0] == '1' ? len/3 : 0) << endl;
        return 0;
    }

    mat[0] = "110";
    mat[1] = "101";
    mat[2] = "011";

    for(int i = 0; i < 3; i++) {
        int flag = 0;
        for(int j = 0; j < n; j++) {
            if(s[j] != mat[i][j%3]) {
                flag = 1; break;
            }
        }
        if(!flag) {
            long long id = len-n;
            while(id%3 != i) id--;
            cout << id/3+1 << endl;
            return 0;
        }
    }

    cout << 0 << endl;

    return 0;
}

#include<bits/stdc++.h>
typedef long long ll ;
#define int ll
using namespace std ;
signed main( )
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int testcases = 1 ;
    // cin >> testcases ;
    while( testcases -- )
    {
        int a , b ;
        cin >> a >> b ;
        int sum = 0 ;
        for(int i = 1 ; i <=a ; i++)
        {
        	for(int j = 1 ; j <= b ; j++)
        	{
        		int n = i*100 ;
        		n += j ;
        		sum += n ;
        	}
        }
        cout << sum ;
        cout << endl ;
    }
    return 0 ;
}


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

#define rng(x) x.begin(), x.end()
#define maxi(x, y) x = max(x, (y))
#define mini(x, y) x = min(x, (y))
#define pb push_back
#define F first
#define S second
#define el '\n'
#define int long long
template<typename T>
istream&operator>>(istream&is,vector<T>&v){for(auto&it:v)is>>it;return is;}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.F << "," << P.S << ")"; }
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ "; for(auto v : V) os << v << " "; return os << "]"; }
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}"; }
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout<<name<<" : "<<arg1<<'\n';}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names,comma-names)<<" : "<<arg1<<" |";__f(comma+1, args...);}
typedef pair<int,int> pi; typedef vector<int> vi; typedef vector<vi> vvi;

/*-----------------------------Code begins----------------------------------*/

const int N = 2000;
const int MOD = 1e9 + 7;

// operation keeping MOD in mind;
int add(int x, int y){
    x += y;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

int mul(int x, int y){
    // to avoid overflow;
    return (x * 1ll * y) % MOD;
}

int fact[N];

// return (x raised to power y) % MOD;
int binpow(int x, int y){
    int z = 1;
    while(y){
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

int inv(int x){
    return binpow(x, MOD - 2);
}

// return x/y;
int divide(int x, int y){
    return mul(x, inv(y));
}

// array of factorials;
void precalc(){
    fact[0] = 1;
    for(int i = 1; i < N; i++)
        fact[i] = mul(fact[i - 1], i);
}

// returns nCk;
int C(int n, int k){
	if(k > n) return 0;
    return divide(fact[n], mul(fact[k], fact[n - k]));
}

void solve(){
	int n; cin>>n;
	char aa, ab, ba, bb; cin>>aa>>ab>>ba>>bb;
	if(n == 2){
		cout<<1<<el;
		return;
	}
	if(ab == aa and ab == 'A'){
		cout<<"1\n";
		return;
	}
	if(ab == bb and ab == 'B'){
		cout<<"1\n";
		return;
	}

	if(ab == ba){
		// not consequtive;
		n--;
		int ans = 0;
		for (int bs = 0; bs <= n; ++bs){
			ans += C(n - bs - 1, bs + 1 - 1);
			ans %= MOD;
		}
		cout<<ans<<el;
	}
	else{
		cout<<binpow(2, n - 3)<<el;
	}
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int T=1;
    // cin>>T;
    precalc();
    while(T--){
        solve();
    }
    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;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

void solve(long long X, long long Y, long long Z){
  ll ans= Y*Z/X;
  if(Y*Z%X==0){
    --ans;
  }
  cout<<ans<<endl;
}

int main(){
  cout<<setprecision(1000);
  long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    long long Z;
    scanf("%lld",&Z);
  solve(X, Y, Z);
  return 0;
}


#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <tuple>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <bitset>
#include <list>
#include<iomanip>

using namespace std;
using ll = long long;
using ULL = unsigned long long;
using pll = std::pair<ll, ll>;
using vi = std::vector<int>;
using vl = std::vector<ll>;
using vb = std::vector<bool>;
using vpll = std::vector<pll>;
using db = double;
using vdb = std::vector<db>;
using qlg= std::priority_queue<ll, vl, std::greater<ll> > ; //ascending
using qll= std::priority_queue<ll, vl, std::less<ll> > ; // descending
using qdg= std::priority_queue<db, vdb, std::greater<db> > ; //ascending
using qdl= std::priority_queue<db, vdb, std::less<db> > ; // descending
template<class T>
using vv = std::vector<std::vector<T> >;

#define REPL(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FORL(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FORL(i, 0, n)

#define MREP(i, n) for (ll i= (ll)(n)-1; i>=0; i-- )
#define MFOR(i, a, b) for (ll i = (ll)(b)-1; i >= (ll)(a); i--)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
#define INF pow(10, 10)
void chmin(ll& a, ll b){ if(a > b) a = b; }
void chmax(ll& a, ll b){ if(a < b) a = b; }

vpll calc_4thval(ll p1, ll p2, vv<ll> &Statuses)
{

    vpll Larges(5);
    REP(i, 5)
    {
        Larges[i] = {max(Statuses[p1][i], Statuses[p2][i]), i};
    }
    sort( all(Larges) );
    return Larges;
}

int main(void)
{

    ll  N;

    cin >> N;
    vv<ll> Statuses(N, vl(5));
    vl Maxvals(5, 0);
    REP(i, N)
    {
        REP(k, 5)
        {
            cin >> Statuses[i][k];
            Maxvals[k] = max(Maxvals[k], Statuses[i][k]);
        }

    }

    /*
    2人で4つ
    */
    ll ans = 0;
    REP(p1, N)
    {
        REP(p2, N)
        {
            if(p1 == p2) continue;
            vpll Stats_2p = calc_4thval(p1, p2, Statuses);
            bool flag = false;
            ll Min = Stats_2p[0].first;
            ll candidate = Stats_2p[1].first;

            REP(i, 5)
            {
                ll subject = Stats_2p[i].second;
                if(Min == Stats_2p[i].first && Maxvals[subject] >= ans)
                {
                    ans = max(ans, min(candidate, Maxvals[subject]) );
                }
            }

        }
    }

    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//const ll INF = numeric_limits<ll>::max() / 4;
//const int INF = numeric_limits<int>::max() / 4;

int main() {
	int N;
	cin >> N;
	vector<vector<int> > X(5, vector<int>(N,0));
	int mx = 0;
	for(int i = 0; i < N; i++){
		for(int k = 0; k < 5; k++){
			cin >> X[k][i];
			mx = (mx < X[k][i] ? X[k][i] : mx);

		}

	}
	int bl = 0;
	int bu = mx + 1;
	vector<bool> P(32);
	while(bl + 1 < bu){
		int b = (bl + bu) / 2;
		fill(P.begin(),P.end(),false);
		for(int i = 0; i < N; i++){
			int t = 0;
			for(int k = 0; k < 5; k++){
				if(b <= X[k][i]) t |= (1 << k);
			}
			P[t] = true;
		}
		bool f = false;
		for(int i1 = 1; i1 < 32; i1++){
			if(!P[i1]) continue;
			for(int i2 = i1; i2 < 32; i2++){
				if(!P[i2]) continue;
				for(int i3 = i2; i3 < 32; i3++){
					if(!P[i3]) continue;
					if(((i1 | i2) | i3) == 31){
						f = true;
						break;
					}
				}
				if(f) break;
			}
			if(f) break;
		}
		if(f){
			bl = b;
		}else{
			bu = b;
		}
	}
	cout << bl << endl;
	return(0);
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937/*_64*/ rng(chrono::steady_clock::now().time_since_epoch().count());
#define printArr(arr, n) cerr << #arr << " = ["; for(int i=0; i<(n); i++){if (i) cerr << ", "; cerr << arr[i];} cerr << "]\n"
template<class A> ostream& operator<<(ostream &cout, vector<A> const &v) {cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";};
template<class A, class B> ostream& operator<<(ostream &cout, const pair<A,B> &x) {return cout << "(" <<x.first << ", " << x.second << ")";};
void _print() {cerr << "]\n";}
template <class T, class... V> void _print(T t, V... v) {cerr << t; if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#define fi first
#define se second
#define SZ(x) (int)((x).size())
#define pii pair<int,int>

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int a[n];
	for (int q = 0; q < n; q++) cin >> a[q];
	for (int q = 0; q < n; q++) a[q]++;
	ordered_set<int> seen;
	ll tot = 0;
	for (int q = n-1; q >= 0; q--) {
		tot += seen.order_of_key(a[q]);
		seen.insert(a[q]);
	}
	cout << tot << "\n";
	for (int q = 0; q < n-1; q++) {
		tot -= (a[q]-1);
		tot += (n-a[q]);
		cout << tot << "\n";
	}
	return 0;
}

// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx,avx2,fma")

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

#define ll long long
#define ull unsigned long long
#define dd double
#define ld long double
#define sl(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define sd(n) scanf("%lf", &n)
#define pll pair <ll, ll>
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define inf (1LL << 61)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define for1(i, stop) for(ll i = 1; i <= stop; ++i)
#define for0(i, stop) for(ll i = 0; i < stop; ++i)
#define rep1(i, start) for(ll i = start; i >= 1; --i)
#define rep0(i, start) for(ll i = (start-1); i >= 0; --i)
#define ms(n, i) memset(n, i, sizeof(n))
#define casep(n) printf("Case %lld:", ++n)
#define pn printf("\n")
#define pf printf
#define EL '\n'
#define fastio std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const ll sz = 3e5 + 10;
ll BIT[sz], ara[sz], big[sz], small[sz], pbig[sz], psmall[sz];

void upd(ll idx, ll n)
{
    while(idx <= n) {
        BIT[idx]++;
        idx += idx&(-idx);
    }
}

ll query(ll idx)
{
    ll ret = 0;
    while(idx > 0) {
        ret += BIT[idx];
        idx -= idx&(-idx);
    }
    return ret;
}

inline ll qry(ll l, ll r)
{
    return query(r) - query(l-1);
}

int main()
{
    ll n;
    cin >> n;

    for1(i, n) {
        sl(ara[i]);
        ara[i]++;
    }

    ll tot = 0;

    rep1(i, n) {

        if(ara[i] == n) big[i] = 0;
        else big[i] = qry(ara[i]+1, n);

        upd(ara[i], n);

        small[i] = qry(1, ara[i]-1);
        tot += small[i];
    }

    ms(BIT, 0);

    for1(i, n) {

        if(ara[i] == n) pbig[i] = 0;
        else pbig[i] = qry(ara[i]+1, n);

        upd(ara[i], n);

        psmall[i] = qry(1, ara[i]-1);
    }

    pf("%lld\n", tot);

    for1(i, n-1) {
        tot -= small[i], tot -= psmall[i];
        tot += pbig[i], tot += big[i];

        pf("%lld\n", tot);
    }

    return 0;
}


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

// template {{{  0
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int R,C;
    Scd2(R,C);

    int N = R*C;

    vector<vii> e(N*2);

    int a;
    Rep(i,N){
        if( i%C == C-1 ) continue;
        Scd(a);
        e[i].push_back({i+1, a});
        e[i+1].push_back({i, a});
    }
    Rep(i,N-C){
        Scd(a);
        e[i].push_back({i+C, a});
        e[i+C+N].push_back({i+N, 1});
    }
    Rep(i,N){
        e[i].push_back({i+N, 1});
        e[i+N].push_back({i, 0});
    }

    vi d(N*2, INF);
    priority_queue<pii, vii, greater<pii>> q;
    q.push({0,0});
    d[0] = 0;

    while(q.size()){
        pii top = q.top();
        q.pop();
        int from = top.second;
        int dist = top.first;
        if( d[from] < dist ) continue;
        for( pii tow : e[from] ) {
            int to = tow.first;
            int cost = tow.second;
            if( dist + cost < d[to] ) {
                d[to] = dist + cost;
                q.push({d[to], to});
            }
        }
    }

    printf ("%d\n", d[N-1]);

    return 0;
}

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

int main(){
  int R,C,inf=1001001001;
  cin >> R >> C;
  vector<vector<int>> A(R,vector<int>(C-1)), B(R-1,vector<int>(C));
  for(int i=0;i<R;i++){
    for(int j=0;j<C-1;j++){
      cin >> A[i][j];
    }
  }
  for(int i=0;i<R-1;i++){
    for(int j=0;j<C;j++){
      cin >> B[i][j];
    }
  }

  vector<vector<int>> V(R,vector<int>(C,inf));
  V[0][0] = 0;
  priority_queue<pair<int,int>> Q;
  Q.push(make_pair(0,0));
  while(!Q.empty()){
    pair<int,int> p = Q.top();
    Q.pop();
    int r = p.second % R, c = p.second / R;
    if(V[r][c]!=-p.first) continue;

    if(c+1<C){
      if(V[r][c+1]>V[r][c]+A[r][c]){
        V[r][c+1] = V[r][c] + A[r][c];
        Q.push(make_pair(-V[r][c+1],(c+1)*R+r));
      }
    }
    if(c-1>=0){
      if(V[r][c-1]>V[r][c]+A[r][c-1]){
        V[r][c-1] = V[r][c] + A[r][c-1];
        Q.push(make_pair(-V[r][c-1],(c-1)*R+r));
      }
    }
    if(r+1<R){
      if(V[r+1][c]>V[r][c]+B[r][c]){
        V[r+1][c] = V[r][c] + B[r][c];
        Q.push(make_pair(-V[r+1][c],c*R+r+1));
      }
    }
    for(int i=1;r-i>=0;i++){
      if(V[r-i][c]>V[r][c]+i+1){
        V[r-i][c] = V[r][c] + i+1;
        Q.push(make_pair(-V[r-i][c],c*R+r-i));
      }
    }
  }

  cout << V[R-1][C-1] << endl;
  return 0;
}


#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
const int N=200005;
int n,l,a[N],b[N],goal[N],p[N];
ll ans;
vector<int> vec;
map<int,vector<int>> mp;
void mandown(){
	puts("-1");
	exit(0);
}
ll solve(int l,int r){
	if(l+1==r){
		return 0;
	}
	ll res=0;
	int mid=l,pos;
	while(mid+1<r&&b[mid+1]<a[mid+1]){
		mid++;
	}
	for(int i=mid,j=i;i>l;i--,j=min(j,i)){
		vector<int> &tmp=mp[b[i]-i];
		if(tmp.size()==0){
			mandown();
		}
		auto it=lower_bound(tmp.begin(),tmp.end(),j);
		it--;
		if(*it<l){
			mandown();
		}
		goal[i]=*it;
		j=min(j,*it+1);
	}
	for(int i=mid+1,j=i;i<r;i++,j=max(j,i)){
		vector<int> &tmp=mp[b[i]-i];
		auto it=upper_bound(tmp.begin(),tmp.end(),j);
		if(it==tmp.end()||*it>r){
			mandown();
		}
		goal[i]=*it;
		j=max(j,*it-1);
	}
	for(int i=l;i<=r;i++){
		p[i]=1;
	}
	pos=mid;
	for(int i=mid;i>l;i--){
		if(pos!=goal[i]){
			res+=p[pos]+pos-goal[i]-1;
			p[goal[i]]+=p[pos]+pos-goal[i]-2;
			pos=goal[i];
		}else{
			p[pos]--;
		}
	}
	pos=mid+1;
	for(int i=mid+1;i<r;i++){
		if(pos!=goal[i]){
			res+=p[pos]+goal[i]-pos-1;
			p[goal[i]]+=p[pos]+goal[i]-pos-2;
			pos=goal[i];
		}else{
			p[pos]--;
		}
	}
	return res;
}
int main(){
	scanf("%d%d",&n,&l);
	n+=2;
	a[1]=b[1]=0;
	a[n]=b[n]=l+1;
	for(int i=2;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=2;i<n;i++){
		scanf("%d",&b[i]);
	}
	for(int i=1;i<=n;i++){
		if(a[i]==b[i]){
			vec.push_back(i);
		}
		mp[a[i]-i].push_back(i);
	}
	for(int i=0;i<(int)vec.size()-1;i++){
		ans+=solve(vec[i],vec[i+1]);
	}
	printf("%lld\n",ans);
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    // 各ペンギンの間のマスに注目
    int N, L;
    cin >> N >> L;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    A.push_back(L+1);
    vector<int> B(N);
    rep(i, N) cin >> B[i];
    B.push_back(L+1);
    vector<ll> roomA(N+1);
    vector<ll> roomB(N+1);
    roomA[0] = A[0] - 1;
    roomB[0] = B[0] - 1;
    rep(i, N) {
        roomA[i+1] = A[i+1] - 1 - A[i];
        roomB[i+1] = B[i+1] - 1 - B[i];
    }
    ll ans = 0;
    int cur = 0; // roomAの今のindex
    for (int i = 0; i < N+1; i++) {
        // cout << ans << '\n';
        if (roomB[i] == 0) {
            continue;
        }
        ll temp = 0;
        while (cur < N+1 && roomA[cur] == 0) cur++;
        ans += max(0, i - cur);
        while (cur < N+1 && temp < roomB[i]) {
            temp += roomA[cur++];
        }
        if (temp != roomB[i]) {
            cout << -1 << '\n';
            return 0;
        }
        ans += max(0, cur - 1 - i);
    }
    cout << ans << '\n';
    return 0;
    // 境界、ll, 0, -, 1i, for s&g, debug
}


//////// Squares
// https://atcoder.jp/contests/hhkb2020/tasks/hhkb2020_d
// date: 2020-10-10T21:00:04.737499
// memo:

//<editor-fold desc="my macro">

#include <bits/stdc++.h>
#ifdef LOCAL
    #include <my/dump.h>
#else
    #define dump(...) 42
    #define dumpi(x) 42
    #define dumpar(...) 42
#endif

typedef long long ll;
using namespace std;

#define repe(x, a) for(auto&& (x) : (a))
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rep3(i, a, b) for(ll i=a, i##_len=(b);i<i##_len;i++)
#define _rep2(i, n) _rep3(i,0,n)
#define repd(...) _overload3(__VA_ARGS__,_repd3,_repd2,)(__VA_ARGS__)
#define _repd3(i, a, b) for(ll i=b-1, i##_len=(a);i>=i##_len;i--)
#define _repd2(i, n) _repd3(i,0,n)
#define loop(...) _overload3(__VA_ARGS__,,_loop2,_loop1)(__VA_ARGS__)
#define _loop2(i, a) for(ll i=a;; i++)
#define _loop1(i) _loop2(i,0)

#define all(x) x.begin(),x.end()
#define SIZE(x) ((ll)(x).size())

#define F first
#define S second
#define vec vector
#define umap unordered_map
#define uset unordered_set

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

#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define inrange(x,start,stop) ((start) <= (x) && (x) < (stop))
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; }

template <typename Cont, typename Func>
Cont fmap(const Cont &container, Func functor) {
    Cont result(container.size());
    std::transform(container.begin(), container.end(), result.begin(), functor);// [](int x){return x * 2;}
    return result;
}
template <typename Cont, typename Pred>
Cont filter(const Cont &container, Pred predicate) {
    Cont result;
    std::copy_if(container.begin(), container.end(), std::back_inserter(result), predicate);// [](int x){return x == 2;}
    return result;
}

template<typename T, typename ...Args>
void ci(T& first, Args&... args) {
    ((cin >> first), ..., (cin >> args)); //C++17
}

template<char Sep, typename T, typename ...Args>
void print_seq(const T& first, const Args&... args) {
    ((cout << first), ..., (cout << Sep << args)); //C++17
}

void co(){ cout << endl; }
template<typename... Words>
void co(Words... words) {
    print_seq<' '>(words...);
    cout << endl;
}
#define coi(x) cout<<(x)<<" "

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define sankou(n,a,b) cout << ((n) ? (a) : (b) ) << endl

#define asrt(expr...) assert((expr))
//</editor-fold>

//digit guide 9876543210987654321
#define LINF           2000000000 //2*10^9
#define INF   9000000000000000000 //9*10^18
#define MOD            1000000007 //1*10^9 + 7
#define MAXR               100000
//digit guide 9876543210987654321

void solve() {
    ll T;
    ci(T);

    rep(t,T) {
        ll N,A,B;
        ci(N,A,B);

//        all = (N-A-B+2) * (N-A-B+1) * (N-A+1) * (N-B+1) * 2;
//        全 = (N-A+1) * (N-B+1) ;
//        かぶらない = (N-A-B+2) * (N-A-B+1);
//        答 = all * (全 - かぶらない / 2) / 全;

        if (N < A+B) {
            co(0);
        } else {
            ll ans = (N - A + 1) * (N - B + 1) - (N - A - B + 2) * (N - A - B + 1) / 2;
            ans %= MOD;
            ans *= (N - A - B + 2);
            ans %= MOD;
            ans *= (N - A - B + 1) * 2;
            ans %= MOD;
            co(ans);
        }

    }
}

int main(){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);

    solve();
    return 0;
}

#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>
#include <omp.h>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;

const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323;
//const long long int pl=1000000;

long long int N,M,K,H,W,T,A,B;
long long int dp[3000][3000]={},res=0;
long long int p[2000300]={};
string S[200];
bool used[200200]={};
int main()
{
    cout << fixed << setprecision(18);
    cin>>T;
    for(long long int q = 0; q < T; q++){
        cin>>N>>A>>B;
        if(N<A+B){cout<<0<<endl;continue;}
        long long int tmp=(N-A-B)%mod;
        long long int mi=(tmp+2)*(tmp+1);
        mi%=mod;
        mi*=mi;
        mi%=mod;
        res=(2*(N-A+1))%mod;
        res*=tmp+2;
        res%=mod;
        res*=tmp+1;
        res%=mod;
        res*=N-B+1;
        res%=mod;

        res-=mi;
        res%=mod;
        res=(res+mod)%mod;
        cout<<res<<endl;
    }
}


#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() {
	char a[100];
	ll b[100];
	ll c[100];
	int sz;
	ll n, x, y, z, l, r, mid;
	bool v;
	rep(i, 100) {
		a[i] = 0;
	}
	cin >> a;
	cin >> n;
	sz = strlen(a);
	if (sz == 1) {
		x = (ll)(a[0] - '0');
		if (x <= n)cout << 1 << endl;
		else cout << 0 << endl;
		return 0;
	}
	l = 0;
	rep(i, sz) {
		c[i] = (ll)(a[i] - '0');
		l = max(l, c[i]);
	}
	z = l;
	r = n + 1;
	while (l + 1 < r) {
		mid = (l + r) / 2;
		x = n;
		rep(i, 100)b[i] = 0;
		rep(i, sz) {
			b[sz - i - 1] = x % mid;
			x /= mid;
		}
		v = true;
		if (x == 0) {
			rep(i, sz) {
				if (c[i] < b[i]) {
					v = true;
					break;
				}
				if (c[i] > b[i]) {
					v = false;
					break;
				}
			}
		}
		if (v)l = mid;
		else r = mid;
	}
	cout << (l-z)<<endl;
	return 0;
}

#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        mkp             make_pair
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((int)(v).size())
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
using          dl         =      deque<ll> ;
const int N = 1e6+5 ;

ll      mod = 1e9+7 ;
vl      adj[N] ;
vpll    adjc[N] ;
ll      vis[N] ;
ll      arr[N] ;

ll muld(ll a,ll b)
{
       return (((a%mod)*(b%mod))%mod);
}
ll sumd(ll a,ll b)
{
       return (((a%mod)+(b%mod))%mod);
}

int main()
{
    IOS;
    ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs;
    string   str ;
    char     ch ;
    double   db ;
    ll       l, r ;
    //code

    cin>>a>>b;
    x=b;
    y=2*a+100;
    if(y>=x)
    {
           cout<<y-x<<endl;
    }
    else cout<<0<<endl;

    //code
    return 0;
}


#include<iostream>
#include <cassert>
#include <numeric>
using namespace std;
#include<vector>
#include <algorithm>
#define re(i,n) for(int i = 0; i < n; i++);
const int MOD = 998244353;

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

    if(a > b - c) cout << "Takahashi"<< endl;
    else cout << "Aoki"<< endl;

    return 0;
}

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

int main() {
  int v, t, s, d;
  scanf("%d %d %d %d", &v, &t, &s, &d);
  if(d < v * t || v * s < d) cout << "Yes";
  else cout << "No";
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#include <functional>
#include <chrono>
#include <cassert>
#include <bitset>
// printf("%.10f\n", ans);
using ll = long long;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 1e5 + 1;
int n, timer;
vector<vector<int>> tree, h;
vector<int> tin, tout;

void dfs(int u, int p, int he)
{
	tin[u] = timer++;
	h[he].push_back(u);
	for (int& v : tree[u]) if (v != p) dfs(v, u, he + 1);
	tout[u] = timer++;
}

int bs1(int& u, vector<int>& vec)
{
	int l = 0, r = vec.size() - 1;
	int id = -1;
	while (l <= r)
	{
		int m = (l + r) >> 1;
		int v = vec[m];
		if (tin[u] <= tin[v] && tout[u] >= tout[v]) r = m - 1, id = m;
		else if (tin[u] <= tin[v]) r = m - 1;
		else l = m + 1;
	}
	return id;
}

int bs2(int& u, vector<int>& vec)
{
	int l = 0, r = vec.size() - 1;
	int id = -2;
	while (l <= r)
	{
		int m = (l + r) >> 1;
		int v = vec[m];
		if (tin[u] <= tin[v] && tout[u] >= tout[v]) l = m + 1, id = m;
		else if (tin[u] <= tin[v]) r = m - 1;
		else l = m + 1;
	}
	return id;
}

int main()
{
	scanf("%d", &n);
	tree = h = vector<vector<int>>(n);
	tin = tout = vector<int>(n);
	for (int i = 1; i < n; i++)
	{
		int p;
		scanf("%d", &p);
		tree[--p].push_back(i);
		tree[i].push_back(p);
	}
	dfs(0, -1, 0);
	int q;
	scanf("%d", &q);
	while (q--)
	{
		int u, d;
		scanf("%d%d", &u, &d);
		u--;
		int l = bs1(u, h[d]);
		int r = bs2(u, h[d]);
		printf("%d\n", r - l + 1);
	}
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;
//const int mod = 998244353;

const int MAX_V = 200005;
int k = 0;

vector<vector<int>> to(MAX_V);
vector<bool> used(MAX_V);
vector<int> dep(MAX_V);
vector<int> in(MAX_V);
vector<int> out(MAX_V);
vector<vector<int>> ls(MAX_V);

void dfs(int v, int d){
    in[v] = k++;
    dep[v] = d;
    used[v] = true;
    for(int u : to[v]){
        if(used[u]) continue;
        dfs(u, d+1);
    }
    out[v] = k;
}

int main()
{
    int n;
    cin >> n;
    rep(i, 0, n-1){
        int p;
        cin >> p;
        p--;
        to[p].push_back(i+1);
        to[i+1].push_back(p);
    }
    dfs(0, 0);
    rep(i, 0, n) ls[dep[i]].push_back(in[i]);
    rep(i, 0, n) sort(ls[i].begin(), ls[i].end());
    auto f = [&](int d, int r){
        return int(lower_bound(ls[d].begin(), ls[d].end(), r) - ls[d].begin());
    };
    int q;
    cin >> q;
    rep(i, 0, q){
        int u, d;
        cin >> u >> d;
        u--;
        printf("%d\n", f(d, out[u]) - f(d, in[u]));
    }
    return 0;
}


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

#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(),(a).rend())
#define ll long long
#define pb(a) push_back(a)

#define PRINTV(v) {for(ll deB=0; deB<(v).size(); deB++){cout << (v)[deB] << " ";}cout << endl;}

int main(){

	ll H,W;
	cin >> H >> W;
	vector< vector<ll> > M(H+1, vector<ll>(W+1, 0));
	vector< vector<ll> > T(H+1, vector<ll>(W+1, 0));
	//vector< vector<ll> > A(H+1, vector<ll>(W+1, 0));
	REP(y,H){
		string S;
		cin >> S;
		REP(x,W){
			if(S[x] == '+') M[y][x] = 1;
			else M[y][x] = -1;
			if((x+y)%2==0) M[y][x] = -M[y][x];
		}
	}
	M[0][0] = 0;

	for(int y=H-2; y>=0; y--){
		T[y][W-1] = T[y+1][W-1] + M[y][W-1];
	}
	for(int x=W-2; x>=0; x--){
		T[H-1][x] = T[H-1][x+1] + M[H-1][x];
	}
	for(int y=H-2; y>=0; y--){
		for(int x=W-2; x>=0; x--){
			if((x+y)%2==0){
				T[y][x] = max(T[y+1][x], T[y][x+1]) + M[y][x];
			}else{
				T[y][x] = min(T[y+1][x], T[y][x+1]) + M[y][x];
			}
		}
	}

	ll ret = T[0][0] + M[H-1][W-1];

	if(ret > 0){
		cout << "Takahashi" << endl;
 	}else if(ret < 0){
		cout << "Aoki" << endl;
	}else{
		cout << "Draw" << endl;
	}

	return 0;
}

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

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
ll MOD = 1000000007;

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << "\n"
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl

template<typename T_vector>
void output_vector(const T_vector &v, bool line_break = false, bool add_one = false, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = int(v.size());
    for (int i = start; i < end; i++) {
      cout << v[i] + (add_one ? 1 : 0) << (line_break ? '\n' : i < end - 1 ? ' ' : '\n');
    }
}

void solve() {
    int h, w; cin >> h >> w;
    vvi dp(h, vi(w, -INF)), s(h, vi(w));
    REP(i, h) REP(j, w) {
        char x; cin >> x;
        if(x == '+') s[i][j] = 1;
        else s[i][j] = -1;
    }
    --h, --w;
    dp[h][w] = 0;
    FORD(i, h, 0) {
        FORD(j, w, 0) {
            if(i < h) MAX(dp[i][j], s[i + 1][j] - dp[i + 1][j]);
            if(j < w) MAX(dp[i][j], s[i][j + 1] - dp[i][j + 1]);
        }
    }
    if(dp[0][0] > 0) OUT("Takahashi");
    else if(dp[0][0] < 0) OUT("Aoki");
    else OUT("Draw");
}

int main()
{
    FAST_INP;

//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r", stdin);
//    freopen("output.txt","w", stdout);
//    #endif

    // int tc; cin >> tc;
    // TC(tc) solve();
    solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define debug(x) cerr << #x << " = " << x << endl
#define boost ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) { cout << endl; }

template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " ";
    err(++it, args...);
}

template<typename T>
inline void read(T& x) {
    x = 0; T f = 1; char ch = getchar();
    while (!isdigit(ch)) f = (ch == '-') ? -1 : 1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

template<typename T, typename ...Args>
inline void read(T& x, Args&... args) { read(x), read(args...); }

constexpr int MAXN = 1e5 + 5, MOD = 1e9 + 7;

int n;
array<int, MAXN> a, cnt;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        for (int j = 2; j <= a[i]; j++) {
            if (a[i] % j == 0) cnt[j]++;
        }
    }

    int ans = 0, id = 0;
    for (int i = 1; i <= 1000; i++) {
        if (cnt[i] > ans) ans = cnt[i], id = i;
    }
    cout << id << endl;
    return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++ i)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

int N;
pair<double, double> seg[2005];

int main()
{
    cin >> N;
    rep(i, N) {
        int t; cin >> t >> seg[i].first >> seg[i].second;
        if (t == 2) seg[i].second -= 0.1;
        if (t == 3) seg[i].first += 0.1;
        if (t == 4) seg[i].first += 0.1, seg[i].second -= 0.1;
    }

    sort(seg, seg + N, [&](pair<double, double> x, pair<double, double> y){
        if (x.first == y.first) return x.second > y.second;
        return x.first < y.first;
    });

    vector<double> ver;
    rep(i, N) ver.push_back(seg[i].first);

    LL ret = 0;
    rep(i, N) {
        int j = upper_bound(ver.begin() + i, ver.end(), seg[i].second) - ver.begin();
        ret += max(0, (j - i - 1));
    }

    printf("%lld\n", ret);

    return 0;
}


#include <bits/stdc++.h>
#define f(a, n) for (int a = 0; a < n; a++)
#define F(a, n) for (int a = 1; a <= n; a++)
#define P (1000000007)

using namespace std;

struct Square{
	bool bulb = 0;
	bool up = 0;
	bool down = 0;
	bool left = 0;
	bool right = 0;
	bool block = 0;
};

Square A[1505][1505];

int main(){
	cin.tie(NULL); ios::sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
	int M, N;
	cin >> N >> M;
	int x, y;
	F(i, N){
		cin >> y >> x;
		A[y][x].bulb = 1;
	}
	F(i, M){
		cin >> y >> x;
		A[y][x].block = 1;
	}
	f(i, H + 2) A[i][0].block = A[i][W + 1].block = 1;
	f(j, W + 2) A[0][j].block = A[H + 1][j].block = 1; // making the perimeter all blocks to simplify later logic

	{ // just creating a new scope for no good reason
		queue<pair<int, int>> Q;
		F(i, H) F(j, W){
			if (A[i][j].bulb){
				Q.push({i, j});
			}
		}
		while (!Q.empty()){
			auto p = Q.front();
			Q.pop();
			int i = p.first, j = p.second;
			if (!A[i][j].block){
				if (!A[i][j].up){ // if we haven't visited this node yet for the up direction
					Q.push({i - 1, j});
					A[i][j].up = 1;
				}
			}
		}
	}
	{ // just creating a new scope for no good reason
		queue<pair<int, int>> Q;
		F(i, H) F(j, W){
			if (A[i][j].bulb){
				Q.push({i, j});
			}
		}
		while (!Q.empty()){
			auto p = Q.front();
			Q.pop();
			int i = p.first, j = p.second;
			if (!A[i][j].block){
				if (!A[i][j].right){ // if we haven't visited this node yet for the up direction
					Q.push({i, j + 1});
					A[i][j].right = 1;
				}
			}
		}
	}
	{ // just creating a new scope for no good reason
		queue<pair<int, int>> Q;
		F(i, H) F(j, W){
			if (A[i][j].bulb){
				Q.push({i, j});
			}
		}
		while (!Q.empty()){
			auto p = Q.front();
			Q.pop();
			int i = p.first, j = p.second;
			if (!A[i][j].block){
				if (!A[i][j].down){ // if we haven't visited this node yet for the up direction
					Q.push({i + 1, j});
					A[i][j].down = 1;
				}
			}
		}
	}
	{ // just creating a new scope for no good reason
		queue<pair<int, int>> Q;
		F(i, H) F(j, W){
			if (A[i][j].bulb){
				Q.push({i, j});
			}
		}
		while (!Q.empty()){
			auto p = Q.front();
			Q.pop();
			int i = p.first, j = p.second;
			if (!A[i][j].block){
				if (!A[i][j].left){ // if we haven't visited this node yet for the up direction
					Q.push({i, j - 1});
					A[i][j].left = 1;
				}
			}
		}
	}
	int ans = 0;
	F(i, H) F(j, W){
		if (A[i][j].up || A[i][j].down || A[i][j].left || A[i][j].right) ans++;
	}
	cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int arr[n][2];
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<2;j++)
    {
      cin>>arr[i][j];
    }
  }
  int min1=arr[0][0];
  int min2=arr[0][1];
  int temp=0;
  for(int i=1;i<n;i++)
  {
    if(arr[i][0]<min1)
    {
      min1=arr[i][0];
      temp=i;
    }
    if(arr[i][1]<min2 && arr[i][1]!=arr[temp][1])
      min2=arr[i][1];
  }
  if(min1+arr[temp][1]<max(min1,min2))
    cout<<min1+arr[temp][1];
  else
    cout<<max(min1,min2);
  return 0;
}


#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#define ll long long
#define pb push_back
#define forn(i,x,n) for(int i=x;i<=n;++i)
#define forr(i,x,n) for(int i=n;i>=x;--i)
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;
const int maxn=20000050;

struct node
{
	int v;int pos;
}aa[maxn],bb[maxn];

int n,s[maxn],a[maxn],b[maxn],c[maxn];

bool cmp(node a,node b)
{
	return a.v<b.v||a.v==b.v&&a.pos<b.pos;
}

int lowbit(int x)
{
	return (x&-x);
}

int query(int x)
{
	int ans=0;
	while(x)
	{
		ans+=s[x];
		x-=lowbit(x);
	}
	return ans;
}

void insert(int x)
{
	while(x<=n)
	{
		s[x]++;
		x+=lowbit(x);
	}
}

int main()
{
	cin>>n;
	forn(i,1,n)
	  {
	  	  cin>>a[i];
	  	  aa[i].v=a[i]+i;
	  	  aa[i].pos=i;
	  }
	forn(i,1,n)
	  {
	  	  cin>>b[i];
	  	  bb[i].v=b[i]+i;
	  	  bb[i].pos=i;
	  }
	sort(aa+1,aa+n+1,cmp);
	sort(bb+1,bb+n+1,cmp);
	bool flag=true;
	for(int i=1;i<=n;++i)
	  if(aa[i].v!=bb[i].v)flag=false;
	if(flag==false) cout<<-1<<endl;
	else
	{
		ll ans=0;
		forn(i,1,n)
		  c[aa[i].pos]=bb[i].pos;
		forn(i,1,n)
		{
			ans+=query(n)-query(c[i]);
			insert(c[i]);
		}
		cout<<ans<<endl;
	}
}

#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int table[26];
int work[26];
bool FLG = false;
vector<char> V;
map<int,int> MAP;

int main(){

	for(int i = 0; i < 26; i++){

		table[i] = 0;
	}

	char S[3][12];
	int len[3];

	for(int i = 0; i < 3; i++){

		scanf("%s",S[i]);
		len[i] = 0;
		for(int k = 0; S[i][k] != '\0'; k++){

			table[S[i][k]-'a']++;
			len[i]++;
		}
	}

	int count = 0;

	for(int i = 0; i < 26; i++){

		if(table[i] > 0){
			V.push_back('a'+i);
			MAP[i] = count++;
		}
	}
	if(count >= 11){

		printf("UNSOLVABLE\n");
		return 0;
	}

	/*for(int i = 0; i < 3; i++){

		printf("%d\n",len[i]);
	}*/
	//printf("count:%d\n",count);

	ll D[10];
	for(int i = 0; i < 10; i++){
		D[i] = i;
	}

	do{

		ll A = 0;
		bool FLG = true;
		for(int i = 0; i < len[0]; i++){

			if(i == 0 && D[MAP[S[0][i]-'a']] == 0){

				FLG = false;
				break;
			}
			A = 10*A + D[MAP[S[0][i]-'a']];
		}
		if(!FLG ||A == 0)continue;

		ll B = 0;
		for(int i = 0; i < len[1]; i++){
			if(i == 0 && D[MAP[S[1][i]-'a']] == 0){

				FLG = false;
				break;
			}
			B = 10*B + D[MAP[S[1][i]-'a']];
		}
		if(!FLG||B == 0)continue;

		ll C = 0;
		for(int i = 0; i < len[2]; i++){
			if(i == 0 && D[MAP[S[2][i]-'a']] == 0){

				FLG = false;
				break;
			}
			C = 10*C + D[MAP[S[2][i]-'a']];
		}
		if(!FLG||C == 0)continue;

		//printf("A:%lld B:%lld C:%lld\n",A,B,C);

		if(A+B == C){

			for(int i = 0; i < 3; i++){

				for(int k = 0; k < len[i]; k++){

					printf("%lld",D[MAP[S[i][k]-'a']]);
				}
				printf("\n");
			}

			return 0;
		}

	}while(next_permutation(D,D+10));

	if(!FLG){

		printf("UNSOLVABLE\n");
	}

	return 0;
}


#include<bits/stdc++.h>
#define            pb            push_back
#define            pl            pair<ll,ll>
#define            pll           pair<ll,pair<ll,ll>>
#define            ll            long long
#define            vl            vector<ll>
#define            fastio        ios_base::sync_with_stdio(false); cin.tie(NULL);
#define            mp            make_pair
#define            w(t)          int t;cin>>t;while(t--)
#define            inf           1e18
#define            fi(a,n)       for(ll i=a;i<n;i++)
#define            fr(i,a,b)     for(ll i=a;i>=b;i--)
#define            fj(a,n)       for(ll j=a;j<n;j++)
#define            k(a,n)        for(ll k=a;k<n;k++)
#define            endl          "\n"
#define            all(v)        (v).begin(),(v).end()
#define            set1(x)       __builtin_popcount(x)
#define            gcd(a,b)      __gcd(a,b)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
using namespace std;
const ll mod= 1000000007;
const ll N =1000005;
void solve()
{
    ll a[3];
    fi(0,3)cin>>a[i];
    sort(a,a+3);
    if(a[2]-a[1]==a[1]-a[0])
    {
      cout<<"Yes"<<endl;
    }
    else
    {
      cout<<"No"<<endl;
    }
}
int main()
{
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
      //w(t)
      solve();

}

#include<bits/stdc++.h>
using namespace std;
int main() {
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (i != j and i != k and j != k) {
          if (a[j] - a[i] == a[k] - a[j]) {
            cout << "Yes";
            return 0;
          }
        }
      }
    }
  }
  cout << "No";
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	const ll mod = m * m;
	ll x = 10, y = n, z = 1;
	while(y > 0){
		if(y & 1){ z = (z * x) % mod; }
		x = (x * x) % mod;
		y >>= 1;
	}
	cout << z / m << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define INF 0x3f3f3f3f
#define pi M_PI
typedef pair<ll, ll> llPair;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef priority_queue<ll> pqll;
ll MOD = 1000000007;
/*
Really doe, like really doe
Really doe, like really doe
*/
ll power(ll x, ll y, ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y / 2, m) % m;
    p = (p * p) % m;

    return (y % 2 == 0) ? p : (x * p) % m;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t;
    t = 1;
    for (ll z = 0; z < t; ++z)
    {
        ll n, m;
        cin >> n >>      m;
        n = power(10, n, m * m);
        cout << (n / m) % m << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define REP(i,x,n) for(ll i = (x); i < (n); ++i)
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);
//const ll mod = 998244353;

template<class T> inline bool chmin(T& a, T b){ if(a > b) { a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a = b; return true;} return false; }
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }

int main(void)
{
    ll n, x;
    string s;
    cin >> n >> x >> s;
    rep(i,n){
        if(s[i] == 'o') x++;
        else{
            x = max(x-1, 0ll);
        }
    }
    cout << x << endl;
    return 0;
}


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

typedef long long ll;

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N), S(N + 1, 0), M(N + 1, 0);
    rep(i, N) cin >> A[i];
    rep(i, N) {
        S[i + 1] = S[i] + A[i];
        M[i + 1] = max(M[i], S[i + 1]);
        //cout << S[i] << " " << M[i] << "\n";
    }
    ll ans = 0, x = 0;
    rep(i, N) {
        ans = max({ans, x + M[i + 1], x + S[i + 1]});
        x += S[i + 1];
    }
    cout << ans << "\n";
    //rep(i, N + 1) cout << S[i] << " " << M[i] << "\n";
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i:x){cout << i << " ";} cout << endl;}
#define isin(x,l,r) ((l)<=(x) && (x)<(r))
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using tii = tuple<int,int,int>;
template<typename T>bool chmin(T&x,const T&y) {if(x>y){x=y;return 1;} else return 0;}
template<typename T>bool chmax(T&x,const T&y) {if(x<y){x=y;return 1;} else return 0;}

int main() {
    ll K;
    cin >> K;
    if (K == 1) {
        cout << 1 << '\n';
        return 0;
    }
    ll ans = 0;
    // 全て違う数
    for (int i = 1; i <= K; i++) {
        for (int j = i+1; j <= K; j++) {
            if ((ll)i * j * (j+1) > K) break;
            int left = j+1;
            int right = K / (i*j);
            ans += (right - left + 1) * 6;
        }
    }
    // 2つ同じ数
    for (int i = 1; i <= K; i++) {
        if ((ll)i * i > K) break;
        int right = K / (i * i);
        int temp = right;
        if (right >= i) temp--; // iと重複
        ans += temp * 3;
    }
    // 全て同じ数
    for (int i = 1; i <= K; i++) {
        if ((ll)i * i * i > K) break;
        ans++;
    }
    cout << ans << '\n';
    return 0;
    // get dp together, ll, paraphrase, debug
}


#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rrep(i,n) for(int i=((n)-1);i>=0;--i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    vector<pair<int,string>> vp;
    rep(i,n){
        string s;
        int a;
        cin>>s>>a;
        vp.push_back({a,s});
    }
    sort(all(vp));
    cout<<vp[n-2].second;
}

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define int long long
using namespace std;

inline void yn(bool a){cout<<(a?"YES":"NO");}

void solve() {
    int n;cin>>n;
    vector<pair<string,int>>v(n);
    for(int i=0;i<n;i++)cin>>v[i].fi>>v[i].se;
    sort(v.begin(),v.end(),[&](pair<string,int>a,pair<string,int>b){
        return a.se>b.se;
    });
    cout<<v[1].fi;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int tc=1;//cin>>tc;
    for (int t = 1; t <= tc; t++) {
        //cout<<"Case #"<<t<<" : ";
        solve();
        cout<<'\n';
    }
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define irreps(i, m, n) for (long long i = ((long long)(n)-1); i > (long long)(m); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) (long long)(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

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

  ll a,b,x,y; cin>>a>>b>>x>>y;

  if(a==b){
    cout<<x<<endl;
  }else if(a<b){
    ll ans=x;
    if(2*x<y) ans+=(b-a)*2*x;
    else ans+=(b-a)*y;
    cout<<ans<<endl;
  }else{
    ll ans=x;
    if(2*x<y) ans+=2*x*(a-b-1);
    else ans+=y*(a-b-1);
    cout<<ans<<endl;
  }

}

#include<bits/stdc++.h>
//#include<iostream>
//#include<string>
//#include<cmath>
//#include<cstdio>
//#include<cstring>
//#include<algorithm>
//#include<cctype>
//#include<vector>
//#include<map>
//#include<deque>
//#include<queue>
using namespace std;

#define re register
#define inf 0x3f3f3f3f
//#define inf 0x3f3f3f3f3f3f3f3fll
#define ll long long
//#define int ll
//#define x first
//#define y second

typedef pair<int,int> PII;

template<typename T>
inline void read(T &x){
	re char ch=getchar();re bool f=false;x=0;
	while(!isdigit(ch)){if(ch=='-'){f=true;}ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	x=f?-x:x; return ;
}

template<typename T>
inline void write(T x){
	if(x<0){putchar('-');x=-x;}
	if(x>=10){write(x/10);}
	putchar(x%10+'0');
}

double const eps=1e-18;
int const N=3e5+5;
int a[N];
struct SegmentTree{
	int l,r;
	int dat;
}t[N*4];

inline void build(int p,int l,int r){
	t[p].l=l,t[p].r=r;
	if(l==r){
		t[p].dat=a[l];
		return ;
	}
	int mid=(l+r)>>1;
	build(p<<1,l,mid);
	build(p<<1|1,mid+1,r);
	t[p].dat=t[p<<1].dat^t[p<<1|1].dat;
}

inline void modify(int p,int x,int y){
	if(t[p].l==t[p].r){
		t[p].dat^=y;
		return ;
	}
	int mid=(t[p].l+t[p].r)>>1;
	if(x<=mid) modify(p<<1,x,y);
	if(x>mid) modify(p<<1|1,x,y);
	t[p].dat=t[p<<1].dat^t[p<<1|1].dat;
}

inline int ask(int p,int l,int r){
	if(t[p].l>=l&&t[p].r<=r){
		return t[p].dat;
	}
	int mid=(t[p].l+t[p].r)>>1;
	int ans=0;
	if(l<=mid) ans^=ask(p<<1,l,r);
	if(mid<r) ans^=ask(p<<1|1,l,r);
	return ans;
}

signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n,m; read(n),read(m);
	for(int i=1;i<=n;i++){
		read(a[i]);
	}
	build(1,1,n);
	while(m--){
		int op,x,y; read(op),read(x),read(y);
		if(op==1){
			modify(1,x,y);
		}
		else{
			write(ask(1,x,y)),puts("");
		}
	}
	return 0;
}
/*
3 4
1 2 3
2 1 3
2 2 3
1 2 3
2 2 3

10 10
0 5 3 4 7 0 0 0 1 0
1 10 7
2 8 9
2 3 6
2 1 6
2 1 10
1 9 4
1 6 1
1 6 3
1 1 7
2 3 5
*/


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  n*=2;
  vector<ll> a[3];
  rep(i,n) {
    ll x;
    char c;
    cin >> x >> c;
    if(c=='R') a[0].pb(x);
    else if(c=='B') a[1].pb(x);
    else a[2].pb(x);
  }
  rep(i,3) sort(all(a[i]));
  P c[3];
  rep(i,3) c[i]=P(a[i].size()%2,i);
  sort(c,c+3,greater<P>());
  ll ans=MAXL;
  if(c[0].F) {
    ll x=c[0].S,y=c[1].S,z=c[2].S;
    rep(i,a[x].size()) {
      ll k=lower_bound(all(a[y]),a[x][i])-a[y].begin();
      if(k<a[y].size()) ans=min(ans,abs(a[x][i]-a[y][k]));
      if(k) ans=min(ans,abs(a[x][i]-a[y][k-1]));
    }
    vector<P> v[2];
    rep(i,a[z].size()) {
      ll k=lower_bound(all(a[x]),a[z][i])-a[x].begin();
      if(k<a[x].size()) {
        ll d=abs(a[z][i]-a[x][k]);
        v[0].pb(P(d,i));
      }
      if(k) {
        ll d=abs(a[z][i]-a[x][k-1]);
        v[0].pb(P(d,i));
      }
    }
    rep(i,a[z].size()) {
      ll k=lower_bound(all(a[y]),a[z][i])-a[y].begin();
      if(k<a[y].size()) {
        ll d=abs(a[z][i]-a[y][k]);
        v[1].pb(P(d,i));
      }
      if(k) {
        ll d=abs(a[z][i]-a[y][k-1]);
        v[1].pb(P(d,i));
      }
    }
    rep(i,2) sort(all(v[i]));
    rep(i,min(3,(int)v[0].size())) {
      rep(j,min(3,(int)v[1].size())) {
        if(v[0][i].S!=v[1][j].S) ans=min(ans,v[0][i].F+v[1][i].F);
      }
    }
  } else ans=0;
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

__attribute__ ((constructor))
void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
}

int main(){
    int n;
    ll k;

    cin >> n >> k;

    vector<vector<ll>> t(n, vector<ll>(n, 0));

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

    vector<int> v(n -1);

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

    ll cnt = 0;

    //N!の順列の全探索
    do{
        ll now = 0;
        FOR(i, 0, n-1){
            if(i == 0){
                now += t[0][v[i]];
            }
            if(i == n - 2){
                now += t[v[i]][0];
            }
            if(i != 0){
                now += t[v[i - 1]][v[i]];
            }
        }
        if(now == k)
            cnt++;
    }while(next_permutation(v.begin(),v.end()));

    cout << cnt << endl;

    return 0;
}