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;
int n, tot;
int a[100005], b[100005], c[100005], z[100005 * 3];
struct dian {
  int u, v, w;
} d[100005 * 3];
bool cmp(dian a, dian b) { return a.u > b.u; }
int mans[100005 * 4], mn[100005 * 4], flag[100005 * 4], mv[100005 * 4];
void update(int x) {
  mans[x] = min(mans[x * 2], mans[x * 2 + 1]);
  mv[x] = min(mv[x * 2], mv[x * 2 + 1]);
}
void build(int x, int l, int r) {
  mans[x] = mn[x] = l;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(x * 2, l, mid);
  build(x * 2 + 1, mid + 1, r);
  update(x);
}
void change(int x, int val) {
  mv[x] = val;
  flag[x] = val;
  mans[x] = mn[x] + val;
}
void down(int x) {
  if (flag[x]) {
    change(x * 2, flag[x]);
    change(x * 2 + 1, flag[x]);
    flag[x] = 0;
  }
}
int find(int x, int l, int r, int val) {
  if (l == r) {
    if (mv[x] < val)
      return l;
    else
      return 0x3f3f3f3f;
  }
  int mid = (l + r) / 2;
  down(x);
  if (mv[x * 2] < val)
    return find(x * 2, l, mid, val);
  else
    return find(x * 2 + 1, mid + 1, r, val);
}
void modify(int x, int l, int r, int tx, int ty, int val) {
  if (l >= tx && r <= ty) {
    change(x, val);
    return;
  }
  int mid = (l + r) / 2;
  down(x);
  if (mid >= tx) modify(x * 2, l, mid, tx, ty, val);
  if (mid < ty) modify(x * 2 + 1, mid + 1, r, tx, ty, val);
  update(x);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    z[++tot] = a[i];
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    z[++tot] = b[i];
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &c[i]);
    z[++tot] = c[i];
  }
  sort(z + 1, z + tot + 1);
  tot = unique(z + 1, z + tot + 1) - z - 1;
  for (int i = 1; i <= tot; i++) d[i] = (dian){n + 1, n + 1, 0x3f3f3f3f};
  for (int i = 1; i <= n; i++) {
    int pos = lower_bound(z + 1, z + tot + 1, a[i]) - z;
    d[pos].u = min(d[pos].u, i);
    pos = lower_bound(z + 1, z + tot + 1, b[i]) - z;
    d[pos].v = min(d[pos].v, i);
    pos = lower_bound(z + 1, z + tot + 1, c[i]) - z;
    d[pos].w = min(d[pos].w, i);
  }
  sort(d + 1, d + tot + 1, cmp);
  int t = 1;
  int ans = 3 * n;
  build(1, 0, n);
  for (int U = n; U >= 0; U--) {
    while (t <= tot && d[t].u > U) {
      int pos = find(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, U + mans[1]);
  }
  printf("%d\n", ans);
  return 0;
}