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 INF = 1000000000;
int n;
set<pair<int, int> > wyk;
multiset<int> M;
void Dodaj(int x, int wys) {
  set<pair<int, int> >::iterator it = wyk.lower_bound(make_pair(x, -1));
  int ost;
  if (it == wyk.end())
    ost = 2 * n - 1;
  else {
    if (it->first > x)
      ost = it->first - 1;
    else {
      if (++it == wyk.end())
        ost = 2 * n - 1;
      else
        ost = it->first - 1;
      --it;
    }
  }
  if (it == wyk.end() || it->first > x) --it;
  if (wys <= it->second) return;
  vector<pair<int, int> > usu;
  while (it->second <= wys) {
    usu.push_back(*it);
    if (it == wyk.begin()) break;
    --it;
  }
  for (int i = 0; i < usu.size(); ++i) {
    wyk.erase(usu[i]);
    M.erase(M.find(usu[i].first + usu[i].second));
  }
  wyk.insert(make_pair(usu.back().first, wys));
  M.insert(usu.back().first + wys);
  if (ost > x) {
    wyk.insert(make_pair(x + 1, usu[0].second));
    M.insert(x + 1 + usu[0].second);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  for (int i = 0; i < n; ++i) cin >> c[i];
  for (int i = 0; i < n; ++i) b.push_back(c[i]);
  map<int, int> gdzieA, gdzieB, gdzieC;
  for (int i = n - 1; i >= 0; --i) gdzieA[a[i]] = i;
  for (int i = 2 * n - 1; i >= 0; --i) gdzieB[b[i]] = i;
  for (int i = n - 1; i >= 0; --i) gdzieC[c[i]] = i;
  vector<int> pos(2 * n - 1);
  for (int i = 0; i < 2 * n; ++i) {
    if (gdzieB[b[i]] != i)
      pos[i] = 0;
    else {
      if (gdzieC.find(b[i]) == gdzieC.end())
        pos[i] = INF;
      else
        pos[i] = gdzieC[b[i]] + 1;
    }
  }
  wyk.insert(make_pair(0, 0));
  M.insert(0);
  for (int i = 0; i < 2 * n; ++i)
    if (gdzieA.find(b[i]) == gdzieA.end() && gdzieB[b[i]] == i)
      Dodaj(i, pos[i]);
  int odp = n + *M.begin();
  for (int i = n - 1; i >= 0; --i) {
    if (gdzieA[a[i]] == i) {
      if (gdzieB.find(a[i]) != gdzieB.end())
        Dodaj(gdzieB[a[i]], pos[gdzieB[a[i]]]);
      else
        break;
    }
    odp = min(odp, i + *M.begin());
  }
  cout << odp;
  return 0;
}