// {{{ by unolight
#pragma region
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
#pragma endregion
// }}}

// {{{ 1-indexed BIT
template<class T>
struct BIT {
    int n;
    vector<T> bit;
    BIT(int n_):n(n_+1), bit(n_+1, 0) {}
    void init() { fill(bit.begin(), bit.end(), 0); }
    void add(int k, T v) {
        for(;k<n; k+=k&-k) bit[k] += v;
    }
    T get(int k) {
        T r=0;
        for(;k>0;k-=k&-k) r+=bit[k];
        return r;
    }
    // (l, r]
    T get(int l, int r) {
        return get(r) - get(l);
    }
    T operator[](int i) { return get(i-1,i); }
};

const int N=200010;
vector<array<int,4>> events;
LL intersection_points() {
  BIT<LL> bit(N);
//   for ( int i=0; i<n; i++ ) {
//     int a,b,c,d;
//     cin >> a >> b >> c >> d; // (x1,y1) (x2,y2)
//     if ( a==c ) { // query
//       events.push_back({a, 2, b, d});
//     } else { // at x1 add, x2 remove
//       events.push_back({a, 1, b, 1});
//       events.push_back({c, 3, b, -1});
//     }
//   }
  sort(events.begin(), events.end());
  long long ans = 0;
  for ( int i=0; i<events.size(); i++ ) {
    if ( events[i][1]==1 ) {
      int y = events[i][2];
      bit.add(y, 1);
    } else if ( events[i][1]==3 ) {
      int y = events[i][2];
      bit.add(y, -1);
    } else {
      int l = events[i][2], r = events[i][3];
      ans += bit.get(l-1, r);
    }
  }
  return ans;
}


void main() {
    int h,w,m;
    R(h,w,m);
    vector<int> x(h+1,w+1),y(w+1,h+1);
    REP(i,m) {
        int a,b;
        R(a,b);
        chmin(x[a],b);
        chmin(y[b],a);
    }
    LL ans=0;
    REP1(i,1,y[1]-1) ans+=x[i]-1;
    REP1(i,1,x[1]-1) ans+=y[i]-1;
    REP1(i,1,y[1]-1) events.push_back({i,2,1,x[i]-1});
    REP1(i,1,x[1]-1) {
        events.push_back({1,1,i,-1});
        events.push_back({y[i]-1,3,i,-1});
    }
    // dump(intersection_points());
    W(ans-intersection_points());
}

 // {{{ main
}}
int main() { unolight::main(); return 0; }
// }}}

/**
 *  author: souravrax
 *  created: 19.06.2021 17:50:09
**/
#include <bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
#define len(x) int((x).size())
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename TC, typename T = typename enable_if<!is_same<TC, string>::value, typename TC::value_type>::type> 
ostream& operator<<(ostream &os, const TC &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
struct dbg {
#ifdef LOCAL
    ~dbg() { cerr << endl; }
    template<typename T> dbg& operator<<(const T& args) { cerr << args; return *this; }
#else
    template<typename T> dbg& operator<<(__attribute__((unused))const T& args) { return *this; }
#endif
};
#define show(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pi = pair<int, int>;

const int MAXN = (int)2e5 + 5;
bitset<MAXN> visited;
vector<int> graph[MAXN];

int dfs(int u) {
    visited[u] = true;
    int ans = 1;
    for (int& v : graph[u]) {
        if (!visited[v]) {
            ans += dfs(v);
        }
    }
    return ans;
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int& i : a) cin >> i;
    for (int i = 0, j = n - 1; i < j; i++, j--) {
        if (a[i] != a[j]) {
            graph[a[i]].push_back(a[j]);
            graph[a[j]].push_back(a[i]);
        } 
    }
    ll ans = 0;
    for (auto& i : a) {
        if (!visited[i]) {
            ans += dfs(i) - 1;
        }
    }
    cout << ans << '\n';
}

