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, ans;
int a[4][500005];
map<int, int> occ[4];
namespace staircase {
set<pair<int, int> > stairs;
multiset<int> results;
inline int get(void) { return *results.begin(); }
inline void add(pair<int, int> a) {
  set<pair<int, int> >::iterator l, i, r = stairs.lower_bound(a);
  if (r->second >= a.second) return;
  l = i = stairs.insert(a).first;
  l--;
  if (results.find(l->first + r->second) != results.end())
    results.erase(results.find(l->first + r->second));
  results.insert(i->first + r->second);
  while (l->second < i->second) {
    r = l--;
    results.erase(results.find(l->first + r->second));
    stairs.erase(r);
  }
  results.insert(l->first + i->second);
}
};  // namespace staircase
inline int fnd(int haystack, int needle) {
  return occ[haystack].count(needle) ? occ[haystack][needle] : 500005;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 3; i++)
    for (int j = 1; j <= n; j++) {
      scanf("%d", &a[i][j]);
      if (!occ[i].count(a[i][j])) occ[i][a[i][j]] = j;
    }
  staircase::results.insert(0);
  staircase::stairs.insert(make_pair(0, 500005));
  staircase::stairs.insert(make_pair(500005, 0));
  for (int i = 2; i <= 3; i++)
    for (int j = 1; j <= n; j++) {
      if (fnd(1, a[i][j]) == 500005)
        staircase::add(make_pair(fnd(2, a[i][j]), fnd(3, a[i][j])));
    }
  ans = 3 * n;
  ans = min(ans, n + staircase::get());
  for (int i = n; i >= 1; i--) {
    if (fnd(1, a[1][i]) == i)
      staircase::add(make_pair(fnd(2, a[1][i]), fnd(3, a[1][i])));
    ans = min(ans, i - 1 + staircase::get());
  }
  printf("%d\n", ans);
  return 0;
}