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 N = 300005;
multiset<int> R;
set<pair<int, int> > S;
int n, a[N], b[N], c[N];
int A[N], B[N], C[N];
int w[N], id[N], ans;
bool cmp(int x, int y) { return A[x] > A[y]; }
void insert(pair<int, int> now) {
  set<pair<int, int> >::iterator i, j, k;
  k = S.lower_bound(now);
  if (k->second >= now.second) return;
  S.insert(now);
  i = S.find(now);
  j = i;
  j--;
  R.erase(R.find(j->first + k->second));
  R.insert(now.first + k->second);
  R.insert(j->first + now.second);
  for (; j->second <= now.second;) {
    i = j;
    j--;
    R.erase(R.find(j->first + i->second));
    R.erase(R.find(i->first + now.second));
    S.erase(i);
    R.insert(j->first + now.second);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%d", &a[i]), w[++*w] = a[i];
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%d", &b[i]), w[++*w] = b[i];
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%d", &c[i]), w[++*w] = c[i];
  sort(w + 1, w + *w + 1);
  *w = unique(w + 1, w + *w + 1) - w - 1;
  for (int i = (int)(1); i <= (int)(*w); i++)
    A[i] = B[i] = C[i] = 3 * n + 1, id[i] = i;
  for (int i = (int)(n); i >= (int)(1); i--)
    A[a[i] = lower_bound(w + 1, w + *w + 1, a[i]) - w] = i;
  for (int i = (int)(n); i >= (int)(1); i--)
    B[b[i] = lower_bound(w + 1, w + *w + 1, b[i]) - w] = i;
  for (int i = (int)(n); i >= (int)(1); i--)
    C[c[i] = lower_bound(w + 1, w + *w + 1, c[i]) - w] = i;
  sort(id + 1, id + *w + 1, cmp);
  S.insert(pair<int, int>(0, 3 * n + 2));
  S.insert(pair<int, int>(3 * n + 2, 0));
  R.insert(0);
  ans = A[id[1]];
  for (int i = 1; i <= *w; i++) {
    insert(pair<int, int>(B[id[i]], C[id[i]]));
    ans = min(ans, A[id[i + 1]] + *R.begin());
  }
  printf("%d", ans);
}