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, A1[200005], A2[200005], A3[200005], tot, B[3 * 200005];
;
void _read(int &x) {
  x = 0;
  char ch = getchar();
  bool flag = false;
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = true;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  if (flag) x = -x;
  return;
}
struct data {
  int x, y, z;
} A[3 * 200005];
bool cmp1(data a, data b) { return a.z > b.z; }
int LAST[3 * 200005];
void Init() {
  _read(N);
  tot = 0;
  for (int i = 1; i <= N; i++) _read(A1[i]), B[++tot] = A1[i];
  for (int i = 1; i <= N; i++) _read(A2[i]), B[++tot] = A2[i];
  for (int i = 1; i <= N; i++) _read(A3[i]), B[++tot] = A3[i];
  sort(B + 1, B + 1 + tot);
  tot = unique(B + 1, B + 1 + tot) - B - 1;
  for (int i = 1; i <= N; i++) {
    A1[i] = lower_bound(B + 1, B + 1 + tot, A1[i]) - B;
    A2[i] = lower_bound(B + 1, B + 1 + tot, A2[i]) - B;
    A3[i] = lower_bound(B + 1, B + 1 + tot, A3[i]) - B;
  }
  for (int i = 1; i <= tot; i++) A[i].x = A[i].y = A[i].z = 3 * N + 1;
  for (int i = N; i >= 1; i--) {
    A[A1[i]].x = i;
    A[A2[i]].y = i;
    A[A3[i]].z = i;
  }
  sort(A + 1, A + 1 + tot, cmp1);
  return;
}
struct sta {
  int x, y;
} miny[200005 * 10], maxy[200005 * 10];
int chi_1[200005 * 20][2], np1, rt1;
void pushup_1(int now) {
  int lc = chi_1[now][0], rc = chi_1[now][1];
  miny[now] = (miny[lc].y < miny[rc].y) ? miny[lc] : miny[rc];
  maxy[now] = (maxy[lc].y > maxy[rc].y) ? maxy[lc] : maxy[rc];
  return;
}
void build_1(int &now, int L, int R) {
  now = ++np1;
  if (L == R) {
    miny[now] = (sta){L, 2000000001};
    maxy[now] = (sta){L, -2000000001};
    return;
  }
  int mid = (L + R) >> 1;
  build_1(chi_1[now][0], L, mid);
  build_1(chi_1[now][1], mid + 1, R);
  pushup_1(now);
  return;
}
void update_1(int now, int L, int R, int x, int y) {
  if (L == R) {
    if (y != -1)
      miny[now] = maxy[now] = (sta){x, y};
    else {
      miny[now] = (sta){x, 2000000001};
      maxy[now] = (sta){x, -2000000001};
    }
    return;
  }
  int mid = (L + R) >> 1;
  if (x <= mid)
    update_1(chi_1[now][0], L, mid, x, y);
  else
    update_1(chi_1[now][1], mid + 1, R, x, y);
  pushup_1(now);
  return;
}
sta Findmin(int now, int L, int R, int x, int y) {
  if (x <= L && R <= y) {
    return miny[now];
  }
  int mid = (L + R) >> 1;
  if (y <= mid)
    return Findmin(chi_1[now][0], L, mid, x, y);
  else if (x > mid)
    return Findmin(chi_1[now][1], mid + 1, R, x, y);
  else {
    sta t1 = Findmin(chi_1[now][0], L, mid, x, y),
        t2 = Findmin(chi_1[now][1], mid + 1, R, x, y);
    if (t1.y >= t2.y)
      return t2;
    else
      return t1;
  }
}
sta Findmax(int now, int L, int R, int x, int y) {
  if (x <= L && R <= y) {
    return maxy[now];
  }
  int mid = (L + R) >> 1;
  if (y <= mid)
    return Findmax(chi_1[now][0], L, mid, x, y);
  else if (x > mid)
    return Findmax(chi_1[now][1], mid + 1, R, x, y);
  else {
    sta t1 = Findmax(chi_1[now][0], L, mid, x, y),
        t2 = Findmax(chi_1[now][1], mid + 1, R, x, y);
    if (t1.y <= t2.y)
      return t2;
    else
      return t1;
  }
}
int np2, rt2, chi_2[200005 * 10][2], minsum[200005 * 10];
void build_2(int &now, int L, int R) {
  now = ++np2;
  if (L == R) {
    minsum[now] = 2000000001;
    return;
  }
  int mid = (L + R) >> 1;
  build_2(chi_2[now][0], L, mid);
  build_2(chi_2[now][1], mid + 1, R);
  minsum[now] = min(minsum[chi_2[now][0]], minsum[chi_2[now][1]]);
  return;
}
void update_2(int now, int L, int R, int x, int y) {
  if (L == R) {
    minsum[now] = x + y;
    return;
  }
  int mid = (L + R) >> 1;
  if (x <= mid)
    update_2(chi_2[now][0], L, mid, x, y);
  else
    update_2(chi_2[now][1], mid + 1, R, x, y);
  minsum[now] = min(minsum[chi_2[now][0]], minsum[chi_2[now][1]]);
  return;
}
void _ready() {
  np1 = np2 = 0;
  build_1(rt1, 0, 3 * N + 2);
  update_1(rt1, 0, 3 * N + 2, 0, 3 * N + 2);
  update_1(rt1, 0, 3 * N + 2, 3 * N + 2, 0);
  build_2(rt2, 0, 3 * N + 2);
  update_2(rt2, 0, 3 * N + 2, 0, 0);
  return;
}
void In(int x, int y) {
  sta tmp1, tmp2, tmp3;
  tmp1 = Findmax(rt1, 0, 3 * N + 2, x, 3 * N + 2);
  if (tmp1.y >= y) return;
  tmp1 = Findmin(rt1, 0, 3 * N + 2, 0, x);
  while (tmp1.y <= y && tmp1.y < 2000000001) {
    update_1(rt1, 0, 3 * N + 2, tmp1.x, -1);
    tmp2.y = 2000000001;
    tmp2 = Findmin(rt1, 0, 3 * N + 2, 0, tmp1.x - 1);
    update_2(rt2, 0, 3 * N + 2, tmp2.x, 2000000001);
    tmp3.y = -2000000001;
    tmp3 = Findmax(rt1, 0, 3 * N + 2, tmp1.x + 1, 3 * N + 2);
    update_2(rt2, 0, 3 * N + 2, tmp1.x, 2000000001);
    tmp1 = Findmin(rt1, 0, 3 * N + 2, 0, x);
  }
  tmp2 = Findmin(rt1, 0, 3 * N + 2, 0, x - 1);
  tmp3 = Findmax(rt1, 0, 3 * N + 2, x + 1, 3 * N + 2);
  update_2(rt2, 0, 3 * N + 2, tmp2.x, y);
  update_2(rt2, 0, 3 * N + 2, x, tmp3.y);
  update_1(rt1, 0, 3 * N + 2, x, y);
  return;
}
void work() {
  _ready();
  int ni = 1, ans = 3 * N;
  for (int i = N + 1; i >= 0; i--) {
    while (A[ni].z > i && ni <= tot) {
      In(A[ni].x, A[ni].y);
      ni++;
    }
    ans = min(ans, i + minsum[rt2]);
  }
  printf("%d\n", ans);
  return;
}
int main() {
  Init();
  work();
  return 0;
}