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>
#pragma comment(linker, "/STACK:1073741824")
using namespace std;
const int nmax = 100100;
pair<int, pair<int, int> > A[3 * nmax];
int a[nmax], b[nmax], c[nmax];
int all[3 * nmax];
int kAll;
bool used[3 * nmax];
bool leaf[4 * 3 * nmax];
int t[4 * 3 * nmax];
inline void push(int v, int tl, int tr) {
  if (tl != tr) {
    leaf[v] = false;
    int mid = (tl + tr) / 2;
    int add = t[v] - tl;
    t[2 * v] = add + tl;
    t[2 * v + 1] = add + mid + 1;
    leaf[2 * v] = leaf[2 * v + 1] = true;
  }
}
void build(int v, int tl, int tr) {
  leaf[v] = true;
  t[v] = tl;
}
void upd(int v, int tl, int tr, int l, int r, int val) {
  if (tl == l && tr == r) {
    leaf[v] = true;
    t[v] = val + tl;
    return;
  }
  if (leaf[v]) push(v, tl, tr);
  int mid = (tl + tr) / 2;
  if (r <= mid) {
    upd(2 * v, tl, mid, l, r, val);
  } else if (mid < l) {
    upd(2 * v + 1, mid + 1, tr, l, r, val);
  } else {
    upd(2 * v, tl, mid, l, mid, val);
    upd(2 * v + 1, mid + 1, tr, mid + 1, r, val);
  }
  t[v] = min(t[2 * v], t[2 * v + 1]);
}
int get(int v, int tl, int tr, int l, int r) {
  if (leaf[v]) {
    int add = t[v] - tl;
    return add + l;
  }
  if (tl == l && tr == r) {
    return t[v];
  }
  if (leaf[v]) push(v, tl, tr);
  int mid = (tl + tr) / 2;
  if (r <= mid) {
    return get(2 * v, tl, mid, l, r);
  } else if (mid < l) {
    return get(2 * v + 1, mid + 1, tr, l, r);
  } else {
    return min(get(2 * v, tl, mid, l, mid),
               get(2 * v + 1, mid + 1, tr, mid + 1, r));
  }
}
void upd(int r, int val, int n) {
  --r;
  if (r >= 1000000000 / 2) {
    r = n;
  }
  int L = -1;
  int R = n + 1;
  while (L + 1 < R) {
    int mid = (L + R) / 2;
    if (get(1, 0, n, mid, mid) - mid < val) {
      R = mid;
    } else {
      L = mid;
    }
  }
  int l = R;
  if (l <= r) {
    upd(1, 0, n, l, r, val);
  }
}
int get(int l, int r, int n) {
  int v = get(1, 0, n, l, r);
  return v;
}
int main() {
  int n, x;
  scanf("%d", &n);
  for (int(i) = 0; (i) < (n); ++(i)) {
    scanf("%d", &x);
    all[kAll++] = x;
    a[i] = x;
  }
  for (int(i) = 0; (i) < (n); ++(i)) {
    scanf("%d", &x);
    all[kAll++] = x;
    b[i] = x;
  }
  for (int(i) = 0; (i) < (n); ++(i)) {
    scanf("%d", &x);
    all[kAll++] = x;
    c[i] = x;
  }
  sort(all, all + 3 * n);
  int kAll = unique(all, all + 3 * n) - all;
  for (int(i) = 0; (i) < (n); ++(i))
    a[i] = lower_bound(all, all + kAll, a[i]) - all;
  for (int(i) = 0; (i) < (n); ++(i))
    b[i] = lower_bound(all, all + kAll, b[i]) - all;
  for (int(i) = 0; (i) < (n); ++(i))
    c[i] = lower_bound(all, all + kAll, c[i]) - all;
  for (int(i) = 0; (i) < (kAll); ++(i))
    A[i] = make_pair((1000000000), (make_pair((1000000000), (1000000000))));
  memset((used), 0, sizeof(used));
  for (int(i) = 0; (i) < (n); ++(i))
    if (!used[a[i]]) {
      A[a[i]].first = i + 1;
      used[a[i]] = true;
    }
  memset((used), 0, sizeof(used));
  for (int(i) = 0; (i) < (n); ++(i))
    if (!used[b[i]]) {
      A[b[i]].second.first = i + 1;
      used[b[i]] = true;
    }
  memset((used), 0, sizeof(used));
  for (int(i) = 0; (i) < (n); ++(i))
    if (!used[c[i]]) {
      A[c[i]].second.second = i + 1;
      used[c[i]] = true;
    }
  sort(A, A + kAll);
  build(1, 0, n);
  int last = -1;
  for (int(i) = (kAll); (i)--;)
    if (A[i].first == 1000000000) {
      int bp = A[i].second.first;
      int cp = A[i].second.second;
      upd(cp, bp, n);
    }
  int ans = get(0, n, n);
  for (int(i) = (kAll); (i)--;)
    if (A[i].first != 1000000000) {
      ans += A[i].first;
      break;
    }
  for (int(i) = (kAll); (i)--;)
    if (A[i].first != 1000000000) {
      int bp = A[i].second.first;
      int cp = A[i].second.second;
      upd(cp, bp, n);
      ans = min(ans, (i ? A[i - 1].first : 0) + get(0, n, n));
    }
  cout << ans << endl;
  return 0;
}