#include"bits/stdc++.h"
using namespace std;
#define pb push_back
#define eb emplace_back
#define ins insert
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define pii pair<int,int>
#define fir first
#define sec second
#define popcount __builtin_popcount
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using ll=long long int;
using ld=long double;
#define mp make_pair
#define mt make_tuple
#define bit(x,j) (((ll)x>>j)&1)
#define um unordered_map
#define mem(a,val) memset(a,val,sizeof(a))
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x){cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(ld x){cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x){cerr<<'\"'<<x<<'\"';}
void __print(const string &x) {cerr<<'\"'<<x<<'\"';}
void __print(bool x){cerr<<(x?"true":"false");}
template<typename T, typename V>
void __print(const pair<T, V> &x){cerr<<'{'; __print(x.first);cerr<<','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{ return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{ return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#ifndef ONLINE_JUDGE
#define debugt(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debugt(...) 42
#endif
constexpr ll inf=2223372036854775807;
constexpr int mod1=(1e9+7);
constexpr int mod2=(998244353);
constexpr int MAX=(1e4+3);
constexpr int N=2e5+5;
void solve()
{
 string s; cin>>s; int cnt=0;
 for(int i=0;i<=8;i++)
 {
   if(s[i]=='Z' and s[i+1]=='O' and s[i+2]=='N' and s[i+3]=='e') cnt++;
 }
 cout<<cnt<<"\n";
}
int main()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t=1; int c=1;
  while(t--)
  {
    solve(); c++;
  }
}

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

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

    int n, q;
    cin >> n >> q;

    vector<int> studentClass(n + 1);
    vector<int> nodeParent(n + 1);
    vector<int> nodeRank(n + 1);
    vector< vector<int> > classStudents(n + 1); // position of students belonging to this class

    for (int i = 1; i <= n; ++i) {
        cin >> studentClass[i];

        classStudents[studentClass[i]].push_back(i);

        nodeParent[i] = i;
        nodeRank[i] = 1;
    }

    const int SQ = sqrt(n + .0);
    int bigClassesCount = 0;
    vector<int> classPosition(n + 1);

    for (int i = 1; i <= n; ++i) {
        if (classStudents[i].size() >= SQ) {
            classPosition[i] = bigClassesCount;
            ++bigClassesCount;
        }
    }

    vector< vector<int> > nodeData(n + 1, vector<int>(bigClassesCount));
    for (int i = 1; i <= n; ++i) {
        if (classStudents[studentClass[i]].size() >= SQ) {
            nodeData[i][classPosition[studentClass[i]]] = 1;
        }
    }

    // dsu stuff
    function<int(int)> findParent = [&nodeParent, &findParent](int node)->int {
        if (nodeParent[node] == node) {
            return node;
        }
        else {
            return nodeParent[node] = findParent(nodeParent[node]);
        }
    };

    // dsu stuff
    auto mergeNodes = [&nodeParent, &nodeRank, &findParent, &nodeData, &bigClassesCount](int firstNode, int secondNode) {
        int firstParent = findParent(firstNode);
        int secondParent = findParent(secondNode);

        if (firstParent == secondParent) {
            return;
        }

        if (nodeRank[firstParent] > nodeRank[secondParent]) {
            swap(firstParent, secondParent);
        }
        else if (nodeRank[firstParent] == nodeRank[secondParent]) {
            ++nodeRank[secondParent];
        }

        for (int i = 0; i < bigClassesCount; ++i) {
            nodeData[secondParent][i] += nodeData[firstParent][i];
        }

        nodeParent[firstParent] = secondParent;
    };

    while (q--) {
        int op;
        cin >> op;

        if (op == 1) {
            int a, b;
            cin >> a >> b;

            mergeNodes(a, b);
        }
        else {
            int x, y;
            cin >> x >> y;

            if (classStudents[y].size() < SQ) {
                int answer = 0;
                for (int i = 0; i < classStudents[y].size(); ++i) {
                    int studentIndex = classStudents[y][i];
                    answer += (findParent(studentIndex) == findParent(x));
                }

                cout << answer << "\n";
            }
            else {
                int groupParent = findParent(x);
                cout << nodeData[groupParent][classPosition[y]] << "\n";
            }
        }
    }

    return 0;
}


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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001;

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

	ll t=1;

	while(t--)
	{
	   ll n;
	   cin>>n;
	   string s;
	   cin>>s;
	   if(s[0]!=s[n-1])cout<<1;
	   else
	   {
	       ll f=0;
	       for(int i=1;i<n-1;i++)
	       {
	           if(s[0]!=s[i]&&s[i+1]!=s[n-1])
	           {
	               f=1;break;
	           }
	       }
	       if(f==1)cout<<2;
	       else cout<<-1;
	   }

	}
	return 0;
}

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

using namespace std;

template<typename T>
long long modpow(const T n,const T p,const T mod);
template<typename T>
long long modinv(const T n,const T mod);
template<typename T>
bool chmax(T &a,const T &b);
template<typename T>
bool chmin(T &a,const T &b);

long long inf=1000000007;

int main(){
	string n;
	cin>>n;
	vector<long long> kazu(10,0);
	for(auto a:n){
		kazu.at(a-'0')++;
	}

	vector<vector<long long>> dp(n.size()+1,vector<long long>(9*20+1,-1));
	vector<long long> youso(9*20,0);
	dp.at(0).at(0)=0;

	for(long long i=0;i<n.size();i++){
		for(long long j=0;j<=9*20;j++){
			chmax(dp.at(i+1).at(j),dp.at(i).at(j));
			if(j-(n.at(i)-'0')<0 || dp.at(i).at(j-(n.at(i)-'0'))==-1) continue;
			chmax(dp.at(i+1).at(j),dp.at(i).at(j-(n.at(i)-'0'))+1);
		}
	}

	long long ans=-1;

	for(long long i=0;i<=n.size();i++){
		for(long long j=0;j<=9*20;j++){//cout<<i<<" "<<j<<" "<<dp.at(i).at(j)<<endl;
			if(j%3==0 && j>0) chmax(ans,dp.at(i).at(j));
		}
	}

	if(ans!=-1) cout<<n.size()-ans<<endl;
	else cout<<-1<<endl;

//	long long ans=-1;
//
//	for(long long i=3;i<=9*20;i++){
//		for(long long j=1;j<=10;j++){cout<<j<<" "<<i<<" "<<dp.at(j).at(i)<<endl;
//			if(dp.at(j).at(i)>=1){cerr<<i<<" "<<youso.at(i)<<endl;
//				chmax(ans,youso.at(i));
//			}
//		}
//	}cout<<youso.at(18)<<endl;
//
//	if(ans==-1) cout<<-1<<endl;
//	else cout<<n.size()-ans<<endl;

	return 0;
}

template<typename T>
long long modpow(const T n,const T p,const T mod){
	if(p==0) return 1;
	if(p%2==0){
		long long a=modpow(n,p/2,mod);
		return a*a%mod;
	}
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}

template<typename T>
long long modinv(const T n,const T mod){
	return modpow(n,mod-2,mod);
}

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

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


#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int x[1010], y[1010];

bool check(int i, int j) {
    if (x[j] - x[i] > 0)
        return (x[i] - x[j] <= y[j] - y[i]) && (y[j] - y[i] <= x[j] - x[i]);
    return (x[i] - x[j] >= y[j] - y[i]) && (y[j] - y[i] >= x[j] - x[i]);
}

int solve() {
    int res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (check(i, j)) {
                res++;
            }
        }
    }
    return res;
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
}

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

    input();
    cout << solve() << endl;
}

#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;
const int MOD = 1000000007;

double abs_slope(pii a, pii b){
    return abs(a.second-b.second+0.0)/abs(a.first-b.first+0.0);
}

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

    int n; cin >> n;

    std::vector<pair<int,int>> points(n);
    rep(i,n){
        int x,y; cin >> x >> y;
        points[i].first = x;
        points[i].second = y;
    }

    int cnt = 0;

    rep(i,n) for(int j=i+1; j<n; j++){
        if(abs_slope(points[i], points[j]) <= 1) cnt++;
    }

    cout << cnt << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ull unsigned long long
#define ll long long
#define ui unsigned int
#define us unsigned short
#define inf_int 1e9
#define inf_ll 1e18
#define mod 1000000007
#define smod 998244353

vector<pair<ll, ll>> v[5];

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);

	int n;
	cin >> n;

	vector<pair<ll, ll>> v[5];
	ll data[n][5];
	for(int x=0;x<n;x++){
		for(int y=0;y<5;y++){
			cin >> data[x][y];
			v[y].push_back({data[x][y], x});
		}
	}

	for(int x=0;x<5;x++){
		sort(v[x].begin(), v[x].end());
	}
	ll ans = 0;
	for(int x=0;x<n;x++){
		for(int y=x+1;y<n;y++){
			vector<pair<ll, ll>> tmp;
			for(int z=0;z<5;z++){
				tmp.push_back({max(data[x][z], data[y][z]), z});
			}

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

			for(int i=1;i<=3;i++){
				int idx = v[tmp[0].second][n-i].second;
				if(idx == x || idx == y) continue;

				tmp[0].first = max(tmp[0].first, v[tmp[0].second][n-i].first);
				break;
			}

			ll mn = inf_ll;
			for(int z=0;z<5;z++) mn = min(mn, tmp[z].first);
			ans = max(ans, mn);
		}
	}
	cout << ans << "\n";
    return 0;
}

// Santai
// Pikirin dengan benar-benar

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vector<int>>;
using viii = vector<vector<vector<int>>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define len(a) (int)a.size()
#define all(a) a.begin(), a.end()

const int INF32 = 1 << 30;
const long long INF64 = 1LL << 60;
const double PI = acos(-1);

bool check(int x, vii A) {
    // N人ごとにA-Eが判定値xを満たしているかを5bitで算出
    set<int> s;
    for (auto a: A) {
        int bits = 0;
        for (auto v: a) {
            bits <<= 1;
            if (v >= x) bits |= 1;
        }
        s.insert(bits);
    }
    // 3人選んで、ABCDEいずれも基準を満たすかどうかを確認
    for (auto s1: s) {
        for (auto s2: s) {
            for (auto s3: s) {
                if ((s1 | s2 | s3) == 0b11111) {
                    return true;
                }
            }
        }
    }
    return false;
}

int main() {
    int N;
    cin >> N;
    vii A(N, vi(5));
    rep(i, N) rep(j, 5) cin >> A[i][j];

    int left = 0;
    int right = INF32;
    while (right - left > 1) {
        int mid = (left + right) / 2;
        (check(mid, A) ? left : right) = mid;
    }
    cout << left << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
struct UnionFind {
private:
    vector<int> par;
    vector<int> count;
    vector<int> rank;
public:
    UnionFind(int N) {
        count.assign(N, 1);
        rank.assign(N, 0);
        par.assign(N, 0);
        rep(i, N) par[i] = i;
    }

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

    void unite(int x, int y) {
        x = root(x), y = root(y);
        if (x == y) return;
        if (rank[x] < rank[y])
            swap(x, y);
        else if (rank[x] == rank[y])
            rank[y]++;
        par[y] = x;
        count[x] += count[y];
        return;
    }

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

    bool issame(int x, int y) {
        return root(x) == root(y);
    }
};
using UF = struct UnionFind;

int main() {
    ll N;
    cin >> N;
    vc<string> S(N);
    rep(i, N) cin >> S[i];

    vvc<int> child(N), parent(N);
    rep(i, N){
        vl srch(N);
        srch[i] = true, child[i].eb(i);
        queue<ll> q;
        q.emplace(i);
        while(!q.empty()){
            ll now = q.front();
            q.pop();
            rep(j, N){
                if (srch[j] or S[now][j] == '0') continue;
                srch[j] = true;
                child[i].eb(j);
                q.emplace(j);
            }
        }
        srch = vl(N), q.emplace(i), parent[i].eb(i), srch[i] = true;
        while(!q.empty()){
            ll now = q.front();
            q.pop();
            rep(j, N){
                if (srch[j] or S[j][now] == '0') continue;
                srch[j] = true;
                parent[i].eb(j);
                q.emplace(j);
            }
        }
    }

    ld ans = 0;
    rep(i, N) ans += 1.0L / parent[i].size();

    cout << ans << endl;
}

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define setbits(x)          __builtin_popcountll(x)
#define lp(a,n) for(ll i=a; i<n; i++)
#define lpi(a,n) for(int i=a; i<n; i++)
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define inf 1e9
#define LB lower_bound
#define UB upper_bound
const int mod = 1000000007;
using namespace std;
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

int prime[100007];
void SieveOfEratosthenes(int n)
{
    memset(prime, -1, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {

        if (prime[p] == -1)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = p;
        }
    }

}
int lps(string s){
    int len = 0;
    int n = s.length();
    int dp[n];
    dp[0] = 0;
    for(int i=1; i<n; i++){
        if(s[i] == s[len]){
            len++;
            dp[i] = len;
            continue;
        }
        if(len!=0){
            len = dp[len-1];
            i--;
            continue;
        }
        dp[i]=0;
    }
    return dp[n-1];
}

ll power(unsigned ll x,unsigned  ll y)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = res*x;

        y = y>>1;
        x = x*x;
    }
    return res;
}

//to calculate p1^x  *  p2^x2  *p3^x3 ----------
//i.e. prime factorization and store pi and xi in vector
vector<pair<ll, ll>> pFactor;

void factorize(long long n)
{
    int count = 0;

    // count the number of times 2 divides
    while (!(n % 2)) {
        n >>= 1; // equivalent to n=n/2;
        count++;
    }

    // if 2 divides it
    if (count)
        pFactor.pb({2,count});

    // check for all the possible numbers that can
    // divide it
    for (long long i = 3; i <= sqrt(n); i += 2) {
        count = 0;
        while (n % i == 0) {
            count++;
            n = n / i;
        }
        if (count)
            pFactor.pb({i,count});
    }

    // if n at the end is a prime number.
    if (n > 2)
        pFactor.pb({n,1});
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
    string s;
    cin>>s;
    if(s[0]==s[1] and s[1]==s[2]){
        cout<<"Won\n";
    }else cout<<"Lost\n";
}


#include<bits/stdc++.h>

#define int long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define fo(i,a,b) for (int i = a; i < b; i++)
#define f(i,n) for (int i = 0; i < n; i++)

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;

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

    vector<int> v(n);

    int sum=0;

    f(i,n){
        cin>>v[i];
        sum+=v[i];
    }

    bool dp[n+1][sum+1];

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

    for (int i = 1; i <= sum; i++)
        dp[0][i] = false;

    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=sum; j++)
        {
            dp[i][j] = dp[i-1][j];

            if (v[i-1] <= j)
                dp[i][j] |= dp[i-1][j-v[i-1]];
        }
    }

    int diff = INT_MAX;

    for (int j=sum/2; j>=0; j--)
    {

        if (dp[n][j] == true)
        {
            diff = sum-2*j;
            break;
        }
    }

    int ans=(sum+diff)/2;

    cout<<ans<<endl;
}

signed main(){

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

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

    solve();
    return 0;
}

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar('-');
  }
  while(s--){
    my_putchar(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
long long N;
long long eval(long long x){
  return ((x)*(x+1LL))>>1;
}
int main(){
  rd(N);
  long long PiIOrLma;
  long long AuJVIghY;
  long long FJNsjZ7B;
  PiIOrLma = 0;
  AuJVIghY = N;
  while(PiIOrLma < AuJVIghY){
    if((PiIOrLma + AuJVIghY)%2==0){
      FJNsjZ7B = (PiIOrLma + AuJVIghY) / 2;
    }
    else{
      FJNsjZ7B = (PiIOrLma + AuJVIghY + 1) / 2;
    }
    if(eval(FJNsjZ7B) < N){
      PiIOrLma = FJNsjZ7B;
    }
    else{
      AuJVIghY = FJNsjZ7B - 1;
    }
  }
  long long ans =AuJVIghY;
  ans = ans -2;
  chmax(ans, 0);
  while(eval(ans) < N){
    ++ ans;
  }
  wt_L(ans);
  wt_L('\n');
  return 0;
}
// cLay version 20210405-1

// --- original code ---
// //no-unlocked
// ll N;
// ll eval(ll x){
// 	return ((x)*(x+1LL))>>1;
// }
// {
// 	rd(N);
// 	ll ans = bsearch_max[ll, k, 0, N](eval(k) < N);
// 	ans = ans -2;
// 	ans >?= 0;
// 	while(eval(ans) < N) ++ ans;
// 	wt(ans);
// }


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string n;
    int k;
    cin>>n>>k;
    int ans=stoi(n);
    for(int i=0;i<=k;i++)
    {
        if(i!=0)
    {string desc=n;
    string asec=n;
    sort(asec.begin(),asec.end());
    sort(desc.begin(),desc.end(),greater<char>());
    int large=stoi(desc);
    int small=stoi(asec);
    ans=large-small;
    n=to_string(ans);
    }
    }
    cout<<ans;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}
template<class T> bool chmax(T& a, const T& b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T> bool chmin(T& a, const T& b) {
	if (a > b) { a = b; return 1; }
	return 0;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	string zone = "ZONe";
	int ans = 0;
	REP(i, 9) {
		bool flag = true;
		REP(j, 4) {
			if (zone[j] != S[i + j])flag = false;
		}
		if (flag)ans++;
	}
	cout << ans << endl;
	return 0;
}


# include <bits/stdc++.h>
# define ull unsigned long long
# define ll long long
# define double long double
# define pll pair<ll,ll>
# define pb push_back
# define fi first
# define se second
# define mp make_pair
# define max3(a,b,c) max(a,max(b,c))
# define min3(a,b,c) min(a,min(b,c))
# define all(x) x.begin(),x.end()
# define fill(a,b) memset(a,b,sizeof(a))
# define gcd(m,n)  __gcd(m, n)
# define pr_double(x) cout << fixed << setprecision(9) << x

using namespace std;
const ll INF = 922337203685477110;
const ll N = 200005;
const ll mod  = 998244353;
const ll M = 22;
ll ad[N];
ll bd[N];
ll na[N],nb[N],swp[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n; cin>>n;
  vector <pll> v;
  for(ll i=0;i<n;i++)
  {
      ll a,b; cin>>a>>b;
      v.pb({a,b});
  }
  ll m; cin>>m;
  na[0]=1; nb[0]=1; swp[0]=1;
  for(ll i=1;i<=m;i++)
  {
      ll c; cin>>c;
      if(c==1)
      {
          swp[i]=-1*swp[i-1];
          ad[i] = bd[i-1];
          bd[i] = ad[i-1]*-1;
          ll temp = nb[i];
          nb[i]=-1*na[i-1];
          na[i]=nb[i-1];
      }
      else if(c==2)
      {
          swp[i]=-1*swp[i-1];
          ad[i] = bd[i-1]*-1;
          ll temp = na[i];
          bd[i] = ad[i-1];
          na[i]=-1*nb[i-1];
          nb[i]=na[i-1];
      }
      else if(c==3)
      {
          ll add; cin>>add;
          swp[i]=swp[i-1]; nb[i]=nb[i-1];
          bd[i]=bd[i-1];
          ad[i] = 2*add-ad[i-1];
          na[i] = -1*na[i-1];
      }
      else{
          ll add; cin>>add;
          swp[i]=swp[i-1]; na[i]=na[i-1];
          ad[i]=ad[i-1];
          bd[i] = 2*add-bd[i-1];
          nb[i] = -1*nb[i-1];
      }
  }
  ll q; cin>>q;
  while(q--)
  {
      ll op,j; cin>>op>>j; j--;
      ll x = v[j].fi; ll y = v[j].se;
      if(swp[op]==-1) swap(x,y);
      if(na[op]==-1) x*=-1;
      if(nb[op]==-1) y*=-1;
      x+=ad[op]; y+=bd[op];
      cout<<x<<" "<<y<<endl;
  }
}

#include <bits/stdc++.h>

#define LL long long

#define ull unsigned long long

#define F(i, j, k) for(int i = j; i <= k; i++)

#define DF(i, j, k) for(int i = j; i >= k; i--)

using namespace std;

template <typename T> inline void read(T &n) {
	T w = 1;
	n = 0;
	char ch = getchar();
	while (!isdigit(ch) && ch != EOF) {
		if (ch == '-') w = -1;
		ch = getchar();
	}
	while (isdigit(ch) && ch != EOF) {
		n = (n << 3) + (n << 1) + (ch & 15);
		ch = getchar();
	}
	n *= w;
}

template <typename T> inline void write(T x) {
	T l = 0;
	ull y = 0;
	if (!x) {
		putchar(48);
		return;
	}
	if (x<0) {
		putchar('-');
		x = -x;
	}
	while (x) {
		y = y * 10 + x % 10;
		x /= 10;
		l++;
	}
	while (l) {
		putchar(y % 10 + 48);
		y /= 10;
		l--;
	}
}

template <typename T> inline void writes(T x) {
	write(x);
	putchar(' ');
}

template <typename T> inline void writeln(T x) {
	write(x);
	puts("");
}

template <typename T> inline void checkmax(T &a,T b) { a = a > b ? a : b; }

template <typename T> inline void checkmin(T &a,T b) { a = a < b ? a : b; }

const int N = 2e5 + 10;

bool chg[N];

struct wzy {
	LL x, c;
	wzy (LL X = 0,LL C = 0) {
		x = X;
		c = C;
	}
};

struct Point {
	LL x, y;
} p[N];

struct Opt {
	wzy x, y;
} opt[N];

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n;
	read(n);
	F(i, 1, n) {
		read(p[i].x);
		read(p[i].y);
	}
	int m;
	read(m);
	opt[0].x.x = 1;
	opt[0].y.x = 1;
	chg[0] = 0;
	F(i, 1, m) {
		int op;
		LL k;
		read(op);
		if (op == 1 || op == 2) {
			opt[i].x = opt[i - 1].y;
			opt[i].y = opt[i - 1].x;
			chg[i] = chg[i - 1] ^ 1;
		}
		else {
			opt[i].x = opt[i - 1].x;
			opt[i].y = opt[i - 1].y;
			chg[i] = chg[i - 1];
			read(k);
		}
		if (op == 1) { opt[i].y.x = -opt[i].y.x; opt[i].y.c = -opt[i].y.c; }
		if (op == 2) { opt[i].x.x = -opt[i].x.x; opt[i].x.c = -opt[i].x.c;}
		if (op == 3) { opt[i].x.x = -opt[i].x.x; opt[i].x.c = 2 * k - opt[i].x.c; }
		if (op == 4) { opt[i].y.x = -opt[i].y.x; opt[i].y.c = 2 * k - opt[i].y.c; }
	}
	int q;
	read(q);
	F(i, 1, q) {
		int ti, pi;
		read(ti);
		read(pi);
		LL x = p[pi].x;
		LL y = p[pi].y;
		if (chg[ti]) swap(x, y);
		writes(x * opt[ti].x.x + opt[ti].x.c);
		writeln(y * opt[ti].y.x + opt[ti].y.c);
	}
	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long W, std::vector<long long> S, std::vector<long long> T, std::vector<long long> P){
  vector<ll> time(200002);
  REP(N){
    time[S[i]]+=P[i];
    time[T[i]]-=P[i];
  }
  REP(time.size()-1){
    time[i+1]+=time[i];
  }
  REP(time.size()){
    if(time[i]>W){
      cout<<NO<<endl;
      return;
    }
  }
  cout<<YES<<endl;
}

int main(){
  cout<<setprecision(1000);
    long long N;
    scanf("%lld",&N);
    long long W;
    scanf("%lld",&W);
    std::vector<long long> S(N);
    std::vector<long long> T(N);
    std::vector<long long> P(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&S[i]);
        scanf("%lld",&T[i]);
        scanf("%lld",&P[i]);
    }
    solve(N, W, std::move(S), std::move(T), std::move(P));
    return 0;
}

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

int main(){
    int64_t n, w;
    cin >> n >> w;
    vector<int> s(n);
    vector<int> t(n);
    vector<int64_t> p(n);
    vector<int64_t> sum(2000005);
    string ans = "Yes";

    for(int i = 0;i < n;i++){
        cin >> s.at(i) >> t.at(i) >> p.at(i);
        sum.at(s.at(i))+=p.at(i);
        sum.at(t.at(i))-=p.at(i);
    }

    for(int i = 0;i < sum.size()-1;i++){
        sum.at(i+1) += sum.at(i);
        if(sum.at(i) > w){
            ans = "No";
        }
    }
    cout << ans << endl;

}


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

int main()
{
  ull n, a; cin >> n;
  ull ans = 0;
  vector<ull> mod(200);
  rep(i, n)
  {
    cin >> a;
    mod.at(a % 200)++;
  }
  rep(i, 200)
  {
    if (mod.at(i) > 0) ans += mod.at(i) * (mod.at(i)-1) / 2;
  }
  cout << ans << endl;
}

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

# define endl "\n"
# define io_boost std::ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
typedef unsigned long long int ulli;
typedef long long int lli;
typedef unsigned int ui;

int N, A[200005];

int main(){
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];
    int m[200] = {0};
    lli ans = 0;
    for(int i = 0; i < N; i++)
        ans += m[A[i] % 200], m[A[i] % 200]++;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver2 {
 public:
  int n, m;
  vector<vector<int>> g, ans;
  vector<int> cnt, dep;
  vector<pair<int, int>> edge;
  Solver2(LL n, LL m) : n(n), m(m), g(n), ans(n, vector<int>(n)), cnt(n), dep(n, -1){};

  void solve() {
    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      g[--a].push_back(--b);
      g[b].push_back(a);
      edge.emplace_back(a, b);
    }
    for (int i = 0; i < n; ++i) {
      cin >> cnt[i];
    }
    for (int i = 0; i < n; ++i) {
      if (dep[i] < 0) {
        dfs(i, -1, 0);
      }
    }

    for (int i = 0; i < m; ++i) {
      if (cnt[edge[i].first] > cnt[edge[i].second]) {
        //|| (cnt[edge[i].first] == cnt[edge[i].second] && dep[edge[i].first] < dep[edge[i].second])) {
        ans[edge[i].first][edge[i].second] = 1;
      } else if (cnt[edge[i].first] < cnt[edge[i].second]) {
        ans[edge[i].first][edge[i].second] = -1;
      }
    }
    DBG(ans)
    for (int i = 0; i < m; ++i) {
      if (ans[edge[i].first][edge[i].second] > 0) {
        cout << "->" << endl;
      } else {
        cout << "<-" << endl;
      }
    }
  }
  void dfs(int c, int p, int d) {
    dep[c] = d;
    for (auto v : g[c]) {
      if (v != p && cnt[v] == cnt[c]) {
        if (ans[c][v] == 0) {
          ans[c][v] = 1;
          ans[v][c] = -1;
        }
        if (dep[v] < 0) dfs(v, c, d + 1);
      }
    }
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, m;
  std::cin >> n >> m;

  Problem::Solver2 sol(n, m);
  sol.solve();
  return 0;
}

#include <iostream>
#include <math.h>
#include <iomanip>
#include <bits/stdc++.h>
#include <string.h>
#include <string>
#include <algorithm>
#define ll long long int
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))

using namespace std;

ll binomialCoeff(ll n,ll k)
{
    ll res = 1;
    if(k >n - k)
        k = n - k;
    for(int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

ll power(ll x,ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return (temp*temp);
    else
        return (((x*temp))*temp);
}

//nCr % mod
//const int N0 = 2e5 + 5;
//ll fact[6*N0];
//ll inv[6*N0],invfac[6*N0];
//ll mod = 1e9 + 7;
//
//void factorial()
//{
//    fact[0] = invfac[0] = fact[1] = invfac[1] = 1;
//    inv[1] = 1;
//    for(int i=2;i<=5*N0 + 10;i++)
//    {
//        fact[i] = (fact[i-1]*i)%mod;
//        inv[i] = (inv[mod%i]*(mod - mod/i))%mod;
//        invfac[i] = (invfac[i-1]*inv[i])%mod;
//    }
//}

vector<ll> primes;

void Sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          primes.push_back(p);
}

//******************************************************    CHECK CONSTRAINTS   ***************************************************************//

const int N = 2e5 + 5;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    int l[n+1],r[n+1];
    int b[2*n + 1] = {0};
    bool bad = 0;
    bool dp[2*n + 1] = {0};
    for(int i=1;i<=n;i++)
    {
        cin >> l[i] >> r[i];
        if(l[i]!=-1)
        {
            if(b[l[i]])
                bad = 1;
            b[l[i]] = i;
        }
        if(r[i] != -1)
        {
            if(b[r[i]])
                bad = 1;
            b[r[i]] = i;
        }
        if(r[i]!=-1 && l[i] > r[i])
            bad = 1;
    }
    dp[0] = 1;
//    for(int i=1;i<=2*n;i++)
//        cout << b[i] << " ";
//    cout << "\n";
    if(bad)
        return cout << "No",0;
    for(int i=1;i<=2*n;i+=2)
    {
        bool found = 0;
        for(int len = 2;len + i - 1<= 2*n;len += 2)
        {
            int f = 0;
            bool good = 1;
            int k = len/2;
            for(int j = i;j <= i - 1 + k;j++)
            {
                int x = b[j];
                int y = b[j+k];
                if(x == 0 && y == 0)
                    continue;
                if(x && y)
                {
                    if(x != y)
                    {
                        good = 0;
                        break;
                    }
                    f = 1;
                }
                if(y==0)
                {
                    if(r[x] != -1)
                    {
                        good = 0;
                        break;
                    }
                }
                if(x==0)
                {
                    if(l[y] != -1)
                    {
                        good = 0;
                        break;
                    }
                }
            }
            //cout << i << " " << len << " " << good << "\n";
            if(good)
            {
                found = 1;
                dp[i + len - 1] |= dp[i-1];
                //cout << i << " " << len << " " << dp[i-1] << " " << dp[i + len - 1] <<  '\n';
            }
        }
    }
//    for(int i=1;i<=2*n;i++)
//        cout << dp[i] << " ";
//    cout << "\n";
    if(dp[2*n])
        cout << "Yes";
    else
        cout << "No";
}


#include<bits/stdc++.h>
#include<iterator>
#include<math.h>

#define optimize()      ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll                     long long int
#define pb                   push_back
#define fi(a,b,c)           for(i=a;i<=b;i=i+c)
#define fia(a,b,c)         for(i=a;i<b;i=i+c)
#define scl(n)              scanf("%lld", &n)
#define scf(n)              scanf("%lf", &n)
#define pfl(x)              printf("%lld\n",x)
#define ct                    cout
#define cn                   cin
#define nl                    '\n'
using namespace std;
int oct(int n)
{
    while(n!=0)
    {
        int x=n%8;
        if(x==7) return 1;
        n/=8;
    }
    return 0;
}
int dec(int n)
{
    while(n!=0)
    {
        int x=n%10;
        if(x==7) return 1;
        n/=10;
    }
    return 0;
}

// Driver program to test above
int main()
{
    int n,i,c=0;
    cn>>n;
    fi(1,n,1)
    {
        if(dec(i)) {c++;continue;}
        if(oct(i)) c++;
    }
    ct<<n-c<<nl;

}

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

   typedef long long ll;

   using namespace std;

   int main(){

         int n,m;
         cin>>n;
         ll sum=0;
         while(n-->0){
            ll a,b;
            cin>>a>>b;

            sum += ((a+b)*(b-a+1))/2;
         }
         cout<<sum<<endl;
      return 0;
   }


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPE(i,l,n) for(ll i=l;i<=ll(n);i++)
#define FORA(i,I) for(const auto& i:I)
#define ALL(v) v.begin(),v.end()
#define UQ(v) v.erase(unique(ALL(v)), v.end())
#define ACM(v) accumulate(ALL(v), 0)
#define P(str) cout << str << endl
#define VLL vector<ll>
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
constexpr int64_t INF = 1e18;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<VLL> v(n, VLL(n));
    REP(i, n)REP(j, n){
        cin >> v[i][j];
    }
    ll cnt = 0;
    VLL a(n - 1);
    iota(ALL(a),1);
    do{
        ll p = 0;
        ll tmp = 0;
        REPE(i, 0, n - 2){
            tmp += v[p][a[i]];
            p = a[i];
        }
        tmp += v[p][0];
        if(tmp == k) ++cnt;
    }while(next_permutation(ALL(a)));
    P(cnt);
}

// Code written by Shubham Agarwal

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define V 8
using namespace std;

void tsp(ll graph[][V], vector<bool>& v, ll currPos,
         ll n, ll count, ll cost, ll& ans, ll k, int &cnt)
{
    if (count == n && graph[currPos][0]) {
    	if(cost + graph[currPos][0] == k)
    		cnt++;
        ans = min(ans, cost + graph[currPos][0]);

        return;
    }

    for (int i = 0; i < n; i++) {
        if (!v[i] && graph[currPos][i]) {

            v[i] = true;

            tsp(graph, v, i, n, count + 1,
                cost + graph[currPos][i], ans, k, cnt);

            v[i] = false;
        }
    }
}

int main(){
	fastio;
	ll n, k;
	cin >> n >> k;
	ll graph[V][V];
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			cin >> graph[i][j];
		}
	}
	vector<bool> v(n);
    for (int i = 0; i < n; i++)
        v[i] = false;
   v[0] = true;
    ll ans = INT_MAX;
    int cnt = 0;
    tsp(graph, v, 0, n, 1, 0, ans, k, cnt);

    cout << cnt;
	return 0;
}


/******************************
 * author: minhkhoa           *
 * location:                  *
 ******************************/
#include <bits/stdc++.h>

using namespace std;

typedef long long int64;
typedef vector<int> vi;
typedef pair<int, int> ii;

const int P = 998244353;

int solve(int A, int B, int C) {
  int64 A1 = 1LL * A * (A + 1) / 2;
  A1 %= P;
  int64 B1 = 1LL * B * (B + 1) / 2;
  B1 %= P;
  int64 C1 = 1LL * C * (C + 1) / 2;
  C1 %= P;
  return (((A1 * B1) % P) * C1) % P;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int A, B, C;
  cin >> A >> B >> C;
  int64 ans = solve(A, B, C);
  cout << ans << "\n";
#ifdef LOCAL
  cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
#endif
  return 0;
}

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

// MODINT
const int MOD = 998244353;
struct mint {
    long long x;
    mint(long long x = 0):x((x % MOD + MOD) % MOD) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    mint inv() const { return pow(MOD - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
    bool operator==(const mint& a) const { return x == a.x; }
};
mint modpow(mint x, ll t) { return x.pow(t); }
mint modinv(mint x) {return x.inv(); }
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

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

    ll n, m, k; cin >> n >> m >> k;
    if (n == 1) {
        mint ans = 0;
        for (int i = 1; i <= k; i++) {
            ans += modpow(mint(k - i + 1), m) - modpow(mint(k - i), m);
        }
        cout << ans << endl;
    }
    else if (m == 1) {
        mint ans = 0;
        for (int i = 1; i <= k; i++) {
            ans += modpow(i, n) - modpow(i - 1, n);
        }
        cout << ans << endl;
    }
    else {
        mint ans = 0;
        for (int i = 1; i <= k; i++) {
            ans += (modpow((mint)i, n) - modpow((mint)(i - 1), n))* modpow((mint)k - i + 1, m);
        }
        cout << ans << endl;
    }

    return 0;
}


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

#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define iint int
#define f(i,a,b)        for(ll i=a;i<b;i++)
#define f0(i,n)         f(i,0,n)
#define fr(i,a,b)       for(ll i=a;i>=b;i--)
#define for1(i,n)       for(ll i=1;i<=n;i++)
#define pb              push_back
#define tc(t)           int t;cin >>t;while(t--)
#define lol             std::ios::sync_with_stdio(false); cin.tie(NULL);
#define endl            "\n"
#define ss              second
#define ff              first
#define ll              long long
#define lld             long double
#define int             long long
#define pii             pair< int,int >
#define pll             pair< ll,ll >
#define sz(a)           a.size()
#define inf             (1000*1000*1000+5)
#define all(a)          a.begin(),a.end()
#define arr(a,n)        int a[n];f0(i, n) cin >> a[i];
#define ini(a,n)        memset(a,n,sizeof(a))
#define printArr(a,n)   f0(i,n) cout<<a[i]<<" ";
#define in              cin>>
#define rr              return 0;
#define vi              vector< int >
#define vs              vector<string>
#define l_b             lower_bound
#define u_b             upper_bound
#define mod             1000000007
#define pi              3.141592653589793238
#define fmap(m)         for(auto it:m)
#define deb(args...)    { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define debarr(arr,a,b) for(int i=(a);i<(b);i++) cout<<(arr[i])<<" ";cout<<endl;
#define long_max        numeric_limits<ll>::max()

vs tokenizer(string str, char ch) {std::istringstream var((str)); vs v; string t; while (getline((var), t, (ch))) {v.pb(t);} return v;}

void remove_dup(vi &a)
{
    auto it = unique(a.begin(), a.end());
    a.resize(distance(a.begin(), it));
}

int dx[8] = { +1, +1, +1, 0, 0, -1, -1, -1};
int dy[8] = { +1, 0, -1, +1, -1, +1, 0, -1};

int dx4[4] = { +1 , -1 , +0 , +0};
int dy4[4] = { 0  , 0 , +1 , -1};

const int N = 5e5 + 10;

const int m = 998244353;

int power(int a, int b) //a^b korte hobe   (binary exponentiation)
{
    int result = 1;
    while (b)
    {
        if (b & 1)
        {
            result = (a % m * result % m) % m;
            b--;
        }
        else
        {
            a = (a % m * a % m) % m;
            b >>= 1;
        }
    }
    return result % m;
}

int pow_inverse(int n)
{
    return power(n, m - 2) % m;
}

bool digit(int n)
{
    string s = to_string(n);
    return s.size();
}

void solve()
{
    int n;
    cin >> n;
    arr(a, n);
    arr(b, n);
    int l = min(a[0], b[0]);
    int r = max(a[0], b[0]);
    f(i, 1, n)
    {
        l = max({l , a[i]});
        r = min({r , b[i]});
    }
    if (l <= r)
        cout << r - l + 1 << "\n";
    else
        cout << "0\n";
}

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

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

#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <algorithm>
#include <math.h>
using namespace std;
int main(){
 int n;cin>>n;
 vector<int> a(n);
 for (int i = 0; i < n; i++)cin>>a[i];
int mx = -1;
int ans = 0;
   for (int j = 2; j < 100000; j++)
 {
   int count = 0;
 for (int i = 0; i < n; i++)
   {

     if(a[i]%j == 0)count++;
   }
   mx = max(mx,count);
   if(mx == count)ans = j;
 }
 cout<<ans<<endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;
int mas[8];
int dist[256];
int dist1[8][8];
int ans[8];
pair<int,int> parts[100000];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m,ma=0;
    cin>>n>>m;
    for(int i=0; i<n; i++){
        cin>>mas[i];
        ma=max(ma,mas[i]);
    }
    for(int i=0; i<m; i++){
        cin>>parts[i].first>>parts[i].second;
        if(ma>parts[i].second){
            cout<<-1;
            return 0;
        }
    }
    for(int i=0; i<(1<<n); i++){
        if(__builtin_popcount(i)<2) continue;
        int sum=0;
        for(int j=0; j<n; j++){
            if(i&(1<<j)){
                sum+=mas[j];
            }
        }
        for(int k=0; k<m; k++){
            if(sum>parts[k].second){
                dist[i]=max(dist[i],parts[k].first);
            }
        }
    }
    int ANS1=1e9;
    vector<int> a;
    for(int i=0; i<n; i++) a.push_back(i);
    do{
        for(int i=0; i<n; i++)
            for(int j=0; j<n; j++)
                dist1[i][j]=0;
        for(int i=1; i<(1<<n); i++){
            int mi=n+1,ma=0;
            for(int j=0; j<n; j++){
                if(i&(1<<j)){
                    mi=min(mi,a[j]);
                    ma=max(ma,a[j]);
                }
            }
            dist1[mi][ma]=max(dist1[mi][ma],dist[i]);
        }
        ans[0]=0;
        for(int i=1; i<=n-1; i++){
            int a=ans[i-1];
            for(int j=0; j<i; j++){
                a=max(a,dist1[j][i]+ans[j]);
            }
            ans[i]=a;
        }
        ANS1=min(ANS1,ans[n-1]);
    }while(next_permutation(a.begin(),a.end()));
    cout<<ANS1;
}

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

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

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

int pref_dist[N], pref_weight[N];

int main() {
  FIO
  int n, m; read(n, m);
  vector<int> w(n); read(w);
  vector<pair<int,int>> arr(m); read(arr);
  map<int,int> mx_dist;
  int mxw = *max_element(all(w));
  trav(x, arr) {
    if (x.second < mxw) {
      print("-1");
      return 0;
    }
    if (mx_dist.count(x.second))
      mx_dist[x.second] = max(mx_dist[x.second], x.first);
    else
      mx_dist[x.second] = x.first;
  }
  int len = 0;
  for (auto x: mx_dist) {
    pref_weight[len] = x.first;
    pref_dist[len] = x.second;
    if (len)
      pref_dist[len] = max(pref_dist[len], pref_dist[len-1]);
    len++;
  }
  vector<int> ind(n, 0);
  iota(all(ind), 0);
  int ans = inf;
  do {
    vector<int> pos(n, 0);
    for (int i = 0; i < n; i++) {
      int pref = w[ind[i]], nx = 0;
      if (i) pos[i] = pos[i-1];
      for (int j = i-1; j >= 0; j--) {
        pref += w[ind[j]];
        auto it = lower_bound(pref_weight, pref_weight + len, pref) - pref_weight - 1;
        if (it < 0)
          continue;
        pos[i] = max(pos[i], pos[j] + pref_dist[it]);
      }
    }
    // print(ind, "+", pos);
    ans = min(ans, pos[n-1]);
  } while (next_permutation(all(ind)));
  print(ans);
  return 0;
}


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

// #include <atcoder/all>
using namespace std;
using namespace __gnu_pbds;
using ll = long long int;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define SZ(x) ((int)(x).size())

#define FASTIO() cin.tie(0); ios::sync_with_stdio(false)
#define FASTIOpre() cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);

// chmax/min: if update a then true
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ceil(a,b) (((a) + ((b) - 1)) / (b))

template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }

//////////////////////////////////////

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
//unordered_map<long long, int, custom_hash> safe_map;
//gp_hash_table<long long, int, custom_hash> safe_hash_table;

#define Yes std::cout << "Yes" << std::endl;
#define No std::cout << "No" << std::endl;
#define YES std::cout << "YES" << std::endl;
#define NO std::cout << "NO" << std::endl;

template <typename T> void resprint(const vector<T>& arg) { for(int i=0; i < (int)arg.size() - 1; ++i) {cout << arg.at(i) << " ";} cout << arg[arg.size()-1] << "\n";};
//////////////////////////////////////

ll mod = 998244353LL;

ll myfact(int n){
    ll x = 1;
    FOR(i, 1, n+1){
        x = (x * i) ;
        x %= mod;
    }
    return x;
}

using namespace std;
int main() {
    FASTIOpre();
    ll n;
    cin >> n;
    vector<ll> dat(n);
    ll total = 0;
    ll x;
    REP(i, n){
        cin >> x;
        total += x;
        dat.at(i) = x;
    }
    if(total % 2 == 1){
        cout << 0 << "\n";
        return 0;
    }
    vector<vector<vector<ll>>> dp(10200, vector<vector<ll>>(110, vector<ll>(110, 0LL)));
    dp.at(0).at(0).at(0) = 1LL;
    REP(i, n){
        REP(value, 5100){
            REP(cnt, i + 1){
                dp[value][i + 1][cnt] += dp[value][i][cnt];
                dp[value][i + 1][cnt] %= mod;
                if(value+dat[i] > 5100) continue;
                dp[value + dat[i]][i + 1][cnt + 1] += dp[value][i][cnt];
                dp[value + dat[i]][i + 1][cnt + 1] %= mod;
            }
        }
    }

    ll res = 0;
    ll tmp = 0;

    FOR(i, 0, n){
        if(dp[total / 2][n][i] != 0){
            tmp =  ((myfact(i) * myfact(n-i)) % mod) * dp[total / 2][n][i];
            res += tmp;
            res %= mod;
        }
    }
    cout << res % mod<< "\n";

}

//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("-Ofast","-funroll-all-loops","-ffast-math")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <cmath>
#include <chrono>
#include <cstring>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <bitset>
#include <cassert>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define endl '\12'
#define eb emplace_back
#define SZ(a) int32_t(a.size())
#define ALL(x) (x).begin(),(x).end()
#define trav(a,x) for (auto& a: x)
#define LOG(FMT...) fprintf(stderr, FMT)
#define close std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define CASET int ___T; cin>>___T; for(int __CS=1;__CS<=___T;__CS++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
constexpr int mod = 1e9+7;
constexpr int Erica = 998244353;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count());
int rnd(int x) { return mrand() % x;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll ex_gcd(ll a, ll b, ll& x, ll& y){if(!b){x=1;y=0;return a;}ll ret=ex_gcd(b,a%b,y,x);y-=a/b*x;return ret;}
LL bin(LL x, LL n, LL MOD) {LL ret = MOD != 1;for (x %= MOD; n; n >>= 1, x = x * x % MOD)if (n & 1) ret = ret * x % MOD;return ret;}
int norm(int x) { return x >= mod ? (x - mod) : x; }
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
inline ll get_inv(ll a) { ll x, y; ex_gcd(a, mod, x, y); return norm(x + mod);}
template<class T>inline void umin(T &x, T y) {x = x > y ? y : x;}
template<class T>inline void umax(T &x, T y) {x = x < y ? y : x;}
template<class T>inline void dec(T &x, T y) {x -= y; if(x < 0) x += mod;}
template<class T>inline void add(T &x, T y) {x += y; if(x >= mod) x -= mod;}
const double PI = acos(-1.0);
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr ull base=2333, P_1=19260817, P_2=999998639;
constexpr int maxn = 1e6+10; // remember to calculate. if tle, check maxn first.

int main()
{
    int n;
    cin >> n;umax(n , 0);
    cout << n << endl;
    return 0;
}


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

int main(){
   vector<int> inp;
   for(int i = 0;i < 3;i++){
      int a;
      cin >> a;
      inp.push_back(a);
   }

   sort(inp.begin(),inp.end());
   cout << inp.at(2)+inp.at(1) << endl;
}

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

#define ll long long
#define FI first
#define SE second
#define pb push_back
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define endl '\n'
#define double long double
#define OOK order_of_key  //no of elements strictly less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/

signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{//cout<<"Case #"<<T1<<": ";
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    int s=a[1]+a[2];
    cout<<s<<endl;
}

return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  int ans = (y * z + x - 1) / x - 1;
  cout << ans << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b)
        cout<<c<<endl;
    else if(a==c)
        cout<<b<<endl;
    else if(b==c)
        cout<<a<<endl;
    else if(a!=b && b!=c && c!=a)
        cout<<0<<endl;
    return 0;

}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <functional>
#include<cmath>
#include<string>
#include<string.h>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include <stdio.h>
#include<bitset>
using namespace std;
#define endl '\n'
#define ll long long
#define d double
#define ull unsigned long long
#define ld long double
#define PI acos(-1)
#define f(n) for (int i = 0; i <n; i++)
#define fn(n) for (int i = 1; i <=n; i++)
#define cc cout<<'\n'
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sz(x) x.size()
#define fx(n) fixed<<setprecision(n)
#define Ceil(x,y) (x+y-1)/y
#define rt return
#define mem(x,y)    memset(x,y,sizeof(x))
#define RT(n) rt cout<<n,0
#define test ll t;cin>>t;while(t--)
const ll MOD = 1e9 + 7;
using namespace std;
void A_KHALIFA()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}
void file() {
	//cout << flush;
#ifndef ONLINE_JUDGE
	freopen("standard.in", "r", stdin);
	freopen("standard.out", "w", stdout);
#endif
	//freopen("cases.in", "r", stdin);
	//freopen("output.out", "w", stdout);
}
ll fastpow(ll x, ll k)
{
	ll ret = 1;
	while (k) {
		if (k & 1) ret = ((ret % MOD) * (x % MOD)) % MOD;
		k >>= 1; x = ((x % MOD) * (x % MOD)) % MOD;
	}
	return ret;
}
int main()
{
	file();
	A_KHALIFA();

	int n, q;
	cin >> n >> q;
	vector<ll>v(n);
	vector<ll>vv(n);
	vector<ll>prefix(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
	}
	sort(all(v));
	vv[0] = v[0] - 1;
	for (int i = 1; i < n; i++)
	{
		vv[i] = v[i] - (v[i-1]+1);
	}
	/*for (int i = 0; i < n; i++)
	{
		cout << vv[i] << ' ';
	}cc;
	rt 0;*/
	prefix[0] = vv[0];
	for (int i = 1; i < n; i++)
	{
		prefix[i] = vv[i];
		prefix[i] += prefix[i - 1];
	}
	/*for (int i = 0; i < n; i++)
		cout << prefix[i] << ' ';*/

	while (q--)
	{
		ll num;
		cin >> num;
		if (num <= prefix.back())
		{
			int l = 0, r = n - 1, mid,idx;
			while (l <= r)
			{
				mid = (l + r) / 2;
				if (prefix[mid] < num)
				{
					l = mid + 1;
				}
				else
				{
					r = mid - 1; idx = mid;
				}
			}
			cout << v[idx] - (prefix[idx] - num + 1) << endl;

		}
		else
		{
			cout << v.back() + (num - prefix.back()) << endl;
		}
	}

}

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define all(a) (a).begin(), (a).end()
#define mp make_pair

template<typename T1, typename T2>
inline void chkmin(T1& x, const T2& y) {
    if (y < x) x = y;
}

template<typename T1, typename T2>
inline void chkmax(T1& x, const T2& y) {
    if (x < y) x = y;
}

const int N = 1e5 + 228;
const ll INF = (ll)1e18 + N;
int n, q;
ll a[N];

bool check(ll val, ll cnt) {
    int pos = upper_bound(a, a + n, val) - a;
    return val - pos >= cnt;
}

void solve() {
    ll k;
    cin >> k;
    ll l = 0, r = INF;
    while (l < r - 1) {
        ll m = (l + r) / 2;
        if (check(m, k)) {
            r = m;
        } else {
            l = m;
        }
    }
    cout << r << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout.precision(20), cout.setf(ios::fixed);
    cin >> n >> q;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    while (q--) {
        solve();
    }
    return 0;
}


#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 ll long long
//#define file
using namespace std;

int i,j,k,l;
ll n,K,ans,s;

ll js(int t)
{
	if (t<2 || t>n*2) return 0;
	if (t<=n+1) return t-1;
	return n*2+1-t;
}

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

	scanf("%d%d",&n,&K);
	fo(i,2,n+n)
	{
		s=i-K;
		ans+=js(i)*js(s);
	}
	printf("%lld\n",ans);

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

//Code by Ritik Agarwal
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)(x).size()
#define int long long int
#define loop(i,a,b) for(int i=a;i<b;i++)
#define scan(arr,n) for (int i = 0; i < n; ++i) cin >> arr[i]
#define vi vector<int>
#define si set<int>
#define pii pair <int, int>
#define sii set<pii>
#define vii vector<pii>
#define mii map <int, int>
#define pb push_back
#define ff first
#define ss second
#define all(aa) aa.begin(), aa.end()
#define rall(a) a.rbegin() , a.rend()
#define read(a,b) int a,b;  cin>>a>>b
#define readt(a,b,c) int a,b,c; cin>>a>>b>>c
#define readf(a,b,c,d) int a,b,c,d; cin>>a>>b>>c>>d;
#define print(v) for(auto x:v) cout<<x<<" ";cout<<endl
#define printPair(res) for(pair<int,int>& p:res) cout<<p.first<<" "<<p.second<<endl;
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
//*****  Constants  *****
const int mod = 1000000007; /* 1e9 + 7*/
const int MAXN = 1000005; /*1e6 +5 */
const int mod1= 998244353;
const int NAX=2E5+5;
int vis[MAXN]={0};
int fac[300001];
void fact(int m){fac[0]=1;for(int i=1;i<=300000;i++) fac[i]=(fac[i-1]%m * i%m)%m;}
/* Iterative Function to calculate (x^y)%p in O(log y)*/
long long power( long long x,  int y, int p){   long long res = 1;
x = x % p; while (y > 0) { if (y & 1)  res = (res * x) % p;  y = y >> 1; x = (x * x) % p;} return res;}
// Returns n^(-1) mod p
long long modInverse( long long n, int p) {  return power(n, p - 2, p); }
long long nCr( long long n,int r, int p) { if (r == 0) return 1; if(n<r) return 0;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; }

int binarySearch(vi arr, int l, int r, int x) {
if (r >= l) { int mid = l + (r - l) / 2; if (arr[mid] == x) return mid;
if (arr[mid] > x)  return binarySearch(arr, l, mid - 1, x);
return binarySearch(arr, mid + 1, r, x); } return -1; }

void solve(int test)
{
read(n,k);
int ans=0;
// loop(a,1,n+1)
// {
//   loop(b,1,n+1)
//   {
//     loop(c,1,n+1)
//     {
//       loop(d,1,n+1)
//       {
//         if(a+b== k+c+d)
//         {
//           cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
//           ans++;
//         }
//       }
//     }
//   }
// }
// cout<<ans<<endl;

 ans=0;
 int maxm=1+n;
 int perm[2*n +1]={0};
 perm[2]=1;
 perm[3]=2;
 int tt=0;
 for(int i=4;i<=n+n;i++)
 {
  int me=i-1;
  if(me>n)
    me=n;
int val=((me - (i+1)/2) +1 )*2;
if(i%2==0)
  val--;
  perm[i]=val;
 }
 //cout<<
 k=abs(k);
if(k>=0)
{
      for(int i=2 ; i<=n+n-k ; i++)
      {
        int left=i;
        int right=i+k;
       // cout<<left<<" "<<right<<endl;
        int r1=perm[left] , r2=perm[right];
        ans+=(r1*r2);

      }

}
cout<<ans<<endl;

}

int32_t main()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);
      #endif
      faster;
      //fact(mod);
      int t=1;
     // cin>>t;
      for(int test=1;test<=t;test++)
      {
          solve(test);
      }
}


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

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

using ll = long long;
using P = pair<int, int>;
using vvi = vector<vector<int>>;
using vi = vector<int>;

const ll MOD = 1e9 + 7;
const int INF = 1001001001;
const double PI = 3.14159265358979323846;

void solve() {
    int n, m, k;
    cin >> n >> m;
    vvi G(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    cin >> k;
    vector<int> C(k);
    rep(i, k) {
        int c;
        cin >> c;
        c--;
        C[i] = c;
    }

    vvi cost(k);
    auto bfs = [&](int start) {
        vector<int> mindist(n, INF);
        queue<P> q;
        q.push(make_pair(start, 0));
        mindist[start] = 0;
        while (!q.empty()) {
            auto now = q.front(); q.pop();
            for (auto next : G[now.first]) {
                int nd = now.second + 1;
                if (mindist[next] <= nd) continue;
                mindist[next] = nd;
                q.push(make_pair(next, nd));
            }
        }
        vector<int> res(k);
        rep(i, k) res[i] = mindist[C[i]];
        return res;
    };

    rep(i, k) cost[i] = bfs(C[i]);

    vector<vector<ll>> dp(1<<k, vector<ll>(k, INF));
    rep(i, k) dp[1<<i][i] = 1;

    for (int x = 0; x < (1<<k); x++) {
        rep(to, k) {
            rep(from, k) {
                if (x != 0 && !(x & (1<<from))) continue;
                if ((x & (1<<to)) == 0) {
                    if (to != from) {
                        chmin(dp[x|(1<<to)][to], dp[x][from] + cost[from][to]);
                    }
                }
            }
        }
    }
    ll ans = INF;
    rep(i, k) chmin(ans, dp[(1<<k)-1][i]);
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}

int main() {

    solve();

    return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#define int long long
namespace do_while_true {
	#define ld double
	#define ll long long
	#define re register
	#define pb push_back
	#define fir first
	#define sec second
	#define pp std::pair<int, int>
	#define mp std::make_pair
	const ll mod = 1000000007;
	template <typename T>
	inline T Max(re T x, re T y) { return x > y ? x : y; }
	template <typename T>
	inline T Min(re T x, re T y) { return x < y ? x : y; }
	template <typename T>
	inline T Abs(re T x) {	return x < 0 ? -x : x; }
	template <typename T>
	inline void read(re T& r) {
		r = 0; bool w = 0; char ch = getchar();
		while(ch < '0' || ch > '9') w = ch == '-' ? 1 : 0, ch = getchar();
		while(ch >= '0' && ch <= '9') r = r * 10 + (ch ^ 48), ch = getchar();
		r = w ? -r : r;
	}
	template <typename T>
	inline T qpow(re T x, re T y) {
		re T sumq = 1; x %= mod;
		while(y) {
			if(y&1) sumq = sumq * x % mod;
			x = x * x % mod;
			y >>= 1;
		}
		return sumq;
	}
}
using namespace do_while_true;

const int N = 100010;
const int INF = 0x3f3f3f3f;

int n, m, k, ent, head[N];
bool vis[N];
int c[N], cost[18][18], dis[N], f[300000][18];
struct Edge {
	int next, to;
}e[N << 1];
inline void add(int x, int y) {
	e[++ent].to = y; e[ent].next = head[x]; head[x] = ent;
}

std::priority_queue< pp >q;

void Dij(int p) {
	for(int i = 1; i <= n; ++i) vis[i] = 0, dis[i] = INF;
	dis[c[p]] = 0; q.push(mp(0, c[p]));
	while(!q.empty()) {
		int x = q.top().sec; q.pop();
		if(vis[x]) continue;
		vis[x] = 1;
		for(int i = head[x]; i; i = e[i].next) {
			int v = e[i].to;
			if(dis[v] > dis[x] + 1) {
				dis[v] = dis[x] + 1;
				q.push(mp(-dis[v], v));
			}
		}
	}
	for(int i = 1; i <= k; ++i) cost[p][i] = dis[c[i]];
}
inline int lowbit(int x) { return x & (-x); }

void solve() {
	read(n); read(m);
	for(int i = 1, x, y; i <= m; ++i) {
		read(x); read(y);
		add(x, y); add(y, x);
	}
	read(k); for(int i = 1; i <= k; ++i) read(c[i]);
	for(int i = 1; i <= k; ++i)
		Dij(i);
	for(int i = 0; i < (1 << k); ++i) {
		for(int j = 1; j <= k; ++j) f[i][j] = INF;
		if(i - lowbit(i) == 0) {
			for(int j = 1; j <= k; ++j)
				if((1 << (j-1)) & i)
					f[i][j] = 1;
		}
		else {
			for(int j = 1; j <= k; ++j)
				if((1 << (j-1)) & i) {
					for(int l = 1; l <= k; ++l)
						f[i][j] = Min(f[i][j], f[i- (1 << (j-1))][l] + cost[l][j]);
				}
		}
	}
	int ans = INF;
	for(int i = 1; i <= k; ++i)
		ans = Min(ans, f[(1 << k)-1][i]);
	if(ans == INF) puts("-1");
	else printf("%lld\n", ans);
}

signed main() {
	#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	#endif
//	freopen("out1.txt", "w", stdout);
	int T = 1;
//	read(T);
	while(T--)
		solve();
	fclose(stdin);
	return 0;
}


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

#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define fp(i,a,b) for(int i=a ; i<b ; i++)
#define fn(i,a,b) for(int i=a ; i>=b ; i--)
#define ones(x) __builtin_popcount(x)
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define dbg(x) cout << (#x) << " = " << x << " "
#define fini cout << "\n";
#define line cout << "-----------------------------------\n";
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;/*
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
/*
int read (){
    int x = 0, f = 1; char s = getchar();while (s < '0' || s > '9') {if (s == '-') f = -1; s = getchar();}
    while (s >= '0' && s <= '9') x = x * 10 + s - '0', s = getchar();
    return x * f;
}*/
const int M=1e1+7;
const int N=1e4+7;
const ll inf=1e18;
const int mod=2147483647;

int h,w;
char mat[12][12];

void go(){
    cin >> h >> w;
    fp(i,1,h+1) fp(j,1,w+1) cin >> mat[i][j];

    int n = 0;
    fp(i,1,h){
        int acum = 0;
        fp(j,1,w+1){
            if (mat[i][j] == mat[i+1][j]){
                if (acum != 0) n++;
                acum = 0;
            }
            else acum++;
        }
    }

    fp(j,1,w){
        int acum = 0;
        fp(i,1,h+1){
            if (mat[i][j] == mat[i][j+1]){
                if (acum != 0) n++;
                acum = 0;
            }
            else acum++;
        }
    }

    cout << n << "\n";
}

int main(){

    fastio;
    int tst = 1;
    // cout << fixed << setprecision(12);
    // cin >> tst;
    fp(i,0,tst) go();

    return 0;
}

#include "bits/stdc++.h"
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, m = 0, n = 0, p = 0, q = 0, mod = 1000000007;
    string s;
    cin >> a >> b;
    vector<vector<char>> v(a,vector<char>(b));
    for(int i=0;i<a;i++)
    {
       for(int j=0;j<b;j++)
       {
           cin >> v.at(i).at(j);
       }
    }
    for(int i=0;i<a-1;i++)
    {
        for(int j=0;j<b-1;j++)
        {
            c=0;d=0;
            for(int k=0;k<2;k++)
            {
                for(int l=0;l<2;l++)
                {
                    if(v.at(i+k).at(j+l)=='.')
                    {
                        c++;
                    }
                    else
                    {
                        d++;
                    }
                }
            }
            if(c==3||d==3)
            n++;
        }
    }
    cout << n;
    return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef bitset<16> BS;
struct edge {
    int to, cost, id;
};
const double EPS = 1E-09;
const ll MOD = 1E+09 + 7; // =998244353;
const ll INF = 1E18;
const int MAX_N = 1E+05;

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

ll M;

string X;

bool f(ll n);

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

    cin >> X >> M;

    ll d = 0;
    for (auto x : X) {
        d = max(d, (ll)(x - '0'));
    }

    reverse(X.begin(), X.end());

    ll high = M + 1, low = 0;
    ll ans = 0;
    //ll high = (ll)(pow((double)M / (double)(X[X.size() - 1]), 1.0 / ((double)X.size() - 1.0))) + 100
    if (X.size() > 1) {
        while (true) {
            ll mid = (high + low) / 2;
            if (mid == high || mid == low)
                break;
            if (f(mid)) {
                high = mid;
            } else {
                low = mid;
            }
            //cout << "high = " << high << ", low = " << low << "\n";
        }
    } else {
        if (X[0] - '0' <= M)
            ans = 1;
    }

    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */

    cout << (X.size() == 1 ? ans : max(0LL, low - d)) << "\n";

    return 0;
}

// bool f(ll n)
// {
//     ll res = 0;
//     for (auto c : X) {
//         ll x = c - '0';
//         if (res > M / n)
//             return true;
//         res = res * n + x;
//     }
//     //cout << "n = " << n << ", res = " << res << "\n";
//     return res > M;
// }

bool f(ll n)
{
    ll res = 0;
    ll d = 1;
    for (int i = 0; i < X.size(); i++) {
        ll x = X[i] - '0';
        //cout << "xd = " << x * d << ", res = " << res << "\n";
        if (x > (M - res) / d)
            return true;
        res += x * d;
        if (n > M / d && i < (int)X.size() - 1)
            return true;
        d *= n;
    }
    return res > M;
}

// bool f(ll n)
// {
//     vector<ll> res;
//     ll m = M;
//     while (m > 0) {
//         res.push_back(m % n);
//         m /= n;
//     }
//     // cout << "n = " << n << "\n";
//     // cout << "Xsize = " << X.size() << ", res.size = " << res.size() << "\n";
//     if (res.size() != X.size())
//         return X.size() > res.size();

//     reverse(res.begin(), res.end());
//     for (int i = 0; i < X.size(); i++) {
//         ll x = X[i] - '0';
//         if (x > res[i])
//             return true;
//         else if (x < res[i])
//             return false;
//     }
//     return false;
// }

#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using ll_P = pair<ll,ll>;
const double PI=3.14159265358979323846;
const int INF = 1000000000;
const ll ll_INF = 1001001001001001001;
const int mod = 1000000007;

int n;
vector<int> p(200005);

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

    int now = 1;
    int last_sorted = 0;

    vector<int> ans;

    rep(i,n){
        if(p[i]==now){
            if(i==last_sorted){
                if(p[i]==n){
                    break;
                }
                cout << -1 << endl;
                return 0;
            }
            for(int j=i;j>last_sorted;j--){
                p[j] = p[j-1];
                ans.push_back(j);
            }
            p[last_sorted] = now;
            now = i+1;
            last_sorted = i;
            i--;
        }
    }
    bool flag = true;
    rep(i,n){
        if(p[i] != i+1) flag = false;
    }

    if(!flag){
        cout << -1 << endl;
    }
    else{
        rep(i,n-1){
            cout << ans[i] << endl;
        }
    }
}


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

//TEMPLATE
#define pb                push_back
#define mp                make_pair
#define ll                long long
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second

#define newline           printf("\n")
#define minusone          printf("-1\n")
#define zeroo             printf("0\n")
#define scl1(a)           scanf("%lld", &a)
#define scl2(a, b)        scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)     scanf("%lld %lld %lld", &a, &b, &c)
#define prl1(a)           printf("%lld\n", a)
#define prl2(a, b)        printf("%lld %lld\n", a, b)
#define ssl1(s)           scanf(" %[^\n]", s)
#define scd1(a)           scanf("%lf", &a)
#define scd2(a, b)        scanf("%lf %lf", &a, &b)
#define prd(a)            printf("%lf\n", a)
#define prld(a)           printf("%Lf\n", a)
#define prcase(cs)        printf("Case %lld: ", cs)
#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotline           cout << "\n"
#define cotminus          cout << "-1\n"
#define cot0              cout << "0\n"
#define cotyes            cout << "YES\n"
#define cotno             cout << "NO\n"
#define cotcase(cs)       cout << "Case " << cs << ": "

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       (s.find(x) != s.end())

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)
#define fori(it, s)       for(auto it = s.begin(); it != s.end(); it++)

#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)

//#define pi              3.1415926536
#define pi                acos(-1)

const ll INF = LLONG_MAX;
const ll SZ = 4e5+5;
const ll mod = 1e9+7;

string s, s1, s2;
ll n, k, ans = 0;
ll a[SZ];
//ll b[SZ];

int main() {
    FR;
    ll cs = 0, tc = 1, x, y, z, i, j, g, p, q, sum = 0, c = 0, t = 0;
//    ll a, b, d;
//    string s, s1, s2;

    cin1(n);
    for1(i, n) cin1(a[i]);

    set <ll> st;
    for0(i, n+3) st.insert(i);

    for1(i, n) {
        auto p = st.begin();
        st.erase(a[i]);
        cot1(*st.begin());
    }

    return 0;
}

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

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

int main(){
    int n;
    cin >> n;
    VI p(n);
    rep(i,n) cin >> p[i];
    int left = 0;
    VI a(200005);
    rep(i,n){
        a[p[i]]++;
        while(a[left] != 0) left++;
        view(left);
    }
    return 0;
}


/*
author:Karan
created:14.06.2021 12:45:48
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(ar) ar.begin(),ar.end()
#define endl '\n'

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll a,b,c;
    cin>>a>>b>>c;
    if(c%2) {
        if(a>b) {
            cout<<">"<<endl;
        }
        else if(a<b) {
            cout<<"<"<<endl;
        }
        else {
            cout<<"="<<endl;
        }
    }
    else {
        if(abs(a)>abs(b)) {
            cout<<">"<<endl;
        }
        else if(abs(a)<abs(b)) {
            cout<<"<"<<endl;
        }
        else {
            cout<<"="<<endl;
        }
    }
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0,endrep=(n); i<endrep; ++i)
#define rep1(i,n) for(ll i=1,endrep=(n); i<=endrep; ++i)
#define revrep(i,n) for(ll i=(ll)(n)-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 60) -123456789;
#define fastio cin.tie(0); ios_base::sync_with_stdio(false); cout<<fixed<<setprecision(10);
#define newl '\n'
#define YN(e) ((e)?"Yes":"No")
#define all(a) begin(a),end(a)
#define rall(a) rbegin(a),rend(a)
#define delif(c,pred) (c).erase(remove_if(all(c),(pred)), end(c))
template <class T,class U> bool updmax(T& a, U b) { if(b>a){ a=b; return true;} return false;}
template <class T,class U> bool updmin(T& a, U b) { if(b<a){ a=b; return true;} return false;}
inline constexpr int Mod = 1000000007;
//inline constexpr int Mod = 998244353;
#define dbg(a) cerr << #a << ": " << (a) << endl;
#define dbgs(s) cerr << #s << endl;
#define dbg1(a,n) cerr<<#a<<": "; rep(i,n) cerr<<(a)[i]<<" "; cerr<<endl;
#define dbg2(m,h,w) cerr<<#m<<":"<<endl; rep(i,(h)){ rep(j,(w))cerr<<(m)[i][j]<<" "; cerr<<endl; }
template <class T, class U> ostream& operator << (ostream& os, pair<T,U> v) {os<<v.first<<","<<v.second;return os;}
template <class T, size_t N> ostream& operator << (ostream& os, array<T,N> v) {rep(i,N)os<<v[i]<<(i+1<(ll)N?" ":"");return os;}
int rng(int n) { return rand()/(RAND_MAX+1.0)*n; }
inline constexpr int offset[] = {1,0,-1,0,1};

int main() {
    fastio;
    ll ans{};
    auto put = [&]{
        if (ans > 0) cout << ">" << endl;
        else if (ans == 0) cout << "=" << endl;
        else cout << "<" << endl;
    };
    ll a,b,c;
    cin >> a >> b >> c;
    if (c%2 == 0) {
        a = abs(a);
        b = abs(b);
    }
    if (a >= 0 && b >= 0) {
        ans = a-b;
    } else if (a <= 0 && b <= 0) {
        ans = a-b;
    } else if (a >= 0 && b < 0) {
        ans = 1;
    } else if (a < 0 && b >= 0) {
        ans = -1;
    }
    put();
}


#include <bits/stdc++.h>

#define f first
#define s second
#define vec vector
#define pb push_back
#define all(x) x.begin(),x.end()
#define m_p make_pair
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int K=86;
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    ll nn=n;
    vec<ll>fib(K+1);
    fib[0]=1;fib[1]=1;
    for(int i=2;i<=K;i++){
        fib[i]=fib[i-1]+fib[i-2];
    }
//    fib.erase(fib.begin)
    vec<int>ans;
    for(int i=0;i<K;i++){
        if(n>=fib[K-i]){
            if(i%2==0) ans.pb(1);
            else ans.pb(2);
            n-=fib[K-i];
//            cerr<<"N "<<n<<endl;
        }
        if(i%2==0)ans.pb(4);
        else ans.pb(3);
    }
    ll x=0,y=0;
    cout<<sz(ans)<<endl;
    for(auto &z : ans){
        if(z==1) x++;
        if(z==2) y++;
        if(z==3) x+=y;
        if(z==4) y+=x;
        cout<<z<<endl;
    }
//    cerr<<"X "<<x<<endl;
//    assert(x==nn);
//        cout<<z<<endl;
    return 0;
}
/*
5 1
1 2 6 7 10
1 1 1 1 2
3 5
*/

#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
//const bool debug = false;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	long long n; cin >> n;
	long long x = 1;
	long long y = 0;
	vector<vector<int>>ans;
	ans.push_back({});
	vector<long long>f;
	while (true) {
		ans.push_back({ 4 });
		y += x;
		f.push_back(y);
		ans.push_back({ 3 });
		x += y;
		f.push_back(x);
		if (x >= n)break;
	}
	rrep(i, f.size()) {
		if (n >= f[i]) {
			n -= f[i];
			ans[(ans.size() - 1) - (i + 1)].push_back(1 + (i + 1) % 2);
		}
	}
	vector<int>a;
	rep(i, ans.size()) {
		rep(j, ans[i].size()) {
			if ((0 == a.size()) && (ans[i][j] >= 3))continue;
			a.push_back(ans[i][j]);
		}
	}
	cout << a.size() << endl;
	rep(i, a.size()) cout << a[i] << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll GD(ll num){//各桁の和
    ll digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
bool is_integer( long double x ){//整数判定
  return std::floor(x)==x;
}

int gcd(int aaa, int bbb)//最大公約数
{
   if (aaa%bbb == 0)
   {
       return(bbb);
   }
   else
   {
       return(gcd(bbb, aaa%bbb));
   }
}

int lcm(int aaa, int bbb)//最小公倍数
{
   return aaa * bbb / gcd(aaa, bbb);
}

int main() {
  int N;
  cin>>N;
  map<int,tuple<int,int,int,int,int,int,int,int,ll>> score;
  set<int> Y;
  //棒大量生成するんご！！！！！！！
  for(int i=0;i<N;i++){
   int a,b;
    ll c;
    cin>>a>>b>>c;
    score[i]=make_tuple(a,b,a+1,b,a,b+1,a+1,b+1,c);
    Y.insert(b);
  }
  Y.insert(10000);
  for(int j=0;j<N;j++){
    set<int> S;
    set<int> min_sum;
    for(int k=0;k<N;k++){
     if(k!=j){
       	if( get<1>(score[j])==get<1>(score[k])&&get<2>(score[j])<=get<0>(score[k])){
          S.insert(get<0>(score[k]));
        }
       if( get<1>(score[j])==get<1>(score[k])&&get<0>(score[j])>=get<2>(score[k])){
         min_sum.insert(get<0>(score[k]));
       }
     }
    }
    if(S.empty()){
      int s1,s2,s3,s4,s5,s6,s7,s8;
      ll s9;
      tie(s1,s2,s3,s4,s5,s6,s7,s8,s9) = score[j];
      s3=10000;
      s7=10000;
      if(min_sum.empty()){
       s1=0;
        s5=0;
      }
      score[j]=make_tuple(s1,s2,s3,s4,s5,s6,s7,s8,s9);
    }else{
      int s1,s2,s3,s4,s5,s6,s7,s8;
      ll s9;
      tie(s1,s2,s3,s4,s5,s6,s7,s8,s9) = score[j];
      s3=*begin(S);
      s7=*begin(S);
            if(min_sum.empty()){
       s1=0;
        s5=0;
      }
      score[j]=make_tuple(s1,s2,s3,s4,s5,s6,s7,s8,s9);
    }
  }
  //ひろげていくんご！！！！
  int y=Y.size();
  map<int,int> coordinate1;
  map<int,int> coordinate2;
  int n=0;
   for (auto value : Y) {
  coordinate1[value]=n;
  coordinate2[n]=value;
     n++;
}
  for(int o=0;o<N;o++){
      int t1,t2,t3,t4,t5,t6,t7,t8;
      ll t9;
      tie(t1,t2,t3,t4,t5,t6,t7,t8,t9) = score[o];
    int hoga=coordinate1[t4];
    int hogi=coordinate2[hoga+1];
    ll hogu=t9/(t3-t1);
    if(hogi-t8<=hogu){
      t6+=hogi-t8;
      t8+=hogi-t8;
    }else{
      t6+=hogu;
      t8+=hogu;
    }
    if(*begin(Y)==t2){
    t2=0;
     t4=0;
   }
    score[o]=make_tuple(t1,t2,t3,t4,t5,t6,t7,t8,t9);
  }

  for(int l=0;l<N;l++){
    int x1,x2,x3,x4,x5,x6,x7,x8;
    ll x9;
    tie(x1,x2,x3,x4,x5,x6,x7,x8,x9) = score[l];
    cout<<x1<<" "<<x2<<" "<<x7<<" "<<x8<<endl;
  }
}

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

const int inf = 10000;

struct Point {
  int x;
  int y;
};

struct Rect {
  Point start;
  Point end;
};

int main() {
  int n;
  cin >> n;
  vector<Point> ad(n);

  // input
  rep(i, n) {
    int _;  // 一旦面積は考えない
    cin >> ad[i].x >> ad[i].y;
    cin >> _;
  }

  // 最初に x 座標を決める
  // 次でy座標を決めるといい感じになる

  vector<Rect> ans(n);
  // calc
  rep(i, n) {
    ans[i].start.x = ad[i].x;
    ans[i].start.y = ad[i].y;
  }

  rep(i, n) {
    int c = inf;

    rep(j, n) {
      if (i == j) continue;

      if (ad[i].x <= ad[j].x) {
        c = min(c, ad[j].x);
      }
    }
    ans[i].end.x = (c == ad[i].x) ? ad[i].x + 1 : c;
  }

  rep(i, n) {
    int d = inf;
    bool isSameX = false;
    rep(j, n) {
      if (i == j) continue;
      if (ad[i].x == ad[j].x) {
        isSameX = true;
        break;
      }
    }
    if (!isSameX) {
      ans[i].start.y = 0;
    }

    rep(j, n) {
      if (i == j) continue;

      if ((ad[i].x <= ad[j].x && ad[j].x <= ans[i].end.x) &&
          (ad[i].y <= ad[j].y)) {
        d = min(d, ad[j].y);
      }
    }
    ans[i].end.y = (d == ad[i].y) ? ad[i].y + 1 : d;
  }

  // output
  rep(i, n) {
    int a = ans[i].start.x;
    int b = ans[i].start.y;
    int c = ans[i].end.x;
    int d = ans[i].end.y;
    printf("%d %d %d %d\n", a, b, c, d);
  }
}