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 const MAXN = maxn;
struct Tri {
  int i, j, k;
  bool operator<(const Tri &t) const { return k < t.k; }
} d[MAXN];
void init() {
  static int a[MAXN], b[MAXN], c[MAXN];
  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::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;
  for (std::set<int>::iterator it = numbers.begin(); it != numbers.end();
       ++it) {
    int x = *it;
    ++tot;
    if (pa.find(x) == pa.end())
      d[tot].i = 4 * n;
    else
      d[tot].i = pa[x];
    if (pb.find(x) == pb.end())
      d[tot].j = 4 * n;
    else
      d[tot].j = pb[x];
    if (pc.find(x) == pc.end())
      d[tot].k = 4 * n;
    else
      d[tot].k = pc[x];
  }
}
void solve() {
  std::sort(d + 1, d + tot + 1);
  int ret = 3 * n;
  points.clear();
  points.insert(pair_type(0, inf));
  points.insert(pair_type(inf, 0));
  act.insert(0);
  int cur = tot;
  while (cur >= 1 && d[cur].k >= 4 * n) {
    insert(pair_type(d[cur].i, d[cur].j));
    --cur;
  }
  while (cur >= 1) {
    ret = std::min(ret, *act.begin() + d[cur].k);
    insert(pair_type(d[cur].i, d[cur].j));
    --cur;
  }
  ret = std::min(ret, *act.begin());
  std::cout << ret << std::endl;
}
int main() {
  init();
  solve();
}
