#pragma GCC optimize(3)
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <queue>
#include <algorithm>
#define maxn 200010
using namespace std;
int read()
{
	int x=0,w=1;
	char ch=getchar();
	while((ch>'9'||ch<'0')&&(ch!='-')) ch=getchar();
	if(ch=='-')
	{
		w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<1)+(x<<3)+ch-'0';
		ch=getchar();
	}
	return x*w;
}
int n;
struct Code
{
	int l,r,num;
}code[maxn];
struct Heap
{
	int l,r,num;
}heap[maxn];
priority_queue <int> q;
int ans,res;
bool cmpl(Code x,Code y)
{
	return x.l<y.l;
}
bool cmpr(Heap x,Heap y)
{
	return x.r<y.r;
}
int main()
{
	n=read();
	for(register int i=1;i<=n;i++)
	{
		code[i].l=read();
		code[i].r=read();
		code[i].num=i;
		heap[i].l=code[i].l;
		heap[i].r=code[i].r;
		heap[i].num=i;
	}
	sort(code+1,code+n+1,cmpl);
	sort(heap+1,heap+n+1,cmpr);
	if(code[n].l-code[1].l>code[n].r-code[1].r) q.push(code[n].l-code[1].l);
	if(code[n-1].l-code[1].l>code[n-1].r-code[1].r) q.push(code[n-1].l-code[1].l);
	if(code[n].l-code[2].l>code[n].r-code[2].r) q.push(code[n].l-code[2].l);
	if(heap[n].r-heap[1].r>=heap[n].l-heap[1].l) q.push(heap[n].r-heap[1].r);
	if(heap[n-1].r-heap[1].r>=heap[n-1].l-heap[1].l) q.push(heap[n-1].r-heap[1].r);
	if(heap[n].r-heap[2].r>=heap[n].l-heap[2].l) q.push(heap[n].r-heap[2].r);
	q.pop();
	cout<<q.top();
    return 0;
}

#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
#include <iostream>
#include <vector>
using namespace std;

struct union_find {
    // When data[x] < 0, x is a root and -data[x] is its tree size. When data[x] >= 0, data[x] is x's parent.
    vector<int> data;
    vector<int> edges;
    int components = 0;

    union_find(int n = -1) {
        if (n >= 0)
            init(n);
    }

    void init(int n) {
        data.assign(n + 1, -1);
        edges.assign(n + 1, 0);
        components = n;
    }

    int find(int x) {
        return data[x] < 0 ? x : data[x] = find(data[x]);
    }

    int get_size(int x) {
        return -data[find(x)];
    }

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);

        if (x == y) {
            edges[x]++;
            return false;
        }

        if (-data[x] < -data[y])
            swap(x, y);

        data[x] += data[y];
        data[y] = x;
        edges[x] += edges[y];
        edges[x]++;
        components--;
        return true;
    }
};

const int V_MAX = 400005;

int main() {
    ios::sync_with_stdio(false);
#ifndef NEAL_DEBUG
    cin.tie(nullptr);
#endif

    int N;
    cin >> N;
    union_find UF(V_MAX);

    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        UF.unite(a, b);
    }

    int answer = 0;

    for (int i = 0; i < V_MAX; i++)
        if (UF.find(i) == i)
            answer += min(UF.get_size(i), UF.edges[i]);

    cout << answer << '\n';
}


#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using Pair = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

int main(){
   int M,H;
   cin >> M >> H;
   if(H%M == 0) cout << "Yes" << endl;
   else cout << "No" << endl;
}

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define endl '\n'

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;

int g(string a)
{
	int t=0;
	for(int i=0;i<a.size();i++)
	{
		t=t*10+a[i]-'0';
	}
	return t;
}

int f(int x)
{
	string s;
	while(x)
	{
		s+=x%10+'0';
		x/=10;
	}
	sort(s.begin(),s.end());
	int ans1=g(s);
	reverse(s.begin(),s.end());
	int ans2=g(s);
	return ans2-ans1;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,k;
	cin>>n>>k;
	int res=n;
	for(int i=1;i<=k;i++)
	{
		res=f(res);
	}
	cout<<res<<endl;

	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define irep(i,a,b) for(int i=int(a);i<(int)b;++i)
#define rrep(i,a,b) for(int i=int(a);i>=(int)b;--i)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll,ll>>>
#define vpl vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define pb push_back
#define se second
#define fi first
#define all(v) v.begin(),v.end()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>

using namespace std;

template<typename T> istream& operator>>(istream&i,v(T)&v){rep(j,v.size())i>>v[j];return i;}
template<typename T> string join(const v(T)&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T> ostream& operator<<(ostream&o,const v(T)&v){if(v.size())o<<join(v);return o;}

using ll = long long;
const ll INF = LLONG_MAX-1e9;
const double PI = acos(-1);

const ll mod = 1e9 + 7; //998244353;

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

ll modpow(ll a,ll b){
    if(b == 0){
        return 1;
    }
    if(b%2 == 0){
        ll tmp = modpow(a,b/2);
        return tmp*tmp%mod;
    }else{
        return modpow(a,b-1)*a%mod;
    }

}

int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<double,double>>ps;
    rep(i,n){
        int t,l,r;
        cin >> t >> l >> r;
        if(t == 1){
            ps.pb({l,r+0.1});

        }else if(t == 2){
            ps.pb({l,r});

        }else if(t == 3){
            ps.pb({l+0.1,r+0.1});

        }else{
            ps.pb({l+0.1,r});
        }
    }
    int ans = 0;
    rep(i,n)for(int j = i+1;j < n; ++j){
        auto p1 = ps[i],p2 = ps[j];
        if(p1.first < p2.first){
            if(p1.second > p2.first)ans++;
        }else if( p1.first > p2.first){
            if(p2.second > p1.first)ans++;
        }else ans++;
    }
    cout << ans << endl;
    return 0;
}

#include              <bits/stdc++.h>
#define ll            long long int
#define w(t)          int t; cin>>t; while(t--)
#define F             first
#define S             second
#define pb            push_back
#define mp            make_pair
#define pii           pair<int,int>
#define mii           map<int,int>
#define sp(x,y)       fixed<<setprecision(y)<<x
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c;
    cin>>a>>b>>c;
    if(a==b)cout<<c;
    else if(a==c)cout<<b;
    else if(b==c)cout<<a;
    else cout<<0;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
#define UNIQ(v) sort(ALL(v)); v.erase(unique(ALL(v)),end(v))
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl

struct UnionFind {
private:
    int N;
    vi parent;
    vi rank_;

    void init(int n) {
        N = n;
        parent.resize(0); parent.clear(); parent.resize(n);
        REP (i, N) parent[i] = i;
        rank_.resize(0); rank_.clear(); rank_.resize(n);
    }

public:
    UnionFind() { init(0); }
    UnionFind(int n) { init(n); }

    int root(int x) {
        return (parent[x] == x) ? x : parent[x] = root(parent[x]);
    }

    bool isSame(int x, int y) {
        return root(x) == root(y);
    }

    void merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;

        if (rank_[x] < rank_[y])
            parent[x] = y;
        else {
            parent[y] = x;
            if (rank_[x] == rank_[y]) rank_[x]++;
        }
    }
};

const int MAX = 111;

int N;
int X[MAX], Y[MAX];

bool check(ld r) {
    UnionFind uf(N+2);

    REP (i, N) REP (j, i) {
        ld dist = pow(pow(X[i]-X[j],2) + pow(Y[i]-Y[j],2), .5);
        if (dist < 2*r) uf.merge(i, j);
    }
    REP (i, N) {
        if (100 - Y[i] < 2*r) uf.merge(i, N);
        if (Y[i] + 100 < 2*r) uf.merge(i, N+1);
    }

    return !uf.isSame(N, N+1);
}

ld solve() {
    ld ok = 0, ng = 200;
    REP (i, 100) {
        ld m = (ok + ng) / 2;
        if (check(m)) ok = m;
        else ng = m;
    }
    return ok;
}

int main() {
    cout << fixed << setprecision(15);
    cin >> N;
    REP (i, N) cin >> X[i] >> Y[i];
    cout << solve() << endl;
}

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

using namespace std;

const int N = 200;

int a[N], b[N], c[N], d[N];

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


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

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

long long n,ans;
string s,t;
set<int> s1;
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
const int INF=1e9;
void f(int idx){
  if(idx==n-1)fin(-1);
  int p=*s1.upper_bound(idx);
  if(p==INF)fin(-1);
  ans+=p-idx;
  s[p]='0';
  s[idx]^=1;
  s1.erase(p);
}
/*
f(idx)はidxを変えたいからidxより大きくて最初の1に対して操作を行いたい訳で
0が続く場合はそこがガッと移動するから直近の1を移動させるイメージ
*/

int main(){
  cin>>n>>s>>t;
  REP(i,n)if(s[i]=='1')s1.insert(i);
  s1.insert(INF);
  REP(i,n-1)if(s[i]!=t[i])f(i);
  if(s!=t)fin(-1);
  cout<<ans<<endl;
}

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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;
    vector <int> vs, vt;
    rep(i, n) if (s[i] == '1') vs.pb(i);
    rep(i, n) if (t[i] == '1') vt.pb(i);
    if (vs.size() < vt.size() || (vs.size() - vt.size()) % 2 == 1) {
        printf("-1\n");
        return 0;
    }
    ll ans = 0;
    int j = 0;
    rep(i, vs.size()) {
        if (j < vt.size() && vs[i] >= vt[j]) {
            ans += vs[i] - vt[j];
            ++ j;
        } else {
            if (i + 1 == vs.size()) {
                printf("-1\n");
                return 0;
            }
            ans += vs[i + 1] - vs[i];
            ++ i;
        }
    }
    if (j < vt.size()) {
        printf("-1\n");
        return 0;
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define int long long int
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << "\n"
#define INF LLONG_MAX

template<typename ... T>
void print(const T& ... t)
{
  initializer_list<int>{ (std::cout << t << " ", 0)... };
  cout  << "\n";
}
template <typename T, size_t SIZE>
inline void zero(T(&arr)[SIZE])
{
    memset(arr, 0, SIZE * sizeof(T));
}

void readFile()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    time_t ttt ;
    struct tm *tmptmptmp ;
    char MY_TIME[50];
    time( &ttt );
    tmptmptmp = localtime( &ttt );
    strftime(MY_TIME, sizeof(MY_TIME), "%I:%M:%S %p", tmptmptmp);

    print("-----------");
    print(MY_TIME);
    print("-----------");
    #endif
}

void smallestLeftandRight(vector<int> &input, vector<int> &left, vector<int> &right)
{
    int sz = input.size();
    left.resize(sz);
    right.resize(sz);
    input.insert(input.begin(), 1, -INF);
    input.push_back(-INF);

    stack<int> s;
    stack<int> pos;
    int idx = -1;

    for(auto val : input)
    {
        if(pos.empty())
        {
            s.push(val);
            pos.push(idx);
            ++idx;
            continue;
        }

        while(!s.empty() and s.top() > val)
        {
            s.pop();
            if(pos.top() != -1)
            {
                right[pos.top()] = idx;
            }
            pos.pop();
        }

        if(s.top() == val)
        {
            if(pos.top() != -1)
            {
                left[idx] = left[pos.top()];
            }
        }

        else
        {
            left[idx] = pos.top();
        }
        s.push(val);
        pos.push(idx);

        ++idx;
    }

}

int maxAreaHistogram(vector<int> &input, vector<int> &left, vector<int> &right)
{
    //Note: We have manipulated the original input array;
    int maxArea = 0;
    for(int idx = 0; idx < left.size(); ++idx)
    {
        int area = input[idx+1] * (right[idx] - left[idx] - 1);
        maxArea = max(maxArea, area);
    }

    return maxArea;

}

int32_t main()
{
	readFile();
    int n; cin >> n;

    vector<int> test, left, right;

    for(int i = 0; i < n; ++i)
    {

        int temp;
        cin >> temp;
        test.push_back(temp);
    }

    smallestLeftandRight(test, left, right);

    cout << maxAreaHistogram(test, left, right) << endl;

}

#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>
#include <functional>
#include <cassert>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ld = long double;
using vld = vector<ld>;
using vb = vector<bool>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

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

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

template <class T> ostream& operator<<(ostream& s, const vector<T>& a) {
    for(auto i : a) s << i << ' ';
    return s;
}

constexpr ll INFL = 1LL << 60;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n;
    cin >> n;
    stack<pll> st;
    ll ans = 0;
    vll A(n+1);
    rep(i, n) cin >> A[i];
    rep(i, n+1) {
        ll a = A[i];
        if(st.empty()) st.emplace(a, i);
        else if(a > st.top().first) st.emplace(a, i);
        else if(a < st.top().first) {
            ll l = i;
            while(!st.empty() && a < st.top().first) {
                pll p = st.top();
                st.pop();
                chmax(ans, p.first * (i - p.second));
                l = p.second;
            }
            st.emplace(a, l);
        }
    }
    cout << ans << endl;
    return;
}

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


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define e(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define out(s) cout << s << endl
#define decimal10(s) cout << fixed << setprecision(10) << s << endl;
typedef long long ll;
using Graph = vector<vector<int>>;
const int MOD = 1000000007;
 int main(){
   float a, b;
   cin >> a >> b;
   float c = 100.0 - (b / a) * 100;
   decimal10(c);
 }

#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define ford(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pib pair<int,bool>
#define vi vector<int>
#define ll long long
#define vll vector<ll>
#define sz(s) (int)(s.size())
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vib vector<pib>
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
string i_t_s(int x){
	string t="";
	while(x){
		t+=x%10+'0';
		x/=10;
	}
	reverse(all(t));
	re t;
}
int s_t_i(string t){
	int x=0;
	rep(i,sz(t)){
		x=x*10+(t[i]-'0');
	}
	re x;
}
ll q_p(ll x,ll y){
	ll res=1;
	x%=mod;
	while(y){
		if(y%2){
			res=res*x;
			res%=mod;
		}
		y/=2;
		x=x*x;
		x%=mod;
	}
	re res;
}
vi v[100001];
int n;
int p;
pib ans(int x){
	ll now=0,s1=0,s2=0;
	vi e;
	bool f=1;
	rep(i,sz(v[x])){
		pib nn=ans(v[x][i]);
		if(nn.se){
			e.pb(nn.fr);
			 f^=1;
		}else{
			if(nn.fr>0)
			s1+=nn.fr;
			else
			s2+=nn.fr;
		}
	}
	sort(all(e));
	now++;
	now+=s2;
	rep(i,sz(e)){
		if(i%2){
			now-=e[i];
		}else
		now+=e[i];
	}
	if(sz(e)%2)
	now-=s1;
	else
	now+=s1;
	re m_p(now,f);
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	forn(i,1,n){
		cin>>p;
		p--;
		v[p].pb(i);
	}
	cout<<(ans(0).fr+n)/2;
	re 0;
}
/*
检查循环是rep(i,n)还是rep(i,m)!!
long long所要的时间比int长!!
没有long long必要不写long long!!
*/


/*
    I love the sound you make when you shut up.
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
/*----typedefs--------*/
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
using ll = long long;
using pi = pair<int, int>;
/*-----in and out--------*/
#define pf(a) cout << a << endl
#define forIn(arr, num) for(int i = 0; i < num; i++) cin >> arr[i];
#define vpnt(ans) for(int i = 0; i < int(ans.size()); i++) cout << ans[i] << (i + 1 < int(ans.size()) ? ' ' : '\n');
/*---useful defines------*/
#define sz(x) (int)(x).size()
#define pb push_back
#define mem(a, b) memset(a,(b), sizeof(a))
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
/*----- the binary answer of life-----*/
#define no cout << "NO" << endl
#define yes cout << "YES" << endl
/*---checking and pushing-----*/
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
/*---- FAST I/O and file read ---*/
void go() {
    ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#endif
}
/*-------- movement in a 2D array ------*/
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
/*--------test-case stuff---------------*/
#define ssolve solve();
#define msolve int t;cin >> t;while(t--) {solve();}
#define mcsolve int t;cin >> t;for(int tt = 1;tt <= t;tt++) {cout << "Case #" << tt << ": ";solve();}
/*----------------------------------------------------------------*/
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
/*-------------- Push your limits here ---------------------------*/
int n, m, k;
int cnt[N];
void add(int x)
{
	for(int i=x;i<=m;i+=(i&(-i))){
		++cnt[i];
	}
}
int ask(int x)
{
	int ret=0;
	for(int i=x;i>0;i-=(i&(-i))){
		ret+=cnt[i];
	}
	return ret;
}

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

    if(!k){
		cout<<1ll*n*m<<endl;
		return;
	}

	for(int i = 0;i < k;i++) {
		int x,y;
		cin>>x>>y;
		a[x]=min(a[x],y-1);
		b[y]=min(b[y],x-1);
	}

	ll ans=0;
	for(int i = 1;i <= b[1];i++) ans+=a[i];

    vector<int> pos(a[1]+1);
	for(int i = 1;i <= a[1];i++) pos[i]=i;

    sort(pos.begin()+1,pos.end(),[&](int x,int y){
		return b[x]<b[y];
	});

    for(int i = 1;i <= a[1];i++) {
		int r=pos[i],l=pos[i-1];
		for(int j=b[l]+1;j<=b[r]&&j<=b[1];j++){
			add(a[j]);
		}
		ans+=b[r]+ask(r-1)-ask(m);
	}

	pf(ans);
}

int main() {
    //go();
    ssolve
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct binary_indexed_tree{
	int N;
	vector<T> BIT;
	binary_indexed_tree(int n){
		N = 1;
		while (N < n){
			N *= 2;
		}
		BIT = vector<T>(N + 1, 0);
	}
	void add(int i, T x){
		i++;
		while (i <= N){
			BIT[i] += x;
			i += i & -i;
		}
	}
	T sum(int i){
		T ans = 0;
		while (i > 0){
			ans += BIT[i];
			i -= i & -i;
		}
		return ans;
	}
	T query(int L, int R){
		return sum(R) - sum(L);
	}
	T all(){
		return BIT[0];
	}
};
int main(){
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> X(M), Y(M);
  for (int i = 0; i < M; i++){
    cin >> Y[i] >> X[i];
    X[i]--;
    Y[i]--;
  }
  vector<int> right(H, W);
  for (int i = 0; i < M; i++){
    right[Y[i]] = min(right[Y[i]], X[i]);
  }
  vector<int> down(W, H);
  for (int i = 0; i < M; i++){
    down[X[i]] = min(down[X[i]], Y[i]);
  }
  binary_indexed_tree<long long> BIT(H);
  for (int i = 0; i < down[0]; i++){
    BIT.add(i, 1);
  }
  vector<vector<int>> s(W);
  for (int i = 0; i < down[0]; i++){
    if (right[i] != W){
      s[right[i]].push_back(i);
    }
  }
  long long ans = 0;
  for (int i = 0; i < down[0]; i++){
    ans += right[i];
  }
  for (int i = 0; i < right[0]; i++){
    for (int j : s[i]){
      BIT.add(j, -1);
    }
    ans += down[i] - BIT.sum(down[i]);
  }
  cout << ans << endl;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <cstring>
#include <bitset>
#include <array>

using namespace std;

typedef long long ll;
const int maxn=2e5+5, mod=998244353, maxp=305, Log=30;

inline int sum(int a, int b){
	if(a+b>=mod){
		return a+b-mod;
	}
	if(a+b<0){
		return a+b+mod;
	}
	return a+b;
}

inline int mul(int a, int b){
	return (ll)a*b%mod;
}

int pote(int a, int b){
	int sol=1;
	for(int i=0; i<Log; i++){
		if((1<<i)&b){
			sol=mul(sol, a);
		}
		a=mul(a, a);
	}
	return sol;
}

int inv;
int a[maxn];
int pot[maxn][maxp];
int sumb[maxn][maxp];
int sump[maxp];
int n;

void precompute(){
	int suma;
	for(int i=0; i<n; i++){
		pot[i][1]=a[i];
		sumb[i][0]=n-1;
		for(int j=2; j<maxp; j++){
			pot[i][j]=mul(pot[i][j-1], a[i]);
		}
	}
	sump[0]=n;
	for(int i=1; i<maxp; i++){
		suma=0;
		for(int j=0; j<n; j++){
			suma=sum(suma, pot[j][i]);
		}
		sump[i]=suma;
		for(int j=0; j<n; j++){
			suma=sum(suma, -pot[j][i]);
			sumb[j][i]=suma;
		}
	}
	inv=pote(2, mod-2);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int k;
	cin >> n >> k;
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	precompute();
	vector < int > pasc={1, 1};
	vector < int > vi;
	int sol;
	int pota, potb;
	int jed;
	for(int i=0; i<k; i++){
		sol=0;
		pota=i+1;
		potb=0;
		for(int j=0; j<(int)pasc.size()-1; j++){
			sol=sum(sol, mul(pasc[j], sum(mul(sump[pota], sump[potb]), -sump[i+1])));
			if(!j){
				jed=sol;
			}
			pota--;
			potb++;
		}
		sol=sum(sol, -jed);
		sol=mul(sol, inv);
		sol=sum(sol, jed);
		cout << sol << '\n';
		for(int j=0; j<(int)pasc.size(); j++){
			if(j){
				vi.push_back(sum(pasc[j], pasc[j-1]));
			}
			else{
				vi.push_back(pasc[j]);
			}
		}
		vi.push_back(pasc.back());
		pasc=vi;
		vi.clear();
	}
	return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>
#include <map>
using namespace std;
using ll = long long int;
using P = pair<int, int>;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for(auto &p: a) cin >> p;
    a.push_back(n+10);
    map<int, int> memo;
    vector<int> exist(n, 0);
    for(int i = 0; i <= n; i++) memo[i] = 1;
    int ans = 1001001001;
    for(int i = 0; i < m; i++){
        exist[a[i]] += 1;
    }
    for(int i = 0; i <= n; i++){
        if(exist[i] > 0){
            memo.erase(i);
        }
    }
    ans = memo.begin()->first;
    //cerr << ans << endl;
    for(int i = m; i < n; i++){
        exist[a[i]] += 1;
        memo.erase(a[i]);
        exist[a[i-m]] -= 1;
        if(exist[a[i-m]] == 0) memo[a[i-m]] = 1;
        ans = min(memo.begin()->first, ans);
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
#include <cassert>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); }
void Yes() { cout << "Yes" << endl; exit(0); }
void No() { cout << "No" << endl; exit(0); }

int N;
int S[200001];
char X[200001];

int memo[200010][10];

bool func(int depth, int a)
{
	if (depth == N)
	{
		return a % 7 == 0;
	}

	if (memo[depth][a] >= 1)
	{
		return memo[depth][a] == 1;
	}

	int a1 = a * 10;
	int a2 = a * 10 + S[depth];

	a1 %= 7;
	a2 %= 7;

	bool f1 = func(depth + 1, a1);
	bool f2 = func(depth + 1, a2);

	bool ans;
	if (X[depth] == 'T')
	{
		ans = f1 || f2;
	}
	else
	{
		ans = f1 && f2;
	}
	memo[depth][a] = ans ? 1 : 2;
	return ans;
}

signed main()
{
	cin >> N;
	string s;
	cin >> s;
	REP(i, N)
	{
		S[i] = s[i] - '0';
	}
	cin >> X;

	bool f = func(0, 0);
	cout << (f ? "Takahashi" : "Aoki") << endl;
}

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

using namespace std;
using LL = long long;
using P = pair<int,int>;
using vv = vector<vector<int>>;
const int INF = (int)1e9;
const LL LINF = (LL)1e18;

int main(){
	int N;
	string S, X;
	cin >> N >> S >> X;
	reverse(S.begin(), S.end());
	reverse(X.begin(), X.end());
	vv dp(N + 1);
	dp[0].emplace_back(0);
	rep(i,N){
		rep(j,7){
			int n = S[i] - '0';
			int k1 = (j * 10 + n) % 7, k2 = j * 10 % 7;
			auto itr1 = find(dp[i].begin(), dp[i].end(), k1);
			auto itr2 = find(dp[i].begin(), dp[i].end(), k2);
			if(X[i] == 'A'){
				if(itr1 != dp[i].end() and itr2 != dp[i].end()){
					dp[i+1].emplace_back(j);
				}
			}
			else{
				if(itr1 != dp[i].end() or itr2 != dp[i].end()){
					dp[i+1].emplace_back(j);
				}
			}
		}
	}
	rep(i,dp[N].size()){
		if(dp[N][i] == 0){
			cout << "Takahashi" << endl;
			return 0;
		}
	}
	cout << "Aoki" << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(ff, aa) for(auto ff : aa)
#define rep2(ff, aa) for(auto &ff : aa)
#define ALL(a)  (a).begin(),(a).end()
using pii = pair<int, int>;
using Graph = vector<vector<ll>>;

void daiku(const vector<ll> &kyori,const vector<vector<pii>> &gg,const ll ss,vector<ll> &dis){

ll nn=gg.size();
vector<ll> rr(nn,INF);
dis=rr;
priority_queue<pii,vector<pii>,greater<pii>> pq;
dis[ss]=0;
pq.emplace(dis[ss],ss);

while(!pq.empty()){
auto ww=pq.top();
pq.pop();
ll genzai=ww.second;
if(ww.first>dis[genzai]) continue;
for(auto &ee:gg[genzai]){
if(chmin(dis[ee.first],dis[genzai]+kyori[ee.second])){
pq.emplace(dis[ee.first],ee.first);
}
}

}

}

int main(){

ll nn,mm,start;
cin>>nn>>mm;

vector<vector<pii>> gg(nn);
vector<ll> kyori(mm);
vector<ll> ans(nn,INF);
vector<vector<pii>> wwee(nn);

ll ss,tt,dd;
rep(i,mm){
cin>>ss>>tt>>dd;
ss--;
tt--;
gg[ss].push_back({tt,i});
wwee[tt].push_back({ss,i});
kyori[i]=dd;
}

ll aaee=INF;
rep(i,nn){
aaee=INF;
daiku(kyori,gg,i,ans);
for(auto ee : wwee[i]){
chmin(aaee,(ans[ee.first]+kyori[ee.second]));
}
if(aaee>=INF){
cout<<-1<<endl;
}else{
cout<<aaee<<endl;
}
}

}

 /*
    Stay motivated and keep working hard
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define cntbit __builtin_popcount
#define fr first
#define mem(arr, val) memset(arr, val, sizeof(arr))
#define sc second
#define sz(v) ((int)(v).size())
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repd(i,a,p) for(int i=a-1;i>=p;i--)
#define md 998244353
#define vi vector<int>
#define vp vector<pair<int,int> >
#define ml map<int,int>
#define MPI 3.1415926536
#define in insert
#define endl "\n"
#define ub  upper_bound
#define lb  lower_bound
#define gcd __gcd
#define setval(a,b) memset(a,b,sizeof(a))
#define lwr lower_bound
#define pii pair<int,int>
#define upr upper_bound
#define ordered_set     tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//CANDIDATE MASTER TOH BNKE RHUNGA
//dsu is pel concept
//KMP is pel concept
int k,n,t,i,j=0,m;
const int N=2e3+5;
int md2;
inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}

inline int mul(int a, int b) {
  return (int) ((long long) a * b % md);
}

inline int power(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int a) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  if (u < 0) u += md;
  return u;
}
vp graph[N];
const int inf=1e9;
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		graph[a].pb({b,c});
	}
	for(int i=1;i<=n;i++)
	{
		priority_queue <pii,vp,greater<pii>> pq;
		pq.push({0,i});
		vector <int> dist(n+1,inf);
		while(pq.size())
		{
	    pii p=pq.top();
	    pq.pop();
	    for(auto it:graph[p.sc])
	    {
	    	if(dist[it.fr]>p.fr+it.sc)
	    	{
	    	dist[it.fr]=p.fr+it.sc;
			pq.push({dist[it.fr],it.fr});
			}
		}
		}
	    if(dist[i]==inf)
	    cout<<-1;
	    else
	    cout<<dist[i];
		cout<<endl;
	}
}


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

int main()
{
  string s;
  cin>>s;
  if(s[0]==s[1]&&s[1]==s[2])
  {
    cout<<"Won";
    return 0;
  }
  else
  {
    cout<<"Lost";
    return 0;
  }
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second
#define bug cout << "ok\n";
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long

const long double pi = 3.14159265358979323846264;
const long long maxn = 2e5 + 1, mod = 1e9 + 7, inf = 3e18;

void solve(){
	char c1, c2, c3;
	cin >> c1 >> c2 >> c3;
	if(c1 == c2 && c2 == c3)cout << "Won";
	else cout << "Lost";
}

main(){
    //file("");
    speed;
	int qq = 1;
	//cin >> qq;
while(qq--)solve();
    return 0;
}


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

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

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define ll long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define imn INT_MIN
#define imx INT_MAX

ld pi=3.14159265358979323846;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}

template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}

void _print() {cerr << "]\n";}

template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...) 20
#endif

ll mod=1e9+7;
vector<ll> seg,fac;
ll power(ll a,ll b,ll m)
{
    a%=m;
    if(b==1)
    return a;
    if(b==0)
    return 1LL;
    ll ret=power(a,b/2,m);
    ret=(ret*ret)%m;
    if(b&1)
    ret=(ret*a)%m;
    return ret;
}

ll power(ll a,ll b)
{
    if(b==1)
    return a;
    if(b==0)
    return 1LL;
    ll ret=power(a,b/2);
    ret=(ret*ret);
    if(b&1)
    ret=(ret*a);
    return ret;
}

ll lcm(ll a,ll b)
{
    return (a*b)/(__gcd(a,b));
}

ll phi(ll n) // Euler-Totient Function
{
    ll result = n;
    for(ll i=2;i*i<=n;i++)
    {
        if (n%i==0)
        {
            while (n%i==0)
            n/=i;
            result/=i;
            result*=(i-1);
        }
    }
    if (n > 1)
    {
        result/=n;
        result*=(n-1);
    }
    return result;
}

ll findpar(ll x,ll par[])
{
    while(x!=par[x])
    {
        x=par[x];
    }
    return x;
}

ll construct(ll a[],ll s,ll e,ll i)
{
    if(s==e)
    {
        seg[i]=a[s];
        return seg[i];
    }
    ll mid=s+(e-s)/2;
    seg[i]=construct(a,s,mid,2*i+1)^construct(a,mid+1,e,2*i+2);
    return seg[i];
}

void update(ll node,ll val,ll s,ll e,ll i)
{
    if(s==e)
    {
        seg[i]=val;
        return;
    }
    ll mid=s+(e-s)/2;
    if(node<=mid)
    {
        update(node,val,s,mid,2*i+1);
    }
    else
    {
        update(node,val,mid+1,e,2*i+2);
    }
    seg[i]=seg[2*i+1]^seg[2*i+2];
}

ll query(ll l,ll r,ll s,ll e,ll i)
{
    if(e<l || s>r)
    return 0;
    if(s>=l && e<=r)
    return seg[i];
    ll mid=s+(e-s)/2;
    return (query(l,r,s,mid,2*i+1)^query(l,r,mid+1,e,2*i+2));
}

void computeFac(ll mx)
{
    fac.resize(mx+10);
    fac[0]=1;
    for(ll i=1;i<mx+10;i++)
    {
        fac[i]=(fac[i-1]*i)%mod;
    }
}

ll ncr(ll a,ll b)
{
    if(a<b || b<0)
    return 0;
    ll x=(fac[a-b]*fac[b])%mod;
    return (fac[a]*power(x,mod-2,mod))%mod;
}

void answer_nikaal()
{
    string s;
    cin>>s;
    ll i=0;
    while(i<s.size() && s[i]!='.')
    cout<<s[i],i++;
}

int main()
{
    make_it_fast;
    int TEST_CASES=1;
    // cin>>TEST_CASES;
    while(TEST_CASES--)
    {
        answer_nikaal();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

int main()
{
	fast;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
    	if(s[i]!='.')
    	{
    		cout<<s[i];
		}
		else
		{
			break;
		}
	}
}


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

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

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

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

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    ll K, N, M;
    cin >> K >> N >> M;
    vl A(K);
    rep(i, K) cin >> A[i];

    ll ng = -1, ok = MOD * MOD;
    vl ansB;
    while(ok - ng > 1){
        ll mid = (ok + ng) / 2;

        ll dcnt = 0, ucnt = 0;
        rep(i, K){
            dcnt += max(0ll, (M * A[i] - mid + N - 1) / N);
            ucnt += (M * A[i] + mid) / N;
        }

        if(!(dcnt <= M and M <= ucnt)) {
            ng = mid;
            continue;
        }
        ok = mid;
        ll rest = M;
        vl B(K);
        rep(i, K) {
            B[i] = max(0ll, (M * A[i] - mid + N - 1) / N);
            rest -= B[i];
        }
        rep(i, K){
            ll d = (M * A[i] + mid) / N - B[i];
            chmin(d, rest);
            B[i] += d, rest -= d;
        }

        ansB = B;
    }

    repa(b, ansB) cout << b << " ";
    cout << endl;
    // err(ok);
}

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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()

typedef long long ll;

#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)

#define fi first
#define se second

const int N =1010;
vector<int> g[26][N];
int vis[N][N], nb[N][N];

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n, m; cin >> n >> m;
	fr(i,m){
		int a, b; char c; cin >> a >> b >> c;
		a--,b--;
		int ic=  c-'a';
		g[ic][a].push_back(b);
		g[ic][b].push_back(a);
		nb[a][b] = 1;
		nb[b][a] = 1;
	}
	fr(i,n) nb[i][i] = 1;

	int INF = INT_MAX/2;
	int ans = INF;
	queue<tuple<int,int,int>> q;
	q.emplace(0,0,n-1);
	vis[0][n-1] = 1;
	while(!q.empty()){
		int dac, a, b; tie(dac,a,b) = q.front(); q.pop();
		if(nb[a][b]){
			if(a==b) rmin(ans,dac);
			else rmin(ans,dac+1);
		}
		if(ans+2<dac) break;
		fr(ic,26){
			for(auto ann : g[ic][a]) for(auto bnn : g[ic][b]){
				int an = ann, bn = bnn;
				if(an>bn) swap(an,bn);
				if(vis[an][bn]) continue;
				q.emplace(dac+2,an,bn);
				vis[an][bn] = 1;
			}
		}
	}
	if(ans==INF) ans = -1;
	cout << ans << "\n";
}


#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class T, class S> inline T pow_L(T a, S b){
  T res = 1;
  res = 1;
  for(;;){
    if(b&1){
      res *= a;
    }
    b >>= 1;
    if(b==0){
      break;
    }
    a *= a;
  }
  return res;
}
inline double pow_L(double a, double b){
  return pow(a,b);
}
unsigned long long powmod(unsigned long long a, unsigned long long b, unsigned long long m){
  unsigned long long r = 1;
  while(b){
    if(b&1){
      r = r * a % m;
    }
    b>>=1;
    a = a * a % m;
  }
  return r;
}
int main(){
  long long A;
  rd(A);
  long long B;
  rd(B);
  long long C;
  rd(C);
  long long k;
  long long res;
  if(pow(B,C) > 10){
    k = powmod(B, C, 4) + 4;
  }
  else{
    k =(pow_L(B,C));
  }
  res = powmod(A, k, 10);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay version 20210103-1 [bug fixed 4]

// --- original code ---
// {
//   ll @A, @B, @C, k, res;
//   if(pow(B,C) > 10){
//     k = powmod(B, C, 4) + 4;
//   } else {
//     k = B ** C;
//   }
//   res = powmod(A, k, 10);
//   wt(res);
// }

#include<bits/stdc++.h>
//#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 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 ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
//using namespace __gnu_pbds;
vector<string> split(const string& s, char c) {
    vector<string> v; stringstream ss(s); string x;
    while (getline(ss, x, c)) v.push_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
    stringstream s; s << "[";
    for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
    s << arr[n - 1] << "]";
    return s.str();
}
#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
    cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
    __evars_out_var(a);
    cerr << "; ";
    __evars(++it, args...);
}
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()
{
    clock_t clk = clock();
    fast_az_fuk
    ll testcase; cin>>testcase;
    for(ll test=1;test<=testcase;test++)
    {//cout<<"Case #"<<test<<": ";
        ll n; cin>>n;
        if(n&1) cout<<"Odd\n";
        else if((n/2)&1) cout<<"Same\n";
        else cout<<"Even\n";
    }
    // cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v(1 << n);
    for (int i = 0; i < (1 << n); i++) cin >> v[i];
    array<int, 2> ar1 {-1, 0};
    for (int i = 0; i < (1 << (n - 1)); i++)
    {
        if (v[i] > ar1[0])
        {
            ar1[0] = v[i];
            ar1[1] = i + 1;
        }
    }
    array<int, 2> ar2 {-1, 0};
    for (int i = (1 << (n - 1)); i < (1 << n); i++)
    {
        if (v[i] > ar2[0])
        {
            ar2[0] = v[i];
            ar2[1] = i + 1;
        }
    }

    auto best = min(ar1, ar2);
    cout << best[1] << "\n";
}

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

/*
std::mt19937 mt{ std::random_device{}() };

std::uniform_int_distribution<int> dist(1, 6);
dist(mt);

while(1){
	val;
	cout << val << endl;
	sol1 = solver1();
	sol2 = solver2();
	if(sol1==sol2){
	cout << "OK" << endl;
	}else{
	cout << "NG" << endl;
	cout << sol1 << endl;
	cout << sol2 << endl;
	break;
	}
}
*/

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);
  ll n;
  cin >> n;
  cout << 100-n%100 << endl;
  return 0;
}


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

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

const int IM = 2e9;
int dat[400004];

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

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

	int N = getint();
	dat[0] = -IM;
	ll kotae = -IM * ll(N);
	for (int i = N + 1; i > 1; i--) {
		dat[i] = getint();
		kotae += dat[i];
	}

	for (int i = 2; i < N + 2; i++) {

		int p = 2 + (dat[2] > dat[3]);
		int v = dat[i] - IM;
		while (v > dat[p]) {
			dat[p >> 1] = dat[p];
			p <<= 1;
			p += dat[p] > dat[p + 1];
		}
		dat[p >> 1] = v;

		int a = getint();
		kotae += a;
		p = i;
		v = a - IM;
		while (v < dat[p >> 1]) dat[p] = dat[p >> 1], p >>= 1;
		dat[p] = v;

		kotae -= dat[1];
	}

	co(kotae);

	Would you please return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll =long long;
using vi = vector<ll>;
using vc = vector<char>;
using vs = vector<string>;
using P = pair<ll , ll>;
using vp = vector<P>;
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define rep2(i, s, n) for (int i = (s); i < n; i++)
#define sort(A) sort(A.begin(),A.end());
#define reverse(A) reverse(A.begin(),A.end());
#define vecint2(A, n, m) vector<vector<long long int>> A(n, vector<long long int>(m));
#define vecchar2(A, n, m) vector<vector<char>> A(n, vector<char>(m));
#define k(s) cout << fixed << setprecision(s);
#define t cout<<"OK"<<endl;
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
const long double pi=3.14159265358979323846;

int main() {
  int N;
  cin>>N;
  vector<string> S(N);
  rep(i,N) cin>>S[i];
  ll dpf[65],dpt[65];
  dpf[0]=1;dpt[0]=1;
  rep(i,N){
    if(S[i]=="AND"){
      dpt[i+1]=dpt[i];
      dpf[i+1]=2*dpf[i]+dpt[i];
    }else{
      dpt[i+1]=2*dpt[i]+dpf[i];
      dpf[i+1]=dpf[i];
    }
  }
  cout<<dpt[N]<<endl;
}


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

template <class _T> inline bool chmax (_T& a,_T b){if(a<b){a=b;return true;}return false;}
template <class _T> inline bool chmin (_T& a,_T b){if(a>b){a=b;return true;}return false;}
const int inf = 2147483647;
const long long INF = 1LL << 60;
const int MAX_N = 11000;
const int MAX_W = 10100;
ll mod = 1000000007;
ll MOD = 998244353;

int main(void){
    ll b,c;
    cin >> b >> c;
    ll ans = 0;
  	if(c==1 && b != 0){
    	cout << 2 << endl;
    	return 0;
    }
    if(b>0){
    //0 <= |b|の部分
	if( b-c/2 <= 0){
	    ans += 2*b+1;
	}else if( b-c/2 > 0 ){
	    if(c%2==0){
		ans += (c/2)*2+1;
	    }else{
		ans += (c/2)*2+2;
	    }
	}
    // |b|より大きい部分
	c--;
	if(c%2==0){
	    ans += (c/2)*2-1;
	}else{
	    ans += (c/2)*2;
	}
    }else if(b==0){
	ans++;
	if(c%2==0){
	    ans += (c/2)*2-1;
	}else{
	    ans += (c/2)*2;
	}
    }else{
    //0 < |b|の部分
	c--;
	if(-b-c/2 <= 0){
	    ans += 2*(-b)+1;
	}else if( -b-c/2 > 0){
	    if(c%2==0){
		ans += (c/2)*2+1;
	    }else{
		ans += (c/2)*2+2;
	    }
	}
        c++;
    // |b|より大きい部分
	if(c%2==0){
	    ans += (c/2)*2-1;
	}else{
	    ans += (c/2)*2;
	}
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
/// 500 485 462 A4
using namespace std;
typedef long long int ll;
typedef complex<double> point;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
const int N=2e5+100;
ll mod=998244353;
ll power(ll n,ll k){
    if (k==0) return 1;
    if (k%2==1){
        ll x=power(n,k/2);
        return x*x%mod*n%mod;
    }
    ll x=power(n,k/2);
    return x*x%mod;
}
ll fac[N];
ll fm[N];
ll ent(ll k,ll n){
    if (k==0 || k==n) return 1;
    if (k<0 || k>n) return 0;
    return fac[n]*fm[k]%mod*fm[n-k]%mod;
}
vector <int> p[N];
int32_t main(){
    sync;
    fac[0]=1;
    fm[0]=1;
    for (int i=1;i<N;i++){
        fac[i]=fac[i-1]*i%mod;
        fm[i]=power(fac[i],mod-2);
    }
    for (int i=2;i<N;i++){
        if (p[i].size()) continue;
        for (int j=i;j<N;j+=i){
            p[j].pb(i);
        }
    }
    ll ans=0;
    ll n,m;
    cin >> n >> m;
    for (int i=1;i<=m;i++){
        ll jav=1;
        for (auto u : p[i]){
            ll z=i,t=0;
            while(z%u==0){
                t++;
                z/=u;
            }
            jav*=ent(n-1,t-1+n);
            jav%=mod;
         //   cout << i << " " << u <<" " << t  << " " << jav<< endl;
        }
        ans+=jav;
    }
    cout << ans%mod << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define ll long long
#define ld long double
#define int ll
#define pb push_back
#define ii pair<int,int>
#define llll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<ii>
#define vllll vector<llll>
#define ff first
#define ss second
#define INF 1000000000
#define HINF 1000000000000000
#define mem(a,b) memset(a,b,sizeof(a))
#define arrin(x,n) int x[n]; for(int o=0;o<n;o++) cin>>x[o]
#define arrout(x,n) for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl
#define vecin(x,n); vi x;int hool; for(int o=0;o<n;o++) {cin>>hool; x.pb(hool);}
#define vecout(x,n) for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<'='<<x<<endl
#define deb2(x,y) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<endl
#define deb3(x,y,z) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<" "<<#z<<'='<<z<<endl
#define debarr(arr,n) for(int o=0;o<n;o++) deb2(o,arr[o])
#define debarrall(arr) debarr(arr,arr.size())
#define IO freopen("input.txt", "r", stdin); freopen("output.txt", "w+", stdout)
const double pi = 3.14159265358979323846;

int powersimple(int a, int b){//a^b
    int res=1;
    while(b>0){
        if(b&1)
		{res=(res*a);
		b--;}
        a=(a*a);
        b>>=1;
    }
    return res;
}

int ncr(int n,int k)
{
	int ans=1;
	if(k>n-k)
	k=n-k;
	for(int i=1;i<=k;i++)
	ans*=(n-i+1),ans/=i;
	return ans;
}

int power(int x,int y,int p)
{
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

int modInverse(int n, int p)
{
    return power(n, p - 2, p);
}

int ncrModPFermat(int n,int r, int p)
{

    if (r == 0)
		return 1;

    int fac[n + 1];
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % p;

    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}

//int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}

///////////////END OF TEMPLATE//////////////////

void solve()
{

	int i=0,j=0,k=0,m,n,p,sum=0,cnt=0;
	cin>>n;
	vi arr;
	for(i=0;i<n;i++)
	{
	    cin>>j;
	    k=__gcd(k,j);
	}
	cout<<k;

}
int32_t main() {
    fast
    //IO;
	//cout<<fixed<<setprecision(6);
    //test
    {

        solve();

    }
    return 0;
}

#include <bits/stdc++.h>

#include <iostream>
// #include <atcoder/all>
// using namespace atcoder;

using namespace std;
using ll = long long;

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

    map<int, int> a;
    int x = 1e9;
    int X = 0;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        a[tmp]++;
        if (tmp > X) X = tmp;
        if (tmp < x) x = tmp;
    }

    while (1) {
        if (x == X) break;
        a[X - x] = a[X];
        a.erase(X);
        X = a.rbegin()->first;
        x = a.begin()->first;
    }

    cout << x << endl;

    return 0;
}


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

int main(){
  int t;
  cin >> t;
  ll N;
  cin >> N;
  ll count=0;
  ll ans=0;

  vector<int> A(100);
  for(int i=0;i<100;i++){
    A[i]=0;
  }

  for(ll i=0;i<100;i++){
    if(i*t/100!=(i+1)*t/100){
      A[count]=i;
      count++;
    }
  }

  int last=0;

  for(int i=99;i>-1;i--){
    if(A[i]!=0){
      last=A[i];
      break;
    }
  }

  ll a=N/count;
  ll b=N%count;

  if(b==0){
    cout << ((a-1)*100+last)*(100+t)/100+1 << endl;
  }

  else{
 cout << (a*100+A[b-1])*(100+t)/100+1 << endl;
  }

}

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

int main()
{
int m=1000000007;
ll n; cin >> n;
vector<ll> a(n);
rep(i,n) cin >>  a[i];
vector<vector<ll>> f(n+2,vector<ll>(2));
f[0][0]=0; f[0][1]=1;
rep(i,n){
    f[i+1][0]=f[i][1]%m;
    f[i+1][1]=(f[i][0]+f[i][1])%m;
}
ll ans=0;
rep(i,n){
    ans=(ans%m)+(a[i]%m)*(((f[i][1]*f[n-i][1])%m)-((f[i][0]*f[n-i][0])%m))%m;
}
ans%=m;
if (ans < 0) ans += m;
cout << ans%m << endl;
}


#include<bits/stdc++.h>
#include<vector>
#include<math.h>
#include<algorithm>
#include<stack>
#include<list>
#include<queue>
#include<set>
#include<string>
#include<string.h>
#include<map>

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")

#define ll long long
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
using namespace std;

const int MOD = 1000000007;
const int Nmax=100005;

ll gcd(ll a,ll b)
{
    if(a==0){
        return b;
    }

    return gcd(b%a,a);
}

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

bool isPrime(ll n){
	for(int i = 2; i <=sqrt(n); i++)
		if(n % i == 0)
			return 0;
	return 1;
}

void binaryRepresentation(int x)
{
    for (int i = 31; i >= 0; i--)
    {
        if (x&(1<<i)) cout << "1";
        else cout << "0";
    }
}

int combination(int n,int r){
    if(r==n || r==0){
        return 1;
    }

    return combination(n-1,r-1) + combination(n-1,r);
}

bool isPowerOfTwo(ll n)
{
   if(n==0)
        return false;

   return (ceil(log2(n)) == floor(log2(n)));
}

ll power(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a);
		b/=2;
		a=(a*a);
	}
	return ans;
}

bool cmp(const pair<ll,ll> &a,const pair<ll,ll> &b)
{
    if(a.first==b.first)
        return a.second<b.second;
    return a.first<b.first;
}

int main()
{
    //vector<vector<int> >ar(n,vector<int> (m,0));
    //vector<int>::iterator ptr;

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

    ll n;
    cin>>n;
    vector<ll>ar(n);

    for(ll i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    sort(ar.begin(),ar.end());

    ll ans=0;

    for(ll i=0;i<n;i++)
        ans+=ar[i]*ar[i];
    ans*=(n-1);

    ll sum=0;
    for(ll i=n-1;i>=0;i--)
    {
        ans-=2*(ar[i]*sum);
        sum+=ar[i];
    }
    cout<<ans;

    return 0;
}

#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();++itr)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
#define incm(x,y) {x=((x)+(y))%mod;}
#define spln(i,n) (i==n?'\n':' ')
#define fac_init(n){fac[0]=fac[1]=inv[1]=fi[0]=fi[1]=1;fz(i,2,n){fac[i]=1ll*fac[i-1]*i%mod;inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;fi[i]=1ll*fi[i-1]*inv[i]%mod;}}
using namespace std;
inline void read(int &x)
{
	char c;int f=1;
	while(!isdigit(c=getchar()))if(c=='-')f=-1;
	x=(c&15);while(isdigit(c=getchar()))x=(x<<1)+(x<<3)+(c&15);
	x*=f;
}
int n,m,mod,i,j,k,l,f[2100005],g[2100005],ans[105];
int main()
{
	read(n);read(m);read(mod);
	int cc=2*n*n*m;
	f[cc/2]=m+1;
	fz1(i,n-1){
		fz0k(j,i){
			int s=0;
			for(k=cc/2/i*i+j;k<=cc;k+=i){
				inc(s,f[k])
				g[k]=s;
				if(k>=i*m) dec(s,f[k-i*m])
			}
		}
		fz(k,cc/2,cc) f[k]=g[k];
	}
	fz1(i,(n+1)/2){
		printf("%d\n",ans[i]=ans[n-i+1]=(f[cc/2]-1+mod)%mod);
		if(i==n){
			i++;break;
		}
		int x=n-i;
		fz0k(j,x){
			int s=0;
			for(k=j;k<=cc;k+=x){
				g[k]=(f[k]-s+mod)%mod;
				inc(s,g[k])
				if(k>=x*m) dec(s,g[k-x*m])
			}
		}
		fz0g(k,cc) f[k]=g[k];
		fz0k(j,i){
			int s=0;
			for(k=cc/i*i+j;k>=0;k-=i)if(k<=cc){
				inc(s,f[k])
				g[k]=s;
				if(k+i*m<=cc) dec(s,f[k+i*m])
			}
		}
		fz0g(k,cc) f[k]=g[k];
	}
	while(i<=n){
		printf("%d\n",ans[i++]);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const ll mod = 998244353;
const int M = 2e5+5;
ll a[M],cs[M],val[M],ncr[500][500],tot[500];
void pre()
{
	ncr[0][0]=1;
	for(int i=1;i<500;i++)
	{
		ncr[i][0] = 1;
		for(int j=1;j<=i;j++)
			ncr[i][j] = (ncr[i-1][j-1]+ncr[i-1][j])%mod;
	}
}
ll power(ll a,ll b)
{
	ll val = 1;
	while(b)
	{
		if(b%2)
			val = (val*a)%mod;
		a = (a*a)%mod;
		b/=2;
	}
	return val;
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	pre();
	int n,k;
	cin>>n>>k;
	ll sum = 0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		sum = (sum+a[i])%mod;
		val[i] = 1;
	}
	for(int j=1;j<=k;j++)
	{
		ll res = 0;
		for(int i=1;i<=n;i++)
		{
			val[i]=(val[i]*a[i])%mod;
			res = (res+val[i])%mod;
		}
		tot[j] = res;
	}
	tot[0] = n;
	for(int i=1;i<=k;i++)
	{
		ll ans = 0;
		ll c = 1;
		for(int j=0;j<=i;j++)
		{
			ll z = ncr[i][j];
			z = (z*tot[i-j])%mod;
			z = (z*tot[j])%mod;
			ans = (ans + z)%mod;
			if(j)
				c=(c*2)%mod;
		}
		ans = (ans-(c*tot[i])%mod+mod)%mod;
		ans = (ans*power(2,mod-2))%mod;
		cout<<ans<<"\n";
	}
	return 0;
}

// Author: wlzhouzhuan
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fir first
#define sec second
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, t) memset(s, t, sizeof(s))
#define mcpy(s, t) memcpy(s, t, sizeof(t))
template<typename T1, typename T2> void ckmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> void ckmax(T1 &a, T2 b) { if (a < b) a = b; }
int read() {
  int x = 0, f = 0; char ch = getchar();
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
  return f ? -x : x;
}
template<typename T> void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
template<typename T> void print(T x, char let) {
  print(x), putchar(let);
}

const int N = 1005;
const int mod = 998244353;

char a[N][N];
int pw[N * N];
int A[N], B[N], C[N];
int n, m;

int main() {
  scanf("%d%d", &n, &m);
  pw[0] = 1;
  for (int i = 1; i <= n * m; i++) {
    pw[i] = 2 * pw[i - 1] % mod;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%s", a[i] + 1);
    for (int j = 1; j <= m; j++) {
      int pos = i + j;
      if (a[i][j] == 'B') A[pos]++;
      if (a[i][j] == 'R') B[pos]++;
      if (a[i][j] == '.') C[pos]++;
    }
  }
  int ans = 1;
  for (int i = 2; i <= n + m; i++) {
    if (A[i] && B[i]) return puts("0") & 0;
    if (!A[i] && !B[i]) ans = 2ll * ans % mod;
  }
  printf("%d\n", ans);
  return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 2e5 + 5, INF = 0x3f3f3f3f;

int main(){

    ll n;
    cin >> n;
    int res = 0;
    for(int i = 1; i <= 1000000; i ++ ){
        int ans = 0, x = i;
        while(x){
            ans ++;
            x /= 10;
        }
        if(i * pow(10, ans) + i <= n)   res ++;
    }

    cout << res << endl;

    return 0;
}

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

#define int long long
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; }

string s;
int n;

int is_ok(int i, int c, int d){
	if(i == n){
		return (c == 0) ? d : INT_MAX;
	}

	return min(is_ok(i+1, (c+s[i]-'0')%3, d), is_ok(i+1, c, d+1));
}

signed main(){
	cin >> s;
	n = s.size();

	int ans = is_ok(0, 0, 0);

	if(ans >= n){
		ans = -1;
	}

	cout << ans << endl;

	return 0;
}


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

const int N = 1000 + 5, mod = 1e9 + 7;

int n, m, a[N], b[N], dp[N][N];

int solve(int idx_a, int idx_b){
    if(idx_a == n) return m - idx_b;
    if(idx_b == m) return n - idx_a;
    if(dp[idx_a][idx_b] != -1) return dp[idx_a][idx_b];
    int op1 = 1 + solve(idx_a + 1, idx_b);
    int op2 = 1 + solve(idx_a, idx_b + 1);
    int op3 = solve(idx_a + 1, idx_b + 1);
    if(a[idx_a] != b[idx_b]) op3++;
    return dp[idx_a][idx_b] = min({op1, op2, op3});
}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];
    memset(dp, -1, sizeof dp);
    cout << solve(0, 0);

    return 0;

}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fon(i,n) for(int i=0;i<n;i++)
#define fo(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll ,ll>
#define vii vector<int>
#define vll vector<ll>
#define vvll vector<vll>
#define vpii vector<pii>
#define vpll vector<pll>
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define M (1000*1000*1000+7)
#define test ll T; cin>>T; while(T--)
#define all(z) z.begin() , z.end()
#define allr(z) z.rbegin() , z.rend()
// =============================================
//1.integer overflow (1e5 * 1e5) (2e9 + 2e9) // 2.runtime error //3.boundary condition

int a[1002] , b[1002];
int dp[1002][1002];
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

   memset(dp , 0 , sizeof(dp));
   int n , m;
   cin >> n >> m;
//    int a[n] , b[n];

   fon(i ,n) cin >> a[i];
   fon(i , m)cin >> b[i];

   for(int i = 0 ; i <= n ; i++)
    for(int j = 0 ; j <= m ; j++)
        if(i==0 || j== 0)
         dp[i][j] = (i+j);

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

   cout << dp[n][m] << endl;

}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define eb emplace_back
using namespace std;
template <class T = int>
using V = vector<T>;
template <class T = int>
using VV = V<V<T>>;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<ld,ld>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    n *= 2;
    V<ll> a(n);
    rep(i,n) cin >> a[i];
    V<int> c(n);
    V<int> id(n);
    rep(i,n) id[i] = i;
    sort(all(id), [&](int i, int j){ return a[i] < a[j]; });
    rep(i,n/2){
        c[id[i]] = 0;
        c[id[i+n/2]] = 1;
    }
    string s = "";
    rep(i,n) s += ')';
    stack<int> st;
    rep(i,n){
        if(st.size()==0) st.push(i);
        else{
            if(c[st.top()] != c[i]){
                s[st.top()] = '(';
                s[i] = ')';
                st.pop();
            }
            else st.push(i);
        }
    }
    cout << s << endl;
}

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

#define PRINT_YesNo(condition) cout<<((condition)?"Yes":"No")<<endl
#define PRINT_YESNO(condition) cout<<((condition)?"YES":"NO")<<endl
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr)
#define SET_PRECISION(x) cout<< fixed << setprecision((x))
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;
typedef vector<int> vi_t;
typedef vector<vector<int> > vvi_t;
typedef vector<ll> vl_t;
typedef vector<vector<ll> > vvl_t;
typedef pair<int, int> pii_t;

vi_t str2numvec(const std::string& str);
vector<string> split(const string &str, char delim);

//=====================//
//  メ  イ  ン  関  数  //
//=====================//
int main()
{
    __MAGIC__;
    int N;
    cin >> N;
    std::vector<pair<long, int> > X(N);
    std::vector<pair<long, int> > Y(N);
    vl_t x(N);
    vl_t y(N);
    for(int i=0; i<N; ++i) {
        cin >> x[i] >> y[i];
        X[i].first = x[i];
        Y[i].first = y[i];
        X[i].second = i;
        Y[i].second = i;
    }
    std::sort(X.begin(), X.end());
    std::sort(Y.begin(), Y.end());

//    ll dx1 = std::abs(X[0].first - X[N-1].first);
//    ll dy1 = std::abs(Y[0].first - Y[N-1].first);
//    ll dx2 = std::max( std::abs(X[1].first - X[N-1].first), std::abs(X[0].first - X[N-2].first) );
//    ll dy2 = std::max( std::abs(Y[1].first - Y[N-1].first), std::abs(Y[0].first - Y[N-2].first) );

    set<pii_t> S;
    S.insert( std::make_pair(min(X[0].second,X[N-1].second), max(X[0].second,X[N-1].second)) );
    S.insert( std::make_pair(min(Y[0].second,Y[N-1].second), max(Y[0].second,Y[N-1].second)) );
    if( std::abs(X[1].first - X[N-1].first) > std::abs(X[0].first - X[N-2].first) ) {
        S.insert( std::make_pair(min(X[1].second,X[N-1].second), max(X[1].second,X[N-1].second)) );
    } else {
        S.insert( std::make_pair(min(X[0].second,X[N-2].second), max(X[0].second,X[N-2].second)) );
    }
    if( std::abs(Y[1].first - Y[N-1].first) > std::abs(Y[0].first - Y[N-2].first) ) {
        S.insert( std::make_pair(min(Y[1].second,Y[N-1].second), max(Y[1].second,Y[N-1].second)) );
    } else {
        S.insert( std::make_pair(min(Y[0].second,Y[N-2].second), max(Y[0].second,Y[N-2].second)) );
    }

    vl_t d;
    for(auto [m, M] : S) {
        d.push_back( std::max(std::abs(x[M]-x[m]), std::abs(y[M]-y[m])) );
    }
    std::sort(d.rbegin(), d.rend());
    cout << d[1] << endl;

    return 0;
}

//-----------------------------
// ヘルパー関数群
//-----------------------------
vi_t str2numvec(const std::string& str)
{
    vi_t v(str.size());
    for(int i=0, n=str.size(); i<n; ++i) {
        v[i] = str[i] - '0';
    }
    return v;
}

vector<string> split(const string &str, char delim){
  vector<string> res;
  size_t current = 0, found;
  while((found = str.find_first_of(delim, current)) != string::npos){
    res.push_back(string(str, current, found - current));
    current = found + 1;
  }
  res.push_back(string(str, current, str.size() - current));
  return res;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<complex>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
#define removeduplicates(vec) vec.erase( unique( vec.begin(), vec.end() ), vec.end() )
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
vector<int>res;
int a[N];
int n;
void rec(int l,int r,int ch){
	if(ch)
	for(int i=r-1;i>=l;i--){
		if(a[i]>a[i+1]){
			swap(a[i],a[i+1]);
			res.pb(i+1);
			rec(l,i,1);
			rec(i+1,r,0);
			return;
		}
	}
	else
	for(int i=l;i<r;i++){
		if(a[i]>a[i+1]){
			swap(a[i],a[i+1]);
			res.pb(i+1);
			rec(l,i,1);
			rec(i+1,r,0);
			return;
		}
	}
}
void solve(){
	cin>>n;
	rep(i,n)cin>>a[i];
	//int mk[n-1]={0};
	//int c=0;
	/*for(int i=0;i<n;i++){
		for(int j=0;j+1<n;j++){
			if(a[j]>a[j+1]){
				if(mk[j]){cout<<-1;return;}
				res.pb(j+1);
				mk[j]=1;
				swap(a[j],a[j+1]);
				c++;
			}
		}
		if(c==n-1)break;
	}*/
	rec(0,n-1,0);
	for(int i=0;i+1<n;i++)if(a[i]>a[i+1]){cout<<-1;return;}
	if(res.size()<n-1){cout<<-1;return;}
	for(int i:res)cout<<i<<"\n";
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define FORD(i, a, b) for (int i=(a); i>(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define HASK(S, x) (S.find(x) != S.end())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 19;

int P[maxN], R[maxN];
bool juz[maxN];
vector <int> res;

void click(int i)
{
	swap(P[i], P[i+1]);
	swap(R[P[i]], R[P[i+1]]);
	juz[i] = true;
	res.pb(i);
}

void fail()
{	printf("-1\n"); exit(0);	}

void solve()
{
	int n;
	scanf ("%d", &n);

	FOR(i, 1, n+1)
	{
		scanf ("%d", P+i);
		R[P[i]] = i;
	}

	FORD(i, n, 1)
	{
		if (R[i] == i and (!juz[i-1] or !juz[i]))	fail();
		while (R[i] != i)
		{
			if (juz[R[i]])	fail();
			click(R[i]);
		}
	}

	for (int i : res)
		printf("%d\n", i);
}

int main()
{
	int t = 1;
	//scanf ("%d", &t);
	FOR(tid, 1, t+1)
	{
		//printf("Case #%d: ", tid);
		solve();
	}
	return 0;
}


// International Master sm0016
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define raftaar ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const ll MOD1=1000000007;

const ll MOD2= 998244353;

const int N=1e6+6;

int main(){
	raftaar

	int a,b;cin>>a>>b;int ans=1;int check[N]={0};

	for(int i=a;i<=b;i++){

		for(int j=1;j*j<=i;j++){

			if(i%j==0){

				if(j*j==i) check[j]++;

				else{check[j]++;check[i/j]++;}
			}
		}
	}
	for(int i=1;i<=max(a,b);i++){

		if(check[i]>1) ans=max(ans,i);
	}

	cout<<ans;
}

#include <iostream>
using namespace std;

int main(){
    int a,b;cin>>a>>b;
    for(int c = b; ; c--) if((a + c - 1) / c < b / c){
        cout << c << endl;
        return 0;
    }
}


#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
//typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll MOD=INF;
const ll inf=INF*INF;
const ll mod=MOD;
const ll MAX=100010;

signed main(){
    string s;cin>>s;
    string a="",b="";
    rep(i,s.size()){
        if(s[i]=='R')swap(a,b);
        else{
            if(a.size()>0&&a[a.size()-1]==s[i])a.pop_back();
            else a+=s[i];
        }
    }
    ll n=a.size(),m=b.size();
    reverse(all(a));
    reverse(all(b));
    rep(i,min(n,m)){
        if(a[n-i-1]==b[m-i-1]){
            a.pop_back();
            b.pop_back();
        }else{
            break;
        }
    }
    reverse(all(a));
    cout<<b<<a<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
//#define int long long
#define rep(i,j,k) for(int i=j;i<k;i+=1)
#define rrep(i,j,k) for(int i=n-1;i>=0;i-=1)
#define sorti(v) sort(v.begin(),v.end())
#define sortd(v) sort(v.begin(),v.end(),greater<int>())
#define mm map<int,int>
#define vv vector<int>
#define tmm map<int,map<int,int>>
#define trav(a, x) for(auto& a : x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define pb push_back
#define alot(x,y) memset(x,y,sizeof(x))
#define pii pair<int,int>
#define code ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int MOD=1e9+7;
const double pi=acos(-1.0);
//memset(array_name,value_to_be_intialized,sizeof(array_name));
// __builtin_popcount(n) count no of set bit in number n
//next_permutation(s.begin(),s.end());
/*int change(string g){
     int p=10;
     int ans=g[g.length()-1]-'0';
     for(int i=g.length()-2;i>=0;i--){
         int j=g[i]-'0';
         ans=p*ans+j;
     }
     return ans;
}
int binpow(int a,int b){
    int res=1;
    while(b>0){
        if(b&1)res*=a;
        a*=a;
        b>>=1;

    }
    return res;
}
// lower_bound==> if the element is present it return its first occurence else 1st element which is greater than
// upper_bound==> it will always return iterator to element which is greater than searched element
*/
vector<pii>v[1000];
char c[2002][2002];
int dis[2002][2002];
bool vis[2002][2002];
bool g[2002];
int n,m;
bool check(int i,int j){
    if(i<n && i>=0 && j<m && j>=0)return true;
    return false;
}
int32_t main ()
{
     code;
    int tt;
    //cin>>tt;
    tt=1;
    while(tt--){
        int x,y;
        cin>>n>>m;
        int rx,ry;
        rep(i,0,n){
            rep(j,0,m){
                cin>>c[i][j];
                if(c[i][j]=='S'){
                    x=i;
                    y=j;
                }
                else if(c[i][j]=='G'){
                    rx=i;
                    ry=j;
                }
                else if(c[i][j]!='#' && c[i][j]!='.'){
                    v[c[i][j]-'a'].pb(make_pair(i,j));
                }
            }
        }
        queue<pii>q;
        q.push(make_pair(x,y));
        alot(vis,false);
        alot(g,false);
        while(!q.empty()){
            pii x=q.front();
            q.pop();
            int i=x.ff;
            int j=x.ss;
            vis[i][j]=true;
            if(check(i+1,j) && c[i+1][j]!='#' && !vis[i+1][j]){
                dis[i+1][j]=dis[i][j]+1;
                vis[i+1][j]=true;
                q.push(make_pair(i+1,j));
            }
            if(check(i-1,j) && c[i-1][j]!='#' && !vis[i-1][j]){
                dis[i-1][j]=dis[i][j]+1;
                vis[i-1][j]=true;
                q.push(make_pair(i-1,j));
            }
            if(check(i,j+1) && c[i][j+1]!='#' && !vis[i][j+1]){
                dis[i][j+1]=dis[i][j]+1;
                vis[i][j+1]=true;
                q.push(make_pair(i,j+1));
            }
            if(check(i,j-1) && c[i][j-1]!='#' && !vis[i][j-1]){
                dis[i][j-1]=dis[i][j]+1;
                vis[i][j-1]=true;
                q.push(make_pair(i,j-1));
            }
            if(c[i][j]>='a' && c[i][j]<='z' && !g[c[i][j]-'0']){
                g[c[i][j]-'0']=true;
                trav(k,v[c[i][j]-'a']){
                     if(!vis[k.ff][k.ss]){
                        dis[k.ff][k.ss]=dis[i][j]+1;
                        vis[k.ff][k.ss]=true;
                        q.push(make_pair(k.ff,k.ss));
                    }
                }
            }

        }
        if(dis[rx][ry]){
        cout<<dis[rx][ry]<<'\n';
        }
        else cout<<"-1\n";

    }
    return 0;

}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
const int INF = 5e6;

int di[4] = {1, 0, -1, 0};
int dj[4] = {0, 1, 0, -1};

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  // vector dist(h, vector(w, INF));
  vector<vector<int>> dist(h, vector<int>(w, INF));
  queue<P> q;
  rep(i,h)rep(j,w) {
    if (s[i][j] == 'S') {
      q.emplace(i,j);
      dist[i][j] = 0;
    }
  }
  vector<vector<P>> warps(256);
  rep(i,h)rep(j,w) warps[s[i][j]].emplace_back(i,j);

  while (!q.empty()) {
    auto [i,j] = q.front(); q.pop();
    if (s[i][j] == 'G') {
      cout << dist[i][j] << endl;
      return 0;
    }
    rep(v,4) {
      int ni = i + di[v], nj = j + dj[v];
      if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if (s[ni][nj] == '#') continue;
      if (dist[ni][nj] != INF) continue;
      dist[ni][nj] = dist[i][j] + 1;
      q.emplace(ni,nj);
    }

    if (islower(s[i][j])) {
      for (P p : warps[s[i][j]]) {
        int ni = p.first, nj = p.second;
        if (dist[ni][nj] != INF) continue;
        dist[ni][nj] = dist[i][j] + 1;
        q.emplace(ni,nj);
      }
      warps[s[i][j]] = vector<P>();
    }
  }
  cout << -1 << endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int N; cin >> N;
	long long A[400010] = {};
	long long sum = 0; long long mn = 0;
	for(int i = 0; i < N * 2; i++){
		cin >> A[i]; sum += A[i];
	}
	priority_queue<long long, vector<long long>, greater<long long>> que;
	for(int i = 0; i < N; i++){
		que.push(A[N-1-i]); que.push(A[N+i]);
		long long p = que.top(); mn += p; que.pop();
	}
	cout << sum - mn << "\n";
}

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  vector<lint> V1(N), V2(N);
  IREP(i, N) cin >> V1[i];
  REP(i, N) cin >> V2[i];
  multiset<lint> st;
  REP(i, N) {
    if(st.size() > 0 && *st.begin() < min(V1[i], V2[i])) {
      st.erase(st.begin());
      st.insert(V1[i]);
      st.insert(V2[i]);
    } else {
      st.insert(max(V1[i], V2[i]));
    }
  }
  lint ans = 0;
  for(lint x : st) ans += x;
  cout << ans << endl;
}


/*
{
######################
#       Author       #
#        Gary        #
#        2021        #
######################
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
//inline int read(){
//    int x=0;
//    char ch=getchar();
//    while(ch<'0'||ch>'9'){
//        ch=getchar();
//    }
//    while(ch>='0'&&ch<='9'){
//        x=(x<<1)+(x<<3)+(ch^48);
//        ch=getchar();
//    }
//    return x;
//}
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
const int MAXN=200000+233;
vector<int> g[MAXN];
int n;
mp fr;
int depth[MAXN],rest[MAXN],cnt;
void dfs(int now,int dis=0,int pre=0){
	check_max(fr,II(dis,now));
	for(auto it:g[now]) if(it!=pre){
		dfs(it,dis+1,now);
	}
}
void dfs2(int now,int pre=0){
	for(auto it:g[now]) if(it!=pre){
		depth[it]=depth[now]+1;
		dfs2(it,now);
	}
	for(auto it:g[now]) if(it!=pre){
		check_max(depth[now],depth[it]);
	}
}
bool cmp(int A,int B){
	return depth[A]<depth[B];
}
void dfs3(int now,int pre=0){
	rest[now]=++cnt;
	vector<int> ord;
	for(auto it:g[now]) if(it!=pre) ord.PB(it);
	sort(ALL(ord),cmp);
	for(auto it:ord) dfs3(it,now),++cnt;
}
int main(){
	scanf("%d",&n);
	rb(i,1,n-1){
		int u,v;
		scanf("%d%d",&u,&v);
		g[u].PB(v);
		g[v].PB(u);
	}
	fr=II(-1,-1);
	dfs(1);
	int tmp=fr.SEC;
	fr=II(-1,-1);
	dfs(tmp);
	int root=fr.SEC;
	dfs2(root);
	dfs3(root);
	rb(i,1,n) printf("%d ",rest[i]);
	return 0;
}

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

const int maxn=200005;
int n,ql,qr,lst,s,t;
vector<int>edge[maxn];
int dist[maxn],par[maxn],dep[maxn],que[maxn],ans[maxn];
bool bad[maxn];

void bfs(int s){
	for(int i=1;i<=n;i++)dist[i]=-1;
	dist[s]=0;
	ql=1;qr=0;
	que[++qr]=s;
	while(ql<=qr){
		int x=que[ql++];
		for(int i=0;i<int(edge[x].size());i++){
			int y=edge[x][i];
			if(dist[y]<0)dist[y]=dist[x]+1,par[y]=x,que[++qr]=y;
		}
	}
}

void dfs(int x,int p){
	lst=x;
	int yy=0;
	for(int i=0;i<int(edge[x].size());i++){
		int y=edge[x][i];
		if(y==p)continue;
		if(!bad[y])
			ans[y]=ans[lst]+dist[lst]+dist[y]-2*dist[x],dfs(y,x);
		else yy=y;
	}
	if(yy)
		ans[yy]=ans[lst]+dist[lst]+dist[yy]-2*dist[x],dfs(yy,x);
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n-1;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	bfs(1);
	for(int i=1;i<=n;i++)if(!s||dist[i]>dist[s])s=i;
	bfs(s);
	for(int i=1;i<=n;i++)if(!t||dist[i]>dist[t])t=i;
	while(t!=s)bad[t]=true,t=par[t];
	ans[s]=1;
	dfs(s,0);
	for(int i=1;i<=n;i++)printf("%d%c",ans[i],i==n?'\n':' ');
	return 0;
}


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

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define IN(x,c) (find(c.begin(),c.end(),x) != (c).end())
#define REP(i,n) for (int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define INIT(a,v) memset(a,v,sizeof(a))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
template<class A, class B> A cvt(B x) { stringstream ss; ss<<x; A y; ss>>y; return y; }

#define SPC << " " <<
#define DEBUG(x) cerr << #x << " = "; cerr << x << endl;
#define DEBUG_ITER(x) cerr << #x << " = "; for (auto _ : x) cerr << _ << ' '; cerr << endl;

typedef pair<int,int> PII;
typedef long long int64;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<double> VD;

int n;
int c[500][500];

int main() {
    //freopen("test.in","r",stdin);
    cin >> n;
    REP (i,n) REP (j,n) cin >> c[i][j];
    if (n==1) {
        cout << "Yes" << endl;
        cout << 0 << endl;
        cout << c[0][0] << endl;
        return 0;
    }
    int ok=1;
    vector<int> dx={0},dy={0};
    REP (i,n-1) {
        set<int> dif;
        REP (j,n) dif.insert(c[i+1][j]-c[i][j]);
        if (dif.size()!=1) { ok=0; break; }
        dy.PB(dy.back()+*dif.begin());
    }
    int m=*min_element(ALL(dy));
    for (int &x : dy) x-=m;
    REP (j,n-1) {
        set<int> dif;
        REP (i,n) dif.insert(c[i][j+1]-c[i][j]);
        if (dif.size()!=1) { ok=0; break; }
        dx.PB(dx.back()+*dif.begin());
    }
    m=*min_element(ALL(dx));
    for (int &x : dx) x-=m;
    int d=c[0][0]-(dy[0]+dx[0]);
    if (d<0) ok=0;
    else {
        for (int &x : dx) x+=d;
    }
    if (!ok) { cout << "No" << endl; return 0; }
    cout << "Yes" << endl;
    REP (i,n) {
        if (i!=0) cout << " ";
        cout << dy[i];
    }
    cout << endl;
    REP (i,n) {
        if (i!=0) cout << " ";
        cout << dx[i];
    }
    cout << endl;
    return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int score(vector<int> v){
  int res = 0;
  vector<int> cnt(10,0);
  rep(i,5){
    cnt[v[i]]++;
  }
  rep(i,10){
    if(i==0) continue;
    res += i*pow(10,cnt[i]);
  }
  //cerr << res << endl;
  return res;
}

int main(){
  int K; cin >> K;
  string S, T; cin >> S >> T;
  vector<int> cnt(10,K);
  cnt[0]=0;
  rep(i,4){
    cnt[S[i]-'0']--;
    cnt[T[i]-'0']--;
  }
  double ans = 0;
  for(int s=1;s<=9;s++){
    for(int t=1;t<=9;t++){
      vector<int> c=cnt;
      c[s]--;
      c[t]--;
      rep(i,10) if(c[i]<0)continue;
      double p;
      if(s==t){
        p = (double)cnt[s]*(cnt[s]-1)/(9*K-8)/(9*K-9);
      }
      else{
        p = (double)cnt[s]*cnt[t]/(9*K-8)/(9*K-9);
      }
      vector<int> ss, tt;
      rep(i,4){
        ss.pb(S[i]-'0');
        tt.pb(T[i]-'0');
      }
      ss.pb(s);
      tt.pb(t);
      if(score(ss)>score(tt)) ans+=p;
    }
  }
  cout << fixed << setprecision(20) << ans << endl;
  return 0;
}


#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <iomanip>
#include <cmath>
#include <set>
#include <unordered_set>
#include <functional>
#include <map>
#include <unordered_map>
#include <string>
#include <tuple>
using namespace std;
using ll = long long;

#define pi 3.14159265358979323846
#define ee 2.71828182845904523536
#define INF 1e18+1

long long gcd(long long x, long long y) { // 最大公約数
    if (y == 0)return x;
    else return gcd(y, x % y);
}

bool prime(int x) {
    for (int i = 2; i <= sqrt(x); i++) {
        if (x % i == 0)return false;
    }
    return true;
}

long long modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0)u += m;
    return u;
}

struct UnionFind {   // UnionFind
    vector<int> par;
    vector<int> siz;

    UnionFind(int N) : par(N), siz(N, 1) {
        for (int i = 0; i < N; i++) par[i] = i;
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (par[rx] > par[ry])swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    ll size(int x) {
        return siz[root(x)];
    }
};

int main() {
    ll n;
    cin >> n;
    ll cnt = 3;
    ll sum3 = 1;
    while (n > cnt) {
        if ((n - cnt) % 5 == 0) {
            ll cn5 = 5;
            ll sum5 = 1;
            while (n - cnt >= cn5) {
                if (n - cnt == cn5) {
                    cout << sum3 << " " << sum5 << endl;
                    return 0;
                }
                cn5 *= 5;
                sum5++;
            }
        }
        cnt *= 3;
        sum3++;
    }
    cout << -1 << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define endl "\n"
#define test ll t; cin>>t; while(t--)
typedef long long int ll;
vector<ll>as;
ll check(ll n){
    if(n<1){
        return -1;
    }
    for(int i=0;i<as.size();i++){
        if(as[i]==n){
            return i+1;
        }
    }
    return -1;
}
int main() {
    FIO;
    ll n,l=-1,r=-1,p,count=1;
    cin>>n;
    p=5ll;
    while(p<n){
        as.push_back(p);
        p*=5;
    }
    p=3ll;
    while(true){
        if(p<n && check(n-p)!=-1){
            l=count;
            r=check(n-p);
            break;
        }
        if(p*3<n){
            p*=3;
            count++;
        }
        else{
            break;
        }
    }
    if(l==-1) cout<<"-1"<<endl;
    else cout<<l<<" "<<r<<endl;
    //cout<<(l==-1?"-1\n":l<<" "<<r<<endl;)
	return 0;
}