import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;
import core.bitop;

/// [..), 1-origin
struct BITree(alias _fun, alias init, T)
if (is(typeof(init) : T))
{
    import std.functional : binaryFun;
    alias fun = binaryFun!_fun;

    ///
    this(size_t n, T[] ts) {
        this.n = n;
        this.tree.length = n+1;
        foreach (ref e; this.tree) e = init;
        foreach (i, t; ts) this.put(i+1, t);
    }

    /// This method does not replace the element but applies old one and new one to the `fun`.
    void put(size_t i, T e) {
        while (i <= this.n) {
            this.tree[i] = fun(this.tree[i], e);
            i += i & -i;
        }
    }

    ///
    T query(size_t i) {
        auto r = init;
        while (i > 0) {
            r = fun(r, this.tree[i]);
            i -= i & -i;
        }
        return r;
    }

private:
    size_t n;
    T[] tree;
}

/// The `init` value is used for the `query` method as first value,
/// so you can not use this argument to initialise the tree.
/// In other words, this is identity element.
BITree!(fun, init, T) bitree(alias fun, alias init, T)(size_t n, T[] ts = [])
{
    return BITree!(fun, init, T)(n, ts);
}

///
BITree!(fun, init, T) bitree(alias fun, alias init, T)(T[] ts)
{
    return BITree!(fun, init, T)(ts.length, ts);
}

alias Card = Tuple!(int, "i", int, "n", bool, "is_red");

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = readln.split.to!(int[]);
    auto BS = readln.split.to!(int[]);

    int res = -1;
    foreach (uint s; 0..2^^N) if (popcnt(s)%2 == 0) {

        Card[] cs;
        foreach (i; 0..N) {
            if ((1<<i) & s) {
                cs ~= Card(i, BS[i], true);
            } else {
                cs ~= Card(i, AS[i], false);
            }
        }
        sort!"a.n < b.n"(cs);

        bool is_diff(int i) {
            if (cs[i].is_red) {
                return i%2 == cs[i].i%2;
            } else {
                return i%2 != cs[i].i%2;
            }
        }

        foreach (i; 0..N) {
            auto j = i+1;
            while (j < N && is_diff(i) && cs[i].n == cs[j].n) {
                if (is_diff(j)) {
                    swap(cs[i], cs[j]);
                } else {
                    j += 2;
                }
            }

            if (is_diff(i)) goto ng;
        }

        {
            if (res == -1) res = int.max;
            auto bit = bitree!("a + b", 0, int)(N+1);
            int rr;
            foreach (j, c; cs) {
                bit.put(c.i+1, 1);
                rr += (j+1) - bit.query((c.i+1).to!size_t);
            }
            res = min(res, rr);
        }
        ng:
    }

    writeln(res);
}