eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Meteorite

Meteorite

Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB

The Ministry of Emergency Situations (MES) was informed about the fall of a large meteorite that exploded in the atmosphere. The employees promptly examined the impact site and mapped the affected area in detail.

It turned out that the affected area is bounded by a complex-shape polygon M. Unfortunately, there is a large city in this area. The boundaries of the city also represent a polygon, G. It is natural to expect that the major damage requiring the intervention of MES occurred at the intersection of polygons M and G.

As an urgent measure, it was decided to calculate the number of separate parts of the city falling into the major damage zone. Note that none of the vertices of polygons M and G lies on the boundary of another polygon.

Write a program that calculates the number of parts in the intersection of polygons M and G.

Вхідні дані

The first line contains integer N, the number of vertices in polygon M. The following N lines contain the coordinates of the vertices of M in the order of contour traversal. Coordinate values are separated with one or several space characters.

The next line contains integer K, the number of vertices in G, and the following K lines contain the coordinates of its vertices.

3N, K300. All coordinates are non-negative integers not exceeding 32000.

Вихідні дані

Output a single number – the count of separate parts in the intersection of polygons M and G.

Приклад

Вхідні дані #1
4
0 0
3 5
7 1
4 3
3
2 2
2 0
7 2
Вихідні дані #1
2
Джерело 2013-2014 ACM Central Region of Russia Quarterfinal, Rybinsk 2013/10/17