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.
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
int n;
int an[N], bn[N], cn[N];
const int LS = N * 3;
int ls[LS], szls;
int ma[LS], mb[LS], mc[LS];
int od[LS];
inline bool cmp_lim_a_r(int a, int b) { return ma[a] > ma[b]; }
multiset<pair<int, int> > hull;
multiset<int> val;
inline int gen(pair<int, int> a, pair<int, int> b) {
  return min(a.first, b.first) + min(a.second, b.second);
}
inline void erase(multiset<pair<int, int> >::iterator it) {
  multiset<pair<int, int> >::iterator itl = it, itr = it;
  --itl, ++itr;
  val.erase(val.find(gen(*itl, *it)));
  val.erase(val.find(gen(*it, *itr)));
  val.insert(gen(*itl, *itr));
  hull.erase(it);
}
inline void make_ins(multiset<pair<int, int> >::iterator it) {
  multiset<pair<int, int> >::iterator itl = it, itr = it;
  --itl, ++itr;
  val.insert(gen(*itl, *it));
  val.insert(gen(*it, *itr));
  val.erase(val.find(gen(*itl, *itr)));
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &an[i]);
  for (int i = 1; i <= n; ++i) scanf("%d", &bn[i]);
  for (int i = 1; i <= n; ++i) scanf("%d", &cn[i]);
  for (int i = 1; i <= n; ++i) {
    ls[++szls] = an[i];
    ls[++szls] = bn[i];
    ls[++szls] = cn[i];
  }
  sort(ls + 1, ls + szls + 1);
  szls = int(unique(ls + 1, ls + szls + 1) - ls - 1);
  for (int i = 1; i <= n; ++i) {
    an[i] = int(lower_bound(ls + 1, ls + szls + 1, an[i]) - ls);
    bn[i] = int(lower_bound(ls + 1, ls + szls + 1, bn[i]) - ls);
    cn[i] = int(lower_bound(ls + 1, ls + szls + 1, cn[i]) - ls);
  }
  for (int i = 1; i <= szls; ++i) ma[i] = mb[i] = mc[i] = 10000000;
  for (int i = 1; i <= n; ++i) {
    ma[an[i]] = min(ma[an[i]], i);
    mb[bn[i]] = min(mb[bn[i]], i);
    mc[cn[i]] = min(mc[cn[i]], i);
  }
  for (int i = 1; i <= szls; ++i) od[i] = i;
  sort(od + 1, od + szls + 1, cmp_lim_a_r);
  int ans = 10000000;
  hull.insert(make_pair(0, 50000005));
  hull.insert(make_pair(50000005, 0));
  val.insert(0);
  for (int it = 1; it <= szls; ++it) {
    int i = od[it];
    ans = min(ans, ma[i] + *val.begin());
    multiset<pair<int, int> >::iterator itr =
        hull.lower_bound(make_pair(mb[i], mc[i]));
    if (itr != hull.end() && itr->first >= mb[i] && itr->second >= mc[i])
      continue;
    multiset<pair<int, int> >::iterator itl =
        hull.upper_bound(make_pair(mb[i], mc[i]));
    --itl;
    while (itl->first <= mb[i] && itl->second <= mc[i]) {
      erase(itl);
      itl = hull.upper_bound(make_pair(mb[i], mc[i]));
      --itl;
    }
    make_ins(hull.insert(make_pair(mb[i], mc[i])));
  }
  ans = min(ans, *val.begin());
  printf("%d\n", ans);
  return 0;
}
