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>
struct data {
  int pa, pb, pc;
};
std::vector<data> da;
int constexpr inf = 1 << 28;
int constexpr maxn = 300007;
int a[maxn], b[maxn], c[maxn];
int n, tot;
std::unordered_map<int, int> pa;
std::unordered_map<int, int> pb;
std::unordered_map<int, int> pc;
std::multiset<int> act;
using pair_type = std::pair<int, int>;
bool operator<(pair_type const& a, pair_type const& b) {
  return a.first < b.first;
}
std::set<pair_type> points;
void erase(pair_type const& p) {
  auto it = points.lower_bound(p);
  auto prev = std::prev(it);
  auto next = std::next(it);
  act.erase(prev->first + it->second);
  act.erase(it->first + next->second);
  act.insert(prev->first + next->second);
  points.erase(p);
}
void insert(pair_type const& p) {
  points.insert(p);
  auto it = points.lower_bound(p);
  auto prev = std::prev(it);
  auto next = std::next(it);
  if (next->second > it->second) {
    points.erase(p);
    return;
  }
  act.insert(prev->first + it->second);
  act.insert(it->first + next->second);
  act.erase(prev->first + next->second);
  while (true) {
    it = std::prev(points.lower_bound(p));
    if (it->second < p.second)
      erase(*it);
    else
      break;
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin >> n;
  std::set<int> numbers;
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
    numbers.insert(a[i]);
  }
  for (int i = 0; i < n; i++) {
    std::cin >> b[i];
    numbers.insert(b[i]);
  }
  for (int i = 0; i < n; i++) {
    std::cin >> c[i];
    numbers.insert(c[i]);
  }
  for (int i = n - 1; i >= 0; i--) pa[a[i]] = pb[b[i]] = pc[c[i]] = i + 1;
  da.resize(numbers.size());
  for (auto i : numbers) {
    if (pa.find(i) == pa.end())
      da[tot].pa = 4 * n;
    else
      da[tot].pa = pa[i];
    if (pb.find(i) == pb.end())
      da[tot].pb = 4 * n;
    else
      da[tot].pb = pb[i];
    if (pc.find(i) == pc.end())
      da[tot].pc = 4 * n;
    else
      da[tot].pc = pc[i];
    tot++;
  }
  std::sort(da.begin(), da.end(),
            [](data const& a, data const& b) { return a.pc < b.pc; });
  int ans = 3 * n;
  points.insert({0, inf});
  points.insert({inf, 0});
  act.insert(0);
  for (int i = tot - 1; i >= 0; i--) {
    if (da[i].pc >= 4 * n) {
      insert({da[i].pa, da[i].pb});
    } else {
      ans = std::min(ans, *act.begin() + da[i].pc);
      insert({da[i].pa, da[i].pb});
    }
  }
  std::cout << std::min(ans, *act.begin()) << '\n';
}
