#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define INF (1e9)

vvi A;
int N, K;

// index が条件を満たすかどうか
bool isOK(ll val) {
  vvi B(N + 1, vi(N + 1, 0));

  // imosu
  // B[i+1][j+1] = A[0][0] ~ A[i][j]
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      B[i + 1][j + 1] = B[i + 1][j] + B[i][j + 1] - B[i][j];
      if (A[i][j] <= val) B[i + 1][j + 1] += 1;
    }
  }

  // for (int i = 0; i <= N; i++) {
  //   for (int j = 0; j <= N; j++) {
  //     cout << B[i][j];
  //   }
  //   cout << endl;
  // }
  // cout << endl;

  for (int i = 0; i <= N - K; i++) {
    for (int j = 0; j <= N - K; j++) {
      // A[i, j] ~ A[i+K, j+K]
      // cout << val << ":  "
      //      << "A[" << i << "][" << j << "] ~ A[" << i + K - 1 << "]["
      //      << j + K - 1 << "]" << endl;
      // for (int a = i; a < i + K; a++) {
      //   for (int b = j; b < j + K; b++) {
      //     if (A[a][b] <= val)
      //       cout << A[a][b] << ' ';
      //     else
      //       cout << "_ ";
      //   }
      //   cout << endl;
      // }
      ll s = B[i + K][j + K] - B[i + K][j] - B[i][j + K] + B[i][j];
      // cout << s << "*2 >= " << K << "*" << K << endl;
      // cout << endl;
      if (s * 2 >= K * K) return true;
    }
  }

  return false;
}

ll binary_search() {
  ll ng = -1;
  ll ok = 1e9 + 1;

  // ok と ng のどちらが大きいかわからないことを考慮
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;  // オーバーフロー注意

    // cout << ok << ' ' << mid << ' ' << ng << endl;
    if (isOK(mid))
      ok = mid;
    else
      ng = mid;
  }
  return ok;
}

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

  ll ans = binary_search();

  cout << ans << endl;
}

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int) x.size()
#define cat(x) cerr << #x << " = " << x << endl
#define all(x) x.begin(), x.end()
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)

using ll = long long;
using ld = long double;
using namespace std;

int n, k, MOD = 998244353;
ll res;

int f(int x) {
	if (2 * n < x) return 0;
	if (x - 1 <= n)	return x - 1;
	return 2 * n - x + 1;
}

int main() {
	scanf("%d%d", &n, &k);
	rep(s, 2, 2 * n) {
		int s2 = s - k;
		if (s2 <= 1) continue;
		res += 1LL * f(s) * f(s2);
	}
	printf("%lld\n", res);
}


#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
/*
  for(int i=0;i<n;i++){
  }
*/

int main(){
  int n;
  cin>>n;
  ll ans=0;
  for(int i=1;i*i<=n;i++){
    /*
    int ok=-1;
    int ng=n+1;
    while(ng-ok>1){
      int mid=(ok+ng)/2;
      if(mid*i>n) ng=mid;
      else ok=mid;
    }
    */
    ans+=n/i/i;
    for(int j=i+1;i*j<=n;j++){
      ans+=n/i/j *2;
    }
  }

  cout<<ans<<endl;
}

#pragma region shig_templates

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pairI2;
typedef pair<LL, LL> pairLL2;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
#define shig_for(i, a, b) for(int i = (a); i < (b); ++i)
#define shig_rep(i, n) shig_for(i, 0, n)
#define shig_forB(bit,a,b) for(int bit = (a); bit < (1<<(b)); ++bit)
#define shig_repB(bit,n) shig_forB(bit,0,n)
#define CINI(a) int (a); cin >> (a)
#define CINLL(a) LL (a); cin >> (a)
#define CINI2(a, b) int a, b; cin >> (a) >> (b)
#define CINLL2(a, b) LL a, b; cin >> (a) >> (b)
#define tmp int temp = 0
#define str string s

template<class T> void COUT(T&& t){ cout << t << endl; }
template<class T,class... Ts>
void COUT(T&& t,Ts&&... ts){ cout << t << " "; COUT(ts...); }
void CIN() {}
template<class T,class... Ts> void CIN(T&& t,Ts&&... ts){ cin >> t; CIN(ts...); }

#pragma endregion

LL check(LL x){
    LL cnt = 0;

    for(LL i = 1; i*i <= x; i++){
        if(i*i == x){
            cnt+=1;
            continue;
        }
        if(x % i == 0)cnt+=2;
    }

    return cnt;
}

int main(){
    LL ans = 0;
    LL K; CIN(K);

    for(LL i = 1; i <= K; i++){
        LL n = check(i);
        LL yoko = K / i;
        ans += n*yoko;
    }

    COUT(ans);
    //for(string& s : S) cin >> s;
    //cout << "Atcoder " << N << endl;
    //cout << fixed << setprecision(10) << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dbl;
#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
const ll INF = 1LL<<60;
const ll MOD = 1'000'000'007LL;
const dbl EPS = 1e-12;
const dbl PI = 3.14159265358979323846;
#define coutALL(x) for(auto i=x.begin();i!=--x.end();++i)cout<<*i<<' ';cout<<*--x.end()<<endl;
ll myceil(ll a,ll b){return (a+(b-1))/b;}
ll myfloor(ll a,ll b){return a/b;}
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}

int N, M;
vector<string> s;
vector<char> CHARS = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', '.'};

void printMat(const vector<string> &mat) {
    for (int i = 0; i < mat.size(); ++i) {
        cout << mat[i] << endl;
    }
}

ll count_blank(const vector<string> &mat) {
    ll cnt = 0;
    REP(i, N) {
        REP(j, N) {
            if (mat[i][j] == '.')
                cnt++;
        }
    }
    return cnt;
}

ll calc_score(const vector<string> &mat) {
    ll score = 0;
    int c = 0;
    REP(k, M) {
        string pat = s[k];
        bool found = false;
        REP(i, N) {
            if (found)
                break;
            REP(j, N) {
                bool horiz = true;
                bool vert = true;
                REP(p, pat.size()) {
                    if (mat[i][(j+p)%N] != pat[p]) {
                        horiz = false;
                        break;
                    }
                }
                if (horiz) {
                    c++;
                    found = true;
                    break;
                }
                REP(p, pat.size()) {
                    if (mat[(i+p)%N][j] != pat[p]) {
                        vert = false;
                        break;
                    }
                }
                if (vert) {
                    c++;
                    found = true;
                    break;
                }
            }
        }
    }
    if (c < M) {
        return int(round(1e8 * c * 1.0 / M));
    } else if (c == M) {
        ll d = count_blank(mat);
        return int(round(1e8 * 2 * N * N * 1.0 / (2 * N * N - d)));
    }
}

vector<string> solve_random() {
    vector<string> ret;
    REP(i, N) {
        string tmp_str = "";
        REP(j, N) {
            tmp_str += CHARS[rand()%9];
        }
        ret.push_back(tmp_str);
    }
    return ret;
}

signed main(){
    cout<<fixed<<setprecision(15);
    srand(time(nullptr));
    cin >> N >> M;
    s.assign(M, "");
    REP(i, M) cin>>s[i];

    vector<string> mat = solve_random();
    printMat(mat);
    // cout << calc_score(mat) << endl;
    return 0;
}

//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;
string to_string(char c) { return string(1,c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return (string)s; }
string to_string(string s) { return s; }
template<class A> string to_string(complex<A> c) {
	stringstream ss; ss << c; return ss.str(); }
string to_string(vector<bool> v) {
	string res = "{"; for(int i = 0; i < (int)v.size(); i++) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> string to_string(bitset<SZ> b) {
	string res = ""; for(size_t i = 0; i < SZ; i++) res += char('0'+b[i]);
	return res; }
template<class A, class B> string to_string(pair<A,B> p);
template<class T> string to_string(T v) { // containers with begin(), end()
	bool fst = 1; string res = "{";
	for (const auto& x: v) {
		if (!fst) res += ", ";
		fst = 0; res += to_string(x);
	}
	res += "}"; return res;
}
template<class A, class B> string to_string(pair<A,B> p) {
	return "("+to_string(p.first)+", "+to_string(p.second)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define wis(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
#else
#define wis(...) 0
#endif
typedef long long ll;
#define all(x) (x).begin(), (x).end()

int main(){
	ios::sync_with_stdio(0);
	double a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << fixed << setprecision(10) << (b * c + d * a) / (b + d) << '\n';
}


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

int A[100000];
int64_t are[100000];
int main() {
	int K, N, M; cin >> K >> N >> M;
	int sum = 0;
	REP(i, K) {
		int64_t a; cin >> a;
		int64_t a2 = a * M;
		A[i] = a2 / N;
		are[i] = (a2 - A[i] * N) << 32 | i;
		sum += A[i];
	}
	nth_element(are, are + K - M + sum, are + K);
	for(int i = K - 1; i >= K - M + sum; i--) A[are[i] & (1 << 20) - 1]++;
	REP(i, K) cout << A[i] << " ";
	return 0;
}

#include<stdio.h>
#include<iostream>
#include<string>
#include<sstream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<tuple>
using namespace std;
int main(){
    long long k;
    long long n;
    long long m;
    long long a[200000];
    long long sum=0;
    long long kiriage=0;
    vector<pair<double,int>> vec;
    vector<pair<int,int>> vec2;
    cin >> k;
    cin >> n;
    cin >> m;
    for (int i = 0; i < k; i++){
        cin >> a[i];
//        vec.push_back({(double)((m*a[i]/n)-floorl((double)(m*a[i]/n))),(double)i});
        vec.push_back({(double)(-m*a[i]+n*floorl((double)(m*a[i]/n))),(double)i});
        vec2.push_back({i,floor((double)(m*a[i]/n))});
        sum+=floor((double)(m*a[i]/n));
    }
    kiriage=m-sum;
    sort(vec.begin(),vec.end());
    for(int i = 0; i < kiriage; i++){
        vec2.at(vec.at(i).second).second+=1;
    }
    sort(vec2.begin(),vec2.end());
    for (int i = 0; i < k; i++){
        cout << (vec2.at(i).second);
      	cout << " ";
    }

}


#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
#define println(x) cout << x << endl
#define print(x) cout << x << " "
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const int MOD = 1e9+7;
int main(){
    int a, b;
    cin >> a >> b;
    REPR(i, b + 1){
        if(b / i > ceil(a / (double)i)){
            println(i);
            return 0;
        }
    }
    return 0;
}

// #include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <complex>
using namespace std;

/* alias */
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using Pi = pair<int, int>;
using Pll = pair<ll, ll>;
using T3 = tuple<int, int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vPi = vector<Pi>;
using vPll = vector<Pll>;

/* REP macro */
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define srep(i, s, n) for (int i = s; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define srrep(i, s, n) for (int i = s; i <= (n); ++i)
#define vrep(i, e) for (int i = e; i >= 0; i--)

/* define short */
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define seci [](Pi a, Pi b) { return a.se < b.se; }
#define secll [](Pll a, Pll b) { return a.se < b.se; }

/* Answer YesNo */
#define YESNO(bool) if (bool) { cout << "YES" << endl; } else { cout << "NO" << endl; }
#define YesNo(bool) if (bool) { cout << "Yes" << endl; } else { cout << "No" << endl; }
#define yesno(bool) if (bool) { cout << "yes" << endl; } else { cout << "no" << endl; }

/* print */
template<typename T>void pf(const T &t) { printf("%.10f\n", t); }
template<typename T>void pf(const T &a, const T &b) { printf("%.10f %.10f\n", a, b); }

template<typename T>void pr(const T &t) { cout << t << endl; }
template<typename T>void pr(const T &a, const T &b) { cout << a << " " << b << endl; }
template<typename T>void pr(const pair<T, T> &p) { cout << p.fi << " " << p.se << endl; }
template<typename T>void pr(const vector<T> &a) { for (T t : a) { cout << t << " "; } cout << endl; }
template<typename T>void pr(const vector<vector<T> > &a) { for (auto t : a) { pr(t); } }
template<typename T>void pr(const vector<pair<T, T> > &a) { for (auto p : a) { pr(p); } }
template<typename T>void pr(const map<T, T> mp) { for (pair<T, T> p : mp) { pr(p); } }

/* other */
template<typename T>ll sum(vector<T> &a) { ll tot = 0; for (T x : a) { tot += (ll)x; } return tot; }
template<typename T>int lowb(const vector<T> &a, const T &x) { return (int)distance(a.begin(), lower_bound(rng(a), x)); }
template<typename T>int uppb(const vector<T> &a, const T &x) { return (int)distance(a.begin(), upper_bound(rng(a), x)); }

/* const Num */
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
const int mod = 1e9 + 7;
const double PI = acos(-1);

int main() {
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) { cin >> a[i]; }

    map<int, int> mp;
    ll ans = 0;
    rep(j, n) {
        ans += j - mp[a[j]];
        mp[a[j]]++;
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

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

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

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

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

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

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

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

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

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

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

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

  vi a(3);
  REP(i, 3) {
    cin >> a[i];
  }

  sort(ALL(a));

  if(a[1] - a[0] == a[2] - a[1]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

using ll = long long;

#define endl '\n'

int main()
{
   ll i,j,n,q;

   cin >> n;

   string s;

   cin >> s;

   cin >> q;

   ll id=0;

   while(q--)
   {
       ll t,l,r;

       cin >> t >> l >> r;

       if(t==2)
       {
           id^=1;
           continue;
       }
       l--,r--;

       if(id==0)swap(s[l],s[r]);
       else
       {
           if(l<n)l+=n;
           else if(l>n)l-=n;
           if(r>=n)r-=n;
           else if(r<n)r+=n;
//cout << l << "  " << r << endl;
           swap(s[l],s[r]);
       }
   }

   if(id)
   {
       for(i=n;i<2*n;i++)cout<<s[i];
       for(i=0;i<n;i++)cout<<s[i];
       cout<<endl;
   }
   else
   {
       cout << s << endl;
   }

}


#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define all(v) v.begin(), v.end()
#define rep(i, begin, end) for(int i = begin; i < (int)(end); i++)
#define contains(v, x) (find(all(v), x) != v.end())
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<class T> T roundup(T a, T b){ return (a + b - 1) / b; }
const double PI = 3.14159265359;
const vector<int> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
const vector<int> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};
using ll = long long;
struct Edge{ int to; ll cost; Edge(int to, ll cost) : to(to), cost(cost) {} };
const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)1e9;
using P = pair<ll, int>;
using Graph = vector<vector<int>>;
/*#include <atcoder/all>
using namespace atcoder;
using mint = modint;*/

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    //mint::set_mod(MOD);

    string s;
    cin >> s;

    reverse(all(s));
    int n = s.size();
    ll ans = 0;
    vector<int> cnt(26);
    rep(i, 0, n - 1){
        if(s[i] == s[i + 1]){
            ans += i - cnt[s[i] - 'a'];
            fill(all(cnt), 0);
            cnt[s[i] - 'a'] = i + 2;
            i++;
        }else cnt[s[i] - 'a']++;
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
template<class T, class U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<class T, class U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T, class Compare = less<>> using Tree = tree<T, null_type, Compare, rb_tree_tag, tree_order_statistics_node_update>;

// DEBUG BEGIN
#ifdef LOCAL
template<class L, class R> ostream &operator<<(ostream &out, const pair<L, R> &p){
	return out << "(" << p.first << ", " << p.second << ")";
}
template<class Tuple, size_t N> struct TuplePrinter{
	static ostream &print(ostream &out, const Tuple &t){ return TuplePrinter<Tuple, N-1>::print(out, t) << ", " << get<N-1>(t); }
};
template<class Tuple> struct TuplePrinter<Tuple, 1>{
	static ostream &print(ostream &out, const Tuple& t){ return out << get<0>(t); }
};
template<class... Args> ostream &print_tuple(ostream &out, const tuple<Args...> &t){
	return TuplePrinter<decltype(t), sizeof...(Args)>::print(out << "(", t) << ")";
}
template<class ...Args> ostream &operator<<(ostream &out, const tuple<Args...> &t){
	return print_tuple(out, t);
}
template<class T> ostream &operator<<(enable_if_t<!is_same<T, string>::value, ostream> &out, const T &arr){
	out << "{"; for(auto &x: arr) out << x << ", ";
	return out << (arr.size() ? "\b\b" : "") << "}";
}
template<size_t S> ostream &operator<<(ostream &out, const bitset<S> &b){
	for(int i = 0; i < S; ++ i) out << b[i];
	return out;
}
void debug_out(){ cerr << "\b\b " << endl; }
template<class Head, class... Tail>
void debug_out(Head H, Tail... T){ cerr << H << ", ", debug_out(T...); }
void debug2_out(){ cerr << "-----DEBUG END-----\n"; }
template<class Head, class... Tail>
void debug2_out(Head H, Tail... T){ cerr << "\n"; for(auto x: H) cerr << x << "\n"; debug2_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#define debug2(...) cerr << "----DEBUG BEGIN----\n[" << #__VA_ARGS__ << "]:", debug2_out(__VA_ARGS__)
#else
#define debug(...) 42
#define debug2(...) 42
#endif
// DEBUG END

int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	auto __solve_tc = [&](int __tc_num){
		string s{"atcoder"}, t;
		cin >> t;
		int n = (int)t.size();
		int res = numeric_limits<int>::max();
		for(auto i = 0; i <= min(7, (int)t.size()); ++ i){ // first mismatch at i
			string obj(s.begin(), s.begin() + i);
			for(auto c = i != 7 ? s[i] + 1 : 'a'; c <= 'z'; ++ c){
				obj += c;
				vector<int> ord(n, -1);
				for(auto p = 0; p < (int)obj.size(); ++ p){
					for(auto i = 0; i < n; ++ i){
						if(!~ord[i] && obj[p] == t[i]){
							ord[i] = p;
							goto OK;
						}
					}
					goto DONE;
					OK:;
				}
				{
					int temp = (int)obj.size();
					Tree<int> tr;
					int cur = 0;
					for(auto &x: ord){
						if(!~x){
							x = temp ++;
						}
						cur += (int)tr.size() - tr.order_of_key(x);
						tr.insert(x);
					}
					debug(obj, cur);
					ctmin(res, cur);
				}
				DONE:;
				obj.pop_back();
			}
		}
		res == numeric_limits<int>::max() ? cout << "-1\n" : cout << res << "\n";
		return 0;
	};
	int __tc_cnt;
	cin >> __tc_cnt;
	for(auto __tc_num = 0; __tc_num < __tc_cnt; ++ __tc_num){
		__solve_tc(__tc_num);
	}
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                //
//                                   Coded by Aeren                                   //
//                                                                                //
////////////////////////////////////////////////////////////////////////////////////////


#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll i,j=0;
    string s,x,p,h[n+5];
    map<string,ll>a,b;
    for(i=0;i<n;i++){
        cin>>h[i];
        s=h[i];
        if(s[0]!='!'){
            x="!";
            x+=s;
            a[x]++;
        }
        else{
            b[s]++;
        }
    }
    for(i=0;i<n;i++){
            s=h[i];
        if(a[s]&&b[s]){
            for(ll g=1;g<s.size();g++)
                cout<<s[g];
            cout<<endl;
            return 0;
        }
    }
    puts("satisfiable");

}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=200010;
char p[maxn][12];
const ll mod=1000000009651;
struct pair_hash
{
    template<class T1, class T2>
    std::size_t operator() (const std::pair<T1, T2>& p) const
    {
        auto h1 = std::hash<T1>{}(p.first);
        auto h2 = std::hash<T2>{}(p.second);
        return h1 ^ h2;
    }
};
unordered_map<pair<ll,ll>,int,pair_hash>mp;
int main(){
    int n;
    char q[12];
    scanf("%d",&n);
    int num=0;
    ll k,f;
    for(int i=1;i<=n;i++){
        getchar();
        scanf("%s",q);
        if(q[0]!='!'){
            k=0;
            f=0;
            int w=strlen(q);
            for(int i=0;i<w;i++){
                k=(k*109139+(int)q[i])%mod;
                f=(f*8893+(int)q[i])%mod;
            }
            mp[make_pair(k,f)]=1;
        }
        else strcpy(p[num++],q);
    }
    int flag=0;
    for(int i=0;i<num;i++){
        k=0;
        f=0;
        int w=strlen(p[i]);
        for(int j=1;j<w;j++){
                k=(k*109139+(int)p[i][j])%mod;
                f=(f*8893+(int)p[i][j])%mod;
        }
        if(mp[make_pair(k,f)]>0){
             for(int j=1;j<w;j++){
               printf("%c",p[i][j]);
        }
            flag=1;
            break;
        }
    }
    if(flag==0)printf("satisfiable\n");
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B; cin >> A >> B;
  if(A+B >= 15 && B >= 8 ) cout << 1;
  else if(A+B >= 10 && B >= 3) cout << 2;
  else if(A + B >= 3) cout << 3;
  else cout << 4;

}

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

using namespace std;

//型短縮
#define ll long long

//マクロ定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int A, B;
  cin >> A >> B;
  int nyuko = A + B;
  if (nyuko >= 15 && B >= 8) {
    cout << 1;
  } else if (nyuko >= 10 && B >= 3) {
    cout << 2;
  } else if (nyuko >= 3) {
    cout << 3;
  } else {
    cout << 4;
  }
}


#include <iostream>

using namespace std;

int main()
{
    int x;
    std::cin >> x;
    if(x>=0)
    cout<< x;
    else
    cout<< 0<<endl;

    return 0;
}

#include <stdio.h>

int main(){
  	int N;

  	scanf("%d",&N);
  	printf("%d",N-1);
	return 0;
}


#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep_S(i,r,n) for(int i = r; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define RSort(a) sort(a.rbegin(), a.rend())
#define Output(a) cout << a << endl

typedef long long int ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vst;

const ll INF = 0x1fffffffffffffff;
const ll MOD = 1000000007;

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

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

    rep(i,n){
        b[a[i]%200]++;
    }
    rep(i,200){
        cnt = cnt + (b[i] * (b[i] - 1)) / 2;
    }
    cout << cnt << endl;
}

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

const int MaxN = 2e5;
const int MaxA = 1e9;

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

	int N, v;
	while(cin >> N){
		long ans = 0;
		vector<int> cnt(200);
		for(int i = 0; i < N; i++){
			cin >> v;
			v = v % 200;
			ans += cnt[v];
			cnt[v] += 1;
		}
		cout << ans << '\n';
	}
}


#include <bits/stdc++.h>

using namespace std;

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

void dfs_root(vector<vector<long long>>& Graph, vector<long long>&root, vector<bool>&seen, long long cur){
    for(auto it : Graph[cur]){
        if(!seen[it]){
            seen[it] = true;
            root[it] = cur;
            dfs_root(Graph, root, seen, it);
        }
    }
}

void dfs_add(vector<vector<long long>>& Graph, vector<long long>&root, vector<bool>&seen, vector<long long> &add,long long cur, long long s){

    // current の addを処理
    seen[cur] = true;
    root[cur] = add[cur] + s;

    for(auto it : Graph[cur]){
        if(!seen[it]){
            dfs_add(Graph, root, seen, add, it, s + add[cur]);
        }
    }
}

int main(){

    long long n;
    cin >> n;

    vector<long long> a(n),b(n);
    vector<vector<long long>> Graph(n);
    rep(i,n - 1){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        Graph[a[i]].push_back(b[i]);
        Graph[b[i]].push_back(a[i]);
    }

    long long q;
    cin >> q;

    vector<long long> root(n, -1);
    vector<bool>      seen(n, false);
    seen[0] = true;
    dfs_root(Graph, root, seen, 0);

    vector<long long> add(n,0);
    rep(i,q){
        long long t,e,x;
        cin >> t >> e >> x;

        long long A,B;
        A = a[e - 1];
        B = b[e - 1];

        if(t == 2)
            swap(A,B);

        if(root[A] == B){
            add[A] += x;
        } else {
            add[0] += x;
            add[B] -= x;
        }
    }

    rep(i,n) root[i] = 0;
    rep(i,n) seen[i] = false;

    seen[0] = true;
    dfs_add(Graph, root, seen , add, 0, 0);

    rep(i,n){
        cout << root[i] << endl;
    }

    return 0;
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define pp pair<ll,ll>
#define ll int
#define True 1
#define gcd __gcd
#define range(i,a,b,c) for(ll i=a;i<b;i+=c)
#define int long long
#define lb lower_bound
#define ub upper_bound
#define False 0
#define maxa(p,q) *max_element(p,q)
#define mina(p,q) *min_element(p,q)
#define pq priority_queue<int>
#define all(v) v.begin(),v.end()
#define len(p) p.size()
#define append pb
#define foi(p,n) for(int i=p;i<n;i++)
#define ini(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define fi first
#define swap(i,j) {int temp=i,i=j,j=temp;}
#define sec second
#define mp make_pair
#define tc while(t--)
#define N ((ll)1001)
#define gtc(a,b) cout<<"Case #"<<a<<": "<<b<<endl;
#define va(n) vector<ar<ll,n>>
#define fo(n) for(int i=0;i<n;i++)
#define rev(n) for(int i=n-1;i>=0;i--)
#define foj(m,n) for(int j=m;j<n;j++)
#define INF 9999999999
#define ar array
#define vp vector<pair<int,int>>
#define vc vector<int>
#define print(p) cout<<p<<"\n";
#define pr(p) cout<<p<<" ";
#define pr2(p,q) cout<<p<<" "<<q<<endl;
#define pr3(p,q,r) cout<<p<<" "<<q<<" "<<r<<endl;
#define pr4(p,q,r,s) cout<<p<<" "<<q<<" "<<r<<" "<<s<<endl;
#define pra(a) for(ll i: a) cout<<i<<" "; cout<<endl;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define isvalid(i,j) (0<=i and i<n and 0<=j and j<m)
#define gh fflush(stdout)
#define why {print("LOL") return 0;}
using namespace std;

ll n,m,t,k,r,maxn,x,y,flag=0,l1,r1,l2,r2,parity[2]={0,0},ok,q,need,p;
ll mod=1e9+7;

signed main()
{
fio
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("all.txt", "w", stdout);
#endif

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

tc{
	cin>>n>>m;
	va(3) a[n+1];
	multiset<ar<ll,2>> s;
	fo(m) {
		ll x,y,c,d;
		cin>>x>>y>>c>>d;
		a[x].pb({y,c,d});
		a[y].pb({x,c,d});
	}
	ll dis[n+1];
	fo(n+1) dis[i]=-1;
	dis[1]=0;
	s.insert({0,1});
	while(s.size()){
		auto i=*s.begin();
		s.erase(s.begin());
		for(auto j: a[i[1]]){
			for(ll k=max(i[0],(ll)sqrt(j[2])-5);k<=max(i[0],(ll)sqrt(j[2])+5);k++)
			if(k>=i[0] and (dis[j[0]]==-1 or dis[j[0]]>k+j[1]+j[2]/(k+1))){
				if(s.find({dis[j[0]],j[0]})!=s.end())
					s.erase(s.find({dis[j[0]],j[0]}));
				dis[j[0]]=k+j[1]+j[2]/(k+1);
				s.insert({dis[j[0]],j[0]});
			}
		}
	}
	print(dis[n])
}

return 0;}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define int ll
#define ld long double
#define reps(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rep(i,n) reps(i,0,n)
#define rreps(i,s,n) for(int i=(int)(s-1);i>=n;i--)
#define rrep(i,n) rreps(i,n,0)
#define all(v) (v).begin(),(v).end()
#define mset(a,n) memset(a,n,sizeof(a))
#define eras(v,n) (v).erase(remove(all(v),n),(v).end())
#define uni(v) sort(all(v));(v).erase(unique(all(v)),(v).end())
#define bcnt(i)  __builtin_popcount(i)
#define fi first
#define se second
constexpr ll INF = 1e18;
constexpr ll MOD = 1000000007;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>T min(vector<T> &v) { return *min_element(v.begin(),v.end()); }
template<class T>T max(vector<T> &v) { return *max_element(v.begin(),v.end()); }
template<class T>T modpow(T a, T b, T m) { a %= m; T r = 1; while (b > 0) { if (b & 1) r = (r * a) % m; a = (a * a) % m; b >>= 1; } return r; }
ll modinv(ll a,ll m=MOD) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
template<class T>string radixconv(T n, T k){ string s; while(n/k){ s=to_string(n%k)+s; n/=k; } s=to_string(n%k)+s; return s; }

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(11);
    cerr << fixed << setprecision(6);
    int ans=INF;
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    rep(i,n){
        cin >> a[i] >> b[i];
        chmin(ans,a[i]+b[i]);
    }
    rep(i,n)rep(j,n)if(i!=j)chmin(ans,(int)max(a[i],b[j]));
    cout << ans << endl;
    return 0;
}

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

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

#define rep(i, n) for(int i = 0;i < n;i++)
#define rep1(i, n) for(int i = 1;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

#define ALL(a)  (a).begin(),(a).end()

vector<vector<ll>> near8={{-1,1},{0,1},{1,1},{-1,0},{1,0},{-1,-1},{0,-1},{1,-1}};
vector<vector<ll>> near4={{0,1},{-1,0},{1,0},{0,-1}};

ll INF = INT64_MAX;

bool ll_sqrt(ll x, ll& lower_bound, ll& upper_bound)
{
	constexpr ll ll_max = numeric_limits<ll>::max();

	bool first_boost = true;

	lower_bound = 0;
	upper_bound = x;
	while (upper_bound - lower_bound > 1)
	{
		if (first_boost)
		{
			ll guess = (ll)sqrt((double)x);
			lower_bound = max(guess - 1, (ll)0);
			upper_bound = lower_bound + 3;
			first_boost = false;
		}

		ll newval = (lower_bound + upper_bound) / 2;
		if ((newval != 0) && (newval > ll_max / newval))  // newval*newval becomes overflow
			upper_bound = newval;  // because overflow means newval is too big
		else
		{
			ll newval_sqr = newval * newval;
			if (newval_sqr < x)
				lower_bound = newval;
			else
				upper_bound = newval;
		}
	}

	if ((upper_bound != 0) && (upper_bound > ll_max / upper_bound))
	{
		if (lower_bound * lower_bound == x)
			upper_bound = lower_bound;
	}
	else
	{
		if (lower_bound * lower_bound == x)
			upper_bound = lower_bound;
		else if (upper_bound * upper_bound == x)
			lower_bound = upper_bound;
	}
	bool is_exact = (lower_bound == upper_bound);
	return is_exact;
}

ll ll_ceil(ll x, int digit);
ll ll_floor(ll x, int digit);

ll ll_floor(ll x, int digit)
{
	if (x < 0)
		return -ll_ceil(-x, digit);

	ll div = 1;
	while (digit != 0)
	{
		div *= 10;
		digit--;
	}
	ll modval = x % div;
	ll ans = x - modval;
	return ans;
}

ll ll_ceil(ll x, int digit)
{
	if (x < 0)
		return -ll_floor(-x, digit);

	ll div = 1;
	while (digit != 0)
	{
		div *= 10;
		digit--;
	}
	ll modval = x % div;
	ll ans = x - modval;
	if (modval != 0)
		ans += div;
	return ans;
}

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

ll H,W;
vector<vector<char>> map1(501, vector<char>(501,'#'));

bool solve(ll h, ll w){
	ll nexth=0;
	ll nextw=0;

	for(vector<ll> to:near4){
		nexth = h+to[0];
		nextw = w+to[1];
		if(nexth < 0 || nexth >=H || nextw < 0 || nextw >=W || map1[nexth][nextw] == '#'){
			continue;
		}
		if(map1[nexth][nextw] =='g'){
			return true;
		}
		map1[nexth][nextw]='#';
		if(solve(nexth, nextw)){
			return true;
		};
	}

	return false;
}

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

	ll A[N];
	ll in ;

	UnionFind nums(200002);

	rep(i,N){
		cin >> A[i];
	}

	ll ans=0;

	ll a, b;
	rep(i, N/2){
		a = A[i];
		b = A[N-i-1];
		if(!nums.same(a,b)){
			ans++;
			nums.unite(a,b);
		}
	}

	cout << ans << endl;

  return 0;
}


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

int n;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    printf("%d %d\n", (i*2 + 1) % n + 1, (i*2 + 2) % n + 1);
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using vtll = vector<tll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); }
void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); }
template<typename T,typename U>
ostream& operator<<(ostream& os, const pair<T,U>& p) {
    cerr << ' ' <<  p.x << ',' << p.y; return os; }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template<typename T,typename U>
ostream& operator<<(ostream& os, const map<T,U>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
struct d_ {
    template<typename T> d_& operator,(const T& x) {
        cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define deb(X ...) dbg(#X, "=", X);
#define EPS (1e-10)
#define INF (1LL<<61)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main(void) {
    ios_base::sync_with_stdio(false);
    ll n; cin >> n;
    F(n) cout << 1+(2*i+1)%n << " " << 1+(2*i)%n << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#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;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
struct point
{
    ll x, y;
};
int main()
{
    FAST
        // freopen("input1.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
        /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
        ll n,
        m;
    cin >> n >> m;
    ve<string> arr(n);
    rep(i, 0, n)
    {
        cin >> arr[i];
    }
    ll cnt = 0, ans = 0;
    rep(i, 0, n)
    {
        cnt=0;
        arr[i].pb('#');
        rep(j, 0, m + 1)
        {
            if (arr[i][j] == '.')
            {
                cnt++;
            }
            else if (cnt!=0)
            {
                ans += cnt - 1;
                cnt = 0;
            }
            // cout<<"cnt.. "<<cnt<<"\n";
        }
        arr[i].pop_back();
    }
    rep(j, 0, m)
    {
        cnt=0;
        rep(i, 0, n)
        {
            if (arr[i][j] == '.')
            {
                cnt++;
            }
            else if (cnt!=0)
            {
                ans += cnt - 1;
                cnt = 0;
            }
        }
        if (cnt!=0)
        ans += cnt - 1;
    }
    cout << ans << "\n";
}

#include <bits/stdc++.h>

#define ll long long
using namespace std;
int n,m;
vector<int> w;
vector<tuple<int,int>>brg; // v / l

vector <vector<int>> adjList;

vector <int> segmentTree;

void build(int l, int r,int index){
    if (l==r) segmentTree[index]=get<1>(brg[l]);
    else{
        int mid = l+r >>1;
        build(l,mid,index*2);
        build(mid+1,r,index*2+1);
        segmentTree[index]=max(segmentTree[index*2],segmentTree[index*2+1]);
    }
}

int get (int tl, int tr, int l, int r, int index) {
    if (l>r) return -1;
    if (l==tl && r==tr) return segmentTree[index];
    int mid = tl+tr >>1;
    return max(get(tl,mid,l,min(r,mid),index*2),get(mid+1,tr,max(l,mid+1),r,index*2+1));
}

vector<vector<ll>> dp;

long long getLongest(int f, int t){
    if (dp[t][f]!=-1) return dp[t][f];
    if (t==f) return 0;
    assert(t>f);
    ll re=adjList[t][f];
    int t2=t-1;
    while(t2>f){
        ll tmp1=getLongest(f,t2);
        ll tmp2=getLongest(t2,t);
        ll tmp=tmp1+tmp2;
        if (re<tmp){
            re=tmp;
        }
        t2--;
    }
    return dp[t][f]=re;
}

int main() {

    cin>>n>>m;
    w.assign(n,0);
    for (int i=0;i<n;i++){
        cin>>w[i];
    }
    sort(w.begin(),w.end());

    brg.assign(m,{0,0});
    for (int i=0;i<m;i++) {
        cin>>(get<1>(brg[i]))>>get<0>(brg[i]);
        if (get<0>(brg[i])<w[0]) {
            cout<<-1<<endl;
            return 0;
        }
    }
    sort(brg.begin(),brg.end());

    segmentTree.assign(4*m+1,-1);
    build(0,m-1,1);

    long long re =INT_MAX;

    adjList.assign(n,vector<int>());
    for (int i=0;i<n;i++){
        adjList[i].assign(i,0);
    }
    do{
        long long retmp=0;
        vector<long long> acu(n+1);
        for (int i=0;i<n;i++) acu[i+1]=acu[i]+w[i];
        // from i to j = acu[j+1]-acu[i]

        for (int i=1;i<n;i++){
            for (int j=i-1;j>=0;j--){
                ll wei=acu[i]-acu[j];
                wei+=w[i];
                auto it = upper_bound(brg.begin(),brg.end(),make_tuple(wei,INT_MIN));
                if (it==brg.begin()) {
                    adjList[i][j]=0;
                    continue;
                }
                it--;
                int l=it-brg.begin();
                adjList[i][j]=get(0,m-1,0,l,1);
            }
        }

        dp.clear();
        dp.assign(n,vector<ll>(n,-1));

        retmp=getLongest(0,n-1);
        if (re>retmp){
            re=retmp;
        }
    }
    while (next_permutation(w.begin(),w.end()));
    cout<<re<<endl;
    return 0;
}


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

// @@ !! LIM()

struct MyExc : exception {};

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, L; cin >> N >> L;
  vector<ll> A(N + 2), B(N + 2);
  for (ll i = 1; i <= N; i++) cin >> A[i];
  for (ll i = 1; i <= N; i++) cin >> B[i];
  A[0] = B[0] = 0;
  A[N+1] = B[N+1] = L+1;

  auto func = [&](ll st, ll en, ll dir) -> ll {
    ll ret = 0;

    if (dir > 0) {

      if (B[en] + 1 != B[en + 1]) return -1;
      ll p = st;
      ll q = st;
      while (p <= en) {
	while (q <= en && B[p] != A[q] - (q - p)) q++;
	ret += q - p;
	while (p < q   && B[p] == A[q] - (q - p)) p++;
      }
      return ret;

    }else {

      if (B[st] - 1 != B[st - 1]) return -1;

      ll p = en;
      ll q = en;
      while (p >= st) {
	while (q >= st && B[p] != A[q] + (p - q)) q--;
	ret += p - q;
	while (q < p   && B[p] == A[q] + (p - q)) p--;
      }
      return ret;
    }
  };

  ll st = 0;
  ll ans = 0;
  ll dir = 0;
  try {
    for (ll i = 0; i < N + 2; i++) {
      if (A[i] == B[i]) {
	if (st < i) {
	  ans += func(st, i - 1, dir);
	}
	st = i + 1;
      }else if (i == st) {
	if (B[i] < A[i]) dir = -1;
	else             dir = 1;
      }else if (dir == 1 && B[i] < A[i]) {
	throw MyExc();
      }else if (dir == -1 && B[i] > A[i]) {
	ans += func(st, i - 1, dir);
	st = i;
	dir = 1;
      }
    }
    cout << ans << endl;
  }catch(const MyExc& e) {
    cout << -1 << endl;
  }

  return 0;
}

#include <iostream>
using namespace std;
typedef long long ll;

const ll INF = 1000000000000000000;

int main()
{
    int n;
    ll x;
    cin >> n >> x;
    ll a[105];
    for(int i = 0; i < n; i++) cin >> a[i];
    ll ans = INF;
    for(int c = 1; c <= n; c++){
        ll dp[102][102];
        for(int j = 0; j <= c; j++){
            for(int k = 0; k < c; k++) dp[j][k] = -INF;
        }
        dp[0][0] = 0;
        for(int i = 0; i < n; i++){
            ll d[102][102];
            for(int j = 0; j <= c; j++){
                for(int k = 0; k < c; k++) d[j][k] = dp[j][k];
            }
            for(int j = 1; j <= c; j++){
                for(int k = 0; k < c; k++) d[j][k] = max(d[j][k], dp[j - 1][(k + c - a[i] % c) % c] + a[i]);
            }
            swap(dp, d);
        }
        if(dp[c][x % c] >= 0) ans = min(ans, (x - dp[c][x % c]) / c);
    }
    cout << ans << endl;
}


//#pragma GCC optimize ("O3", "unroll-loops")
//#pragma GCC target ("avx2")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define all_of(v) (v).begin(), (v).end()
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define fi first
#define se second
//const int MAXN = 300005;
//const LL INF = (LL) 1e9 + 8763;
const LL MOD = (LL) 1e9 + 7;
using namespace std;
template <class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template <class T> using maxheap = priority_queue<T, vector<T>, less<T>>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// function<vector<int>(int, int, int)> func = [&] (int m, int l, int c) {};

LL qpow(LL a, LL pw, LL mod) {
	LL res = 1;
	a %= mod;
	while (pw) {
		if (pw & 1) res = res * a % mod;
		a = a * a % mod;
		pw >>= 1;
	}
	return res;
}
LL mod_inv(LL a, LL mod) {
	// for prime
	a %= mod;
	return qpow(a, mod - 2, mod);
}

/* fac, C, H */
const int LIM = 2000005; // Double for H(n, k)
LL fac[LIM], finv[LIM];
void init_fac(LL mod) {
	fac[0] = finv[0] = 1;
	for (int i = 1; i < LIM; i++) {
		fac[i] = fac[i - 1] * i % mod;
		finv[i] = qpow(fac[i], mod - 2, mod);
	}
}
LL C(LL n, LL k, LL mod) {
	assert(n < mod && k < mod); // otherwise, use Lucas
	if (k > n || n < 0 || k < 0) return 0;
	return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

void solve() {
	init_fac(MOD);
	LL n, m, k;
	cin >> n >> m >> k;
	if (n - m > k) {
		cout << "0\n";
		return;
	}
	cout << (C(n + m, n, MOD) - C(n + m, m + k + 1, MOD) + MOD) % MOD << '\n';
}

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

	int tc = 1;
//	cin >> tc;
	for (int i = 1; i <= tc; i++) {
		solve();
	}

	return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define int long long

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

    int dp[31][31];
    dp[0][0] = 1;
    for (int i = 0; i <= 30; ++i) {
        for (int j = 0; j <= 30; ++j) {
            if (i + j == 0) continue;
            dp[i][j] = 0;
            if (i - 1 >= 0) dp[i][j] += dp[i - 1][j];
            if (j - 1 >= 0) dp[i][j] += dp[i][j - 1];
        }
    }

    int a, b, k;
    cin >> a >> b >> k;

    while (a + b) {
        if (a >= 1 && dp[a - 1][b] >= k) cout << 'a', a--;
        else {
            assert(b);
            cout << 'b';
            if (a) k -= dp[a - 1][b];
            b--;
        }
    }
}


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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  if (a + b >= a + c && a + b >= b + c)
  {
    cout << a + b;
  }
  else if (a + c >= a + b && a + c >= b + c)
  {
    cout << a + c;
  }
  else
  {
    cout << b + c;
  }
}

#include <iostream>
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
#define ll long long
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define vll vector<ll>
using namespace std;

//fast I/O
auto optimizer = []() {  // makes I/O fast
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  return 0;
}();

// Snippet for computing ncr and factorials
// All computations done modulo 'mod'
vll fact,ifact;
void compute_factorials(ll n)
{
    fact.resize(n+1);
    ifact.resize(n+1);
    fact[0]=1;ifact[0]=1;
    fact[1]=1;ifact[1]=1;
    vll inverse_of_number(n+1);
    inverse_of_number[0]=1;   // inverse is not 1 but taken for easy code
    inverse_of_number[1]=1;
    for(ll i=2;i<=n;i++)
    {
        inverse_of_number[i] = (inverse_of_number[mod % i] * (mod - (mod / i)) ) % mod;
        fact[i]=(fact[i-1]*i)%mod;
        ifact[i]=(ifact[i-1]*inverse_of_number[i])%mod;
    }
    return;
}
ll ncr(ll n,ll r)
{
    if(n<0 || r>n || r<0)
        return 0;
    ll ans=fact[n];
    ans=(ans*ifact[r])%mod;
    ans=(ans*ifact[n-r])%mod;
    return ans;
}

//DSU start ---
ll find_sets(vector<ll> &v, ll a){
    if(v[a] < 0){
        return a;
    }
    return v[a] = find_sets(v,v[a]);
}

void union_sets(vector<ll> &v, ll a, ll b){
    a = find_sets(v,a);
    b = find_sets(v,b);
    if(a != b){
        if(v[a] < v[b]){
            v[a] += v[b];
            v[b] = a;
        }
        else{
            v[b] += v[a];
            v[a] = b;
        }
    }
}

//---end DSU

//power mode where (x^y) % p is calculated in log (y) time
int power(ll x, ll y, ll p)
{
    int res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

void print(vector<ll> &vect){
    for(auto num : vect){
        cout << num << " ";
    }
    cout << endl;
}

void printll(vector<vector<ll>> &vect){
    for(auto num : vect){
        for(auto itr : num){
            cout << itr << " ";
        }
        cout << endl;
    }
}

//seive
ll N = 1e5;
vll lpf(N+1,0);
void leastPrimeFactor(){
    lpf[1] = 1;
    for (int i = 2; i <= N; i++){
        if(lpf[i] == 0){
            lpf[i] = i;
            for (int j = 2*i; j <= N; j += i){
                if (lpf[j] == 0){
                    lpf[j] = i;
                }
            }
        }
    }
}

//Code -

int main() {
	ll n,i,j,t,m,temp,k,z;
    ll a,b,c;
    cin >> a >> b >> c;
    cout << max((a+b),max((b+c),(c+a)));
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int N;
  cin>>N;
  vector<string> S(N);
  rep(i,N) cin>>S[i];

  vector<vector<int>> D(N,vector<int> (N,0));
  rep(i,N) rep(j,N) D[i][j]=S[i][j]-'0';
  rep(i,N) D[i][i]=1;

  for(int k=0;k<N;k++){
    for(int i=0;i<N;i++) for(int j=0;j<N;j++){
      if(D[i][k]&&D[k][j]) D[i][j]=1;
    }
  }

  vector<int> num(N,0);
  rep(i,N) rep(j,N) num[j]+=D[i][j];

  double ans=0.0;
  rep(i,N) ans+=1.0/(double)num[i];

  cout<<fixed<<setprecision(15)<<ans<<endl;

  return 0;
}

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

template <typename T>
inline void read(T &num) {
    T x = 0, f = 1; char ch = getchar();
    for (; ch > '9' || ch < '0'; ch = getchar()) if (ch == '-') f = -1;
    for (; ch <= '9' && ch >= '0'; ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ '0');
    num = x * f;
}

int n, e[N][N], cnt[N];
long double ans;
bool vis[N];

void dfs(int x) {
    vis[x] = 1; cnt[x]++;
    for (int i = 1; i <= n; i++) {
        if (e[x][i] && !vis[i]) dfs(i);
    }
}

long double calc(int x) {
    long double res = x * 1.0 / (x+1);
    return res;
}

int main() {
 //   freopen("1.in", "r", stdin);
    read(n); ans = n;
    for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) {
        scanf("%1d", &e[i][j]);
    }
    for (int i = 1; i <= n; i++) {
        memset(vis, 0, sizeof(vis));
        dfs(i); cnt[i]--;
    }
    for (int i = 1; i <= n; i++) {
        long double now = calc(cnt[i]);
        ans -= now;
    }
    printf("%.20Lf\n", ans);
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    int p = 0;
    int i = 0;
    while(p < N) {
        p += i + 1;
        i += 1;
    }
    cout << i << endl;
}

#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

#if __cplusplus >= 201402L
#include <shared_mutex>
#endif

#if __cplusplus >= 201703L
#include <any>
#include <charconv>
// #include <execution>
#include <filesystem>
#include <optional>
#include <memory_resource>
#include <string_view>
#include <variant>
#endif

#if __cplusplus > 201703L
#include <barrier>
#include <bit>
#include <compare>
#include <concepts>
#if __cpp_impl_coroutine
# include <coroutine>
#endif
#include <latch>
#include <numbers>
#include <ranges>
#include <span>
#include <stop_token>
#include <semaphore>
#include <source_location>
#include <syncstream>
#include <version>
#endif

using namespace std;
int main(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long n;
    cin>>n;
    long ans;
    for(int i=1;i<pow(10,5);i++){
    	ans=i*(i+1);
    	ans=ans/2;
    	if(ans>=n){cout<<i;
    		break;}

    }

  }


//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define P pair<ll,ll>
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

ll lmax(ll x,ll y){
  if(x < y) return y;
  else return x;
}

ll lmin(ll x, ll y){
  if(x > y)return y;
  else return x;
}

ll gen(ll x,ll y){
  if(y == 0)return 1;
  if(y == 1)return x;
  if(y%2 == 1){
    return ((x%MOD)*gen(x,y-1)%MOD)%MOD;
  }else{
    ll res = gen(x,y/2)%MOD;
    return ((res%MOD)*(res%MOD))%MOD;
  }
}

ll gcd(ll x, ll y){
  if(x < y) swap(x,y);
  if(y == 0) return x;
  return gcd(y,x%y);
}

ll lcm(ll x,ll y){
  ll s = gcd(x,y);
  x /= s;
  y /= s;
  return x*y*s;
}

int main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1;i <= n;i++){
    int m = i;
    bool ok1 = true,ok2 = true;
    while(m > 0){
      if(m%10 == 7){
        ok1 = false;
      }
      m /= 10;
    }
    m = i;
    while(m > 0){
      if(m%8 == 7){
        ok2 = false;
      }
      m /= 8;
    }
    if(ok1 && ok2)ans++;
  }
  cout  << ans << endl;

  return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
	ll cost;
};
using Graph = vector<vector<Edge>>;

const int MAX = 10000000;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/****** define constant end ********/
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k)
		return 0;
	if (n < 0 || k < 0)
		return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1)
		res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

#ifdef LOCAL
#define debug(...)                                                    \
	std::cerr << "LINE: " << __LINE__ << "  [" << #__VA_ARGS__ << "]:", \
		debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << std::endl; }

template <typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	std::cerr << " " << h;
	if (sizeof...(t) > 0) std::cout << " :";
	debug_out(t...);
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
	return os << pa.first << " " << pa.second;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
	for (std::size_t i = 0; i < vec.size(); i++)
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}

template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b) {
	return a < b && (a = b, true);
}

template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b) {
	return a > b && (a = b, true);
}

int solve() {
	ll n;
	cin >> n;
	vl p(n);
	vector<bool> m(200005);
	REP(i, n){
		cin >> p[i];
	}
	ll now = 0;
	REP(i, n){
		m[p[i]] = true;
		FOR(j, now, 200005){
			if(!m[j]){
				cout << j << endl;
				if(now < j){
					now = j;
				}
				break;
			}
		}
	}
	return 0;
}

int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long i64;

const int MAX_N = 200000 + 5;
const int A = 1e8;

int n[2], N, Q;
int a[2][MAX_N];
i64 ans;

int Root[2], total_node;
struct SegmentNode {
    i64 cnt, sum;
    int ls, rs;
} node[MAX_N * 50];

inline void segment_update(int i) {
    node[i].cnt = node[node[i].ls].cnt + node[node[i].rs].cnt;
    node[i].sum = node[node[i].ls].sum + node[node[i].rs].sum;
}
void segment_modify(int &i, int l, int r, int mp, int mv) {
    i = i ? i : ++ total_node;
    if (l == r) {
        node[i].cnt += mv;
        node[i].sum += 1ll * mv * l;
        return;
    }
    int mid = l + r >> 1;
    if (mp <= mid) {
        segment_modify(node[i].ls, l, mid, mp, mv);
    } else {
        segment_modify(node[i].rs, mid + 1, r, mp, mv);
    }
    segment_update(i);
}
i64 qcnt, qsum;
void segment_query(int i, int l, int r, int ql, int qr) {
    if (!i || ql <= l && r <= qr) {
        qcnt += node[i].cnt;
        qsum += node[i].sum;
        return;
    }
    int mid = l + r >> 1;
    if (ql <= mid) {
        segment_query(node[i].ls, l, mid, ql, qr);
    }
    if (mid + 1 <= qr) {
        segment_query(node[i].rs, mid + 1, r, ql, qr);
    }
}

int main() {
    scanf("%d%d%d", &n[0], &n[1], &Q);
    segment_modify(Root[0], 0, A, 0, n[0]);
    segment_modify(Root[1], 0, A, 0, n[1]);
    for (int i = 1; i <= Q; i ++) {
        int t, x, y;
        scanf("%d%d%d", &t, &x, &y), t --;
        qcnt = qsum = 0;
        segment_query(Root[t ^ 1], 0, A, a[t][x], A);
        ans -= 1ll * (n[t ^ 1] - qcnt) * a[t][x] + qsum;
        segment_modify(Root[t], 0, A, a[t][x], -1);
        a[t][x] = y;
        segment_modify(Root[t], 0, A, a[t][x], 1);
        qcnt = qsum = 0;
        segment_query(Root[t ^ 1], 0, A, a[t][x], A);
        ans += 1ll * (n[t ^ 1] - qcnt) * a[t][x] + qsum;
        printf("%lld\n", ans);
    }
    return 0;
}

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

template <typename T>
struct BIT {
    int n;
    vector<T> dat;

    BIT(int n) : n(n), dat(n + 1, 0) {}

    T sum(int idx) {  // 1-indexed
        T res(0);
        for (int i = idx; i > 0; i -= i & -i) res += dat[i];
        return res;
    }

    T sum(int l, int r) {  // 0-indexed
        return sum(r) - sum(l);
    }

    void add(int idx, T x) {  // 0-indexed
        idx++;
        for (int i = idx; i <= n; i += i & -i) dat[i] += x;
    }

    int lower_bound(T x) {
        if (x <= 0) return T(0);
        int res = 0, r = 1;
        while (r < n) r <<= 1;
        for (; r > 0; r >>= 1) {
            if (res + r <= n && dat[res + r] < x) {
                x -= dat[res + r];
                res += r;
            }
        }
        return res;
    }

    int upper_bound(T x) {
        return lower_bound(x + 1);
    }

    void print() {
        for (int i = 0; i < n; i++) cout << sum(i, i + 1) << " ";
        cout << endl;
    }
};

signed main() {
    int n, m, q;
    cin >> n >> m >> q;
    map<ll, int> mp;
    mp[0] = 0;
    int t[q], x[q];
    ll y[q];
    rep(i, q) {
        cin >> t[i] >> x[i] >> y[i];
        x[i]--;
        mp[y[i]] = 0;
    }
    int i = 0;
    for (auto& p : mp) {
        p.second = i++;
    }
    ll ans = 0;
    ll a[n] = {}, b[m] = {};
    BIT<int> A(mp.size()), B(mp.size());
    BIT<ll> Asum(mp.size()), Bsum(mp.size());
    A.add(0, n);
    B.add(0, m);
    rep(i, q) {
        if (t[i] == 1) {
            ans -= a[x[i]] * B.sum(0, mp[a[x[i]]]);
            ans -= Bsum.sum(mp[a[x[i]]], mp[y[i]]);
            ans += y[i] * B.sum(0, mp[y[i]]);
            A.add(mp[a[x[i]]], -1);
            A.add(mp[y[i]], 1);
            Asum.add(mp[a[x[i]]], -a[x[i]]);
            Asum.add(mp[y[i]], y[i]);
            a[x[i]] = y[i];
        } else {
            ans -= b[x[i]] * A.sum(0, mp[b[x[i]]]);
            ans -= Asum.sum(mp[b[x[i]]], mp[y[i]]);
            ans += y[i] * A.sum(0, mp[y[i]]);
            B.add(mp[b[x[i]]], -1);
            B.add(mp[y[i]], 1);
            Bsum.add(mp[b[x[i]]], -b[x[i]]);
            Bsum.add(mp[y[i]], y[i]);
            b[x[i]] = y[i];
        }
        cout << ans << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 2e5 + 5;

struct Edge
{
	int next,to;
}e[MAXN<<1];
int head[MAXN],etot=0;
inline void add(int u,int v)
{
	e[++etot] = (Edge){ head[u],v};
	head[u] = etot;
}

int n;

int dep[MAXN], mxdep[MAXN];
void dfs_dep(int u,int fa)
{
	mxdep[u] = dep[u];
	for(int i=head[u]; i; i=e[i].next)
	{
		int v = e[i].to;
		if(v == fa) continue;
		dep[v] = dep[u] + 1;
		dfs_dep(v,u);
		mxdep[u] = max(mxdep[u], mxdep[v]);
	}
}

inline int get_far(int u)
{
	dep[u] = 0; dfs_dep(u,0);
	return max_element(dep+1,dep+n+1) - dep;
}

inline bool cmp_mxdep(int x,int y){ return mxdep[x] < mxdep[y];}

int res[MAXN], cur_res = 0;
void dfs_res(int u,int fa)
{
	res[u] = ++cur_res;
	vector<int> g;
	for(int i=head[u]; i; i=e[i].next)
	{
		int v = e[i].to;
		if(v != fa) g.push_back(v);
	}
	sort(g.begin(), g.end(), cmp_mxdep);

	for(int i=0; i<(int)g.size(); ++i)
		dfs_res(g[i], u);
	++cur_res;
}

int main(void)
{
	scanf("%d",&n);
	for(int i=1; i<n; ++i)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v); add(v,u);
	}

	int rt = get_far(get_far(1));
	dep[rt] = 0;
	dfs_dep(rt, 0);
	dfs_res(rt, 0);

	for(int i=1; i<=n; ++i) printf("%d ",res[i]);
	return 0;
}

#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;

const int N=105,M=105*105;

int a[M],b[M],ans[M];
int c[N],vis[N];
vector<int> rem;
vector<pair<int,int> > adj[N];
int can[N][N];
int n,m;

void go(int x,int pa=-1)
{
	if(vis[x]==1) return;
	vis[x]=1;
	for(auto i:adj[x])
	{
		if(i.S==pa) continue;
		if(ans[i.S]==-1)
		{
			ans[i.S]=(a[i.S]!=x);
			go(i.F,i.S);
		}
	}
}

int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
		can[i][i]=1;
	for(int i=0;i<m;i++)
	{
		scanf("%d %d",&a[i],&b[i]);
	}
	for(int i=1;i<=n;i++)
		scanf("%d",&c[i]);
	for(int i=0;i<m;i++)
	{
		if(c[a[i]]!=c[b[i]])
		{
			ans[i]=c[a[i]]<c[b[i]];
		}
		else
		{
			rem.push_back(i);
			ans[i]=-1;
		}
	}
	// 0 -> , 1 <-
	for(int i=0;i<rem.size();i++)
	{
		int x=rem[i];
		adj[a[x]].push_back({b[x],x});
		adj[b[x]].push_back({a[x],x});
		vis[a[x]]=-1; vis[b[x]]=-1;
	}
	for(int i=1;i<=n;i++)
	{
		if(vis[i]==-1)
			go(i);
	}
	for(int i=0;i<m;i++)
	{
		if(ans[i])
			puts("<-");
		else
			puts("->");
	}
}


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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define pb push_back
#define eb emplace_back

#define INF 1000000000
#define INFLL 1000000000000000000LL

using namespace std;

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

using ll = long long;
using P = pair<ll, ll>;

#define MAX_H 500+10
#define MAX_W 500+10
#define MOD 998244353

ll H, W, ans;
string S[MAX_H];
set<char> A[10000];

int main() {

	cin >> H >> W;
	REP(i, H)cin >> S[i];

	REP(i, H) {
		REP(j, W) {
			A[i + j].insert(S[i][j]);
		}
	}

	ans = 1;

	REP(i, 10000) {
		bool r = false, b = false, w = false;
		for (auto&& x : A[i]) {
			if (x == 'R')r = true;
			if (x == 'B')b = true;
			if (x == '.')w = true;
		}
		if (r && b)ans = 0;
		if (w && !b && !r)ans = ans * 2 % MOD;
	}

	cout << ans << endl;

	return 0;
}

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

vl memo(5000000,-1);

long long mod_pow(long long x, long long y, long long M){
    if(memo[y]!=-1){
        return memo[y];
    }
    if(y == 0){
        memo[y]=1;
        return 1;
    }
    if(y & 1){
        return memo[y]=mod_pow(x, y - 1, M) * x % M;
    }
    long long t = mod_pow(x, y / 2, M);
    return memo[y] = t * t % M;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin >> H >> W;
    vvc c(H,vc(W));
    ll base=0;
    rep(i,H){
        rep(j,W){
            cin >> c[i][j];
            if(c[i][j]=='.'){
                base++;
            }
        }
    }
    ll ans=0;
    vvl yoko(H,vl(W));
    vvl tate(H,vl(W));
    rep(i,H){
        int res=0;
        int now=0;
        rep(j,W){
            if(c[i][j]=='#'){
                FOR(k,res,j){
                    yoko[i][k]=now;
                }
                res=j+1;now=0;
            }
            else{
                now++;
            }
        }
        FOR(k,res,W){
            yoko[i][k]=now;
        }
    }
    rep(i,W){
        int res=0;
        int now=0;
        rep(j,H){
            if(c[j][i]=='#'){
                FOR(k,res,j){
                    tate[k][i]=now;
                }
                res=j+1;now=0;
            }
            else{
                now++;
            }
        }
        FOR(k,res,H){
            tate[k][i]=now;
        }
    }
    /*rep(i,H){
        rep(j,W){
            cout << yoko[i][j];
        }
        cout << '\n';
    }
    rep(i,H){
        rep(j,W){
            cout << tate[i][j];
        }
        cout << '\n';
    }*/
    rep(i,H){
        rep(j,W){
            if(c[i][j]=='.'){
                ans+=mod_pow(2,base-tate[i][j]-yoko[i][j]+1,MOD)*(mod_pow(2,tate[i][j]+yoko[i][j]-1,MOD)-1)%MOD;
                ans%=MOD;
            }
        }
    }
    cout << ans << endl;
}


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

const int64_t MOD = 1e9 + 7;
const int64_t MOD2 = 998244353;
const int INF = 1e9;
const long long inf = 1LL<<62;

/*
　<方針>
  B-A<=72であり, A-B間で数を選んでも73以上の共通因数をもつことはない.

  (proof)A-B間の数n, m(n != m)が共通因数r>=73を持つとすると
  n = ra_1
  m = ra_2
  が成り立つ. この時n<mとしても一般性を失わず, a_2 > a_1である. すなわち
  m - n = r(a_2 - a_1) > r
  これはB-A <= 72に矛盾する.

  以上の考察から, 持ちうる共通因数は72以下である. しかし, 2^72のbitDPは明らかに間に合わない.
  そこで, 例えば72を共通因数に持つ場合を考えると, これは明らかに2や3を素因数に持っている.
  ようするに, 与えられる数の集合がA-B間の数に限定される場合, 72までの素数を共通として持つかの判定のみでよいということになる.
  72以下の素数は20個しかなく, これの判定だけならbitDPが間に合う.
*/

int main() {
  long long A, B;
  cin >> A >> B;
  vector<int> ep; //72までの素数の集合
  vector<int> pr(73, 1);
  pr[0] = pr[1] = 0;
  for (int i=2; i*i<=72; i++) {
    if (pr[i]) {
      for (int x = i*2; x<=72; x+=i) {
        pr[x] = 0;
      }
    }
  }
  for (int i=2; i<=72; i++) {
    if (pr[i]) ep.push_back(i);
  }
  vector<int> msk(B-A+1); //Aからi番目の数について, 72までの素因数のなかで持っているものをbitで表現
  for (long long x=A; x<=B; x++) {
    for (int i=0; i<20; i++) {
      if (x%ep[i] == 0) msk[x-A] |= 1<<i;
    }
  }
  vector<vector<long long>> dp(B-A+2, vector<long long>(1<<20));
  dp[0][0] = 1;
  for (long long x = A; x <= B; x++) {
    for (int lcm = 0; lcm<(1<<20); lcm++) {
      if (!(lcm & msk[x-A])) {
        dp[x-A+1][lcm | msk[x-A]] += dp[x-A][lcm]; //素因数がかぶっていない場合
      }
      dp[x-A+1][lcm] += dp[x-A][lcm];
    }
  }
  long long ans = 0;
  for (int i = 0; i<(1<<20); i++) {
    ans += dp[B-A+1][i];
  }
  cout << ans << endl;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ld long double
#define mem(x,y) memset(x,y,sizeof x)

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

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

int dp[1009][1009];

int a[1009],b[1009];

void solve()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=m;i++) cin>>b[i];

	for(int i=1;i<=n;i++) dp[i][0]=i;
	for(int i=1;i<=m;i++) dp[0][i]=i;

	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	{
		if(a[i]==b[j])
		{
			dp[i][j]=min(min(dp[i][j-1],dp[i-1][j])+1,dp[i-1][j-1]);
		}
		else
		{
			dp[i][j]=min(dp[i-1][j-1]+1,min(dp[i-1][j],dp[i][j-1])+1);
		}
	}
	cout<<dp[n][m]<<'\n';
}

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


#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define l long
#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 all(v) v.begin(),v.end()
int main()
{
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 ll n;
  cin>>n;
  ll a=1000;
  ll ans=0;
  while(a<=n)
  {
    ans+=n-a+1;
    a*=1000;
  }
  cout<<ans<<endl;
}

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iterator>
#include <map>
#include <unordered_map>
#include <numeric>
#include <set>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <tuple>
#include <cstdio>

#include <chrono> //performance check

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<set<int>> graph;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;

template <typename T>
istream &operator>>(istream &is, vector<T> &arr);
template <typename T>
ostream &operator<<(ostream &os, vector<T> &arr);
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &p);

#define setup() (ios_base::sync_with_stdio(false), cin.tie(0))
#define forN(i, n) for (int i = 0; i < int(n); i++)
#define forRange(i, l, r) for (int i = int(l); i <= int(r); i++)

template <typename T>
istream &operator>>(istream &is, vector<T> &arr)
{
	typename vector<T>::iterator a;
	for (a = arr.begin(); a != arr.end(); a++)
	{
		is >> *a;
	}
	return is;
}

template <typename T>
ostream &operator<<(ostream &os, vector<T> &arr)
{
	typename vector<T>::iterator a;
	for (a = arr.begin(); a != arr.end(); a++)
	{
		os << *a << " ";
	}
	os << endl;
	return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &p)
{
	os << p.first << " " << p.second << '\n';
	return os;
}

ll INF = 1e18;
ll MOD = 998244353;

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

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

bool valid(int i, int j, int n, int m)
{
	return i >= 0 && i < n && j >= 0 && j < m;
}

vector<pair<int, int>> dirs = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int main()
{
	// freopen("output.txt", "w", stdout);

	int n;
	cin >> n;
	cout << (n % 2 == 1 ? "Black" : "White") << endl;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define DBG(a) cout<< "line "<<__LINE__ <<" : "<< #a <<" --> "<<(a)<<endl
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int mod = 998244353;
long double pi = acosl(-1);
const ll infl = 1e17+100;
const int inf = 1e9+100;
const int nmax = 1e6+5;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ost;

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

    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<int>a(n+1);
    for(int &x : a) cin>>x;

    int kom = inf;
    for(int i=0; i<n; i++){
        kom = min(kom, abs(a[i]-a[i+1]));
    }

    vector< vector<int> >ans(kom, vector<int>(n+1) );
    for(int i=0; i<=n; i++){
        int z = a[i]/kom;
        int extra = a[i]%kom;
        for(int j=0; j<kom; j++){
            ans[j][i] = z;
            if(j<extra) ans[j][i]++;
        }
    }

    cout<<kom<<"\n";
    for(auto z : ans){
        for(auto x : z){
            cout<<x<<" ";
        }
        cout<<"\n";
    }
}
/*
*/

// clang-format off
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#ifndef godfather
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#endif

#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef gp_hash_table<int, int> umap;
typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update> oset;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pii> vii;

#define INF 1000000000000000000
#define inf 1000000000
// #define MOD 67280421310721
#define MOD  1000000007
// #define MOD 998244353
#define PI 3.1415926535897932385

#define pb push_back
#define bitc __builtin_popcountll
#define mp make_pair
#define all(ar) ar.begin(), ar.end()

#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define foreach(it, ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fil(ar, val) memset(ar, val, sizeof(ar))  // 0x3f for inf, 0x80 for -INF can also use with pairs

#ifdef godfather
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T>
void __p(std::vector<T> a) { cout << "{ "; for (auto p : a) __p(p); cout << "}"; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.first); __p(a.second); cout << "}"; }
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) { __p(a1); __p(a...); }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cout<<name<<" : ";__p(arg1);cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    int bracket=0,i=0;
    for(; ;i++)
        if(names[i]==','&&bracket==0)
            break;
        else if(names[i]=='(')
            bracket++;
        else if(names[i]==')')
            bracket--;
    const char *comma=names+i;
    cout.write(names,comma-names)<<" : ";
    __p(arg1);
    cout<<"| ";
    __f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define trace(...)
#define end_routine()
#endif

mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
inline bool equals(double a, double b) { return fabs(a - b) < 1e-9; }
ll modpow(ll b, ll e, ll mod=MOD) {
    ll ans=1; for(;e;b=b*b%mod,e/=2) if(e&1) ans=ans*b%mod; return ans; }

ld modp(ld b, ll e) {
    ld ans=1; for(;e;b=b*b,e/=2) if(e&1) ans=ans*b; return ans; }

void solve()
{
    // START
    ll n;
    cin >> n;
    vi arr(n);
    rep(i,n)cin >> arr[i];
    sort(all(arr));

    rep(i,n){
        if(arr[i]!=i+1){
            cout<<"No\n";
            return;
        }
    }
    cout<<"Yes\n";

    // END
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0), cout.precision(15);   cout<<fixed;
    #ifdef godfather
        cin.exceptions(cin.failbit);
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    // cin>>t;
    fr(i,1,t)
    {
        // cout<<"Case #"<<i<<": ";
        solve();
    }
    end_routine();
}


#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// #include <boost/rational.hpp>

// using bigint = boost::multiprecision::cpp_int;
// using fraction = boost::rational<bigint>;
using namespace std;

#define pb push_back
#define eb emplace_back
#define unused [[maybe_unused]]
#define tempT template<class T>
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl
#define ans_exit(x) { cout << x << endl; exit(0); }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (ll i = (ll)(n); i < (ll)(m); i++)

using ll   unused = long long;
using ld   unused = long double;
using vl   unused = vector<ll>;
using vvl  unused = vector<vl>;
using vvvl unused = vector<vvl>;
using lp   unused = pair<ll, ll>;
using lmap unused = map<int, int>;

unused constexpr ll MOD = 998244353;
unused constexpr ll INF = 1 << 30;
unused constexpr ll LINF = 1LL << 62;
unused constexpr int DX[8] = {0, 1, 0,-1, 1, 1,-1,-1};
unused constexpr int DY[8] = {1, 0,-1, 0, 1,-1, 1,-1};
unused inline bool bit(ll b, ll i) { return b & (1LL << i); }
unused inline ll ceiv(ll a, ll b) { return (a + b - 1) / b; }
unused inline ll mod(ll a, ll m = MOD) { return (a % m + m) % m; }
unused inline ll floordiv(ll a, ll b) { return a / b - (a < 0 && a % b); }
unused inline ll ceildiv(ll a, ll b) { return floordiv(a + b - 1, b); }
tempT unused inline bool in_range(T a, T x, T b) { return a <= x && x < b; }
unused inline bool in_range(ll x, ll b) { return in_range(0LL, x, b); }
tempT unused bool chmin(T &a, T b) { if(a > b) {a = b; return 1;} return 0; }
tempT unused bool chmax(T &a, T b) { if(a < b) {a = b; return 1;} return 0; }

pair<vector<ll>, ll> modloopvector(ll a, ll m) {
    set<ll> s; vector<ll> v;
    ll tmp = 1;
    while(!s.count(tmp)) {
        s.insert(tmp);
        v.push_back(tmp);
        tmp = mod(tmp * a, m);
    }
    int loop_start_idx
            = distance(v.begin(), find(v.begin(), v.end(), tmp));
    return {v, loop_start_idx};
}

ll modpow(ll a, ll n, ll m = MOD){
    ll ret = 1;
    while(n>0){
        if(n&1) ret = (ret * a) % m;
        a = (a * a) % m;
        n >>= 1;
    }
    return ret % m;
}

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

    auto [v, idx] = modloopvector(a, 10);
    int cycle = (int)v.size() - idx;

    ll bc = 1;
    rep(i, c) {
        bc *= b;
        if(bc >= idx) break;
    }

    ll ans;
    if(bc < idx) {
        ans = v[bc];
    } else {
        ll tmp = modpow(b, c, cycle);
        tmp = mod(tmp - idx, cycle) + idx;
        ans = v[tmp];
    }

    cout << ans << endl;
}


#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define fillarray(array, value, begin, end) fill((array) + (begin), (array) + (end) + 1, value)
#define fillvector(v, value) fill((v).begin(), (v).end(), value)
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
#define vecfirst (*vec.begin())
#define veclast (*vec.rbegin())
#define vecall(v) (v).begin(), (v).end()
#define vecupsort(v) (sort((v).begin(), (v).end()))
#define vecdownsort(v, type) (sort(vecall(v), greater<type>()))
#define veccmpsort(v, cmp) (sort(vecall(v), cmp))
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end()
{
#ifdef ONLINE
    printf("\n\nTime used: %.6lf(s)\n", ((double)TIME__END - TIME__START) / 1000);
    system("pause");
#endif
}
int n;
int a[2005];
ll ans;
map<int, int> mpg;

inline void solve()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    int g = a[1];
    for (int i = 1; i <= n; ++i)
        g = __gcd(a[i], g);
    for (int i = 1; i <= n; ++i)
        a[i] /= g;
    int mn = *min_element(a + 1, a + n + 1);
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j * j <= a[i]; ++j)
            if (a[i] % j == 0)
                mpg[j] = __gcd(mpg[j], a[i]), mpg[a[i] / j] = __gcd(mpg[a[i] / j], a[i]);
    for (auto i : mpg)
        ans += (i.first == i.second && i.first <= mn);
    cout << ans << endl;
}

int main()
{
    TIME__START = clock();
    int Test = 1;
    // scanf("%d", &Test);
    while (Test--)
    {
        solve();
        // if (Test)
        //     putchar('\n');
    }
    TIME__END = clock();
    program_end();
    return 0;
}

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); (i)++)
#define per(i, n) for (ll i = n - 1; i >= 0; (i)--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define ROF(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define ALL(x) std::begin(x), std::end(x)
#define rALL(x) std::rbegin(x), std::rend(x)
#define fi first
#define se second
typedef long long ll;

// (x1, y1)と(x2, y2)の外積, 1->2で反時計回りなら正
inline ll ccw(ll x1, ll y1, ll x2, ll y2){
    ll res = x1 * y2 - x2 * y1;
    if(res == 0){ // 外積0のとき、同方向ならLLONG_MAX, 逆方向ならLLONG_MIN, 一方でも0なら0を返す
        ll a = x1 * x2 + y1 * y2;
        if(a > 0) return LLONG_MAX;
        else if(a < 0) return LLONG_MIN;
        else return 0;
    }
    return res;
}
inline ll norm2(ll x, ll y){ return x * x + y * y; }

int main(){
    //input, initialize
    ll N; cin >> N;
    vector<ll> a(N), b(N), c(N), d(N);
    //solve
    if(N == 1){ cout << "Yes"; return 0; }
    rep(i, N) cin >> a[i] >> b[i];
    rep(i, N) cin >> c[i] >> d[i];
    rep(i, N) { a[i] *= N; b[i] *= N; c[i] *= N; d[i] *= N; }

    ll c1x, c1y, c2x, c2y; c1x = c1y = c2x = c2y = 0;
    rep(i, N) { c1x += a[i]; c1y += b[i]; c2x += c[i]; c2y += d[i]; }
    c1x /= N; c1y /= N; c2x /= N; c2y /= N;
    rep(i, N) { a[i] -= c1x; b[i] -= c1y; c[i] -= c2x; d[i] -= c2y; }

    if(a[0] == 0 && b[0] == 0){
        swap(a[0], a[1]); swap(b[0], b[1]);
    }
    set<pair<ll, ll>> p1, p2; // 外積, ノルム2乗の順
    rep(i, N){
        p1.insert(make_pair(ccw(a[0], b[0], a[i], b[i]), norm2(a[i], b[i])));
    }
    rep(i, N){
        p2 = {};
        if(c[i] == 0 && d[i] == 0) continue;
        rep(j, N){
            p2.insert(make_pair(ccw(c[i], d[i], c[j], d[j]), norm2(c[j], d[j])));
        }
        if(p1 == p2) {cout << "Yes" << '\n'; return 0;}
    }
    //output
    cout << "No\n";
    //debug
}


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

#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);//cout.precision(dbl::max_digits10);
#define pb(x) push_back(x)
#define mod 1000000007ll //998244353ll
#define vi vector<int>
#define v(x) vector< x >
#define lld long double
#define pii pair<int, int>
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define repe(i,x,y) for(int i=x; i<=y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define show(x) cout<<x<<"\n"
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}

typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
lld pi=3.1415926535897932;

/*-----------------------------------------------------------*/

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

	map<int,int> mp;
	for(int i=2;i*i<=n;i++){
		if(!mp.count(i)){
			for(int j=i*i;j<=n;j*=i)
				mp[j]=1;
		}
	}
	return n-mp.size();
}

int32_t main(){
	IOS

	int t=1;

	while(t--)
	cout<<solve()<<endl;

	return 0;
}

#include <bits/stdc++.h>
#define poi 200100
#define int long long
using namespace std;
typedef long long ll;
typedef double db;
set<int> s;
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');
}
inline int ksm(int x, int y)
{
    int ans = 1;
    for (; y; y >>= 1)
    {
        if (y & 1)
            ans = (ans * x);
        x = (x * x);
    }
    return ans;
}
signed main()
{
    int n = re(), ans = 0;
    for (int a = 2;; a++)
    {
        bool canEnter = 0;
        for (int b = 2, num; (num = ksm(a, b)) <= n; b++)
        {
            canEnter = 1;
            if (s.find(num) == s.end())
                ans++, s.insert(num);
        }
        if (!canEnter)
            break;
    }
    wr(n - ans);
    return 0;
}


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

using ll = long long int;
using vll = vector<ll>;
ll const mod = 1e9 + 7;
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define repr(i,a,n) for(ll i=a;i>=n;i--)
#define aashish_999 ios_base::sync_with_stdio(false);cin.tie(NULL)

int main()
{
    aashish_999;

    ll testcases = 1;
    //cin >> testcases;
    while(testcases--)
    {
        ll n;
        cin >> n;

        ll ans = 2;
        for(ll i = 3; i <= n; i++)
            ans = (ans * i) / __gcd(ans, i);

        cout << ans + 1 << endl;
    }

}

#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define inf 2147483647
#define ll long long
//#define file
using namespace std;

int n,i,j,k,l;
int c[501][501];
int a[501],b[501];
ll A[501],B[501];
ll ma1,ma2,mb1,mb2;

void Exit()
{
	printf("No\n");
	exit(0);
}

int main()
{
	#ifdef file
	freopen("b.in","r",stdin);
	#endif

	scanf("%d",&n);
	fo(i,1,n)
	{
		fo(j,1,n)
		scanf("%d",&c[i][j]);
	}
	fo(i,2,n) a[i]=c[i][1]-c[1][1],ma1=min(ma1,a[i]),ma2=max(ma2,a[i]);
	fo(j,2,n) b[j]=c[1][j]-c[1][1],mb1=min(mb1,b[j]),mb2=max(mb2,b[j]);
	fo(j,1,n)
	{
		fo(i,2,n)
		if (c[i][j]-c[1][j]!=a[i])
		Exit();
	}
	fo(i,1,n)
	{
		fo(j,2,n)
		if (c[i][j]-c[i][1]!=b[j])
		Exit();
	}

	if (-ma1-mb1>c[1][1]) Exit();
	printf("Yes\n");
	A[1]=-ma1,B[1]=c[1][1]-A[1];
	fo(i,2,n) A[i]=a[i]+A[1],B[i]=b[i]+B[1];
	fo(i,1,n) printf("%lld ",A[i]);printf("\n");
	fo(i,1,n) printf("%lld ",B[i]);printf("\n");

	fclose(stdin);
	fclose(stdout);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<ll, ll>;
using tp = tuple<ll, ll, ll>;

template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;

#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)

constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll)1e9 + 7;
constexpr long long MOD = 998244353LL;
static const ld pi = 3.141592653589793L;

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

//グラフ関連
struct Edge {
    int to, rev;
    ll cap;
    Edge(int _to, ll _cap, int _rev) : to(_to), cap(_cap), rev(_rev) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, int from, int to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (int)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (int)G[from].size() - 1));
}

void solve() {
    ll n, k;
    cin >> n >> k;
    Graph g(n);

    REP(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        add_edge(g, a, b, 1, true, 1);
    }
    ll t = 0;
    REP(i, n) {
        if(g[i].size() == 1)
            t = i;
    }

    auto check = [&](ll x) -> bool {
        ll con = 0;
        auto dfs = [&](auto &&self, int v, int p) -> ll {
            ll d = 0;
            for(auto e : g[v]) {
                if(e.to == p)
                    continue;
                ll nd = self(self, e.to, v);

                if(d < 0) {
                    if(nd < 0) {
                        chmin(d, nd);
                    } else {
                        if(d + nd >= 0)
                            d = nd;
                    }
                } else {
                    if(nd < 0) {
                        if(d + nd < 0)
                            d = nd;
                    } else {
                        chmax(d, nd);
                    }
                }
            }
            if(d >= x) {
                con++;
                d = -x - 1;
            }
            return d + 1;
        };
        if(dfs(dfs, t, -1) > 0)
            con++;

        return con <= k;
    };

    ll l = 0;
    ll r = n;
    while(l + 1 < r) {
        ll m = l + r >> 1;
        if(check(m))
            r = m;
        else
            l = m;
    }
    cout << r << en;
}

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

    // ll t;
    // cin >> t;
    // REP(i, t - 1) {
    //     solve();
    // }

    solve();

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
long long N,K;
  cin >> N >> K;
  vector<vector<long long>> data(N, vector<long long>(2));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> data.at(i).at(j);
    }
  }
  sort(data.begin(),data.end());
  long long a=K;
  for (int i = 0; i < N; i++) {
    if(data.at(i).at(0)<=a){
      a+=data.at(i).at(1);}
    else{break;}
  }
 cout << a << endl;
}


#include <bits/stdc++.h>

#pragma region my_template

struct Rep {
  struct I {
    int i;
    void operator++() { ++i; }
    int operator*() const { return i; }
    bool operator!=(I o) const { return i < *o; }
  };
  const int l_, r_;
  Rep(int l, int r) : l_(l), r_(r) {}
  Rep(int n) : Rep(0, n) {}
  I begin() const { return {l_}; }
  I end() const { return {r_}; }
};
struct Per {
  struct I {
    int i;
    void operator++() { --i; }
    int operator*() const { return i; }
    bool operator!=(I o) const { return i > *o; }
  };
  const int l_, r_;
  Per(int l, int r) : l_(l), r_(r) {}
  Per(int n) : Per(0, n) {}
  I begin() const { return {r_ - 1}; }
  I end() const { return {l_ - 1}; }
};

template <class F>
struct Fix : private F {
  Fix(F f) : F(f) {}
  template <class... Args>
  decltype(auto) operator()(Args&&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};

template <class T = int>
T scan() {
  T res;
  std::cin >> res;
  return res;
}

template <class T, class U = T>
bool chmin(T& a, U&& b) {
  return b < a ? a = std::forward<U>(b), true : false;
}
template <class T, class U = T>
bool chmax(T& a, U&& b) {
  return a < b ? a = std::forward<U>(b), true : false;
}

#ifndef LOCAL
#define DUMP(...) void(0)
template <int OnlineJudge, int Local>
constexpr int OjLocal = OnlineJudge;
#endif

using namespace std;

#define ALL(c) begin(c), end(c)

#pragma endregion

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n = scan();
  double du = scan();
  double hu = scan();
  double ans = 0;
  while (n--) {
    double d = scan();
    double h = scan();
    double cur = hu - (hu - h) / (du - d) * du;
    chmax(ans, cur);
  }
  cout << ans << '\n';
}

/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")*/
// only when really needed

/* GNU G++17 7.3.0: No long long for faster code
   GNU G++17 9.2.0 (64 bit, msys 2): Long long only for faster code */

#include <bits/stdc++.h>

#define for1(i,a,b) for (int i = a; i <= b; i++)
#define for2(i,a,b) for (int i = a; i >= b; i--)
#define int long long

#define sz(a) (int)a.size()
#define pii pair<int,int>

/*
__builtin_popcountll(x) : Number of 1-bit
__builtin_ctzll(x) : Number of trailing 0
*/

#define PI 3.1415926535897932384626433832795
#define INF 1000000000000000000
#define MOD 1000000007
#define MOD2 1000000009
#define EPS 1e-6

using namespace std;

int n;
double d, h, a[1005], b[1005];

signed main() {

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

    // freopen("cf.inp", "r", stdin);
    // freopen("cf.out", "w", stdout);

    cin >> n >> d >> h;

    for1(i,1,n) cin >> a[i] >> b[i];

    double l = 0.0, r = 1000.0;

    for1(i,1,100) {

    	bool flag = true;
    	double m = (l + r)/2;
    	for1(i,1,n) {

    		double br = m + (h - m)*(a[i] / d);
    		if (br + EPS < b[i]) {
    			flag = false;
    			break;
    		}

    	}

    	if (flag) r = m;
    	else l = m;

    }

    cout << fixed << setprecision(3) << l;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <iomanip>

#define MOD 1000000007
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;

int main() {

	int n;
	cin >> n;

	double e = 0.0;
	for(int i = n; i > 1; i--) {
		e += (double)n / (n - i + 1);
	}

	cout << setprecision(10) << e << endl;
}

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

int main() {

    ll L; cin >> L;
    vector<int> order(11);
    rep(i,11) order[i] = i + 1;
    ll ans = 1;
    rep(i,11) {
        ans *= (L - 1 - i);
        rep(j,11) {
            if (ans % order[j] == 0) {
                ans /= order[j];
                order[j] = 1;
            }
        }
    }
    cout << ans << endl;

    return 0;
}