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 GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O2")
using namespace std;
const int N = 100000 + 10;
const long long MOD = 1000000000 + 7;
const long long INF = 1000000010;
const long long LOG = 25;
struct node {
  int ans, mn;
};
int n, a[3][N], b[N], c[N], koj[3][N], lazy[N << 2], adad[N];
node seg[N << 2];
void modify(int id, int x, int l) {
  seg[id].mn = x;
  seg[id].ans = l + x;
  lazy[id] = x;
}
void shift(int id, int l, int r) {
  if (lazy[id] == -1) return;
  int md = (l + r) >> 1;
  modify(id << 1, lazy[id], l);
  modify(id << 1 | 1, lazy[id], md);
  lazy[id] = -1;
}
void Set(int id, int lq, int rq, int x, int l, int r) {
  if (rq <= l || r <= lq) return;
  if (lq <= l && r <= rq) {
    modify(id, x, l);
    return;
  }
  int md = (l + r) >> 1;
  shift(id, l, r);
  Set(id << 1, lq, rq, x, l, md);
  Set(id << 1 | 1, lq, rq, x, md, r);
  seg[id].mn = min(seg[id << 1].mn, seg[id << 1 | 1].mn);
  seg[id].ans = min(seg[id << 1].ans, seg[id << 1 | 1].ans);
}
int get(int id, int x, int l, int r) {
  if (r - l == 1) return l;
  shift(id, l, r);
  int md = (l + r) >> 1;
  if (seg[id << 1].mn < x) return get(id << 1, x, l, md);
  return get(id << 1 | 1, x, md, r);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i < (N << 2); i++) lazy[i] = -1, seg[i].mn = seg[i].ans = INF;
  cin >> n;
  vector<int> num;
  for (int i = 0; i < 3; i++)
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
      num.push_back(a[i][j]);
    }
  sort(num.begin(), num.end());
  num.resize(unique(num.begin(), num.end()) - num.begin());
  for (int i = 0; i < 3; i++)
    for (int j = 1; j <= n; j++) {
      a[i][j] = lower_bound(num.begin(), num.end(), a[i][j]) - num.begin() + 1;
    }
  for (int i = 1; i <= 3 * n; i++) {
    for (int j = 0; j < 3; j++) koj[j][i] = INF;
  }
  for (int i = 0; i < 3; i++)
    for (int j = 1; j <= n; j++) {
      if (koj[i][a[i][j]] == INF) koj[i][a[i][j]] = j;
    }
  set<pair<int, int> > st;
  for (int i = 0; i < num.size(); i++) {
    st.insert({-koj[2][i + 1], i + 1});
  }
  for (int i = 1; i <= n; i++) st.erase({-koj[2][a[0][i]], a[0][i]});
  for (int i = 0; i <= n; i++) {
    if (st.size() == 0) {
      adad[i] = 0;
    } else {
      adad[i] = -(st.begin()->first);
      st.erase({-koj[2][a[1][i + 1]], a[1][i + 1]});
    }
  }
  for (int i = 0; i <= n; i++) Set(1, i, i + 1, adad[i], 0, n + 1);
  int ans = seg[1].ans + n;
  for (int i = n - 1; i >= 0; i--) {
    if (koj[0][a[0][i + 1]] == i + 1) {
      int x = koj[1][a[0][i + 1]];
      int y = koj[2][a[0][i + 1]];
      if (seg[1].mn >= y) {
        ans = min(ans, i + seg[1].ans);
        continue;
      }
      int koj = get(1, y, 0, n + 1);
      if (koj >= x) {
        ans = min(ans, i + seg[1].ans);
        continue;
      }
      Set(1, koj, x, y, 0, n + 1);
      ans = min(ans, i + seg[1].ans);
    }
    ans = min(ans, i + seg[1].ans);
  }
  cout << ans;
  return 0;
}