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 type;
struct bg {
  int l, k, id;
  friend bool operator<(const bg& a, const bg& b) {
    return a.k > b.k || a.k == b.k && a.l < b.l;
  }
};
set<bg> S;
priority_queue<pair<int, int> > Q;
int pos[3][110000 * 3], p[110000 * 3], a[110000], b[110000], c[110000], cnt,
    ans, tot, i, j, n;
bool flag[110000 * 24];
bg mk(int l, int k, int id) {
  bg res = {l, k, id};
  return res;
}
int Find(int x) { return lower_bound(p + 1, p + tot + 1, x) - p; }
void add(int x, int y) {
  set<bg>::iterator t = S.lower_bound(mk(-1, y, -1)), t1, t2;
  if (t == S.end() || x < t->l) return;
  int l = t->l, tmp;
  t1 = t;
  for (;;) {
    t2 = t1;
    t2++;
    if (t2 == S.end())
      tmp = 1e9;
    else
      tmp = (t2->l) - 1;
    if (x >= tmp) {
      flag[t1->id] = 1;
      S.erase(t1);
      t1 = t2;
    } else {
      flag[t1->id] = 1;
      bg res1 = {l, y, ++cnt}, res2 = {x + 1, t1->k, ++cnt};
      S.erase(t1);
      S.insert(res1);
      S.insert(res2);
      Q.push(make_pair(-res1.l - res1.k, res1.id));
      Q.push(make_pair(-res2.l - res2.k, res2.id));
      return;
    }
  }
}
void init() {
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) scanf("%d", &a[i]), p[++tot] = a[i];
  for (i = 1; i <= n; ++i) scanf("%d", &b[i]), p[++tot] = b[i];
  for (i = 1; i <= n; ++i) scanf("%d", &c[i]), p[++tot] = c[i];
  sort(p + 1, p + tot + 1);
  tot = unique(p + 1, p + tot + 1) - p - 1;
  for (i = 1; i <= n; ++i) {
    a[i] = Find(a[i]);
    b[i] = Find(b[i]);
    c[i] = Find(c[i]);
  }
  memset(pos, 3, sizeof(pos));
  for (i = n; i >= 1; --i) {
    pos[0][a[i]] = i;
    pos[1][b[i]] = i;
    pos[2][c[i]] = i;
  }
}
int main() {
  init();
  S.insert(mk(0, 0, ++cnt));
  Q.push(make_pair(0, cnt));
  for (i = 1; i <= tot; ++i)
    if (pos[0][i] > 1e6) add(pos[1][i] - 1, pos[2][i]);
  while (flag[Q.top().second]) Q.pop();
  ans = -Q.top().first + n;
  for (i = n; i >= 1; --i) {
    if (pos[0][a[i]] == i) {
      add(pos[1][a[i]] - 1, pos[2][a[i]]);
    }
    while (flag[Q.top().second]) Q.pop();
    ans = min(ans, i - 1 - Q.top().first);
  }
  printf("%d\n", ans);
}