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.
1
2
3
2
 8
190409007 190409007 352375776 190409007 352375776 352375776 352375776 352375776
190409007 190409007 190409007 190409007 190409007 352375776 352375776 190409007
190409007 352375776 352375776 190409007 190409007 190409007 352375776 352375776
 1
1
1
1
 1
377489979
588153796
588153796
 2
1 1
2 2
3 3
 4
1 1 1 1
1 1 1 1
1 1 1 1
 2
1 2
2 2
1 1
 3
1 1 2
1 1 3
1 1 4

2
 2
 1
 2
 3
 1
 2
 9

#include <bits/stdc++.h>
int const maxn = 300010;
int const inf = 1 << 28;
struct data {
  int pa, pb, pc;
};
std::vector<data> d;
int a[maxn], b[maxn], c[maxn];
int tot, n, endpos;
using Pair = std::pair<int, int>;
std::set<Pair> seq;
std::multiset<int> ans;
void erase(Pair const &p) {
  auto y = seq.lower_bound(p);
  auto x = y;
  auto z = y;
  --x, ++z;
  ans.erase(x->first + y->second);
  ans.erase(y->first + z->second);
  ans.insert(x->first + z->second);
  seq.erase(y);
}
void insert(Pair const &p) {
  seq.insert(p);
  auto y = seq.lower_bound(p);
  auto x = y;
  auto z = y;
  --x, ++z;
  if (z->second > y->second) {
    seq.erase(p);
    return;
  }
  ans.insert(x->first + y->second);
  ans.insert(y->first + z->second);
  ans.erase(x->first + z->second);
  while (1) {
    x = seq.lower_bound(p);
    --x;
    if (x->second < p.second) {
      erase(*x);
    } else
      break;
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin >> n;
  for (int i = 1; i <= n; i++) std::cin >> a[i];
  for (int i = 1; i <= n; i++) std::cin >> b[i];
  for (int i = 1; i <= n; i++) std::cin >> c[i];
  std::unordered_map<int, int> pa, pb, pc;
  std::set<int> numbers;
  for (int i = n; i >= 1; i--) numbers.insert(a[i]), pa[a[i]] = i;
  for (int i = n; i >= 1; i--) numbers.insert(b[i]), pb[b[i]] = i;
  for (int i = n; i >= 1; i--) numbers.insert(c[i]), pc[c[i]] = i;
  d.resize(numbers.size());
  for (auto x : numbers) {
    if (pa.find(x) == pa.end())
      d[tot].pa = 4 * n;
    else
      d[tot].pa = pa[x];
    if (pb.find(x) == pb.end())
      d[tot].pb = 4 * n;
    else
      d[tot].pb = pb[x];
    if (pc.find(x) == pc.end())
      d[tot].pc = 4 * n;
    else
      d[tot].pc = pc[x];
    tot++;
  }
  std::sort(d.begin(), d.end(),
            [](data const &a, data const &b) { return a.pc < b.pc; });
  int ret = 3 * n;
  seq.insert({0, inf});
  seq.insert({inf, 0});
  ans.insert(0);
  for (int i = tot - 1; i >= 0; i--) {
    if (d[i].pc >= 4 * n)
      insert({d[i].pa, d[i].pb});
    else {
      ret = std::min(ret, *ans.begin() + d[i].pc);
      insert({d[i].pa, d[i].pb});
    }
  }
  ret = std::min(ret, *ans.begin());
  std::cout << ret << '\n';
}
