Problem: We have N cards numbered 1, 2, ..., N. Card i (1 \leq i \leq N) has an integer A_i written in red ink on one side and an integer B_i written in blue ink on the other side. Initially, these cards are arranged from left to right in the order from Card 1 to Card N, with the red numbers facing up.

Determine whether it is possible to have a non-decreasing sequence facing up from left to right (that is, for each i (1 \leq i \leq N - 1), the integer facing up on the (i+1)-th card from the left is not less than the integer facing up on the i-th card from the left) by repeating the operation below. If the answer is yes, find the minimum number of operations required to achieve it.

* Choose an integer i (1 \leq i \leq N - 1). Swap the i-th and (i+1)-th cards from the left, then flip these two cards.

Constraints

* 1 \leq N \leq 18
* 1 \leq A_i, B_i \leq 50 (1 \leq i \leq N)
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N
A_1 A_2 ... A_N
B_1 B_2 ... B_N


Output

If it is impossible to have a non-decreasing sequence, print `-1`. If it is possible, print the minimum number of operations required to achieve it.

Examples

Input

3
3 4 3
3 2 3


Output

1


Input

2
2 1
1 2


Output

-1


Input

4
1 2 3 4
5 6 7 8


Output

0


Input

5
28 15 22 43 31
20 22 43 33 32


Output

-1


Input

5
4 46 6 38 43
33 15 18 27 37


Output

3

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y>a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[31][2];
int l[55][1000100];
int j[1];

long long x,y,z,mod=1000000007;
//string r;
char r[100333];

P u[100011];
queue<int> q;

//stack<int> s;
set<int> s;
map<long long,int> p;
vector<int> v,v1;

bool as(P a,P b)
{
  return a.y<b.y;
}

int f(int n,int m,int c)
{
  if(c>a) return 0;
  if(l[n][m]>=0) return l[n][m];
  int x=mod,e=0;
  for(int i=1,p=1;i<=a;p*=2,i++)
  if((m&p)==0&&o[i][(i-c+10000)%2]>=n)
  {
    //puts("#");
    x=min(x,e+f(o[i][(i-c+10000)%2],m+p,c+1));
    //printf("#%d %d %d %d\n",i,x,c,m);
    e++;
  }
  else if((m&p)==0) e++;
  return l[n][m]=x;
}

int main()
{
  memset(l,-1,sizeof(l));
  scanf("%d",&a);
  for(int i=0;i<2;i++)
  for(int t=1;t<=a;t++)
    scanf("%d",&o[t][i]);
  k=f(0,0,1);
  if(k<mod) printf("%d",k);
  else puts("-1");
}