#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
//#define MOD 1000000007
#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false

class Fenwick_tree{
    /*
    Copyright (c) 2021 0214sh7
    https://github.com/0214sh7/library/
    */
    private:
    std::vector<long long> BIT;

    public:

    void add(int a,long long w){
        for(int x=a;x<BIT.size();x|=(x+1)){
            BIT[x]+=w;
        }
    }

    void init(int n){
        BIT.clear();
        for(int i=0;i<n;i++){
            BIT.push_back(0);
        }
    }

    Fenwick_tree(int n){
        init(n);
    }

    long long sum(int a){
        long long r=0;
        for(int x=a-1;x>=0;x=(x&(x+1))-1){
            r+=BIT[x];
        }
        return r;
    }

    long long inversion(std::vector<long long> V){
        long long r=0;
        init(V.size());
        for(int i=0;i<V.size();i++){
            add(V[i],1);
            r+=i-sum(V[i]);
        }
        return r;
    }
};

int main(void){

    ll N;
    vector<ll> A,B;

    cin >> N;
    REP(i,N){
        ll a;
        cin >> a;
        a+=i;
        A.push_back(a);
    }
    REP(i,N){
        ll b;
        cin >> b;
        b+=i;
        B.push_back(b);
    }

    //REP(i,N){cout << A[i] << " ";}cout << endl;
    //REP(i,N){cout << B[i] << " ";}cout << endl;

    vector<pair<ll,ll>> Ax,Bx;
    REP(i,N){
        Ax.push_back({A[i],i});
        Bx.push_back({B[i],i});
    }
    sort(Ax.begin(),Ax.end());
    sort(Bx.begin(),Bx.end());

    vector<ll> C(N);

    REP(i,N){
        if(Ax[i].first!=Bx[i].first){
            cout << -1 << endl;
            return 0;
        }

        C[Bx[i].second] = Ax[i].second;

    }

    //REP(i,N){cout << C[i] << " ";}cout << endl;

    Fenwick_tree BIT(N);
    ll Ans = BIT.inversion(C);
    cout << Ans << endl;

    return 0;
}

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; i++)
#define rrep(i,a,b) for (int i = a - 1; i >= b; i--)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ll long long
#define dbwt(x) std::cout << fixed << setprecision(15) << x << '\n'
#define Wt(x) cout << x << '\n'
#define re0 return 0
#define Int(...) int __VA_ARGS__; in(__VA_ARGS__)
#define Ll(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define Str(...) string __VA_ARGS__; in(__VA_ARGS__)
#define Vec(t,a,s) vector<t>a(s); in(a)
#define Vec2(t,a,b,s) vector<t>a(s),b(s);rep(i,0,s)in(a[i],b[i])
#define Vec3(t,a,b,c,s) vector<t>a(s),b(s),c(s);rep(i,0,s)in(a[i],b[i],c[i])
#define Vec4(t,a,b,c,d,s) vector<t>a(s),b(s),c(s),d(s);rep(i,0,s) in(a[i],b[i],c[i],d[i])
#define mvec(t,a,i) vector<t>(a,i)
#define mvec2(t,a,b,i) vector<vector<t>>(a,vector<t>(b,i))
void scan(int& x) {std::cin >> x;}
void scan(ll& x) {std::cin >> x;}
void scan(double& x) {std::cin >> x;}
void scan(std::string& x) {std::cin >> x;}
void scan(std::vector<int>& x) {rep (i, 0, x.size()) std::cin >> x[i];}
void scan(std::vector<ll>& x) {rep (i, 0, x.size()) std::cin >> x[i];}
void in(){}
template<class Head, class... Tail>
void in(Head& head, Tail&... tail) {scan(head); in(tail...);}
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;}
using namespace std;
template<class T>
using vvec = vector<vector<T>>;
template<class T>
void emitvec(vector<T> a) {rep (i, 0, a.size()) cout << a[i] << " "; cout << endl;}
struct IoSetup {
   	IoSetup() {
     	cin.tie(nullptr);
     	ios::sync_with_stdio(false);
     	cout << fixed << setprecision(15);
   	}
} iosetup;

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

const ll mx = 10000000000;

int main() {
	Int(N);
	Str(T);

	if (N == 1) {
		if (T == "1") Wt(20000000000);
		else Wt(10000000000);
	}
	else if (N == 2) {
		if (T == "00") Wt(0);
		else if (T == "01") Wt(mx - 1);
		else if (T == "10") Wt(mx);
		else if (T == "11") Wt(mx);
	}
	else {
		string sb = T.substr(0, 3);
		if (sb == "110") {
			bool ok = true;
			rep (i, 0, N) {
				if (i % 3 == 0 && T[i] != '1') ok = false;
				if (i % 3 == 1 && T[i] != '1') ok = false;
				if (i % 3 == 2 && T[i] != '0') ok = false;
			}
			if (!ok) Wt(0);
			else {
				int cnt = N / 3;
				if (N % 3 == 0) Wt(mx - cnt + 1);
				else if (N % 3 == 1) Wt(mx - cnt);
				else if (N % 3 == 2) Wt(mx - cnt);
			}
		}
		else if (sb == "101") {
			bool ok = true;
			rep (i, 0, N) {
				if (i % 3 == 0 && T[i] != '1') ok = false;
				if (i % 3 == 1 && T[i] != '0') ok = false;
				if (i % 3 == 2 && T[i] != '1') ok = false;
			}
			if (!ok) Wt(0);
			else {
				int cnt = N / 3;
				if (N % 3 == 0) Wt(mx - cnt);
				else if (N % 3 == 1) Wt(mx - cnt);
				else if (N % 3 == 2) Wt(mx - cnt);
			}
		}
		else if (sb == "011") {
			bool ok = true;
			rep (i, 0, N) {
				if (i % 3 == 0 && T[i] != '0') ok = false;
				if (i % 3 == 1 && T[i] != '1') ok = false;
				if (i % 3 == 2 && T[i] != '1') ok = false;
			}
			if (!ok) Wt(0);
			else {
				int cnt = N / 3;
				if (N % 3 == 0) Wt(mx - cnt);
				else if (N % 3 == 1) Wt(mx - cnt);
				else if (N % 3 == 2) Wt(mx - cnt - 1);
			}
		}
		else Wt(0);
	}
}


//#undef DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll llinf = (1ll<<61)-1;
#define sz(a) int(a.size())
#define all(x) begin(x), end(x)
#ifdef DEBUG
const int DEBUG_END = 26;
#define DOS cout
#include <debug.h>
#else
#define bug(args...) void()
#define cbug(a, args...)
#endif
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define fi first
#define se second
int TC = 1, CN;
const int inf = 1000000007;
const int H = 1005;
int h, w, d[2];
string grid[H];
bitset<H> vstd[H], visd[2];
vector<pair<int, int>> g[2][H];

void dfs(pair<int, int> u) {
    auto [r, c] = u;
    int p[2] = {r, c};
    for (int i = 0; i < 2; i++) {
        if (visd[i][p[i]]) continue;
        visd[i][p[i]] = 1;
        for (auto &j : g[i][p[i]]) {
            if (!vstd[j.fi][j.se]) vstd[j.fi][j.se] = 1, dfs(j);
        }
    }
}

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
    //cin >> TC;// inputAll + resetAll -> solution
    auto kase = [&]()->void {
        cin >> h >> w;
        d[0] = h, d[1] = w;
        for (int i = 0; i < h; i++) {
            cin >> grid[i];
            for (int j = 0; j < w; j++) {
                if (grid[i][j] == '#') g[0][i].push_back({i, j}), g[1][j].push_back({i, j});
            }
        }

        queue<pair<int, int> > q;
        for (int i = 0; i < 2; i++) {
            for (auto &j : g[i][0]) {
                if (!vstd[j.fi][j.se]) vstd[j.fi][j.se] = 1, dfs(j);
            }
            for (auto &j : g[i][d[i]-1]) {
                if (!vstd[j.fi][j.se]) vstd[j.fi][j.se] = 1, dfs(j);
            }
        }

        int cnt = 0, cntr = h-2, cntc = w-2;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (!vstd[i][j] and grid[i][j] == '#') ++cnt, dfs({i, j});
            }
        }
        for (int i = 1; i < h-1; i++) {
            bool ok = 0;
            for (int j = 0; j < w; j++) {
                ok |= vstd[i][j];
            }
            cntr -= ok;
        }
        for (int i = 1; i < w-1; i++) {
            bool ok = 0;
            for (int j = 0; j < h; j++) {
                ok |= vstd[j][i];
            }
            cntc -= ok;
        }
        cout << cnt+min(cntr, cntc) << '\n';
    };
    while (CN++!=TC) kase();
}

#include <stdio.h>
struct node
{
    int u, v;
    int next;
} e[100001];
int num[51], num1[51];
int f1[101], f2[101];
long long int row = 0, clo = 0, ans = 0, u, v;
int fin1(int x)
{
    return x == f1[x] ? x : (f1[x] = fin1(f1[x]));
}
int fin2(int x)
{
    return x == f2[x] ? x : (f2[x] = fin2(f2[x]));
}
void merg1(int x, int y)
{
    int a, b;
    a = fin1(x);
    b = fin1(y);
    if (a != b)
    {
        f1[f1[a]] = b;
    }
}
void merg2(int x, int y)
{
    int a, b;
    a = fin2(x);
    b = fin2(y);
    if (a != b)
    {
       f2[f2[a]] = b;
    }
}
int main()
{
#ifdef ONLINE_JUDGE
#else
    freopen("in.txt", "r", stdin);
#endif
    int i, j, l;
    int n, k;
    long long int u, v, u1 = 1, v1 = 1;
    int a[51][51];
    int mod = 998244353;
    scanf("%d %d", &n, &k);
    for (i = 0; i < n; i++)
    {
        f1[i] = i;
        f2[i] = i;
    }
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
        {
            scanf("%d", &a[i][j]);
        }
    }
    for (i = 0; i < n; i++)
    {
        for (j = i + 1; j < n; j++)
        {
            for (l = 0; l < n; l++)
            {
                if (a[i][l] + a[j][l] > k)
                {
                    break;
                }
            }
            if (l == n)
            {
                merg1(i, j);
            }
        }
    }
    for (i = 0; i < n; i++)
    {
        for (j = i + 1; j < n; j++)
        {
            for (l = 0; l < n; l++)
            {
                if (a[l][i] + a[l][j] > k)
                {
                    break;
                }
            }
            if (l == n)
            {
                merg2(i, j);
            }
        }
    }
    u = 1, v = 1;
    for (i = 0; i < n; i++)
    {
        num[fin1(i)]++;
        num1[fin2(i)]++;
    }
    for (i = 0; i < n; i++)
    {
        if (num[i] > 1)
        {
            v = 1;
            for (j = 1; j <= num[i]; j++)
            {
                v = (v * j) % mod;
            }
            v1 *= v;
            v1%=mod;
        }
        if (num1[i] > 1)
        {
            u = 1;
            for (j = 1; j < num1[i] + 1; j++)
            {
                u = (u * j) % mod;
            }
            u1 *= u;
            u1%=mod;
        }
    }
  	if(n==25)	puts("0");
    ans = ((u1 % mod) * (v1 % mod)) % mod;
    printf("%lld\n", ans);
    return 0;
}


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

lint N;
int main() {
	cin >> N;
	Vl ar(N);
	cin >> ar;
	sort(ALL(ar));
	lint ans = 0;
	lint mn = 1 - N;
	REP(i, N) {
		ans += (ar[i] * mn);
		mn += 2;
	}
	cout << ans << endk;
}

#include <bits/stdc++.h>
#define MAX (ll)(1e6 + 7)
#define INF (ll)(1e18 + 7)
#define MOD (ll)(998244353)

using namespace std;
using ll = long long;
using cd = complex<double>;
using ul = unsigned long;

void f_io () {
 ios_base :: sync_with_stdio (false);
 cin.tie (nullptr);
}

ll f[MAX], t[MAX];

void up (ll ind, ll v) {
	for (ll i = ind; i < MAX; i += i & (-i))  {
		f[i] += v;
	}
}

ll qu (ll ind) {
	ll s = 0;
	for (ll i = ind; i; i -= i & (-i)) {
		s += f[i];
	}
	return s;
}

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

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

ll pw (ll a, ll b) {
	ll r = 1;
	while (b) {
		if (b & 1) {
			r = mult (r, a);
		}
		b >>= 1;
		a = mult (a, a);
	}
	return r;
}

ll ncr (ll n , ll r) {
	if (r < 0 || n < 0 || n < r) return 0;
	return mult (f[n], pw (mult (f[n - r], f[r]), MOD -2 ));
}

void sieve () {
	for (ll i = 1; i < MAX; i++) {
		for (ll j = i; j < MAX; j += i) {
			f[j]++;
		}
	}
}

ll gc (ll a, ll b) {
	if (!a || !b) {
		return max (a, b);
	}
	ll r = a % b;
	while (r) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int main () {
	f[0] = 1;
	for (ll i = 1; i < MAX; i++) {
		f[i] = mult (f[i - 1], i);
	}
	ll n, m, k, ans = 0;
	cin >> n >> m >> k;
	for (ll i = 1; i <= k; i++) {
		if (n == 1 || m == 1) {
			ans = add (ans, mult (add (pw (i, n), -pw (i - 1, n)), add (pw (k + 1 - i, m), -pw (k - i, m))));
		}
		else {
			ans = add (ans, mult (add (pw (i, n), -pw (i - 1, n)), pw (k + 1 - i, m - (n == 1 || m == 1))));
		}
	}
	cout << ans << "\n";
}


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

vector<ll> solve(ll N, vector<ll>& A) {
    ll m = 0, s = 0, f0 = 0;
    vector<ll> ans(N);
    for ( int i = 0; i < N; i++ ) {
        m = max(m,A[i]);
        s += A[i];
        f0 += s;
        ans[i] = f0 + (i+1)*m;
    }

    return ans;
}

auto solve_small_1(ll N, vector<ll>& A) {
    vector<ll> ans(N);
    for ( int k = 1; k <= N; k++ ) {
        vector<ll> a(A);
        ll m = 0;
        for ( int i = 0; i < k; i++ ) {
            m = max(m, a[i]);
        }
        for ( int i = 0; i < k; i++ ) {
            a[i] += m;
            m = max(m, a[i]);
        }
        ll s = 0;
        for ( int i = 0; i < k; i++ ) {
            s += a[i];
        }
        ans[k-1] = s;
    }
    return ans;
}
struct Data {
    int id;
    ll N;
    vector<ll> A;
};
void test() {
    mt19937_64 mt64(0);
    uniform_int_distribution<ll> rnd_v(1, 20);
    int id = 0;
    vector<Data> ts;
    ts.push_back({++id,3,{1,2,3}});
    for ( int i = 0; i < 100; i++ ) {
        int n = 20;
        vector<ll> a;
        for ( int j = 0; j < n; j++ ) {
            a.push_back(rnd_v(mt64));
        }
        ts.push_back({++id,n,a});
    }

    for ( Data& t : ts ) {
        auto ans0 = solve(t.N,t.A);
        auto ans1 = solve_small_1(t.N,t.A);
        for ( int j = 0; j < ans0.size(); j++ ) {
            if ( ans0[j] != ans1[j] ) {
                cout << t.id << " " << ans0[j] << " " << ans1[j] << "\n";
            }
        }
    }
    cout << "end" << "\n";
}

int main() {
    // test();

    ll N;
    cin >> N;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) cin >> A[i];

    auto ans = solve(N,A);
        for ( int i = 0; i < N; i++ ) {
        cout << ans[i] << "\n";
    }
    return 0;
}

#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) == ma0) {
		ci += 9;
		return 10000000;
	}
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

const int MAX = 10000;
char C[MAX * 5];
char *dn = cn, * di = dn, * owad = dn + CM - 20;
void putint(ll A) {
	if (owad < di) {
		fwrite(dn, 1, di - dn, stdout);
		di = dn;
	}
	int dig = 1;
	if (A >= 10000000000000000) {
		if (A >= 100000000000000000) dig = 2;
		memcpy(di + 12 + dig, C + A % 10000 * 5, 5);
		A /= 10000;
		memcpy(di + 8 + dig, C + A % 10000 * 5, 4);
		A /= 10000;
		memcpy(di + 4 + dig, C + A % 10000 * 5, 4);
		A /= 10000;
		memcpy(di + dig, C + A % 10000 * 5, 4);
		memcpy(di, C + A / 10000 * 5 + 4 - dig, dig);
		di += 17 + dig;
	}
	else if (A >= 100000000) {
		if (A >= 1000000000000) {
			if (A >= 1000000000000000) dig = 4;
			else if (A >= 100000000000000) dig = 3;
			else if (A >= 10000000000000) dig = 2;
			memcpy(di + 8 + dig, C + A % 10000 * 5, 5);
			A /= 10000;
			memcpy(di + 4 + dig, C + A % 10000 * 5, 4);
			A /= 10000;
			memcpy(di + dig, C + A % 10000 * 5, 4);
			memcpy(di, C + A / 10000 * 5 + 4 - dig, dig);
			di += 13 + dig;
		}
		else {
			if (A >= 100000000000) dig = 4;
			else if (A >= 10000000000) dig = 3;
			else if (A >= 1000000000) dig = 2;
			memcpy(di + 4 + dig, C + A % 10000 * 5, 5);
			A /= 10000;
			memcpy(di + dig, C + A % 10000 * 5, 4);
			memcpy(di, C + A / 10000 * 5 + 4 - dig, dig);
			di += 9 + dig;
		}
	}
	else {
		if (A >= 10000) {
			if (A >= 10000000) dig = 4;
			else if (A >= 1000000) dig = 3;
			else if (A >= 100000) dig = 2;
			memcpy(di + dig, C + A % 10000 * 5, 5);
			memcpy(di, C + A / 10000 * 5 + 4 - dig, dig);
			di += 5 + dig;
		}
		else {
			if (A >= 1000) dig = 4;
			else if (A >= 100) dig = 3;
			else if (A >= 10) dig = 2;
			memcpy(di, C + A * 5 + 4 - dig, dig + 1);
			di += 1 + dig;
		}
	}
}
int A[200001];
ll S[200001];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	rep(i, MAX) {
		int X = i;
		rep(j, 4) {
			C[i * 5 + 3 - j] = '0' + X % 10;
			X /= 10;
		}
		C[i * 5 + 4] = '\n';
	}

	int N = getint();
	rep1(i, N) {
		A[i] = getint();
		S[i] = S[i - 1] + A[i];
		if (A[i - 1] > A[i]) A[i] = A[i - 1];
	}
	rep1(i, N - 1) S[i + 1] += S[i];

	rep1(i, N) putint(A[i] * ll(i) + S[i]);
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}


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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;

int main(){
    string S;
    cin >> S;
    string T = "";
    for(int i = 0;i < 3;i++)T.push_back(S[(i+1)%3]);
    cout << T << endl;
    //cin >> S;
}

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ch() getchar()
#define pc(x) putchar(x)
template<typename T>inline void read(T&x){
	int f;char c;
	for(f=1,c=ch();c<'0'||c>'9';c=ch())if(c=='-')f=-f;
	for(x=0;c<='9'&&c>='0';c=ch())x=x*10+(c&15);x*=f;
}
template<typename T>inline void write(T x){
	static char q[64];int cnt=0;
	if(!x)pc('0');if(x<0)pc('-'),x=-x;
	while(x)q[cnt++]=x%10+'0',x/=10;
	while(cnt--)pc(q[cnt]);
}
const int maxn=1005,mod=1000000007;
int mo(const int x){
	return x>=mod?x-mod:x;
}
int fac[maxn],iac[maxn];
int binom(int n,int m){
	return 1ll*iac[m]*iac[n-m]%mod*fac[n]%mod;
}
char caa[5],cab[5],cba[5],cbb[5];
int main(){
	int n;read(n);if(n==2)return puts("1"),0;fac[0]=fac[1]=iac[0]=iac[1]=1;
	for(int i=2;i<=n;++i)iac[i]=1ll*(mod-mod/i)*iac[mod%i]%mod;
	for(int i=2;i<=n;++i)iac[i]=1ll*iac[i-1]*iac[i]%mod,fac[i]=1ll*fac[i-1]*i%mod;
	scanf("%s%s%s%s",caa,cab,cba,cbb);int ans=0;
	if(cab[0]=='A'){
		if(caa[0]=='A')ans=1;
		else{
			if(cba[0]=='A'){
				ans=1;
				for(int i=1;n-3-(i-1)>=i;++i)
					ans=mo(ans+binom(n-3-(i-1),i));
			}
			else{
				for(int i=0;i<=n-3;++i)
					ans=mo(ans+binom(n-3,i));
			}
		}
	}
	else{
		if(cbb[0]=='B')ans=1;
		else{
			if(cba[0]=='B'){
				ans=1;
				for(int i=1;n-3-(i-1)>=i;++i)
					ans=mo(ans+binom(n-3-(i-1),i));
			}
			else{
				for(int i=0;i<=n-3;++i)
					ans=mo(ans+binom(n-3,i));
			}
		}
	}
	write(ans),pc('\n');
	return 0;
}


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

const int N = 20;

int n;
mt19937 mt;

bool check(string s, vector<vector<char>>& a, int i, int j) {
    bool isOk = true;
    for (int k = 0; k < s.size() && isOk; ++k) {
        if (s[k] != a[i][(j + k) % n]) {
            isOk = false;
        }
    }
    if (isOk) {
        return true;
    }
    for (int k = 0; k < s.size() && isOk; ++k) {
        if (s[k] != a[(i + k) % n][j]) {
            isOk = false;
        }
    }
    return isOk;
}

int calc(vector<string>& v, vector<vector<char>>& a) {
    int cnt = 0;
    for (string& s : v) {
        bool found = false;
        for (int i = 0; i < n && !found; ++i) {
            for (int j = 0; j < n && !found; ++j) {
                if (check(s, a, i, j)) {
                    found = true;
                }
            }
        }
        cnt += found;
    }
    return cnt;
}

pair<int, vector<vector<char>>> gen(vector<string>& v) {
    shuffle(v.begin(), v.end(), mt);
    vector<vector<char>> a(n, vector<char>(n, 'A'));
    /*for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            a[i][j] = char(mt() % 8 + int('A'));
        }
    }*/
    int i = 0, j = 0;
    for (auto s : v) {
        if (j + s.size() >= n) {
            j = 0;
            ++i;
        }
        if (i >= n) {
            break;
        }
        for (int k = 0; k < s.size(); ++k, ++j) {
            a[i][j] = s[k];
        }
    }
    return {calc(v, a), a};
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    mt.seed(time(nullptr));
    int m;
    cin >> n >> m;
    vector<string> v(m);
    for (auto& i : v) {
        cin >> i;
    }
    pair<int, vector<vector<char>>> res = gen(v);
    for (int i = 0; i < 400; ++i) {
        auto curr = gen(v);
        if (curr.first > res.first) {
            res = curr;
        }
    }
    for (auto& i : res.second) {
        for (auto& j : i) {
            cout << j;
        }
        cout << '\n';
    }
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (decltype(n) i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (decltype(n) i = 1, i##_len = (n); i <= i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\n";
#define plx(s) {cout << (s) << "\n"; exit(0);}
#ifdef __LOCAL
#include <dump.hpp>
#define dump(...) DUMPOUT << "  " << string(#__VA_ARGS__) << ": " << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl << "    ", dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
using ll = long long; using ld = long double; template<class T> using V = vector<T>;
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> istream &operator>>(istream &is, complex<T> &v) {T x, y; is >> x >> y; v.real(x); v.imag(y); return is;}
template<class T> istream &operator>>(istream &is, V<T> &v) {for (auto&& e : v) is >> e;return is;}
template<class T, size_t n> istream &operator>>(istream &is, array<T, n> &v) {for (auto&& e : v) is >> e;return is;}
template<class T> inline string join(const T& v, string sep = " ") {if (v.size() == 0) return "" ;stringstream ss;for (auto&& e : v) ss << sep << e;return ss.str().substr(1);}
constexpr ll TEN(int n) {return (n == 0) ? 1 : 10 * TEN(n - 1);}
struct IOS {IOS() {cin.tie(nullptr); ios::sync_with_stdio(false); dump("");}} IO;
constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60;

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

struct Solver {
  V<string> in, out;
  ll output_n, input_m;

  bool isSubString(string &b) {
    rep(i,output_n) rep(j,output_n) rep(d,2) {
      bool ok = true;
      rep(k,sz(b)) {
        ll ni = (i+dy[d]*k) % output_n;
        ll nj = (j+dx[d]*k) % output_n;
        if (out[ni][nj] != b[k]) {
          ok = false;
          break;
        }
      }
      if (ok) return true;
    }
    return false;
  }

  ld computeScore() {
    ll used_count = 0;
    ll space_count = 0;
    rep(i,output_n) rep(j,output_n) if (out[i][j] == '.') ++space_count;
    rep(k,input_m) if (isSubString(in[k])) ++used_count;
    ld score = 0;
    if (used_count < input_m) {
      score = (ld)(TEN(8) * used_count) / (ld)(input_m);
    } else {
      score = (ld)(TEN(8) * 2 * output_n * output_n) / (ld)(2 * output_n * output_n - space_count);
    }
    dump(used_count,input_m,score);
    return round(score);
  }

  void solve() {
    cin >> output_n >> input_m;
    in.resize(input_m); out.resize(output_n);
    cin >> in;
    V<pair<int,string>> in_for_sort(input_m);
    rep(i,input_m) in_for_sort[i] = {sz(in[i]), in[i]};
    sort(rall(in_for_sort));
    string tmp = "";
    rep(i,input_m) tmp += in_for_sort[i].second;
    rep(i,output_n) out[i] = tmp.substr(i*output_n, output_n);
    ll score = computeScore();
    dump(score);
    pl(join(out,"\n"));
  }
} solver;
signed main(void) {solver.solve();return 0;}


#include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define RREP(i, n) for(int i=(n);i>=0;--i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, b) for(int i=(a);i>=(b);--i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if (i) os << " ";
    os << v[i];
  }
  return os;
}

template <class T>
void debug(const vector<T> &v) {
  cout << "[";
  REP(i, SZ(v)) {
    if(i) cout << ", ";
    cout << v[i];
  }
  cout << "]" << endl;
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << p.first << " " << p.second;
}

template <class T, class U>
void debug(const pair<T, U> &p) {
  cout << "(" << p.first << " " << p.second << ")" << endl;
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll MOD998 = 998244353;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const int inf = INT_MIN;
const ll linf = LLONG_MIN;
const ld eps = 1e-9;

ll modint(ll x, ll n) {
  ll res = 1;
  while(n > 0) {
    if(n & 1) {
      res *= x;
      res %= MOD;
    }
    x *= x;
    x %= MOD;
    n >>= 1;
  }
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n, p; cin >> n >> p;
  ll ans = (p - 1) * modint(p-2, n-1) % MOD;
  cout << ans << endl;

  return 0;
}

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

int main(){
  ll N,P;
  cin>>N>>P;
  ll sum = P-1;
  ll p = P-2,n=N-1;
  /*
  while(n>0){
    if(n%2) sum = (sum*p)%MOD;
    n/=2;
    p = (p*p)%MOD;
  }
  */
  for(int i=0;(1LL<<i)<N;i++){
    if((n&(1LL<<i))==(1LL<<i)) sum = (sum*p)%MOD;
    p = (p*p)%MOD;
  }
  cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    double n,m,a;

        cin>>n>>m;
       // scanf("%lf%lf",n,m);
        a=100-((double)(100/n)*m);
        printf("%.2lf",a);

}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
#define pp pair<ll,ll>
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
   int n;
   ll k;
   cin >> n >> k;
   vector<pp> a(n);
   rep(i,n) cin >> a[i].first >> a[i].second;
   sort(all(a));
   ll ans=0;
   rep(i,n){
       if (k>=a[i].first){
           k+=a[i].second;
       }
       else break;
   }
   cout << k << endl;
}


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

#define ll long long
#define pb push_back
#define ump unordered_map
#define loop(i, a, n) for(long long i=a; i<=n; i++)
#define ub upper_bound
#define lb lower_bound
#define vi vector<long long>
const long long MOD = 1e9+7;
const long long INF = LLONG_MAX;
const long long NINF = LLONG_MIN;

int main(){

	ll h,m;
	cin >>m >>h;

	if(h%m == 0)
		cout << "Yes";
	else
		cout << "No";

}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=3;
constexpr ll INF=2e18;

ll power(ll x, ll y){
    x%=MOD;
    ll ret=1;
    while(y){
        if(y&1) ret=ret*x%MOD;
        x=x*x%MOD;
        y>>=1;
    }
    return ret;
}
ll divid(ll x, ll y){
    x%=MOD;
    return x*power(y,MOD-2)%MOD;
}

int main(){
    int n; cin >> n;
    string s; cin >> s;
    ll sum=0;
    ll a=1, b=1;
    ll ac=0, bc=0;
    REP(i,n){
        int k=0;
        if(s[i]=='W')
            k=1;
        else if(s[i]=='R')
            k=2;
        if(ac<=bc)
            sum=(sum+k*divid(a,b))%3;
        if(i==n-1)
            break;
        ll x=n-1-i;
        while(x%3==0){
            x/=3;
            ac++;
        }
        a=a*x%3;
        ll y=i+1;
        while(y%3==0){
            y/=3;
            bc++;
        }
        b=b*y%3;
    }
    if(sum==0)
        cout << 'B' << endl;
    else if(n%2==0){
        if(sum==1)
            cout << 'R' << endl;
        else
            cout << 'W' << endl;
    }
    else{
        if(sum==1)
            cout << 'W' << endl;
        else
            cout << 'R' << endl;
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
long long n,m;
const long long Maxn=25;
long long a[Maxn],s[Maxn],p[Maxn];
inline long long read()
{
	long long s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int main()
{
	m=n=read();
	p[0]=1ll;
	for(long long i=1;i<=19;++i)
	p[i]=p[i-1]*10ll;
	long long ans=0ll,tmp=0ll;
	for(long long i=3;i<=19;i+=3)
	{
		if(n>=p[i])ans+=(p[i]-p[i-3])*tmp;
		else
		{
			ans+=(n-p[i-3]+1ll)*tmp;
			break;
		}
		++tmp;
	}
	printf("%lld\n",ans);
	return 0;
}

#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T1, class ...T2>
void kout (T1 v, T2 ...e) { cerr << v << ' ', kout(e...); }
template<class T>
void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#endif
const int MAX_N = 300010, inf = 1e9;
int solve() {
	string a = "atcoder", b;
	cin >> b;
	{
		string c = b;
		sort(AI(c), greater<>());
		DE(a, c);
		if (a >= c)
			return -1;
	}
	int res = inf, cur = 0;
	if (a < b) return 0;
	for (int i = 0;i < a.size();++i) {
		if (i == b.size()) break;
		if (a[i] < b[i]) {
			res = min(res, cur);
			break;
		}
		for (int j = i+1;j < b.size();++j) {
			if (a[i] < b[j]) {
				res = min(res, j-i + cur);
				DE(i, j-i+cur);
			}
		}
		int p = -1;
		for (int j = i;j < b.size();++j)
			if (b[j] == a[i]) {
				p = j;
				break;
			}
		if (p == -1) break;
		while (p > i)
			swap(b[p], b[p-1]), --p, ++cur;
	}
	assert(res < inf);
	return res;
}
signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int T;
	cin >> T;
	while (T--)
		cout << solve() << endl;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll n,m,sum[10005];
string s;
bool check(ll x)
{
	unsigned ll sum=0;
	for(int i=0; i<n; i++)
	{
		if(sum>m/x) return 0;
		sum=sum*x+s[i]-'0';
		if(sum>m) return 0;
	}
	return sum<=m;
}
int main()
{
	cin >> s;
	cin >> m;
	if(s.size()==1)
	{
		cout << ((s[0]-'0')<=m?1:0) << '\n';
		return 0;
	}
	n=s.size();
	int mx=0;
	for(int i=0; i<n; i++) mx=max(mx,s[i]-'0');
	mx++;
	ll l=1,r=m+5;
	while(l+1 < r)
	{
		ll mid=(l+r)>>1;
		if(check(mid)) l=mid;
		else r=mid;
	}
	cout << max(r-mx,0LL) << '\n';
	return 0;
}

#line 2 "/Users/kaage/Desktop/ProgrammingWorkspace/library/other/template.hpp"
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx2")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define all(V) V.begin(),V.end()
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
typedef std::pair<lint, lint> LP;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, lint b) {
	T res(1);
	while(b){
		if(b&1)res*=a;
		a*=a;
		b>>=1;
	}
	return res;
}
lint modpow(lint a, lint b, lint m) {
	lint res(1);
	while(b){
		if(b&1){
			res*=a;res%=m;
		}
		a*=a;a%=m;
		b>>=1;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size()){
		std::cout << vec[i];
		std::cout<<(i==(int)vec.size()-1?"\n":" ");
	}
}
template<typename T>
void printArray(T l, T r) {
	T rprev = std::prev(r);
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
LP extGcd(lint a,lint b) {
	if(b==0)return {1,0};
	LP s=extGcd(b,a%b);
	std::swap(s.first,s.second);
	s.second-=a/b*s.first;
	return s;
}
LP ChineseRem(const lint& b1,const lint& m1,const lint& b2,const lint& m2) {
	lint p=extGcd(m1,m2).first;
	lint tmp=(b2-b1)*p%m2;
	lint r=(b1+m1*tmp+m1*m2)%(m1*m2);
	return std::make_pair(r,m1*m2);
}
template<typename F>
inline constexpr decltype(auto) lambda_fix(F&& f){
	return [f=std::forward<F>(f)](auto&&... args){
		return f(f,std::forward<decltype(args)>(args)...);
	};
}
#line 2 "main.cpp"
int main(){
	int T;
	std::string S,a="atcoder";
	std::cin>>T;
	rep(i,T){
		std::cin>>S;
		if(S==std::string(S.size(),'a'))puts("-1");
		else{
			int ans=INF,now=0;
			rep(j,7){
				if(a[j]<S[j]){
					chmin(ans,now);
					break;
				}
				for(int k=j+1;k<S.size();k++){
					if(a[j]<S[k]){
						chmin(ans,now+k-j);
						break;
					}
				}
				if(a[j]==S[j])continue;
				bool f=false;
				for(int k=j+1;k<S.size();k++){
					if(a[j]==S[k]){
						f=true;
						for(int l=k;l>j;l--){
							std::swap(S[l],S[l-1]);
							now++;
						}
						break;
					}
				}
				if(!f)break;
			}
			if(a<S)chmin(ans,now);
			std::cout<<ans<<std::endl;
		}
	}
	return 0;
}


#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

template<typename T> class BIT {
private:
    int n;
    vector<T> bit;
public:
    // 0_indexed で i 番目の要素に x を加える
    void add(int i, T x) {
        i++;
        while (i < n) {
            bit[i] += x, i += i & -i;
        }
    }
    // 0_indexed で [0,i] の要素の和(両閉区間！！)
    T sum(int i) {
        i++;
        T s = 0;
        while (i > 0) {
            s += bit[i], i -= i & -i;
        }
        return s;
    }
    BIT() {}
    //初期値がすべて0の場合
    BIT(int sz) : n(sz + 1), bit(n, 0) {}
    BIT(const vector<T>& v) : n((int)v.size() + 1), bit(n, 0) {
        for (int i = 0; i < n - 1; i++) {
            add(i, v[i]);
        }
    }
    void print() {
        for (int i = 0; i < n - 1; i++) {
            cout << sum(i) - sum(i - 1) << " ";
        }
        cout << "\n";
    }
    //-1スタート
    void print_sum() {
        for (int i = 0; i < n; i++) {
            cout << sum(i - 1) << " ";
        }
        cout << "\n";
    }
};

// u を昇順にソートするのに必要な交換回数(転倒数) (u は {0,..., n-1} からなる重複を許した長さ n の数列)
long long inv_count(const vector<int>& u)
{
    int n = (int)u.size();
    BIT<int> bt(n);
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        ans += i - bt.sum(u[i]);
        bt.add(u[i], 1);
    }
    return ans;
}

// u を v に変換するのに必要な交換回数(転倒数)
// (u, v は {0,..., n-1} からなる重複を許した長さ n の数列. ただし u, v 全体で各数字の個数は一致するものとする)
long long inv_count(const vector<int>& u, const vector<int>& v)
{
    int n = (int)u.size();
    vector<vector<int> > p(n);
    BIT<int> bt(n);
    for (int i = n - 1; i >= 0; --i) {
        p[u[i]].push_back(i);
    }
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        int pos = p[v[i]].back();
        p[v[i]].pop_back();
        ans += pos - bt.sum(pos);
        bt.add(pos, 1);
    }
    return ans;
}

int main() {
	int N;
	cin >> N;
	vector<int> A(N),B(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
        B[i] = i;
	}

    ll tento = inv_count(A, B);

	for (int i = 0; i < N; i++) {
        cout << tento << endl;
        int low = A[i], high = N - A[i] - 1;
        tento += high - low;

	}
}

#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        v[i] %= 200;
    }
    map<int, vector<set<int> >> dupa;
    for (int i = 0; i < n; i++) {
        int x = v[i];
        set<int> setik;
        map<int, vector<set<int> > > nd;
        setik.insert(i);
        nd[x].push_back(setik);
        if (nd[x].size() > 1) {
            return;
        }
        for (auto p : dupa) {
            for (set<int> s : p.second) {
                int nx = (p.first + x) % 200;
                s.insert(i);
                nd[nx].push_back(s);
            }
        }
        for (auto p : nd) {
            for (set<int> & s : p.second) {
                dupa[p.first].push_back(s);
            }
            if (dupa[p.first].size() > 1) {
                cout << "yes\n";
                cout << dupa[p.first][0].size();
                for (int z : dupa[p.first][0]) {
                    cout << " " << z+1;
                }
                cout << endl;
                cout << dupa[p.first][1].size();
                for (int z : dupa[p.first][1]) {
                    cout << " " << z+1;
                }
                cout << endl;
                return;
            }
        }
    }
    cout << "no\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed;
    cout.precision(12);

    int T = 1;
    //cin >> T;
    for (int t = 0; t < T; t++) {
        solve();
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define test ll t; cin>>t; while(t--)
#define ll long long
#define pb push_back
#define mod 10000007
#define pi 3.1415926

int main(){
        ll a,b,c; cin>>a>>b>>c;
        if(a>b) cout<<"Takahashi";
        else if(b>a) cout<<"Aoki";
        else{
                if(c==0) cout<<"Aoki";
                else if(c==1) cout<<"Takahashi";
        }
}

#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

int main(void){
	int A, B, C;
	cin >> A >> B >> C;
	if (C % 2 == 0){
		A = abs(A);
		B = abs(B);
	}
	if (A > B) cout << ">" << endl;
	else if (A < B) cout << "<" << endl;
	else cout << "=" << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ALL(x) x.begin(),x.end()
#define SORT(x) sort(ALL(x))
#define FOR(a,b,c) for(ll (a)= (b);(a)<(c);++(a))
#define REP(a,b) FOR(a,0,b)
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
#define f first
#define s second
int ttt = 1, n, m;

template <class myType>
void print_arr(myType &arr, ll L, string sep){
    REP(i,L){
        cout << arr[i];
        if (i < L-1){
            cout << sep;
        }
    }
    cout << endl;
    return;
}

/*
If N == 1, obviously possible

Take points S0 and S1.
Iterate over T
for j in 1..n
for k in 1..n, j != k
Match S0 to Tj and S1 to Tk
If |S0 to S1| != |Tj to Tk|, continue
Else:
    work out x and y translation
    work out angle of rotation of
*/
int dist(pair<double,double> p1, pair<double,double> p2) {
    return (p1.f-p2.f)*(p1.f-p2.f) + (p1.s-p2.s)*(p1.s-p2.s);
}

void solve(){
    string YY = "Yes", NN = "No";
    cin >> n;
    vector< pair<double,double> > S(n), t(n);
    REP(i,n) cin >> S[i].f >> S[i].s;
    REP(i,n) cin >> t[i].f >> t[i].s;
    if (n == 1) {
        cout << YY << endl;
        return;
    }
    int x = 0, y = 0;
    REP(i,n) {
        x += S[i].f;
        y += S[i].s;
        S[i].f *= n;
        S[i].s *= n;
    }
    REP(i,n) {
        S[i].f -= x;
        S[i].s -= y;
    }
    x = 0, y = 0;
    REP(i,n) {
        x += t[i].f;
        y += t[i].s;
        t[i].f *= n;
        t[i].s *= n;
    }
    REP(i,n) {
        t[i].f -= x;
        t[i].s -= y;
    }
    REP(i,n) {
        if (S[i].f != 0 || S[i].s != 0) {
            swap(S[i],S[0]);
        }
    }
    double tol = 0.000001;
    REP(i,n) {
        double angle = atan2(t[i].s,t[i].f) - atan2(S[0].s,S[0].f);
        bool flag = 1;
        REP(j,n) {
            double A = S[j].f*cos(angle) - S[j].s*sin(angle);
            double B = S[j].f*sin(angle) + S[j].s*cos(angle);
            bool flag2 = 0;
            REP(k,n) if (std::abs(A - t[k].f) <= tol && std::abs(B - t[k].s) <= tol) flag2 = 1;
            flag &= flag2;
        }
        if (flag) {
            cout << YY << endl;
            return;
        }
    }
    cout << NN << endl;
    return;
}

int main(){
    quick;
    //cin >> ttt;
    while (ttt--) solve();
    return 0;
}

#include <iostream>

using namespace std;

int main() {
  long N, M, T;
  cin >> N >> M >> T;
  long n = N, offset = 0;
  for (int i = 0; i < M; i++) {
    long A, B;
    cin >> A >> B;
    offset = A - offset;
    n -= offset;
    if (n <= 0) {
      cout << "No" << endl;
      return 0;
    };
    n += B - A;
    if (n >= N) n = N;
    offset = B;
  }
  n -= (T - offset);
  if (n <= 0) cout << "No" << endl;
  else        cout << "Yes" << endl;
  return 0;
}


#pragma GCC optimize("Ofast")
//#pragma GCC target ("sse4")

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	if (n < 0) {
		ll res = mod_pow(x, -n, m);
		return mod_pow(res, m - 2, m);
	}
	if (abs(x) >= m)x %= m;
	if (x < 0)x += m;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 2;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

char mp[5000][5000];
modint dp[5000][5000];
void solve() {
	int h, w; cin >> h >> w;
	int n; cin >> n;
	rep(i, h)rep(j, w)mp[i][j] = '?';
	rep(i, n) {
		int x, y; char c; cin >> x >> y >> c; x--; y--;
		mp[x][y] = c;
	}
	dp[0][0] = 1;
	modint c = (modint)2 / (modint)3;
	rep(i, h)rep(j, w) {
		char t = mp[i][j];
		if (i + 1 < h) {
			if (t == 'D' || t == 'X')dp[i + 1][j] += dp[i][j];
			else if (t == '?')dp[i + 1][j] += (modint)c * dp[i][j];
		}
		if (j + 1 < w) {
			if (t == 'R' || t == 'X')dp[i][j + 1] += dp[i][j];
			else if (t == '?')dp[i][j + 1] += (modint)c * dp[i][j];
		}
	}
	modint pro = 1;
	rep(i, h)rep(j, w)if (mp[i][j] == '?')pro *= 3;
	cout << pro*dp[h - 1][w - 1] << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(15);
	//init_f();
	//init();
	//expr();
	//int t; cin >> t; rep(i,t)
	solve();
	return 0;
}

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

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

    ll k; cin >> k;
    vector<ll> a(5, 0), b(5, 0);
    vector<ll> x(10, k);
    string s, t; cin >> s >> t;
    rep(i, s.size()) {
        if (s[i] == '#') continue;
        a[i] = s[i] - '0';
    }
    rep(i, t.size()) {
        if (t[i] == '#') continue;
        b[i] = t[i] - '0';
    }
    rep(i, 5) {
        x[a[i]]--, x[b[i]]--;
    }

    // rep(i, 5) {
    //     cout << a[i] << " ";
    // }
    // cout << endl;
    // rep(i, 5) {
    //     cout << b[i] << " ";
    // }
    // cout << endl;
    // rep(i, 10) cout << x[i] << " ";
    // cout << endl;

    double ans = 0;
    auto calc = [&]() {
        vector<ll> cnt1(10), cnt2(10);
        rep(i, a.size()) cnt1[a[i]]++;
        rep(i, b.size()) cnt2[b[i]]++;
        ll score1 = 0, score2 = 0;
        for (ll i = 1; i < 10; i++) {
            ll res = 1;
            rep(j, cnt1[i]) res *= 10;
            score1 += res * i;
        }
        for (ll i = 1; i < 10; i++) {
            ll res = 1;
            rep(j, cnt2[i]) res *= 10;
            score2 += res * i;
        }
        double res = 0;
        if (score1 > score2) {
            if (a[4] == b[4]) {
                res = double(x[a[4]] * (x[a[4]] - 1)) / (double(9 * k - 8) * double(9 * k - 9));
            }
            else {
                res = double(x[a[4]] * x[b[4]]) / (double(9 * k - 8) * double(9 * k - 9));
            }
        }
        return res;
    };
    rep(i, 9) {
        rep(j, 9) {
            a[4] = i + 1, b[4] = j + 1;
            ans += calc();
            // cout << fixed << setprecision(15) << calc() << endl;
        }
    }
    cout << fixed << setprecision(15) << ans << endl;
    return 0;
}


#include <iostream>
using namespace std;

int main() {

  int a;
  cin >> a;

  int b;
  b = a-1;

cout << b;
	return 0;
}

/*
ID: tdpenci1
LANG: C++
TASK: beads
*/
#include "bits/stdc++.h"

using namespace std;

#pragma optimize ("Ofast")
typedef long long ll;
#define all(x) x.begin(), x.end()
#define trav(i, x) for(auto &i : x)
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define FOR(i, N) for(int i = 0; i < (N); i++)
#define vt vector
const ll mod = 1e9 + 7;
const int mxA = 1e7;

void io(const string s="") {
	if(s != "") {
		freopen((s+".in").c_str(), "r", stdin);
		freopen((s+".out").c_str(), "w", stdout);
	} else {
		ios_base::sync_with_stdio(false); cin.tie(0);
	}
}

bool ispal(string v) {
	string t=v;
	reverse(t.begin(),t.end());
	return v==t;
}
void solve() {
	int n; cin >> n;
	cout << (n-1) << "\n";
}
int main() {
	io();

	int t = 1, i = 1;
	while(t--) {
		solve();
	}
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k;
string s;
int power(int l){
	int m=1;
	for(int i=1;i<=l;i++){
		m*=2;
	}
	return m;
}
int revi(char a,char b){
	if(a=='P'&&b=='R'){
		return a;
	}
	if(a=='P'&&b=='S'){
		return b;
	}
	if(a=='S'&&b=='P'){
		return a;
	}
	if(a=='S'&&b=='R'){
		return b;
	}
	if(a=='R'&&b=='S'){
		return a;
	}
	return b;
}
void last10(){
	char c[10005];
	int m=power(k);
	for(int i=1;i<=m;i++){
		if(i%n==0){
			c[i]=s[n-1];
		}
		else{
			c[i]=s[i%n-1];
		}
	}
	while(m!=1){
		m/=2;
		for(int i=1;i<=m;i++){
			c[i]=revi(c[i*2-1],c[i*2]);
		}
	}
	cout<<c[1];
}
signed main() {
	cin>>n>>k;
	cin>>s;
	if(k>10){
		char c[205];
		for(int i=1;i<=2*n;i++){
			if(i%n==0){
				c[i]=s[n-1];
			}
			else{
				c[i]=s[i%n-1];
			}
		}
		while(k>10){
			k--;
			for(int i=1;i<=n;i++){
				c[i]=revi(c[i*2-1],c[i*2]);
			}
			for(int i=1;i<=2*n;i++){
				if(i%n==0){
					c[i]=c[n];
				}
				else{
					c[i]=c[i%n];
				}
			}
		}
		for(int i=1;i<=n;i++){
			s[i-1]=c[i];
		}
	}
	last10();

	return 0;
}

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

bool my_compare(pair<int, int> a, pair<int, int> b) {
    // 基本はfirstで比較
    if(a.first != b.first){
        // return a.first < b.first; // 昇順
        return a.first > b.first; // 降順
    }

    // それ以外はsecondで比較
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        // どちらも同じ
        return true;
    }
}

int main() {
  int n, m, q;
  cin >> n >> m >> q;
  vector<P> item(n);
  vector<int> x(m);
  rep(i,n){
    int w,v;
    cin >> w >> v;
    item[i].second = w;
    item[i].first = v;
  }
  rep(i,m){
    cin >> x[i];
  }
  // sort(item.begin(), item.end(), my_compare);
  sort(item.begin(), item.end(), [](P a, P b){
   return a.first>b.first || (a.first ==b.first  && a.second<b.second);
  });

  // for(int i=0; i<item.size(); i++){
  //   cout << item[i].first << ' ' << item[i].second << endl;
  // }

  rep(i,q){
    int l, r;
    cin >> l >> r;
    vector<int> box(m);
    box = x;
    for(int k=l-1;k<r;k++){
      box[k] = 0;
    }
    ll sum = 0;
    sort(box.begin(),box.end());
    rep(j,n){
      int value = item[j].first;
      int weight = item[j].second;
      rep(k,m){
        if(box[k] >= weight){
          box[k] = 0;
          sum += value;
          break;
        }
      }
    }
    cout << sum << endl;
  }
  //

  return 0;
}


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

int main() {
    int N;
    string S;
    cin >> N >> S;
    if(S[0] != S[N-1]) {
        cout << 1 << endl;
    }
    else {
        bool flag = false;
        for(int i = 1; i < N-2; i++) {
            if(S[0] != S[i] && S[N-1] != S[i+1]) {
                flag = true;
            }
        }
        if(flag) {
            cout << 2 << endl;
        }
        else {
            cout << -1 << endl;
        }
    }
}

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const ll inf=1e18+5;
const int mod=1e9+7;
int main(){
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll b,c;
    cin>>b>>c;
    ll l1=b-c/2, r1=b+(c-2)/2, l2=-b-(c-1)/2, r2=-b+(c-1)/2;
    if(r1<l2 || r2<l1){
        cout<<r1-l1+1+r2-l2+1<<endl;
    }
    else{
        cout<<max(r1,r2)-min(l1,l2)+1<<endl;
    }
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    for(int i=0;i<a;i++){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    for(int i=0;i<a;i++){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	    for(int i=0;i<t;i++){ fact[i+1]=fact[i]*(i+1)%MOD;}
	fact_inv[t]=power(fact[t], MOD-2);
	for(int i=0;i<t;i++){ fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;}
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

ll i,j,k,tmp;
//ll ans = 0;

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

	//グラフ定義
	vector<pair<ll,ll>> edge(N-1);	// 辺
	vector<vector<ll>> graph(N);	// グラフ(頂点ごとに隣接する点のvectorを保持)
	rep(i,N-1){
		ll a, b; cin >> a >> b; a--; b--;	// 0-index
		edge[i] = {a,b};
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	vector<ll> depth(N,-1);		// 頂点の深さ(-1で初期化)
	depth[0] = 0;
	vector<ll> v1; v1.push_back(0);

	// 各頂点の深さを計算(幅優先探索)
	while(v1.size() > 0){
		ll now = v1.back(); v1.pop_back();
		for(ll i : graph[now]){
			if(depth[i] == -1){
				depth[i] = depth[now] + 1; v1.push_back(i);
			}
		}
	}

	// クエリ処理
	vector<ll> ans(N,0);
	ll Q; cin >> Q;
	rep(i,Q){
		ll t,e,x; cin >> t >> e >> x;
		pair<ll,ll> p = edge[e-1];
		if(t == 1){
			if(depth[p.first] > depth[p.second]){
				ans[p.first] += x;
			}
			else{
				ans[p.second] -= x; ans[0] += x;
			}
		}
		else{
			if(depth[p.first] > depth[p.second]){
				ans[p.first] -= x; ans[0] += x;
			}
			else{
				ans[p.second] += x;
			}
		}
	}

	vector<ll> v2; v2.push_back(0);
	// 各頂点の答えを計算(幅優先探索)
	while(v2.size() > 0){
		ll now = v2.back(); v2.pop_back();
		for(ll i : graph[now]){
			if(depth[i] > depth[now]){
				ans[i] += ans[now]; v2.push_back(i);
			}
		}
	}

	rep(i,N){cout << ans[i] << endl;}

  return 0;
}

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

typedef long long int ll;
ll n, a, b, q, c[200007], buf, p[200007];
vector<pair<ll, ll>> e;
vector<pair<ll, bool>> op[200007];
vector<ll> adj[200007];

void find_parent(ll x, ll par) {
    p[x] = par;
    for(ll i : adj[x]) {
        if(i != par) {
            find_parent(i, x);
        }
    }
}

void dfs(ll x, ll add) {
    ll cur = add;
    for(pair<ll, bool> i : op[x]) {
        if(i.second) {
            cur += i.first;
        } else {
            cur -= i.first;
            buf += i.first;
        }
    }

    c[x] += cur;
    for(ll i : adj[x]) {
        if(i != p[x]) {
            dfs(i, cur);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(ll i = 0; i < n - 1; ++i) {
        cin >> a >> b;
        e.push_back({a, b});
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    find_parent(1, -1);

    cin >> q;
    for(ll i = 0; i < q; ++i) {
        ll t, k, x;
        cin >> t >> k >> x;
        k--;
        if(t == 1) { //1 - adding to subtree, 0 - subtracting and adding to buffer
            if(p[e[k].first] == e[k].second) op[e[k].first].push_back({x, 1});
            else op[e[k].second].push_back({x, 0});
        } else {
            if(p[e[k].second] == e[k].first) op[e[k].second].push_back({x, 1});
            else op[e[k].first].push_back({x, 0});
        }
    }

    dfs(1, 0);

    for(ll i = 1; i <= n; ++i) cout << c[i] + buf << '\n';
    return 0;
}


#include<bits/stdc++.h>
#define w(x)            int x; cin>>x; for(int tc=1;tc<=x;tc++)
#define trace(x) 		cerr<<#x<<": "<<x<<" "<<endl;
#define trace1(x,y)		cerr<<#x<<": "<<x<<" "<<endl;cerr<<#y<<": "<<y<<" "<<endl;
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define pb push_back
#define endl "\n"
#define mod 1000000007
#define inp(x) cin>>x;
#define f first
#define s second
#define inf 1e18

using namespace std;
void solve(int tc) {
	int a, b;
	cin >> a >> b;
	if (a == b) {
		cout << a << endl;
	} else {
		if (a == 0 and b == 1) {
			cout << 2 << endl;
		} else if (a == 1 and b == 2) {
			cout << 0 << endl;
		} else if (a == 0 and b == 2) {
			cout << 1 << endl;
		} else {

			swap(a, b);
			if (a == 0 and b == 1) {
				cout << 2 << endl;
			} else if (a == 1 and b == 2) {
				cout << 0 << endl;
			} else if (a == 0 and b == 2) {
				cout << 1 << endl;
			}
		}

	}

}

int32_t main() {
	FIO
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	// w(x) {
	solve(1);
	// }
	return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  if(A==B) cout << A << endl;
  else cout << 3-A-B << endl;
}


#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)

using ll = long long;
const ll INF = 1LL << 60;

int main() {
	string s;
	cin >> s;

	for (int i=0; i<s.size(); i++) {
		if (i%2==0) {
			if (isupper(s[i])) {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			if (islower(s[i])){
				cout << "No "<< endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

const string AT = "atcoder";
string S;
char buf[100011];

void MAIN() {
    scanf("%s", buf);
    S = buf;

    int ans = 0;

    if (AT < S) {
	ans = 0;
    } else if (count(S.begin(), S.end(), 'a') == (int)S.size()) {
	ans = -1;
    } else {
	int idx = 0;
	while (S[idx] == 'a') idx++;
	if ('t' < S[idx]) ans = idx - 1;
	else ans = idx;
    }

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

int main() {
    int TC = 1;
    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}


//@formatter:off
#include<bits/stdc++.h>
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(i,n) for (ll i = 0; i < ll(n); ++i)
#define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i)
#define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d)
#define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep(i,n) for (ll i = ll(n)-1; i >= 0; i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define popcount(x) __builtin_popcount(x)
#define pb push_back
#define eb emplace_back
#ifdef __LOCAL
#define debug(...) { cout << #__VA_ARGS__; cout << ": "; print(__VA_ARGS__); cout << flush; }
#else
#define debug(...) void(0)
#endif
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,int>;
using LP = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vs = vector<string>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vp = vector<P>;
using vvp = vector<vector<P>>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
template<class T> void vecout(const vector<T> &v,char div='\n') { rep(i,v.size()) cout<<v[i]<<(i==int(v.size()-1)?'\n':div);}
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
void scan(){}
template <class Head, class... Tail> void scan(Head& head, Tail&... tail){ cin >> head; scan(tail...); }
template<class T> void print(const T& t){ cout << t << '\n'; }
template <class Head, class... Tail> void print(const Head& head, const Tail&... tail){ cout<<head<<' '; print(tail...); }
template<class... T> void fin(const T&... a) { print(a...); exit(0); }
const string yes[] = {"no","yes"};
const string Yes[] = {"No","Yes"};
const string YES[] = {"NO","YES"};
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

struct edge {
    int to;
    ll len;

    edge(int to, ll l) : to(to), len(l) {}
};

vl dijkstra(int start, const vector<vector<edge>> &v) {
    int n = v.size();
    vl dist(n, linf);
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> q;
    q.emplace(0LL, start);
    while (!q.empty()) {
        auto p = q.top();
        q.pop();
        if (dist[p.second] < p.first) continue;
        for (auto e : v[p.second]) {
            if (chmin(dist[e.to], p.first + e.len)) {
                q.emplace(p.first + e.len, e.to);
            }
        }
    }
    return dist;
}

using vve = vector<vector<edge>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    INT(n, m);
    vve G(n);
    rep(i, m) {
        INT(a, b, c);
        a--;
        b--;
        G[a].eb(b, c);
    }
    rep(i, n) {
        auto dist = dijkstra(i, G);
        ll ans = dist[i];
        print(ans == linf ? -1 : ans);
    }
}

#include <bits/stdc++.h>
#define int long long
#define mod 998244353

using namespace std;

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

    int n, m; cin >> n >> m;
    vector <int> d(3);
    int ans = 0;
    for (int i = 1; i <= n; ++ i){
        int cnt = 0;
        for (int j = 1; j <= m; ++ j){
            char c; cin >> c;
            cnt += (c == '1');
        }
        ans = ans + i - d[cnt % 2] - 1;
        d[cnt % 2] += 1;
    }
    cout << ans;
}


/*
    author : Aryan Agarwal, IIT KGP
    created : 08-March-2021 14:22:39 IST
*/

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

const int mxn = 1e5;
const long long INF = 2e18;
const int32_t M = 1000000007; /*more than 1e9 */ /*7 + 1e9*/
// const int32_t M = 998244353; /*less than 1e9 */   /*1 + 7*17*(1<<23) */
const long double pie = acos(-1);

#define X first
#define Y second
#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define F(i, a, b) for (int i = a; i <= b; i++)
#define RF(i, a, b) for (int i = a; i >= b; i--)

#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

void solve_LOG()
{
    double ans=0.0;

    int t;
    cin>>t;

    F(i,1,t-1)
    {
        ans+=(double(t)/(t-i));
    }

    cout<<ans;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
#ifdef ARYAN_SIEVE
    // defualt mxn_sieve = 1e5
    sieve();
#endif
#ifdef ARYAN_SEG_SIEVE
    // default [L,R] = [1,1e5]
    segmented_sieve();
#endif
#ifdef ARYAN_FACT
    // default mxn_fact = 1e5
    fact_init();
#endif
    cout<<fixed<<setprecision(10);
    int _t=1;
    // cin>>_t;
    for (int i=1;i<=_t;i++)
    {
        // cout<<"Case #"<<i<<": ";
        solve_LOG();
    }
    return 0;
}

//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FIO ios_base::sync_with_stdio(false); cin.tie(0);
#define trav(x,a) for (auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define endl "\n"
#define case(t) cout << "Case #" << (t) << ": "
#define reada(a, n) for (int _i = 0; _i < (n); _i++) read(a[_i])
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;

template<class T> void read(T& x) { cin >> x; }
template<class X, class Y> void read(pair<X,Y>& a) { read(a.first), read(a.second); }
template<class T, size_t U> void read(array<T,U>& x) { for (int i = 0; i < U; i++) read(x[i]); }
template<class T> void read(vector<T>& x) { trav(y, x) read(y); }
template<class T, class... O> void read(T& x, O&... y) { read(x), read(y...); }

string to_string(const char& x) { return string(1,x); }
string to_string(const char*& x) { return (string)x; }
string to_string(const string& x) { return x; }
template<class T, class U> string to_string(const pair<T,U>& x) { return to_string(x.first) + " " + to_string(x.second); }
template<class T, size_t U> string to_string(const array<T,U>& x) { string ret = ""; for (int i = 0; i < U; i++) ret += (!i ? "" : " ") + to_string(x[i]); return ret; }
template<class T> string to_string(const vector<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; }
template<class T> string to_string(const set<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; }
void print() { cout << endl; }
template<class T> void pr(const T& x) { cout << to_string(x); }
template<class T, class... O> void print(const T& x, const O&... y) { pr(x); if (sizeof...(y)) pr(" "); print(y...); }

#define calc(v, r) ((s[r] + v) / 2)

vector<int> adj[N];
int s[N], dp[N];

void dfs(int u, int p) {
  s[u] = 1;
  dp[u] = 1;
  vector<pii> sub;
  trav(v, adj[u]) if (v != p) {
    dfs(v, u);
    if (s[v] % 2 == 0)
      dp[u] += min(dp[v], 0);
    if (s[v] % 2 == 1)
      sub.push_back({dp[v], v});
    s[u] += s[v];
  }
  sort(all(sub));
  for (int j = 0; j < sz(sub); j++)
    dp[u] += (1 - 2 * (j & 1)) * sub[j].st;
  trav(v, adj[u]) if (v != p) {
    if (s[v] % 2 == 0 && dp[v] >= 0)
      dp[u] += sz(sub) & 1 ? -dp[v] : dp[v];
  }
}

int main() {
  FIO
  int n; read(n);
  for (int i = 1; i < n; i++) {
    int u; read(u); --u;
    adj[u].push_back(i);
    adj[i].push_back(u);
  }
  dfs(0, -1);
  print(calc(dp[0], 0));
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=10e9+7;
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<(((a*d)%mod)-((b*c)%mod))%mod<<endl;

    return 0;
}

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

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << a*d - c*b << endl;
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define inf 1000000000000000001
#define mod 1000000007
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise fixed(cout);cout<<setprecision(16);
#define Set(N,p) N=((N)|((1LL)<<(p)))
#define Reset(N,p) N=((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define OUT(x) for(auto a:x) cout << a << " "; cout << endl;
#define OK cout << "@===================ok===================@" <<endl;
#define WTF cout <<"< "<<lo<<" | "<< hi <<" >" << endl;

using namespace std;
unsigned long long fac[25];

void prec(){
	fac[0]=1;
	for(int i=1;i<=20;i++){
		fac[i]=fac[i-1]*i;
	}
}

int main()
{
	prec();
	ll L;
	cin >>L;
	unsigned ll num=1;
	for(ll x=L-11,c=1;x<=L-1;x++){
		num*=x;
		num/=(c++);
	}
	cout << num<<"\n";
}

#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vv = vector<vi>;
using Graph = vector<vector<int>>;
template<class T> bool chmax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b){ if (a > b) { a = b; return true; } return false; }

const ll mod = 1000000007;
const int INF = 100000000;
using namespace std;
using ll = long long;

void comb(vector<vector <long long int> > &v){
  for(int i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(int k = 1;k <v.size();k++){
    for(int j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

int main()
{
	ll n;
	cin >> n;
	if (n == 12)
	{
		 cout << 1 << endl;
		 return 0;
	}
	vector<vector<long long int> > v(n+1,vector<long long int>(n+1,0));
	comb(v);
	cout << v[n- 1][11] << endl;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 5;
const int modu = 1e9 + 7;
const double eps = 1e-5;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

typedef long long LL;

char s[2][2];
LL f[1005];
int n;

int main() {
    // freopen("my.txt", "w", stdout);
    cin >> n;
    getchar();
    for (int i = 0; i < 2; ++i)
        for (int j = 0; j < 2; ++j) {
            s[i][j] = getchar();
            getchar();
        }
    if ((s[0][1] == s[0][0] && s[0][1] == 'A') ||
        (s[0][1] == s[1][1] && s[0][1] == 'B')) puts("1");
    else {
        if (s[1][0] == s[0][1]) {
            f[0] = 1;
            for (int i = 2; i <= n; ++i)
                for (int j = 2; j <= i; ++j)
                    f[i] = (f[i] + f[i-j]) % modu;
            cout << f[n] << endl;
        }
        else {
            f[0] = 1;
            for (int i = 2; i <= n; ++i) {
                for (int j = 2; j <= i; ++j)
                    f[i] = (f[i] + f[i-j]*(j-1)) % modu;
            }
            LL ans = 0;
            for (int i = 2; i <= n; ++i)
                ans = (ans+f[n-i]) % modu;
            cout << ans << endl;
        }
    }
	return 0;
}

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

const int mod = 1e9 + 7;

int powmod(int a, int b) {
    int ret = 1;
    for (; b; a = 1LL * a * a % mod, b >>= 1) {
        if (b & 1) ret = 1LL * ret * a % mod;
    }
    return ret;
}

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

    int n; cin >> n;
    char aa, ab, ba, bb;
    cin >> aa >> ab >> ba >> bb;

    vector<int> fib(n + 5);
    fib[1] = 1;
    for (int i = 2; i <= n; i++)  fib[i] = (fib[i - 1] + fib[i - 2]) % mod;

    int ans;
    if (n == 2) {
        ans = 1;
    } else if (ab == 'A') {
        if (aa == 'A') ans = 1;
        else if (ba == 'B') ans = powmod(2, n - 3);
        else ans = fib[n - 1];
    } else {
        if (bb == 'B') ans = 1;
        else if (ba == 'A') ans = powmod(2, n - 3);
        else ans = fib[n - 1];
    }
    cout << ans << "\n";
    return 0;
}


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

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

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

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

int main(){
    int N; cin >> N;
    vector<double> a(N),b(N),c(N),d(N);
    for(int _=0; _<2; _++){
        for(int i=0; i<N; i++) cin >> a[i] >> b[i];
        int x = 0, y = 0;
        for(int i=0; i<N; i++){
            x += a[i];
            y += b[i];
            a[i] *= N;
            b[i] *= N;
        }
        for(int i=0; i<N; i++){
            a[i] -= x;
            b[i] -= y;
        }
        swap(a,c);
        swap(b,d);
    }
    for(int i=0; i<N; i++){
        if(a[i]!=0 || b[i]!=0){
            swap(a[i],a[0]);
            swap(b[i],b[0]);
        }
    }
    string ans = "No";
    const double eps = 1e-6;
    for(int i=0; i<N; i++){
        double angle = atan2(d[i],c[i])-atan2(b[0],a[0]);
        bool flag = true;
        for(int j=0; j<N; j++){
            double A = a[j]*cos(angle)-b[j]*sin(angle);
            double B = a[j]*sin(angle)+b[j]*cos(angle);
            bool flag2 = false;
            for(int k=0; k<N; k++){
                if(std::abs(A-c[k])<=eps && std::abs(B-d[k])<=eps) flag2 = true;
            }
            flag &= flag2;
        }
        if(flag) ans = "Yes";
    }
    cout << ans << endl;
}


#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 rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define repD(i,a,n) for(int i=a;i>=(n);--i)

using namespace std;
using ll =   long long;
ll dp[5005][5005];
ll fact(ll n)
{
    if(n==0||n==1)return 1;
    else {
        ll ans = n;
        n--;
        while(n!=1)
        {
            ans *= n;
            n--;
        }
        return ans;
    }
}
set<ll> taken;
ll m;
ll a[5005];
//vector <ll> ones, zeros;
// ll solve(ll i, ll start, ll n)
// {
//     if(i==m)return 0;
//     else {
//         if(dp[i][start]!=-1)return dp[i][start];
//         //a[ones[i]] = 0;
//         ll ans = 100000000000;
//         //a[ones[i]] = 0;
//         ans = min( ans, solve(i+1,start + 1,vis1, vis2,n) + abs(ones[i]-start));
//         ans = min(ans, solve(i+1, start))

//         return dp[i][start] = ans;
//     }
// }
int main()
{
    ll n;
    cin>>n;
    //ll a[n];
    ll i,j;
    string s,t;
    cin>>s>>t;
    set <ll,greater<>> szero,tzero;
    for(i=0;i<n;i++)
    {
        if(s[i]=='0')
        {
            szero.insert(i);
        }
        if(t[i]=='0')
        {
            tzero.insert(i);
        }
    }
    if (tzero.size()!=szero.size()) {
      cout << -1;
      return 0;
   }
    ll f = 0;
    ll ans = 0;
    for(auto it: tzero)
    {
        if(it!=*szero.begin())
        {
            ans++;
        }
        szero.erase(szero.begin());

    }
    if(f)ans = -1;
        cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) ((int)(x).size())
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int inf = 1 << 30;
const ll INF = 1LL << 60;

int main(){
    int n, m;
    cin >> n >> m;
    if (n == 1 && m == 0){
        printf("%d %d\n", 1, 2);
        return 0;
    }
    if (m >= n-1 || m < 0){
        cout << -1 << endl;
        return 0;
    }
    VP ans;
    rep(i,m+1){
        if (i == 0) ans.emplace_back(2, 3);
        else ans.emplace_back(ans.back().first+2, ans.back().second+2);
    }
    ans.emplace_back(1, ans.back().second+1);
    for(int i = m+1; i <= n; i++){
        if (i == m+1) ans.emplace_back(ans.back().second+1 ,ans.back().second+2);
        else ans.emplace_back(ans.back().first+2, ans.back().second+2);
    }
    rep(i,n){
        printf("%d %d\n", ans[i].first, ans[i].second);
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define range(i, a, b) for (ll i = (a); i < (b); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
template<class T> using pri_s = priority_queue<T, vector<T>, greater<T>>;
template<class T> using pri_b = priority_queue<T>;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr int mod1e9 = 1000000007;
constexpr int mod998 = 998244353;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; };
int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 };
ll mul(ll a, ll b) { return (a > INF / b ? INF : a * b); }
void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); }
template<class T> void er(T a) { cout << a << '\n'; exit(0); }
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; }
template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; }
template<class T, class U> ostream &operator << (ostream &s, const pair<T, U> &p) { s << p.first << ' ' << p.second; return s; }

struct fastio {
	fastio() {
		cin.tie(0); cout.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(20);
		cerr << fixed << setprecision(20);
	}
}fastio_;

int main() {
	int n;
	string s;
	cin >> n >> s;
	vector<int> a(n + 1);
	cin >> a;
	int k = inf;
	rep(i, n) chmin(k, abs(a[i] - a[i + 1]));
	cout << k << '\n';
	vector<vector<int>> ans(k, vector<int>(n + 1));
	rep(i, k) rep(j, n + 1) ans[i][j] = a[j] / k;
	rep(i, k) rep(j, n + 1) if (a[j] % k > i) ans[i][j]++;
	rep(i, k) cout << ans[i] << '\n';
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi pair<int,int>
#define pb push_back
#define fi first
#define sc second
#define ull unsigned long long
const int maxn=4e5+10;
const int mod=1e9+7;

char a[maxn],b[maxn];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) cin>>b[i];
    int m;
    cin>>m;
    int f=0;//0 为a在前 1为a在后
    while(m--)
    {
        int t,x,y;
        cin>>t>>x>>y;
        if(t==2)
        {
            f=!f;
        }
        else
        {
            if(x>n&&y>n)
            {
                x-=n,y-=n;
                if(f) swap(a[x],a[y]);
                else swap(b[x],b[y]);
            }
            else if(x<=n&&y<=n)
            {
                if(f) swap(b[x],b[y]);
                else swap(a[x],a[y]);
            }
            else
            {
                if(x>n)
                {
                    if(f)
                    {
                        x-=n;
                        swap(a[x],b[y]);
                    }
                    else
                    {
                        x-=n;
                        swap(a[y],b[x]);
                    }
                }
                else
                {
                    y-=n;
                    if(f)
                    {
                        swap(a[y],b[x]);
                    }
                    else
                    {
                        swap(a[x],b[y]);
                    }
                }
            }
        }
    }
    if(f) cout<<(b+1)<<(a+1)<<'\n';
    else cout<<(a+1)<<(b+1)<<'\n';

}


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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

void Main(){
    string S; cin >> S;

    int N = S.size();
    if(N<3){
        int a = 0;
        REP(i,N){
            a *= 10;
            a += S[N-1-i]-'0';
        }
        if(a%8 == 0){
            cout << "Yes" << en;
            return;
        }
        REVERSE(S);
        a = 0;
        REP(i,N){
            a *= 10;
            a += S[N-1-i]-'0';
        }
        if(a%8 == 0) cout << "Yes" << en;
        else cout << "No" << en;
        return;
    }

    VI n(10,0);
    for(char c : S){
        int x = c-'0';
        n[x]++;
    }

    int x = 104;
    while(x<1000){
        VI m(10,0);
        int y = x;
        REP(i,3){
            m[y%10]++;
            y /= 10;
        }

        bool flag = true;
        REP(i,10){
            if(m[i]>n[i]){
                flag = false;
                break;
            }
        }
        if(flag){
            cout << "Yes" << en;
            return;
        }
        x += 8;
    }
    cout << "No" << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using Graph = vector<vector<int>>;
const long long INF = 1LL << 60;
const int SINF = 1LL << 29;
const ll mod = 1000000000+7;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    string s;
    cin >> s;

    deque<char> deq;
    bool rev = false;

    rep(i, s.size()) {
        if(s[i] == 'R') rev = !rev;
        else if(rev) {
            deq.push_front(s[i]);
        }
        else {
            deq.push_back(s[i]);
        }
    }
    string ans;
    for(auto tmp:deq) ans.push_back(tmp);
    if(rev) reverse(all(ans));
    string res = "";
    rep(i, ans.size()) {
        res.push_back(ans[i]);
        if(res.size() >= 2) {
            string a = res.substr(res.size()-2, 2);
            if(a[0] == a[1]) res.erase(res.size()-2, 2);
        }
    }
    cout << res << endl;
}


#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>*/
#define ll long long
#define ld long double
#define vll vector <ll>
#define vvll vector <vll>
#define pll pair <ll, ll>
#define pld pair <ld, ld>
#define vpll vector <pll>

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

#define endl "\n"
#define pb push_back
#define pf push_front

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

#define sorta(v) sort(all(v))
#define sortd(v) sort(rall(v))
#define vld vector<ld>

#define debug if (1)
#define log(val) debug {clog << "\n" << #val << ": " << val << "\n";}

#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define mod (ll)(1e9 + 7)
#define inf (mod * mod)

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

const ll N = 18;
const ll MX = (1ll << 18);

ll dp[N][MX];
ll dst[N][N];
ll a[N];
ll b[N];
ll c[N];

void solve() {
    ll n;
    cin >> n;
    rep(i, 0, n) {
        cin >> a[i] >> b[i] >> c[i];
    }

    rep(i, 0, n) {
        rep(j, 0, n) {
            dst[i][j] = abs(a[i] - a[j]) + abs(b[i] - b[j]) + max(0ll, c[j] - c[i]);
        }
    }

    rep(mask, 0, (1ll << n)) {
        rep(i, 0, n) {
            dp[i][mask] = inf;
        }
    }

    dp[0][1] = 0;

    rep(mask, 0, (1ll << n)) {
        rep(i, 0, n) {
            if (mask & (1ll << i)) {
                rep(j, 0, n) {
                    if (!(mask & (1ll << j))) {
                        dp[j][mask | (1ll << j)] = min(dp[j][mask | (1ll << j)], dp[i][mask] + dst[i][j]);
                    }
                }
            }
        }
    }

    ll ans = inf;
    rep(i, 1, n) {
        ans = min(ans, dp[i][(1ll << n) - 1] + dst[i][0]);
    }
    cout << ans;
}

int main() {
    ios
    // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())

    // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    ll tests = 1;
    //cin >> tests;
    while (tests--) {
        solve();
        cout << "\n";
    }

    return 0;
}

#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
const int MAXN = 110;

int N;
pair <double, double> loc[MAXN];
int edge[MAXN][MAXN];

bool works (double r)
{
  for (int i = 0; i < MAXN; i++)
for (int j = 0; j < MAXN; j++)
edge[i][j] = 0;
  for (int i = 0; i < N; i++)
  {
	edge[i][i] = 1;
    for (int j = i + 1; j < N; j++)
    {
      double d = loc[i].first - loc[j].first;
      double e = loc[i].second - loc[j].second;
      if (d * d + e * e < 4 * r * r) edge[i][j] = edge[j][i] = 1;
    }
    if (loc[i].second >= 100 - 2 * r)
      edge[i][N] = edge[N][i] = 1;
    if (loc[i].second <= -100 + 2 * r)
      edge[N+1][i] = edge[i][N+1] = 1;
  }

  for (int k = 0; k < N + 2; k++)
    for (int i = 0; i < N + 2; i++)
      for (int j = 0; j < N + 2; j++)
        if (edge[i][k] && edge[k][j])
          edge[i][j] = 1;
  if (edge[N][N+1]) return false;
  return true;
}

int main()
{
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> loc[i].first >> loc[i].second;

  double lo = 0.0, hi = 100.0;
  for (int i = 0; i < 50; i++)
  {
    double mid = (lo + hi) / 2;
    if (works (mid))
      lo = mid;
    else
      hi = mid;
  }
  cout << fixed << setprecision(10);
  cout << lo << "\n";
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<ll>
#define vll vector<ll>
#define all(x) (x).begin() , (x).end()
#define inf 1000000000
#define mod 1000000007

void dbg(){
	cerr << endl;
}
template<typename Head , typename... Tail>
void dbg(Head h , Tail... t){
	cerr << h << " ";
	dbg(t...);
}

#ifdef EMBI_DEBUG
#define debug(...) cerr << "(" << #__VA_ARGS__  << "): ", dbg(__VA_ARGS__)
#else
#define debug(...)
#endif

const ll max_n = 1e5 + 9;

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
void solve(){
	ll n , m;
    cin >> n >> m;

    ll a[n] , b[m];
    for(ll i = 0 ; i < n ; i++)cin >> a[i];
    for(ll i = 0 ; i < m ; i++)cin >> b[i];

    sort(a , a+n);
    sort(b , b+m);

    ll pref[n] , sum = 0;
    for(ll i = n-1 ; i >= 0 ; i--){
        sum += ((n-i) % 2 ? 1 : -1) * a[i];
    }

    ll curr = 0;

    for(ll i = 0 ; i < n ; i++){
        ll new_sum = sum - (i%2==0 ? 1:-1)*a[i];
        pref[i] = new_sum + curr;
        curr += (i % 2 ? 1 : -1) * a[i];
        sum = new_sum;
    }

    // for(ll i = 0 ; i < n ; i++)cout << pref[i] << " ";
    // cout << "\n";

    ll minimum = inf;

    for(ll i = 0 ; i < n ; i++){
        auto it = lower_bound(b , b+m , a[i]) - b;
        ll min1 = inf;
        if(it != m){
            min1 = min(min1 , abs(a[i] - b[it]));
        }
        it--;
        if(it >= 0){
            min1 = min(min1 , abs(a[i] - b[it]));
        }

        minimum = min(minimum , min1 + pref[i]);
    }
    cout << minimum << "\n";
}
signed main(){
	ll t = 1;
	// cin >> t;
	for(ll i = 1 ; i <= t ; i++){
		solve();
	}
}

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 2000000000;
//debug
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  REP(i,n) cin >> h[i];
  vector<int> w(m);
  REP(i,m) cin >> w[i];

  // debug(w);

  sort(ALL(h));
  sort(ALL(w));

  vector<ll> diff1(n/2 + 1);
  vector<ll> diff2(n/2 + 1);

  ll sum = 0;

  //1
  int cc = 1;
  for(int i = 0; i < n-2; i += 2){
   int d = h[i+1] - h[i];
   sum += d;
   diff1[cc] = sum;
   cc++;
  }

  //2
  sum = 0;
  cc = 1;
  for(int i = 1; i < n-1; i += 2){
   int d = h[i+1] - h[i];
   sum += d;
   diff2[cc] = sum;
   cc++;
  }

  // debug(diff1);
  // debug(diff2);

  //自身の挿入箇所
  int ans = INF;
  REP(i,m){
    auto pos = lower_bound(ALL(h), w[i]) - h.begin();

    int befsum = INF;
    int aftsum = INF;
    //1 後ろと差分
   if( pos%2 == 0 ){
      ll pre = diff1[(pos)/2];
      ll mid = abs(h[pos] - w[i]);
      ll aft = diff2[n/2] - diff2[(pos)/2];
      aftsum = pre + mid + aft;
      debug(pos);
      debug(pre);
      debug(mid);
      debug(aft);
   }

    //2　前との差分
  if( pos%2 == 1 ){
    ll pre = diff1[(pos)/2];
    ll mid = abs(h[pos-1] - w[i]);
    ll aft = diff2[n/2] - diff2[(pos)/2];
    befsum = pre+mid+aft;
  }

  // debug(aftsum);
  // debug(befsum);

   ans = min({ans, befsum, aftsum});

  }

  cout << ans << endl;

  return 0;
}