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;
struct gt {
  int x, y;
  inline gt(int a = 0, int b = 0) {
    x = a;
    y = b;
  }
  inline bool operator<(const gt &a) const {
    if (a.x == x)
      return y < a.y;
    else
      return x < a.x;
  }
};
set<gt> S;
multiset<int> res;
int n, N;
int a[310000], b[310000], c[310000], fa[310000], fb[310000], fc[310000],
    q[310000];
struct po {
  int x, y, z;
} ans[310000];
inline int get(int x) { return lower_bound(q + 1, q + 1 + N, x) - q; }
inline bool cmp(const po &x, const po &y) { return x.x > y.x; }
int flag[310000];
inline void in(int x, int y) {
  if (x > n || y > n) return;
  flag[x + y]++;
  if (flag[x + y] == 1) res.insert(x + y);
}
inline void er(int x, int y) {
  if (x > n || y > n) return;
  flag[x + y]--;
  if (flag[x + y] == 0) res.erase(x + y);
}
inline void Add(set<gt>::iterator t1) {
  gt std = gt(0, 0);
  gt nxt, pre;
  if (t1 == S.begin())
    pre = std;
  else {
    pre = *(--t1);
    t1++;
  }
  if (++t1 == S.end())
    nxt = std;
  else
    nxt = *t1;
  t1--;
  er(pre.x, nxt.y);
  in(pre.x, (*t1).y);
  in((*t1).x, nxt.y);
}
inline void Del(set<gt>::iterator t1) {
  gt std = gt(0, 0);
  gt nxt, pre;
  if (t1 == S.begin())
    pre = std;
  else {
    pre = *(--t1);
    t1++;
  }
  if (++t1 == S.end())
    nxt = std;
  else
    nxt = *t1;
  t1--;
  in(pre.x, nxt.y);
  er(pre.x, (*t1).y);
  er((*t1).x, nxt.y);
  S.erase(t1);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    q[++q[0]] = a[i];
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    q[++q[0]] = b[i];
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &c[i]);
    q[++q[0]] = c[i];
  }
  sort(q + 1, q + 1 + q[0]);
  N = unique(q + 1, q + 1 + q[0]) - q - 1;
  for (int i = 1; i <= n; i++) {
    a[i] = get(a[i]);
    b[i] = get(b[i]);
    c[i] = get(c[i]);
  }
  memset(fa, 63, sizeof fa);
  memset(fb, 63, sizeof fb);
  memset(fc, 63, sizeof fc);
  for (int i = n; i >= 1; i--) fa[a[i]] = i;
  for (int i = n; i >= 1; i--) fb[b[i]] = i;
  for (int i = n; i >= 1; i--) fc[c[i]] = i;
  for (int i = 1; i <= N; i++) ans[i] = (po){fa[i], fb[i], fc[i]};
  sort(ans + 1, ans + 1 + N, cmp);
  int Res = 21333333;
  if (ans[1].x <= n) Res = ans[1].x;
  gt tmp;
  for (int i = 1; i <= N; i++) {
    tmp = gt(ans[i].y, ans[i].z);
    set<gt>::iterator t1 = S.upper_bound(tmp);
    if (t1 == S.end() || t1->y < tmp.y) {
      if (t1 != S.begin()) {
        --t1;
        while (t1->y <= tmp.y) {
          if (t1 == S.begin()) {
            Del(t1);
            break;
          }
          Del(t1--);
        }
      }
      S.insert(tmp);
      Add(S.lower_bound(tmp));
    }
    if (res.begin() != res.end()) Res = min(Res, (*res.begin()) + ans[i + 1].x);
  }
  printf("%d\n", Res);
  return 0;
}