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>
using namespace std;
const int INF = 1e6;
struct Point {
  int x, y, z;
  Point(int a, int b, int c) : x(a), y(b), z(c){};
  Point() : x(INF), y(INF), z(INF){};
};
bool operator<(Point a, Point b) {
  if (a.x != b.x)
    return a.x < b.x;
  else if (a.y != b.y)
    return a.y < b.y;
  else
    return a.z < b.z;
}
struct Pareto {
  set<pair<int, int>> s;
  set<pair<int, pair<int, int>>> ans;
  Pareto() {}
  void getEdges(set<pair<int, int>>::iterator it, pair<int, int>& p1,
                pair<int, int>& p2) {
    if (it == s.begin()) {
      p1.first = 0;
      p1.second = it->second;
    } else {
      p1.first = prev(it)->first;
      p1.second = it->second;
    }
    if (next(it) == s.end()) {
      p2.first = it->first;
      p2.second = 0;
    } else {
      p2.first = it->first;
      p2.second = next(it)->second;
    }
  }
  int insert(pair<int, int> p) {
    s.insert(p);
    set<pair<int, int>>::iterator it = s.find(p), itother;
    if (next(it) != s.end() && next(it)->second >= it->second) {
      s.erase(it);
      return ans.begin()->first;
    }
    pair<int, int> p1, p2;
    bool removed = 0;
    while (it != s.begin() && it->second >= prev(it)->second) {
      itother = prev(it);
      s.erase(it);
      getEdges(itother, p1, p2);
      ans.erase(
          make_pair(p1.first + p1.second, pair<int, int>(p1.first, p1.second)));
      if (!removed)
        ans.erase(make_pair(p2.first + p2.second,
                            pair<int, int>(p2.first, p2.second)));
      s.erase(itother);
      s.insert(p);
      it = s.find(p);
      removed = true;
    }
    if (!removed) {
      if (next(it) != s.end()) {
        itother = next(it);
        s.erase(it);
        getEdges(itother, p1, p2);
        ans.erase(make_pair(p1.first + p1.second,
                            pair<int, int>(p1.first, p1.second)));
        s.insert(p);
        it = s.find(p);
      }
      if (it != s.begin()) {
        itother = prev(it);
        s.erase(it);
        getEdges(itother, p1, p2);
        ans.erase(make_pair(p2.first + p2.second,
                            pair<int, int>(p2.first, p2.second)));
        s.insert(p);
        it = s.find(p);
      }
    }
    getEdges(it, p1, p2);
    ans.insert(
        make_pair(p1.first + p1.second, pair<int, int>(p1.first, p1.second)));
    ans.insert(
        make_pair(p2.first + p2.second, pair<int, int>(p2.first, p2.second)));
    return ans.begin()->first;
  }
} pareto;
map<int, Point> mp;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1, a; i <= n; i++) {
    scanf("%d", &a);
    mp[a];
    mp[a].x = min(mp[a].x, i);
  }
  for (int i = 1, a; i <= n; i++) {
    scanf("%d", &a);
    mp[a];
    mp[a].y = min(mp[a].y, i);
  }
  for (int i = 1, a; i <= n; i++) {
    scanf("%d", &a);
    mp[a];
    mp[a].z = min(mp[a].z, i);
  }
  vector<Point> v;
  for (auto p : mp) v.push_back(p.second);
  sort(v.rbegin(), v.rend());
  int ans = INF;
  for (int i = 0; i < v.size(); i++) {
    ans = min(ans, (i + 1 == v.size() ? 0 : v[i + 1].x) +
                       pareto.insert(pair<int, int>(v[i].y, v[i].z)));
  }
  printf("%d\n", ans);
}
