1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include <bits/stdc++.h>

struct point {
    int x;
    int p;
    bool operator<(const struct point& par) {
        return (x < par.x);
    }
};

struct se {
    int p;
    int o;
    int k;
};

#define MAX(A, B) (((A) > (B)) ? (A) : (B))

int xobszary[1000010];
int yobszary[1000010];
se stos[500010];
point xlist[1000010];
point ylist[1000010];
int xusage[500010];
int yusage[500010];

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int n, X, Y, i, os, ss, op, prev, p, k, j;
    int64_t score, total = 1;

    std::cin >> n >> X >> Y;
    for (i = 0; i < 2 * n; i += 2) {
        std::cin >> xlist[i].x >> ylist[i].x >> xlist[i + 1].x >> ylist[i + 1].x;
        xlist[i].p = i / 2 + 1;
        ylist[i].p = i / 2 + 1;
        xlist[i + 1].p = i / 2 + 1;
        ylist[i + 1].p = i / 2 + 1;
    }

    int* obszary;
    point* list;
    int *usage;
    int *border;
    bool create;
    
    obszary = xobszary;
    list = xlist;
    usage = xusage;
    border = &X;

    {
        std::sort(list, list + (2 * n));
        os = 1;
        op = 0;
        ss = 1;

        prev = 0;
        for (i = 0; i < 2 * n; ++i) {
            obszary[op] += (list[i].x - prev);
            prev = list[i].x;

            p = list[i].p;
            if (usage[p] == 0) {
                stos[ss] = {p, op, 0};
                usage[p] = ss;
                ss++;
                op = os;
                os++;
            } else {
                stos[usage[p]].p = -1;
                k = MAX(stos[ss - 1].k, ss - usage[p]);
                stos[ss - 1].k = k;
                create = true;
                while (stos[ss - 1].p < 0) {
                    create = true;
                    if (k == 1) {
                        op = stos[ss - 1].o;
                        create = false;
                    }
                    ss--;
                    k--;
                    k = MAX(stos[ss - 1].k, k);
                    stos[ss - 1].k = k;
                }
                if (create) {
                    op = os;
                    os++;
                }
            }
        }
        obszary[0] += (*border - prev);

        score = 0;
        for (i = 0; i < os; ++i) {
            score = MAX(obszary[i], score);
        }

        total *= score;
    }

    obszary = yobszary;
    list = ylist;
    usage = yusage;
    border = &Y;

    {
        std::sort(list, list + (2 * n));
        os = 1;
        op = 0;
        ss = 1;

        prev = 0;
        for (i = 0; i < 2 * n; ++i) {
            obszary[op] += (list[i].x - prev);
            prev = list[i].x;

            p = list[i].p;
            if (usage[p] == 0) {
                stos[ss] = {p, op, 0};
                usage[p] = ss;
                ss++;
                op = os;
                os++;
            } else {
                stos[usage[p]].p = -1;
                k = MAX(stos[ss - 1].k, ss - usage[p]);
                stos[ss - 1].k = k;
                create = true;
                while (stos[ss - 1].p < 0) {
                    create = true;
                    if (k == 1) {
                        op = stos[ss - 1].o;
                        create = false;
                    }
                    ss--;
                    k--;
                    k = MAX(stos[ss - 1].k, k);
                    stos[ss - 1].k = k;
                }
                if (create) {
                    op = os;
                    os++;
                }
            }
        }
        obszary[0] += (*border - prev);

        score = 0;
        for (i = 0; i < os; ++i) {
            score = MAX(obszary[i], score);
        }

        total *= score;
    }

    std::cout << total << "\n";
    return 0;
}