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
163
164
165
166
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

struct point {
    int x, y;
};

void fill(int x, int y, map<int, map<int, int>> &level_map_to_fill) {
    if (level_map_to_fill[x][y] != 0) return;
    level_map_to_fill[x][y] = 1;
    //cout << level_map_to_fill[x][y] << " ";
    fill(x - 1, y, level_map_to_fill);
    fill(x + 1, y, level_map_to_fill);
    fill(x, y - 1, level_map_to_fill);
    fill(x, y + 1, level_map_to_fill);
}

void fill_up(int x, int y, map<int, map<int, int>> &level_map_to_fill) {
    if (level_map_to_fill[x][y] == 0) {
        return;
    }
    //if (level_map_to_fill[x][y] != 0) return;
    //level_map_to_fill[x][y]++;
    //cout << level_map_to_fill[x][y] << " ";

    if (level_map_to_fill[x][y + 1] >= level_map_to_fill[x][y]) {
        fill_up(x, y + 1, level_map_to_fill);
        level_map_to_fill[x][y]++;
    }
    if (level_map_to_fill[x+1][y] >= level_map_to_fill[x][y]) {
        fill_up(x+1, y, level_map_to_fill);
    } else return;

    //fill(x - 1, y, level_map_to_fill);
    //fill(x + 1, y, level_map_to_fill);
    //fill(x, y - 1, level_map_to_fill);
    //fill(x, y + 1, level_map_to_fill);
}


int main() {
    int n;
    cin >> n;
    int min_x = 0, min_y = 0;
    int max_x = 0, max_y = 0;
    vector<vector<point>> points(n);
    for (int count = 0; count < n; count++) {
        int temp;
        cin >> temp;
        temp /= 2;
        vector<point> temp_points;
        for (int count1 = 0; count1 < temp; count1++) {
            int temp1, temp2;
            cin >> temp1 >> temp2;
            point temp_point;
            temp_point.x = temp1;
            temp_point.y = temp2;
            temp_points.push_back(temp_point);
            max_x = max(max_x, temp1);
            max_y = max(max_y, temp2);
            min_x = min(min_x, temp1);
            min_y = min(min_y, temp2);
        }
        points[count] = temp_points;
    }
    vector<map<int, map<int, int >>> map_level(n);

    for (int count = 0; count < n; count++) {
        for (int countx = min_x - 1; countx <= max_x + 1; countx++) {
            map<int, int> temp_map;
            for (int county = min_y - 1; county <= max_y + 1; county++) {
                if ((countx == min_x - 1 || countx == max_x + 1) || (county == min_y - 1 || county == max_y + 1)) {
                    temp_map[county] = -1;
                } else temp_map[county] = 0;
            }
            map_level[count][countx] = temp_map;
        }
    }

    for (int count = 0; count < n; count++) {
        for (int count_point = 0; count_point < points[count].size(); count_point++) {
            point start_point = points[count][count_point];
            point end_point;
            if (count_point + 1 == points[count].size()) {
                end_point = points[count][0];
            } else {
                end_point = points[count][count_point + 1];
            }

            if (start_point.x > end_point.x) {
                for (int countx = start_point.x; countx >= end_point.x; countx--) {
                    map_level[count][countx][start_point.y] = 1;
                }
                if (start_point.y > end_point.y) {
                    for (int county = start_point.y; county >= end_point.y; county--) {
                        map_level[count][end_point.x][county] = 1;
                    }
                } else if (start_point.y < end_point.y) {
                    for (int county = start_point.y; county <= end_point.y; county++) {
                        map_level[count][end_point.x][county] = 1;
                    }
                }
            }
            if (start_point.x < end_point.x) {
                for (int countx = start_point.x; countx <= end_point.x; countx++) {
                    map_level[count][countx][start_point.y] = 1;
                }
                if (start_point.y > end_point.y) {
                    for (int county = start_point.y; county >= end_point.y; county--) {
                        map_level[count][end_point.x][county] = 1;
                    }
                } else if (start_point.y < end_point.y) {
                    for (int county = start_point.y; county <= end_point.y; county++) {
                        map_level[count][end_point.x][county] = 1;
                    }
                }
            }
        }
        //map_level[count][points[count][0].x][points[count][0].y] = 0;
        fill(points[count][0].x + 1, points[count][0].y + 1, map_level[count]);
    }

    map<int, map<int, int>> map_end;

    for (int count = 0; count < n; count++) {
        for (int countx = min_x; countx <= max_x; countx++) {
            for (int county = min_y; county <= max_y; county++) {
                map_end[countx][county] += map_level[count][countx][county];
            }
        }
    }


    for (int countx = min_x + 1; countx < max_x - 1; countx++) {
        for (int county = min_y + 1; county < max_y - 1; county++) {
            //cout << map_end[countx][county] << " ";
            if ((map_end[countx - 1][county - 1] >= map_end[countx][county]) &&
                (map_end[countx][county - 1] >= map_end[countx][county]) &&
                (map_end[countx - 1][county] >= map_end[countx][county])) {
                fill_up(countx, county, map_end);
                break;
            }
        }
        //cout << '\n';
    }

    /*for (int countx = min_x; countx <= max_x; countx++) {
        for (int county = min_y; county <= max_y; county++) {
            cout << map_end[countx][county] << " ";
        }
        cout << '\n';
    }*/
    int max_out = 0;
    for (int countx = min_x; countx <= max_x; countx++) {
        for (int county = min_y; county <= max_y; county++) {
            max_out = max(max_out, map_end[countx][county]);
        }
        //cout << '\n';
    }
    cout << max_out << '\n';
    return 0;
}