#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int did[202020];
vector<int> ret;

int main() {
    int n;
    cin>>n;
    vector<int> p(n),r(n);
    rep(i,n){
        cin>>p[i];
        p[i]--;
        r[p[i]]=i;
    }

    rep(i,n){
        int x=r[i];
        while(x>i){
            if(did[x-1]==1){
                cout<<-1<<endl;
                return 0;
            }
            did[x-1]=1;
            ret.push_back(x);
            swap(p[x-1],p[x]);
            r[p[x]]=x;
            r[p[x-1]]=x-1;
            x--;
        }
    }
    rep(i,n-1){
        if(did[i]==0){
            cout<<-1<<endl;
            return 0;
        }
    }

    for(auto e : ret) cout<<e<<endl;
}
#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second
#define INF 0x3f3f3f3f
#define N 28
using namespace std;


lint log5(lint n){
    lint ans = 0;
    while(n > 0){
        ans++;
        n/=5;
    }
    return ans;
}


int bb(const vector<lint> &pot5, lint val){
    if(val > pot5.back()) return -1;
    int l=0, r = (int) pot5.size() -1;
    while(l <= r){
        int m = (l+r)/2;
        if(pot5[m] == val) return m;
        if(pot5[m] < val) l = m + 1;
        else r = m-1;
    }
    return -1;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    lint n;
    cin>>n;
    vector<lint> pot5(N);
    pot5[0] = 1;
    for(int i=1; i<N; i++){
        pot5[i] = pot5[i-1] * 5LL;
        assert(pot5[i] > pot5[i-1]);
    }
    assert(pot5.back() > (lint) 1e18);
    

    lint pot = 1;
    int id = 0;
    while(pot <= n){

        int id5 = bb(pot5, n - pot);
        if(id > 0 && id5 > 0){
            cout<<id<<" "<<id5<<"\n";
            return 0;
        }
        pot *= 3LL;
        id++;

    }
    cout<<"-1\n";
    return 0;
}
