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.
1
2
3
2
 8
190409007 190409007 352375776 190409007 352375776 352375776 352375776 352375776
190409007 190409007 190409007 190409007 190409007 352375776 352375776 190409007
190409007 352375776 352375776 190409007 190409007 190409007 352375776 352375776
 1
1
1
1
 1
377489979
588153796
588153796
 2
1 1
2 2
3 3
 4
1 1 1 1
1 1 1 1
1 1 1 1
 2
1 2
2 2
1 1
 3
1 1 2
1 1 3
1 1 4

2
 2
 1
 2
 3
 1
 2
 9

#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
const int mo = 1000000007;
const int inf = (int)1e9;
inline int IN() {
  char ch;
  (ch = getchar());
  int f = 0, x = 0;
  for (; ((ch) == '\n' || (ch) == '\r' || (ch) == '\t' || (ch) == ' ');
       (ch = getchar()))
    ;
  if (ch == '-') f = 1, (ch = getchar());
  for (; !((ch) == '\n' || (ch) == '\r' || (ch) == '\t' || (ch) == ' ');
       (ch = getchar()))
    x = x * 10 + ch - '0';
  return (f) ? (-x) : (x);
}
int Pow(int x, int y, int p) {
  int A = 1;
  for (; y; y >>= 1, x = (long long)x * x % p)
    if (y & 1) A = (long long)A * x % p;
  return A;
}
int a[N], b[N], c[N], d[N], n, m, res, ztw;
struct node {
  int u, v, w;
  void reset() {
    if (!u) u = inf + ztw, ++ztw;
    if (!v) v = inf + ztw, ++ztw;
    if (!w) w = inf + ztw, ++ztw;
  }
} A[N];
struct po {
  double x, y;
  po operator+(const po &a) const { return (po){x + a.x, y + a.y}; }
  po operator-(const po &a) const { return (po){x - a.x, y - a.y}; }
  double operator*(const po &a) const { return x * a.y - y * a.x; }
  int operator<(const po &a) const { return x < a.x; }
};
set<po> st;
multiset<double> ans;
inline int cmp(const node &A, const node &B) { return A.u < B.u; }
double calc(po x, po y) { return x.x + y.y; }
void insert(int x, int y) {
  po tmp = (po){(double)x, (double)y};
  if (!st.size()) {
    st.insert(tmp);
    return;
  }
  auto u = st.lower_bound(tmp), v = u;
  if (u == st.begin() && u->y > tmp.y) return;
  if (u != st.begin()) {
    --v;
    if (u != st.end() && (tmp - *u) * (*v - *u) <= 0) return;
    if (u != st.end()) ans.erase(ans.find(calc(*v, *u)));
    while (v != st.begin()) {
      auto w = v;
      --w;
      if ((*v - tmp) * (*w - tmp) > 0) break;
      st.erase(v);
      ans.erase(ans.find(calc(*w, *v)));
      v = w;
    }
    if (v == st.begin()) {
      if (v->y < tmp.y) st.erase(v);
    }
  }
  u = st.lower_bound(tmp);
  while (1) {
    if (u == st.end()) break;
    auto w = u;
    ++w;
    if (w == st.end()) break;
    if ((*u - *w) * (tmp - *w) > 0) break;
    ans.erase(ans.find(calc(*u, *w)));
    st.erase(u);
    u = w;
  }
  u = st.lower_bound(tmp), v = u;
  if (u != st.begin()) --v, ans.insert(calc(*v, tmp));
  if (u != st.end()) ans.insert(calc(tmp, *u));
  st.insert(tmp);
}
int main() {
  scanf("%d", &n);
  for (int i = (int)1; i <= (int)n; i++) scanf("%d", a + i);
  for (int i = (int)1; i <= (int)n; i++) scanf("%d", b + i);
  for (int i = (int)1; i <= (int)n; i++) scanf("%d", c + i);
  for (int i = (int)1; i <= (int)n; i++) {
    d[++m] = a[i];
    d[++m] = b[i];
    d[++m] = c[i];
  }
  sort(d + 1, d + m + 1);
  m = unique(d + 1, d + m + 1) - (d + 1);
  for (int i = (int)1; i <= (int)n; i++) {
    a[i] = lower_bound(d + 1, d + m + 1, a[i]) - d;
    b[i] = lower_bound(d + 1, d + m + 1, b[i]) - d;
    c[i] = lower_bound(d + 1, d + m + 1, c[i]) - d;
  }
  for (int i = (int)1; i <= (int)n; i++) {
    if (!A[a[i]].u) A[a[i]].u = i;
    if (!A[b[i]].v) A[b[i]].v = i;
    if (!A[c[i]].w) A[c[i]].w = i;
  }
  for (int i = (int)1; i <= (int)m; i++) A[i].reset();
  sort(A + 1, A + m + 1, cmp);
  int res = 3 * n;
  for (int i = (int)m; i >= (int)0; i--) {
    double u = *(ans.begin());
    if (!ans.size()) u = inf;
    if (st.size()) {
      u = min(u, st.begin()->y);
      u = min(u, st.rbegin()->x);
    }
    res = min(res, A[i].u + (int)u);
    insert(A[i].v, A[i].w);
  }
  cout << res << endl;
  return 0;
}
