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;
template <class T>
bool chmax(T &a, const T &b) {
  return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  return (b < a) ? (a = b, 1) : 0;
}
using ll = long long;
using R = long double;
const R EPS = 1e-9L;
inline int sgn(const R &r) { return (r > EPS) - (r < -EPS); }
inline R sq(R x) { return sqrt(max(x, 0.0L)); }
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int inf = 1 << 20;
int a[300010], b[300010], c[300010];
int fa[300010], fb[300010], fc[300010];
multiset<int> score;
using pii = pair<int, int>;
set<pii> points;
void show() {
  cerr << "Point Set: " << endl;
  for (auto &it : points) {
    cerr << it.first << " " << it.second << endl;
  }
  cerr << "Score: " << endl;
  for (auto &it : score) cerr << it << endl;
}
void add(int y, int x) {
  pii e = pii(y, x);
  auto it = points.lower_bound(e);
  if (e.second <= it->second) return;
  while (1) {
    auto p = *it;
    it--;
    if (e.second < p.second) break;
    auto q = *it;
    auto tmp = score.lower_bound(q.first + p.second);
    score.erase(tmp);
    if (p.first <= e.first) points.erase(p);
  }
  {
    it = points.lower_bound(e);
    auto p = *it;
    it--;
    auto q = *it;
    points.insert(e);
    score.insert(e.first + p.second);
    score.insert(q.first + e.second);
  }
  return;
}
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = int(0); i < int(n); ++i) scanf("%d", a + i);
  for (int i = int(0); i < int(n); ++i) scanf("%d", b + i);
  for (int i = int(0); i < int(n); ++i) scanf("%d", c + i);
  vector<int> value;
  for (int i = int(0); i < int(n); ++i) {
    value.push_back(a[i]);
    value.push_back(b[i]);
    value.push_back(c[i]);
  }
  sort(begin(value), end(value)),
      (value).erase(unique(begin(value), end(value)), end(value));
  const int m = value.size();
  for (int i = int(0); i < int(m); ++i) fa[i] = fb[i] = fc[i] = inf;
  for (int i = int(0); i < int(n); ++i) {
    a[i] = lower_bound(begin(value), end(value), a[i]) - begin(value);
    b[i] = lower_bound(begin(value), end(value), b[i]) - begin(value);
    c[i] = lower_bound(begin(value), end(value), c[i]) - begin(value);
    if (fa[a[i]] == inf) fa[a[i]] = i;
    if (fb[b[i]] == inf) fb[b[i]] = i;
    if (fc[c[i]] == inf) fc[c[i]] = i;
  }
  score.insert(0);
  points.insert({0, 2 * inf});
  points.insert({2 * inf, 0});
  for (int i = int(0); i < int(m); ++i) {
    if (fa[i] == inf) {
      add(fb[i] + 1, fc[i] + 1);
    }
  }
  int ret = n + *begin(score);
  for (int i = int(n) - 1; i >= int(0); --i) {
    if (fa[a[i]] == i) add(fb[a[i]] + 1, fc[a[i]] + 1);
    chmin(ret, i + *begin(score));
  }
  printf("%d\n", ret);
  return 0;
}