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 inf = 500000000;
const int N = 300100;
struct dui {
  int x, id;
} a[3 * N];
struct nd {
  int vl, id;
};
struct com {
  bool operator()(nd x, nd y) { return x.vl > y.vl; }
};
int b[N], c[N], d[N], e[N], f[N], q[N], to[N], g[N], t[N], n, top, ans;
set<nd, com> s;
set<nd, com>::iterator it;
multiset<int> se;
multiset<int>::iterator itt;
bool cmp(dui x, dui y) { return x.x < y.x; }
void ycl() {
  int i, j, k;
  memset(t, 0, sizeof(t));
  for (i = 1; i <= n; i++) {
    if (!t[b[i]]) e[i] = 1;
    t[b[i]]++;
  }
  memset(t, 0, sizeof(t));
  for (i = 1; i <= n; i++) {
    if (!t[c[i]]) f[c[i]] = i;
    t[c[i]]++;
  }
  memset(t, 0, sizeof(t));
  for (i = 1; i <= n; i++) {
    if (!t[d[i]]) g[d[i]] = i;
    t[d[i]]++;
  }
}
void in(int l, int r, int va, int ad) {
  int x, y;
  it = s.upper_bound((nd){va, 0});
  nd pos = *it;
  if (pos.id > r) return;
  x = pos.id;
  while (1) {
    it = s.upper_bound((nd){va, 0});
    pos = *it;
    if (pos.id > r)
      break;
    else {
      s.erase(pos);
      itt = se.find(pos.id + pos.vl);
      se.erase(itt);
    }
    y = pos.vl;
  }
  it = s.upper_bound((nd){va, 0});
  pos = *it;
  if (pos.id > r + 1) s.insert((nd){y, r + 1}), se.insert(y + r + 1);
  s.insert((nd){va, x});
  se.insert(x + va);
}
int main() {
  int i, j, k, ans, top, cnt, p, m, l, r, va;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i].x), a[i].id = i;
  for (i = 1; i <= n; i++) scanf("%d", &a[n + i].x), a[n + i].id = n + i;
  for (i = 1; i <= n; i++)
    scanf("%d", &a[n + n + i].x), a[n + n + i].id = n + n + i;
  sort(a + 1, a + 3 * n + 1, cmp);
  top = 0;
  for (i = 1; i <= 3 * n; i++) {
    if (a[i].x != a[i - 1].x) top++;
    if (a[i].id <= n)
      b[a[i].id] = top;
    else if (a[i].id <= 2 * n)
      c[a[i].id - n] = top;
    else
      d[a[i].id - n - n] = top;
  }
  for (i = 1; i <= n; i++) t[b[i]]++;
  for (i = 1; i <= n; i++) t[c[i]]++;
  cnt = 0;
  for (i = 1; i <= top; i++)
    if (!t[i]) cnt++;
  p = 0;
  while (cnt) {
    p++;
    t[d[p]]++;
    if (t[d[p]] == 1) cnt--;
  }
  to[n] = p;
  for (i = n; i; i--) {
    t[c[i]]--;
    if (!t[c[i]])
      while ((p < n) && (d[p] != c[i])) t[d[++p]]++;
    if ((p == n) && (d[p] != c[i])) break;
    to[i - 1] = p;
  }
  for (i--; i >= 0; i--) to[i] = inf;
  memset(t, 0, sizeof(t));
  for (i = 1; i <= n; i++) t[b[i]]++;
  for (i = 1; i <= n; i++) t[d[i]]++;
  cnt = 0;
  for (i = 1; i <= top; i++)
    if (!t[i]) cnt++;
  p = 0;
  while (cnt) {
    p++;
    t[c[p]]++;
    if (t[c[p]] == 1) cnt--;
  }
  q[n] = cnt;
  for (i = n; i; i--) {
    t[d[i]]--;
    if (!t[d[i]])
      while ((p < n) && (c[p] != d[i])) t[c[++p]]++;
    if ((p == n) && (c[p] != d[i])) break;
    q[i - 1] = p;
  }
  for (i--; i >= 0; i--) q[i] = inf;
  memset(t, 0, sizeof(t));
  ycl();
  ans = inf;
  memset(t, 0, sizeof(t));
  for (i = 1; i <= n; i++) t[c[i]]++;
  for (i = 1; i <= n; i++) t[d[i]]++;
  for (m = n; m >= 0; m--)
    if ((!t[b[m]]) && (e[m])) break;
  for (i = 0; i <= n; i++)
    if ((!i) || (to[i] != to[i - 1])) {
      s.insert((nd){to[i], i});
      se.insert(to[i] + i);
      ans = min(ans, n + to[i] + i);
    }
  s.insert((nd){-inf, n + 1});
  int la;
  for (i = n; ((i > m) && (i)); i--) {
    if (!f[b[i]])
      r = n;
    else
      r = f[b[i]] - 1;
    if (g[b[i]])
      l = q[g[b[i]] - 1], va = g[b[i]];
    else
      l = 0, va = inf;
    if (e[i]) in(0, r, va, i - 1);
    ans = min(ans, i - 1 + (*(se.begin())));
  }
  printf("%d\n", ans);
  return 0;
}