#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <utility>
#include <queue>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
const int LEN = 100000;

struct fastio {
  int it, len;
  char s[LEN + 5];
  fastio() {
    it = len = 0;
  }
  char get() {
    if (it < len) return s[it++];
    it = 0, len = fread(s, 1, LEN, stdin);
    return len ? s[it++] : EOF;
  }
  bool notend() {
    char c;
    for (c = get(); c == ' ' || c == '\n' || c == '\r'; c = get());
    if (it) it--;
    return c != EOF;
  }
  void put(char c) {
    if (it == LEN) fwrite(s,1,LEN,stdout), it = 0;
    s[it++] = c;
  }
  void flush() {
    fwrite(s, 1, it, stdout);
    it = 0;
  }
}buff, bufo;
inline int getint() {
  char c; int res = 0, sig = 1;
  for (c = buff.get(); c < '0' || c > '9'; c = buff.get()) if(c == '-') sig = -1;
  for (; c >= '0' && c <= '9'; c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline ll getll() {
  char c; ll res = 0, sig = 1;
  for (c = buff.get(); c < '0' || c > '9'; c = buff.get()) if (c == '-') sig = -1;
  for (; c >= '0' && c <= '9'; c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline void putint(int x, char suf) {
  if (!x) bufo.put('0');
  else {
    if (x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[15];
    while (x) {
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for (; k; k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline void putll(ll x, char suf) {
  if (!x) bufo.put('0');
  else {
    if (x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[25];
    while (x) {
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for (; k; k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline char get_char() {
  char c;
  for (c = buff.get(); c == ' ' || c == '\n' || c == '\r'; c = buff.get());
  return c;
}
template<class T> bool chmin(T &x, T y) {
  return x > y ? (x = y, true) : false;
}
template<class T> bool chmax(T &x, T y) {
  return x < y ? (x = y, true) : false;
}

#define maxn 55
const ll mod = 998244353;
ll n, k, fct[maxn], a[maxn][maxn];

namespace Dsu {
  int par[maxn], siz[maxn];
  void init(int x) {
    for (int i = 1; i <= x; i++) {
      par[i] = i;
      siz[i] = 1;
    }
  }
  int fin(int x) {
    if (par[x] == x) return x;
    return par[x] = fin(par[x]);
  }
  void uni(int x, int y) {
    x = fin(x), y = fin(y);
    if (x == y) return;
    if (siz[x] < siz[y]) {
      par[x] = y;
      siz[y] += siz[x];
    } else {
      par[y] = x;
      siz[x] += siz[y];
    }
  }
}

int main() {
  n = getint(), k = getint();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      a[i][j] = getint();
    }
  }
  fct[0] = 1;
  for (int i = 1; i <= n; i++) fct[i] = fct[i - 1] * i % mod;
  ll ans = 1;

  Dsu::init(n);
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      bool ok = true;
      for (int l = 1; l <= n; l++) {
        ok &= (a[i][l] + a[j][l] <= k);
      }
      if (ok) Dsu::uni(i, j);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (Dsu::par[i] == i) (ans *= fct[Dsu::siz[i]]) %= mod;
  }

  Dsu::init(n);
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      bool ok = true;
      for (int l = 1; l <= n; l++) {
        ok &= (a[l][i] + a[l][j] <= k);
      }
      if (ok) Dsu::uni(i, j);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (Dsu::par[i] == i) (ans *= fct[Dsu::siz[i]]) %= mod;
  }

  putll(ans, '\n');
  bufo.flush();
  return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

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

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

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    int N;
    cin >> N;
    V<int> A(N), B(N);
    int sz = N * 2;
    V<int> tp(sz), com(sz, -1);

    bool ng = false;

    rep(i, N) {
        cin >> A[i] >> B[i];
        if (A[i] != -1) {
            --A[i];
            if (tp[A[i]]) ng = true;
            tp[A[i]] = i + 1;
        }
        if (B[i] != -1) {
            --B[i];
            if (tp[B[i]]) ng = true;
            tp[B[i]] = -(i + 1);
        }

        if (A[i] != -1 && B[i] != -1) {
            com[A[i]] = B[i];
            com[B[i]] = A[i];
        }
    }
    if (ng) {
        puts("No");
        return 0;
    }

    V<bool> dp(sz + 1);
    dp[0] = true;

    rep(i, sz) {
        if (!dp[i]) continue;
        for (int j = i + 1; j < sz; ++j) {
            int w = j - i + 1;
            if (w & 1) continue;
            w /= 2;
            bool ok = true;

            rep(k, w) {
                int p = i + k, q = i + k + w;
                if (com[p] != -1 && !(i <= com[p] && com[p] <= j)) {
                    ok = false;
                }
                if (com[q] != -1 && !(i <= com[q] && com[q] <= j)) {
                    ok = false;
                }
                if (tp[p] != 0 && tp[q] != 0) {
                    if (tp[p] < 0 || tp[p] + tp[q] != 0) {
                        ok = false;
                    }
                }
                if (tp[p] < 0 || tp[q] > 0) {
                    ok = false;
                } else {
                    if (tp[p] != 0) {
                        int v = tp[p] - 1;
                    }
                }
            }
            if (ok) {
                dp[j + 1] = true;
            }
        }
    }
    puts(dp[sz] ? "Yes" : "No");

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
typedef long long ll;
int n, m, a[200005], b[200005];
int main() {
	std::cin >> n >> m;
	int w = 2100000000;
	for (int i = 1; i <= m; ++i) {
		std::cin >> a[i];
	}
	std::sort(a, a + m + 1);
	a[m + 1] = n + 1;
	for (int i = 1; i <= m + 1; ++i) {
		b[i] = a[i] - a[i - 1] - 1;
		if (b[i] != 0) w = std::min(b[i], w);
	}
	int ans = 0;
	for (int i = 1; i <= m + 1; ++i) {
		ans += (b[i] + w - 1) / w;
	}
	std::cout << ans << "\n";
	return 0;
}

#include<cstdio>
#include<algorithm>
int a[200000];
using namespace std;
int main(void)
{
	long long ans=0,x=0;
	int n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++)	scanf("%d",&a[i]);
    sort(a,a+n);
	for(i=n-1;i>=1;i--){
    	ans+=x;
    	x+=(long long)(a[i]-a[i-1])*(n-i);
    	ans+=(long long)(a[i]-a[i-1])*(n-i);
    }
    printf("%lld\n",ans);
    return 0;
}


/**
 *    author:  otera
**/
#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60;
#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++)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
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; }

void solve() {
    ll x, y; cin >> x >> y;
    if(x >= y) {
        cout << x - y << "\n";
        return;
    }
    ll ans = y - x;
    for(int i = 0; ; ++ i) {
        ll x_ = x * (1LL<<i);
        ll len = abs(x_ - y);
        ll cnt = i;
        // for(int bit = (1LL<<i); bit >= 1; bit >>= 1) {
        //     ll cand1 = len / bit, cand2 = cand1 + 1;
        //     // if(abs(len - bit * cand1) <= abs(len - bit * cand2)) {
        //         cnt += cand1;
        //         len = abs(len - bit * cand1);
        //     // } else {
        //     //     cnt += cand2;
        //     //     len = abs(len - bit * cand2);
        //     // }
        // }
        ll cand1 = len / (1LL<<i), cand2 = cand1 + 1;
        ll tmp1 = cand1 + cnt, len1 = abs(len - cand1 * (1LL<<i));
        vector<bool> check(i, 0);
        for(int j = i - 1; j >= 0; -- j) {
            if(len1 & (1LL<<j)) {
                check[j] = 1;
            } else {
                check[j] = 0;
            }
        }
        int now = 0;
        for(int j = i - 1; j >= 0; -- j) {
            if(check[j] == 1) {
                ++ now;
            }
            if(j == 0 or check[j] == 0) {
                tmp1 += min(2LL, now);
                now = 0;
            }
        }
        ll tmp2 = cand2 + cnt, len2 = abs(len - cand2 * (1LL<<i));
        for(int j = i - 1; j >= 0; -- j) {
            if(len2 & (1LL<<j)) {
                check[j] = 1;
            } else {
                check[j] = 0;
            }
        }
        now = 0;
        for(int j = i - 1; j >= 0; -- j) {
            if(check[j] == 1) {
                ++ now;
            }
            if(j == 0 or check[j] == 0) {
                tmp2 += min(2LL, now);
                now = 0;
            }
        }
        chmin(ans, tmp1);
        chmin(ans, tmp2);
        if(x_ > y) break;
    }
    cout << ans << "\n";
    // int k = 0;
    // while(x * (1LL<<(k + 1)) <= y) ++ k;

}

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

#include <bits/stdc++.h>
using namespace std;
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;
}
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define FOR(i, a, b) for(int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

ll g1(ll n) {
    string s = to_string(n);
    sort(RALL(s));
    return stoll(s);
}

ll g2(ll n){
    string s = to_string(n);
    sort(ALL(s));
    return stoll(s);
}

ll f(ll n) {
    return g1(n) - g2(n);
}

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

    ll now = N;
    REP(i, K) now = f(now);

    cout << now << endl;
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
const int N=1e5+10;
ll n;
ll a[N],b[N];
ll res,sum;
vector<int>	v[2];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)	cin>>a[i],sum+=a[i];
	for(int i=1;i<=n;i++){
		cin>>b[i];
		b[i]=b[i]-a[i];
		if(i%2)	v[1].push_back(b[i]);
		else	v[0].push_back(b[i]);
	}
	sort(v[1].begin(),v[1].end());
	sort(v[0].begin(),v[0].end());
	res=sum;
	for(int i=v[1].size()-1;i>=0;i--){
		sum+=v[0][i]+v[1][i],res=max(res,sum);
	}
	cout<<res;
	return 0;
}

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

typedef long long ll;
const int N = 1e5 + 10;
ll tot = 0;
int n, a[N], b[N];
priority_queue<int> q[2];

int main() {
    cin >> n;
    rep(i, 1, n) scanf("%d", &a[i]), tot += a[i];
    rep(i, 1, n) scanf("%d", &b[i]), q[i & 1].push(b[i] - a[i]);
    while (q[0].size() && q[1].size() && q[0].top() + q[1].top() > 0) {
        tot += q[0].top() + q[1].top(), q[0].pop(), q[1].pop();
    }
    printf("%lld\n", tot);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
inline int re()
{
    char c = getchar();
    int x = 0, k = 1;
    while (c < '0' || c > '9')
    {
        if (c == '-')
            k = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
        x = (x << 1) + (x << 3) + c - '0', c = getchar();
    return k * x;
}
void wr(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        wr(x / 10);
    putchar(x % 10 + '0');
}
signed main()
{
    char c = getchar();
    bool isLowerCase = 1;
    while (c != '\377' && c != '\n')
    {
        if (isLowerCase && (c < 'a' || c > 'z'))
            printf("No"), exit(0);
        if ((!isLowerCase) && (c < 'A' || c > 'Z'))
            printf("No"), exit(0);
        isLowerCase = !isLowerCase;
        c = getchar();
    }
    printf("Yes");
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
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;}
#define rep(i,n) for(int i=0;i<(n);i++)
#define drep(i,n) for(int i=(n)-1;i>=0;i--)
template<class T> void print(vec<T>& v){rep(i,v.size()) cout << v[i] << (i+1!=(int) v.size()? " ":"\n");}
#define all(x) (x).begin(),(x).end()
#define debug(x)  cerr << #x << " = " << (x) << endl;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    cout << (N+99)/100 << "\n";
}


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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> A(N), B(N), P(N);
    for ( int i = 0; i < N; i++ ) cin >> A[i];
    for ( int i = 0; i < N; i++ ) cin >> B[i];
    for ( int i = 0; i < N; i++ ) {
        cin >> P[i];
        P[i]--;
    }
    vector<pii> ws(N);
    for ( int i = 0; i < N; i++ ) {
        ws[i] = pii(A[i],i);
    }
    sort(ws.begin(), ws.end());
    vector<ll> rP(N);   // 荷物iを持っている人
    for ( int i = 0; i < N; i++ ) {
        rP[P[i]] = i;
    }

    vector<pii> ans;
    for ( int k = 0; k < N; k++ ) {
        ll a = ws[k].first;
        int i = ws[k].second;
        if ( P[i] == i ) continue;
        int j = rP[i];
        if ( B[P[i]] >= A[i] ) return -1;
        if ( B[P[j]] >= A[j] ) return -1;
        ans.push_back(pii(i,j));
        swap(rP[P[i]],rP[P[j]]);
        swap(P[i],P[j]);
        // cout << "\n";
        // cout << "P";
        // for ( int i = 0; i < N; i++ ) {
        //     cout << P[i] << " ";
        // }
        // cout << "\n";
        // cout << "rP";
        // for ( int i = 0; i < N; i++ ) {
        //     cout << rP[i] << " ";
        // }
        // cout << "\n";
    }
    cout << ans.size() << "\n";
    for ( int i = 0; i < ans.size(); i++ ) {
        cout << ans[i].first+1 << " " << ans[i].second+1 << "\n";
    }
    return 0;
}

int main() {
    auto ans = solve();
    if ( ans < 0 ) {
        cout << ans << "\n";
    }
    return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

template <typename T>
T mypow(T x, T n, const T &p = -1)
{ //x^nをmodで割った余り
	T ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

using namespace std;
// using namespace atcoder;

void solve()
{
	int n;
	cin>>n;
	vector<int>a(n),b(n),p(n);
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	rep(i,n)cin>>p[i],p[i]--;
	auto c=p;
	sort(all(c));

	int ans=0;
	vector<pair<int,int>>pp;
	rep(i,n){
		if(p[i]!=i){
			if(a[i]<=b[p[i]]||a[p[i]]<=b[p[p[i]]])break;
			else if(p[p[i]]==i){
				pp.eb(i+1,p[i]+1);
				swap(p[i],p[p[i]]);
				++ans;
			}
			else if(a[i]>b[p[p[i]]]){
				pp.eb(i+1,p[i]+1);
				swap(p[i],p[p[i]]);
				++ans;
				--i;
			}
		}
	}

	if(c==p){
		cout<<ans<<"\n";
		rep(i,pp.size()){
			cout<<pp[i].first<<" "<<pp[i].second<<"\n";
		}
	}
	else cout<<-1<<"\n";
}

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


//Bismillahir Rahmanir Raheem
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
#define sf(x) scanf("%d",&x)
#define sfl(x) scanf("%lld",&x)
#define lli long long int
#define ll64 int64_t
#define pb push_back
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define frr(i,a) for(int i=0;i<a;i++)
#define frl(i,a) for(lli i=0;i<a;i++)
#define fr1(i,a) for(int i=1;i<=a;i++)
#define iter(x)  x.begin(),x.end()
#define Memset(a,x,n) for(int i=0;i<n;i++)a[i]=x;
#define fi first
#define si second
//std::string s=std::bitset<M>(n).to_string();  //number to binary string
//lower_bound returns an iterator pointing to the first element in the range [first,last) which has a value not less than ‘val’.
//upper_bound returns an iterator pointing to the first element in the range [first,last) which has a value greater than ‘val’.
typedef pair<lli,lli>pll;
int main()
{
    lli a,b,c;
    cin>>a>>b>>c;
    if((a*a+b*b)<(c*c))
    {
        cout<<"Yes"<<endl;
    }
    else{ cout<<"No"<<endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n1,n2) for(int i=(int)(n1); i<(int)(n2); ++i)
#define REP(i,n)     for(int i=0        ; i<(int)(n) ; ++i)
using llint = long long int;
const double EPS = 1e-9;
// debug
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#define DEBUG(x) cout << '(' << __LINE__ << ") " << #x << ": " << x << endl;
#else
#define DEBUG(x)
#endif

int main() {
  int n,q;
  string s,s1,s2;
  cin >> n;
  cin >> s;
  cin >> q;
  s1=s.substr(0,n);
  s2=s.substr(n);

  int t, a, b;
  REP(i,q) {
    cin >> t >> a >> b;
    if(t==1) {
      if(a>n) swap(s2[a-1-n],s2[b-1-n]);
      else if(b<=n) swap(s1[a-1],s1[b-1]);
      else swap(s1[a-1],s2[b-1-n]);
    }
    else swap(s1,s2);
  }

  cout << s1+s2 << "\n";

}

// end


#include <bits/stdc++.h>
#define mem(arr, val) memset(arr, val, sizeof(arr))
#define all(v) v.begin(), v.end()
#define endl '\n'
#define decision (yes ? "YES" : "NO")
using namespace std;
// const double PI = acos(-1.0);
// const double E = exp(1.0);
const double EPS = 1e-9;
const int INF = (int)2e9;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e5;
const int N = (int)1e5;

int main() {
#ifdef MY_LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> a(n), p(n), x(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> p[i] >> x[i];
    }
    vector<int> prices;
    for (int i = 0; i < n; i++) {
        if (a[i] < x[i]) {
            prices.push_back(p[i]);
        }
    }

    int ans = -1;
    if (!prices.empty()) ans = *min_element(all(prices));
    cout << ans << endl;

    return 0;
}

// clang-format off
/* #pragma GCC optimize("Ofast") */
/* #pragma GCC optimize("unroll-loops") */

#pragma GCC diagnostic ignored "-Wregister"

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

#define int ll

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pii> vpii;

namespace fio {
	struct fastio
	{
		char s[100000];
		int it,len;
		fastio(){it=len=0;}
		inline char get()
		{
			if(it<len)return s[it++];
			it=0;
			len=fread(s,1,100000,stdin);
			if(len==0)return EOF;else return s[it++];
		}
		bool notend()
		{
			char c=get();
			while(c==' '||c=='\n')c=get();
			if(it>0)it--;
			return c!=EOF;
		}
	}_buff;
	inline ll getnum()
	{
		ll r=0;bool ng=0;char c;c=_buff.get();
		while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
		if(c=='-')ng=1,c=_buff.get();
		while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
		return ng?-r:r;
	}
	template<class T> inline void write(T x) {
		if(x<0)putchar('-'),x=-x;
		register short a[20]={},sz=0;
		while(x)a[sz++]=x%10,x/=10;
		if(sz==0)putchar('0');
		for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
	}

	inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}

	template<class T> inline void write(T x, char c) { putnum(x), putchar(c); }
	template<class T> inline void writeln(T x) { write(x), putchar('\n'); }
	template<class T> inline void writesp(T x) { write(x), putchar(' '); }

	void read() { ; }
	void read(int32_t &x) { x = getnum(); }
	void read(ll &x) { x = getnum(); }
	void read(string &s) { char c=_buff.get(); while(isspace(c))c=_buff.get(); while(not isspace(c)){ s += c; c=_buff.get(); } }
	template<typename H, typename... T> inline void read(H &x, T &... g) { read(x); read(g...); }
}
using namespace fio;

#define endl '\n'
#define rep(i, begin, end) for (__typeof(begin) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); (begin) > (end) ? i-- : i++)
#define all(X) begin(X),end(X)
#define sz(x) ((int) x.size())
// clang-format on

double eps = 1e-10;

int32_t main() {

#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	/* freopen("output.txt", "w", stdout); */
#endif
	int x, y, a, b;
	read(x, y, a, b);

	vi v;
	v.push_back(x);

	while (v.back() <= y / a)
		v.push_back(v.back() * a);

	if (v.back() >= y)
		v.pop_back();

	int res = sz(v) - 1;

	rep(i,0,sz(v))
		res = max(res, i + (y - v[i] - 1) / b);

	writeln(res);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(i,n) for(ll i=0;i<n;i++)
#define foi(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define Foi(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sortall(x) sort(all(x))
#define sz(x) int((x).size())
#define PI 3.1415926535897932384626 1170 01:10
typedef pair<int, int> pii;
typedef vector<int>   vi;
typedef vector<pii>	vpii;
typedef vector<vi>	vvi;
typedef vector<ll>	vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<bool> vb;
#define ld long double
const int INF = 1000000009;
const unsigned int M = 1000000007;
const long long INFLL = (long long )INF * (long long)INF;
const ld EPS = 10e-9;
template <typename T> void ckmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void ckmax(T &a, const T &b) { a = max(a, b); }
namespace __input {
    template <class T1, class T2> void re(pair<T1, T2> &p);
    template <class T> void re(vector<T> &a);
    template <class T, size_t SZ> void re(array<T, SZ> &a);

    template <class T> void re(T &x) { cin >> x; }
    void re(double &x) { string t; re(t); x = stod(t); }
    template <class Arg, class... Args> void re(Arg &first, Args &...rest) { re(first); re(rest...); }

    template <class T1, class T2> void re(pair<T1, T2> &p) { re(p.f, p.s); }
    template <class T> void re(vector<T> &a) { for (int i = 0; i < sz(a); i++) re(a[i]); }
    template <class T, size_t SZ> void re(array<T, SZ> &a) { for (int i = 0; i < SZ; i++) re(a[i]); }
}
using namespace __input;

namespace __output {
    template <typename T> struct is_outputtable { template <typename C> static constexpr decltype(declval<ostream &>() << declval<const C &>(), bool()) test(int) { return true; } template <typename C> static constexpr bool test(...) { return false; } static constexpr bool value = test<T>(int()); };
    template <class T, typename V = decltype(declval<const T &>().begin()), typename S = typename enable_if<!is_outputtable<T>::value, bool>::type> void pr(const T &x);

    template <class T, typename V = decltype(declval<ostream &>() << declval<const T &>())> void pr(const T &x) { cout << x; }
    template <class T1, class T2> void pr(const pair<T1, T2> &x);
    template <class Arg, class... Args> void pr(const Arg &first, const Args &...rest) { pr(first); pr(rest...); }

    template <class T, bool pretty = true> void prContain(const T &x) { if (pretty) pr("{"); bool fst = 1; for (const auto &a : x) pr(!fst ? pretty ? ", " : " " : "", a), fst = 0; if (pretty) pr("}"); }

    template <class T> void pc(const T &x) { prContain<T, false>(x); pr("\n"); }
    template <class T1, class T2> void pr(const pair<T1, T2> &x) { pr("{", x.f, ", ", x.s, "}"); }
    template <class T, typename V, typename S> void pr(const T &x) { prContain(x); }

    void ps() { pr("\n"); }
    template <class Arg> void ps(const Arg &first) { pr(first); ps(); }
    template <class Arg, class... Args> void ps(const Arg &first, const Args &...rest) { pr(first, " "); ps(rest...); }
}
using namespace __output;
namespace __io {
    void setIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout << setprecision(15); }
}
using namespace __io;

//Overflow (to check before every problem!!!!)
//#define int long long
///////////////////////////////////////////////

///////////////////////////////////////////////
void solve() {
	int a,b,c;
	re(a,b,c);
	if(c==0){
		if(a>b){ps("Takahashi");return;}
		else{ps("Aoki");return;}
	}
	if(c==1){
		if(b>a){ps("Aoki");return;}
		else{ps("Takahashi");return;}
	}

}
//////////////////////////////////////////////////////////////

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

#include<bits/stdc++.h>
#define maxn 500010
using namespace std;
int read()
{
	int 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;
}
signed main()
{
	int n=read(),m=read(),C=read();
	if(C&1)
	{
		if(n>=m) cout<<"Takahashi\n";
		else cout<<"Aoki\n";
	}
	else
	{
		if(n>m) cout<<"Takahashi\n";
		else cout<<"Aoki\n";
	}
	return 0;
}


//khodaya khodet komak kon
# include <bits/stdc++.h>

/*
// ordered_set
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
# define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/

using namespace std;

typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
typedef pair <pii, int>                                  ppi;
typedef pair <int, pii>                                  pip;
typedef pair <pii, pii>                                  ppp;
typedef pair <ll, ll>                                    pll;

# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define SZ(x)                                           int(x.size())
# define lc                                              id << 1
# define rc                                              id << 1 | 1
# define InTheNameOfGod                                  ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);

ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));}

const int xn = 1e2 + 10;
const int xm = 1e5 + 10;
const int sq = 320;
const int inf = 1e9 + 10;
const ll INF = 1e9 + 10;
const int mod = 1e9+7;//1e9 + 7;//998244353;
const int base = 257;

int n, num[xn];
string s;
vector <int> vec[10007];

int main(){
	cin >> n;
	cin >> s;
	for (int i = 1; i <= n+1; ++i)	cin >> num[i];
	int mn = 1e9;
	for (int i = 2; i <= n+1; ++i)	mn = min(mn, abs(num[i]-num[i-1]));
	for (int i = 1; i <= n+1; ++i){
		for (int j = 0; j < num[i]%mn; ++j)	vec[j].push_back(num[i]/mn+1);
		for (int j = num[i]%mn; j < mn; ++j)	vec[j].push_back(num[i]/mn);
	}
	cout << mn << '\n';
	for (int i = 0; i < mn; ++i){
		for (int j : vec[i])	cout << j << ' ';
		cout << '\n';
	}
	return 0;
}

/*
5 14 5 5
0 5 9
5 12 10
0 7 7
7 12 8
4 7 10
0 12
0 5
0 7
7 12
0 13

5 30 5 1
0 5 1
5 10 1
10 15 1
15 20 1
20 25 1
0 25
*/

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include<atcoder/all>
using namespace std;
// using namespace atcoder;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    vector<int> a(n+1);
    for(auto&i:a) cin>>i;
    int k  = 1000000;
    rep(i, n){
      chmin(k, (int)abs(a[i+1] - a[i]));
    }
    cout << k << endl;
    rep(i, k) {
      rep(j, n+1) {
        if(j) cout << " ";
        cout << (a[j]+i)/k;
      }
      cout << endl;
    }

}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
using lint=long long;
#define debug(output) cout<<#output<<"= "<<output<<endl
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
void solve(){
    int n;cin>>n;
    vector<int> a(n);
    map<int,int> memo;
    rep(i,n){
        cin>>a[i];
        memo[a[i]]+=1;
    }
    bool flag=true;
    for(auto& val:memo){
        if(val.second&1)flag=false;
    }
    if(flag){
        cout<<"Second"<<"\n";
        return;
    }
    if(n&1){
        cout<<"Second"<<"\n";
    }
    else{
        cout<<"First"<<"\n";
    }
}
signed main(){
  int t;cin>>t;
  rep(i,t)solve();
  return 0;
}

#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
constexpr ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
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; }
constexpr int dy[4]={ -1,0,1,0 };
constexpr int dx[4]={ 0,-1,0,1 };

int T;
int N, A[100000];

signed main(){
    cin >> T;
    while(T--){
        cin >> N;
        rep(i, N) cin >> A[i];

        if(N%2 == 1) cout << "Second" << endl;
        else{
            sort(A, A+N);
            bool flg = true;
            rep(i, N/2){
                flg &= (A[2*i] == A[2*i+1]);
            }
            if(flg) cout << "Second" << endl;
            else cout << "First" << endl;
        }
    }
}


/*** author: yuji9511 ***/
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << "\n"

void solve(){
    ll n,a,b;
    cin >> n >> a >> b;
    print(n-a+b);

}

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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define pb push_back()
#define ff first
#define ss second
#define MOD 1000000007
int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin >> t;
	while (t--) {
		int k, n, m;
		cin >> k >> n >> m;
		int ans[k];
		int a[k];
		int sum = 0;
		for (int i = 0; i < k; i++) {
			cin >> a[i];
			ans[i] = m * a[i] / n;
			sum += ans[i];
		}
		sum = m - sum;
		pair<int, int> diff[k];
		for (int i = 0; i < k; i++) {
			diff[i].ff = abs((ans[i] + 1) * n - a[i] * m);
			diff[i].ss = i;
		}
		sort(diff, diff + k);
		for (int i = 0; i < sum; i++) {
			ans[diff[i].ss]++;
		}
		for (int i = 0; i < k; i++) {
			cout << ans[i] << " ";
		}
		cout << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i,n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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;}
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

const int MX = 1500;
const pair<int, int> direction[4] = {
  { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 }
};

int h,w,n,m;

bool light[MX][MX];
bool wall[MX][MX];
bool ok[MX][MX];

bool visited[MX][MX];
bool memo[MX][MX];

bool f(int d, int i, int j) {
  if (i < 0 || j < 0 || h <= i || w <= j) return false;
  if (wall[i][j]) return false;
  if (light[i][j]) return true;
  if (visited[i][j]) return memo[i][j];

  visited[i][j] = true;
  int ni = i + direction[d].first;
  int nj = j + direction[d].second;

  return memo[i][j] = f(d, ni, nj);
}

int main() {
  IOS;
  cin >> h >> w >> n >> m;
  REP(i,n) {
    int a,b; cin >> a >> b;
    a--; b--; light[a][b] = 1;
  }
  REP(i,m) {
    int c,d; cin >> c >> d;
    c--; d--; wall[c][d] = 1;
  }

  REP(d,4) {
    REP(i,h) REP(j,w) visited[i][j] = 0;
    REP(i,h) REP(j,w) if(f(d,i,j)) ok[i][j] = 1;
  }

  int ans = 0;
  REP(i,h) REP(j,w) ans += ok[i][j];
  COUT(ans);
  return 0;
}

#include<bits//stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
ll mod = 1e9+7;
template <class Abel> struct BIT {
    Abel UNITY_SUM = 0;
    vector<Abel> dat;
    BIT(int n, Abel unity = 0) : UNITY_SUM(unity), dat(n, unity) { }
    void init(int n) {
        dat.assign(n, UNITY_SUM);
    }
    inline void add(int a, Abel x) {
        for (int i = a; i < (int)dat.size(); i |= i + 1)
            dat[i] = dat[i] + x;
    }
    inline Abel sum(int a) {
        Abel res = UNITY_SUM;
        for (int i = a - 1; i >= 0; i = (i & (i + 1)) - 1)
            res = res + dat[i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sum(b) - sum(a);
    }
    void print() {
        for (int i = 0; i < (int)dat.size(); ++i)
            cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};
int main(){
   int h,w,m,x,y;cin >>h>>w>>m;
   vector<vector<int>> X(h),Y(w);
   rep(i,m){
      cin >>x >>y;x--;y--;
      X[x].push_back(y);
      Y[y].push_back(x);
   }rep(i,h) {
      X[i].push_back(w);sort(ALL(X[i]));
   }
   rep(i,w) {
      Y[i].push_back(h);sort(ALL(Y[i]));
   }
   ll ans = 0;
   rep(i,X[0][0]) ans += Y[i][0];
   BIT<int> bit(w+2);
   for(int i=X[0][0];i<w;i++) bit.add(i,1);
   rep(i,Y[0][0]){
      ans += bit.sum(0,X[i][0]);
      for(int j:X[i]) if(bit.sum(j,j+1)==0) bit.add(j,1);
   }cout << ans << endl;
}


#pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,a,n) for(int i=a;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
int main()
{
    fio;
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll n,x;
        cin>>n>>x;
        string s;
        cin>>s;
        for(char c:s)
        {
            if(c=='x' && x>0)
            x--;
            else if(c=='o')
            x++;
        }
        cout<<x<<endl;
    }
}

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,sse3,sse4")

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
const ll INF=1e18+7;
const int MAXN=1e6+7;

//struct EDGE {int n,next;} edge[MAXN<<1];
int n,x;
string s;
signed main()
{
	ios_base::sync_with_stdio(false),cin.tie(0);
	cin>>n>>x>>s;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='x')
		{
			if(x>0) x--;
		}
		else x++;
	}
	cout<<x<<endl;
	return 0;
}


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

vector <int> dy = {0, 1, 0, -1};
vector <int> dx = {1, 0, -1, 0};

const int INF = 1000000000;
const ll INFLL = 100000000000000000;

int main(){
    int n; cin >> n;
    vector <int> a(n-1), b(n-1);
    vector <vector<int>> G(n);
    rep(i, n-1){
        int _a, _b; cin >> _a >> _b;
        _a--; _b--;
        a.at(i) = _a;
        b.at(i) = _b;
        G.at(_a).push_back(_b);
        G.at(_b).push_back(_a);
    }

    vector <vector<int>> tree(n);
    map<pair<int, int>, int> Tree;
    deque <int> d; d.push_back(0);
    vector <int> seen(n, -1); seen.at(0) = 1;
    while(d.size()){
        auto now = d.front();
        d.pop_front();
        for(auto next: G.at(now)){
            if(seen.at(next) != -1) continue;
            seen.at(next) = 1;
            tree.at(now).push_back(next);
            Tree[make_pair(now, next)] = 1;
            d.push_back(next);
        }
    }

    // for(int i = 0; i < n; i ++){
    //     cout << i << ": ";
    //     for(auto v: tree.at(i)){
    //         cout << v << " ";
    //     }
    //     cout << endl;
    // }

    vector <ll> w(n);
    int q; cin >> q;
    while(q--){
        int t; cin >> t;
        ll e, x; cin >> e >> x;
        e --;
        int v_a, v_b;
        v_a = a.at(e);
        v_b = b.at(e);

        int from, not_to;
        if(t == 1){
            from = v_a;
            not_to = v_b;
        }
        else if(t == 2){
            from = v_b;
            not_to = v_a;
        }

        if(Tree[make_pair(from, not_to)] == 1){
            w.at(0) += x;
            w.at(not_to) += -x;
        }
        else{
            w.at(from) += x;
        }
    }
    deque <int> d2; d2.push_back(0);
    vector <int> seen2(n, -1); seen2.at(0) = 1;
    while(d2.size()){
        auto now = d2.front();
        d2.pop_front();
        for(auto next: G.at(now)){
            if(seen2.at(next) != -1) continue;
            seen2.at(next) = 1;
            d2.push_back(next);

            w.at(next) += w.at(now);
        }
    }

    for(auto ans: w){
        cout << ans << endl;
    }

}

#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define rng(i,l,r) for (int i=l; i<r; i++)
#define V(t) vector<t>
#define VV(t) V(vector<t>)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
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; }

template <typename T>
struct RMQ {
   const T INF = numeric_limits<T>::max();
   int n; // leafs
   vector<T> dat; // tree array
   RMQ(int n_) : n(), dat(n_ * 4, 0) {
      n = 1;
      while (n_ > n) n *= 2;
   }
   void update(int i, T x) {
      i += n - 1;
      dat[i] ^= x;
      while (i > 0) {
         i = (i - 1) / 2; // parent
         dat[i] = (dat[i * 2 + 1] ^ dat[i * 2 + 2]);
      }
   }
   // the minimum element of [a,b)
   T query(int a, int b) { return query_sub(a, b, 0, 0, n); }
   T query_sub(int a, int b, int k, int l, int r) {
      if (r <= a || b <= l) {
         return 0;
      }
      if (a <= l && r <= b) {
         return dat[k];
      } else {
         T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
         T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
         return vl ^ vr;
      }
   }
};

int main() {
   int n, q; cin >> n >> q;
   RMQ<int> st(n);
   rep(i,n) {
      int a; cin >> a;
      st.update(i, a);
   }
   // rep(i,6) cout << st.dat[i] << endl;
   rep(_,q) {
      int t,x,y; cin >> t >> x >> y;
      if (t == 1) { //replace
         st.update(x-1, y);
      } else { // x ... y
         cout << st.query(x-1,y) << endl;
      }
   }
}


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

#define Test(x) {static int testInt=1000;if((testInt--)>0) cout<<x<<"\t";}
#define BIGint 1000000007
#define FASTio ios::sync_with_stdio(false);cin.tie(NULL);

/****************************************************/
int main() {
	FASTio
	int n;cin>>n;int a[n];for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	ll out=a[0]+1;
	for(int i=1;i<n;i++) out=(out*(a[i]-a[i-1]+1))%BIGint;
	cout<<out<<"\n";
	return 0;
}

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

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

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

int main(){
   int n;
   cin>>n;
   vector<int> a(n);
   rep(i,0,n)cin>>a[i];
   a.push_back(0);
   sort(ALL(a));
   a.erase(unique(ALL(a)),a.end());

   Fp res=1;
   rep(i,0,a.size()-1)res*=a[i+1]-a[i]+1;
   cout<<res<<'\n';
   return 0;
}


#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define PRINT(a) printf("%.15Lf\n",a);
#define YESNO(a) cout << (a ? "YES" : "NO") << endl
#define YesNo(a) cout << (a ? "Yes" : "No") << endl
#define yesno(a) cout << (a ? "yes" : "no") << endl
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12
//priority_queue<int,vector<int>, greater<int> > q2;

int dp[200010][7];
int ten[200010];
int N;
string S, X;

int solve(int now, int m) {
	//cout << now << " " << m << endl;
	if (dp[now][m] != 0)return dp[now][m];
	if (now == N) {
		if (m == 0)return 1;
		else return 2;
	}
	else {
		int ans1 = solve(now + 1, m);
		int ans2 = solve(now + 1, (m + (S[now] - '0')*ten[N - now - 1]) % 7);
		//cout << now << " " << m << " " << ans1 << " " << ans2  <<" "<< S[now]<< endl;
		if (ans1 == 1 && ans2 == 1) {
			dp[now][m] = 1;
			return 1;
		}
		else if (ans1 == 2 && ans2 == 2) {
			dp[now][m] = 2;
			return 2;
		}
		else if (X[now] == 'T'){
			dp[now][m] = 1;
			return 1;
		}
		else{
			dp[now][m] = 2;
			return 2;
		}
	}
}

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

	cin >> N;
	REP(i, N) {
		if (i == 0)ten[i] = 1;
		else {
			ten[i] = (ten[i - 1] * 10) % 7;
		}
	}
	cin >> S >> X;
	int ans = solve(0, 0);
	if (ans == 1) {
		cout << "Takahashi" << endl;
	}
	else {
		cout << "Aoki" << endl;
	}

	return 0;
}

#include <bits/stdc++.h>

#define f first
#define s second

using namespace std;

typedef long long ll;

const int maxk = 10 + 1;
const int maxn = 2e5 + 17;

int N;
string S, X;

int DP[maxk][maxn];

bool solve(int i, int rem) {
    int &ret = DP[rem][i];
    if (ret != -1) return ret;

    if (i == N) return ret = !rem;

    int x = solve(i + 1, 10 * rem % 7);
    int y = solve(i + 1, (10 * rem + S[i] - '0') % 7);
    if (X[i] == 'A') return ret = min(x, y);
    return ret = max(x, y);
}

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

    memset(DP, 0xFF, sizeof DP);

    cin >> N >> S >> X;
    cout << (solve(0, 0) ? "Takahashi" : "Aoki") << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) \
  SORT(var);       \
  REVERSE(var)
#define OPTIMIZE_STDIO         \
  ios::sync_with_stdio(false); \
  cin.tie(0);                  \
  cout.precision(10);          \
  cout << fixed
#define endl '\n'

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

void solve(istream& cin, ostream& cout) {
  int t;
  cin >> t;
  REP(i, t) {
    int n;
    cin >> n;
    vector<string> s(3);
    REP(i, 3) {
      cin >> s[i];
    }
    string ans(2 * n + 1, ' ');
    REP(i, n) {
      ans[i] = '0';
      ans[i + n] = '1';
    }
    ans[2 * n] = '0';
    cout << ans << endl;
  }
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t; long long N; cin >> t >> N;
    set<int> S;
    for (int i = 1; i <= 100; i++) {
        S.emplace(((100 + t) * i) / 100);
    }
    int M = 100 + t;
    vector<int> V;
    for (int i = 1; i <= M; i++) {
        if (!S.count(i)) V.emplace_back(i);
    }
    N--;
    long long x = N / V.size();
    long long y = N % V.size();
    cout << x * M + V[y] << "\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,cnt,MOD=1000000007,ans=1,bik[200001],dp[1001][2];
char AA,AB,BA,BB;
map<ll,ll> mp;
ll f(ll x,ll y){
    if(y==0)return 1;
    if(y%2==0)return f(x,y/2)*f(x,y/2)%MOD;
    return x*f(x,y-1)%MOD;
}
ll comb(ll x,ll y){
    return bik[x]*f(bik[x-y],MOD-2)%MOD*f(bik[y],MOD-2)%MOD;
}
void ini(void){
    bik[0]=1;
    for(ll i=1LL;i<=200000;i++){
        bik[i]=bik[i-1]*i%MOD;
    }
    return ;
}
int main(void){
    cin>>n;
    dp[0][0]=dp[0][1]=1;
    for(int i=0;i<n;i++){
        dp[i+1][0]=dp[i][0]+dp[i][1];
        dp[i+1][0]%=MOD;
        dp[i+1][1]=dp[i][0];
    }
    if(n<=3){
        cout<<1<<endl;
        return 0;
    }
    cin>>AA>>AB>>BA>>BB;
    if(AB=='A'){
        if(AA=='A'){
            cout<<1<<endl;
            return 0;
        }
        else{
            if(BA=='B'){
                cout<<f(2,n-3)<<endl;
                return 0;
            }
            else{
                cout<<(dp[n-4][0]+dp[n-4][1])%MOD<<endl;
                return 0;
            }
        }
    }
    else{
        if(BB=='B'){
            cout<<1<<endl;
            return 0;
        }
        else{
            if(BA=='A'){
                cout<<f(2,n-3)<<endl;
                return 0;
            }
            else{
                cout<<(dp[n-4][0]+dp[n-4][1])%MOD<<endl;
                return 0;
            }
        }

    }
}

#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int n,m,t;
int a[1111],b[1111];
int now;
int nt;
int main()
{
	ios::sync_with_stdio(0);
	bool f=0;
	cin>>n>>m>>t;
	now=n;
	rep(i,m)cin>>a[i]>>b[i];
	rep(i,m)
	{
		if(!i)now-=a[i];
		else now-=a[i]-b[i-1];
		if(now<=0)f=1;
		now+=b[i]-a[i];
		if(now>n)now=n;
	}
	now-=t-b[m-1];
	if(now<=0)f=1;
	if(f)cout<<"No\n";
	else cout<<"Yes\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

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

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T> ostream &operator<<(ostream &os, multiset<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) { dump_func(__VA_ARGS__) }
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

struct mint {
    long long x;
    mint(long long _x=0):x((_x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint modpow(long long t) const {
        if (!t) return 1;
        mint a = modpow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return modpow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
    friend std::ostream& operator<<(std::ostream& os, const mint& a){
        os << a.x;
        return os;
    }
};
int main() {
    int N, P;
    cin >> N >> P;
    mint ans = mint(P-1)*mint(P-2).modpow(N-1);
    cout << ans << endl;
}

#include <bits/stdc++.h>
#define Mashu cout << "UUZ ate it." << endl
#define RE register int
#define ll long long
using namespace std;

inline int read(){
	char ch=getchar();
	int x=0,cf=1;
	while(ch<'0'||ch>'9') {
		if(ch=='-') cf=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	if (cf < 0) return -x;
	else return x;
}

int G[55];
template<class T> inline void write(T x){
	if (x < 0){
		putchar('-');
		x = -x;
	}
	int g=0;
	do{G[++g]=x%10;x/=10;}while(x);
	for(int i=g;i>=1;--i)putchar('0'+G[i]);putchar('\n');
}

struct edge{
	int to;
	int nxt;
	int w;
}e[400010];

int f[200010], cnt = 0;

void add(int u, int v, int w){
	e[++cnt].to = v;
	e[cnt].w = w;
	e[cnt].nxt = f[u];
	f[u] = cnt;
}

int main(){
	unsigned long long X, Y;
	cin >> X >> Y;
	__int128 x = X, y = Y;
	int cs = 0;
	__int128 ans = LONG_LONG_MAX;
	__int128 qvq = 1;
	__int128 MX = 1;
	for (int i = 1; i <= 24; i++) MX *= 10;
	while (x <= MX){
		__int128 qwq = max(x, y) - min(x, y);
		__int128 qaq = qwq / qvq;
		__int128 cirno = qwq % qvq;
		int awa = 0;
		while (cirno){
			if (cirno & 1){
				awa++;
			}
			else{
				if (awa && cirno != 1) qaq += min(2, awa);
				awa = 0;
			}
			cirno >>= 1;
		}
		if (awa) qaq += min(2, awa);
		ans = min(ans, qaq + cs);
		x *= 2;
		qvq *= 2;
		cs++;
	}
	write(ans);
	return 0;
	Mashu;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<30;
const ll inf_l = 1LL<<61;
const int MAX = 1e5;

int n;
vint both;
vector<bool> is_end;
vector<bool> is_start;

map<P,bool> memo_1;
map<int,bool> memo_2;

bool dfs(int start) {
    if (start == 2 * n) return true;
    if (memo_2.count(start)) return memo_2[start];
    bool res = false;
    for (int len = 1; start + 2 * len - 1 < 2 * n; len++) {
        bool ok = true;
        if (memo_1.count(P(start, len))) ok = memo_1[P(start, len)];
        else {
            for (int s = start; s < start + len; s++) {
                int t = s + len;
                if (both[s] != -1) {
                    if (both[s] != t) ok = false;
                } else {
                    if (is_end[s] || is_start[t]) ok = false;
                    if (is_end[t] && is_start[s]) ok = false;
                }
            }
            memo_1[P(start, len)] = ok;
        }
        if (ok) res |= dfs(start + 2 * len);
    }
    return memo_2[start] = res;

}

int main() {
    cin >> n;
    both.assign(2 * n, -1);
    is_end.assign(2 * n, false);
    is_start.assign(2 * n, false);
    set<int> used;
    rep(i,n) {
        int a, b; cin >> a >> b;
        if (used.count(a) && a != -1) {
            cout << "No" << endl;
            return 0;
        }
        if (used.count(b) && b != -1) {
            cout << "No" << endl;
            return 0;
        }
        used.insert(a); used.insert(b);
        if (a != -1 && b != -1) both[--a] = --b;
        else if (a == -1 && b == -1) continue;
        else if (a == -1) is_end[--b] = true;
        else if (b == -1) is_start[--a] = true;
    }
    if (dfs(0)) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
int a[MAXN], b[MAXN], dur[MAXN], dp[MAXN], g[MAXN];
int dd(int i){
    if(i > 2*n) return 1;
    if(dp[i] != -1)
        return dp[i];
    dp[i] = 0;
    for(int j = 1; i + 2*j <= 2*n + 1; j++){
        bool can = 1;
        for(int c = i; c < i + j; c++){
            if(dur[c] == 2 || (dur[c] == 1 && dur[c + j] != 0) || (dur[c] == 3 && g[c] != c + j)){
                can = 0;
                break;
            }
        }
        for(int c = i + j; c < i + 2*j; c++){
            if(dur[c] == 1 || (dur[c] == 2 && dur[c - j] != 0) || (dur[c] == 3 && g[c] != c - j)){
                can = 0;
            }
            if(!can) break;
        }
        dp[i] |= (can && dd(i + 2*j));
    }
    return dp[i];
}

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

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif

    cin>>n;
    memset(dp, -1, sizeof(dp));
    for(int i = 0; i < n; i++){
        cin>>a[i]>>b[i];
        if(a[i] == -1 && b[i] == -1){
            continue;
        }else if(a[i] == -1){
            if(dur[b[i]] != 0){
                cout<<"No"<<endl;
                return 0;
            }
            dur[b[i]] = 2;
        }else if(b[i] == -1){
            if(dur[a[i]] != 0){
                cout<<"No"<<endl;
                return 0;
            }
            dur[a[i]] = 1;
        }else{
            if(dur[a[i]] != 0 || dur[b[i]] != 0){
                cout<<"No"<<endl;
                return 0;
            }
            dur[a[i]] = 3;
            dur[b[i]] = 3;
            g[b[i]] = a[i];
            g[a[i]] = b[i];
            if(b[i] <= a[i]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }

    if(dd(1))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}


/* May the force be with you */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define FASTANDFURIOUS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define For(i,n) for(ll i=0;i<n;i++)
#define MOD 1000000007
#define MAX 1000001
#define pll pair <ll,ll>
#define pii pair <int,int>
#define dbg(x)    cout << #x << ": " << x << endl;
#define read(n,v) For(i,n)cin>>v[i]
#define mxh priority_queue<int>
#define mnh priority_queue<int,vector<int>,greater<int>>
#define mkp make_pair
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define fi first
#define se second
#define No cout<<"No\n";
#define Yes cout<<"Yes\n";
#define endl '\n'
#define INF 1e18

vl fact(1001,1);

ll pow(ll x, unsigned ll y, ll p){
    ll res=1LL;
    x=x%p;
    if (x==0) return 0;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll _pow(int a, int b){
    if(!b)
        return 1;
    ll temp = _pow(a, b / 2);
    temp = (temp * temp);
    if(b % 2)
        return (a * temp);
    return temp;
}
ll invmod(int a,int m){
    return pow(a,m-2,m);
}
ll ncr(int n,int r){
    if(n<r)
        return 0;
    ll ans=fact[n];
    ans*=invmod(fact[n-r],MOD);
    ans%=MOD;
    ans*=invmod(fact[r],MOD);
    ans%=MOD;
    return ans;
}
ll ncr_2(ll n, ll k ){
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    ll result = n;
    for(ll i = 2; i <= k; ++i ) {
        result = result * (n-i+1);
        result /= i;
    }
    return result;
}
signed main(){
   FASTANDFURIOUS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int tc=1;
    // cin>>tc;
    For(t,tc){
        int n;
        cin>>n;
        vi a(n),b(n),c(n);
        map<int,int> mp;
        For(i,n){
            cin>>a[i];
            mp[a[i]]++;
        }
        For(i,n){
            cin>>b[i];
        }
        For(i,n)cin>>c[i];
        ll cnt=0LL;
        for(auto x:c){
            int y = b[x-1];
            cnt+=mp[y];
        }
        cout<<cnt<<endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n;
	cin>>n;
	int a[n+1],b[n+1],c[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)
	{
		cin>>b[i];
	}
	for(int i=1;i<=n;i++)
	{
		cin>>c[i];
	}
	//int cnt=0;
	vector <int> cnt(n+1);
	for(int i=1;i<=n;i++)
	{
		cnt[b[c[i]]]+=1;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		ans+=cnt[a[i]];
	}
	cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
   int64_t n,x; cin >> n >> x;
   string s; cin >> s;
   for(char c : s){
     if(c=='o')x++;
     if(c=='x'&&x>0)x--;
   }
   cout<<x<<"\n";
}

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define ll long long
#define dl long double
#define all(arr) arr.begin(), arr.end()
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pie 3.14159265358979323846264338327950L
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define endl "\n"
#define int long long
#define sz(x) (int)x.size()
#define template_array_size (int)1e6 + 6
#define INF (int)1e18
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
using namespace std;

int gcd(int a,int b){ if(!a)return b;return gcd(b%a,a);}
int lcm(int a, int b) { return (a*b)/ gcd(a,b);}

const int MOD = 1e9 + 7;
const int mod = 1e9 + 7;

void sout(){
	cout<<endl;
}
template <typename T,typename... Types>
void sout(T var1,Types... var2){
	cout<<var1<<" ";
	sout(var2...);
}
template<typename T>
void sout(vector<T> arr) {
    for(auto it : arr) {
        cout<<it<<" ";
    }
    sout();
}

// int n,m;
// int temp;
// int cnt;
// int ans;
// int ind;
// int i,j;
// int a,b;

// vector<int> arr;
// vector<int> brr;
// int k;

void test_case () {

    int n, x;
    cin>>n>>x;

    string s;
    cin>>s;

    for(auto it : s) {
        if(it == 'o') {
            x++;
        } else {
            x--;
        }
        x = max(x, 0*1ll);
    }

    cout<<x;

}

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

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

    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/


#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
const int N = 1e6;
ll a,b,c;
ll binpow(ll a,ll b){
    ll res = 1;
    while(b){
        if(b & 1){
            res *= a;
            res %= 4;
        }
        a *= a;
        a %= 4;
        b >>= 1;
    }
    return res;
}
int main(){
    ios::sync_with_stdio(0);

    cin >> a >> b >> c;

    int x = binpow(b,c);
    //cout << x << endl;
    ll d = 1;
    if(x == 0) x = 4;
    while(x--){
        d*=a;
        d%=10;
    }

    cout << d << endl;
}

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

#define ll          long long
#define int        ll
#define pb          push_back
#define ppb         pop_back
#define eb          emplace_back
#define endl		'\n'
#define max(a,b)	((a)>(b)?(a):(b))
#define min(a,b)	((a)<(b)?(a):(b))
#define vi          vector<int>
#define vii         vector<pair<int, int> >
#define mp          make_pair
#define mem1(a)     memset((a),-1,sizeof(a))
#define mem0(a)     memset((a),0,sizeof(a))
#define memf(a)     memset((a),false,sizeof(a))
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    (a)*((b)/gcd((a),(b)))
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mi          map<int,int>
#define sz(x)       (ll)(x).size()
#define rep(i,a,b)  for(int i=(a);i<(b);i++)
#define pii         pair<int,int>

// Returns pow(base,exponent)%MOD in log(exponent) using binary exponentiation

int powermodp(long long base, long long exponent, long long mod) {
	long long ans = 1;
	while (exponent != 0)
	{
		if (exponent & 1)
			ans = (1LL * ans * base) % mod;
		base = (1LL * base * base) % mod;
		exponent >>= 1;
	}
	return ans % mod;
}

int solve()
{
	int a, b, c;
	cin >> a >> b >> c;
	int r = powermodp(b, c, 4);
	r+=4;
	int e = powermodp(a, r, 10);
	cout << e;

	return 0;
}
signed main()
{
	FAST
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int t = 1;
	// cin>>t;
	while (t)
	{
		solve();
		t--;
	}
	return 0;
}


#include<bits/stdc++.h>
//#include <atcoder/all>

#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define fi first
#define se second
#define sz(x) ((int)x.size())

using namespace std;
//using namespace atcoder;
using ld = long double;
using ll = long long;
using P = pair<ll, ll>;

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

const ll ZER = 0;
const ll MOD = 998244353;
const ll INF = 1e9;

int main(){
    int n;
    cin >> n;
    double res = 0;
    REP(i, 1, n - 1){
      res += (double)1.0 / (double)i;
    }
    cout << fixed << setprecision(10) << (double) n * res<< endl;
}

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

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

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

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

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

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

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

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

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

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

using namespace templates;

ll func(){
    ll n = in()*2;
    set<ll> s;
    for(ll i=1;i*i<=n;++i){
        if(n%i)continue;
        s.emplace(i);
        s.emplace(n/i);
    }
    ll ans = 0;
    foreach(i,s){
        if((i&1)==((n/i)&1))continue;
        ++ans;
    }
    return ans;
}

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


#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<stack>

using namespace std;
const int N = 2e5+10;

int main(){

 /*freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);*/
    char str[N];
    char ans[N];
    int n;
    cin>>n>>str;
    int res = 0;
    for(int i = 0,j = 0;i<n;++i){
        ans[j++]=str[i];
        if(ans[j-1]=='x'&&j>=3){if(ans[j-2]=='o'&&ans[j-3]=='f')j-=3,res+=3;}
    }
    cout<<n-res<<endl;
  /* fclose(stdin);
    fclose(stdout);*/
}

#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <sstream>
#include <fstream>
#include <numeric>
#include <tuple>
#include <ctime>
#include <random>

using namespace std;

#define fori(t) for(int i = 0; i < t; ++i)
#define forj(n) for(int j = 0; j < n; ++j)
#define fork(n) for(int k = 0; k < n; ++k)
#define forai(a) for(auto& i : a)
#define foraj(a) for(auto& j : a)
#define forak(a) for(auto& k : a)
#define forp(s, n, d) for(int p = s; p < n; p += d)
#define fast cin.tie(0); cout.tie(0); std::ios_base::sync_with_stdio(0);
#define pb(a) push_back(a);
#define pob(a) pop_back(a);
#define sorti(a) sort((a).begin(), (a).end());
#define sortm(a, n) sort(a, a + n);
#define reversi(a) reverse((a).begin(), (a).end());
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
#define yes cout << "Yes\n";
#define no cout << "No\n";
#define ans(a) cout << a << '\n';
#define endl cout << '\n';
#define res(a, n) (a).resize(n);
#define read(a, n) (a).resize(n); fori(n) cin >> a[i];
#define print(a) for (auto i : a) cout << i << ' ';
#define clear(a) (a).clear();
//#define int long long
//#define double long double

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<long long, long long> llll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<int, pair<int, int>>> viii;
typedef pair<int, pair<int, int>> iii;
typedef vector<pair<long long, long long>> vllll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;
typedef pair<char, char> cc;
typedef pair<pair<char, char>, char> ccc;
typedef vector<char> vc;
typedef pair<int, char> ic;
typedef pair<ii, char> iic;
typedef vector<bool> vb;
typedef set<int> si;
typedef vector<vector<ii>> vvii;
typedef vector<vector<iii>> vviii;
typedef vector<vector<llll>> vvllll;

const int INF = 2147483647;
const ll LONGINF = 9223372036854775807;
const ll MOD = 1e9 + 7;

string s;
list<char> help;

void solve()
{
    int n;
    cin >> n >> s;
    string est = "";
    fori(n) help.push_back(s[i]);
    auto i = help.begin();
    while (i != help.end())
    {
        est += *i;
        if (est.size() == 3)
        {
            if (est == "fox")
            {
                auto first = i, last = i;
                --first;
                --first;
                ++last;
                auto next = help.erase(first, last);
                if (next != help.begin()) --next;
                if (next != help.begin()) --next;
                i = next;
                est = "";
            }
            else
            {
                string temp = est;
                est = "";
                est += temp[1];
                est += temp[2];
                ++i;
            }
        }
        else ++i;
    }
    ans(help.size())
}

signed main()
{
    fast
    bool mult = false;
    if (mult)
    {
        int t;
        cin >> t;
        while (t--) solve();
    }
    else solve();
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){
    ll ans=0,n;
    map<ll,ll>cnt;
    scanf("%lld",&n);
    for(ll i=1;i<=n;i++){
        ll x;
        scanf("%lld",&x);
        cnt[x]++;
        if(i==1)continue;
        ans+=i-cnt[x];
    }
    printf("%lld\n",ans);
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define vi vector<ll>
#define mod 1000000007
#define pb push_back
#define vs vector<string>
#define pii pair<ll,ll>
#define unm unordered_map
#define mp make_pair
#define pq_max priority_queue ll;
#define pq_min priority_queue<ll,vi,greater<ll> >
#define all(n) n.begin(),n.end()
#define ff first
#define ss second
#define loop(i,a,b) for(int i=(a);i<=b;i++)
#define loopprev(i,a,b) for(int i=(a);i>=b;i--)
#define bitc(n) __builtin_popcount(n) //the numbers of one in bit representation
#define bitlz(n) __builtin_clz(n) //the number of zeroes at begining of the bit representation
#define bilcz(n) __builtin_ctz(n) //the number of zeroes at the end of the bit representation

template <typename T> T gcd(T a, T b){if(a%b) return gcd(b,a%b);
return b;}

void solve()
{
    ll n;
    cin>>n;

    vi a(n);
    loop(i,0,n-1)
    {
        cin>>a[i];
    }

    sort(all(a));

    ll ans=n*(n-1)/2;

    ll c=1;
    loop(i,0,n-1)
    {
        if(a[i]==a[i+1] && i+1<n)
        {
            c++;
        }
        else
        {
            ans=ans-c*(c-1)/2;
            c=1;
        }
    }

    cout<<ans<<"\n";

}

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


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll I=1167167167167167167;
ll Q=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";}
void yneos(bool a){if(a) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n";}

//おちこんだりもしたけれど、私はげんきです。
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin>>N;
	vector<int> p(N),q(N);
	iota(q.begin(),q.end(),1);
	rep(i,N) cin>>p[i];
	So(p);
	yneos(p==q);
}

#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<utility>
#include<bitset>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;

#define ll                  long long
#define ssort(v)            sort(v.begin(), v.end())
#define ssortr(v)           sort(v.begin(),v.end(),greater<int>())
#define uniquee(x)          x.erase(unique(x.begin(), x.end()),x.end())
#define sz(s)               s.size()
#define lg(s)               s.length()

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n; cin>>n;
	vector<int>A(n);
	map<int,int>mp;
	for(int i=0;i<n;i++){
		cin>>A[i];
		mp[A[i]]++;
	}
	for(auto it=mp.begin();it!=mp.end();++it){
		if(it->second!=1){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}


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

int n;
int main(){
	cin>>n;
	float k = n;
	float actual = 1.08*k;
	int actuals = floor(actual);
	if(actuals>206){
		cout<<":("<<endl;
	}else if(actuals == 206){
		cout<<"so-so"<<endl;
	}else{
		cout<<"Yay!"<<endl;
	}
	return 0;
}

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>PLL;
typedef pair<int, int>PII;
typedef pair<double, double>PDD;
#define I_int ll
inline ll read()
{
    ll x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9')
    {
        if(ch == '-')f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
#define read read()
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define multiCase int T;cin>>T;for(int t=1;t<=T;t++)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repp(i,a,b) for(int i=(a);i<(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define perr(i,a,b) for(int i=(a);i>(b);i--)
ll ksm(ll a, ll b, ll p)
{
    ll res = 1;
    while(b)
    {
        if(b & 1)res = res * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return res;
}
const int inf = 0x3f3f3f3f;
#define PI acos(-1)

const int maxn=1e5+100;

int main(){
	int n=read;
	int res=1.08*n;
	if(res<206) puts("Yay!");
	else if(res==206) puts("so-so");
	else puts(":(");

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

    int n;
    cin >> n;
    vector<long long> a0(n/2);
    vector<long long> a1(n/2);
    vector<long long> b0(n/2);
    vector<long long> b1(n/2);
    for (int i = 0; i < n/2; i++) {
        cin >> a0[i];
        cin >> a1[i];
    }
    for (int i = 0; i < n/2; i++) {
        cin >> b0[i];
        a0[i] -= b0[i];
        cin >> b1[i];
        a1[i] -= b1[i];
    }

    sort(a0.begin(), a0.end());
    sort(a1.begin(), a1.end());
    sort(b0.begin(), b0.end());
    sort(b1.begin(), b1.end());

    long long ans = 0;
    long long cand = 0;
    for (int i = 0; i < n/2; i++) {
        cand += b0[i] + b1[i];
    }
    ans = cand;
    for (int cnta = 0; cnta < n/2; cnta++) {
        cand += a0[n/2-1-cnta];
        cand += a1[n/2-1-cnta];
        ans = max(ans, cand);
    }

    cout << ans << endl;

    return 0;
}

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <unistd.h>
#include <stdlib.h>
#include <cassert>

using namespace std;
// using namespace atcoder;

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

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

const ll INF = 2e18;
const ll fact_table = 3200008;

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

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

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

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)();
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)

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

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

ll mypow(ll a, ll b, ll m = mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= m; b >>= 1;}(x *= a) %= m; b--;} return x;}
vec readvec(ll read) { vec res(read); for (int i = 0; i < read; i++) { cin >> res[i]; } return res;}
void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;}
void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;}
void line() { p("--------------------"); return;}

/*
ll fact[fact_table + 5], rfact[fact_table + 5];

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

bool multicase = false;

// ACLにするのを忘れない
ll n, l;
ll dp[100005][3][3];

ll idx = 0;

void solve() {
    cin >> n;
    vec a(n), b(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        cin >> b[i];
    }
    ll ans = 0;
    vec even, odd;
    for(int i=0;i<n;i++){
        ans += b[i];
        a[i] -= b[i];
        if (i % 2 == 0) {
            even.pb(a[i]);
        } else {
            odd.pb(a[i]);
        }
    }
    sort(even.begin(), even.end());
    sort(odd.begin(), odd.end());
    reverse(even.begin(), even.end());
    reverse(odd.begin(), odd.end());
    for(int i=0;i<n/2;i++){
        if (even[i] + odd[i] > 0) {
            ans += even[i] + odd[i];
        }
    }
    p(ans);
    return;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

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

// solve();
    return 0;
}


#include <bits/stdc++.h>
/// TONI BO$$ was here
/// #MLC

using namespace std;
long long v[100];
vector <int> supl;
vector <int> op;
int main()
{
    int i, s, k, ct;
    long long n;
    scanf("%lld", &n);
    v[0] = v[1] = 1;
    for(i = 2; i <= 100; i++)
        v[i] = v[i - 1] + v[i - 2];
    for(i = 1; v[i] <= n; i++);
    s = --i;
    if(s % 2 == 1)
        s--;
    n -= v[s];
    vector <int> supl;
    while(n)
    {
        for(i = 1; v[i] <= n; i++);
        i--;
        supl.push_back(s - i);
        n -= v[i];
    }
    /*for(auto it : supl)
        printf("%d\n",it);
    printf("\n");*/
    op.push_back(1);
    k = 1;
    if(supl.size() && supl[0] == 0)
        op.push_back(1);
    else
        k = 0;
    for(i = 1,ct = 4; i <= s; i++,ct = 7 - ct)
    {
        op.push_back(ct);
        if(k < supl.size() && supl[k] == i){
            if(ct == 3)
                op.push_back(1);
            else
                op.push_back(2);
            k++;
        }
    }
    printf("%d\n",op.size());
    for(auto it : op)
        printf("%d\n",it);

    return 0;
}

#include <bits/stdc++.h>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
const ul mod = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin.tie(NULL);
    ll x;
    cin >> x;
    ll next = (x / 100 + 1) * 100;
    cout << next - x << endl;
    return 0;
}


#include <iostream>
#include<cmath>
#include<vector>
#include<set>
#include <algorithm>
#include<map>
#include<string>
#include <chrono>
using namespace std;typedef long long ll;
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 1000000007 //問題による
#define FORA(i,I) for(const auto& i:I)
ll myceil(ll a,ll b){return (a+(b-1))/b;}//aをbで割る時の繰上げ
ll myfloor(ll a,ll b){return a/b;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll c,ll d){ll g=gcd(c,d);return (c/g)*d;}
ll PRS(ll N, ll P, ll M){if(P==0)return 1;if(P%2==0){ll t=PRS(N,P/2,M);return t*t % M;}return N*PRS(N,P-1,M);}//繰り返し自乗
ll count(ll a){
    ll i=1;
    ll c=0;
    for(i=1;i<=sqrt(a);i++){
        if(a%i==0 && i!=a/i){
            c+=2;
        }else if(a%i==0){
            c++;
        }
    }
    return c;
}
int main() {
    ll i,j,k,n;
    cin>>n;
    vector<ll>a(n),b(n);
    vector<ll>c;
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n){
        cin>>b[i];
    }
    ll mxa=0,mxb=0;
    ll pre=0;
    rep(i,n){
        mxa=max(mxa,a[i]);
        ll ans=max(pre,mxa*b[i]);
        cout<<ans<<endl;
        pre=ans;

    }
    return 0;

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,i,j,max1=0,max2=0,l=-1,r=-1;
  	cin>>n;
  	long a[n],b[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  for(i=0;i<n;i++)
    cin>>b[i];
  for(i=0;i<n;i++)
  {
    if(max2>r)
    r=max2;
		if(a[i]>max1)
        {
          l=i;
          max1=a[i];
        }
    	/*if(b[i]>max2)
        {
          r=i;
          max2=b[i];
        }*/
    max2=(long long)max1*b[i];

    if(r>max2)
    cout<<r<<endl;
    else
      cout<<max2<<endl;
  }
}


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

int main(void)
{
    char S, T;
    cin >> S >> T;

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

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rev(i,n,a) for(ll i=n-1;i>=a;i--)
#define f first
#define s second
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vpii vector<pair<int,int>>
#define vpll vector<pll>
#define pll pair<ll,ll>
#define secreterror() ios_base::sync_with_stdio(false);cin.tie(NULL);

void solve(){

   char ch;
   cin>>ch;
   char bb;
   cin>>bb;

   if(ch=='Y'){
       if(bb =='a'){
           cout<<"A"<<endl;
        }else if(bb=='b'){
            cout<<"B"<<endl;

        }else{
            cout<<"C"<<endl;
        }
    }
   else{
       cout<<bb<<endl;
   }

}

int main()
{
    secreterror()
    // ll t;
    // cin>>t;
    // while(t--){
        solve();
    // }

}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = a - 1; i >= b; i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--){
        ll N,A,B;
        cin >> N >> A >> B;
        if(N<A+B){
            cout << 0 << '\n';
        }
        else{
            ll ans=((N-A+1)*(N-A+1)%MOD)*((N-B+1)*(N-B+1)%MOD)%MOD;
            ll minus=0;
            //cout << ans << '\n';
            minus=((N-A+1)*(N-B+1)%MOD-(N-A-B+2)*(N-A-B+1)%MOD)%MOD;
            minus%=MOD;
            minus=minus*minus;
            minus%=MOD;
            ans-=minus;
            ans%=MOD;
            ans=(ans+MOD)%MOD;
            cout << ans << '\n';
        }
    }
}


//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 100005
ll C[MAXN];
ll D[MAXN];
vector<pair<ll,ll>> adj[MAXN];
ll dis[MAXN];

ll getDis(ll t, ll c, ll d)
{
    return(t + c + d/(t + 1LL));
}

void dijkstra(ll source)
{
    set<pair<ll,ll>> s;
    s.insert({dis[source], source});

    while(!s.empty())
    {
        pair<ll,ll> p = *s.begin();
        s.erase(p);
        ll u = p.second;
        //cout<<u<<endl;

        for(auto it: adj[u])
        {
            ll v = it.first;
            ll index = it.second;
            ll c = C[index];
            ll d = D[index];

            ll wait = max(0LL, (ll)sqrt(d) - dis[u]);
            ll ans = LLONG_MAX;
            for(ll i=0;i<=3;++i)
            {
                ll w = max(0LL, wait + i);
                ans = min(ans, getDis(w + dis[u], c, d));
                w = max(0LL, wait - i);
                ans = min(ans, getDis(w + dis[u], c, d));
            }

            //cout<<u<<" "<<v<<" "<<ans<<endl;

            if(dis[v] > ans)
            {
                s.erase({dis[v], v});
                dis[v] = ans;
                s.insert({dis[v], v});
            }
        }
    }
}

//Shit Man: There can be multiple edges as well
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll N,M; cin>>N>>M;

    for(ll i=1;i<=N;++i)
        dis[i] = LLONG_MAX;

    for(ll i=0;i<M;++i)
    {
        ll u,v; cin>>u>>v;
        adj[u].push_back({v, i});
        adj[v].push_back({u, i});
        cin>>C[i];
        cin>>D[i];
    }

    dis[1] = 0;
    dijkstra(1);

    if(dis[N] == LLONG_MAX)
        cout<<-1<<endl;
    else
        cout<<dis[N]<<endl;
}

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

typedef long long ll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define nl cout<<"\n"
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD ){ x += y; if( x >= m ) x -= m; }
template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD ){ x -= y; if( x < 0 ) x += m; }
ll mod( ll n, ll m=MOD ){ n%=m;if(n<0)n+=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e16;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

vector<array<ll,3>> gr[MAXN];
ll dist[MAXN];

void dijkstra(int start)
{
	dist[start] = 0;
	priority_queue<array<ll,2>> pq;

	pq.push({0,start});

	auto travel = [&]( ll c, ll d, ll t )
	{
		return c + ( d / (t+1) );
	};

	while( !pq.empty() )
	{
		ll time = -pq.top()[0];
		int node = pq.top()[1];
		pq.pop();

		if( dist[node] != time )
			continue;

		for( auto it : gr[node] )
		{
			int nxt = it[0];
			ll c = it[1];
			ll d = it[2];
			ll sq = sqrt(d) - time - 1;

			ll best = INF;
			ll mn = max(time, sq-5);
			for(ll del=mn;del<=mn+10;del++)
				best = min( best, (del-time) + travel(c,d,del) );

			if( dist[node] + best < dist[nxt] )
			{
				dist[nxt] = dist[node] + best;
				pq.push({-dist[nxt], nxt});
			}
		}
	}
}

void solve()
{
	int n,m;
	cin>>n>>m;

	for(int i=1;i<=n;i++)
		dist[i] = INF;

	for(int i=0;i<m;i++)
	{
		int u,v,c,d;
		cin>>u>>v>>c>>d;
		gr[u].pb({v,c,d});
		gr[v].pb({u,c,d});
	}
	dijkstra(1);

	ll ans = dist[n];
	if( ans == INF )
		ans = -1;
	cout<<ans,nl;
}

int main()
{
	#ifdef gupta_samarth
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	fastio();

	int t = 1;
	// cin>>t;
	for(int test=1;test<=t;test++)
	{
		// cout<<"Case #"<<test<<": ";
		solve();
	}

	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}