Problem: There are three arrays a, b and c. Each of them consists of n integers. SmallY wants to find three integers u, v, w (0 ≤ u, v, w ≤ n) such that the following condition holds: each number that appears in the union of a, b and c, appears either in the first u elements of a, or in the first v elements of b, or in the first w elements of c. Of course, SmallY doesn't want to have huge numbers u, v and w, so she wants sum u + v + w to be as small as possible.

Please, help her to find the minimal possible sum of u + v + w.

Input

The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an — array a. The third line contains the description of array b in the same format. The fourth line contains the description of array c in the same format. The following constraint holds: 1 ≤ ai, bi, ci ≤ 109.

Output

Print a single integer — the minimum possible sum of u + v + w.

Examples

Input

3
1 1 101
1 2 1
3 2 1


Output

5

Input

5
1 1 2 2 3
2 2 4 3 3
3 3 1 1 1


Output

5

Note

In the first example you should choose u = 3, v = 0, w = 2. 

In the second example you should choose u = 1, v = 3, w = 1.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool setmin(T &a, T b) {
  if (b < a) {
    a = b;
    return true;
  } else
    return false;
}
template <class T>
bool setmax(T &a, T b) {
  if (b > a) {
    a = b;
    return true;
  } else
    return false;
}
const int MAXN = 300010;
struct Tri {
  int i, j, k;
  bool operator<(const Tri &t) const { return k < t.k; }
} d[MAXN];
int n, endpos;
void init() {
  static int a[MAXN], b[MAXN], c[MAXN];
  cin >> n;
  for (int i = (int)(1); i <= (int)(n); ++i) cin >> a[i];
  for (int i = (int)(1); i <= (int)(n); ++i) cin >> b[i];
  for (int i = (int)(1); i <= (int)(n); ++i) cin >> c[i];
  map<int, int> pa, pb, pc;
  set<int> numbers;
  for (int i = (int)(n); i >= (int)(1); --i) numbers.insert(a[i]), pa[a[i]] = i;
  for (int i = (int)(n); i >= (int)(1); --i) numbers.insert(b[i]), pb[b[i]] = i;
  for (int i = (int)(n); i >= (int)(1); --i) numbers.insert(c[i]), pc[c[i]] = i;
  n = 0;
  int tt = endpos = MAXN * 3;
  for (set<int>::iterator it = numbers.begin(); it != numbers.end(); ++it) {
    int x = *it;
    ++n;
    if (pa.find(x) == pa.end())
      d[n].i = ++tt;
    else
      d[n].i = pa[x];
    if (pb.find(x) == pb.end())
      d[n].j = ++tt;
    else
      d[n].j = pb[x];
    if (pc.find(x) == pc.end())
      d[n].k = ++tt;
    else
      d[n].k = pc[x];
  }
}
struct Pair {
  int i, j;
  Pair(int i, int j) : i(i), j(j) {}
  bool operator<(const Pair &t) const { return i < t.i; }
};
set<Pair> seq;
multiset<int> ans;
void del(Pair p) {
  set<Pair>::iterator y = seq.lower_bound(p);
  set<Pair>::iterator x = y, z = y;
  --x, ++z;
  ans.erase(ans.find(x->i + y->j));
  ans.erase(ans.find(y->i + z->j));
  ans.insert(x->i + z->j);
  seq.erase(y);
}
void add(Pair p) {
  seq.insert(p);
  set<Pair>::iterator y = seq.lower_bound(p);
  set<Pair>::iterator x = y, z = y;
  --x, ++z;
  if (z->j > y->j) {
    seq.erase(p);
    return;
  }
  ans.insert(x->i + y->j);
  ans.insert(y->i + z->j);
  ans.erase(ans.find(x->i + z->j));
  while (1) {
    x = seq.lower_bound(p);
    --x;
    if (x->j < p.j) {
      del(*x);
    } else
      break;
  }
}
void solve() {
  sort(d + 1, d + n + 1);
  int ret = 1 << 30;
  seq.clear();
  seq.insert(Pair(0, 1 << 28));
  seq.insert(Pair(1 << 28, 0));
  ans.insert(0);
  int cur = n;
  while (cur >= 1 && d[cur].k >= endpos) {
    add(Pair(d[cur].i, d[cur].j));
    --cur;
  }
  while (cur >= 1) {
    ret = min(ret, *ans.begin() + d[cur].k);
    add(Pair(d[cur].i, d[cur].j));
    --cur;
  }
  ret = min(ret, *ans.begin());
  cout << ret << endl;
}
int main() {
  init();
  solve();
  return 0;
}