// Warning: very old code.
#include <fstream>
#include <algorithm>
#include <vector>
#define VALMAX 100005
using namespace std;
struct node {
int left, right;
int lazy, maxima;
node(int _left = 0, int _right = 0, int _lazy = 0, int _maxima = 0) :
left(_left), right(_right), lazy(_lazy), maxima(_maxima) {}
inline void make_lazy(int value) {
maxima += value;
lazy += value;
}
} arb[VALMAX * 4];
void build(int left, int right, int pos) {
arb[pos].left = left, arb[pos].right = right;
arb[pos].lazy = arb[pos].maxima = 0;
if (left == right)
return ;
const int mijl = (left + right) / 2;
build(left, mijl, 2 * pos);
build(mijl + 1, right, 2 * pos + 1);
}
void update(int left, int right, int value, int pos) {
if (arb[pos].left == left && arb[pos].right == right) {
arb[pos].make_lazy(value);
return ;
}
const int mijl = (arb[pos].left + arb[pos].right) / 2;
if (right <= mijl)
update(left, right, value, 2 * pos);
else if (left > mijl)
update(left, right, value, 2 * pos + 1);
else {
update(left, mijl, value, 2 * pos);
update(mijl + 1, right, value, 2 * pos + 1);
}
arb[pos].maxima = max(arb[2 * pos].maxima, arb[2 * pos + 1].maxima) + arb[pos].lazy;
}
struct point {
int x, y;
point(int _x = 0, int _y = 0): x(_x), y(_y) {}
} points[VALMAX + 5];
struct event {
int type; // 1 = insert, -1 = erase
int which;
event(int _type = 0, int _which = 0): type(_type), which(_which) {}
};
vector <event> events[VALMAX + 5];
int sweep_maxima_OY_asc[VALMAX + 5];
int sweep_maxima_OY_desc[VALMAX + 5];
int sweep_maxima_OX_asc[VALMAX + 5];
int sweep_maxima_OX_desc[VALMAX + 5];
int dx, dy, n;
inline void do_sweeping (int *sweep_maxima_OY_asc, int *sweep_maxima_OY_desc) {
build(0, VALMAX, 1);
for (int i = 1; i <= n; i++) {
events[points[i].x].push_back(event(1, i));
if (points[i].x + dx <= VALMAX)
events[points[i].x + dx].push_back(event(-1, i));
}
vector <event> :: iterator it;
for (int i = 0; i <= VALMAX; i++) {
if (i)
sweep_maxima_OY_asc[i] = sweep_maxima_OY_asc[i - 1];
for (it = events[i].begin(); it != events[i].end(); it++)
if (it -> type == 1) {
update(points[it -> which].y, min(points[it -> which].y + dy, VALMAX), it -> type, 1);
sweep_maxima_OY_asc[i] = max(sweep_maxima_OY_asc[i], arb[1].maxima);
}
for (it = events[i].begin(); it != events[i].end(); it++)
if (it -> type == -1) {
update(points[it -> which].y, min(points[it -> which].y + dy, VALMAX), it -> type, 1);
sweep_maxima_OY_asc[i] = max(sweep_maxima_OY_asc[i], arb[1].maxima);
}
events[i].clear();
}
//Baleere descendenta
build(0, VALMAX, 1);
for (int i = 1; i <= n; i++) {
events[points[i].x].push_back(event(1, i));
if (points[i].x - dx >= 0)
events[points[i].x - dx].push_back(event(-1, i));
}
for (int i = VALMAX; i >= 0; i--) {
sweep_maxima_OY_desc[i] = sweep_maxima_OY_desc[i + 1];
for (it = events[i].begin(); it != events[i].end(); it++)
if (it -> type == 1) {
update(points[it -> which].y, min(points[it -> which].y + dy, VALMAX), it -> type, 1);
sweep_maxima_OY_desc[i] = max(sweep_maxima_OY_desc[i], arb[1].maxima);
}
for (it = events[i].begin(); it != events[i].end(); it++)
if (it -> type == -1) {
update(points[it -> which].y, min(points[it -> which].y + dy, VALMAX), it -> type, 1);
sweep_maxima_OY_desc[i] = max(sweep_maxima_OY_desc[i], arb[1].maxima);
}
events[i].clear();
}
}
inline void invert () {
for (int i = 1; i <= n; i++)
swap(points[i].x, points[i].y);
swap(dx, dy);
}
int main()
{
ifstream cin("parcele.in");
ofstream cout("parcele.out");
cin >> dx >> dy >> n;
for (int i = 1; i <= n; i++)
cin >> points[i].x >> points[i].y;
do_sweeping(sweep_maxima_OY_asc, sweep_maxima_OY_desc);
invert();
do_sweeping(sweep_maxima_OX_asc, sweep_maxima_OX_desc);
int maxima = 0;
for (int i = 0; i < VALMAX; i++) {
maxima = max(maxima, sweep_maxima_OY_asc[i] + sweep_maxima_OY_desc[i + 1]);
maxima = max(maxima, sweep_maxima_OX_asc[i] + sweep_maxima_OX_desc[i + 1]);
}
cout << maxima << '\n';
cin.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