#pragma GCC optimize("Ofast")
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define mod (int)(1e9+7)
#define mod2 998244353
#define flush fflush(stdout);
#define PI 3.1415926535897932384626433832795

void solve() {
    int n; cin>>n;
    int a[n],b[n];
    for(auto &it:a)
        cin>>it;
    for(auto &it:b)
        cin>>it;
    map<int,int> m;
    for(int i=0;i<n;i++){
        for(int j=min(a[i],b[i]);j<=max(a[i],b[i]);j++)
            m[j]++;
    }
    int ans=0;
    for(auto &it:m){
        if(it.second==n)ans++;
    }
    cout<<ans;
}

int32_t main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = 0; i <= (n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main() { 
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  if (n <= 1) {
    cout << 0 << endl;
    return 0;
  }

  const int M = 200005;

  UnionFind uf(M);
  rep(i,n) uf.unite(a[i], a[n-1-i]);

  int ans = 0;
  rep(i,M) {
    if (uf.find(i) != i) continue;
    ans += uf.size(i) - 1;
  }

  cout << ans << endl;

  return 0; 
}
