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

#define  all(x)        (x).begin(),(x).end()
#define  pb            push_back
#define  lb            lower_bound
#define  ub            upper_bound
#define  fi            first
#define  se            second
#define  pii           pair<int,int>
#define  fastIO        ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
#define int long long

typedef double db;
typedef long long ll;

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 1e9;

void solve() {

	int n; cin >> n;
	int ans = (n + 99) / 100;
	cout << ans;
}

signed main() {

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

	fastIO

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

	for (int tt = 1; tt <= t; tt++) {
		solve();
	}
}

#include <bits/stdc++.h>
#define startt ios_base::sync_with_stdio(false);cin.tie(0);
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef unsigned long long ull;
typedef long long  ll;
using namespace std;
#define FOR(n) for(int i=0;i<n;i++)
#define vt vector
#define vint vector<int>
#define all(v) v.begin(), v.end()
#define sz(a) (int)a.size()
#define MOD 1000000007
#define MOD2 998244353
#define MX 1000000000
#define nax 100005
#define MXL 1000000000000000000
#define PI 3.14159265
#define pb push_back
#define pf push_front
#define sc second
#define fr first
#define int ll
#define endl '\n'
#define ld long double

int ceildiv(int one, int two) {
    if (one % two == 0) {return one / two;}
    else {return one / two + 1;}
} int power(int n, int pow, int m) {
    if (pow == 0) return 1;
    if (pow % 2 == 0) {
        ll x = power(n, pow / 2, m);
        return (x * x) % m;
    }
    else return (power(n, pow - 1, m) * n) % m;
} int gcd(int a, int b) {
    if (!b)return a;
    return gcd(b, a % b);
} int factorial(int n, int mod) {
    if (n > 1)
        return (n * factorial(n - 1, mod)) % mod;
    else
        return 1;
} int lcm(int a, int b) {
    return (a * b) / gcd(a, b);
} vector<int> read(int n) {vector<int> a; for (int i = 0; i < n; i++) { int x; cin >> x; a.pb(x);} return a;}vector<vector<int>> adj;void init(int n) {for (int i = 0; i <= n; i++) { vector<int> a; adj.pb(a);}}

void decToOctal(int n)
{

    // array to store octal number
    int octalNum[100];

    // counter for octal number array
    int i = 0;
    while (n != 0) {

        // storing remainder in octal array
        octalNum[i] = n % 8;
        n = n / 8;
        i++;
    }

    // printing octal number array in reverse order
    for (int j = i - 1; j >= 0; j--)
        cout << octalNum[j];
}

bool dec(int n)
{
    int octalNum[100];
    int i = 0;
    int ncop = n;
    while (n != 0) {
        octalNum[i] = n % 8;
        n = n / 8;
        i++;
    }
    while(ncop != 0)
    {
        if(ncop%10 == 7)
        {
            return false;
        }
        ncop/=10;
    }
    for (int j = i - 1; j >= 0; j--)
    {
        if(octalNum[j] == 7)
        {
            return false;
        }
    }
    return true;
}

void solve()
{
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        if(dec(i))
        {
            ans++;
        }
    }
    cout << ans << endl;
}

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


#include "bits/stdc++.h"
#define rep(i,n) for(int i=0; i<(n); ++i)
#define fo(i,a,b) for(int i=a; i<(b); ++i)
#define out(a) cout << a << endl
#define so(v) sort(v.begin(),v.end())
#define revso(v) sort(v.begin(),v.end(), greater<int>())
using namespace std;
using ll = long long;

int main()
{
	int n, k, m; cin >> n >> k >> m;

	int res = n * m;
	rep(i, n-1)
	{
		int a; cin >> a;
		res -= a;
	}
	res = max(0, res);
	if (res > k) res = -1;
	out(res);

}

#include<bits/stdc++.h>
using namespace std;
int n;
int m;
int k;

int main(){
    cin >> n >> k >> m;
    int top = 0;
    for(int i = 0;i<n-1;i++){
        int s;
        cin >> s;
        top+=s;
    }
    int gereken = n*m;
    if(top > gereken){
        cout << "0";
        return 0;
    }
    int suanki = gereken-top;
    if(suanki > k){
        cout << "-1";
        return 0;
    }
    cout << suanki;

}


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

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
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 N;
int C[101010];
vector<int> E[101010];
map<int,int> M;
vector<int> R;

void dfs(int cur,int pre) {
	if(M[C[cur]]==0) R.push_back(cur+1);
	M[C[cur]]++;
	FORR(e,E[cur]) if(e!=pre) dfs(e,cur);
	M[C[cur]]--;
}

void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>N;
	FOR(i,N) cin>>C[i];
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	dfs(0,0);
	sort(ALL(R));
	FORR(r,R) cout<<r<<endl;
}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
typedef struct a{
	int to,next;
}per;
per si[maxn*2];
int n,ctt,m,co[maxn],vis[maxn],head[maxn],ans[maxn],cur;
void add(int u,int v){
	si[++ctt].next=head[u];
	si[ctt].to=v;
	head[u]=ctt;
}
void dfs(int now,int fa){
	if(!vis[co[now]]) ans[++cur]=now;
	vis[co[now]]++;
	for(int i=head[now];i!=-1;i=si[i].next){
		int to=si[i].to;
		if(to!=fa){
			dfs(to,now);
		}
	}
	vis[co[now]]--;
}
int main(){
	memset(head,-1,sizeof(head));
	cin>>n;
	for(int i=1;i<=n;++i) cin>>co[i];
	int u,v;
	for(int i=1;i<n;++i){
		cin>>u>>v;
		add(u,v);
		add(v,u);
	}
	dfs(1,-10);
	sort(ans+1,ans+1+cur);
    for(int i=1;i<=cur;++i) cout<<ans[i]<<"\n";
	return 0;
}


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

#define int long long
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60;
#define rep(i, n) for(int i = 0; i < n; ++ i)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
    int n, m; cin >> n;
    vector<int> x(n), y(n);
    rep(i, n) {
        cin >> x[i] >> y[i];
    }
    cin >> m;
    vector<int> r(m + 1, 0);
    vector<int> sx(m + 1, 1), sy(m + 1, 1);
    vector<int> nx(m + 1, 0), ny(m + 1, 0);
    rep(i, m) {
        int op; cin >> op;
        r[i + 1] = r[i];
        sx[i + 1] = sx[i], sy[i + 1] = sy[i];
        nx[i + 1] = nx[i], ny[i + 1] = ny[i];
        if(op == 1) {
            r[i + 1] ^= 1;
            swap(sx[i + 1], sy[i + 1]);
            swap(nx[i + 1], ny[i + 1]);
            sy[i + 1] *= (-1); //?
            ny[i + 1] *= (-1); //?
        } else if(op == 2) {
            r[i + 1] ^= 1;
            swap(sx[i + 1], sy[i + 1]);
            swap(nx[i + 1], ny[i + 1]);
            sx[i + 1] *= (-1); //?
            nx[i + 1] *= (-1); //?
        } else if(op == 3) {
            sx[i + 1] *= (-1);
            nx[i + 1] *= (-1);
            int p; cin >> p;
            nx[i + 1] += 2 * p;
        } else {
            sy[i + 1] *= (-1);
            ny[i + 1] *= (-1);
            int p; cin >> p;
            ny[i + 1] += 2 * p;
        }
    }
    int q; cin >> q;
    rep(_, q) {
        int a, b; cin >> a >> b;
        -- b;
        int X = x[b], Y = y[b];
        if(r[a]) swap(X, Y);
       // cerr << a << " " << sy[a] << " " << ny[a] << "\n";
        cout << X * sx[a] + nx[a] << " " << Y * sy[a] + ny[a] << "\n";
    }
}

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define each(e, v) for(auto &e: v)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct io_setup{
    io_setup(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

template<typename T>
T gcd(const T &a, const T &b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}

template<typename T>
T lcm(const T &a, const T &b) {return a*(b/gcd(a,b));}

template<typename T>
T extgcd(const T &a, const T &b, T &x, T &y){
    if(b == 0) {x = 1, y = 0; return a;}
    T g = extgcd(b, a%b, y, x);
    y -= (a/b)*x;
    return g;
}

int mod(const long long &a, const int &m){
    int ret = a%m;
    return ret+(ret < 0? m : 0);
}

int modinv(const int &a, const int &m){ //aとmは互いに素
    int x, y;
    extgcd(a, m, x, y);
    return mod(x, m);
}

template<typename T>
T floor_sum(const T &n, const T &m, T a, T b){ //Σ(floor((a*i+b)/m)) (0<=i<n)
    T ret = (a/m)*(n*(n-1)/2)+(b/m)*n;
    a %= m, b %= m;
    T y = (a*n+b)/m;
    if(y == 0) return ret;
    ret += floor_sum(y, a, m, a*n-(m*y-b));
    return ret;
}

template<typename T>
pair<T, T> Chinese_reminder_theorem(const T &a1, const T &m1, const T &a2, const T &m2){
    T x, y, g = extgcd(m1, m2, x, y);
    if((a2-a1)%g != 0) return make_pair(0, -1);
    T m = m1*(m2/g);
    T tmp = mod(x*((a2-a1)/g), m2/g);
    T a = (m1*tmp+a1) % m;
    return make_pair(a, m);
}

bool prepare_Garner(vector<int> &a, vector<int> &m){ //mの各要素がそれぞれ互いに素とは限らない場合の前処理
    int n = a.size();
    for(int i = 0; i < n; i++){
        for(int j = 0; j < i; j++){
            int g = gcd(m[i], m[j]);
            if((a[i]-a[j])%g != 0) return false;
            m[i] /= g, m[j] /= g;
            int gi = gcd(m[i], g), gj = g/gi;
            do{
                g = gcd(gi, gj);
                gi *= g, gj /= g;
            } while(g > 1);
            m[i] *= gi, m[j] *= gj;
        }
    }
    return true;
}

int Garner(vector<int> a, vector<int> m, const int &M){ //mの各要素はそれぞれ互いに素
    m.push_back(M);
    vector<long long> coeffs(m.size(), 1);
    vector<long long> constants(m.size(), 0);
    for(int k = 0; k < (int)a.size(); k++){
        long long x = a[k]-constants[k], y = modinv(coeffs[k], m[k]);
        long long t = mod(x*y, m[k]);
        for(int i = k+1; i < m.size(); i++){
            constants[i] += t*coeffs[i], constants[i] %= m[i];
            coeffs[i] *= m[k], coeffs[i] %= m[i];
        }
    }
    return constants.back();
}

int main(){
    int T; cin >> T;

    while(T--){
        ll X, Y, P, Q; cin >> X >> Y >> P >> Q;

        ll A = 2*(X+Y), B = P+Q;
        ll L = lcm(A, B);

        ll ans = LLONG_MAX;

        for(ll i = X; i < X+Y; i++){
            for(ll j = P; j < P+Q; j++){
                pll p = Chinese_reminder_theorem(i, A, j, B);
                if(p.second == -1) continue;
                if(p.first >= max(i, j)) chmin(ans, p.first);
                else chmin(ans, p.first+L);
            }
        }

        if(ans == LLONG_MAX) cout << "infinity\n";
        else cout << ans << '\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repn(i, n) for (int i = (int)(n)-1; i>= 0; --i)
#define ll long long
using Graph = vector<vector<int>>;
int main(){
    int n, Q, cnt = 0;
    string s;
    cin >> n >> s >> Q;
    rep(q, Q){
        int t, a, b;
        cin >> t >> a >> b;
        a--;
        b--;
        if (t == 1){
            if (cnt%2 == 0){
                char tmp = s[a];
                s[a] = s[b];
                s[b] = tmp;
            }
            else {
                if (a >= n) {
                    a -= n;
                    b -= n;
                }
                else if (b < n){
                    a += n;
                    b += n;
                }
                else {
                    a += n;
                    b -= n;
                }
                char tmp = s[a];
                s[a] = s[b];
                s[b] = tmp;
            }
        }
        else cnt++;
    }
    if (cnt%2 == 1){
        string tmp;
        s = s.substr(n, n) + s.substr(0, n);
    }
    cout << s << endl;
}

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

typedef long long ll;
typedef pair<int,int> pii;

const int N=25;

int a[N],n;
int ans=(1<<30)+1;
int idx[N],cnt;

void dfs(int rank){
	if(rank==n) {
		idx[cnt++]=n;
		int l,r,h,w;
		h=0;
		l=0;
		for(int i=0;i<cnt;i++){
			r=idx[i];
			w=0;
			for(int j=l;j<=r;j++) {
				w|=a[j];
			}
			h^=w;
			l=r+1;
		}
		ans=min(ans,h);
		cnt--;
		return ;
	}
	idx[cnt++]=rank;
	dfs(rank+1);
	cnt--;
	dfs(rank+1);
}

int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	cnt=0;
	dfs(1);
	cout<<ans<<endl;
	return 0;
}


//  “Alhamdulillah for Everything”

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

//---------DEFINES------------
#define      pai              acos(-1)
#define      ff               first
#define      ss               second
#define      ll               long long
#define      pb               push_back
#define      mp               make_pair
#define      pll              pair<ll,ll>
#define      sz(a)            (ll)a.size()
#define      endl             "\n"
#define      sline(s)         getline(cin,s);
#define      gcd(a, b)        __gcd(a, b)
#define      lcm(a, b)        ((a*b)/gcd(a,b))
#define      all(sob)         sob.begin(),sob.end()
#define      ms(a, b)         memset(a,b,sizeof(a))
#define      rep(i,b,n)       for(ll i = b;i <= n; i++)
#define      rev(i,b,n)       for(ll i = b;i >= n; i--)
#define      setp(x)          cout<<fixed<<setprecision(x)
#define      watch(x)         cout<<(#x)<<" = "<<(x)<<'\n'
#define      TEST_CASE(t)     for(ll zz=1;zz<=t;zz++)
#define      PRINT_CASE       cout<<"Case "<<zz<<": ";
#define      fii              freopen("input.txt","r",stdin);
#define      foo              freopen("output.txt","w",stdout);
#define      ActioN           ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

//-------CONSTANTS------------
const        ll               mod = 1e9+7;
const        ll               mxn = 1e5+7;
const        ll               inf = 1e18;

//------MOD-FUNCTIONS---------
inline      void              normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline       ll               modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline       ll               modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline       ll               modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline       ll               modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline       ll               modInverse(ll a) { return modPow(a, mod - 2); }
inline       ll               modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

int  main()
{
    //Light_Camera:)
    ActioN;
    ll i,j,k,a,b,c,d,n,m,t,u,v,w,x,y,z;
    vector<ll>vec(3);
    for(i=0;i<3;i++)
    {
        cin>>vec[i];
    }
    sort(all(vec));
    a=vec[0];
    b=vec[1];
    c=vec[2];
    if(a==b)
    {
        cout<<c<<endl;
    }
    else if(b==c)
    {
        cout<<a<<endl;
    }
    else
    {
        cout<<0<<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(b==c)
{
 cout << a << endl;
}
else if(c==a)
{
 cout << b << endl;
}
else
{
 cout << 0 << endl;
}
return 0;
}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define pb(a) push_back(a)
#define set0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define INF 0x3f3f3f3f
typedef long long ll;

int main(){
	int T; cin>>T;
	while(T--){
		ll n; cin>>n;

		int d=0;
		while(n%2==0){
			n/=2;
			d++;
		}
		if(!d) puts("Odd");
		else if(d==1) puts("Same");
		else puts("Even");
	}
    return 0;
}

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

#define ll long long

int main() {

	ll t, n;
	scanf("%lld", &t);
	while (t--) {
		scanf("%lld", &n);
		if (n%2==1) {
			printf("Odd\n");
		}
		else {
			if (n % 4 == 2) {
				printf("Same\n");
			}
			else {
				printf("Even\n");
			}
		}
	}
}


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

ll solve1(ll b,ll c){
    ll depth=c/2,flip=c&1;
    if(depth<b)return (1+depth)*2-(!flip);
    else return b*2+1;
}

ll solve2(ll b,ll c){
    ll depth=c/2,flip=c&1;
    return max(ll(0),depth*2-(!flip));
}

int main(){
    scanf("%lld%lld",&b,&c);
    if(b>0)ans=solve1(b,c)+solve2(-b,c-1);
    else if(b==0)ans=1+solve2(b,c);
    else ans=solve2(b,c)+solve1(-b,c-1);
    printf("%lld",ans);
    return 0;
}

//wtrl,everybody hangbeat me
#include<bits/stdc++.h>
/*#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>*/
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<ll,ll> pll;
/*=====================================================================*/
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define sz(a) (int)(a.size())
#define all(s) (s).begin(),(s).end()
#define m_p make_pair
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,p,n) for(int i=p;i<=n;i++)
#define ford(i,p,n) for(int i=n;i>=p;i--)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i)
#define INF 1e9
#define PI acos(-1)
/*=====================================================================*/
string int_to_string(ll n)
{
	string s="";
	while(n)
	{
		ll now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
ll string_to_int(string s)
{
	ll n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
/*======================================================================*/
ll lcm(int a,int b)
{
	return a/__gcd(a,b)*b;
}
bool prime(int n)
{
	if(n==0||n==1)
	  return false;
	for(int i=2;i*i<=n;i++)
	  if(n%i==0)
	    return false;
	return true;
}
/*======================================================================*/
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
const int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
/*======================================================================*/
int main()
{
    std::ios::sync_with_stdio(false);
  /*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
  */
  /*====================================================================*/
  ll b,c;
  cin>>b>>c;
  if(c==1)
  {
  	if(b!=0)
  	{
  	  cout<<2<<endl;
    }
    else
    {
    	cout<<1<<endl;
	}
  	return 0;
  }
  if(b>=0)
  {
  ll ans=2;
  ans+=(c-1)/2+c/2-1;
  if((c-1)/2+c/2<max(2*abs(b)-1,(ll)0))
  {
    ans+=(c-1)/2+c/2;
  }
  else
  {
  	ans+=max(2*abs(b)-1,(ll)0);
  }
  cout<<ans<<endl;
  }
  else
  {
  ll ans=2;
  ans+=c/2+(c-1)/2;
  if((c-1)/2+c/2-1<max(2*abs(b)-1,(ll)0))
  {
    ans+=(c-1)/2+c/2-1;
  }
  else
  {
  	ans+=max(2*abs(b)-1,(ll)0);
  }
  cout<<ans<<endl;
  }
  return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

ll sum() { return 0; }
template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;

void solve() {

}

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

//    int tc; cin >> tc;
//    TC(tc) solve();
	int n, m, t;
	cin >> n >> m >> t;
	vi a(m), b(m);
	REP(i, m) cin >> a[i] >> b[i];
	int left = n;
	left -= a[0];
	if(left <= 0) {
		OUT("No");
		return 0;
	}
	left += (b[0] - a[0]);
	MIN(left, n);
	FOR(i, 1, m ) {
		left -= (a[i] - b[i - 1]);
		if(left <= 0) {
			OUT("No");
			return 0;
		}
		left += (b[i] - a[i]);
		MIN(left, n);
	}
	left -= (t - b[m - 1]);
	if(left <= 0) {
		OUT("No");
		return 0;
	}
	OUT("Yes");
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define PI acos(-1)
#define EPS 1e-9
#define debug cerr <<
#define var(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define close << "\n";

int total_n(double start,double end){
    return (end - start + 1);
}

int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("../input.txt","r",stdin);
    int N,M,T;
    cin >> N >> M >> T;
    int maxx = N;
    int last = 0;
    for (int i = 0; i < M; ++i) {
        int a,b;
        cin >> a >> b;
        if(i!=0){
            N = max(0,N - total_n(last,a) + 1);
            if(N == 0){
                cout << "No" close
                return 0;
            }
        }

        if(i == 0){
            N = max(0,N - total_n(0,a) + 1);
            if(N == 0){
                cout << "No" close
                return 0;
            }
        }

        N = min(maxx,N + total_n(a,b) - 1);
        if(N == 0){
            cout << "No" close
            return 0;
        }

        last = b;
    }

    N = max(0,N - total_n(last,T) + 1);
    if(N == 0){
        cout << "No" close
        return 0;
    }

    if(N == 0){
        cout << "No" close
        return 0;
    }else{
        cout << "Yes" close
        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;
#define PI  3.14159265358979323846
#define lp(i,n) for(int i = 0; i <n;i++)
#define rlp(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define fr first
#define sc second
#define vt vector
#define sz(v) ((int)((v).size()))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
template<class T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;
int dx[] = {0,0,-1,1};
int dy[] = {1,-1,0,0};
void init(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
template<class T> void read(T& x) {
	cin >> x;
}
void read(double& d) {
	string t;
	read(t);
	d=stod(t);
}
void read(long double& d) {
	string t;
	read(t);
	d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
	read(h);
	read(t...);
}
template<class A> void read(vt<A>& x) {
	for(auto& a:x)
		read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
	for(auto& a:x)
		read(a);
}
void _run(){
	int a,b,c,d;
	read(a,b,c,d);
	int cnt =0;
	while(a--&&b--&&c--&&d--)cnt++;
	cout<<cnt<<endl;
}
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
	init();
    int t=1;
    // read(t);
    while(t--)_run();

    return 0;
}

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

void solve(){
    int n;
    cin >> n;
    vector<pair<int,int>> v;
    for(int i=0;i<n;i++){
        int t,l,r;
        cin >> t >> l >> r;
        l *=2;
        r *=2;
        if(t  == 2 || t == 4)r--;
        if(t  == 3 || t == 4)l++;
        if(l <= r)
        v.push_back({l,r});
    }
    int ans = 0;
    for(int i=0;i<v.size();i++){
        for(int j=0;j<i;j++){
            auto u = v[i];
            auto k = v[j];
            if(!(k.second < u.first || u.second < k.first)){
                ans++;
            }
        }
    }
    cout << ans;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef Local
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    #ifdef Local
    cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}


#include <bits/stdc++.h>

using namespace std;

#define FOR(it, ar) for(auto &it: ar)
#define loop(i, start, end) for(auto i = (start); i <= (end); i++)
#define loopSkip(i, start, end, skip) for(auto i = (start); i <= (end); i += skip)
#define loopRev(i, start, end) for(int i = (start); i >= (end); i--)
#define FLASH ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define testCases(t) cin >> t; while(t--)
#define readLine(s) getline(cin, s);
#define PN(n) cout << (n)
#define PN1(n) cout << (n) << " "
#define PN2(a, b) cout << (a) << " " << (b) << " "
#define PN3(a, b, c) cout << (a) << " " << (b) << " " << (c) << " "
#define PNN1(n) cout << (n) << "\n"
#define PNN2(a, b) cout << (a) << " " << (b) << "\n"
#define PNN3(a, b, c) cout << (a) << " " << (b) << " " << (c) << "\n"
#define PrintObject(ar) for(auto var: ar) cout << var << " "; cout << "\n"
#define PrintMap(map) for(auto var: map) PNN2(var.first, var.second)
#define PrintPair(pair) PNN2(pair.first, pair.second)
#define IN1(n) cin >> n
#define IN2(a, b) cin >> a >> b
#define IN3(a, b, c) cin >> a >> b >> c
#define ALL(s) s.begin(), s.end()
#define ENTER PNN1("")
#define FLUSH cout.flush()
#define llPair std::pair<lli, lli>
#define iiPair std::pair<int, int>
// #define ONLINE_JUDGE

// Math macros
#define M_PI 3.14159265358979323846

typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;

template <typename T>
T ii() {
	T a;
	IN1(a);
	return a;
}

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

  size_t operator()(uint64_t x) const {
      static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
      return splitmix64(x + FIXED_RANDOM);
  }
};

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

	int n;
	IN1(n);
	vector<int> ar(n);
	FOR(it, ar) IN1(it);

	unordered_set<int> dp;
	loop(i, 1, n) dp.insert(i);

	FOR(it, ar) dp.erase(it);
	PNN1(dp.empty() ? "Yes" : "No");

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool testcase(){
 ll n;
 cin>>n;
 vector<ll> arr;
 for(int i=0;i<n;++i){
    ll temp;
    cin>>temp;
    arr.push_back(temp);
}
sort(arr.begin(),arr.end());
for(int i=0;i<n-1;++i){
    if(abs(arr[i]-arr[i+1])!=1)
        return false;
}
return true;
}
int main() {
 if(testcase())
 cout<<"Yes";
 else
 cout<<"No";
}


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

#define ff first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()

const int mod = 1e9+7;
const int inf = 1e9;
const int mx  = 1e6+5;

int n; string s;
void solve(int cs){
//    cout << "Case " << cs << ": ";
    cin >> n >> s;
    vector<char> v;
    for(char c : s){
        if(c == 'x'){
            if(v.size()<2)
                v.push_back(c);
            else{
                char v2 = v.back(); v.pop_back();
                char v1 = v.back(); v.pop_back();
                if(v1=='f' && v2=='o') continue;
                v.push_back(v1);
                v.push_back(v2);
                v.push_back(c);
            }
        }else v.push_back(c);
    }cout << v.size() << "\n";
}

int main(){

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

    int tc = 1, cs = 1;
//    cin >> tc;
    while(tc--) solve(cs++);

    return 0;
}

#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int find(const int& idx, std::vector<int>& idx_to_path) {
  if (idx == idx_to_path[idx]) return idx;
  return idx_to_path[idx] = find(idx_to_path[idx], idx_to_path);
}
int main(int argc, char** argv) {
  int n;
  cin >> n;
  std::vector<char> s(n+2, '.');
  rep(i, n) {
    cin >> s[i+2];
  }
  n += 2;

  std::vector<int> idx(n);
  rep(i, n) idx[i] = i;

  int ans {n-2};

  for (int i = 2;i < n;++i) {
    int c3 = i;
    int c2 = find(c3-1, idx);
    int c1 = find(c2-1, idx);
    if (s[c1] == 'f' && s[c2] == 'o' && s[c3] == 'x') {
      idx[c3] = find(c1-1, idx);
      idx[c2] = find(idx[c3]-1, idx);
      idx[c1] = find(idx[c2]-1, idx);
      ans -= 3;
    }
  }
  std::cout << ans << '\n';
}


#include <cstdio>

int main() {
  char a = getchar(), b = getchar(), c = getchar();
  if(a == b && a == c) puts("Won");
  else puts("Lost");
  return 0;
}

#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  char c[3];
  REP(i,3)cin>>c[i];
  sort(c,c+3);
  if(c[0]==c[2])cout<<"Won"<<endl;
  else cout<<"Lost"<<endl;
  return 0;
}


#include<bits/stdc++.h>
//#pragma GCC optimize "trapv"
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define fast_az_fuk      ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll               long long
#define lll              __int128
#define ull              unsigned ll
#define ld               long double
#define pb               push_back
#define pf               push_front
#define dll              deque<ll>
#define vll              vector<ll>
#define vvll             vector<vll>
#define pll              pair<ll,ll>
#define vpll             vector<pll>
#define dpll             deque<pll>
#define mapll            map<ll,ll>
#define umapll           umap<ll,ll>
#define endl             "\n"
#define all(v)           v.begin(),v.end()
#define ms(a,x)          memset(a,x,sizeof(a))
#define random(l,r,T)    uniform_int_distribution<T>(l,r)(rng)

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

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;

#ifdef LOCAL
    #include <debug.h>
#endif

template<typename T> istream& operator >>(istream &in,vector<T> &v){ for(auto &x:v) in>>x; return in;}
template<typename T> ostream& operator <<(ostream &out,const vector<T> &v){ for(auto &x:v) out<<x<<' '; return out;}
template<typename T1,typename T2> istream& operator >>(istream &in,pair<T1,T2> &p){ in>>p.first>>p.second; return in;}
template<typename T1,typename T2> ostream& operator <<(ostream &out,const pair<T1,T2> &p){ out<<p.first<<' '<<p.second; return out;}
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);
    }
};
template<class T, class H>using umap=unordered_map<T,H,custom_hash>;
template<class T>using uset=unordered_set<T,custom_hash>;

int32_t main()
{
    #ifdef LOCAL
        freopen("error.txt", "w", stderr);
    #endif
    // clock_t clk = clock();
    fast_az_fuk
    ll n; cin>>n; vll a(n); cin>>a;
    mapll hash; for(ll x:a) hash[x]++;
    ll ans = 0;
    for(int i=0;i<n;i++){
        ans += n - hash[a[i]];
    }
    ans /= 2;
    cout<<ans;
    // cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n';
    return 0;
}

#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define REP(i,n) for(int i = 0;i < n;i++)
#define RNG(i,s,n) for(int i = s;i <= n;i++)
#define _RNG(i,e,s) for(int i = e;i >= s;i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define dup(x,y) (x + y - 1) / (y)
#define all(x) (x).begin(),(x).end()
#define lb(x,key) lower_bound(all(x) , (key))
#define ub(x,key) upper_bound(all(x) , (key))

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using vpi = vector<pi>;
using vpl = vector<pl>;

#define debug(arr) cout << #arr << " = " << arr << '\n'
#define debug2(a,b) cout<<"["<<#a<<","<<#b<<"] = "<<"["<<a<<","<<b<<"]\n"
#define debug3(a,b,c) cout<<"["<<#a<<","<<#b<<","<<#c<<"] = "<<"["<<a<<","<<b<<","<<c<<"]\n"
template<class T> ostream &operator << (ostream& out, const vector<T>& arr) {
    cout << "{"; for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i]; cout << "}";
    return out;
}
template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) {
    cout << "{\n"; for (auto& vec : arr)cout << "  " << vec << ",\n"; cout << "}";
    return out;
}
template<class S,class T> ostream &operator << (ostream& out, const pair<S,T>& p){
    cout << "{" << p.first << "," << p.second << "}" << '\n';
    return out;
}
template<class T> istream &operator >> (istream& in, vector<T>& arr) {
    for (auto& i : arr)cin >> i; return in;
}
template<class S,class T> istream &operator >> (istream& in,pair<S,T>& p){
    cin >> p.first >> p.second; return in;
}

#define F first
#define S second

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

    ll ans = 0;

    ll n,k;
    cin >> n >> k;
    k = abs(k);
    for(ll i = 2;i + k <= 2 * n;i++){
        ll p,q;
        if(i > n){
            p = 2 * n - i + 1;
        }else{
            p = i - 1;
        }
        if(i + k > n){
            q = 2* n - (i + k) + 1;
        }else{
            q = i + k - 1;
        }
        ans+= p * q;
    }
    cout << ans << '\n';
    return 0;
}


/**
*   author:  akifpathan
*   created: Monday 10.05.2021 06:02:17 PM
**/

#ifdef akifpathan
#include "debug.h"
#else
#include<bits/stdc++.h>
using namespace std;
#define debug(x...)
#endif

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

//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve()
{
	string a,b,c;
	cin>>a>>b>>c;

	vector<char>vec;
	for(char x: a) vec.push_back(x);
	for(char x: b) vec.push_back(x);
	for(char x: c) vec.push_back(x);

	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());

	if(vec.size()>10)
	{
		cout<<"UNSOLVABLE";
		return;
	}

	while(vec.size()<10) vec.push_back('*');
	sort(vec.begin(),vec.end());

	auto convert=[&](const string &x)
	{
		ll num=0;
		if(vec[0]==x[0]) return LLONG_MIN;
		for(auto it: x)
		{
			num*=10;
			for(int i=0;i<10;i++) if(vec[i]==it)
			{
				num+=i;
				break;
			}
		}
		return num;
	};

	do
	{
		ll x=convert(a);
		ll y=convert(b);
		ll z=convert(c);

		if(x+y==z)
		{
			cout<<x<<"\n"<<y<<"\n"<<z;
			return;
		}
	}
	while(next_permutation(vec.begin(),vec.end()));

	cout<<"UNSOLVABLE";
}

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

	int testcase=1;
	//cin>>testcase;

	for(int i=1;i<=testcase;i++)
	{
		//cout<<"Case "<<i<<": ";
		solve();
	}

	#ifdef akifpathan
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	#endif

	return 0;
}

#include <bits/stdc++.h>

int main(){
    std::string s1, s2, s3;
    std::cin >> s1 >> s2 >> s3;

    std::map< int, int > mp;

    std::vector< int > s1v(s1.size());
    std::vector< int > s2v(s2.size());
    std::vector< int > s3v(s3.size());

    for(int i=0; i<s1.size(); i++){
        auto itr = mp.find(s1[i] - 'a');
        if(itr != mp.end()){
            s1v[i] = mp[s1[i] - 'a'];
        }else{
            if(mp.size() == 10){
                std::cout << "UNSOLVABLE" << std::endl;
                return 0;
            }
            mp[s1[i] - 'a'] = mp.size();
            s1v[i] = mp[s1[i] - 'a'];
        }
    }

    for(int i=0; i<s2.size(); i++){
        auto itr = mp.find(s2[i] - 'a');
        if(itr != mp.end()){
            s2v[i] = mp[s2[i] - 'a'];
        }else{
            if(mp.size() == 10){
                std::cout << "UNSOLVABLE" << std::endl;
                return 0;
            }
            mp[s2[i] - 'a'] = mp.size();
            s2v[i] = mp[s2[i] - 'a'];
        }
    }

    for(int i=0; i<s3.size(); i++){
        auto itr = mp.find(s3[i] - 'a');
        if(itr != mp.end()){
            s3v[i] = mp[s3[i] - 'a'];
        }else{
            if(mp.size() == 10){
                std::cout << "UNSOLVABLE" << std::endl;
                return 0;
            }
            mp[s3[i] - 'a'] = mp.size();
            s3v[i] = mp[s3[i] - 'a'];
        }
    }

    std::deque< std::vector< int > > per_all;
    std::vector< int > per(10);
    for(int i=0; i<10; i++){
        per[i] = i;
    }
    per_all.push_back(per);
    for(int i=0; i<10; i++){
        std::deque< std::vector< int > > tmp;
        while(!per_all.empty()){
            per = per_all.front(); per_all.pop_front();
            tmp.push_back(per);
            for(int j=i+1; j<10; j++){
                std::vector< int > per_tmp = per;
                std::swap(per_tmp[i], per_tmp[j]);
                tmp.push_back(per_tmp);
            }
        }
        per_all = tmp;
    }

    while(!per_all.empty()){
        per = per_all.front(); per_all.pop_front();
        if(per[s1v[0]] == 0 || per[s2v[0]] == 0 || per[s3v[0]] == 0){
            continue;
        }
        long long n1 = 0, n2 = 0, n3 = 0;
        for(int i=0; i<s1.size(); i++){
            n1 = n1 * 10 + per[s1v[i]];
        }
        for(int i=0; i<s2.size(); i++){
            n2 = n2 * 10 + per[s2v[i]];
        }
        for(int i=0; i<s3.size(); i++){
            n3 = n3 * 10 + per[s3v[i]];
        }
        if(n1 + n2 == n3){
            std::cout << n1 << std::endl;
            std::cout << n2 << std::endl;
            std::cout << n3 << std::endl;
            return 0;
        }

    }

    std::cout << "UNSOLVABLE" << std::endl;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007 // 998244353
#define INFLL (1LL<<62)
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
__attribute__((constructor))
void init(){ std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout<<std::fixed<<std::setprecision(15); }
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ll n, ans = 0;
    cin >> n;
    vi a(n), sa(n), ssa(n), sssa(n, 0);
    map<ll, ll> cnt;
    rep(i, n){
        cin >> a[i];
        cnt[(a[i] == 0 ? 0 : (a[i] <= -1 ? -1 : 1))]++;
        sa[i] = a[i];
        if(i != 0){
            sa[i] += sa[i-1];
            ssa[i] += ssa[i-1] + sa[i];
            chmax(sssa[i], max(sssa[i-1], sa[i]));
        }
        else{
            ssa[i] = a[i];
            chmax(sssa[i], sa[i]);
        }
    }

    // 全部合算でOK
    if(cnt[1]+cnt[0] == n){
        cout << ssa[n-1] << endl;
        return 0;
    }
    else if(cnt[0] + cnt[-1] == n){
        cout << 0 << endl;
        return 0;
    }

    rep(i, n-1){
        chmax(ans, ssa[i]);
        chmax(ans, ssa[i] + sssa[i]);
    }
    chmax(ans, ssa[n-1]);
    cout << ans << endl;
}

//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# 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;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit);
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5+5;
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());

int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}

void solve() {
	int n;
	cin >> n;
	ll sum = 0;
	ll cur = 0;
	ll ans = 0, pref = 0;
	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		sum += x;
		pref = max(pref, sum);
		ans = max(ans, cur+pref);
		cur += sum;
	}
	cout << ans << '\n';
}

int main () {
	SpeedForce;

	int T = 1;
	//cin >> T;
	while(T--) solve();

	return Accepted;
}

// B...a


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) a.begin(),a.end()
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<typename T>
using v=vector<T>;
template<typename T>
using vv=vector<v<T>>;
template<typename T>
using vvv=vector<vv<T>>;

int main(){
    int n;
    cin>>n;
    stack<int> l;
    queue<int> r;
    ll s=0;
    rep(i,n){
        int a;
        cin>>a;
        s+=a;
        l.push(a);
    }
    rep(i,n){
        int a;
        cin>>a;
        s+=a;
        r.push(a);
    }
    priority_queue<int,vector<int>,greater<>> q;
    ll a=0;
    rep(i,n){
        q.push(l.top());
        q.push(r.front());
        l.pop();
        r.pop();
        a+=q.top();
        q.pop();
    }
    cout<<s-a<<endl;
}

#include<bits/stdc++.h>
using namespace std;
const int N=4e5+7;
typedef long long LL;
struct str{
	int v,x;
}p[N];
bool operator <(str a,str b){
	return a.v>b.v;
}
set<int> S;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)S.insert(i);
	for(int i=1;i<=n;i++)scanf("%d",&p[i].v),p[i].x=n-i+1;
	for(int i=1;i<=n;i++)scanf("%d",&p[n+i].v),p[n+i].x=i;
	int tot=2*n;
	sort(p+1,p+tot+1);
	LL ans=0;
	for(int i=1;i<=tot;i++){
		str v=p[i];
		if(S.upper_bound(v.x)!=S.begin()){
			ans+=v.v;
			S.erase(--S.upper_bound(v.x));
		}
	}
	printf("%lld\n",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxm=2e6+5;
char s[maxm];
char t[maxm];
int n;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
    cin>>n;
    cin>>(s+1);
    cin>>(t+1);
    vector<int>pos;
    for(int i=1;i<=n;i++){
        s[i]-='0',t[i]-='0';
        if(s[i])pos.push_back(i);
    }
    int len=pos.size();
    int cur=0;
    int ans=0;
    for(int i=1;i<=n;i++){
        while(cur<len&&pos[cur]<=i)cur++;
        if(s[i]==t[i])continue;
        if(cur>=len){
            cout<<-1<<endl;
            return 0;
        }
        ans+=pos[cur]-i;
        s[pos[cur]]=0;
        cur++;
    }
    cout<<ans<<endl;
    return 0;
}

//ABC 182 C - To 3
//题目地址：https://atcoder.jp/contests/abc182/tasks/abc182_c

#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

int main() {
    int64_t n;
    scanf("%" SCNd64, &n);

    int cnt[3] = { 0 };
    while (n) {
        cnt[n % 10 % 3]++;
        n /= 10;
    }
    int cur = (cnt[1] + 2 * cnt[2]) % 3;
    int k = cnt[0] + cnt[1] + cnt[2];
    int res;
    if (!cur) res = 0;
    else if (cur == 1) {
        if (cnt[1]) {
            if (k == 1) res = -1;
            else res = 1;
        } else {
            if (k == 2) res = -1;
            else res = 2;
        }
    } else {
        if (cnt[2]) {
            if (k == 1) res = -1;
            else res = 1;
        } else {
            if (k == 2) res = -1;
            else res = 2;
        }
    }
    printf("%d\n", res);

    return 0;
}


#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,l,r) for(int i=(r)-1,i##_left=(l);i>=i##_left;--i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define TIN(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
#define VIND(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem,--_elem
#define OUT(x) cout << (x);
#define OUTL(x) cout << (x) << endl;
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;}
template<class T>
string join(vector<T>& v, string delim="") { ostringstream os; rep(i,v.size())i?os<<delim<<v[i]:os<<v[0]; return os.str(); }
#pragma endregion RegionDefs

void solve()
{
    TIN(string, s);
    ll ans = 0;
    rep(i, 9) {
        if (s[i] == 'Z' && s[i+1] == 'O' && s[i+2] == 'N' && s[i+3] == 'e') ++ans;
    }
    OUTL(ans);
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}


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

using ll = long long;

void solve(long long N, std::vector<long long> A, std::vector<long long> B){
    ll ma = 0;
    ll mi = 1e9;
    for(int i = 0;i < N;i++){
        ma = max(A[i], ma);
        mi = min(B[i], mi);
    }
    cout<<max(mi - ma + 1, 0LL)<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&B[i]);
    }
    solve(N, std::move(A), std::move(B));
    return 0;
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

// Mod int
const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint operator~() const { return mint(1) / *this;}
  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){ (x*=a.pow(mod-2).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 operator/(const mint& a)const{ return mint(*this) /= a;}
  mint pow(ll t) const {
    if(!t) return 1;
    mint res = pow(t/2);
    res *= res;
    return (t&1)?res*x:res;
  }
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
mint ex(mint x, ll t) { return x.pow(t);}
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
typedef vector<mint> vm;
struct comb {
  vm f, g;
  comb(){}
  comb(int mx):f(mx+1),g(mx+1) {
    f[0] = 1;
    rrep(i,mx) f[i] = f[i-1]*i;
    g[mx] = f[mx].pow(mod-2);
    for(int i=mx;i>0;i--) g[i-1] = g[i]*i;
  }
  mint operator()(int a, int b) {
    if (a < b) return 0;
    return f[a]*g[b]*g[a-b];
  }
};
//

mint f(int a) {
  return mint(a)*(a+1)/2;
}

int main() {
  mint ans = 1;
  rep(i,3) {
    int a;
    scanf("%d",&a);
    ans *= f(a);
  }
  cout<<ans<<endl;
  return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 100100;
const int mod = 1000000007;
ll v[100];

int main()
{
    ll n;
	cin >> n;
	ll z = 1;
	ll minn = n;
	for(int i = 1; i <= 61; i++){
		z = z*2;
		if(n < z){
			break;
		}
		ll k = n / z;
		ll x = k + i + (n-k*z);
		minn = min(minn,x);
	}
	cout << minn << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> pin;

const int N = 4e5 + 5;
const int Maxn = 4e5;
const ll P = 998244353LL;

int n, m;
ll fac[N], ifac[N];

template <typename T>
inline void read(T &X) {
    char ch = 0; T op = 1;
    for (X = 0; ch > '9' || ch < '0'; ch = getchar())
        if (ch == '-') op = -1;
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        X = (X * 10) + ch - '0';
    X *= op;
}

inline ll fpow(ll x, ll y) {
    ll res = 1;
    for (x %= P; y > 0; y >>= 1) {
        if (y & 1) res = res * x % P;
        x = x * x % P;
    }
    return res;
}

inline ll getc(int x, int y) {
    return fac[x] * ifac[y] % P * ifac[x - y] % P;
}

inline ll solve(int now) {
    vector <int> vec;
    int tmp = now;
    for (int i = 2; i * i <= now; i++) {
        if (tmp % i == 0) {
            int cnt = 0;
            for (; tmp % i == 0; ++cnt, tmp /= i);
            vec.push_back(cnt);
        }
    }
    if (tmp != 1) vec.push_back(1);
    ll res = 1;
    for (int i = 0; i < vec.size(); i++) res = res * getc(vec[i] + n - 1, n - 1) % P;
    return res;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("sample.in", "r", stdin);
    clock_t st_clock = clock();
#endif

    fac[0] = 1;
    for (int i = 1; i <= Maxn; i++) fac[i] = fac[i - 1] * i % P;
    ifac[Maxn] = fpow(fac[Maxn], P - 2);
    for (int i = Maxn - 1; i >= 0; i--) ifac[i] = ifac[i + 1] * (i + 1) % P;
    read(n), read(m);
    ll ans = 0;
    for (int i = 1; i <= m; i++) {
        ans += solve(i);
        if (ans >= P) ans -= P;
    }
    printf("%lld\n", ans);

#ifndef ONLINE_JUDGE
    clock_t ed_clock = clock();
    printf("time = %f ms\n", (double)(ed_clock - st_clock) / CLOCKS_PER_SEC * 1000);
#endif
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

template <class T>
T gcm(T a, T b) {
    if (a < b) {
        T w = a;
        a = b;
        b = w;
    }

    while (b != 0) {
        T w = a % b;
        a = b;
        b = w;
    }

    return a;
}

int main() {
    vector<long long> p = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 };

    int n;
    cin >> n;

    vector<long long> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }

    long long res = 1;
    for (int i = 0; i < static_cast<int>(p.size()); i++) {
        res *= p[i];
    }

    for (int i = 1; i < (1 << p.size()); i++) {
        long long q = 1;
        for (int j = 0; j < static_cast<int>(p.size()); j++) {
            if ((i & (1 << j)) > 0) {
                q *= p[j];
            }
        }

        bool r = true;
        for (int j = 0; j < n; j++) {
            r = r && gcm(q, x[j]) > 1;
        }

        if (r && res > q) {
            res = q;
        }
    }

    cout << res << endl;
}

#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

const int N=505;

int n;
int a[N][N];

int diff[N];
int ans_a[N],ans_b[N];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			scanf("%d",&a[i][j]);

	bool flag=true;
	for(int i=1;i<n;i++)
		diff[i]=a[1][i+1]-a[1][i];

	for(int i=2;i<=n;i++)
		for(int j=1;j<n;j++)
			if(diff[j]!=a[i][j+1]-a[i][j])
				flag=false;

	int mn=1<<30;
	for(int i=1;i<=n;i++)
		mn=min(mn,a[1][i]);
	for(int i=1;i<=n;i++)
		ans_b[i]=a[1][i]-mn;
	for(int i=1;i<=n;i++)
	{
		ans_a[i]=(a[i][1]-a[1][1])+(a[1][1]-ans_b[1]);
		if(ans_a[i]<0)
			flag=false;
	}

	if(flag)
	{
		printf("Yes\n");
		for(int i=1;i<=n;i++)
			printf("%d%c",ans_a[i],i==n?'\n':' ');
		for(int i=1;i<=n;i++)
			printf("%d%c",ans_b[i],i==n?'\n':' ');
	}
	else
		printf("No\n");
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<bool> vb;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1 << 30;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    int r = 0;
    int ans = -1;
    for(int x = 2; x <= 1100; ++x) {
        int cnt = 0;
        rep(i,n) {
            if(a[i] % x == 0) cnt++;
        }
        if(chmax(r, cnt)) ans = x;
    }
    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
#define inf 0x3f3f3f3f3f3f3f3f
string s;
int dig[65];
ll pow(ll a, ll b) {
	ll res = 1;
	while(b) {
		if(b & 1) res = res * a;
//		if()
		a = a * a;

	}
	return res;
}
int len;
	ll m;
bool solve(ll r) {
	ll sum = 0;
	int f = 1;
	for(int i = 0; i < len; i++) {
		if(inf / r < sum) {
			return false;
		}
		sum = sum * r + dig[i];
		if(sum > m || sum < 0) {
			f = 0;
			break;
		}
	}
	return f;
}
int main() {
	cin >> s;
	scanf("%lld", &m);
	int d = 0;
	len = s.size();
	for(int i = 0; i < len; i++) {
		d = max(d, s[i] - '0');
		dig[i] = s[i] - '0';
	}
	if(len == 1) {
		printf("%d\n", dig[0] <= m);
		return 0;
	}
	if(!solve(d + 1)) {
		printf("%d\n", 0);
		return 0;
	}
	ll l = d + 1, r = 1e18, mid;
	while(l < r) {
		mid = (l + r + 1) >> 1ll;
		if(solve(mid)) {
			l = mid;
		}
		else {
			r = mid - 1;
		}
	}
	printf("%lld\n", l - d);
}


#include <bits/stdc++.h>
using namespace std;
long long n,k,a[10][10];
vector<int>sol={1,2,3,4,5,6,7,8};
int ans=0;
void solve(int i){
    long long tmp=0;
    for(int i=0;i<n;i++){
        tmp+=a[sol[i]][sol[i+1]];
    }
    tmp+=a[sol[n-1]][1];
    if(tmp==k)ans+=1;
    tmp=0;
 while(next_permutation(sol.begin(),sol.begin()+n)){
    if(sol[0]==1){
        for(int i=0;i<n;i++){
            tmp+=a[sol[i]][sol[i+1]];
        }

        tmp+=a[sol[n-1]][1];
        if(tmp==k)ans+=1;
        tmp=0;
    }
 }
}
int main() {
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++) {
            cin >> a[i][j];
        }
    }
solve(1);
    cout<<ans;
    return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;

const int N = 1e5 + 10;

int n, x;
int a[N];

int main(){
    cin >> n >> x;
    for(int i = 0; i < n; i++) cin >> a[i];
    int i = 0, j = 0;
    while(j < n){
        if(a[j] == x) j++;
        else a[i++] = a[j++];
    }
    for(int k = 0; k < i; k++) cout << a[k] << " ";
    cout << endl;
    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

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

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

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

int main(){
  int n,k;
  cin >> n >> k;
  vvi t(n, vi(n));
  REP(i,n)REP(j,n)cin >> t[i][j];

  vi a(n-1);
  iota(ALL(a),1);
  int ans=0;
  do {
    int d=0;
    d += t[0][a[0]];
    REP(i,n-2)d+=t[a[i]][a[i+1]];
    d += t[a[n-2]][0];
    if(d==k)ans++;
  } while( next_permutation(a.begin(), a.end()) );
  cout << ans << endl;
}

//author-micheal corleone
//the godfather
#include <bits/stdc++.h>
#include <set>
#include<algorithm>
#include <set>
#include<algorithm>
#define ll long long int
#define in(n) scanf("%lld",&n)
#define in2(a,b) scanf("%lld %lld",&a,&b)
#define out(n) printf("%lld\n",n)
#define inf 999999999999999999
#define endl "\n"
#define precise(x) fixed << setprecision(x)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int mod =1000000007;
#define f(i,a,n) for(int i=a;i<n;i++)
#define pb push_back

using namespace std;

bool sortcol( const vector<int>& v1,
               const vector<int>& v2 ) {
 return v1[1] < v2[1];
}
 ll mod_pow(int a,int b,int M = mod)
{
    int res = 1;

    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }

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

ll ncr(ll n,ll r){if(n==1 || r==0)return 1;if(r>n/2)r=n-r;
	ll ans=1;for(ll i=1;i<=r;i++){ans=((ans * n )/i);n--;}return ans;
}
ll ncrsum(ll n,ll r, ll mod){
    if(n==1 || r==0)return 1;
  //  ll ans=1,sum=1;for(ll i=1;i<=r;i++){ans=((((ans * n)%MOD )*modinv(i,MOD))%mod);n--;sum+=ans;sum%=mod;}return sum;
}
 //diamond[2000005],ans[1000006];
 const int maxn=3e5+100;
 ll maximum=4000000;

 vector<ll> primes;

void SieveOfEratosthenes()
{

    vector<ll> prime(maximum+1,1);
   // memset(prime, 1, sizeof(prime));

    for (ll p=2; p*p<=maximum; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == 1)
        {
            // Update all multiples of p greater than or
            // equal to the square of it
            // numbers which are multiple of p and are
            // less than p^2 are already been marked.
            for (ll i=p*p; i<=maximum; i += p)
                prime[i] = 0;
        }
    }

    for (ll p=2; p<=maximum; p++)
    {
    	if (prime[p])
		{
			primes.pb(p);
		 }
	}

}
 ll  a[20];
 ll n,k;
ll timing[50][50];
ll answer=0;
ll final_answer=0;
void findPermutations(ll a[], ll n)
{
    sort(a,a+n);
    do {
        answer=0;
        answer=answer+timing[1][a[0]];
        for(ll i=0;i<n-1;i++)
		{
			answer=answer+timing[a[i]][a[i+1]];
		 }
		 answer=answer+timing[a[n-1]][1];
		 if(answer==k) final_answer++;

		 //cout<<answer<<endl;
    } while (next_permutation(a, a + n));
}

int main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
     ll ta;
    //cin>>ta;
    //SieveOfEratosthenes();
    ta=1;
     for(ll testcase=0;testcase<ta;testcase++)
    {
        ll i1,i2,j,j1,a1,i31,i3,j2,i5,i4,i6,i7,i,m,t;
        ll x,y,z,l;
        ll total=0,cnt=0;
        ll flag=0,flag1=0;
        y=0;
        ll res,res1,ans,res2,sum,curr;
        ans=0,cnt=0;
        res1=0,res=0,sum=0;
        ll required,days,h,w;
        ll s1=0;
         ll k1,k2,k3,k4,p;
        k1=0,k2=0,k3=0,k4=0;
        //for(it=mp.begin();it!=mp.end(),it++)
        //{
        //	for(int i=0;i<it->second.size();i++) cout<<it->second[i]<<" ";
		//}
	    string s;
	    cin>>n>>k;

	    for(i=1;i<=n;i++)
	    {
	    	for(j=1;j<=n;j++)
	    	{
	    		cin>>timing[i][j];
			}
		}

	    for(i=2;i<=n;i++)
	    {
	    	a[s1]=i;
	    	s1++;
		}
		findPermutations(a,n-1);
		cout<<final_answer<<endl;
	}

}


#include <bits/stdc++.h>

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

set<int> solve(set<int> A, set<int> B) {
  set<int> retv;

  set<int> set_u;
  set_union(ALL(A), ALL(B), inserter(set_u, set_u.begin()));
  set<int> set_i;
  set_intersection(ALL(A), ALL(B), inserter(set_i, set_i.begin()));

  set_difference(ALL(set_u), ALL(set_i), inserter(retv, retv.begin()));
  return retv;
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M;
  set<int> A, B;

  cin >> N >> M;
  for (size_t i = 0; i < N; i++) {
    int A_i;
    cin >> A_i;
    A.insert(A_i);
  }
  for (size_t i = 0; i < M; i++) {
    int B_i;
    cin >> B_i;
    B.insert(B_i);
  }

  // main procedure
  set<int> ans = solve(A, B);

  // output
  for (auto &&x : ans) {
    cout << x << (x == *(ans.rbegin()) ? "\n" : " ");
  }

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int N=105;

long long x;
int mem[N][N][N],vis[N][N][N],vid;
int arr[N];
int n,k;

int go(int ind,int rem,int remi)
{
	if(ind>=n) return (rem==0&&remi==0?0:-(1<<30));
	int &ret=mem[ind][rem][remi];
	if(vis[ind][rem][remi]==vid) return ret;
	vis[ind][rem][remi]=vid;
	ret=max(arr[ind]+go(ind+1,(rem+k-arr[ind]%k)%k,remi-1),go(ind+1,rem,remi));
	return ret;
}

int main()
{
	scanf("%d %lld",&n,&x);
	for(int i=0;i<n;i++) scanf("%d",&arr[i]);
	long long ans=(1LL<<60);
	for(int i=1;i<=n;i++)
	{
		vid++;
		k=i;
		long long res=go(0,x%i,i);
		//cout << i << " " << res << endl;
		if(res>0) ans=min(ans,(x-res)/k);
	}
	printf("%lld\n",ans);
}


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

using ll = long long;

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

  int r, c;
  cin >> r >> c;

  vector<vector<ll>> a(r, vector<ll>(c - 1)), b(r - 1, vector<ll>(c));
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c - 1; j++) {
      cin >> a.at(i).at(j);
    }
  }
  for (int i = 0; i < r - 1; i++) {
    for (int j = 0; j < c; j++) {
      cin >> b.at(i).at(j);
    }
  }

  vector<vector<vector<ll>>> dp(r, vector<vector<ll>>(c, vector<ll>(2, 2e18)));
  vector<ll> dp2(c, 2e18), dp3(c, 0);
  dp[0][0][0] = 0;
  dp2[0] = 0;
  priority_queue<tuple<ll, ll, ll, ll>, vector<tuple<ll, ll, ll, ll>>, greater<tuple<ll, ll, ll, ll>>> pq;
  pq.push(make_tuple(0, 0, 0, 0));
  while (!pq.empty()) {
    auto [dist, ix, iy, iz] = pq.top();
    pq.pop();
    if (dp[ix][iy][iz] < dist) continue;
    if (iz == 0) {
      if (iy < c - 1 && dp[ix][iy + 1][iz] > dp[ix][iy][iz] + a[ix][iy]) {
        dp[ix][iy + 1][iz] = dp[ix][iy][iz] + a[ix][iy];
        pq.push(make_tuple(dp[ix][iy + 1][iz], ix, iy + 1, iz));
      }
      if (iy > 0 && dp[ix][iy - 1][iz] > dp[ix][iy][iz] + a[ix][iy - 1]) {
        dp[ix][iy - 1][iz] = dp[ix][iy][iz] + a[ix][iy - 1];
        pq.push(make_tuple(dp[ix][iy - 1][iz], ix, iy - 1, iz));
      }
      if (ix < r - 1 && dp[ix + 1][iy][iz] > dp[ix][iy][iz] + b[ix][iy]) {
        dp[ix + 1][iy][iz] = dp[ix][iy][iz] + b[ix][iy];
        pq.push(make_tuple(dp[ix + 1][iy][iz], ix + 1, iy, iz));
      }
      if (dp[ix][iy][iz + 1] > dp[ix][iy][iz] + 1) {
        dp[ix][iy][iz + 1] = dp[ix][iy][iz] + 1;
        pq.push(make_tuple(dp[ix][iy][iz + 1] , ix, iy, iz + 1));
      }
    }
    else {
      if (ix > 0 && dp[ix - 1][iy][iz] > dp[ix][iy][iz] + 1) {
        dp[ix - 1][iy][iz] = dp[ix][iy][iz] + 1;
        pq.push(make_tuple(dp[ix - 1][iy][iz] , ix - 1, iy, iz));
      }
      if (dp[ix][iy][iz - 1] > dp[ix][iy][iz]) {
        dp[ix][iy][iz - 1] = dp[ix][iy][iz];
        pq.push(make_tuple(dp[ix][iy][iz - 1] , ix, iy, iz - 1));
      }
    }
  }

  cout << min(dp[r - 1][c - 1][0], dp[r - 1][c - 1][1]) << '\n';
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define debug(x) cerr << #x << ": " << x << endl;
#define fin(a) { cout << a << endl; return 0; }
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using ld = long double;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
template<class T> using priq     = priority_queue<T>;
template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; }
struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF;

template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) {
    return in >> p.first >> p.second;
}
template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) {
    return out << '{' << p.first << ',' << p.second << '}';
}
template<class T, class U> pair<T,U> operator+(const pair<T,U> &l, const pair<T,U> &r) {
    return make_pair(l.first+r.first, l.second+r.second);
}
template<class T, class U> pair<T,U> operator-(const pair<T,U> &l, const pair<T,U> &r) {
    return make_pair(l.first-r.first, l.second-r.second);
}
template<class T, class U> pair<T,U> operator*(const pair<T,U> &l, const pair<T,U> &r) {
    return make_pair(l.first*r.first, l.second*r.second);
}
template<class T, class U> pair<T,U> operator/(const pair<T,U> &l, const pair<T,U> &r) {
    return make_pair(l.first/r.first, l.second/r.second);
}
template<class T, class U> pair<T,U>& operator+=(pair<T,U> &l, const pair<T,U> &r) { return l = l+r; }
template<class T, class U> pair<T,U>& operator-=(pair<T,U> &l, const pair<T,U> &r) { return l = l-r; }
template<class T, class U> pair<T,U>& operator*=(pair<T,U> &l, const pair<T,U> &r) { return l = l*r; }
template<class T, class U> pair<T,U>& operator/=(pair<T,U> &l, const pair<T,U> &r) { return l = l/r; }

template<class T>
istream& operator>>(istream &in, vector<T> &v) {
    for(auto &&e : v) in >> e;
    return in;
}
template<class T>
ostream& operator<<(ostream &out, const vector<T> &v) {
    for(const auto &e : v) out << e << ' ';
    return out;
}

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

int main(){
    int n;
    cin >> n;
    V<Pl> ps(n);
    cin >> ps;

    int m;
    cin >> m;
    V<V<ll>> xs(m+1,V<ll>(3)), ys(m+1,V<ll>(3)); // vector = {a, b, c}, point = ax + by + c
    xs[0] = {1,0,0};
    ys[0] = {0,1,0};
    Rep(i,m) {
        int ty;
        cin >> ty;
        if(ty == 1) {
            xs[i] = ys[i-1];
            ys[i] = { -xs[i-1][0], -xs[i-1][1], -xs[i-1][2] };
        }
        if(ty == 2) {
            ys[i] = xs[i-1];
            xs[i] = { -ys[i-1][0], -ys[i-1][1], -ys[i-1][2] };
        }
        if(ty == 3) {
            ll p; cin >> p;
            ys[i] = ys[i-1];
            xs[i] = { -xs[i-1][0], -xs[i-1][1], -xs[i-1][2]+2*p };
        }
        if(ty == 4) {
            ll p; cin >> p;
            xs[i] = xs[i-1];
            ys[i] = { -ys[i-1][0], -ys[i-1][1], -ys[i-1][2]+2*p };
        }
    }

    int q;
    cin >> q;
    V<Pl> anss(q);
    rep(i,q) {
        int a, b;
        cin >> a >> b;
        b--;
        ll x = ps[b].fi;
        ll y = ps[b].se;
        ll ansx = xs[a][0]*x + xs[a][1]*y + xs[a][2];
        ll ansy = ys[a][0]*x + ys[a][1]*y + ys[a][2];
        anss[i] = make_pair(ansx, ansy);
    }
    for(Pl ans : anss) {
        cout << ans.fi << ' ' << ans.se << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,m,tot,head[N];
long long dis[N];
bool vis[N];
struct Star
{
	int to,nxt,c,d;
}edge[2*N];
void Lian(int x,int y,int z,int w)
{
	tot++;
	edge[tot].c=z;
	edge[tot].d=w;
	edge[tot].nxt=head[x];
	edge[tot].to=y;
	head[x]=tot;
}
struct Point
{
	long long dd;
	int p;
	bool operator<(const Point &x)const{
		return dd>x.dd;
	}
};
void dijkstra()
{
	for(int i=1;i<=n;i++) dis[i]=1e18;
	Point a;
	a.dd=0;
	a.p=1;
	dis[1]=0;
	priority_queue<Point> q;
	q.push(a);
	while(!q.empty())
	{
		a=q.top();
		q.pop();
		int x=a.p;
		if(vis[x]) continue;
		vis[x]=1;
		for(int i=head[x];i;i=edge[i].nxt)
		{
			long long val;
			int y=edge[i].to;
			int k=sqrt(edge[i].d);
			if(dis[x]<=k) val=0ll+k+(edge[i].d/(k+1))+edge[i].c;
			else val=0ll+dis[x]+(edge[i].d/(dis[x]+1))+edge[i].c;
			if(val<dis[y])
			{
				dis[y]=val;
				a.dd=dis[y],a.p=y;
				q.push(a);
			}
		}
	}
 }
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		Lian(a,b,c,d);
		Lian(b,a,c,d);
	}
	dijkstra();
	if(dis[n]==1e18) puts("-1");
	else printf("%lld",dis[n]);
	return 0;
}

/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - Rush Hour 2
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_M = 100000;
const long long LINF = 1LL << 62;

/* typedef */

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

/* global variables */

vpii nbrs[MAX_N];
int cs[MAX_M], ds[MAX_M], mts[MAX_M];
ll ts[MAX_N];

/* subroutines */

ll edget(ll t, int ci, int di) { return t + ci + di / (t + 1); }

ll calcmint(ll t, int ei) {
  int ci = cs[ei], di = ds[ei];
  return edget(max(t, (ll)mts[ei]), ci, di);
}

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d%d%d", &a, &b, cs + i, ds + i);
    a--, b--;
    nbrs[a].push_back(pii(b, i));
    nbrs[b].push_back(pii(a, i));
    mts[i] = round(sqrt(ds[i])) - 1;
  }

  fill(ts, ts + n, LINF);
  ts[0] = 0;

  priority_queue<pli> q;
  q.push(pli(0, 0));

  while (! q.empty()) {
    pli u = q.top(); q.pop();
    ll ut = -u.first;
    int ui = u.second;
    if (ts[ui] != ut) continue;

    if (ui == n - 1) break;

    for (auto ve: nbrs[ui]) {
      int vi = ve.first, ei = ve.second;
      ll vt = calcmint(ut, ei);
      if (ts[vi] > vt) {
	ts[vi] = vt;
	q.push(pli(-vt, vi));
      }
    }
  }

  ll gt = ts[n - 1];
  printf("%lld\n", (gt >= LINF) ? -1LL : gt);
  return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

// 1-indexed
template<typename T>
struct BIT{
    int n;
    vector<T> bit;
    BIT(int n_=0):n(n_),bit(n+1){}
    T sum(int i){
        T res=0;
        for(;i>0;i-=(i&-i))res+=bit[i];
        return res;
    }
    void add(int i,T a){
        if(i==0)return;
        for(;i<=n;i+=(i&-i)){bit[i]+=a;}
    }
    int lower_bound(T k){ // k<=sum(res)
        if(k<=0)return 0;
        int res=0,i=1;
        while((i<<1)<=n)i<<=1;
        for(;i;i>>=1){
            if(res+i<=n&&bit[res+i]<k)k-=bit[res+=i];
        }
        return res+1;
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    map<int,vector<int>> mp;
    for(int i=n-1;i>=0;i--){
        mp[a[i]+i].push_back(i);
    }
    for(int i=0;i<n;i++){
        cin >> b[i];
        if(mp[b[i]+i].size()==0){
            printf("-1\n");
            return 0;
        }
        int id=mp[b[i]+i].back();
        mp[b[i]+i].pop_back();
        b[i]=id;
    }
    BIT<int> bit(n);
    ll res=0;
    for(int i=0;i<n;i++){
        res+=i-bit.sum(b[i]+1);
        bit.add(b[i]+1,1);
    }
    cout << res << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

ll seg[1ll<<20];

void set_value(ll q, ll sl=0, ll sr=1ll<<19, ll pos=1) {
    if (q<sl || sr<=q) return;
    seg[pos]++;
    if (pos>=(1ll<<19)) return;
    ll sm = (sl+sr)/2;
    set_value(q,sl,sm,pos*2);
    set_value(q,sm,sr,pos*2+1);
    return;
}

ll get_cnt(ll ql, ll qr, ll sl=0, ll sr=1ll<<19, ll pos=1) {
    if (qr<=sl || sr<=ql) return 0;
    if (ql<=sl && sr<=qr) return seg[pos];
    ll sm = (sl+sr)/2;
    ll lsum = get_cnt(ql,qr,sl,sm,pos*2);
    ll rsum = get_cnt(ql,qr,sm,sr,pos*2+1);
    return lsum+rsum;
}
int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    REP(i,n) {cin >> a[i];a[i]+=i;}
    REP(i,n) {cin >> b[i];b[i]+=i;}
    vector<ll> as = a;
    vector<ll> bs = b;
    sort(as.begin(),as.end());
    sort(bs.begin(),bs.end());
    REP(i,n) {
        if (as[i]!=bs[i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    vector<P> ap(n);
    vector<P> bp(n);
    REP(i,n) {ap[i]={a[i],i}; bp[i]={b[i],i};}
    sort(ap.begin(),ap.end());
    sort(bp.begin(),bp.end());
    vector<P> t(n);
    REP(i,n) {
        t[i]={ap[i].second+1ll,bp[i].second+1ll};
    }
    sort(t.begin(),t.end());
    // REP(i,n) cout << t[i].first << " " << t[i].second << endl;
    ll ans = 0;
    REP(i,n) {
        ll val = t[i].second;
        set_value(val);
        ans += get_cnt(val+1,1ll<<19);
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
#include <cmath>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll INFI = 1001001001;
const ll INFL = 1001001001001001001;
const ll MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, in, fn) for (ll i = in; i <= fn; i++)
#define debug(x) cerr << #x << ": " << x << endl

void sort2vectors(vector<ll> &av, vector<ll> &bv)
{
    int n = av.size();
    vector<ll> p(n), av2(n), bv2(n);
    iota(p.begin(), p.end(), 0);
    sort(p.begin(), p.end(), [&](ll a, ll b) { return av[a] < av[b]; });
    for (int i = 0; i < n; i++)
    {
        av2[i] = av[p[i]];
        bv2[i] = bv[p[i]];
    }
    av = av2;
    bv = bv2;
}

int main()
{
    long long K;
    scanf("%lld", &K);
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> A(K), A2(K), num(K);
    std::vector<long long> B(K), sa(K);
    for (int i = 0; i < K; i++)
    {
        scanf("%lld", &A[i]);
    }

    ll sum = 0;
    rep(i, K)
    {

        A2[i] = A[i];
        num[i] = i;
        B[i] = M * A[i] / N;
        sum += B[i];
        //debug(B[i]);
        sa[i] = (llabs((B[i] + 1) * N - A[i] * M)) - (llabs(B[i] * N - A[i] * M));
        //debug(sa[i]);
    }
    ll amari = M - sum;
    sort2vectors(sa, num);
    rep(i, amari)
    {
        B[num[i]]++;
    }
    rep(i, K)
    {
        cout << B[i] << " ";
    }
    cout << endl;
    return 0;
}

#include <bits/stdc++.h>

template <class T>
inline void read(T &x) {
	static char ch;
	static bool opt;
	while (!isdigit(ch = getchar()) && ch != '-');
	x = (opt = ch == '-') ? 0 : ch - '0';
	while (isdigit(ch = getchar()))
		x = x * 10 + ch - '0';
	if (opt)
		x = ~x + 1;
}

template <class T>
inline void putint(T x) {
	static char buf[45], *tail = buf;
	if (!x)
		putchar('0');
	else {
		if (x < 0)
			putchar('-'), x = ~x + 1;
		for (; x; x /= 10) *++tail = x % 10 + '0';
		for (; tail != buf; --tail) putchar(*tail);
	}
}

template <class T>
inline bool tense(T &x, const T &y) {
	return y < x ? x = y, true : false;
}

template <class T>
inline bool relax(T &x, const T &y) {
	return x < y ? x = y, true : false;
}

template <class T>
inline T getAbs(const T &x) {
	return x < 0 ? -x : x;
}

typedef long long s64;
typedef long double ld;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
#define mp(x, y) std::make_pair(x, y)

using std::cerr;

const int MaxN = 1e5 + 5;
const s64 INFs64 = 1LL << 60;

int n, m, K, a[MaxN], b[MaxN];

s64 pre[MaxN][2];

inline bool check(s64 mid) {
	for (int i = 1; i <= K; ++i) {
		s64 l = 0, r = m;
		tense(r, (1LL * a[i] * m + mid) / n);
		if (1LL * a[i] * m > mid)
			relax(l, (1LL * a[i] * m - mid - 1) / n + 1);

		pre[i][0] = pre[i - 1][0] + l;
		pre[i][1] = pre[i - 1][1] + r;

		// cerr << l << ' ' << r << '\n';
	}
	return m >= pre[K][0] && m <= pre[K][1];
}

inline s64 findBest() {
	s64 l = 0, r = 1e18, mid, res = 1e18;
	while (l <= r) {
		mid = (l + r) >> 1;
		if (check(mid))
			res = mid, r = mid - 1;
		else
			l = mid + 1;
	}
	return res;
}

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

	read(K), read(n), read(m);
	for (int i = 1; i <= K; ++i) {
		read(a[i]);
	}

	s64 best = findBest();

	// cerr << best << '\n';
	check(best);

	for (int i = K, cur = m; i >= 1; --i) {
		s64 l = 0, r = m;
		tense(r, (1LL * a[i] * m + best) / n);
		if (1LL * a[i] * m > best)
			relax(l, (1LL * a[i] * m - best - 1) / n + 1);

		tense(r, cur - pre[i - 1][0]);
		relax(l, cur - pre[i - 1][1]);

		b[i] = l;
		cur -= b[i];
	}
	for (int i = 1; i <= K; ++i) {
		printf("%d%c", b[i], " \n"[i == K]);
	}

	return 0;
}


#include <bits/stdc++.h>
//#include <cmath>
typedef long long ll;
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007
//#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define bs(yup,x) binary_search(yup.begin(),yup.end(),x) //it will return bollean value
#define lb(yup,x) lower_bound(yup.begin(),yup.end(),x)  //it will return the adress of the number which is equal to or just greater than x ,and if it is equal to yup.end() than their in no such number exist
#define ub(yup,x) upper_bound(yup.begin(),yup.end(),x)
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
using namespace std;
const long long N=1000001,INF=2000000000000000000;
const long double EPS= 0.000000000001;

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

ll modinverse(ll n,ll p){
	return power(n,p-2,p);
}

ll nCr(ll n,ll r,ll p){
	ll f[n+1];
	f[0] = 1;
	for(ll i=1;i<=n;i++){
		f[i] = f[i-1]*i%p;
	}

	return (f[n]%p * modinverse(f[r],p)%p * modinverse(f[n-r],p)%p)%p;
}

int main() {
    IOS;
    //fill(isprime, true);
    //pre();
    int t;
    //cin>>t;
    t=1;
    while(t--){
		int n;
		cin>>n;
		int a[1005] = {0};
		for(int i=0;i<n;i++){
			int x;
			cin>>x;
			a[x] = 1;
		}
		int f=0;
		for(int i=1;i<=n;i++){
			if(a[i]==0){
				f=1;
				cout<<"No"<<endl;
				break;
			}
		}
		if(!f){
			cout<<"Yes"<<endl;
		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node{long long x,y;}f[200002];
long long n,a=0,b=0,cnt=0;
bool cmp(node x,node y){return 2*x.x+x.y>2*y.x+y.y;}
int main(){
    scanf("%lld",&n);
    for(int i=0;i<n;++i)scanf("%lld%lld",&f[i].x,&f[i].y),a+=f[i].x;
    sort(f,f+n,cmp);
    while(b<=a){b+=f[cnt].x+f[cnt].y;a-=f[cnt].x;++cnt;}
    printf("%lld",cnt);
    return 0;
}

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"
#define COUT16(x) cout << fixed << setprecision(16) << (x) << "\n";

int main(){
    int n;cin >> n;
    ll a[n],b[n];
    ll sum_a = 0;
    vector<ll> sum_ad;
    REP(i,n){
        cin >> a[i] >> b[i];
        sum_a += a[i];
        sum_ad.push_back(2*a[i]+b[i]);
    }
    sort(sum_ad.begin(),sum_ad.end(),greater<ll>());
    ll count = 0,sum=0;
    REP(i,n){
        sum += sum_ad[i];
        count++;
        if(sum>sum_a){
            COUT(count);
            return 0;
        }
    }
}


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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)
#define DEB(x)	cout << #x << " " << x << endl;
#define DEB_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

typedef long long int LL;
typedef pair<int, int> PI;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VL;

struct bySum{
	bool operator() (PI a, PI b) {
		return 2*(LL)a.first+a.second > 2*(LL)b.first+b.second;
	}
};

int main() {

	IOS

	int n;
	cin >> n;
	int a[n], t[n];
	REP(i, n)
		cin >> a[i] >> t[i];

	LL suma = 0;
	REP(i, n)
		suma += a[i];

	PI at[n];
	REP(i, n)
		at[i] = {a[i], t[i]};

	sort(at, at+n, bySum());

	// DEB(suma);
	// REP(i, n)
	// 	cout << at[i] << "," << at[i].second << " ";
	// cout << endl;

	int c = 0, ai = 0;
	LL sumt = 0;

	while (suma >= sumt) {
		sumt += (LL)at[ai].first + at[ai].second;
		suma -= at[ai].first;

		ai++;
		// DEB(suma);
		// DEB(sumt);
		c++;
	}

	cout << c;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
bool cmp(pair<ll,ll> a, pair<ll, ll> b){
    return (2*a.first+a.second) > (2*b.first+b.second);
}

int main(){
    ll n, i, ans=0, ak=0, x, y;
    cin>>n;
    vector<pair<ll, ll>> vt;
    for(i=0;i<n;i++){
        cin>>x>>y;
        vt.push_back({x, y});
        ak+=x;
    }
    sort(vt.begin(), vt.end(), cmp);
    for(i=0;i<n;i++){
        ans+=vt[i].first+vt[i].second;
        ak-=vt[i].first;
        if(ans>ak){
            cout<<i+1;
            return 0;
        }
    }
}


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

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

  ll X = round(a * 10000);
  ll Y = round(b * 10000);
  ll R = round(c * 10000);

  vector<string> str;
  ll ans = 0;
  ll x_s =  ceil((X-R)/10000.0)*10000;
  ll x_e = floor((X+R)/10000.0)*10000;

  for (int i=x_s; i<=x_e; i+=10000) {

    ld rt = sqrtl( (ld)R*(ld)R - ((ld)i-(ld)X)*((ld)i-(ld)X) );
    ll j_large = floor(((ld)Y+ rt )/10000.0)*10000;
    ll j_small =  ceil(((ld)Y- rt )/10000.0)*10000;

    ans += (j_large - j_small) /10000 + 1;
  }

  cout << ans << endl;
  return 0;
}

// {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
// }}}

// 1 unit is 10000
const int K=10000;
LL x,y,r;
void input() {
    double a,b,c;
    R(a,b,c);
    x=round(abs(a)*K);
    y=round(abs(b)*K);
    r=round(abs(c)*K);
}
bool in( LL a, LL b ) {
    return (a-x)*(a-x)+(b-y)*(b-y)<=r*r;
}
LL solve( LL lim ) {
    LL l=0,r=1;
    LL res=0;
    for ( int j=(int)(1e9)+K; j>=lim; j-=K ) {
        while ( in(l*K,j) ) l--;
        while ( in(r*K,j) ) r++;
        res+=r-l-1;
    }
    return res;
}
void main() {
    input();
    // make center between 0 ~ 1
    x%=K;
    y%=K;
    LL ans=0;
    // solve upper part
    ans+=solve(K);
    // solve bottom part
    y=-y; // let bottom part be upper
    ans+=solve(0);
    W(ans);
}

 // {{{ main
}}
int main() { unolight::main(); return 0; }
// }}}


#include <iostream>

using namespace std;

int main() {

    string str;
    cin >> str;

    int len = str.length();

    for(int i = 0; i < len; i++) {
        if(str[i] == '.') {
            break;
        } else {
            cout << str[i];
        }
    }

    cout << endl;

    return 0;
}

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

int main() {
	/*ll t ;
	cin>>t;
	while(t --) {

	} */
	ll n;
	cin>>n;
	if(n % 100 == 0) {
		cout<<n / 100<<"\n";
	}
	else {
		cout <<(n / 100) + 1<<"\n";
	}
}


#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define pp pair<ll, ll>
#define lb lower_bound
#define ub upper_bound
#define mk make_pair
#define pb push_back
#define llp(i, x, n) for (ll i = x; i < n; i++)
#define fr first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define ull unsigned long long ll
#define mod 1000000007
using namespace std;
int main()
{
	fast;
    ll n;
    cin>>n;
    ll a[n];
    llp(i,0,n)
    cin>>a[i];
    sort(a,a+n);
    ll b[n];
    b[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--)
    {
    	b[i]=a[i]+b[i+1];
    }
    ll sum=0;

    for(ll i=0;i<n-1;i++)
    {
    	sum+=b[i+1]-(n-i-1)*a[i];
    }
    cout<<sum<<endl;
}

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

int main() {
  size_t n_num;
  std::cin >> n_num;

  std::vector<int64_t> nums(n_num);
  for (auto &ele : nums) {
    std::cin >> ele;
  }

  std::sort(nums.begin(), nums.end());

  int64_t ans = 0;
  int64_t delta = 0;
  for (size_t i = 0; i < n_num; i++) {
    delta += nums[i] - nums[0];
  }
  ans += delta;
  for (size_t i = 1; i < n_num; i++) {
    delta -= (nums[i] - nums[i - 1]) * (n_num - i);
    ans += delta;
  }
  std::cout << ans << std::endl;
}


#include<bits/stdc++.h>

#define HAS_TEST_CASE 0

namespace rG{

typedef long long ll;

const int N=5e5;

int n,m,k,a[N+10];
char s[N+10];

inline void main(){
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d\n",2*a+100-b);
}

} // namespace rG

int main(){
#if defined(LOCAL)&&HAS_TEST_CASE
	freopen("tmp.out","w",stdout);
#endif
#if HAS_TEST_CASE
	int T;scanf("%d",&T);
	while(T--)rG::main();
#else
	rG::main();
#endif
	return 0;
}

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

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

void solve(int _rot){
   // printf("Case #%d: ",_rot);
   int n;
   cin>>n;
   vector<int> a(n);
   rep(i,0,n)cin>>a[i];

   if(n&1)puts("Second");
   else{
      map<int,int> cnt;
      rep(i,0,n)cnt[a[i]]++;
      for(auto& [tmp,c]:cnt)if(c&1)goto out;
      puts("Second");
      return;
      out:;
      puts("First");
   }
}

int main(){
   int t; scanf("%d",&t);
   rep(rot,0,t)solve(rot+1);
   return 0;
}