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;
const int MAXN = 6e5 + 21, inf = 1e7 + 21;
int n, sz;
int A[MAXN], B[MAXN], C[MAXN], a[MAXN], b[MAXN], c[MAXN];
int dp[MAXN], cnt[MAXN];
int bw[MAXN << 2], lazy[MAXN << 2];
struct node {
  int ans, mn, mx;
  node(int a = 0, int b = 0, int c = 0) { mn = a, mx = b, ans = c; }
} seg[MAXN << 2];
inline node MRG(node a, node b) {
  return node(min(a.mn, b.mn), max(a.mx, b.mx), min(a.ans, b.ans));
}
inline void relax(int x, int id, int st) {
  seg[id] = node(lazy[id] = x, x, x <= n ? x + st : 3 * n);
}
inline void shift(int id, int st, int en) {
  if (!(~lazy[id])) return;
  int mid = (st + en) >> 1;
  relax(lazy[id], id << 1, st);
  relax(lazy[id], id << 1 | 1, mid);
  lazy[id] = -1;
}
void build(int id = 1, int st = 0, int en = n + 1) {
  lazy[id] = -1;
  if (en - st == 1) {
    seg[id] = node(dp[st], dp[st], dp[st] + st);
    return;
  }
  int mid = (st + en) >> 1;
  build(id << 1, st, mid);
  build(id << 1 | 1, mid, en);
  seg[id] = MRG(seg[id << 1], seg[id << 1 | 1]);
}
void update(int l, int r, int x, int id = 1, int st = 0, int en = n + 1) {
  if (r <= st || en <= l || seg[id].mn >= x) return;
  if (l <= st && en <= r && seg[id].mx < x) return relax(x, id, st);
  shift(id, st, en);
  int mid = (st + en) >> 1;
  update(l, r, x, id << 1, st, mid);
  update(l, r, x, id << 1 | 1, mid, en);
  seg[id] = MRG(seg[id << 1], seg[id << 1 | 1]);
}
inline void pre() {
  int cur = 0;
  sort(bw, bw + sz);
  sz = unique(bw, bw + sz) - bw;
  fill(A, A + sz, n + 1);
  fill(B, B + sz, n + 1);
  fill(C, C + sz, n + 1);
  for (int i = n; i; i--) {
    a[i] = lower_bound(bw, bw + sz, a[i]) - bw;
    b[i] = lower_bound(bw, bw + sz, b[i]) - bw;
    c[i] = lower_bound(bw, bw + sz, c[i]) - bw;
    A[a[i]] = i;
    B[b[i]] = i;
    C[c[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    cur += !cnt[a[i]]++;
    cur += !cnt[c[i]]++;
  }
  for (int i = 0, p = n; i <= n; i++) {
    cur += !cnt[b[i]]++;
    while (p && cnt[c[p]] > 1) cnt[c[p--]]--;
    if (cur < sz)
      dp[i] = 3 * n;
    else
      dp[i] = p;
  }
  build();
  return;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    bw[sz++] = a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    bw[sz++] = b[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    bw[sz++] = c[i];
  }
  pre();
  int ans = n + seg[1].ans;
  for (int i = n; i > 0; i--) {
    if (A[a[i]] == i) {
      update(0, B[a[i]], C[a[i]]);
    }
    ans = min(ans, i + seg[1].ans - 1);
  }
  cout << ans;
  return 0;
}