// Kỹ thuật sử dụng: Quy hoạch động+Tìm kiếm nhị phân
#include<bits/stdc++.h>
#define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
using namespace std;
ll n,m,k,res;
pair<ll,ll> toado[1002];
void tkiem(ll p,ll &a,pair<ll,ll> &b,pair<ll,ll> &c, ll &d,const map<ll,ll> &pos)
{
c=*pos.upper_bound(p);
if(c.first<n+1) d=(pos.upper_bound(c.first))->first;
b=*(--pos.lower_bound(p));
if(b.first>0) a=(--pos.lower_bound(b.first))->first;
}
void in(ll p,map<ll,ll> &pos,set<pair<ll,ll>,greater<pair<ll,ll>>> &s)
{
ll d=n+10,a=-1,res=++pos[p];
pair<ll,ll> c={0,0},b={0,0};
tkiem(p,a,b,c,d,pos);
if(res>1)
{
s.erase({c.first-b.first-1,b.first});
return;
}
if(a>-1&&b.second==1)
{
s.erase({c.first-a-1,a});
s.insert({p-a-1,a});
}
if(d<n+10&&c.second==1)
{
s.erase({d-b.first-1,b.first});
s.insert({d-p-1,p});
}
s.insert({c.first-b.first-1,b.first});
}
int main()
{
faster
ll i,r1,r2,r,c,ma,j;
cin>>m>>n>>k;
for(i=1;i<=k;i++)
{
cin>>r>>c;
toado[i]={r,c};
}
sort(toado+1,toado+k+1);
toado[k+1]={m+1,0};
for(i=1;i<=k;i++)
{
if(toado[i].first>toado[i-1].first)
{
r1=-1;
if(toado[i].first>toado[i-1].first) r1=toado[i-1].first+1;
map<ll,ll> pos;
set<pair<ll,ll>,greater<pair<ll,ll>>> s;
ma=0;
pos.insert({0,1});
pos.insert({n+1,1});
for(j=i;j<=k+1;j++)
{
if(toado[j].first>toado[j-1].first)
{
if(j>1)
{
r2=toado[j].first-1;
ma=(s.begin())->first;
res=max(res,(r2-r1+1)*ma);
if(j<=k) in(toado[j].second,pos,s);
}
else
{
pos[toado[j].second]=1;
s.insert({n,0});
}
}
else in(toado[j].second,pos,s);
}
}
}
cout<<res;
}
Ly8gS+G7uSB0aHXhuq10IHPhu60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