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;
void gn(int &x) {
  x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
}
int n, ans, a[100010], b[100010], c[100010], val[100010 * 3], vt;
int e[100010];
struct node {
  int u, v, w;
  node() {}
  node(int _u, int _v, int _w) {
    u = _u;
    v = _v;
    w = _w;
  }
  bool operator<(const node &b) const { return u > b.u; }
} d[100010 * 3];
int cov[100010 * 4], mvl[100010 * 4], mans[100010 * 4], mi[100010 * 4];
void cover(int p, int v) {
  cov[p] = v;
  mvl[p] = v;
  mans[p] = mi[p] + v;
}
void down(int p) {
  if (cov[p]) {
    cover((p << 1), cov[p]);
    cover((p << 1) | 1, cov[p]);
    cov[p] = 0;
  }
}
void up(int p) {
  mvl[p] = min(mvl[(p << 1)], mvl[(p << 1) | 1]);
  mans[p] = min(mans[(p << 1)], mans[(p << 1) | 1]);
}
int gpos(int p, int l, int r, int v) {
  if (l == r) return mvl[p] < v ? l : 0x3f3f3f3f;
  int mid = (l + r) >> 1;
  down(p);
  if (mvl[(p << 1)] < v) return gpos((p << 1), l, mid, v);
  return gpos((p << 1) | 1, mid + 1, r, v);
}
void modify(int p, int l, int r, int s, int t, int v) {
  if (l == s && r == t) {
    cover(p, v);
    return;
  }
  int mid = (l + r) >> 1;
  down(p);
  if (t <= mid) modify((p << 1), l, mid, s, t, v);
  if (s > mid) modify((p << 1) | 1, mid + 1, r, s, t, v);
  if (s <= mid && t > mid)
    modify((p << 1), l, mid, s, mid, v),
        modify((p << 1) | 1, mid + 1, r, mid + 1, t, v);
  up(p);
}
void build(int p, int l, int r) {
  mi[p] = mans[p] = l;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build((p << 1), l, mid);
  build((p << 1) | 1, mid + 1, r);
  up(p);
}
int main() {
  gn(n);
  for (int i = 1; i <= n; ++i) gn(a[i]), val[++vt] = a[i];
  for (int i = 1; i <= n; ++i) gn(b[i]), val[++vt] = b[i];
  for (int i = 1; i <= n; ++i) gn(c[i]), val[++vt] = c[i];
  sort(val + 1, val + vt + 1);
  vt = unique(val + 1, val + vt + 1) - val - 1;
  for (int i = 1; i <= vt; ++i) d[i] = node(n + 1, n + 1, 0x3f3f3f3f);
  int pos;
  for (int i = 1; i <= n; ++i) {
    pos = lower_bound(val + 1, val + vt + 1, a[i]) - val;
    d[pos].u = min(d[pos].u, i);
    pos = lower_bound(val + 1, val + vt + 1, b[i]) - val;
    d[pos].v = min(d[pos].v, i);
    pos = lower_bound(val + 1, val + vt + 1, c[i]) - val;
    d[pos].w = min(d[pos].w, i);
  }
  sort(d + 1, d + vt + 1);
  int t = 1;
  ans = 3 * n;
  build(1, 0, n);
  for (int U = n; U >= 0; --U) {
    while (t <= vt && d[t].u > U) {
      int pos = gpos(1, 0, n, d[t].w);
      if (pos <= d[t].v - 1) modify(1, 0, n, pos, d[t].v - 1, d[t].w);
      ++t;
    }
    ans = min(ans, mans[1] + U);
  }
  printf("%d\n", ans);
  return 0;
}