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, a[100010], b[100010], c[100010], m, d[100010 * 3];
int aa[100010 * 3], bb[100010 * 3], cc[100010 * 3], cnt[100010 * 3];
set<pair<int, int> > bst;
set<pair<int, int> >::iterator it, l, r;
multiset<int> heap;
void ins(pair<int, int> x) {
  r = bst.lower_bound(x);
  if (x.second <= r->second) return;
  bst.insert(x), it = bst.find(x), l = it, --l;
  heap.erase(heap.lower_bound(l->first + r->second)),
      heap.insert(it->first + r->second);
  while (l->second <= it->second)
    r = l--, heap.erase(heap.lower_bound(l->first + r->second)), bst.erase(r);
  heap.insert(l->first + it->second);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), d[++m] = a[i];
  for (int i = 1; i <= n; ++i) scanf("%d", &b[i]), d[++m] = b[i];
  for (int i = 1; i <= n; ++i) scanf("%d", &c[i]), d[++m] = c[i];
  sort(d + 1, d + m + 1);
  m = unique(d + 1, d + m + 1) - d - 1;
  for (int i = 1; i <= n; ++i) a[i] = lower_bound(d + 1, d + m + 1, a[i]) - d;
  for (int i = 1; i <= n; ++i) b[i] = lower_bound(d + 1, d + m + 1, b[i]) - d;
  for (int i = 1; i <= n; ++i) c[i] = lower_bound(d + 1, d + m + 1, c[i]) - d;
  for (int i = 1; i <= m; ++i) aa[i] = bb[i] = cc[i] = n * 3;
  for (int i = 1; i <= n; ++i) aa[a[i]] = min(aa[a[i]], i);
  for (int i = 1; i <= n; ++i) bb[b[i]] = min(bb[b[i]], i);
  for (int i = 1; i <= n; ++i) cc[c[i]] = min(cc[c[i]], i);
  bst.insert(make_pair(0, n * 4));
  bst.insert(make_pair(n * 4, 0));
  heap.insert(0);
  for (int i = 1; i <= n; ++i) ++cnt[a[i]];
  for (int i = 1; i <= m; ++i)
    if (!cnt[i]) ins(make_pair(bb[i], cc[i]));
  int ans = n + *heap.begin();
  for (int i = n; i; --i) {
    if (!--cnt[a[i]]) ins(make_pair(bb[a[i]], cc[a[i]]));
    ans = min(ans, i - 1 + *heap.begin());
  }
  printf("%d", ans);
}