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

// #define NDEBUG
#include<cassert>

namespace Elaina{
    #define rep(i, l, r) for(int i=(l), i##_end_=(r); i<=i##_end_; ++i)
    #define drep(i, l, r) for(int i=(l), i##_end_=(r); i>=i##_end_; --i)
    #define fi first
    #define se second
    #define mp(a, b) make_pair(a, b)
    #define Endl putchar('\n')
    #define mmset(a, b) memset(a, b, sizeof a)
    typedef long long ll;
    typedef pair<int, int> pii;
    typedef pair<ll, ll> pll;
    template<class T>inline T fab(T x){ return x<0? -x: x; }
    template<class T>inline void getmin(T& x, const T rhs){ x=min(x, rhs); }
    template<class T>inline void getmax(T& x, const T rhs){ x=max(x, rhs); }
    template<class T>inline T readin(T x){
        x=0; int f=0; char c;
        while((c=getchar())<'0' || '9'<c) if(c=='-') f=1;
        for(x=(c^48); '0'<=(c=getchar()) && c<='9'; x=(x<<1)+(x<<3)+(c^48));
        return f? -x: x;
    }
    template<class T>inline void writc(T x, char s='\n'){
        static int fwri_sta[1005], fwri_ed=0;
        if(x<0) putchar('-'), x=-x;
        do fwri_sta[++fwri_ed]=x%10, x/=10; while(x);
        while(putchar(fwri_sta[fwri_ed--]^48), fwri_ed);
        putchar(s);
    }
}
using namespace Elaina;

ll n, N;

ll fib[100]; // fib[82]=99194853094755497

int cnt[100];

vector<pii>need;
vector<int>cmd;

signed main(){
    fib[0]=fib[1]=1;
    rep(i, 2, 82) fib[i]=fib[i-1]+fib[i-2];
    N=n=readin(1ll);
    drep(i, 82, 1) if(n>=fib[i]){
        cnt[i]=n/fib[i];
        n=n%fib[i];
    }
    int step=0;
    rep(i, 1, 82) if(cnt[i]){
        // printf("need (%d, %d)\n", i, cnt[i]);
        need.push_back(mp(i, cnt[i]));
        step=i;
    }
    ll x=0, y=0; int pre;
    if(need.back().fi%2==0){
        x=need.back().se, pre=3;
        while(need.back().se)
            cmd.push_back(1), --need.back().se;
    }
    else{
        y=need.back().se, pre=4;
        while(need.back().se)
            cmd.push_back(2), --need.back().se;
    }
    // printf("init :> x == %lld, y == %lld\n",  x, y);
    need.pop_back();
    rep(i, 1, step){
        if(pre==4) cmd.push_back(pre=3), x=x+y;
        else cmd.push_back(pre=4), y=x+y;
        if(step-i==need.back().fi){
            if(need.back().fi%2==0){
                x+=need.back().se;
                while(need.back().se)
                    cmd.push_back(1), --need.back().se;
            }
            else{
                y+=need.back().se;
                while(need.back().se)
                    cmd.push_back(2), --need.back().se;
            }
            need.pop_back();
        }
    }
    // printf("x == %lld, y == %lld\n",  x, y);
    writc((int)cmd.size());
    for(int i=0, siz=cmd.size(); i<siz; ++i)
        writc(cmd[i]);
    return 0;
}
#include <iostream>
#include <vector>
#include <algorithm>
#include <cinttypes>

static const int N = 200005;

int n;
static std::pair<int, int> a[N], b[N];
static int p[N];
static int f[N];

void add(int i, int d) {
	for (++i; i < N; i += i & -i) {
		f[i] += d;
	}
}

int get(int i) {
	int s = 0;
	for (; i > 0; i -= i & -i) {
		s += f[i];
	}
	return s;
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i].first);
		a[i].first += i;
		a[i].second = i;
	}
	for (int i = 0; i < n; ++i) {
		scanf("%d", &b[i].first);
		b[i].first += i;
		b[i].second = i;
	}
	std::sort(a, a + n);
	std::sort(b, b + n);
	for (int i = 0; i < n; ++i) {
		if (a[i].first != b[i].first) {
			printf("-1\n");
			return 0;
		}
		p[a[i].second] = b[i].second;
	}
	long long res = 0;
	for (int i = n - 1; i >= 0; --i) {
		res += get(p[i]);
		add(p[i], 1);
	}
	printf("%" PRId64 "\n", res);
}
