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;
set<pair<int, int> > pontos;
set<pair<int, int> > regioes;
pair<int, int> exc[3 * 100010];
set<pair<int, int> >::iterator it, it2;
pair<int, pair<int, int> > lim[3 * 100010];
pair<int, pair<int, int> > vet[3 * 100010];
int n, tam, resp = 1000000010, yant, exc_ant, exc_at;
int main() {
  scanf("%d", &n);
  for (int i = 0, aux; i < 3 * n; i++) {
    scanf("%d", &aux);
    vet[i] = make_pair(aux, make_pair(i / n, i % n + 1));
  }
  sort(vet, vet + 3 * n);
  lim[0] = make_pair(1000000010, make_pair(1000000010, 1000000010));
  if (vet[0].second.first == 0)
    lim[0].first = vet[0].second.second;
  else if (vet[0].second.first == 1)
    lim[0].second.first = vet[0].second.second;
  else
    lim[0].second.second = vet[0].second.second;
  for (int i = 1; i < 3 * n; i++) {
    if (vet[i].first != vet[i - 1].first) {
      tam++;
      lim[tam] = make_pair(1000000010, make_pair(1000000010, 1000000010));
    }
    if (vet[i].second.first == 0)
      lim[tam].first = min(vet[i].second.second, lim[tam].first);
    else if (vet[i].second.first == 1)
      lim[tam].second.first = min(vet[i].second.second, lim[tam].second.first);
    else
      lim[tam].second.second =
          min(vet[i].second.second, lim[tam].second.second);
  }
  tam++;
  sort(lim, lim + tam);
  pontos.insert(make_pair(0, 0));
  regioes.insert(make_pair(0, 1000000010 + 1));
  regioes.insert(make_pair(1000000010 + 1, 0));
  resp = lim[tam - 1].first;
  for (int i = tam - 1; i >= 0; i--) {
    it = regioes.lower_bound(lim[i].second);
    yant = (*it).second;
    if ((*it).second < lim[i].second.second) {
      pontos.insert(make_pair(lim[i].second.first + yant, yant));
      it--;
      while ((*it).second <= lim[i].second.second) {
        exc[exc_at] = (*it);
        exc_at++;
        pontos.erase(make_pair((*it).first + yant, yant));
        yant = (*it).second;
        it--;
      }
      pontos.erase(make_pair((*it).first + yant, yant));
      pontos.insert(
          make_pair((*it).first + lim[i].second.second, lim[i].second.second));
      for (; exc_ant < exc_at; exc_ant++) {
        regioes.erase(exc[exc_ant]);
      }
      regioes.insert(lim[i].second);
    }
    it = pontos.begin();
    if (i != 0)
      resp = min(resp, lim[i - 1].first + (*it).first);
    else
      resp = min(resp, (*it).first);
  }
  printf("%d\n", resp);
  return 0;
}