АВТ
Язык:

Дистанционный практикум по программированию

Задачи Online статус Соревнования
Новости Справка СДО
 
Здравствуйте, Гость! Войдите с паролем или зарегистрируйтесь.

1261. Meteorite

Ограничение времени: 1 сек.
Ограничение памяти:65536 КБайт
Баллы:100
Статистика Послать на проверку Задачу добавил debug

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.

 

Input

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.

 

Output

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

 

Limitations

3 ≤ N, K ≤ 300

All coordinates are non-negative integers not exceeding 32000.

 

Example

Input

Output

4

0 0

3 5

7 1

4 3

3

2 2

2 0

7 2

2

 

All Rybinsk-2013 problems

Статистика Послать на проверку Обсуждение задачи Автор/источник:
Задачи с соревнований и сборов / Чемпионат мира по программированию (ICPC) / Рыбинск-2013 /
1260. I - Klingon Battle Bagel 1261. 1262. K - Triangles
 
время генерации 0.14 сек.
© Copyright ВоГУ, АВТ, Носов Д.А., Андрианов И.А.