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

typedef long long int ll;
constexpr int kN = int(1E5 + 10);

int a[kN], b[kN], y[kN], x[kN];

int main() {
	int n, l, idx = -1, now = 0, lst = 0;
	ll ans = 0;
	scanf("%d%d", &n, &l);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
	a[0] = b[0] = 0, a[n + 1] = b[n + 1] = l + 1;
	for (int i = 0; i <= n; i++) x[i] = a[i + 1] - a[i] - 1;
	for (int i = 0; i <= n; i++) y[i] = b[i + 1] - b[i] - 1;
	for (int i = 0; i <= n; i++) if (y[i]) {
		now = 0;
		while (x[lst] == 0) lst++;
		while (now < y[i]) now += x[++idx];
		if (now > y[i]) {
			printf("-1\n");
			return 0;
		}
		ans += max(i - lst, 0) + max(idx - i, 0);
		lst = idx + 1;
	}
	printf("%lld\n", ans);
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ldb double
template<typename T>void ckmn(T&a,T b){a=min(a,b);}
template<typename T>void ckmx(T&a,T b){a=max(a,b);}
void rd(int&x){scanf("%i",&x);}
void rd(ll&x){scanf("%lld",&x);}
void rd(char*x){scanf("%s",x);}
void rd(ldb&x){scanf("%lf",&x);}
void rd(string&x){scanf("%s",&x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&i:x)rd(i);}
template<typename T,typename...A>void rd(T&x,A&...args){rd(x);rd(args...);}
template<typename T>void rd(){T x;rd(x);return x;}
int ri(){int x;rd(x);return x;}
template<typename T>vector<T> rv(int n){vector<T> x(n);rd(x);return x;}
template<typename T>void ra(T a[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]);}
template<typename T1,typename T2>void ra(T1 a[],T2 b[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]);}
template<typename T1,typename T2,typename T3>void ra(T1 a[],T2 b[],T3 c[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]),rd(c[st+i]);}
void re(vector<int> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){rd(u,v);E[u].pb(v);if(!dir)E[v].pb(u);}}
template<typename T>void re(vector<pair<int,T>> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){T w;rd(u,v,w);E[u].pb({v,w});if(!dir)E[v].pb({u,w});}}

void NO(){printf("-1\n");exit(0);}
ll Solve(vector<pii> pts){
	if(pts[0].first==pts[0].second){
		for(pii&p:pts)p.first*=-1,p.second*=-1;
		reverse(pts.begin(),pts.end());
	}
	ll ans=0;
	for(int i=0,las=-1;i+1<pts.size();i++){
		int bot=i,top=pts.size()-1,mid,ptr=pts.size();
		while(top>=bot){
			mid=top+bot>>1;
			int o=pts[mid].first-(mid-i);
			if(o>=pts[i].second)ptr=mid,top=mid-1;
			else bot=mid+1;
		}
		if(ptr==pts.size()||pts[ptr].first-(ptr-i)!=pts[i].second)NO();
		if(las!=ptr)ans+=ptr-i;
		las=ptr;
	}
	return ans;
}
vector<int> zero;
const int N=100050;
int a[N],b[N];
int main(){
	int n,l;rd(n,l);
	ra(a,n);
	ra(b,n);
	a[n+1]=b[n+1]=l+1;
	for(int i=0;i<=n+1;i++)if(a[i]==b[i])zero.pb(i);
	ll ans=0;
	for(int i=1;i<zero.size();i++){
		int l=zero[i-1]+1,r=zero[i]-1;
		vector<pii> pts;
		pts.pb({a[l-1],b[l-1]});
		int L=l;while(a[L]>b[L])pts.pb({a[L],b[L]}),L++;
		ans+=Solve(pts);
		pts.clear();
		pts.pb({a[r+1],b[r+1]});
		int R=r;while(a[R]<b[R])pts.pb({a[R],b[R]}),R--;
		reverse(pts.begin(),pts.end());
		ans+=Solve(pts);
		if(L!=R+1)NO();
	}
	printf("%lld\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
long long m;
int l;
string x;
bool check(long long d){
	long long tmp=0,base=1;
	for (int i=l-1;i>=0;i--){
		if (base>m) return false;
		tmp+=base*(x[i]-'0');
		if (tmp>m) return false;
		if (base>(m/d)&&i!=0) return false;
		base*=1ll*d;
	}
	//cout<<d<<" "<<tmp<<endl;
	return true;
}
int main(){
	IO;
	cin>>x;
	cin>>m;
	if (x.size()==1){
		if (x[0]-'0'>m) cout<<0<<endl;
		else cout<<1<<endl;
		return 0;
	}
	l=x.size();
	long long d=0;
	for (int i=0;i<l;i++){
		d=max(d,(long long)(x[i]-'0'));
	}
	d++;
	long long l=d,ans=0,r=1e18;
	while (l<=r){
		long long mid=(l+r)/2;
		if (check(mid)){
			ans=mid-d+1;
			l=mid+1;
		}else r=mid-1;
	}
	cout<<ans<<endl;
	return 0;
}

using namespace std;
#include <bits/stdc++.h>
int A,B;
int main(){
	scanf("%d%d",&A,&B);
	int sum=max(A,B)*(max(A,B)+1)/2;
	if (A<B){
		for (int i=1;i<=B;++i)
			printf("%d ",-i);
		for (int i=1;i<A;++i)
			printf("%d ",i),sum-=i;
		printf("%d\n",sum);
	}
	else{
		for (int i=1;i<=A;++i)
			printf("%d ",i);
		for (int i=1;i<B;++i)
			printf("%d ",-i),sum-=i;
		printf("%d\n",-sum);
	}
	return 0;
}


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

typedef long long ll;
const int N = 1e5 + 10, M = (1 << 20) + 2;
int n, m, a[N], cnt[N];
char s[N][22];

int main() {
    cin >> n >> m;
    rep(i, 1, n) {
        scanf("%s", s[i]);
        rep(j, 0, m - 1) {
            a[i] = (a[i] << 1) + s[i][j] - '0';
        }
        ++cnt[__builtin_popcount(a[i]) & 1];
    }
    printf("%lld\n", 1ll * cnt[0] * cnt[1]);
    return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

long long mod_div(long long a,long long b){
	long long tmp = MOD - 2,c = b,ret = 1;
	while(tmp > 0){
		if(tmp & 1){
			ret *= c;ret %= MOD;
		}
		c *= c;c %= MOD;tmp >>= 1;
	}
	return a*ret%MOD;
}

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

	ll n, m;cin >> n >> m;

	vector<bool> no_prime(m);
	vector<ll> primes;
	for(int i = 2;i * i <= m;i++) {
		if(no_prime[i])continue;
		primes.PB(i);
		for(ll j = 2 * i;j <= m;j += i)no_prime[j] = true;
	}
	vector<ll> kai(202020, 1);
	vector<ll> inv(202020, 1);
	for(ll i = 1;i < 202020;i++) {
		kai[i] = kai[i-1] * i % MOD;
		inv[i] = mod_div(1, kai[i]);
	}

	ll ans = 0;
	for(ll i = 1;i <= m;i++) {
		ll now = 1;
		ll tmp = i;
		for(ll ele: primes) {
			if(ele > i)break;
			int cou = 0;
			while(tmp % ele == 0) {
				tmp /= ele;
				cou++;
			}
			now = (now * kai[(n-1) + cou]) % MOD;
			now = (now * (inv[n-1] * inv[cou] % MOD)) % MOD;
		}

		if(tmp > 1) {
			now = (now * kai[(n-1) + 1]) % MOD;
			now = (now * (inv[n-1] * inv[1] % MOD)) % MOD;
		}

		// cout << "tmp: " << i << " " << now << endl;
		ans = (ans + now) % MOD;
	}

	cout << ans << endl;
	// SHOW1d(primes, primes.size());

	return 0;
}


#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define debug(x) cout << #x << ": " << (x) << endl
#else
#define debug(x)
#endif
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int maxn=1e6+7,inf=0x3f3f3f3f,mod=998244353;

int fa[maxn];
int find(int x)
{
    return fa[x]==x?fa[x]:fa[x]=find(fa[x]);
}
ll quick(ll x,ll n)
{
    ll res=1;
    while(n)
    {
        if(n&1) res=res*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return res;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;++i) fa[i]=i;
    for(int i=1,x;i<=n;++i)
    {
        cin>>x;
        int fx=find(i),fy=find(x);
        if(fx!=fy) fa[fy]=fx;
    }
    int cnt=0;
    for(int i=1;i<=n;++i) if(find(i)==i) cnt++;
    cout<<(quick(2,cnt)-1+mod)%mod<<'\n';
    return 0;
}

// Parasparopagraho Jīvānām

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

using namespace  __gnu_pbds ;
using namespace __gnu_cxx ;
using namespace std ;

typedef long long ll ;
typedef long double ldb ;

typedef pair<int, int> pii ;
typedef pair<int, ll> pil ;
typedef pair<ll,ll> pll ;

typedef vector<int> vi ;
typedef vector<ll> vll ;
typedef vector<pii> vpi ;
typedef vector<pll> vpl ;
typedef vector<pair<ll,int> > vpli ;
typedef vector<int,pil> edges ;
typedef vector<vi> matrix ;
typedef priority_queue<int> pqu ;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ;

#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define per(i,b,a) for (int i = (b); i >= (a); i--)

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define ins insert
#define bk back
#define con continue
#define lbd lower_bound
#define ubd upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

#define pr cout << // I don't like this but my laptop's 'O' key is not functioning well

/* Careful when using long long
__builtin_clz(int x) {} //: the number of zeros at the beginning of the number
__builtin_ctz(int x) {} //: the number of zeros at the end of the number
__builtin_popcount(int x) {} //: the number of ones in the number
__builtin_parity(int x) {} //: the parity (even or odd) of the number of ones */

const int mod1 = 1000000007 ;
const int mod2 = 998244353 ;
const ll  infl = 4e18 ;
const int infi = 2e9 ;
const int maxn = 5e5 + 5 ;
const int block = 500 ;
const int logn = 60 ;
const int alpha = 27 ;
const ldb pi = acos(-1) ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ;
int rng_lr(int a, int b)
{
    int ret ;
    ret = uniform_int_distribution<int>(a, b)(rng) ;
    return ret ;
    // For shuffling use shuffle(all, rng) ;
}

ll modpow(ll a, ll b, int MOD) { ll res = 1 ; while(b) { if(b&1) { res = res*a ; res %= MOD ; } a *= a ; a %= MOD ; b >>= 1 ; } return res%MOD ; }
void upmin(int &a, int b) { if(a < b) { a = b ; } }
void relax(int &a, int b) { if(a > b) { a = b ; } }
ll add(ll a, ll b, int MOD) { a += b ; if(a >= MOD) { a -= MOD ; } return  a ; }
ll sub(ll a, ll b, int MOD) { a -= b ; if(a < 0) { a += MOD ; } return a ; }
ll mul(ll a, ll b, int MOD) { b %= MOD ; a *= b ; a %= MOD ; return a ; }
ll inverse(ll a, ll MOD) { a = modpow(a, MOD - 2, MOD) ; return a ; }
ll lcm(ll a, ll b) { ll ret ; ll g = __gcd(a, b) ; ret = a/g ; ret = ret*b ; return ret ; }
int icast(char ch) { return int(ch-'a') ; }
void hyn(int a, int b) { if(a == b) cout << "YES\n" ; else cout << "NO\n" ; }
void pyd(int a, int b) { if(a == b) cout << "First\n" ; else cout << "Second\n" ; }

// Check constraints + overflows + types in typedef

int main()
{
    ios::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    int n ;
    cin >> n ;
    map<ll,int> dic ;
    dic[0] = 1 ;
    ll e = 0, o  = 0 ;
    ll res = 0 ;
    rep(i,0,n-1) {
    	int x ;
    	cin >> x ;
    	if(i&1) e += x ;
    	else o += x ;
    	ll d = e - o ;
    	res += dic[d] ;
    	dic[d]++ ;
    }
    pr res << "\n" ;

    return 0 ;
}


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

int main(){
    int n; cin >> n;
    vector<vector<ll>> v(n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 5; j++){
            int x; cin >> x;
            v[i].push_back(x);
        }
    }
    auto check = [&](int x){
        set<int> s;
        for(int i = 0; i < n; i++){
            int bit = 0;
            for(int j = 0; j < 5; j++){
                if(v[i][j] >= x){
                    bit = bit | (1LL << j);
                }
            }
            s.insert(bit);
        }
        for(auto &i: s){
            for(auto &j: s){
                for(auto &k: s){
                    if((i | j | k) == 31){
                        return true;
                    }
                }
            }
        }
        return false;
    };
    int l = 0, r = 1e9 + 2;
    while(l + 1 < r){
        int mid = l + ((r-l) >> 1);
        if(check(mid)){
            l = mid;
        } else {
            r = mid;
        }
    }
    cout << l << '\n';
}

#include "bits/stdc++.h"
using namespace std ;
const int mxN =800 ;
int n,k,a[mxN+1][mxN+1],p[mxN+1][mxN+1] ;
// ask if we can have median as atleast x or not ?
bool ok(int x){
  for(int i=1;i<n+1;i++)
    for(int j=1;j<n+1;j++)
      p[i][j]=p[i-1][j]+p[i][j-1]-p[i-1][j-1]+(a[i][j]>x) ;
  for(int i=1;i<n+2-k;i++){
    for(int j=1;j<n+2-k;j++){
      int c=p[i+k-1][j+k-1]+p[i-1][j-1]-p[i-1][j+k-1]-p[i+k-1][j-1] ;
      if(c<(k*k)/2+1)
        return 0  ;
    }
  }
  return 1 ;
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k ;
  for(int i=1;i<n+1;i++)
    for(int j=1;j<n+1;j++)
      cin >> a[i][j] ;
  int lb=0,rb=1e9 ;
  while(lb<rb){
    int mb=(lb+rb)/2 ;
    if(ok(mb))
      lb=mb+1 ;
    else
      rb=mb  ;
  }
  cout << lb  ;
}


/*
	JAI JAGANNATH!
*/
//@Author : zanj0

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

#define int 			long long int

#define ff              first
#define ss              second
#define pb              push_back
#define MOD             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define endl       		"\n"
#define timetaken cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n"

void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
const int MAX = 3e6 + 5;
int fac[MAX], finv[MAX];
int inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
int COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int add(int a, int b) {
	return ((a % MOD) + (b % MOD)) % MOD;
}
int mul(int a, int b) {
	return ((a % MOD) * (b % MOD)) % MOD;
}
int fastPow(int base, int p) {
	int ret = 1;
	while (p) {
		if (p & 1) ret = mul(ret, base);
		base = mul(base, base);
		p >>= 1;
	}
	return ret;
}
int sub(int a, int b) {
	return (((a % MOD) - (b % MOD)) + MOD) % MOD;
}
void solve() {
	int n, m, k;
	cin >> n >> m >> k;
	COMinit();
	if (n > m + k) {
		cout << 0 << endl;
	} else if (k >= n) {
		cout << COM(n + m, n) << endl;
	} else {
		cout << sub(COM(n + m, n), COM(n + m, m + k + 1)) << endl;
	}

}
int32_t main()
{
	zanj0();
	solve();
	timetaken;
	return 0;
}

/**
*    author: zakhio (mttk1528)
*    created: 19.12.2020 21:02:51
**/
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

#ifdef _LOCAL_
#define _GLIBCXX_DEBUG
#endif

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

#define name(x) #x
#define dump(x) cout << name(x) << " = " << x << endl
#define print(x) cout << (x) << endl
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rrep(i,n) for (int i = (int)(n - 1); i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define len(x) (int)(x.size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) ll(__builtin_popcountll(bit))
#define roundup(x,y) (x + y - 1) / y

using ll = int64_t;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;

const double pi = acos(-1.0);
const ll LINF = 1e18;
const int INF = 1e9;
const int MAX = 1000010;
const int MOD1 = 1000000007;
const int MOD2 = 998244353;
const int di[4] = {1, 0, -1, 0};
const int dj[4] = {0, 1, 0, -1};
const int di2[8] = {0, 1, 0, -1, 1, 1,-1, -1};
const int dj2[8] = {1, 0,-1, 0, 1, -1, 1, -1};

template <typename T> inline bool chmax(T &a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <typename T> inline bool chmin(T &a, T b) {if (b < a) {a = b; return 1;} return 0;}
template <typename T> T bpow(T a, int n) {T r(1); while(n) {if (n & 1) r *= a; a *= a; n >>= 1;} return r;}
template <typename T> auto comp(vector<T> a) {sort(all(a)); a.erase(unique(all(a)),a.end()); return a;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T,U> &p) {os << p.first << " " << p.second; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T,U> &mp) {for (auto p : mp) {os << "[" << p << "]\n";} return os;}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {rep(i,len(v)) {if (i) os << " "; os << v[i];} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T> &st) {int c(0); for (auto x : st) {if(c) os << " "; os << x; c++;} return os;}
template <typename T> istream &operator>>(istream &i, vector<T> &v) {rep(j,len(v)) i >> v[j]; return i;}
template <typename T, typename U> istream &operator>>(istream &i, pair<T,U> &p) {i >> p.first >> p.second; return i;}

string convert_base(int a, int base) {
    if (a == 0) return "0";
    string str;
    while (a) {
        int rest = a % base;
        str += to_string(rest);
        a /= base;
    }
    reverse(all(str));
    return str;
}

void solve() {

    int n; cin >> n;

    int ans = 0;

    rep(i,n) {
        int num = i+1;
        bool ok = true;
        string s1 = to_string(num);
        string s2 = convert_base(num, 8);
        rep(j,len(s1)) if (s1[j] == '7') ok = false;
        rep(j,len(s2)) if (s2[j] == '7') ok = false;
        if (ok) ans++;
    }

    print(ans);
    return;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    solve();
    return 0;
}


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

//#define ENVIRONMENT_LINKED_ACL

#ifdef ENVIRONMENT_LINKED_ACL
#include <atcoder/convolution>
#include <atcoder/lazysegtree>
#include <atcoder/segtree.hpp>
#endif

//#define ENVIRONMENT_LINKED_BOOST

#ifdef ENVIRONMENT_LINKED_BOOST
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#endif

using namespace std;
using uint = unsigned int;
using ll   = long long;
using ull  = unsigned long long;
#define REP(i, a, b)    for (ll i = a; i < b; ++i)
#define REPREV(i, a, b) for (ll i = a; i > b; --i)

const int _ = []() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    return 0;
}();

template <typename value_t>
void resize(value_t& v, const value_t& val) { v = val; }
template <typename vec_t, typename value_t, typename... arg_t>
void resize(std::vector<vec_t>& v, const value_t& val, int size, arg_t... arg) {
    v.resize(size);
    for (auto& c : v) resize(c, val, arg...);
}

template <typename A, typename B>
void chmin(A& a, const B& b) {
    a = min(a, static_cast<A>(b));
};
template <typename A, typename B>
void chmax(A& a, const B& b) {
    a = max(a, static_cast<A>(b));
};

int main() {
    ll N;
    cin >> N;
    string s;
    cin >> s;
    ll Q;
    cin >> Q;
    bool flip = false;
    REP(q, 0, Q) {
        ll t, a, b;
        cin >> t >> a >> b;
        if (t == 1) {
            --a;
            --b;
            if (flip) {
                if (a >= N)
                    a -= N;
                else
                    a += N;
                if (b >= N)
                    b -= N;
                else
                    b += N;
            }
            swap(s[a], s[b]);
        }
        else {
            flip = !flip;
        }
    }
    if (flip)
        cout << s.substr(N) + s.substr(0, N) << endl;
    else
        cout << s << endl;

    return 0;
}

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

#define int int64_t

int ok;
int n, q;
string s;

int f(int i) {
	if(ok)
		return i;
	if(i < n)
		return n + i;
	else
		return i - n;
}

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

	cin >> n >> s >> q;
	ok = 1;

	while(q--) {
		int t, a, b;
		cin >> t >> a >> b;
		a--, b--;

		if(t == 1)
			swap(s[f(a)], s[f(b)]);
		else
			ok ^= 1;
	}

	if(ok)
		cout << s;
	else {
		for(int i = 0; i < n; i++)
			swap(s[i], s[i + n]);
		cout << s;
	}

	return 0;
}


#include<bits/stdc++.h>
typedef int LL;
typedef double dl;
#define opt operator
#define pb push_back
#define pii std::pair<LL,LL>
const LL maxn=1e6+9,mod=998244353,inf=0x3f3f3f3f;
LL Read(){
	LL x(0),f(1); char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') f=-1; c=getchar();
	}
	while(c>='0' && c<='9'){
		x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
	}return x*f;
}
void Chkmin(LL &x,LL y){
	if(y<x) x=y;
}
void Chkmax(LL &x,LL y){
	if(y>x) x=y;
}
LL add(LL x,LL y){
	return x+=y,x>=mod?x-mod:x;
}
LL dec(LL x,LL y){
	return x-=y,x<0?x+mod:x;
}
LL mul(LL x,LL y){
	return 1ll*x*y%mod;
}
LL Pow(LL base,LL b){
	LL ret(1); while(b){
		if(b&1) ret=mul(ret,base); base=mul(base,base); b>>=1;
	}return ret;
}
LL n;
LL a[maxn];
std::vector<LL> Ans;
LL Rand(LL l,LL r){
	return rand()%(r-l+1)+l;
}
void Init(){
//	srand(time(NULL));
	/*
	n=Rand(5,10);
	for(LL i=1;i<=n;++i) a[i]=i;
	std::random_shuffle(a+1,a+1+n);
	for(LL i=1;i<=n;++i) printf("%d ",a[i]); puts("");
	return;
//	*/
	n=Read();
	for(LL i=1;i<=n;++i) a[i]=Read();
}
void Opt(LL x){
//	printf("# %d\n",x);
    /*
	if(!((Ans.size()&1)^(x&1))){
		puts("WA");
	}
	*/
	Ans.pb(x);
	std::swap(a[x],a[x+1]);
	assert(x^n);
}
void Solve(){
	if(n==2){
		if(a[1]==1 && a[2]==2){
			puts("0");
		}else{
			puts("1"); puts("1");
		}
		return;
	}
	std::vector<LL>().swap(Ans);
	for(LL m=1;m<n;++m){
		if(a[m]==m) continue;
		LL p(0);
		for(LL i=m+1;i<=n;++i) if(a[i]==m){
			p=i; break;
		}
//		printf("%d:%d\n",m,p);
		assert(p);
		if(m==n-1){
			if((Ans.size()&1)==((p-1)&1)){
				Opt(n-2); Opt(n-1);
				Opt(n-2); Opt(n-1); Opt(n-2);
			}else{
//				puts("033");
				Opt(p-1);
			}
		}else{
			if((Ans.size()&1)==((p-1)&1)){
//				puts("#1");
				if(p^n){
				    Opt(p); ++p;
				    Opt(p-2);
			    }else{
			    	Opt(n-2);
				}
			}
//			puts("#2");
			while(p^m){
				Opt(p-1); --p;
			}
		}
	}
	LL flag(1);
	for(LL i=1;i<=n;++i) flag&=(a[i]==i);
	assert(flag);
	assert(Ans.size()<=n*n);
	printf("%d\n",Ans.size());
	if(Ans.size()){
	    for(LL i=0;i<Ans.size();++i){
		    assert(i^(Ans[i]&1));
		    printf("%d ",Ans[i]);
	    }puts("");
    }
}
int main(){
//	srand(time(NULL));
//	freopen("y1.txt","r",stdin);
	LL T=Read();
	while(T--){
		Init();
		Solve();
	}
	return 0;
}

#include<bits/stdc++.h>
#include<bits/extc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t){
	while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr<<#x<<": "; for(auto i:x) cerr<<i<<" "; cerr<<endl;}}
#define debugr(l,r,x) {{cerr<<#x<<": "; for(int i=l;i<=r;i++) cerr<<x<<" "; cerr<<endl;}}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debugr(l,r,x)
#define cerr while(0) cerr
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define int long long
typedef __int128 INT;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define priority_queue std::priority_queue
#define F first
#define S second
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int a[505], pos[505];
int n;

void swappe(int x, int y){
	swap(pos[a[x]], pos[a[y]]);
	swap(a[x], a[y]);
}
bool check(){
	for(int i=1; i<n; i++){
		if(a[i] > a[i+1]) return false;
	}
	return true;
}
void print(){
	for(int i=1; i<=n; i++){
		cerr<<a[i]<<" ";
	}
	cerr<<endl;
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T;
	cin>>T;
	while(T--){
		cin>>n;
		for(int i=1; i<=n; i++){
			cin>>a[i];
			pos[a[i]]=i;
		}
		int t=1;
		vector<int> ans;
		if(check()) goto hell;
		for(int i=1; i<=n; i++){
			if(pos[i]==i) continue;
			while((pos[i]-1+t)%2==1){
				if((t+n-1)%2==0){
					swappe(n-1, n);
					ans.push_back(n-1);
				}
				else{
					swappe(n-2, n-1);
					ans.push_back(n-2);
				}
				t++;
				print();
				if(check()) goto hell;
			}
			for(int j=pos[i]; j>=i+1; j--){
				swappe(j-1, j);
				ans.push_back(j-1);
				t++;
				print();
			}
		}
		hell:;
		cout<<ans.size()<<'\n';
		for(int i: ans) cout<<i<<" ";
			cout<<'\n';
	}
}


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

using namespace std;
using ll = long long;

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

	string s; cin >> s;
	reverse(s.begin(), s.end());

	for (char& c : s) {
		switch (c) {
		case '6':
			c = '9'; break;
		case '9': c = '6'; break;
		}
	}

	cout << s;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
using P=pair<ll,ll>;
int main() {
    string s;
    cin >> s;
    map<ll,ll>ok;
    for(ll i=0;i<10;i++){
        if(s[i]=='o') ok[i]++;
    }
    ll ans=0;
    for(ll i=0;i<10;i++){
        if(s[i]=='x') continue;
        for(ll j=0;j<10;j++){
            if(s[j]=='x') continue;
            for(ll k=0;k<10;k++){
                if(s[k]=='x') continue;
                for(ll l=0;l<10;l++){
                    if(s[l]=='x') continue;
                    map<ll,ll>copy=ok;
                    copy[i]--;
                    copy[j]--;
                    copy[k]--;
                    copy[l]--;
                    bool judge=true;
                    for(auto x:copy){
                        if(x.second>0) judge=false;
                    }
                    if(judge) ans++;
                }
            }
        }
    }
    cout << ans << endl;
}


#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;
  }
  ll in(){
    ll res;
    cin >> res;
    return res;
  }

  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>
  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;
  }
}

using namespace templates;

ll gcd(ll a,ll b){
    return b ? gcd(b,a%b) : a;
}

ll func(){
    int n = in();
    vector<ll> line(n);
    foreach(i,line)i=in();
    ll mins= *min_element(all(line));
    map<ll,ll> candidates;
    candidates[mins] = mins;
    method(add,void,ll v,ll value){
        if(v > mins)return;
        if(candidates.count(v)){
            candidates[v] = gcd(candidates[v],value);
        }else{
            candidates[v] = value;
        }
    };

    foreach(i,line){
        for(ll j=1;j*j<=i;++j){
            if(i%j)continue;
            add(j,i);
            add(i/j,i);
        }
    }
    ll res = 0;
    foreach(i,candidates){
        if(i.first==i.second)++res;
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << func() << endl;
  return 0;
}

#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <sstream>
#include <utility>

using namespace std;

typedef long long ll;

class Graph {
	unordered_map<int, vector<int> > nodes;
	unordered_map<int, ll> sums;
	vector<pair<int, int> > edges;
	unordered_map<int, int> depths;

	void dfs(int start, unordered_set<int>& visited, vector<int>& sorted){
		if(visited.find(start) != visited.end()) return;
		visited.insert(start);

		const auto it = nodes.find(start);
		if(it != nodes.end())
			for(const int neighbor : it->second)
				dfs(neighbor, visited, sorted);

		sorted.push_back(start);
	}

public:
	void add_edge(int a, int b, bool directed=false){
		if(nodes.find(a) == nodes.end()){
			nodes[a] = vector<int>();
			sums[a] = 0;
		}

		nodes[a].push_back(b);

		if(!directed) add_edge(b, a, true);
		else edges.push_back(make_pair(b,a));
	}

	int get_root()	{
		unordered_set<int> visited;
		vector<int> sorted;

		for(const auto& x : nodes) {
			dfs(x.first, visited, sorted);
		}

		return sorted[0];
	}

	void compute_depths(int current, int current_depth, unordered_set<int>& visited){
		if(visited.find(current) != visited.end()) return;
		visited.insert(current);

		depths[current] = current_depth;
		for(const int neighbor : nodes[current])
			compute_depths(neighbor, current_depth + 1, visited);
	}

	void process_query(int t, int e, int x, int root){
		const int ignore = t == 1 ? edges[e-1].second : edges[e-1].first;
		const int not_ignore = t == 1 ? edges[e-1].first : edges[e-1].second;

		if(depths[ignore] < depths[not_ignore]){
			sums[not_ignore] += x;
		}
		else{
			sums[root] += x;
			sums[ignore] -= x;
		}
	}

	void print_sums(int current) {
		for(const auto& x : sums){
			cout << x.first << ": " << x.second << "\n";
		}
	}

	void accum_sums(int current, ll current_sum, unordered_set<int>& visited, vector<pair<int,ll> >& out) {
		if(visited.find(current) != visited.end()) return;
		visited.insert(current);

		auto it = sums.find(current);
		if(it == sums.end()) return;

		out.push_back(make_pair(current, current_sum + it->second));

		for(const int neighbor : nodes[current])
			accum_sums(neighbor, current_sum + it->second, visited, out);
	}
};

int main(){
	string num;
	Graph g;

	getline(cin, num);
	int n = stoi(num);
	for(int i = 0; i < n-1; ++i){
		string in;
		getline(cin, in);
		stringstream ss(in);

		int a, b;
		ss >> a >> b;

		g.add_edge(a,b);
	}

	unordered_set<int> visited;
	int root = g.get_root();
	g.compute_depths(root, 0, visited);

	getline(cin, num);
	int q = stoi(num);
	for(int i = 0; i < q; ++i){
		string in;
		getline(cin, in);
		stringstream ss(in);

		int t, e, x;
		ss >> t >> e >> x;
		g.process_query(t, e, x, root);
	}

	visited = unordered_set<int>();
	vector<pair<int,ll> > out;
	g.accum_sums(root, 0, visited, out);

	sort(out.begin(), out.end());

	for(int i = 0; i < out.size(); i++) cout << out[i].second << "\n";
}


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

#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define deb(x) cout << #x << " : " << x << " "

template<class X>
void input(X *arr, int n){
    for(int i=0; i<n; ++i) cin >> arr[i];
}

template<class X>
void input(vector<X>&arr, int n){
    for(int i=0; i<n; ++i) cin >> arr[i];
}

template<class X>
void print(X *arr, int n){
    for(int i=0; i<n; ++i) cout << arr[i] << " ";
    cout << "\n";
}

template<class X>
void print(vector<X>&arr, int n){
    for(int i=0; i<n; ++i) cout << arr[i] << " ";
    cout << "\n";
}

int main(){
	FAST;
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	int test = 1;
	//cin >> test;
	for(int tt=1; tt<=test; ++tt){
		ll arr[3];
		input(arr, 3);
		sort(arr, arr+3);
		cout << arr[1] + arr[2] << "\n";
	}
	return 0;
}

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

#define ll long long

int main()
{
    int n, q;
    cin >> n >> q;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector<ll> c(n);
    for (int i = 0; i < n; i++) {
        c[i] = a[i] - (i + 1);
    }

    while(q--) {
        ll k; cin >> k;

        if (k > c.back()) {
            cout << a.back() + (k - c.back()) << "\n";
        }
        else {
            int i = lower_bound(c.begin(), c.end(), k) - c.begin();
            cout << (a[i] - 1) - (c[i] - k) << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define eps 1e-8
#define PI 3.141592653589793
#define bsize 512

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define bs 1000000007

using namespace std;

ll int fact(ll int a){
    ll int fact=1;
    for(int i=2;i<=a;i++){
        fact*=i;
    }
    return fact;
}

int main()
{

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

    ll int l,ans=1;
    cin>>l;

    for(int i = 1; i <= 11; i++) {
        ans *= (l-1) - 11 + i;
        ans /= i;
    }

    cout << ans;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<lint, lint>;
const int mod = 1000000007;
#define all(a) (a).begin(),(a).end()
#define rep(i, n) for (lint i = 0; i < (lint)(n); i++)
inline lint fcl(lint num){
    return (num == 1 ? 1 : (num * fcl(num - 1)));
}
int main(){
    lint k;
    lint a, b, c;
    cin >> k;
    lint ans = 0;
    for(lint i = 1; i <= k; i++){
        for(lint j = 1; i * j <= k; j++){
            ans += k / (i * j);
        }
    }
    cout << ans << endl;
}


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

#define ll long long
#define MOD 1000000007
#define pii pair <int, int>

long long GCD(long long a, long long b)
{
	if (!b) return a;
	return GCD(b, a % b);
}

int main()
{
	ll a,b,w;
	ll x, y;
	scanf("%lld %lld %lld", &a, &b, &w);
	ll bet = b - a;
	ll count = 1000 * w;
    x = count / b;
	if (count % b != 0)
		x++;
	y = count / a;
	if (x * b - count <= x * bet && count - y * a <= y * bet)
	{
		printf("%lld %lld", x, y);
	}
	else
		printf("UNSATISFIABLE");

}

#include <bits/stdc++.h>
#define ll long long int
#define db double
#define pb push_back
#define mpr make_pair
#define andl "\n"
#define f first
#define s second
#define mset(x,y) memset(x,y,sizeof(x))
#define fr(i,n) for(long long int i=0;i<n;i++)
#define trace(it,x) for(auto it = (x).begin(); it != (x).end(); it++)
#define mod 1000000007
#define fastio ios::sync_with_stdio (false); cin.tie (0); cout.tie (0);
#define runtime cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
using namespace std;

// convert number to string to_string(x);
// convert string to number stoi();

// ll mulmod(ll x,ll y)
// {
//     return ((x%mod)*(y%mod))%mod;
// }

// ll binpow(ll x, ll y)
// {
//     ll z = 1;
//     while(y > 0)
//     {
//         if(y % 2 == 1)
//             z = mulmod(z, x);
//         x = mulmod(x, x);
//         y /= 2;
//     }
//     return z;
// }

// ll ncr(ll n,ll r)
// {
//     return mulmod(fact[n],binpow(mulmod(fact[n-r],fact[r]),mod-2));
// }

// ll pwr(ll n,ll m)
// {
//   if(n==1 || m==0)
//     return 1;

//   ll x=pwr(n,m/2);
//   if(m%2==0)
//     return x*x;
//   else
//     return n*x*x;
// }

// ll pwr(ll n,ll m,ll b)
// {
//   if(n==1 || m==0)
//     return 1;

//   ll x=pwr(n,m/2,b);
//   if(m%2==0)
//     return ((x%b)*(x%b))%b;
//   else
//     return ((n%b)*(((x%b)*(x%b))%b))%b;
// }

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

    ll mn=0,mx=0;

    w=w*1000;

    mx=w/a;

    if(w%a)
    {
        ll x=w%a,d=b-a;
        if(x>mx*d)
        {
            cout << "UNSATISFIABLE";
            return;
        }
    }

    mn=w/b;

    if(w%b)
    {
        ll x=w%a,d=b-a;
        if(x>=a)
            mn++;
        else
        {
            ll k=a-x;
            if(k>mn*d)
            {
                cout << "UNSATISFIABLE";
                return;
            }
            else
                mn++;
        }
    }
    cout << mn << " " << mx;
  return ;
}

int main()
{
  fastio

  ll t=1;
  // cin >> t;

  while(t--)
    solve();

  runtime
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

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

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define sz(s) int64_t(s.size())
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())

const ll mod = 1e9 + 7;

template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

template<class T, class U>
void chkmax(T &a, U b) {
    a = max(a, (T)b);
    return;
}

template<class T, class U>
void chkmin(T &a, U b) {
    a = min(a, (T)b);
    return;
}

ll ppow (ll x, ll s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    ll b = ppow (x, s / 2);
    return (b * b) % mod;
}

vector<int> zf (string s) {

	int n = sz(s);

	vector<int> z (n);

	for (int i = 1, l = 0, r = 0; i < n; i++) {

		if (i <= r)
			z[i] = min (r - i + 1, z[i - l]);

		while (i + z[i] < n && s[z[i]] == s[i + z[i]])
			z[i]++;

		if (i + z[i] - 1 > r)
			l = i,  r = i + z[i] - 1;

	}

	return z;

}

vector<int> pf(string p) {
    int n = sz(p);
    vector<int> pref_fun(n, 0);

    for (int i = 1;i < n;i++) {
        int j = pref_fun[i - 1];
        while (j > 0 && p[i] != p[j])
            j = pref_fun[j - 1];
        if (p[i] == p[j])
            j++;
        pref_fun[i] = j;
    }
    return pref_fun;
}

vector<vector<int> > mul(vector<vector<int> > &a, vector<vector<int> > &b) {
    int n = sz(a);
    vector<vector<int> > c(n, vector<int> (n, 0));

    for (int i = 0;i < n;i++) {
        for (int j = 0;j < n;j++) {
            for (int k = 0;k < n;k++) {
                ll ga = a[i][k];
                ga *= b[k][j];
                ga %= mod;
                c[i][j] += ga;
                if (c[i][j] >= mod) {
                    c[i][j] -= mod;
                }
            }
        }
    }

    return c;
}

vector<vector<int> > matrix_pow(vector<vector<int> > a, ll y) {
    int n = sz(a);
    vector<vector<int> > res(n, vector<int> (n, 0));
    for (int i = 0;i < n;i++) res[i][i] = 1;
    while (y) {
        if (y%2 == 1) {
            res = mul(res, a);
            y--;
        }else {
            a = mul(a, a);
            y /= 2;
        }
    }
    return res;
}

ll f(ll x) {
    vector<int> gg;
    while (x) {
        gg.pb(x%10);
        x /= 10;
    }
    sort(all(gg));
    ll res1 = 0, res2 = 0;
    for (auto x : gg) res1 = res1 * 10 + x;
    reverse(all(gg));
    for (auto x : gg) res2 = res2 * 10 + x;
    return max(res1, res2) - min(res1, res2);
}

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

    ll n, k;
    cin >> n >> k;

    for (int i = 0;i < k;i++) n = f(n);

    cout << n;

    return 0;
}

/*
    @uthor: Amit Kumar
    user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define int      long long
#define double   long double
#define uint     unsigned long long
#define all(vec) vec.begin(),vec.end()
#define endl "\n"
int google_itr = 1;
#define google(x) cout<<"Case #"<<x<<": "
#define pi 3.14159265358979323846264338327950L

vector<string> vec_splitter(string s) {
        s += ',';
        vector<string> res;
        while(!s.empty()) {
                res.push_back(s.substr(0, s.find(',')));
                s = s.substr(s.find(',') + 1);
        }
        return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
        if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
        stringstream ss; ss << H;
        cerr << args[idx] << " = " << ss.str();
        debug_out(args, idx + 1, LINE_NUM, T...);
}

#define XOX
#ifdef XOX
    #define deb(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
    #define deb(...) 42
#endif

const int mod = 1e9+7;
const int inf = 1e18;

void virus(){
        int n, k;
        cin >> n >> k;

        int last = n;
        auto inc = [&](int num) {
            string s = to_string(num);
            sort(all(s));
            return stoll(s);
        };
        auto dec = [&](int num) {
            string s = to_string(num);
            sort(all(s), greater<char>());
            return stoll(s);
        };
        for(auto i=0; i<k; i++) {
            int curr = dec(last) - inc(last);
            last = curr;
        }

        cout << last << endl;
}

int32_t 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*/

    int t = 1;
    //cin >> t;
    while(t--){
           auto start = system_clock::now();
           virus();
           auto stop = system_clock::now();
           duration<double> duration = (stop - start);
           //cerr << "\nTime: "<< fixed << setprecision(10) << (double)duration.count() <<"sec"<< endl;
           //your code goes here
    }
    return 0;
}


#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 100; int n, m, x, y;
char mat[maxN][maxN + 1];

int di[4] = {0, 0, -1, 1}, dj[4] = {1, -1, 0, 0};
int main()
{
  while (~scanf("%d %d %d %d", &n, &m, &x, &y))
  {
    x--, y--;
    for (int i = 0; i < n; i++)
      scanf(" %s", mat[i]);

    int ans = -3;
    for (int k = 0; k < 4; k++)
    {
      int i = x, j = y;
      while (i >= 0 && i < n && j >= 0 && j < m && mat[i][j] == '.')
      {
        i += di[k], j += dj[k];
        ans++;
      }
    }
    ans = max(ans, 0);

    printf("%d\n", ans);
  }
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
  int h, w, x, y, cnt = 1;
  cin >> h >> w >> x >> y;
  vector<string> s(h);
  for (int i = 0; i < h; i++) cin >> s.at(i);

  for (int i = 1; i < 100; i++) {
    if (x - 1 + i >= h) {
      break;
    }
    if (s.at(x - 1 + i).at(y - 1) == '.')
      cnt++;
    else
      break;
  }
  for (int i = 1; i < 100; i++) {
    if (x - 1 - i < 0) {
      break;
    }
    if (s.at(x - 1 - i).at(y - 1) == '.')
      cnt++;
    else
      break;
  }
  for (int i = 1; i < 100; i++) {
    if (y - 1 + i >= w) {
      break;
    }
    if (s.at(x - 1).at(y - 1 + i) == '.')
      cnt++;
    else
      break;
  }
  for (int i = 1; i < 100; i++) {
    if (y - 1 - i < 0) {
      break;
    }
    if (s.at(x - 1).at(y - 1 - i) == '.')
      cnt++;
    else
      break;
  }
  cout << cnt << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
using P = pair<int,int>;
using vp=vector<P>;
int main(){//cout<<fixed<<setprecision(20);
  int n;
  cin>>n;
  vp a(n);
  rep(i,0,n)cin>>a[i].first>>a[i].second;
  int ans=0;
  rep(i,0,n-1)rep(j,i+1,n)if(abs(a[i].second-a[j].second)<=abs(a[i].first-a[j].first))ans++;
  cout<<ans<<endl;
}

// â��Experience is the name everyone gives to their mistakes.â�� â�� Oscar Wilde
// Take care of mod becoming -ve

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define fro(i, s, e) for (auto i = s; i <= e; ++i)
#define int long long
#define ld long double
#define fr(i, n) for (int i = 0; i < n; i++)
#define ff first
#define ss second
#define mp make_pair
#define vi std::vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define setbits(x) __builtin_popcountll(x)
#define zrbits(x) __builtin_ctzll(x)
#define tc    \
    int t;    \
    cin >> t; \
    while (t--)
#define FILE                          \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout)
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define ps(x, y) fixed << setprecision(y) << x
#define endl "\n"
#define rev(i, e, s) for (auto i = e; i >= s; --i)
#define mod 1000000007
#define min_pq priority_queue<int, std::vector<int>, greater<int>>
#define printclock cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n";
using namespace std;
const int N = 1e5 + 5;
const int inf = 1000000000000000000;
#define fit(s, x) memset(s, x, sizeof(s));
#define out(x) cout << x << "\n"
#define deb(x) cout << #x <<": "<< x << "\n"
#define fr1(i, n) for (int i = 1; i <= n; i++)
#define pi 3.14159265358979323846264338327950
typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        PBDS;
#define debug(...) cerr<<" ["<<#__VA_ARGS__": "<<(__VA_ARGS__)<<"] "
// Use __gcd(a,b) for gcd
// find(all(x),key) to get the iterator and its index is obtained by find(all(x),key)-x.begin()
// find_if(iterator_first,iterator_last,unary function) returns first iterator if any element corresponding to unary function exists and if no such element is found it retrurns the last iterator
/*For example:
find_if(all(x),isodd) for x being a vector{10,25,40,55}; *it returns 25*/
/*search(all(v1),all(v2),pred) searches for all the elements of v2 present in v1 based on pred function the iterator correspond
to the first element of sequence if it exists and if not then th elast iterator is obtained.*/
//use substr(size_t pos,size_t len) for the substrings
// iota(forward itr,backwrd itr,val) can be used for consecutive numbers
//use emplace_back in vector
int power(int a, int b, int m = mod)
{
  long long ans = 1;
  while (b > 0)
  {
    if (b & 1LL)
    {
      ans = (ans * a) % mod;
    }
    a = (a * a) % mod;
    b = (b >> 1LL);
  }
  return ans;
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }

  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
int modInv(int a, int m = mod) {
  return power(a, m - 2, m); //m is prime
}
int dx[8] = {0, 1, 0, -1, -1, -1, 1, 1} ;
int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1} ;
int get(int n) {
  int ans = 0;
  while (n) {
    ans += (n % 10);
    n /= 10;
  }
  return ans;
}
inline void solve() {
  int n;
  cin >> n;
  std::vector<pii> v(n);
  fr(i, n) {
    int x, y;
    cin >> x >> y;
    v[i].ff = x;
    v[i].ss = y;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; ++j) {
      ld slope = abs((ld)(v[j].ss - v[i].ss) / (v[j].ff - v[i].ff));
      if (slope <= 1) {
        ans++;
      }
    }
  }
  out(ans);
}
int32_t main()
{
  fio;
#ifndef ONLINE_JUDGE
  FILE;
#endif
  // tc{
  //   solve();
  // }
  solve();
  printclock;
  return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ldb double
template<typename T>void ckmn(T&a,T b){a=min(a,b);}
template<typename T>void ckmx(T&a,T b){a=max(a,b);}
void rd(int&x){scanf("%i",&x);}
void rd(ll&x){scanf("%lld",&x);}
void rd(char*x){scanf("%s",x);}
void rd(ldb&x){scanf("%lf",&x);}
void rd(string&x){scanf("%s",&x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&i:x)rd(i);}
template<typename T,typename...A>void rd(T&x,A&...args){rd(x);rd(args...);}
template<typename T>void rd(){T x;rd(x);return x;}
int ri(){int x;rd(x);return x;}
template<typename T>vector<T> rv(int n){vector<T> x(n);rd(x);return x;}
template<typename T>void ra(T a[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]);}
template<typename T1,typename T2>void ra(T1 a[],T2 b[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]);}
template<typename T1,typename T2,typename T3>void ra(T1 a[],T2 b[],T3 c[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]),rd(c[st+i]);}
void re(vector<int> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){rd(u,v);E[u].pb(v);if(!dir)E[v].pb(u);}}
template<typename T>void re(vector<pair<int,T>> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){T w;rd(u,v,w);E[u].pb({v,w});if(!dir)E[v].pb({u,w});}}

const int mod=998244353;
int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
void ckadd(int&a,int b){a=add(a,b);}
int sub(int a,int b){a-=b;return a<0?a+mod:a;}
void cksub(int&a,int b){a=sub(a,b);}
int mul(int a,int b){return (ll)a*b%mod;}
void ckmul(int&a,int b){a=mul(a,b);}
int powmod(int x,int k){int ans=1;for(;k;k>>=1,ckmul(x,x))if(k&1)ckmul(ans,x);return ans;}
int inv(int x){return powmod(x,mod-2);}

const int N=1000050;
int F[N],I[N];
int binom(int n, int k){ return mul(F[n],mul(I[k],I[n-k]));}
void calc()
{
	F[0]=1;
	for(int i=1;i<N;i++) F[i]=mul(F[i-1],i);
	I[N-1]=inv(F[N-1]);
	for(int i=N-2;~i;i--) I[i]=mul(I[i+1],i+1);
}

int go[N];

int main(){
	calc();
	int n,m;
	rd(n,m);
	for(int i=2;i<=m;i++){
		if(!go[i]){
			for(int j=i;j<=m;j+=i)go[j]=i;
		}
	}
	int ans=0;
	for(int last=1;last<=m;last++){
		vector<pii> fact;
		for(int i=last;i>1;i/=go[i]){
			if(fact.empty()||fact.back().first!=go[i]){
				fact.pb({go[i],1});
			}else fact.back().second++;
		}
		int sol=1;
		for(auto it:fact){
			ckmul(sol,binom(it.second+n-1,it.second));
		}
		ckadd(ans,sol);
	}
	printf("%i\n",ans);
	return 0;
}

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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

int main() {
	const int mod = 998244353, i2 = 499122177;
	int n, k;
	scanf("%d %d", &n, &k);
	vector <int> a(n);
	rep(i, n) scanf("%d", &a[i]);
	vector <int> sum(k + 1), sum2(k + 1);
	rep(i, n) {
		int e = 1, e2 = 1;
		rep(j, k + 1) {
			sum[j] += e;
			if (sum[j] >= mod) sum[j] -= mod;
			sum2[j] += e2;
			if (sum2[j] >= mod) sum2[j] -= mod;
			e = 1LL * e * a[i] % mod;
			e2 = 1LL * e2 * (a[i] * 2) % mod;
		}
	}
	vector <vector <int> > C(k + 1, vector <int> (k + 1));
	rep(i, k + 1) rep(j, i + 1) C[i][j] = j ? (C[i - 1][j - 1] + C[i - 1][j]) % mod : 1;
	vector <int> ans(k + 1);
	for (int x = 1; x <= k; ++ x) {
		for (int y = 0; y <= x; ++ y)
			(ans[x] += 1LL * C[x][y] * sum[y] % mod * sum[x - y] % mod) %= mod;
		(ans[x] += mod - sum2[x]) %= mod;
		ans[x] = 1LL * ans[x] * i2 % mod;
		printf("%d\n", ans[x]);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repx(i, x, n) for (ll i = (ll)(x); i < (ll)(n); i++)
#define repr(i, n) for (ll i = ((ll)(n)-1); i >= 0; i--)
#define reprx(i, x, n) for (ll i = ((ll)(n)-1); i >= (ll)(x); i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((ll)(x).size())
#define submit(x) {cout<<x<<endl; return 0;}
#define X first
#define Y second
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T>bool chmax(T &a,T b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a,T b) {if (b<a) {a=b; return 1;} return 0;}
template<class T>long long ip(T a, T b) {bitset<60> s(b); long long val=1; for(int i=0;i<60;i++){if(s.test(i))val*=a; a*=a;} return val;}
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1LL << 60;
const double PI = 3.1415926535897932;

int main() {
  double x,y,z;
  cin>>x>>y>>z;
  double price = y / x;
  double ans = z * price;
  ll ans2 = ans;
  if (ans2 - ans == 0) ans2--;
  submit(ans2)
}

#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>

int x, y, z;

void solve()
{
	cin >> x >> y >> z;
	for(int i = 0;; i++)
	{
		if(x*i >= z*y)
		{
			cout << i - 1 << "\n";
			return;
		}
	}
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt", "r", stdin);
#endif
	solve();
	return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
//#define int long long
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PI = pair<pair<int,int>,int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using Tiib = tuple<int, int, bool>;
const int INF = 1001001007;
const long long mod = 1000000007LL;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int main(){
    int n; cin >> n;
    ld a = 0.0;
    ld b = 0.0;
    ld c = 0.0;
    rep(i,n){
        ld k; cin >> k;
        a += abs(k);
        b += k * k;
        c = max(c,abs(k));
    }
    cout << setprecision(20);
    cout << a << endl;
    cout << sqrt(b) << endl;
    cout << c << endl;
}

#include <string>
#include <math.h>
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
  int n;
  cin >> n;
  long long a = 0;
  long long b = 0;
  long long c = 0;
  long long x;
  for (long i = 0; i < n; i++) {
    cin >> x;
    if (x < 0)
     x = x * (-1);
    a = a + x;
    b = b + x * x;
    if (c < x)
      c = x;

  }
  long double bb =sqrt(b);
  cout << a << '\n' << fixed << setprecision(15) << bb << '\n';
  cout << c << '\n';
}


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

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int &it : a) {
        cin >> it;
        it %= 200;
    }
    vector<int> p(200, -1);
    if (n > 8) n = 8;
    for (int m = 1; m < (1 << n); m++) {
        int sum = 0;
        for (int i = 0; i < n; i++) {
            if ((m >> i) % 2 == 1) {
                sum += a[i];
            }
        }
        sum %= 200;
        if (p[sum] != -1) {
            cout << "Yes\n";
            cout << __builtin_popcount(p[sum]);
            for (int i = 0; i < n; i++) {
                if ((p[sum] >> i) % 2 == 1) {
                    cout << ' ' << i + 1;
                }
            }
            cout << '\n';
            cout << __builtin_popcount(m);
            for (int i = 0; i < n; i++) {
                if ((m >> i) % 2 == 1) {
                    cout << ' ' << i + 1;
                }
            }
            cout << '\n';
            return 0;
        } else {
            p[sum] = m;
        }
    }
    cout << "No\n";
}

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

const int N = 200010, mod = 1e9 + 7;

ll dp[N][20], k, num[N];
char s[N];

ll dfs(int pos, bool limit, bool lead, int cnt, ll state, int now){
	if(!pos){
		//printf("now = %d cnt = %d state = %lld\n", now, cnt, state);
		return cnt == k;
	}
	if(cnt > k)	return 0;
	if(!limit && !lead && ~dp[pos][cnt])	return dp[pos][cnt];
	ll ans = 0;
	int up = limit ? num[pos] : 15;
	//printf("up = %d\n", up);
	for(int i = 0; i <= up; ++ i){
		if(lead && !i)	ans = (ans + dfs(pos - 1, limit && i == up, true, 0, 0, 0)) % mod;
		else{
			//printf("pos = %d i = %d a = %d st = %d st | a = %d\n", pos, i, 1 << i, state, state | (1 << i));
			//printf("State = %lld x = %d\n", state, state || (1 << i));
			if((state >> i) & 1)	ans = (ans + dfs(pos - 1, limit && i == up, false, cnt, state, now * 16 + i)) % mod;
			else	ans = (ans + dfs(pos - 1, limit && i == up, false, cnt + 1, state | (1 << i), now * 16 + i)) % mod;
		}
	}
	if(!limit && !lead)	dp[pos][cnt] = ans;
	return ans;
}

ll solve(){
	int len = strlen(s + 1);
	for(int i = 1, j = len; i < j; ++ i, -- j)	swap(s[i], s[j]);
	for(int i = 1; i <= len; ++ i){
		if(s[i] >= '0' && s[i] <= '9')	num[i] = s[i] - '0';
		else	num[i] = s[i] - 'A' + 10;
	}
//	for(int i = 1; i <= len; ++ i)	printf("%d ", num[i]);
//	exit(0);
	return dfs(len, true, true, 0, 0, 0);
}

int main(){
	scanf("%s", s + 1);
	cin >> k;
	memset(dp, -1, sizeof dp);
	cout << solve();
	return 0;
}


#include <bits/stdc++.h>
#define ll                long long int
#define ld                long double
#define endl              "\n"
#define mp                make_pair
#define HCF               __gcd
#define LCM(m,n)          (m*n)/__gcd(m,n)
#define maxa(v)           *(max_element(all(v))
#define mina(v)           *(min_element(all(v))
#define vi                vector<ll>
#define pll               pair<ll,ll>
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define M                 998244353ll
#define S                 second
#define F                 first
#define inf               (int)1e9
#define fon(i,j,n)        for(ll i=j;i<(n);++i)
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define asort(v)          sort(v.begin(),v.end())
#define dsort(v)          sort(v.begin(),v.end(),greater<int>())
#define BS(v,k)           binary_search(v.begin(),v.end(),k)
#define UB(v,k)           (upper_bound(v.begin(),v.end(),k)-v.begin())
#define LB(v,k)           (lower_bound(v.begin(),v.end(),k)-v.begin())
#define mod               1000000007ll
using namespace std;
bool prime(ll n){bool b=true;
    for(ll i=2;i<=sqrt(n);i++){if(n%i==0){b=false;break;
        }
    }
    if(b)return true;
    else return false;
}

void solve(){
 ll n;cin>>n;
map<ll,ll>m;set<ll>s;
fon(i,0,n){ll x;cin>>x;s.insert(x);m[x]++;}
vi sum;
sum.pb(0);
ll k=1;
for(auto i:s) { sum.pb(sum[k - 1] + m[i]);k++; }
k=sum.size();
ll ans=0;
fon(i,1,k){ans+=(sum[i]-sum[i-1])*(sum[k-1]-sum[i]);}

cout<<ans;
    return;
}

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

    int tsc=1;
    while(tsc--){
        solve();
        cout<<endl;  }

    return 0;
}

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

using vi=vector<int>;
using vvi=vector<vi>;
using LL=long long;
using vL=vector<LL>;
using vvL=vector<vL>;

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

  long long a;
  map<long long ,long long > Map;
  for (int i=0 ; i<n ; i++) {
    cin>>a;
    Map[a]++;
  }

  long long ans=n*(n-1)/2;
  for (auto k : Map) {
    long long m=k.second;
    ans-=m*(m-1)/2;
  }
  cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MOD = 1000000007;
template <class T>
struct fenwick_tree {
	vector<T> x;
	fenwick_tree(int n) : x(n, 0) {}
	T sum(int i, int j) {
		if (i == 0) {
			T S = 0;
			for (j; j >= 0; j = (j & (j + 1)) - 1) S += x[j];
			return S;
		} else
			return sum(0, j) - sum(0, i - 1);
	}
	void add(int k, T a) {
		for (; k < x.size(); k |= k + 1) x[k] += a;
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(2 * N);
	int res = 0;
	for (int i = 0; i < 2 * N; i++) {
		cin >> A[i];
	}
	vector<int> B;
	for (int i = 0; i < N; i++) {
		B.push_back(min(A[N - 1 - i], A[i + N]));
		B.push_back(max(A[N - 1 - i], A[i + N]));
	}

	int sum = 0;
	priority_queue<int> pq;
	for (int i = 1; i < 2 * N; i++) {
		if (i % 2 == 0) {
			int a = -pq.top();
			if (a < B[i]) {
				res += B[i] - a;
				pq.pop();
				pq.push(-B[i]);
			}
		} else {
			res += B[i];
			pq.push(-B[i]);
		}
	}
	// fenwick_tree<int> ft(2 * N);
	// for (int i = 0; i < 3 * N; i++) {
	// 	ft.add(i, 1);
	// }
	// vector<pair<int, int> > vp;
	// for (int i = 0; i < 2 * N; i++) {
	// 	vp.emplace_back(B[i], i);
	// }
	// sort(B.rbegin(), B.rend());
	// for (int i = 0; i < 2 * N; i++) {
	// 	//cerr << vp[i].first << " " << vp[i].second << endl;
	// 	int p = vp[i].second;
	// 	if (ft.sum(0, p) - 2 >= 0) {
	// 		ft.add(p, -2);
	// 		res += vp[i].first;
	// 	}
	// }
	cout << res << endl;
}

#include<iostream>
#include<algorithm>
#include<numeric>
#include<queue>
#include<vector>
using namespace std;
const int BUF = 400005;

int nVal;
int val[BUF];

void read() {
    cin >> nVal;
    nVal *= 2;
    for (int i = 0; i < nVal; ++i) {
        cin >> val[i];
    }
}

void work() {
    long long sum = accumulate(val, val + nVal, 0LL);
    priority_queue<int, vector<int>, greater<int> > Q;
    for (int i = 0, L = nVal / 2 - 1, R = nVal / 2; i < nVal; i += 2, --L, ++R) {
        Q.push(val[L]);
        Q.push(val[R]);
        sum -= Q.top();
        Q.pop();
    }

    cout << sum << endl;
}

int main() {
    read();
    work();
    return 0;
}


#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0, length = n; i < length; i++)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ep emplace
#define epb emplace_back
#define scll static_cast<long long>
#define sz(x) static_cast<int>((x).size())
#define pfll(x) printf("%lld\n", x)
#define ci(x) cin >> x
#define ci2(x, y) cin >> x >> y
#define ci3(x, y, z) cin >> x >> y >> z
#define ci4(w, x, y, z) cin >> w >> x >> y >> z
#define co(x) cout << x << endl
#define co2(x, y) cout << x << " " << y << endl
#define co3(x, y, z) cout << x << " " << y << " " << z << endl
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;
typedef priority_queue<int> PQ;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
typedef priority_queue<P> PQP;
typedef priority_queue<P, vector<P>, greater<P>> PQPG;

const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9;
int n, m, q, t[MAX_N], x[MAX_N], y[MAX_N], memo[MAX_N][2];
map<int, int> ma;
vector<ll> ans;

P bit[MAX_N + 2][2];

P sum(int i, int j) {
    P s = P(0, 0);
    while (i > 0) {
        s.fi += bit[i][j].fi;
        s.se += bit[i][j].se;
        i -= i & -i;
    }
    return s;
}

void add(int i, int j, int x, int y) {
    while (i <= q + 1) {
        bit[i][j].fi += x;
        bit[i][j].se += y;
        i += i & -i;
    }
}

int main() {
    ci3(n, m, q);
    rep(i, q) {
        ci3(t[i], x[i], y[i]);
        ma.ep(y[i], 0);
    }
    ma.ep(0, 0);
    int cnt = 0;
    for (auto &i: ma) i.se = ++cnt;
    ans.epb(0);
    rep(i, n) add(1, 0, 1, 0);
    rep(i, m) add(1, 1, 1, 0);
    rep(i, q) {
        int old_y = memo[x[i] - 1][t[i] - 1];
        add(ma[y[i]], t[i] - 1, 1, y[i]);
        add(ma[old_y], t[i] - 1, -1, -old_y);
        P p1 = sum(ma[y[i]] - t[i] % 2, t[i] % 2);
        P p2 = sum(ma[old_y] - t[i] % 2, t[i] % 2);
        ll tmp = ans.back();
        tmp += scll(p1.fi) * y[i] - scll(p2.fi) * old_y;
        tmp += p2.se - p1.se;
        ans.epb(tmp);
        memo[x[i] - 1][t[i] - 1] = y[i];
    }
    rep(i, q) co(ans[i + 1]);
    return 0;
}

#include<bits/stdc++.h>
#include<bits/extc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t){
	while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr<<#x<<": "; for(auto i:x) cerr<<i<<" "; cerr<<endl;}}
#define debugr(l,r,x) {{cerr<<#x<<": "; for(int i=l;i<=r;i++) cerr<<x<<" "; cerr<<endl;}}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debugr(l,r,x)
#define cerr while(0) cerr
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef __int128 INT;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define priority_queue std::priority_queue
#define F first
#define S second
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

struct Node{
	typedef ll T;
	static constexpr T unset = INT_MIN, unit=0;
	T f(T a, T b) { return max(a, b); }
	T mset=unset, madd=0, val=unit; int lo, hi;
	Node *l=0, *r=0;
	Node(int lo, int hi): lo(lo), hi(hi){
		if(lo<hi){
			int mid=(lo+hi)/2;
			l=new Node(lo, mid); r=new Node(mid+1, hi);
		}
	}
	T query(int L, int R){
		push();
		if(R<lo || hi<L) return unit; //sentinel
		if(L<=lo && hi<=R) return val;
		return f(l->query(L, R), r->query(L, R));
	}
	void set(int L, int R, T x, int t=1){
		push();
		if(R<lo || hi<L) return;
		if(L<=lo && hi<=R){
			(t==1 ? mset : madd)=x;
			push(); return;
		}
		l->set(L, R, x, t), r->set(L, R, x, t);
		val=f(l->val, r->val);
	}
	void add(int L, int R, T x) { return set(L, R, x, 0); }
	void push(){
		mset!=unset ? val=mset : val+=madd; //multiply (hi-lo+1) for sum queries
		if(l){ //if parent, push down
			if(mset!=unset){
				l->mset=r->mset=mset;
				l->madd=r->madd=0;
			}
			else if(madd){
				l->mset!=unset ? l->mset+=madd : l->madd+=madd;
				r->mset!=unset ? r->mset+=madd : r->madd+=madd;
			}
		}
		mset=unset, madd=0;
	}
};

map<int, int> mp;
ordered_set os[3];
ll a[3][200006];
ll cnt[3];
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, m, q;
	cin>>n>>m>>q;
	vector<pair<int, pii>> queries;
	set<int> s;
	s.insert(0);
	for(int i=1; i<=q; i++){
		int t, x, y;
		cin>>t>>x>>y;
		queries.push_back({t, {x, y}});
		s.insert(y);
	}
	int cur=1;
	for(int i: s) mp[i]=cur++;
	ll ans = 0;
	Node **tree = new Node*[3];
	for(int i=1;i<3;i++) tree[i] = new Node(0, 200005);

	auto sum = [&](int t, ll v){
		ll ans = cnt[t];
		ans -= tree[t]->query(mp[v], mp[v]);
		ans += os[t].order_of_key(v+1) * v;
		return ans;
	};

	for(int i=0; i<n; i++) os[1].insert(0);
	for(int j=0; j<m; j++) os[2].insert(0);
	//debugv(os[1]);
	//debugv(os[2]);
	for(auto [t, p]: queries){
		auto [x, y] = p;
		ans += sum(3-t, y) - sum(3-t, a[t][x]);
		cout<<ans<<'\n';
		cnt[t]+=y-a[t][x];
		tree[t]->add(mp[y], 200004, y);
		tree[t]->add(mp[a[t][x]], 200004, -a[t][x]);
		os[t].erase(os[t].lower_bound(a[t][x]-1));
		os[t].insert(y);
		a[t][x] = y;
		debugv(os[1]);
		debugv(os[2]);
	}
}


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

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, b) for (ll i = a; i < b; ++i)
#define rep_down(i, a, b) for (ll i = a; i > b; --i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>

constexpr ll INF = (1ll << 60);
constexpr ll mod = 1000000007;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    ll n,a[100001],b[100001],sum=0;
    cin>>n;
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n){
        cin>>b[i];
    }
    rep(i,n){
        sum+=a[i]*b[i];
    }
    if(sum==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test            int t;cin>>t;while(t--)
#define REP(i,n)        for (int i = 1; i <= n; i++)
#define MOD             1000000007
#define MOD2            998244353
#define ll              long long
#define ld              long double
#define int             ll
#define pb              push_back
#define ii              pair<int,int>
#define vi              vector<int>
#define vii             vector<ii>
#define ff              first
#define ss              second
#define INF             1000000000
#define HINF            1000000000000000
#define mem(a,b)        memset(a,b,sizeof(a))
#define arrin(x,n)      int x[n]; for(int o=0;o<n;o++) cin>>x[o]
#define arrout(x,n)     for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl
#define vecin(x,n);     vi x;int hool; for(int o=0;o<n;o++) {cin>>hool; x.pb(hool);}
#define vecout(x,n)     for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl
#define all(x)          x.begin(),x.end()
#define deb(x)          cout<<#x<<'='<<x<<endl
#define deb2(x,y)       cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<endl
#define deb3(x,y,z)     cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<" "<<#z<<'='<<z<<endl
#define debarr(arr,n)   for(int o=0;o<n;o++) deb2(o,arr[o])
#define debarrall(arr)  debarr(arr,arr.size())
#define IO              freopen("input1.txt", "r", stdin); freopen("output1.txt", "w+", stdout)
const double pi = 3.14159265358979323846;

int powersimple(int a, int b){//a^b
    int res=1;
    while(b>0){
        if(b&1)
		{res=(res*a);
		b--;}
        a=(a*a);
        b>>=1;
    }
    return res;
}

int ncr(int n,int k)
{
	int ans=1;
	if(k>n-k)
	k=n-k;
	for(int i=1;i<=k;i++)
	ans*=(n-i+1),ans/=i;
	return ans;
}

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;
}

int modInverse(int n, int p)
{
    return power(n, p - 2, p);
}

int ncrModPFermat(int n,int r, int p)
{

    if (r == 0)
		return 1;

    int fac[n + 1];
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % p;

    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}

int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}

///////////////END OF TEMPLATE//////////////////

void solve()
{

	int i,j,a,b,ca=0,cb=0;
    cin>>a>>b;
    while(a>0)
    {
        ca+=a%10;
        a/=10;
    }
    while(b>0)
    {
        cb+=b%10;
        b/=10;
    }
    cout<<max(ca,cb);
}
int32_t main() {

    #ifndef ONLINE_JUDGE
        freopen("input1.txt", "r", stdin);
        freopen("output1.txt", "w+", stdout);
    #else
      // online submission
    #endif

    fast
    //IO;
	//cout<<fixed<<setprecision(15);
    //test
    {

        solve();

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b)     for(int i=a;i>=b;--i)
#define init(a, x) memset(a,x,sizeof(a))
#define ld long double
#define dd double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector<pll> vplll;
ll mod = 1e9+7;
const ld PI = 2 * acos(0.0);
const vector<ll> dx = {1, -1, 0, 0};
const vector<ll> dy = {0, 0, 1, -1};
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define len(x) (ll) x.length()
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,t,n,m,k,q;
    t = 1;
    // cin>>t;
    while(t--)
    {
        cin>>a>>b>>n>>m;;
        string s[a];
        for(int i=0;i<a;i++)
            cin>>s[i];
        ll ans =1;
        int cnt = 0;
        for(int i=m;i<b;i++)
        {
            if(s[n-1][i]=='.')
                cnt++;
            else
                break;
        }
        // ans += (cnt*(cnt-1))/2;
        ans += cnt;
        cnt =0;
        for(int i=m-2;i>=0;i--)
        {
            if(s[n-1][i]=='.')
                cnt++;
            else
                break;
        }
        ans += cnt;
        cnt = 0;
        for(int i=n;i<a;i++)
        {
            if(s[i][m-1]=='.')
                cnt++;
            else
                break;
        }
        ans += cnt;
        cnt =0;
        for(int i=n-2;i>=0;i--)
        {
            if(s[i][m-1]=='.')
                cnt++;
            else
                break;
        }
        ans += cnt;
        // ans += (cnt*(cnt-1))/2;
        cout<<ans<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
using pint = pair<ll, ll>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main() {
    int h, w, x, y;
    cin >> h >> w >> x >> y;
    vector<string> s(h);
    rep(i, 0, h) cin >> s[i];
    int cnt = 0;
    rep(i, x - 1, h) {
        if (s[i][y - 1] == '#') break;
        cnt++;
    }
    per(i, 0, x - 1) {
        if (s[i][y - 1] == '#') break;
        cnt++;
    }
    rep(i, y, w) {
        if (s[x - 1][i] == '#') break;
        cnt++;
    }
    per(i, 0, y - 1) {
        if (s[x - 1][i] == '#') break;
        cnt++;
    }
    cout << cnt << "\n";
}


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

ll solve(vl& A, map<P, ll>& m, ll x, int i) {
    if (i == int(A.size()) - 1) return 1;
    if (m.count(P(x, i))) return m[P(x, i)];
    ll d = x % A[i + 1];
    ll ret = solve(A, m, x - d, i + 1);
    if (d > 0) ret += solve(A, m, x + (A[i + 1] - d), i + 1);
    return m[P(x, i)] = ret;
}

int main() {
    // input
    ll N, X;
    cin >> N >> X;
    vl A(N);
    rep(i, N) cin >> A[i];

    // solve
    map<P, ll> m;
    ll ans = solve(A, m, X, 0);
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define revrep(i,n) for(ll i=(n)-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define newl '\n'
#define YN(e) ((e)?"Yes":"No")
#define all(a) begin(a),end(a)
#define rall(a) rbegin(a),rend(a)
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}
inline constexpr int Mod = 1000000007;
//inline constexpr int Mod = 998244353;
ll needs[200005];

int main() {
    fastio;
    ll ans=1;
    ll N,W;
    cin >> N >> W;
    rep(i,N) {
        ll s,t,p;
        cin >> s >> t >> p;
        needs[s] += p;
        needs[t] -= p;
    }
    rep(i,200005-1) {
        needs[i+1] += needs[i];
        if (needs[i] > W)
            ans = 0;
    }
    cout << YN(ans) << endl;
}


#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
  FAST/**/

  ll n;
  cin>>n;
  vector<ll> divi[n+1];
  for(ll i=1;i<n;i++)
        for(ll j=2*i;j<=n;j+=i)
            divi[j].pb(i);

  ll val[n+1];
  memset(val,0,sizeof(val));

  set<ll, greater<ll>> st;
  for(ll i=1;i<=n;i++)
        st.insert(i);
  while(st.size()>0)
  {
      auto curr = *st.begin();
      st.erase(st.begin());

      autoit(divi[curr], it)
      {
          if(val[*it] > val[curr]-1)
              val[*it] = val[curr]-1;
      }
  }

  ll maxi = 0;
  for(ll i=1;i<=n;i++)
        maxi = min(maxi, val[i]);
  maxi--;
  for(ll i=1;i<=n;i++)
        val[i]-=maxi;
  for(ll i=1;i<=n;i++)
        cout<<val[i]<<" ";

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a; i>=b; i--)

typedef vector<int> vi;
typedef long long int ll;
typedef vector<ll> vll;
#define fastio std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI 3.1415926535
ll Mod = 1e9+7;
// ll Mod = 998244353;

// ll mult(ll a, ll b) {
//     ll ret = 1;
//     ret = ((a%Mod) * (b%Mod))%Mod;
//     return ret;
// }

// ll power(ll a, ll b = Mod-2) {
//     if(b == 0) return 1;
//     ll ret = 1;
//     while(b) {
//         if(b&1) {
//             ret = mult(ret,a);
//         }
//         a = mult(a,a);
//         b>>=1;
//     }
//     return ret;
// }

// ll sub(ll a, ll b) {
//     ll ret = (a%Mod - b%Mod + Mod)%Mod;
//     return ret;
// }

// void seive(vector<bool> &status) {
//      for(ll i = 2; i<=1e6; i++) {
//          if(status[i]) {
//                 for(ll j =i*i; j<=1e6; j+=i) status[j] = 0;
//          }
//      }
//  }

// int getmex(vi& occr, int n, int mex) {
//     for(int i = mex; i<n; i++) {
//         if(occr[i] == 0) return i;
//     }
//     return n;
// }

// void swap(int &a, int &b) {
//     a = a + b;
//     b = a - b;
//     a = a - b;
// }

void solve_case() {
    int n;
    cin>>n;

    f(i,1,n+1) {
        fr(j,31,0) {
            if(i&(1<<j)) {
                cout<<j+1<<' ';
                break;
            }
        }
    }
}

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

	fastio;
    // vector<bool> status(1e6+1,1);
    int t = 1;
    // vll primes;
    // seive(status);
    // f(i,2, 1e6+1) {
    //     if(status[i]) primes.push_back(i);
    // }
    // cin>>t;
    while(t--) {
        solve_case();
    }
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using iPair = pair<int,int>;
using lPair = pair<ll, ll>;
using ivector = vector<int>;
using lvector = vector<ll>;
using istack = stack<int>;
using iqueue = queue<int>;
using ivv = vector<vector<int>>;
using lvv = vector<vector<ll>>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
vector<iPair> dir = {{1,0}, {-1,0}, {0,1}, {0,-1}};
#define dump(x) cout << #x << " = " << (x) << endl
#define ALL(x) begin(x),end(x)
#define rep(i,s,e) for(ll i=(s), i_stop=(e); i<i_stop; ++i)
#define repRev(i,s,e) for(ll i=(e)-1, i_stop=(s); i>=i_stop; --i)
#define range(i,s,n) for(ll i=(s), i_stop=(s)+(n); i<i_stop; ++i)
#define rangeRev(i,s,n) for(ll i=(s), i_stop=(s)-(n); i>i_stop; --i)
#define foreach(x,container) for(auto &&x:container)
template<typename T> bool chmax(T& a, const T b) {if(a<b) {a=b;return true;} return false;}
template<typename T> bool chmin(T& a, const T b) {if(a>b) {a=b;return true;} return false;}
template<typename T> void printArr(vector<T> &arr){
    for(auto &x:arr) {cout << x << " ";} cout << endl;
}

// =====================================================>

/*

*/

void solve() {
    ll n,q; cin>>n>>q;
    lvector a(n+1);
    range(i, 1, n) cin>>a[i];
    sort(ALL(a));
    // printArr(a);

    lvector s(n); s[0] = a[1] - 1;
    for(ll i = 1; i < n; ++i) {
        // [ a[i]+1, a[i+1] )
        s[i] = s[i-1] + a[i+1] - a[i] - 1;
    }

    // printArr(s);

    while(q--) {
        ll k; cin>>k;
        if(k > s[n-1]) {
            cout << a[n] + (k-s[n-1]) << endl;
        } else {
            int idx = lower_bound(ALL(s), k) - s.begin();
            if(idx == 0) {
                cout << k << endl;
            } else {
                // 在 [a[i]+1, a[i+1]) 之間
                cout << a[idx] + (k - s[idx-1]) << endl;
            }
        }
    }
}

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

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

// modpow
template<class T> T modpow(T b,T p,T m){
  T rt = 1; b %= m;
  while(p>0){
    if(p&1) rt = (rt*b)%m;
    b = (b*b)%m; p>>=1;
  }
  return rt;
}

// small mod combination
// # f,g を次のようにする
// - f[i] : i が何回 MOD で割れるか. これを f_pre とする
// - g[i] : i の MOD で割れない部分の MOD での余り. これを g_pre とする
// # その後, f,g を次のようにする
// - f[i] : i! が何回 MOD で割れるか
//   * f[i] = f_pre[1]+...+f_pre[i] 累積和
// - g[i] : i! が MOD で割れない部分の MOD での余り
//   * g[i] = g_pre[1]*...*g_pre[i] 累積積(mod)
const int64_t MOD = 3;
const int64_t fMAX = 400007;
int64_t f[fMAX+1],g[fMAX+1],g_inv[fMAX+1];

void init(){
  for(int64_t i=1,tmp;i<=fMAX;i++){
    tmp = i;
    while(tmp%3==0){
      tmp /= 3; f[i]++;
    }
    g[i] = tmp%3;
  }
  g[0]=1;
  for(int64_t i=1;i<=fMAX;i++)
    f[i] += f[i-1];
  for(int64_t i=1;i<=fMAX;i++)
    g[i] = g[i]*g[i-1]%MOD;
  for(int64_t i=0;i<=fMAX;i++)
    g_inv[i] = modpow(g[i],MOD-2,MOD);
  return;
}

int64_t modcomb_s(int64_t n,int64_t r,int64_t m){
  if(f[n]-f[r]-f[n-r]>0) return 0;
  return g[n]*g_inv[r]*g_inv[n-r]%m;
}

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

  int64_t n; cin >> n;
  string s; cin >> s;

  init();
  vector<int64_t> a(n);
  for(int64_t i=0;i<n;i++){
    if(s[i]=='B') a[i] = 0;
    else if(s[i]=='R') a[i] = 1;
    else if(s[i]=='W') a[i] = 2;
  }
  int64_t ans=0;
  for(int64_t i=0;i<n;i++){
    ans += a[i] * modcomb_s(n-1,i,MOD);
    ans %= MOD;
  }

  ans = ans * modpow((int64_t)2,n-1,MOD) % MOD;

  string ans_s;
  if(ans==0) ans_s='B';
  else if(ans==1) ans_s='R';
  else if(ans==2) ans_s='W';

  cout << ans_s << "\n";

  return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#define ll long long
#define nl '\n'
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define pii pair<int, int>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
void solve() {
    int n,k;
    cin>>n>>k;
    int sumn = 0;
    for(int i =1;i<=n;i++){
        for(int j = 1;j<=k;j++){
            string room_no = to_string(i)+"0"+to_string(j);
            sumn+=stoi(room_no);
        }

    }
    cout<<sumn<<nl;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int te = 1;
    //cin >> te;
    while(te--) solve();
}

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

int main(){
    ll ii, jj, count(0),flor(0);
    cin >> ii>>jj;
    rep(i,jj){
        count+=i+1;
    }
    rep(i,ii){
        flor+=i+1;
    }
    count =100 * flor * jj + count*ii;
    cout << count;
    return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<vector>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
template<typename T>
using vec = vector<T>;
#define rep(i, n) for (i64 i = 0; i < (i64)(n); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;
void solve(){
}
using i64 = int_fast64_t;
constexpr i64 MAX = 10000000;
constexpr i64 MOD = 1000000007;
i64 fac[MAX], finv[MAX], inv[MAX];
template <i64 modulus>
class modcal
{

public:
  i64 a;

  constexpr modcal(const i64 x = 0) noexcept : a(x % modulus) {}
  constexpr i64 &value() noexcept { return a; }
  constexpr const i64 &value() const noexcept { return a; }
  constexpr modcal operator+(const modcal rhs) const noexcept
  {
    return modcal(*this) += rhs;
  }
  constexpr modcal operator-(const modcal rhs) const noexcept
  {
    return modcal(*this) -= rhs;
  }
  constexpr modcal operator*(const modcal rhs) const noexcept
  {
    return modcal(*this) *= rhs;
  }
  constexpr modcal operator/(const modcal rhs) noexcept
  {
    return modcal(*this) /= rhs;
  }
  constexpr modcal &operator+=(const modcal rhs) noexcept
  {
    a += rhs.a;
    if (a >= modulus)
    {
      a -= modulus;
    }
    return *this;
  }
  constexpr modcal &operator-=(const modcal rhs) noexcept
  {
    if (a < rhs.a)
    {
      a += modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modcal &operator*=(const modcal rhs) noexcept
  {
    a = a * rhs.a % modulus;
    return *this;
  }
  constexpr modcal &operator/=(modcal rhs) noexcept
  {
    i64 exp = modulus - 2;
    while (exp)
    {
      if (exp % 2)
      {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }

  void COMninit()
  {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
      fac[i] = fac[i - 1] * i % modulus;
      inv[i] = MOD - inv[modulus % i] * (modulus / i) % modulus;
      finv[i] = finv[i - 1] * inv[i] % modulus;
    }
  }
  i64 COMn(i64 n, i64 k)
  {
    if (n < k)
      return 0;
    if (n < 0 || k < 0)
      return 0;
    return fac[n] * (finv[k] * finv[n - k] % modulus) % modulus;
  }
  constexpr modcal<1000000007> modpow(const modcal<1000000007> &a, i64 n)
  {
    if (n == 0)
      return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1)
      t = t * a;
    return t;
  }
};
using modc = modcal<1000000007>;
int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    i64 h,w;
    cin >> h >> w;
    vec<string> s(h);
    rep(i,h)cin >> s[i];
    i64 dx[3] = {1,1,0};
    i64 dy[3] = {0,1,1};
    vec<vec<vec<modc>>> dp(h,vec<vec<modc>>(w,vec<modc>(4,0)));
    dp[0][0][3] = 1;
    rep(i,h){
        rep(j,w){
            rep(k,4){
                if(dp[i][j][k].a == 0)continue;
                rep(v,3){
                    i64 ny = dy[v] + i;
                    i64 nx = dx[v] + j;
                    if(nx < 0 || nx >= w || ny < 0 || ny >= h)continue;
                    if(s[ny][nx] == '#')continue;
                    dp[ny][nx][v] += dp[i][j][k];
                    if(k == v)dp[ny][nx][v] += dp[i][j][k];
                }
            }
        }
    }
    modc ans = 0;
    rep(i,3){
        ans += dp[h - 1][w - 1][i];
    }
    cout << ans.a << endl;
}

// Author : ps41

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll M = 1e9 + 7, N = 2e3 + 5;
string a[N];
ll row[N][N], col[N][N], dp[N][N], diag[N][N];
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
	ll n, m;
	cin >> n >> m;
	for (ll i = 1; i <= n; i++) cin >> a[i], a[i] = "#" + a[i];
	dp[1][1] = 1;
	row[1][1] = 1, col[1][1] = 1, diag[1][1] = 1;
	for (ll i = 1; i <= n; i++)
	{
		for (ll j = 1; j <= m; j++)
		{
			if (i == 1 and j == 1) continue;
			if (a[i][j] == '#') dp[i][j] = 0, row[i][j] = 0, col[i][j] = 0, diag[i][j] = 0;
			else
			{
    			dp[i][j] = (row[i][j - 1] + col[i - 1][j] + diag[i - 1][j - 1]) % M;
    			row[i][j] = (dp[i][j] + row[i][j - 1]) % M;
    			col[i][j] = (dp[i][j] + col[i - 1][j]) % M;
    			diag[i][j] = (dp[i][j] + diag[i - 1][j - 1]) % M;
    		}
		}
	}
	cout << dp[n][m];
}


/*
Sat-Chitta-Ananda
*/

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

int32_t main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);

	int x, y; cin >> x >> y;
	int a; cin >> a;
	int b; cin >> b;
	int e = 0;

	while(x < y)
	{
		if(LLONG_MAX/x >= a && x*a <= x+b) x *= a, ++e;
		else {
			e += (y-x)/b;
			if((y-x)%b != 0) ++e;
			break;
		}
	}

	cout << e-1 << '\n';
	return 0;
}

// Created by ...
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<ll,ll>
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
//#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(ll a,ll b){if(a<b)return a; return b;}
ll Max(ll a,ll b){if(a>b)return a; return b;}
int32_t main() {
    IOS;

        unsigned long long int x,y,a,b,exp=0;
        cin>>x>>y>>a>>b;

        while(x<y && x*a<x+b){
        	if(x*a>=y || x*a<x)break;
        	x*=a;
        	if(x<0)break;
        	++exp;
        }
        exp+=Max(0,(y-x-1)/b);
        cout<<exp;

        cout<<'\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define M 1000000007
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;

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

    int t = 1, i;
    //cin >> t;

    while (t--)
    {
        ll n, k;
        cin >> n >> k;
        while (k--)
        {
            if (n % 200 == 0)
            {
                n /= 200;
            }
            else
            {
                n *= 1000;
                n += 200;
            }
        }
        cout << n;
    }

    return 0;
}

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

int main() {
	ll N, K;
	cin >> N >> K;
	for (; K; K--) {
		if (N % 200 == 0) {
			N /= 200;
		}
		else {
			N = N * 1000 + 200;
		}
	}
	cout << N << endl;
}


#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>
#include <limits>
#include <iostream>

using namespace std;

int n;
vector<vector<pair<int, int>>> graph;
int best_path[2001][2001];

long long calc(int start) {
  priority_queue<pair<long long, int>> pq;
  vector<long long> dist(n, LLONG_MAX);
  vector<char> visit(n, 0);
  pq.emplace(0, start);
  dist[start] = 0;
  while (!pq.empty()) {
    long long curdist;
    int cur;
    tie(curdist, cur) = pq.top();
    pq.pop();
    curdist = -curdist;
    if (visit[cur]) continue;
    for (auto edge : graph[cur]) {
      int next = edge.first;
      long long nd = edge.second + curdist;
      if (dist[next] > nd) {
        dist[next] = nd;
        pq.emplace(-nd, next);
      }
    }
  }
  long long ans = LLONG_MAX;
  for (int i = 0; i < n; i++) {
    if (dist[i] == LLONG_MAX)continue;
    if (best_path[i][start] == -1) continue;
    ans = min(ans, best_path[i][start] + dist[i]);
  }
  if (ans == LLONG_MAX) ans = -1;
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) best_path[i][j] = -1;
  graph.resize(n);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    graph[a].emplace_back(b, c);
    if (best_path[a][b] == -1 || best_path[a][b] > c) {
      best_path[a][b] = c;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << calc(i) << "\n";
  }
  return 0;
}

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

ll infty = (ll)pow(10, 15);

int main(){
  ll N, M;
  cin >> N >> M;

  map<pll, ll> loads;
  map<ll, vl> from;
  map<ll, vl> to;

  ll A, B, C;

  rep(i, M){
    cin >> A >> B >> C;

    if(loads.count({A, B}) == 1){ // 既に登録されていた場合、注意が必要
      loads[{A, B}] = min(loads[{A, B}], C);
    } else{
      loads[{A, B}] = C;
      from[A].push_back(B);
      to[B].push_back(A);
    }
  }

  rep2(i, 1, N + 1){
    if((from.count(i) == 0) || (to.count(i) == 0)){
      cout << -1 << "\n";
      continue;
    }

    vl dist(N + 1, infty);
    vl done(N + 1, 0);
    priority_queue<pll, vpll, greater<pll> > Q;

    dist[0] = 0;
    Q.push({0, 0});

    while(!Q.empty()){
      ll cost = Q.top().first;
      ll cnode = Q.top().second;
      Q.pop();

      if(cost > dist[cnode])
	continue;

      if(cnode == 0){
	for(auto itr = from[i].begin(); itr != from[i].end(); itr++){
	  if(dist[*itr] > loads[{i, *itr}] + dist[cnode]){
	    dist[*itr] = loads[{i, *itr}] + dist[cnode];
	    Q.push({dist[*itr], *itr});
	  }
	}
      } else{
	for(auto itr = from[cnode].begin(); itr != from[cnode].end(); itr++){
	  if(dist[*itr] > loads[{cnode, *itr}] + dist[cnode]){
	    dist[*itr] = loads[{cnode, *itr}] + dist[cnode];
	    Q.push({dist[*itr], *itr});
	  }
	}
      }
    }

    if(dist[i] < infty)
      cout << dist[i] << "\n";
    else
      cout << -1 << "\n";
  }

  return 0;
}