#include <bits/stdc++.h>
#include <cmath>
#define rep(i,n)    for(int i=0;i<(n);++i)
#define repA(i,k,n) for(int i=k;i<=(n);++i)
#define repD(i,k,n)	for(int i=k;i>=(n);--i)
#define endl '\n'
#define print(b)	for(auto a:b) cout<<a<<' ';
#define printN(b)   for(auto a:b) cout<<a<<endl;
#define fin    		freopen("C:\\Users\\Nazmul Rahul\\Desktop\\in.txt", "r++", stdin)
#define fout   		freopen("C:\\Users\\Nazmul Rahul\\Desktop\\out.txt", "w++", stdout)
#define fastio    	ios::sync_with_stdio(false)
#define max(a,b)	((a)>(b)?(a):(b))
#define min(a,b)	((a)<(b)?(a):(b))
#define pb    		push_back
#define pob   		pop_back
#define ll 			long long int
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
	fin;
	fout;
#endif
	// pair<int, string>p;
	// p = {1, "rahul"};
	// cout << p.first << " " << p.second << endl;
	// pair<pair<int, string>, int>q;
	// int i = 8;
	// q = {{i, "rahul"} , i};
	// cout << q.first.first << endl << q.first.second << endl << q.second << endl;
	// vector<pair<int, string>>p;
	// p.push_back({3, "r"});
	// p.push_back({4, "a"});
	// for (int i = 0; i < p.size(); i++)
	// 	cout << p[i].first << endl << p[i].second << endl;
	// for (auto a : p)
	// 	cout << a.first << endl << a.second << endl;
	int sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;
	float x = abs(sx - gx);

	if (sx > gx) {
		float ans = float(sx) - (x * (float)sy) / ((float)sy + (float)gy);
		// cout << ans << endl;
		printf("%f\n", ans );

	}
	else {
		float ans = float(sx) + (x * (float)sy) / ((float)sy + (float)gy);
		printf("%f\n", ans );
	}

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod=1000000007;
ll fact[200000];
ll power(ll x,ll y)
{
    ll res=1;
    while(y)
    {
        if(y&1) res=(res*x)%mod;
        x=(x*x)%mod; y>>=1;
    }
    return res;
}
ll nCr(ll n,ll r){
    if(r>n) return 0;
    else if(r<0) return 0;
    else if(r==0||r==n)return 1;
    ll ans=fact[n];
    ans=(ans*power(fact[n-r],mod-2))%mod; ans=(ans*power(fact[r],mod-2))%mod;
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ll t=1;
   // cin>>t;
    for(ll tc=0;tc<t;tc++)
    {
       ll a,b,c,d;
       cin>>a>>b>>c>>d;
       ll ans=-1e9;
       for(ll i=a;i<=b;i++){
        for(ll j=c;j<=d;j++){
            ans=max(ans,i-j);
          }
       }
       cout<<ans<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#include<iostream>

using namespace std;
void build();
#define ll              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define f(i,a,b)      for(int i=a;i<=b;i++)
#define rf(i,a,b)      for(int i=a;i>=b;i--)
#define fr(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))
#define all(v)          v.begin(),v.end()
#define srt(v)         sort(v.begin(),v.end())
#define rv(v)          reverse(v.begin(),v.end())
#define mx             100005

void solve(){
	int n,k;
	cin>>n>>k;
	int sum=0;
	for(int i=1;i<=n;i++){
		//int t=1;
		for(int j=1;j<=k;j++){
			int tm=i*100+j;
			sum+=tm;
		}
	}
	cout<<sum<<endl;
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
    int t=1;
    //cin>>t;
    while(t--){
    	solve();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int res=0;
	bool zf=0;
	char c;
	while(((c=getchar())<'0'||c>'9')&&c!='-');
	if(c=='-')zf=1;
	else res=c-'0';
	while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
	if(zf)return -res;
	return res;
}
const int maxn=2e5+5,N=2e5;
int p[maxn],q[maxn];
struct op{
	int id,val;
}r[maxn];
inline int cmp(op x,op y){
	return x.val>y.val;
}
int s[maxn];
inline void add(int x){
	for(;x<=N;++s[x],x+=x&-x);
	return;
}
inline int query(int x,int A=0){
	for(;x;A+=s[x],x-=x&-x);
	return A;
}
signed main(){
	int h=read(),w=read(),m=read();
	for(register int i=1;i<=h;++i){
		p[i]=w;
	}
	for(register int i=1;i<=w;++i){
		q[i]=h;
	}
	int m1=h,m2=w;
	while(m--){
		int x=read(),y=read();
		p[x]=min(p[x],y-1),q[y]=min(q[y],x-1);
		if(x==1){
			m2=min(m2,y-1);
		}
		if(y==1){
			m1=min(m1,x-1);
		}
	}
	long long A=0;
	for(register int i=1;i<=m1;++i){
		A+=p[i];
	}
	for(register int i=1;i<=m2;++i){
		A+=q[i];
	}
	for(register int i=1;i<=m2;++i){
		r[i].id=i,r[i].val=q[i];
	}
	sort(r+1,r+m2+1,cmp);
	int now=1;
	for(register int i=m1;i>=1;--i){
		while(now<=m2&&r[now].val>=i){
			add(r[now].id);
			++now;
		}
		A-=query(p[i]);
	}
	printf("%lld\n",A);
	return 0;
}


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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vll;

///*********************************** C o n s t ***********************************///

const int       N=1e6+123;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7

ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};       ///first 4 for adjacent
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};
ll dx8[]= {+1, +1, -1, -1, +2, +2, -2, -2};    ///knights move
ll dy8[]= {+2, -2, +2, -2, +1, -1, +1, -1};

///********************************** M a r c o ***********************************///

#define pb push_back
#define MP make_pair
#define F first
#define S second
#define test ll tc; cin>>tc; while(tc--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define endl '\n'
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b,ll MOD){ a%=MOD;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=MOD;--b;}a*=a;a%=MOD;b/=2;}return pr;}
ll modinverse(ll a){return powmod(a,MOD-2,MOD);}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){vl v; ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<N;jj+=2*ii)a[jj]=true; v.pb(2);for(ii=3;ii<N;ii+=2)if(!a[ii])v.pb(ii);}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///

void _case()
{
    ll n,m,i,j,ans=0,x,y;
    cin>>n>>m>>x>>y;
    string a[n];
    for(auto& i:a) cin>>i;
    if(a[x-1][y-1]=='.') ans++;
    else{
        cout<<0<<endl; return;
    }
    for(i=y-2;i>=0;i--){
        if(a[x-1][i]=='.') ans++;
        else break;
    }
    for(i=y;i<m;i++){
        if(a[x-1][i]=='.') ans++;
        else break;
    }
    for(i=x-2;i>=0;i--){
        if(a[i][y-1]=='.') ans++;
        else break;
    }
    for(i=x;i<n;i++){
        if(a[i][y-1]=='.') ans++;
        else break;
    }
    cout<<ans<<endl;
}

main()
{
    fastio();
    _case();

}

///See you soon

#include <bits/stdc++.h>

// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#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 rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

void solve() {
    int n;
    cin >> n;
    vl a(n);
    rep (i, n) cin >> a[i];
    sort(all(a));
    if (n % 2 == 0) {
        for (int i = 0; i < n; i += 2) {
            if (a[i] != a[i + 1]) {
                cout << "First" << endl;
                return;
            }
        }
        cout << "Second" << endl;
    }
    else {
        cout << "Second" << endl;
    }
}

signed main() {
    fio();

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}


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

void solve()
{
	int a, b, c;
	cin >> a >> b >> c;
	while (true)
	{
		if (c % 2 == 0)
		{
			if (a == 0)
			{
				cout << "Aoki" << endl;
				return;
			}
			a--;
		}
		else{
			if (b == 0)
			{
				cout << "Takahashi" << endl;
				return;
			}
			b--;
		}
		c++;
	}
}

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

//7.21
//rng_58 bless me

#include<bits/stdc++.h>
using namespace std;
//define:
#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
//fast io:
inline int Read() {
	int s = 0,f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9'){
		if(ch == '-') {
			f = -1;
		}
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		s = s * 10 + ch - '0';
		ch = getchar();
	}
	return s * f;
}
inline void Wte(ll x) {
    if(x < 0) {
    	putchar('-');
		x = -x;
	}
    if(x > 9)  {
		Wte(x / 10);
	}
    putchar(x % 10 + '0');
}
inline void Write(ll x) {
	Wte(x);
	putchar(' ');
}
//const:
const int MAXN = 0;
//something:
int L,R;
//run:
void solve() {
	L = Read(); R = Read();
	ll N = R - 2 * L + 1;
	if(N < 0) {
		puts("0");
		return;
	}
	Write(N * (N + 1) * 1ll / 2); puts("");
}
//times:
void Times(int T) {
	while(T--) {
		solve();
	}
}
//begin:
int main() {
	int T;
	T = 1;
	T = Read();
	Times(T);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define MOD2 1000000009
#define sp fixed<<setprecision
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
ll add(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD + b%MOD + MOD)%MOD;}
ll sub(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD - b%MOD + MOD)%MOD;}
ll mul(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return ((a%MOD)*(b%MOD) + MOD)%MOD;}
void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (sz(name)) {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}
int main(){
    setIO();
    ll n,x;
    cin>>n>>x;
    vector<ll>res;
    for(int i=0;i<n;i++){
      ll ele;
      cin>>ele;
      if(ele!=x)
        res.pb(ele);
    }
    for(auto u:res)
      cout<<u<<" ";

}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef int64_t ll;
const ll maxOne = 1'000'000'007;
ll add(ll a, ll b){
    if(a<0){
        a += maxOne;
    }
    if(b<0){
        b += maxOne;
    }
    return (a+b)%maxOne;
}
ll mul(ll a, ll b){
    if(a<0){
        a += maxOne;
    }
    if(b<0){
        b += maxOne;
    }
    return (a*b)%maxOne;
}
ll sub(ll a, ll b){
    if(a<b){
        a += maxOne;
    }
    return (a-b)%maxOne;
}

int main() {
    ll n;
    cin >> n;
    vector<ll> vals(n);
    for(auto& val:vals){
        cin >> val;
    }
    if(n==1){
        cout << vals[0] << endl;
        return 0;
    }

    ll dpp = vals[0];
    ll dps = 0;
    ll cp = 1;
    ll cs = 0;
    for(ll i=1; i<n; i++){
        ll nextDpp = add(dpp, mul(vals[i], add(cp, cs)));
        nextDpp = add(nextDpp, dps);
        ll nextDps = sub(dpp, mul(vals[i], cp));
        ll nextCp = add(cp, cs);
        ll nextCs = cp;

        dpp = nextDpp;
        dps = nextDps;
        cp = nextCp;
        cs = nextCs;
    }
    cout << add(dpp, dps) << endl;

    return 0;
}


#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    vector<vll> v(N+1, vll(2,-1));
    v[N][0]=v[N][1]=0;
    rep(i,N){
        ll x,c; cin>>x>>c; c--;
        auto &vec = v[c];
        if (vec[0]!=-1){
            chmin(vec[0], x);
            chmax(vec[1], x);
        }else{
            vec[0]=vec[1]=x;
        }
    }
    int prev_i=-1;
    vll dp(2);
    rep(i,N+1){
        if (v[i][0]==-1) continue;
        vll nxt(2,LLONG_MAX);
        rep(j,2){
            int cur = (prev_i!=-1) ? v[prev_i][j] : 0;
            chmin(nxt[0], dp[j]+abs(cur-v[i][1])+(v[i][1]-v[i][0]));
            chmin(nxt[1], dp[j]+abs(cur-v[i][0])+(v[i][1]-v[i][0]));
        }
        swap(dp,nxt);
        prev_i = i;
    }
    cout<<dp[0]<<endl;
    return 0;
}

#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 2e5 + 5;
const lli inf = 1e18;

int n;
int x[maxn], c[maxn];
bool app[maxn];

int l[maxn], r[maxn];

int lst_l, lst_r;
lli f[2], nf[2];

void read_input()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
    {
        cin >> x[i] >> c[i];
        app[c[i]] = true;
        l[c[i]] = r[c[i]] = x[i];
    }
}

void solve()
{
    for(int i = 1; i <= n; ++i)
    {
        l[c[i]] = min(l[c[i]], x[i]);
        r[c[i]] = max(r[c[i]], x[i]);
    }
    lst_l = 0; lst_r = 0;
    f[0] = f[1] = 0;
    for(int i = 1; i <= n; ++i)
    {
        if(!app[i]) continue;
        nf[0] = min(abs(lst_l - r[i]) + f[0] + abs(l[i] - r[i]), abs(lst_r - r[i]) + f[1] + abs(l[i] - r[i]));
        nf[1] = min(abs(lst_l - l[i]) + f[0] + abs(l[i] - r[i]), abs(lst_r - l[i]) + f[1] + abs(l[i] - r[i]));
        lst_l = l[i]; lst_r = r[i];
        f[0] = nf[0];
        f[1] = nf[1];
    }
    cout << min(f[0] + abs(lst_l), f[1] + abs(lst_r));
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
// auto mod int
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod; return *this;}
  mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod; return *this;}
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
struct Comb {
  vector<mint> fact, ifact;
  Comb(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(300);

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  vector<mint> b(n);
  rep(i,n) cin >> a[i], b[i] = a[i];

  vector<mint> s(k+1);
  s[0] = n;
  rep(p,k)rep(i,n) s[p+1] += b[i], b[i] *= a[i];

  mint m = mint(1)/2;
  for(int x=1;x<=k;++x){
    mint ans = 0;
    rep(i,x+1) ans += c(x,i) * s[i] * s[x-i];
    ans -= s[x] * mint(2).pow(x);
    ans *= m;
    cout << ans << endl;
  }
}

#include <bits/stdc++.h>

const int K = 300;
const int N = 200000;
const int P = 998244353;
inline int add(int x, int y) {x += y; return x >= P ? x - P : x;}
inline int sub(int x, int y) {x -= y; return x < 0 ? x + P : x;}
inline int mul(int x, int y) {return (int)(1ll * x * y % P);}

int s[K + 5], t[K + 5], c[K + 5][K + 5];

int p[N + 5], a[N + 5], n, k;
int main() {
	scanf("%d%d", &n, &k);
	for(int i=1;i<=n;i++) scanf("%d", &a[i]), p[i] = 1;
	for(int j=0;j<=k;j++) for(int i=1;i<=n;i++)
		s[j] = add(s[j], p[i]), t[j] = add(t[j], mul(p[i], p[i])), p[i] = mul(p[i], a[i]);
	for(int i=0;i<=k;i++) for(int j=0;j<=i;j++)
		c[i][j] = (j ? add(c[i - 1][j - 1], c[i - 1][j]) : 1);

	int iv2 = (P + 1) >> 1;
	for(int i=1;i<=k;i++) {
		int ans = 0;
		for(int j=0;j<=i;j++) {
			int del = mul(iv2, sub(mul(s[j], s[i - j]), s[i]));
			ans = add(ans, mul(c[i][j], del));
		}
		printf("%d\n", ans);
	}
}


#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()
//vector<vector<bool>> seat;

int main(){
    ll h,w,x,y;
    cin>>h>>w>>x>>y;
    vector<vector<char> > s(h,vector<char>(w));
    rep(i,h){
        rep(j,w){
            cin>>s[i][j];
        }
    }
    x--;y--;
    ll ans=0;
    for(ll i=x;i<h;i++){
        if(s[i][y]=='.'){
           // cout<<i<<" "<<y<<endl;
            ans++;
        }else{
            break;
        }
    }
    for(ll i=x-1;i>=0;i--){
        if(s[i][y]=='.'){
            ans++;
        }else{
            break;
        }
    }
    for(ll i=y+1;i<w;i++){
        //cout<<s[x][i]<<endl;
        if(s[x][i]=='.'){
           //cout<<x<<" "<<i<<endl;
            ans++;
        }else{
            break;
        }
    }
    for(ll i=y-1;i>=0;i--){
        if(s[x][i]=='.'){
            //cout<<x<<" "<<i<<endl;
            ans++;
        }else{
            break;
        }
    }
    cout<<ans<<endl;

}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plp;
typedef pair<pll,ll> ppl;
typedef pair<pll,pll> ppp;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<pll> vpll;
typedef vector<plp> vplp;
typedef vector<ppl> vppl;
typedef vector<ppp> vppp;
typedef vector<vpll> vvpll;
typedef vector<bool> vbool;
typedef vector<vbool> vvbool;
typedef vector<double> vd;
typedef priority_queue<pll,vpll,greater<pll> > pqpll;
typedef priority_queue<pll,vpll> pqrpll;
typedef priority_queue<ll, vll, greater<ll> > pqll;
typedef priority_queue<ll, vll> pqrll;

struct edge{ ll to,cost; edge(ll to,ll cost): to(to), cost(cost){} };
typedef vector<vector<edge>> Graph;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF 1000000000000000000
#define INF 1000000000
#define fs first
#define sc second
#define EPS 1e-10
#define ALL(a) a.begin(), a.end()

template<typename T> ll sz(vector<T> &vec){ return (ll)vec.size(); }
template<typename T> ll sz(priority_queue<T, vector<T> > &pq) {return (ll)pq.size(); }
template<typename T> ll sz(priority_queue<T, vector<T>, greater<T> > &pq) {return (ll)pq.size(); }
ll sz(string &s) {return (ll)s.size(); }

void chmin(ll &a, ll &b) { if(a > b) a = b; }
void chmax(ll &a, ll &b) { if(a < b) a = b; }

ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
ll dx[4] = {0,-1,1,0},dy[4] = {-1,0,0,1};
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }
vbool is_visited(200000,false);

void dfs(ll k, vll &a, vll &minnum, vvll &G){
    rep(i,0,sz(G[k])){
        if(!is_visited[G[k][i]]){
            is_visited[G[k][i]] = true;
            dfs(G[k][i], a, minnum, G);
        }
        minnum[k] = min(minnum[k],min(minnum[G[k][i]],a[G[k][i]]));
    }
}

int main(){
    ll n,m;
    cin >> n >> m;
    vll a(n);
    rep(i,0,n) cin >> a[i];
    vvll G(n);

    rep(i,0,m){
        ll x,y;
        cin >> x >> y;
        x--; y--;
        G[y].push_back(x);
    }

    vll minnum(n,LINF);
    rep(i,0,n){
        if(!is_visited[i]){
            is_visited[i] = true;
            dfs(i,a,minnum,G);
        }
    }

    ll ans = -LINF;
    rep(i,0,n){
        ans = max(ans,a[i]-minnum[i]);
    }
    assert(ans != -LINF);
    cout << ans << endl;

    return 0;
}


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

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

    vector<ll> a, b;
    ll x = 1, y = 1;
    while (1){
        if (x > INF / 3) break;
        if (x > n) break;
        x *= 3;
        a.push_back(x);
    }
    while (1){
        if (y > INF / 5) break;
        if (y > n) break;
        y *= 5;
        b.push_back(y);
    }

    // for (auto ele : a){
    //     printf("%lld ", ele);
    // }
    // cout << endl;
    // for (auto ele : b){
    //     printf("%lld ", ele);
    // }
    // cout << endl;

    rep(i,(int)a.size()){
        rep(j,(int)b.size()){
            if (a[i] + b[j] == n){
                printf("%lld %lld\n", i+1, j+1);
                return 0;
            }
        }
    }
    cout << -1 << endl;
    return 0;
}

//
//  main.cpp
//  atcoder
//
//  Created by 荣恒嬉 on 2020/10/24.
//

#include <bits/stdc++.h>
#define ll unsigned long long
using namespace std;
int main() {
	ll a;
	cin>>a;
	ll x=1,y=1;
	for(int i=1;i<38;i++){
		x*=3;
		ll y=1;
		for(int j=1;j<28;j++){
			y*=5;
			if(x+y==a)
			{
				cout<<i<<" "<<j;
				return 0;
			}
		}
	}
	cout<<-1;
	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;}
#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>;
template<typename T>bool chmin(T& x,const T&y) {if(x>y){x=y;return true;} else return false;}
template<typename T>bool chmax(T& x,const T&y) {if(x<y){x=y;return true;} else return false;}

template<typename T>
struct BIT {
    int n;
    vector<T> d;
    BIT(int n=0):n(n), d(n+1) {}
    void add(int i, T x=1) {
        for (i++; i <= n; i += i&-i) {
            //i&-iで最下位bitを足している
            d[i] += x;
        }
    }
    T sum(int i) {
        T x = 0;
        for (i++; i; i -= i&-i) {
            x += d[i];
        }
        return x;
    }
    T semiopenSum(int l, int r) {
        // [l,r)の半開区間
        return sum(r-1) - sum(l-1);
    }
};  // BIT<int> bit(N);

int main() {
    ll H, W, M;
    cin >> H >> W >> M;
    vector<int> col(W, H), row(H, W);
    rep(i, M) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        chmin(col[y], x);
        chmin(row[x], y);
    }
    ll ans = 0;
    rep(i, col[0]) ans += row[i];
    rep(j, row[0]) ans += col[j];
    vector<vector<int>> A(H+1);
    rep(j, row[0]) A[col[j]].push_back(j);
    BIT<int> bit(W+1);
    rep(j, row[0]) bit.add(j, 1);
    rep(i, col[0]) {
        for (int a : A[i]) {
            bit.add(a, -1);
        }
        ans -= bit.semiopenSum(0, row[i]);
    }
    cout << ans << '\n';
    return 0;
    // 重複, 境界, 条件, ll (1e5のnCr), 0, -, 1i, for s&g, debug
}

#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)
const int mod = 1e9+7;
const int mod1 = 998244353;
const ll inf = 1e14;
const int nax = 200005;
int H, W, M, x[nax], y[nax], L[nax], T[nax], a[nax];
vector<int> row[nax];
void MIN(int &a, int b){
  a = min(a, b);
}
void update(int pos){
  while(pos <= W){
    a[pos]++;
    pos += pos&-pos;
  }
}
int sum(int pos){
  int now = 0;
  while(pos >= 1){
    now += a[pos];
    pos -= pos&-pos;
  }
 return now;
}
void solve()
 {
  cin>>H>>W>>M;
  for(int i = 1; i <= H; i++)
     L[i] = W + 1;
  for(int i = 1; i <= W; i++)
     T[i] = H + 1;
  for(int i = 1; i <= M; i++){
    cin>>x[i]>>y[i];
    MIN(L[x[i]], y[i]);
    MIN(T[y[i]], x[i]);
  }
  ll ans = 0;
  for(int i = 1; i <= W; i++){
    if(i < L[1])
      ans += T[i] - 1;
    else
      T[i] = 1;
    row[T[i]].pb(i);
  }
  for(int i = 1; i < T[1]; i++){
    ans += sum(L[i] - 1);
    for(int x : row[i])
       update(x);
  }
  cout<<ans;
 }
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
 /* int t;
  cin>>t;
  while(t--)*/
   solve();
  return 0;
}


#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpl = vector<pair<ll, ll>>;
using pll = pair<ll, ll>;
#define rep(i, k, n) for(ll i = k; i < n; i++)
#define pb push_back
#define mp make_pair

int main(){
    ll n; cin >> n;
    vll a(n);
    rep(i, 0, n) cin >> a[i];

    sort(a.begin(), a.end());
    ll ans = 0;
    rep(i, 0, n){
        ans += ((2*i+1) - n) * a[i];
    }

    cout << ans << endl;
}

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

#define ar array<ll, 2>
#define ll long long
#define in insert
#define pb push_back
#define pii pair<ll,ll>
#define vt vector
#define P_Q(x) priority_queue<x>
#define p_q(x) priority_queue<x, vector<x>, greater<x>>
#define For(i, n) for(ll i = 0; i < n; i++)
#define Rev(i, n) for(ll i = n-1; i >= 0; i--)
#define FOR(i, n) for(ll i = 1; i <= n; i++)
#define REV(i, n) for(ll i = n; i >= 1; i--)
#define Rep(i,a,b) for(ll i = a; i <= b; i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int) (x).size()

void solve()
{
  long double x,y,r;
  cin>>x>>y>>r;
  ll ans=0;
  r=nextafter(r,1e14);
  for(ll i=ceil(x-r);i<=floor(x+r);i++)
  {
  	long double count=sqrt((r*r)-(x-i)*(x-i));
  	ans+=floor(y+count)-ceil(y-count)+1;
  }
  cout<<ans<<endl;
   return;
}

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


#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int i,f=0,p=0;
    string s,s1;
    cin>>s;
    for(i=s.size()-1;i>=0;i--)
    {
        if(s[i]!='0')break;
        else if(s[i]=='0')p++;
    }
    for(i=1;i<=p;i++)
    {
        s1+='0';
    }
    for(i=0;i<s.size();i++)
    {
        s1+=s[i];
    }
    for(i=0; i < s1.size() ; i++)
    {
        if(s1[i] != s1[s1.size()-i-1])
        {
            f = 1;
            break;
        }
    }
    if(f==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0 ;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,f=0,b,c=0,d;
	cin>>a;
	while(a%10==0&&a!=0){
	a/=10;
	}
	d=a;
	while(a>0){
	b=a%10;
	a/=10;
	c=c*10+b;
	}
	if(d==c) f=1;
    if(f==1) cout<<"Yes";
    else cout<<"No";
	return 0;
}


/*Bismillahi-r-Rahmani-r-Rahim*/
#include<bits/stdc++.h>
using namespace std;
#define  ll         long long
#define  pi         acos(-1.0)
#define  mod        1000000007
#define  yes        cout<<"YES"<<endl
#define  no         cout<<"NO"<<endl
#define  vi         vector<int>
#define  vl         vector<ll int>
#define  pb         push_back
#define  test       cin>>t;while(t--)
#define  lcm(a,b)   a*b/__gcd(a,b)
#define  sd         second
#define  ft         first

int main()
{
     ios_base::sync_with_stdio(false);cin.tie(NULL);
     ll int i,n,t,j=0,p,x,a=0,b,l=0,r=0,y,k,c,sum=0,m,d,cnts=0;
     cin>>n;
     map<string,int>mp;
    // map<string,int>:: iterator it;

     string sm,sp;
     for(i=0;i<n;i++){
        cin>>sm;
        mp[sm]++;
     }
     i=0;
     string s[mp.size()];
     for(auto it : mp){
       sp=it.ft;
       if(sp[0]=='!'){
        sp=sp.substr(1,sp.size()-1);
       }

       s[i++]=sp;

     }
     l=0;
     sort(s,s+mp.size());
     for(i=0;i<mp.size()-1;i++){
        if(s[i]==s[i+1]){
            l=1;sm=s[i];break;
        }
     }
     if(l==0){
        cout<<"satisfiable"<<endl;
     }
     else{
        cout<<sm<<endl;
     }

}

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__)
#define boost {ios_base::sync_with_stdio(false); cin.tie(); cout.tie();}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <int> vi;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll nax = 2e5+6969, INF = 2e9+6969;

int n;
set <string> a,b;

int main()
{
	cin >> n;
	for(int i=0;i<n;i++)
	{
		string tmp;
		cin >> tmp;
		if(tmp[0] == '!') a.insert(tmp);
		else b.insert(tmp);
	}
	string ans = "satisfiable";
	for(auto e: b)
	{
		string tmp = "!" + e;
		if(a.find(tmp) != a.end()) ans = e;
	}
	cout << ans << "\n";
	return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (ll i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){

    int N;
    string S;
    string T;
    cin >> N >> S >> T ;

    int n1 = count(all(S),'0');
    int n0 = count(all(T),'0');

    int szc=0, tzc=0;

    if (n1!=n0)
        cout << "-1" <<endl;
    else{
        vector<int> sv (n0);
        vector<int> tv (n0);
        rep(i,N){
            if (S[i]=='0'){
                sv[szc]=i;
                szc++;
            }
            if (T[i]=='0'){
                tv[tzc]=i;
                tzc++;
            }
        }
        int ans = 0;

        rep(i,n0){
            //cout << sv[i]<<" " <<tv[i]<<endl;
            if (sv[i]!=tv[i])
                ans++;
        }
        cout <<ans <<endl;

    }
    return 0;
}

#include <bits/stdc++.h>
#define ll long long int
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define N 200005
using namespace std;
void great(){
    cout<<">";
}
void same(){
    cout<<"=";
}
void small(){
    cout<<"<";
}
int main()
{
    ll a,b,c;
    cin>>a>>b>>c;
    if(a>0 && b>0){
        if(a>b) great();
        else if(a<b) small();
        else same();
    }
    else if(a==0){
        if(b==0) same();
        else if(b<0){
            if(c&1) great();
            else small();
        }
        else small();
    }
    else if(b==0){
        if(a<0){
            if(c&1) small();
            else great();
        }
        else great();
    }
    else if(a>0){
        if(c&1) great();
        else{
            if(a>abs(b)) great();
            else if(a==abs(b)) same();
            else small();
        }
    }
    else{
        if(b>0){
            if(c&1) small();
            else{
                if(abs(a)>b) great();
                else if(abs(a)==b) same();
                else small();
            }
        }
        else{
            if(c%2==0){
                a=abs(a);
                b=abs(b);
            }
            if(a>b) great();
            else if(a==b) same();
            else small();
        }
    }
    return 0;
}


/*
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
*
* @author: Xingjian Bai
* @date: 2021-04-10 13:21:51
* @description:
*
*
* @notes:
* g++ -fsanitize=address -ftrapv
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  */
#include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define TIME (double)clock()/CLOCKS_PER_SEC
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
const int mod = 1000000007;
const ll oo = 1e18;
const ld eps = 1e-8;
#define debug(x) cerr << "(debug mod) " << #x << " = " << x << endl

int n;
ll v[1000010], s[1000010];
priority_queue <ll> q;

int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= 2 * n; i ++) {
    	cin >> v[i];
    	s[i] = s[i - 1] + v[i];
    }
    // ll mn = 1e16;
    // for (int i = n; i <= 2 * n; i ++)
    	// mn = min (mn, s[i] - s[i - n]);
    // cerr << mn << " " << s[2 * n] << endl;
    // cout << s[2 * n] - mn << endl;

    ll mn = 0;
    for (int i = n; i >= 1; i --) {
    	q.push(-v[i]);
    	q.push(-v[n + n - i + 1]);
    	mn += q.top();
    	q.pop();
    }
    cout << s[2 * n] + mn << endl;
    return 0;
}

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define ef(a) emplace_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define tomax(a, b) ((a) = max((a), (b)))
#define tomin(a, b) ((a) = min((a), (b)))
#define topos(a) ((a) = (((a) % MOD + MOD) % MOD))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

using namespace std;
using namespace __gnu_pbds;

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

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

ll ifloor(ll a, ll b){
    if(b < 0) a *= -1, b *= -1;
    if(a < 0) return (a - b + 1) / b;
    else return a / b;
}

ll iceil(ll a, ll b){
    if(b < 0) a *= -1, b *= -1;
    if(a > 0) return (a + b - 1) / b;
    else return a / b;
}

int main(){
    StarBurstStream

    int n;
    cin >> n;

    vector<ll> v(2 * n + 1);
    ll sum = 0;
    for(int i = 1; i <= 2 * n; i++){
        cin >> v[i];
        sum += v[i];
    }

    std::priority_queue<ll, vector<ll>, greater<>> pq;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        pq.push(v[n - i + 1]);
        pq.push(v[n + i]);
        ans += pq.top();
        pq.pop();
    }
    ans = sum - ans;
    cout << ans << "\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(v)	((v).begin()), ((v).end())
#define pb	push_back
#define mp	make_pair
#define mod 1000000007
#define debug(x)  cout<<#x<<" = "<<x<<" \n"
typedef long long ll;
typedef unsigned long long ull;
void xin(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}
// int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
// inline bool valid(int x, int y, char v) {
//     return x >= 0 && x < n && y >= 0 && y < m && !visited[x][y] && grid[x][y] == v;
// }

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

    char S,T;
    cin>>S>>T;
    if(S == 'Y')
    {
        cout<<char(T-32)<<endl;
    }
    else
    {
        cout<<T<<endl;
    }

    return 0;

}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define init(a,i) for(int k=0;k<(i);k++)(a)[k]=0
#define in(a,i) for(int k=0;k<(i);k++)cin>>(a)[k]
#define all(a)  (a).begin(),(a).end()
#define inf 2147483647
#define range(x,a,b) (a)<=x&&x<=(b)
int main(){
	char s,t;
	cin>>s>>t;
	if(s=='Y'){
		switch(t){
			case 'a':
			cout<<'A';
			break;
			case 'b':
			cout<<'B';
			break;
			case 'c':
			cout<<'C';
			break;
		}
	}
	else {
		cout<<t;
	}
	return 0;
}


#ifdef LOCAL
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#endif
#include "bits/stdc++.h"

using namespace std;
using namespace std::chrono;

#define ll long long
#define vll vector<ll>
#define pii pair<ll,ll>
#define un_mp unordered_map<ll,ll,modified_hash>
#define endl "\n"
#define pb push_back
#define all(a) a.begin(),a.end()

ll  mod=1000000007;

struct modified_hash {

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

    ll operator()(uint64_t x) const{
        static const uint64_t random= steady_clock::now().time_since_epoch().count();
        return splitmix64(x + random);
    }
};
const ll N = 1000000;
ll lp[N+1];
vector<ll> pr;

void solve(){
    ll a,b,k,c,n,d,m,x,y,l,r;
	ll i,j;
    cin>>l>>r;
    ll fans=0;
    for(ll i=2LL;i<=r;i++){
        un_mp mp;
        ll fk=i;
        bool flag=true;
        while (fk>1){
            mp[lp[fk]]++;
            if(mp[lp[fk]]>1) flag=false;
            fk/=lp[fk];
        }

        ll cnt=mp.size();
        ll ans=r/i-((l-1)/i);
        if(flag&&cnt%2==0){
            fans-=(ans*(ans-1))/2;
        }
        else if(flag){
            // cout<<i2<<" "<<ans<<endl;
            fans+=(ans*(ans-1))/2;
        }

    }
    for(ll i=max(2LL,l);i<=r;i++) fans-=(r/i-1);
    cout<<fans*2<<endl;

    return;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c,n,tt,d,m,k,x,y;
    tt=1;
    // cin>>tt;
    for (ll i=2;i<=N;++i){
        if (lp[i]==0){
            lp[i]=i;
            pr.push_back(i);
        }
        for (ll j=0;j<(ll)pr.size()&&pr[j]<=lp[i]&&i*pr[j]<=N;++j){
            lp[i*pr[j]]=pr[j];
        }
    }
    while(tt--){
        solve();
    }
}

// E - Divide Both
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

int main(){
	int L, R; cin>>L>>R;

	auto x = [&](int k){ return R/k - (L-1)/k; };

	ll ans = 0;
	vector<ll> F(R+1);
	for(int k=R; k>=2; --k){
		ll c = x(k);
		F[k] = c * c;
		for(int g=2*k; g<=R; g+=k) F[k] -= F[g];
		ans += F[k];
	}

	for(int g=max(2, L); g<=R; ++g) ans -= x(g)*2 - 1;
	cout<< ans <<endl;
}


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

using namespace std;

int cd(long long int i){
    int j=0;
    while(i){
        j++;
        i=i/10;
    }
    return j;
}

int main(){
    int N;
    cin>>N;
    vector<int> V1(N);
    vector<int> V2(N);
    int max=0, min=INT32_MAX;
    for(int i=0; i<N; i++){
        cin>>V1[i];
        if(V1[i]>max){
            max=V1[i];
        }
    }
    for(int i=0; i<N; i++){
        cin>>V2[i];
        if(V2[i]<min){
            min=V2[i];
        }
    }
    if(max>min){
        cout<<0;
    }
    else{
        cout<<min-max+1;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,sum=0,c;
	cin>>n;
	int a[n+1],b[n+1];
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<=1000;i++)
	{
		c=1;
		for(int j=1;j<=n;j++)
			if(i<a[j]||i>b[j])
				c=0;
		if(c==1)
			sum++;
	}
	cout<<sum;
	return 0;
}


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

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

  int n;
  cin >> n;
  long long ans = 0;
  vector<int> a(2 * n);
  for (auto &i : a) cin >> i;
  priority_queue<int, vector<int>, greater<int>> pq;
  pq.emplace(max(a[n - 1], a[n]));
  for (int i = 1; i < n; i++) {
    int u = a[n - i - 1];
    int v = a[n + i];
    if (pq.top() < min(u, v)) {
      pq.pop();
      pq.emplace(min(u, v));
    }
    pq.emplace(max(u, v));
  }
  while (!pq.empty()) {
    ans += pq.top();
    pq.pop();
  }
  cout << ans << '\n';
  return 0;
}

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

int main(){
    int N; cin >> N;
    vector<pair<ll, ll>> range(N);
    for(int i = 0; i < N; i++){
        int t; ll l, r; cin >> t >> l >> r;
        l *= 2LL; r *= 2LL;
        if(t == 2 || t == 4)r--;
        if(t == 3 || t == 4)l++;
        range[i] = make_pair(l, r);
    }
    int ans = 0;
    for(int i = 0; i < N - 1; i++){
        ll l1 = range[i].first, r1 = range[i].second;
        for(int j = i + 1; j < N; j++){
            ll l2 = range[j].first, r2 = range[j].second;
            if(r1 < l2 || l1 > r2)continue;
            ans++;
        }
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
#define PI 3.141592653589793238462
#define eps 1e-20
#define fi first
#define se second
using namespace std;
using cd = complex<double>;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdd;
ll mod=1e9+7;
ll qpow(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1) res=res*a%mod;
        a=a*a%mod;b/=2;
    }return res%mod;
}
int main(){
    ll n,p;cin>>n>>p;
    ll x=p-1,ans=x;
    ans*=qpow(x-1,n-1);
    cout<<ans%mod<<endl;
}

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

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

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


#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int n,q,c[maxn],f[maxn];
map <int,int> mp[maxn];

inline int F(int x)
{
	if(f[x]==x) return x;
	return f[x]=F(f[x]);
}

inline void mer(int u,int v)
{
	int tx=F(u),ty=F(v);
	if(tx!=ty)
	{
		int x=mp[tx].size(),y=mp[ty].size();
		if(x<y)
		{
			for(map <int,int>::iterator it=mp[tx].begin();it!=mp[tx].end();it++)
			{
				pair <int,int> p=*it;
				mp[ty][p.first]+=p.second;
			}
			f[tx]=ty;
		}
		else
		{
			for(map <int,int>::iterator it=mp[ty].begin();it!=mp[ty].end();it++)
			{
				pair <int,int> p=*it;
				mp[tx][p.first]+=p.second;
			}
			f[ty]=tx;
		}
	}
}

int main()
{
	n=read(); q=read(); rep(i,1,n) c[i]=read(),f[i]=i;
	rep(i,1,n) mp[i][c[i]]++;
	while(q--)
	{
		int opt=read(),u=read(),v=read();
		if(opt==1) mer(u,v);
		else
		{
			printf("%d\n",mp[F(u)][v]);
		}
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()

 ll H,W;
ll A,B;
vector<vector<bool>> note;

ll dfs(ll h,ll w,ll count) {
    if(h==H-1&w==W-1) {

        if(count==A) {
            return 1;
        }
        else return 0;
    }

ll s=0;

if(!note[h][w]) {
if(h<H-1&&w<W-1) {
    if(!note[h+1][w]) {
        note[h][w]=true;
        note[h+1][w]=true;
        s+=dfs(h+1,w,count+1);
        note[h][w]=false;
        note[h+1][w]=false;
    }
    if(!note[h][w+1]) {
        note[h][w]=true;
        note[h][w+1]=true;
        s+=dfs(h+1,w,count+1);
     note[h][w]=false;
     note[h][w+1]=false;
    }

    s+=dfs(h+1,w,count);
}
else if(h==H-1) {
    if(!note[h][w+1]) {
        note[h][w]=true;
        note[h][w+1]=true;
        s+=dfs(0,w+1,count+1);
        note[h][w]=false;
        note[h][w+1]=false;
        s+=dfs(0,w+1,count);
    }
    else {
        s+=dfs(0,w+1,count);
    }
}
else {
    if(!note[h+1][w]) {
        note[h][w]=true;
        note[h+1][w]=true;
        s+=dfs(h+1,w,count+1);
    note[h][w]=false;
    note[h+1][w]=false;
    s+=dfs(h+1,w,count);
    }
else {
    s+=dfs(h+1,w,count);
}
}

}

else {
    if(h<H-1) {
        s+=dfs(h+1,w,count);
    }
    else {
        s+=dfs(0,w+1,count);
    }
}

return s;
}

  int main() {

     cin>>H>>W;

     cin>>A>>B;

     note=vector<vector<bool>>(H,vector<bool> (W,false));

     cout<<dfs(0,0,0)<<endl;
  }


/*
	may God of speed-forces be with us !!

	--problem isnt, life is empty;
	--problem is, life is full of emptiness;
		a non-strugling pupil coder !!
*/

#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
//#define biGinf 9e+18
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define inpv(v) for(auto &x:v) cin>>x
#define otpv(v) for(auto &x:v) cout<<x<<nwl
#define otpv2(v) for(auto &x:v) cout<<x<<" "
#define CASES int tt;cin>>tt; while(tt--)
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define forr(i,r,n) for(int i=r; i<=n; i++)
#define forj(j,n) for(int j=n; j>=0; j--)
#define forx(x,v) for(auto &x:v)
#define sz(v) (int)(v).size()
#define rz(n) resize(n)
#define vec(x) vector < x >
#define vvim(n,m,v) vvi v(n, vi(m))
using int64 = long long;
using vi = vector < int >;
using vi64 = vector < int64 >;
using mii = map <int , int >;
using vvi = vector < vi >;
using pii = pair < int , int >;
using vpii = vector < pii >;
const int inf = 2e9 + 7;
const char nwl = '\n';
const int mxx = 1e6 + 3;
int64 sumV(vi &v) {
	int64 s = 0;
	for (int x : v) {
		s += (int64)x;
	}
	return s;
}
int gcd(int a, int b) {
	if (!b) return a;
	return gcd(b, a % b);
}
//const int64 biGinf = 9e+18;
const string yo = "Yes\n", no = "No\n";

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ur code

	int n;
	cin >> n;
	vpii v(n);
	for0(i, n) {
		cin >> v[i].F >> v[i].S;
	}

	std::map<int, int> x, y, z;

	for0(i, n) {
		x[v[i].F]++;
		y[v[i].S]++;
		z[v[i].F - v[i].S]++;
	}

	bool f = 0;

	for (auto e : x) {
		if (e.S >= 3)f = 1;
		if (f) break;
	}

	for (auto e : y) {
		if (e.S >= 3)f = 1;
		if (f) break;
	}
	for (auto e : z) {
		if (e.S >= 3)f = 1;
		if (f) break;
	}
	if (!f) {
		for0(i, n) {
			for (int j = i + 1; j < n; j++) {
				for (int k = j + 1; k < n; k++) {
					if ((v[i].F - v[j].F) and (v[i].F - v[k].F)) {
						if (((float)(v[i].S - v[j].S) / ((v[i].F - v[j].F))) == ((float)(v[i].S - v[k].S) / ((v[i].F - v[k].F)))) f = 1;
					}
					if (f) break;
				}
				if (f) break;
			}
			if (f) break;
		}
	}
	if (f) cout << yo;
	else cout << no;

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i) >> y.at(i);
  }

  string ans = "No";

  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      for (int k = j+1; k < n; k++) {
        int x1 = x.at(j) - x.at(i);
        int y1 = y.at(j) - y.at(i);
        int x2 = x.at(k) - x.at(i);
        int y2 = y.at(k) - y.at(i);
        if (x1*y2 == x2*y1) {
          ans = "Yes";
        }
      }
    }
  }

  cout << ans << endl;
  return 0;
}


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

int n,m,ans;

int now[2008],to[20000],pre[20000],tot;

void add(int x,int y) {
	to[++tot]=y;
	pre[tot]=now[x];
	now[x]=tot;
}

bool vis[20000];
void dfs(int u) {
	vis[u]=1;
	ans++;
	for(int i=now[u]; i; i=pre[i]) {
		int v=to[i];
		if(!vis[v]) dfs(v);
	}
}

int main() {
	cin>>n>>m;
	for(int i=1,x,y; i<=m; i++) {
		cin>>x>>y;
		add(x,y);
	}
	for(int i=1; i<=n; i++) {
		memset(vis,0,sizeof vis);
		dfs(i);
	}
	printf("%d\n",ans);
	return 0;
}

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

vector<vector<int>> g;
vector<int> visited;

int dfs(int v) {
  int res = 1;
  visited[v] = 1;
  for (auto nv : g[v]) {
    if (visited[nv]) continue;
    res += dfs(nv);
  }
  return res;
}

int main() {
  int n, m;
  cin >> n >> m;
  g.resize(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
  }
  int ans = 0;
  rep(i, n) {
    visited.assign(n, 0);
    ans += dfs(i);
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define f(a,b,c,d) for(ll a=b; a<c; a+=d)
#define MOD 1000000007
#define pb push_back
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue

void solve()
{
  	ll a, b, c;
  cin >> a >> b >> c;
  cout << 21 - a - b - c;
}

signed main()
{

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

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

    ll t = 1;
    //cin >> t;
    ll tt = t;
    while (t--)
    {
        //cout << "Case #" << tt - t << ": ";
        solve();
    }
}

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
#define int long long
#define ll long long
#define pii std::pair<int, int>
#define pdd std::pair<double, double>
#define INF (1LL << 33)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define SHOW(p)                                                                \
  if (test)                                                                    \
    cout << #p " : " << p << endl;
bool test = false;
int R, X, Y;
signed main() {
  test = true;
  test = false;
  cin >> R >> X >> Y;
  if (test) {
    cout << X * X + Y * Y << endl;
  }
  if (X * X + Y * Y == R * R) {
    cout << 1 << endl;
  } else if (X * X + Y * Y <= 4 * R * R) {
    cout << 2 << endl;
  } else {
    cout << ceil(sqrt((X * X + Y * Y - 1) / (R * R) + 1)) << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using Int = long long;  // clang-format off
using pii = std::pair<Int, Int>;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define RREP_(i, a_, b_, a, b, ...) for (Int i = Int(b) - 1, low##i = (a); i >= low##i; i--)
#define RREP(i, ...) RREP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on
struct in {
    template <class T> operator T() {
        T t;
        std::cin >> t;
        return t;
    }
};
void out() { std::cout << "\n"; }
template <class Head, class... Tail> void out(Head&& h, Tail&&... t) {
    std::cout << h << (sizeof...(Tail) == 0 ? "" : " "), out(std::forward<Tail>(t)...);
}
template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; }
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; }
template <class T> using V = std::vector<T>;

/**
 *    author:  knshnb
 *    created: Sun Jun 27 14:56:28 JST 2021
 **/

using comp = std::complex<double>;
double EPS = 1e-8;
bool equal(double a, double b) { return std::abs(a - b) < EPS; }
bool equal(comp a, comp b) { return std::abs(a - b) < EPS; }
bool set_equal(V<comp> a, V<comp> b) {
    for (comp x : a) {
        bool del = false;
        for (comp y : b) {
            if (equal(x, y)) {
                del = true;
                b.erase(std::find(ALL(b), y));
                break;
            }
        }
        if (!del) return false;
    }
    return true;
}
bool check(V<comp> a, V<comp> b, Int i, Int j) {
    Int n = a.size();
    comp dif1 = a[0], dif2 = b[i];
    REP(k, n) a[k] -= dif1, b[k] -= dif2;
    if (!equal(std::abs(a[1]), std::abs(b[j]))) return false;
    comp arg = a[1] / b[j];
    assert(equal(std::abs(arg), 1.));
    REP(k, n) b[k] *= arg;
    return set_equal(a, b);
}
signed main() {
    Int n = in();
    V<comp> s(n), t(n);
    REP(i, n) s[i].real(in()), s[i].imag(in());
    REP(i, n) t[i].real(in()), t[i].imag(in());
    if (n == 1) {
        out("Yes");
        return 0;
    }
    REP(i, n) {
        REP(j, n) {
            if (i == j) continue;
            if (check(s, t, i, j)) {
                out("Yes");
                return 0;
            }
        }
    }
    out("No");
}

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

using I64 = int64_t;

template <typename T> T gcd(T x, T y) {
  if (y == 0) {
    return x;
  } else {
    return gcd(y, x % y);
  }
}

template <typename T> T lcm(T x, T y) { return x / gcd(x, y) * y; }

const char NL = '\n';

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> va(N), vb(M);
  for (auto &a : va) {
    cin >> a;
  }
  for (auto &b : vb) {
    cin >> b;
  }

  sort(va.begin(), va.end());
  sort(vb.begin(), vb.end());

  auto ia = va.begin();
  auto ib = vb.begin();
  vector<int> ans;
  for (; ia != va.end() || ib != vb.end();) {
    if (ia == va.end()) {
      ans.push_back(*ib);
      ib++;
    } else if (ib == vb.end()) {
      ans.push_back(*ia);
      ia++;
    } else if (*ia > *ib) {
      ans.push_back(*ib);
      ib++;
    } else if (*ia < *ib) {
      ans.push_back(*ia);
      ia++;
    } else {
      ia++;
      ib++;
    }
  }

  bool blank = false;
  for (auto x : ans) {
    if (blank) {
      cout << ' ';
    }
    cout << x;
    blank = true;
  }
  cout << NL;
}


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

int N;
ll X;
vector<ll> A;
map<pair<int, ll>, ll> memo;

ll dfs(int i, ll x) {
    if (x == 0) return 1;
    if (i == -1) return 0;
    if (i < N - 1 && A[i + 1] <= x) return 0;
    if (x % A[i] == 0) return 1;
    if (memo.count({i, x})) return memo[{i, x}];
    ll a = x / A[i];
    ll ret = 0;
    if (i == N - 1 || A[i] * a < A[i + 1]) {
        ret += dfs(i - 1, x - A[i] * a);
    }
    if (i == N - 1 || A[i] * (a + 1) < A[i + 1]) {
        ret += dfs(i - 1, A[i] * (a + 1) - x);
    }
    return memo[{i, x}] = ret;
}

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

    cin >> N >> X;
    A.resize(N);
    for (auto& x : A) cin >> x;
    cout << dfs(N - 1, X) << endl;
}

#include<bits/stdc++.h>
using namespace std;
char s[101][101];
int ans;
int main() {
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; i++)
		scanf("%s",s[i]+1);
	for(int i=1; i<n; i++) {
		bool ok=false;
		for(int j=1; j<=m; j++) {
			if(s[i][j]!=s[i+1][j]) {
				if(!ok) {
					ans++;
					ok=true;
				}
			} else ok=false;
		}
	}
	for(int i=1; i<m; i++) {
		bool ok=false;
		for(int j=1; j<=n; j++) {
			if(s[j][i]!=s[j][i+1]) {
				if(!ok) {
					ans++;
					ok=true;
				}
			} else ok=false;
		}
	}
	printf("%d\n",ans);
	return 0;
}


#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    long long n;
    cin >> n;

    vector<long long> fibs;
    fibs.push_back(1);
    fibs.push_back(1);

    while (fibs.back() < n) {
        long long x = fibs[fibs.size() - 2] + fibs[fibs.size() - 1];
        fibs.push_back(x);
    }

    const int LIMIT = 130;
    // const int LIMIT = 0;
    vector<int> res;
    if (n < LIMIT) {
        for (int i = 0; i < n; ++i) {
            res.push_back(1);
        }
    } else {
        int m = fibs.size();

        if (fibs.back() == n) {
            for (int i = m - 1, t = 3; i > 1; --i, t = 7 - t) {
                res.push_back(t);
            }
            res.push_back(1);
            res.push_back(2);
        } else {
            assert(fibs.back() > n);

            vector<int> coes(m, 0);
            {
                long long x = n - fibs[m - 2];
                // cout << "X " << x << endl;
                for (int i = m - 1; i >= 0; --i) {
                    coes[i] = x / fibs[i];
                    x -= coes[i] * 1LL * fibs[i];
                }
            }

            for (int i = m - 2, j = 0, t = 3; i > 1; --i, t = 7 - t, ++j) {
                for (int k = 0; k < coes[j]; ++k) {
                    res.push_back(t >> 1);
                }
                res.push_back(t);
            }
            res.push_back(1);
            res.push_back(2);
        }
        reverse(res.begin(), res.end());
    }

    auto calc = [&](vector<int>& ops) {
        long long x = 0;
        long long y = 0;
        for (auto op : ops) {
            if (op == 1) {
                ++x;
            } else if (op == 2) {
                ++y;
            } else if (op == 3) {
                x += y;
            } else {
                assert(op == 4);
                y += x;
            }
        }
        return x;
    };

    // cout << calc(res) << " | " << n << endl;

    cout << res.size() << '\n';
    for (auto x : res) {
        cout << x << '\n';
    }

    return 0;
}

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

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

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N; cin>>N;
    vll fib(2); fib[0]=fib[1]=1;
    for(int i=2; fib[i-2]+fib[i-1]<=N; i++){
        fib.pb(fib[i-2]+fib[i-1]);
    }
    int F = fib.size();

    set<int> se;
    RFOR(i,F-1,0){
        if (fib[i]>N) continue;
        se.ins(i);
        N-=fib[i];
    }

    vi ans;
    RFOR(i,F-1,0){
        if (se.count(i)){
            if (i&1) ans.pb(2);
            else ans.pb(1);
        }
        if (i&1) ans.pb(3);
        else ans.pb(4);
    }
    int K = ans.size();
    cout<<K<<"\n";
    rep(i,K) cout<<ans[i]<<"\n";

    return 0;
}


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

#define int long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define pll pair<int,int>
#define MOD 1000000007
#define M2 998244353
#define INF 2e18
#define EPS 1e-9
#define minheap priority_queue<int, vector<int>, greater<int>>
const ld PI = 3.14159265358979323846;
const int MAX_N = 1e6 + 5;

vector<int> findVals(int a) {
    vector<int> vals;
    int val = a;
    vals.pb(a);
    if (a == 1)
        return vals;
    val = val * a;
    val = val % 10;
    while (val != a) {
        vals.pb(val);
        val *= a;
        val %= 10;
    }
    return vals;
}

int power(int x, int y, int p) {
    int res = 1;
    x = x % p;

    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

void solve() {
    int a, b, c;
    cin >> a >> b >> c;
    a %= 10;
    vector<int> vals = findVals(a);
    int len = vals.size();
    if (len == 1) {
        cout << a << "\n";
        return;
    }
    b %= len;
    int rem = power(b, c, len);
    rem %= len;
    int ind = rem - 1;
    if (ind < 0)
        ind = len - 1;

    cout << vals[ind] << "\n";

}

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

// clang-format off
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcountll
#define ffs __builtin_ffsll
#define ctz __builtin_ctzll
#define clz __builtin_clz
#define clzll __builtin_clzll
#define all(a) (a).begin(), (a).end()

using namespace std;
using namespace __gnu_pbds;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
// clang-format on

int main() {
    fastio();

    int n;
    string s, t;
    cin >> n >> s >> t;

    int borrow = 0;
    ll ans = 0;
    forn(i, n) {
        ans += borrow;

        if (s[i] == '1' and t[i] == '0') {
            if (borrow > 0)
                borrow--;
            else
                borrow++;
        }

        if (s[i] == '0' and t[i] == '1') {
            borrow++;
        }
    }

    bool ok = borrow == 0;

    cout << (ok ? ans : -1) << endl;

    return 0;
}


#ifdef _DEBUG
#include "../../../library/src/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else
#define DMP(...) ((void)0)
#endif

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <functional>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

struct init {
    init() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} init_;

lint modpow(lint a, lint n, lint mod = MOD) {
    lint res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {

    lint N, M;
    cin >> N >> M;

    cout << modpow(10, N, M * M) / M % M << '\n';

    return 0;
}

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

bool solve(long long s, long long p) {
    p = 4 * p;
    long long up = min(p, (long long)sqrt(p) + 5);
    for (long long p1 = 1; p1 <= up; p1++) {
        if (p % p1 == 0 && 2 * s == p1 + p / p1) return true;
    }
    return false;
}

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

    long long s, p;
    cin >> s >> p;
    cout << (solve(s, p) ? "Yes" : "No") << "\n";

    return 0;
}


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

typedef long long int ll;
#define All(a) (a).begin(),(a).end()
#define INF numeric_limits<ll>::max()
#define MOD 1000000007
ll n;
vector<ll> v;

bool check(ll md){
	vector<ll> y;
	ll N=n;
	while(N>0){
		y.push_back(N%md);
		N/=md;
	}
	reverse(All(y));
	if(v.size()>y.size()) return false;
	if(v.size()<y.size()) return true;
	for(ll i=0;i<v.size();i++){
		if(v[i]<y[i])return true;
		if(v[i]>y[i])return false;
	}
	return true;
}

int main(){
	ll ans,MAX=0,tmp;
	string s;
	cin >> s>>n;

	if(s.size()==1){
		if((s[0]-'0')<=n){
			cout<<1<<endl;
		}else{
			cout<<0<<endl;
		}
		return 0;
	}

	for(auto i:s){
		tmp=i-'0';
		v.push_back(tmp);
		MAX=max(MAX,tmp);
	}

	//reverse(All(v));

	ll ng=n+1,ma=MAX,md;
	//cout << ng <<" "<<ma<< endl;

	while(ng-ma>1){
		ll md=(ma+ng)/2;
		//cout<<md<<endl;
		if(check(md)){
			ma=md;
		}else{
			ng=md;
		}

	}
	cout<<ma-MAX<<endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    int ans = 1;
    for(int i = b - a; i ; i--)
    {
        if(b / i != (a + i - 1) / i)
        {
            cout << i;
            break;
        }
    }
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i, n, s) for (int i = (int)(n); i >= (int)(s); i--)
#define mp make_pair
#define tp make_tuple
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef tuple<int,int,int> T;
typedef tuple<ll,ll,ll> TL;
ll mod = 1000000007;
ll mod2 = 998244353;

struct UnionFind {
    int _n;
    vector<int> par, siz;

    UnionFind(int n) : par(n), siz(n, 1) {
        _n = n;
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    int unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return -1;
        if (siz[rx] < siz[ry]) swap(rx, ry);
        // rx>=ry rxが親
        siz[rx] += siz[ry];
        par[ry] = rx;  //rxにryを結合
        return rx;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        return siz[root(x)];
    }
};

ll fraction (ll n){
    if (n==1) return 1;
    return n * fraction(n-1) % mod2;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;cin>>n>>k;
    vector<vector<ll>> a(n,vector<ll>(n));
    rep(i,0,n){
        rep(j,0,n){
            cin>>a[i][j];
        }
    }

    UnionFind uf1(n);
    ll ans = 1;

    rep(i,0,n){
        rep(j,0,n){
            ll f = 0;
            if (i<j){
                f = 1;
                rep(s,0,n){
                    if (a[i][s]+a[j][s]>k){
                        f = 0;
                    }
                }
            }
            if (f) {
                uf1.unite(i,j);
            }
        }

    }

    rep(i,0,n){
        if (uf1.par[i]==i){
            ans = ans * fraction(uf1.size(i)) %mod2;
        }
    }

    UnionFind uf2(n);

    rep(i,0,n){
        rep(j,0,n){
            ll f = 0;
            if (i<j){
                f = 1;
                rep(s,0,n){
                    if (a[s][i]+a[s][j]>k){
                        f = 0;
                    }
                }
            }
            if (f) {
                uf2.unite(i,j);
            }
        }
    }

    rep(i,0,n){
        if (uf2.par[i]==i){
            ans = ans * fraction(uf2.size(i)) %mod2;
        }
    }

    cout<<ans<<endl;
}

#include <iostream>
#include <algorithm>
#define MOD 998244353
int N, K;
int A[50][50];
int row_ok[50][50];
int col_ok[50][50];
long long num[51];
using namespace std;

long long calc(int line_ok[][50]) {
    long long ans = 1;
    int group[50];
    int groupN[50];
    for (int i=0; i<N; i++) group[i] = i;
    for (int i=0; i<N; i++) {
        groupN[i] = 0;
    }

    for (int _=0; _<=N; _++) {
        for (int i=0; i<N; i++) {
            for (int j=0; j<N; j++) {
                if (line_ok[i][j] == 1) {
                    int x = min(group[i], group[j]);
                    group[i] = group[j] = x;
                }
            }
        }
    }
    for (int i=0; i<N; i++) {
        groupN[group[i]]++;
    }
    for (int i=0; i<N; i++) {
        if (groupN[i] > 0) {
            ans *= num[groupN[i]];
            ans %= MOD;
        }
    }
    return ans;
}
int main() {
    {
        long long x = 1;
        for (int i=1; i<51; i++)
        {
            x *= i;
            x %= MOD;
            num[i] = x;
        }
    }

    cin >> N >> K;
    for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
            cin >> A[i][j];
        }
    }

    for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
            bool ok = true;
            for (int c=0; c<N; c++) {
                if (A[c][i] + A[c][j] > K) {
                    ok = false;
                    break;
                }
            }
            if (ok) col_ok[i][j] = 1;
        }
    }

    for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
            bool ok = true;
            for (int c=0; c<N; c++) {
                if (A[i][c] + A[j][c] > K) {
                    ok = false;
                    break;
                }
            }
            if (ok) row_ok[i][j] = 1;
        }
    }

    // row
    cout << (calc(row_ok) * calc(col_ok)) % MOD << endl;

    return 0;
}


#include <iomanip>
#include <iostream>
#include <cmath>
using namespace std;

int main() {
	int n;
	cin >> n;
	long long m = 0, c = 0;
	double e = 0;
	for (int i = 0; i < n; i++) {
		long long x;
		cin >> x;
		m += abs(x);
		c = max(c, abs(x));
		e += (x * x);
	}
	e = sqrt(e);
	cout << m << endl;
	cout << setprecision(18) << e << endl;
	cout << c << endl;
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cerr << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int getInt()
{
    int x;
    scanf("%d", &x);
    return x;
}
template <typename T>
istream &operator>>(istream &i, v(T) & v)
{
    rep(j, sz(v)) i >> v[j];
    return i;
}
template <typename T>
string join(const v(T) & v)
{
    stringstream s;
    rep(i, sz(v)) s << ' ' << v[i];
    return s.str().substr(1);
}
template <typename T>
ostream &operator<<(ostream &o, const v(T) & v)
{
    if (sz(v))
        o << join(v);
    return o;
}
template <typename T1, typename T2>
istream &operator>>(istream &i, pair<T1, T2> &v) { return i >> v.fi >> v.se; }
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const pair<T1, T2> &v) { return o << v.fi << "," << v.se; }
template <typename T>
bool mins(T &x, const T &y)
{
    if (x > y)
    {
        x = y;
        return true;
    }
    else
        return false;
}
template <typename T>
bool maxs(T &x, const T &y)
{
    if (x < y)
    {
        x = y;
        return true;
    }
    else
        return false;
}
template <typename T>
ll suma(const v(T) & a)
{
    ll res(0);
    for (auto &&x : a)
        res += x;
    return res;
}
constexpr double eps = 1e-10;
constexpr ll LINF = 1001002003004005006ll;
constexpr int INF = 1001001001;
#define dame        \
    {               \
        puts("-1"); \
        return 0;   \
    }
#define yn           \
    {                \
        puts("Yes"); \
    }                \
    else { puts("No"); }
constexpr int MAX = 1000001;

int main()
{
    cout << fixed << setprecision(20);
    int n;
    long double b = 0, c = 0, d = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        long double a;
        cin >> a;
        b += max(a, -a);
        c += max(a, -a) * (long double)max(a, -a);
        d = max(d, max(a, -a));
    }
    c = sqrt(c);
    cout << b << "\n";
    cout << c << "\n";
    cout << d << "\n";
    return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=b;i>=a;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define VI vector<int>
#define VLL vector<ll>
#define MPII map<pair<int,int>,int>
#define mp make_pair
#define PQI priority_queue<int>
#define lowbit(x) x&-x
#define debug(a) cout<<#a<<'='<<a<<'\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6 + 10;
const int M = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);
const double eps=1e-5;

struct point{
    int x,y;
    bool operator < (point t) const{
        if (x == t.x)
            return y < t.y;
        return x < t.x;
    }
    bool operator == (point t) const{
        return x == t.x && y == t.y;
    }
}p[N];
int a[M],c[M];
int getsum(int x){
    int res = 0;
    while(x){
        res += c[x];
        x-=lowbit(x);
    }
    return res;
}
void update(int x, int y, int n){
    while (x <= n){
        c[x] += y;
        x += lowbit(x);
    }
}
point read(){
    int x,y;
    scanf("%d%d", &x, &y);
    return (point){x,y};
}
int main()
{
    int h, w, m;
    scanf("%d%d%d", &h, &w, &m);
    int mx = h + 1, my = w + 1;
    for (int i = 1; i <= m; i++){
        p[i] = read();
        if (p[i].y == 1)
            mx = min(mx, p[i].x);
        if (p[i].x == 1)
            my = min(my, p[i].y);
    }
    for (int i = mx + 1; i <= h; i++){
        p[++m].x = i;
        p[m].y = 1;
    }
    for (int i = my + 1; i <= w; i++){
        p[++m].x = 1;
        p[m].y = i;
    }
    sort(p + 1, p + 1 + m);
    //m = unique(p + 1, p + 1 + m) -(p + 1);
    int pos = 1;
    ll ans = 0;
    for (int i = 1; i <= m; i++){
        if (a[p[i].y] == 0){
            a[p[i].y] = 1;
            update(p[i].y, 1, w);
        }
        if (i == m || p[i + 1].x != p[i].x){
            ans += getsum(w) - getsum(p[pos].y - 1);
            pos = i + 1;
        }
    }
    printf("%lld\n", 1ll* h * w - ans);
    return 0;
}

#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#include <cctype>
#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 repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

vector<vector<ll>> dist;

int main()
{
	ll n; cin >> n;
	vector<ll> xl(n);
	vector<ll> yl(n);
	vector<ll> zl(n);
	dist.resize(n, vector<ll>(n));
	vector<vector<ll>> dp(1 << 17 + 1,vector<ll>(18, INF));
	rep(i, n) {
		ll x, y, z; cin >> x >> y >> z;
		xl[i] = x;
		yl[i] = y;
		zl[i] = z;
	}
	rep(i, n) {
		rep(j, n) {
			dist[i][j] = abs(xl[i] - xl[j]) + abs(yl[i] - yl[j]) + max((ll)0, zl[j] - zl[i]);
		}
	}
	dp[1][0] = 0;
	rep(i, 1 << n) {
		rep(x, n) {
			if (i & (1 << x)) {
				rep(y, n) {
					chmin(dp[i | (1 << y)][y], dp[i][x] + dist[x][y]);
				}
			}
		}
	}
	cout << dp[(1 << n) - 1][0] << endl;
	system("Pause");
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
using pld = pair<ld,ld>;
using vll = vector<ll>;
using vld = vector<ld>;
using vstr = vector<string>;
#define _GLIBCXX_DEBUG
#define rep(j, m) for (ll j = 0; j < (ll)(m); j++)
#define rep2(i, l, n) for (ll i = l; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
const ld PI = 3.1415926535897932;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
vll dx = {-1,0,1,0};
vll dy = {0,-1,0,1};
vll Dx = {-1,-1,-1,0,0,1,1,1};
vll Dy = {-1,0,1,-1,1,-1,0,1};
const ll INF = 1000000000000000;

int main() {
    ll N;
    cin >> N;
    if (N*108/100 > 206) {cout << ":(" << endl;}
    else if (N*108/100 == 206) {cout << "so-so" << endl;}
    else {cout << "Yay!" << endl;}
}

#include <bits/stdc++.h>

#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 1e5 + 7;

int main(){
    int d; scanf("%d", &d);
    printf("%d\n", 100 - d % 100);
    return 0;
}


#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

string s;
bool ans = true;
bool flag = true;
int point = 0;

int main()
{
    cin >> s;
    reverse(s.begin(), s.end());
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '0') {
            continue;
        } else {
            point = i;
            break;
        }
    }

    for (int i = point; i < s.size(); i++) {
        if (s[i] == s[s.size() - 1 - i + point]) {
        } else {
            flag = false;
        }
    }
    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

//kyoprosaikoooooooooooo!!
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
//素数判定 O(√N)
ll prime (ll abc) {
  if (abc < 2) {
    return 0;
  }
  else if (abc == 2) {
    return 1;
  }
  else if (abc % 2 == 0) {
    return 0;
  }
  double sqrtabc = sqrt(abc);
  for (int i = 3; i <= sqrtabc; i++) {
    if (abc % i == 0) {
      return 0;
    }
  }
  return 1;
}
//素因数分解(約数列挙) O(√N)
vector<ll> divisor(ll n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
//最大公約数
ll gcd(ll x,ll y){
    if(x<y) swap(x,y);
    ll r;
    while(y>0){
        r=x%y;
        x=y;
        y=r;
    }
    return x;
}
//最小公倍数
ll lcm(ll x,ll y){
    return (ll)(x/gcd(x,y))*y;
}
int main() {
  string S;
  cin >> S;
  int sum = 0;
  deque<char> ans;
  if (S.at(0) != 'R') {
    ans.push_back(S.at(0));
  }
  else {
    sum++;
  }
  for (int i = 1; i < (int)S.size(); i++) {
    char a = S.at(i);
    if (a == 'R') {
      sum++;
    }
    else {
      if (sum % 2 == 0) {
        ans.push_back(a);
      }
      else {
          ans.push_front(a);
      }
    }
  }
  if (sum % 2 == 1) {
    reverse(ans.begin(), ans.end());
  }
  string A = "";
  for (char c : ans) {
    if (A.back() == c && A.size()) {
      A.pop_back();
    }
    else {
      A.push_back(c);
    }
  }
  cout << A << endl;
}


#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007;

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);

	int N;
	long double ans = 0;

	cin>>N;

	for(int i = 1; i < N; i++){
		ans += (long double)N / (N - i);
	}

	cout<<ans<<endl;

	return 0;
}

#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
    ll modpow(ll x, ll b,ll mod=MOD){
        ll res = 1;
        while(b){
            if(b&1)res = res * x % mod;
            x = x * x % mod;
            b>>=1;
        }
        return res;
    }

    ll modinv(ll x){
        return modpow(x, MOD-2);
    }

    bool was_output = false;
    template<class t>
    void output(t a){
        if(was_output)cout << " ";
        cout << a;
        was_output = true;
    }
    void outendl(){
        was_output = false;
        cout << endl;
    }

    template<class t>
    istream& operator>>(istream&is, vector<t>&x){
        for(auto &i:x)is >> i;
        return is;
    }

    template<class t, class u>
    istream& operator>>(istream&is, pair<t, u>&x){
        is >> x.first >> x.second;
        return is;
    }

    template<class t>
    ostream& operator<<(ostream&os, vector<t> &v){
        os << "{";
        for(t &i:v){
            os << i << ", ";
        }
        os << "}";
        return os;
    }

    template<class t = long long>
    t in(){
        t res; cin >> res; return res;
    }

    template<class t>
    void out(t x){
        cout << x;
    }

    template<class t>
    vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
        sort(line.begin(),line.end(),comp);
        return line;
    }

    template<class t>
    vector<t> reversed(vector<t> line){
        reverse(line.begin(),line.end());
        return line;
    }
    string reversed(string str){
        reverse(str.begin(),str.end());
        return str;
    }

    long long gcd(long long a,long long b){
        while(b){
            a %= b;
            swap(a,b);
        }
        return a;
    }

    long long lcm(long long a,long long b){
        return a / gcd(a,b) * b;
    }
}

using namespace templates;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n = in();
    double ans = 0;
    rep(i,1,n){
        ans += 1 / (1 - (n-i) / (double) n);
    }
    printf("%.20lf\n",ans);
    return 0;
}


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

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

  vector<pair<ll,ll>> a;

  rep(i,n){
    ll t, l, r;
    cin >> t >> l >> r;
    l *= 2;
    r *= 2;
    if(t==2) r--;
    else if(t==3) l++;
    else if(t==4){
      l++; r--;
    }
    a.push_back(make_pair(l,r));
  }

  sort(ALL(a));

  ll ans = 0;
  for(int i=0; i < (int)a.size()-1; i++){
    ll s = a[i].second;
    for(int j=i+1; j < (int)a.size(); j++){
      ll t = a[j].first;
      ll u = a[j].second;
      if(t <= s && s <= u) ans++;
      else if(u <= s) ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

// ＵＴＦ−８

#include<bits/stdc++.h>

using namespace std;
using ll = long long int;
using lc = complex<double>;
template <class T>
bool complex_comparator(const complex<T> &a, const complex<T> &b) {
    return real(a) == real(b) ? imag(a) < imag(b) : real(a) < real(b);
}

/* #include<atcoder/all> */
/* using namespace atcoder; */

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

int main(void) {
    constexpr ll MOD = 1 ? 1e9+7 : 998244353;
    const double PI = acos(-1);
    constexpr double eps = 1e-5;
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);

    if(1) {
        ll n;
        cin >> n;
        vector<tuple<ll,ll,ll>> v(n);
        for(auto &[t, l, r]: v)
            cin >> t >> l >> r;

        ll res = 0;
        for(ll i=0; i<n; i++)
            for(ll j=i+1; j<n; j++) {
                auto [t1, l1, r1] = v[i];
                auto [t2, l2, r2] = v[j];

                bool ok = true;

                ok &= ((t1<3) && ((t2&1) == 1) && l1 <= r2) || l1 < r2;
                ok &= ((t2<3) && ((t1&1) == 1) && l2 <= r1) || l2 < r1;

                res += ok;
            }
        cout << res<< endl;
    }
    return 0;
}


#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define mydeb(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
//#define mydeb(fmt, ...)

int main()
{
    int64_t k,n,m;
    cin >> k >> n >> m;
    vector<int64_t> a(k);
    rep(i,k)
    {
        cin >> a[i];
    }

    vector<int64_t> modn(k);
    int64_t modtotal=0;
    rep(i,k)
    {
        modn[i]=(a[i]*m)%n;
        modtotal+=modn[i];
        //mydeb("i:%d modn:%ld\n",i,modn[i]);
    }
    modtotal/=n;

    vector<pair<int,int>> mp(k);
    rep(i,k)
    {
        mp[i]=make_pair(modn[i],i);
    }
    sort(mp.begin(),mp.end());

    auto it=mp.rbegin();
    vector<int> add1(k);
    rep(i,modtotal)
    {
        add1[it->second]=1;
        ++it;
    }

    bool first=true;
    rep(i,k)
    {
        if (first==false)
        {
            cout << " ";
        }
        first=false;
        cout << a[i]*m/n + add1[i];
    }
}

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

const int mod=1000000007;
const int N=1e5 ;
const ll INF=1e18;

struct Edge
{
	int to,t,k ;
	Edge(int to, int t ,int k):to(to),t(t),k(k){}

};

void solve(){

int n,m,s,d ;
cin>>n>>m>>s>>d ;

s-- ;
d-- ;

vector<vector<Edge>> g(n+1) ;

rep(i,m){

	int a,b,t,k ;
	cin>>a>>b>>t>>k ;
	a-- ;
	b-- ;
	g[a].emplace_back(b,t,k) ;
	g[b].emplace_back(a,t,k) ;

}

vector<ll> dist(n,INF) ;

priority_queue<P,vector<P>,greater<P>> q ;

auto push=[&](int v,ll x){
	if(dist[v]<=x) return ;
	dist[v]=x ;
	q.emplace(x,v) ;

};

push(s,0) ;

while(!q.empty()){

	auto x=q.top().first ;
	auto v=q.top().second ;

	q.pop() ;
	if(dist[v]!=x)	continue ;

	for(Edge &e:g[v]){
		ll nx=((x+e.k-1)/e.k)*e.k+e.t ;
		push(e.to,nx) ;
	}
}

if(dist[d]==INF)
	cout<<-1 ;
else
	cout<<dist[d] ;

}

int main(){

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

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

		int y ;

		y=1 ;
		//cin>>y ;

		while(y--){

			solve() ;

		}

		return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
/* * * *   * * *   	* * * */
/* *
 *
 * I love Ylva Eriksson
 *
 * */
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n; cin >> n;
	vector <int> a(n);
	for (int i = 0; i < n; ++i) cin >>a[i];
	int cnt = 0, ans= 0;
	for (int i = 2; i <= 1000; ++i) {
		int cur = 0;
		for (int j = 0; j < n; ++j) cur += (a[j] % i == 0);
		if (cur > cnt) {cnt = cur, ans = i; }
	}
	cout << ans << '\n';
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
long long mod=1e9+7,ans,n;
int main ()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    long long a[n+1],f[n+1];
    for(int i=1;i<=n;i++) cin >> a[i];
    f[0]=1,f[1]=1;
    for(int i=2;i<=n;i++) f[i]=(f[i-1]+f[i-2])%mod;
     ans=(f[n]*a[1])%mod;
    for(int i=2;i<=n;i++)
    {
        ans+=(f[n+1-i]*f[i-1]%mod*2%mod+mod-f[n])%mod*a[i]%mod;
		ans%=mod;
    }
    cout << ans;
}


#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define BIT(i) (1LL << (i))
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const long long MOD = 1000000007;

const ll sz = 18;
ll N, M;
ll dp[BIT(sz)];
vector<pll> C[sz + 1];

bool check(ll bit){
    vector<ll> acc(N, 0);
    REP(i, N){
        if(bit & BIT(i)) acc[i]++;
    }
    ll j = accumulate(ALL(acc), 0LL);
    REP(i, N - 1) acc[i + 1] += acc[i];
    for(auto [y, z] : C[j]){
        if(z < acc[y]) return false;
    }
    return true;
}

signed main(){
    cin >> N >> M;
    ll X, Y, Z;
    REP(i, M){
        cin >> X >> Y >> Z;
        Y--;
        C[X].push_back({Y, Z});
    }
    dp[0] = 1;
    REP(i, BIT(N)){
        REP(j, N){
            if(i & BIT(j)) continue;
            if(check(i | BIT(j))){
                dp[i | BIT(j)] += dp[i];
            }
        }
    }
    cout << dp[BIT(N) - 1] << endl;
    return 0;
}

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

const int maxl=3e5+10;

int n,m,k,tot,cas,ans;
int a[maxl];ll fac[maxl];
int cnt[maxl][20];
ll dp[20][maxl];
int x[maxl],y[maxl],z[maxl];
bool vis[maxl];
char s[maxl];

inline void prework()
{
	fac[0]=1;
	for(int i=1;i<=18;i++)
		fac[i]=fac[i-1]*i;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
		scanf("%d%d%d",&x[i],&y[i],&z[i]);
	for(int s=1;s<(1<<n);s++)
	{
		for(int i=1;i<=n;i++)
		{
			if(s>>(i-1)&1)
				cnt[s][i]=1;
			cnt[s][i]+=cnt[s][i-1];
		}
	}
}

inline bool jug(int ind,int s)
{
	for(int i=1;i<=m;i++)
	if(x[i]==ind && cnt[s][y[i]]>z[i])
		return false;
	return true;
}

inline void mainwork()
{
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int s=1;s<(1<<n);s++)
		if(cnt[s][n]==i && jug(i,s))
		{
			for(int j=1;j<=n;j++)
			if(s>>(j-1)&1)
				dp[i][s]+=dp[i-1][s^(1<<(j-1))];
		}
}

inline void print()
{
	printf("%lld",dp[n][(1<<n)-1]);
}

int main()
{
	int t=1;
	//scanf("%d",&t);
	for(cas=1;cas<=t;cas++)
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}