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 long long int MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;
stringstream sss;
const long long int maxn = 100010;
long long int n;
long long int A[maxn], B[maxn], C[maxn];
map<long long int, long long int> cnt_in_A, fst_in_B, fst_in_C;
set<pair<long long int, long long int> > hist;
long long int seg[maxn * 4];
long long int lazy[maxn * 4];
void build(long long int x = 1, long long int l = 0, long long int r = n + 1) {
  seg[x] = l;
  if (r - l > 1) {
    long long int mid = (l + r) / 2;
    build(x * 2, l, mid);
    build(x * 2 + 1, mid, r);
  }
}
void push(long long int x) {
  seg[x * 2] += lazy[x];
  lazy[x * 2] += lazy[x];
  seg[x * 2 + 1] += lazy[x];
  lazy[x * 2 + 1] += lazy[x];
  lazy[x] = 0;
}
void update(long long int li, long long int ri, long long int v,
            long long int x = 1, long long int l = 0, long long int r = n + 1) {
  if (seg[x] >= BIG) return;
  if (li >= r || l >= ri) {
  } else if (li <= l && r <= ri) {
    seg[x] += v;
    lazy[x] += v;
  } else {
    if (lazy[x]) push(x);
    long long int mid = (l + r) / 2;
    update(li, ri, v, x * 2, l, mid);
    update(li, ri, v, x * 2 + 1, mid, r);
    seg[x] = min(seg[x * 2], seg[x * 2 + 1]);
  }
}
void set_max(long long int i, long long int v) {
  auto rt = hist.upper_bound({i, BIG});
  if (rt->second >= v) return;
  auto lt = rt;
  --lt;
  if (lt->first == i && lt->second >= v) return;
  while (lt->second <= v) {
    long long int b = lt->first, hb = lt->second;
    --lt;
    long long int a = lt->first;
    update(a + 1, b + 1, -(hb - rt->second));
  }
  update(lt->first + 1, i + 1, v - rt->second);
  ++lt;
  hist.erase(lt, rt);
  hist.insert({i, v});
}
void MAIN() {
  cin >> n;
  for (long long int i = (0); i < (n); ++i) cin >> A[i];
  for (long long int i = (0); i < (n); ++i) cin >> B[i];
  for (long long int i = (0); i < (n); ++i) cin >> C[i];
  for (long long int i = (0); i < (n); ++i) cnt_in_A[A[i]]++;
  for (long long int i = (n)-1; i >= (0); --i) {
    fst_in_B[B[i]] = i;
    fst_in_C[C[i]] = i;
  }
  build();
  hist.insert({-1, BIG + 1});
  hist.insert({BIG, 0});
  long long int s = 0;
  for (long long int i = (0); i < (n); ++i) {
    if (cnt_in_A.count(C[i]) + fst_in_B.count(C[i]) == 0 && fst_in_C[C[i]] == i)
      s = i + 1;
  }
  set_max(n, s);
  for (long long int i = (n)-1; i >= (0); --i) {
    if (cnt_in_A[B[i]] == 0 && fst_in_B[B[i]] == i) {
      long long int s = fst_in_C.count(B[i]) ? fst_in_C[B[i]] + 1 : BIG;
      set_max(i, s);
    }
  }
  long long int ans = n + seg[1];
  for (long long int i = (n)-1; i >= (0); --i) {
    if (--cnt_in_A[A[i]] == 0) {
      long long int f = fst_in_B.count(A[i]) ? fst_in_B[A[i]] : n;
      long long int s = fst_in_C.count(A[i]) ? fst_in_C[A[i]] + 1 : BIG;
      set_max(f, s);
    }
    ans = min(ans, (i + seg[1]));
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(10);
  sss << R"(
10
3 2 2 1 3 4 1 10 5 10
2 10 8 9 9 10 3 1 3 4
1 4 6 8 8 3 4 5 8 10
10
2 5 10 6 4 3 1 1 9 5
5 10 5 2 4 1 1 4 7 4
5 1 4 9 2 6 10 9 8 3
10
2 10 2 1 8 8 3 1 7 10
2 10 5 7 8 8 2 6 1 6
1 5 6 6 7 8 4 9 4 4
5
1 1 2 2 3
2 2 4 3 3
3 3 1 1 1
    )";
  MAIN();
  return 0;
}