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 maxn = 300005;
struct pi {
  int lazy;
  int mi;
  int mm;
  int le, ri;
  int ma = 0;
} pp[maxn << 2];
void build(int tot, int l, int r) {
  pp[tot].le = l;
  pp[tot].ri = r;
  pp[tot].ma = 0;
  pp[tot].mm = 0;
  pp[tot].lazy = -1;
  if (l == r) {
    pp[tot].lazy = 0;
    pp[tot].mi = l;
    return;
  }
  int mid = (l + r) / 2;
  build(2 * tot, l, mid);
  build(2 * tot + 1, mid + 1, r);
  pp[tot].mi = min(pp[2 * tot].mi, pp[2 * tot + 1].mi);
}
void update(int tot) { pp[tot].mi = pp[tot].lazy + pp[tot].le; }
void merg(int tot, int l, int r, int p) {
  if (pp[tot].lazy >= p) return;
  if (pp[tot].mm >= p) return;
  if (l <= pp[tot].le && r >= pp[tot].ri) {
    if (pp[tot].ma <= p) {
      pp[tot].ma = p;
      pp[tot].lazy = p;
      pp[tot].mm = p;
      pp[tot].mi = p + pp[tot].le;
      return;
    } else {
      merg(2 * tot, l, r, p);
      merg(2 * tot + 1, l, r, p);
    }
  } else {
    if (pp[tot].lazy != -1) {
      pp[2 * tot].lazy = pp[tot].lazy;
      update(2 * tot);
      pp[2 * tot + 1].lazy = pp[tot].lazy;
      update(2 * tot + 1);
      pp[tot].lazy = -1;
    }
    int mid = (pp[tot].le + pp[tot].ri) / 2;
    if (l <= mid) merg(2 * tot, l, r, p);
    if (r > mid) merg(2 * tot + 1, l, r, p);
  }
  pp[tot].mi = min(pp[2 * tot].mi, pp[2 * tot + 1].mi);
  pp[tot].ma = max(pp[tot].ma, p);
  pp[tot].mm = min(pp[2 * tot].mm, pp[2 * tot + 1].mm);
}
int a[maxn], b[maxn], c[maxn], d[maxn];
int ne[3][maxn];
set<int> ss;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    d[i] = a[i];
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    d[n + i] = b[i];
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &c[i]);
    d[2 * n + i] = c[i];
  }
  sort(d + 1, d + 1 + 3 * n);
  for (int i = 1; i <= n; i++) {
    a[i] = lower_bound(d + 1, d + 3 * n + 1, a[i]) - d;
    ss.insert(a[i]);
  }
  for (int i = 1; i <= n; i++) {
    b[i] = lower_bound(d + 1, d + 3 * n + 1, b[i]) - d;
    ss.insert(b[i]);
  }
  for (int i = 1; i <= n; i++) {
    c[i] = lower_bound(d + 1, d + 3 * n + 1, c[i]) - d;
    ss.insert(c[i]);
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 1; j <= 3 * n; j++) ne[i][j] = 3 * n + 1;
  }
  for (int i = n; i >= 1; i--) ne[0][a[i]] = i;
  for (int i = n; i >= 1; i--) ne[1][b[i]] = i;
  for (int i = n; i >= 1; i--) ne[2][c[i]] = i;
  int ans = 3 * n;
  build(1, 0, 3 * n + 1);
  for (int i = 1; i <= 3 * n; i++) {
    if (ss.find(i) == ss.end()) continue;
    if (ne[0][i] > n) {
      merg(1, 0, ne[1][i] - 1, ne[2][i]);
    }
  }
  for (int i = n; i >= 1; i--) {
    ans = min(ans, i + pp[1].mi);
    if (ne[0][a[i]] == i) {
      merg(1, 0, ne[1][a[i]] - 1, ne[2][a[i]]);
    }
  }
  ans = min(ans, pp[1].mi);
  cout << ans << endl;
}