#include #include #include using namespace std; using ll = long long; #include int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll ans = 0; ll h,w,n; cin>>h>>w>>n; vector> a(h,vector(w+1,0)); for(int i = 0;i>x>>y; x--;y--; a[x][y] = 1; } for(int i = 0;i last(w+1,-1); for(int i = 0;i> st; for(int j = 0;j<=w;j++){ if(a[i][j]) last[j] = i; int len = i - last[j]; ll cnt = 0; while(st.size()){ pair now = st.top(); if(now.first<=len) break; st.pop(); ll can = now.first; ll mx = len; if(st.size()) mx = max(mx,st.top().first); ll use = can - mx; ans += use * (now.second) * (now.second+1) / 2; if(st.size()&&st.top().first>len){ st.top().second += now.second; continue; } cnt += now.second; } cnt++; if(st.size()&&st.top().first==len) st.top().second += cnt; else st.push(make_pair(len,cnt)); } } cout<