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;
multiset<int> st;
int mx[300010 * 4], cv[300010 * 4], n;
inline void Down(int x) {
  if (cv[x]) {
    mx[x * 2] = mx[x * 2 + 1] = cv[x];
    cv[x * 2] = cv[x * 2 + 1] = cv[x], cv[x] = 0;
  }
}
inline void Cov(int x, int l, int r, int a, int b, int c) {
  if (l == a && r == b) {
    mx[x] = cv[x] = c;
    return;
  }
  int md = (l + r) / 2;
  Down(x);
  if (b <= md) Cov(x * 2, l, md, a, b, c);
  if (md < a) Cov(x * 2 + 1, md + 1, r, a, b, c);
  if (a <= md && md < b)
    Cov(x * 2, l, md, a, md, c), Cov(x * 2 + 1, md + 1, r, md + 1, b, c);
  mx[x] = max(mx[x * 2], mx[x * 2 + 1]);
}
inline int Pre(int x, int l, int r, int a) {
  if (l == r) {
    if (mx[x] <= a) return (l);
    return (n + 1);
  }
  int md = (l + r) / 2;
  Down(x);
  if (mx[x * 2 + 1] > a) return (Pre(x * 2 + 1, md + 1, r, a));
  return (min(md + 1, Pre(x * 2, l, md, a)));
}
inline int Ask(int x, int l, int r, int a) {
  if (l == r) return (mx[x]);
  int md = (l + r) / 2;
  Down(x);
  if (a <= md)
    return (Ask(x * 2, l, md, a));
  else
    return (Ask(x * 2 + 1, md + 1, r, a));
}
pair<int, int> p[300010];
int m, ans;
inline void Chg(int x, int y) {
  int od = Ask(1, 1, n + 1, x), xx = x, odd = od, pr = x;
  if (od >= y) return;
  while (od < y) {
    pr = Pre(1, 1, n + 1, od);
    multiset<int>::iterator it = st.find(pr - 1 + od);
    st.erase(it);
    x = pr - 1;
    if (!x) break;
    od = Ask(1, 1, n + 1, x);
  }
  Cov(1, 1, n + 1, pr, xx, y);
  if (xx + 1 <= n + 1) st.insert(xx + odd);
  x = Pre(1, 1, n + 1, y);
  st.insert(x - 1 + y);
}
map<int, int> mp;
int va[300010], a[300010], b[300010], c[300010], u[300010], v[300010];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (int i = 1; i <= n; i++)
    if (!mp[a[i]]) u[++m] = a[i], mp[a[i]] = m, va[i] = 1;
  for (int i = 1; i <= n; i++)
    if (!mp[b[i]]) u[++m] = b[i], mp[b[i]] = m;
  for (int i = 1; i <= n; i++)
    if (!mp[c[i]]) u[++m] = c[i], mp[c[i]] = m;
  for (int i = 1; i <= n; i++)
    if (!p[mp[b[i]]].first) p[mp[b[i]]].first = i;
  for (int i = 1; i <= n; i++)
    if (!p[mp[c[i]]].second) p[mp[c[i]]].second = i;
  for (int i = 1; i <= n; i++) v[mp[a[i]]] = 1;
  st.insert(0);
  for (int i = 1; i <= m; i++)
    if (!v[i]) {
      if (!p[i].first) p[i].first = n + 1;
      if (!p[i].second) p[i].second = 1e9 + 1;
      Chg(p[i].first, p[i].second);
    }
  ans = n + (*st.begin());
  for (int i = n; i; i--) {
    if (va[i]) {
      int d = mp[a[i]];
      if (!p[d].first && !p[d].second) break;
      if (!p[d].first) p[d].first = n + 1;
      if (!p[d].second) p[d].second = 1e9 + 1;
      Chg(p[d].first, p[d].second);
      int nw = i - 1 + (*st.begin());
      ans = min(ans, nw);
    } else {
      int nw = i - 1 + (*(st.begin()));
      ans = min(ans, nw);
    }
  }
  printf("%d\n", ans);
}