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;
const int MAX = 400000;
int N;
int A[4][100100];
map<int, int> earliest[4];
map<int, int> staircase;
set<pair<int, pair<int, int> > > corners;
map<int, pair<int, int> > corners_x;
void corners_delete(int x) {
  if (corners_x.find(x) == corners_x.end()) return;
  pair<int, int> p = corners_x[x];
  corners.erase(make_pair(p.first + p.second, p));
  corners_x.erase(p.first);
}
void corners_insert(pair<int, int> p) {
  corners_delete(p.first);
  corners.insert(make_pair(p.first + p.second, p));
  corners_x[p.first] = p;
}
void disp() {
  cout << "staircase = ";
  for (map<int, int>::iterator it = staircase.begin(); it != staircase.end();
       it++)
    cout << '(' << it->first << ',' << it->second << ") ";
  cout << "corners = ";
  for (set<pair<int, pair<int, int> > >::iterator it = corners.begin();
       it != corners.end(); it++) {
    cout << '(' << it->second.first << ',' << it->second.second << ") ";
  }
  cout << endl;
}
void init() {
  staircase[0] = 2 * MAX, staircase[2 * MAX] = 0;
  corners_insert(pair<int, int>(0, 0));
}
void insert(pair<int, int> p) {
  pair<int, int> p0 = p;
  if (staircase.lower_bound(p.first)->second >= p.second) return;
  if (p.first < staircase.lower_bound(p.first)->first) {
    map<int, int>::iterator right = staircase.lower_bound(p.first);
    corners_insert(pair<int, int>(p.first, right->second));
  }
  staircase[p.first] = p.second;
  while (true) {
    map<int, int>::iterator left = --staircase.lower_bound(p.first);
    if (left->second > p.second) {
      corners_delete(left->first);
      corners_insert(pair<int, int>(left->first, p.second));
      break;
    } else if (left->second == p.second) {
      corners_delete(left->first);
      break;
    }
    staircase.erase(left->first);
    corners_delete(left->first);
  }
}
void process(int v) {
  pair<int, int> p;
  p.first = (earliest[1].find(v) == earliest[1].end() ? MAX : earliest[1][v]);
  p.second = (earliest[2].find(v) == earliest[2].end() ? MAX : earliest[2][v]);
  insert(p);
}
int bestval() { return corners.empty() ? MAX : corners.begin()->first; }
int main() {
  cin >> N;
  for (int k = 1; k <= 3; k++)
    for (int i = 1; i <= N; i++) cin >> A[k][i];
  for (int k = 1; k <= 3; k++)
    for (int i = N; i >= 1; i--) earliest[k][A[k][i]] = i;
  init();
  for (int k = 1; k <= 2; k++)
    for (int i = 1; i <= N; i++) {
      int v = A[k][i];
      if (earliest[3].find(v) == earliest[3].end()) process(v);
    }
  int best = N + corners.begin()->first;
  for (int i = N; i >= 1; i--) {
    if (earliest[3][A[3][i]] == i) process(A[3][i]);
    best = min(best, i - 1 + bestval());
  }
  cout << best << endl;
  return 0;
}