QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 10

#11659. Polygons

Statistics

Yesterday Little John had a test on geometry. The description of the most difficult problem follows. Given two triangles $ A $ and $ B $, calculate the area of region $ A + B $, which is defined as follows: $ A + B = \{p_{1} + p_{2} : p_{1} \in A, p_{2} \in B\}$. For example, if $ A $ has the vertices (0, 0), (0, 2), (2, 0) and $ B $ has the vertices (0, 0), (0, 1), (3, 0), then $ A $ + $ B $ is a polygon with the vertices (0, 0), (0, 3), (3, 2) and (5, 0), so its area is 9.5.

Afterwards, John started to wonder how to solve a modified problem - "How to calculate area of $ A + B $, if $ A $ and $ B $ are arbitrary convex polygons". Little John has a test on biology tomorrow and has no time to solve this problem himself. He asked you for help in solving this task.

Write a program, which:

  • reads the descriptions of two convex polygons $ A $ and $ B $,
  • computes the area of $ A + B $,
  • writes it doubled to the standard output.

Input Format

The first line of the standard input contains two integers $ n $ and $ m $ ($3 ≤ n, m ≤ 100\,000$) separated with a single space and denoting the numbers of vertices of polygons $ A $ and $ B $. In the second line there are $ n $ pairs of integers ($ x_{i} $, $ y_{i} $) ($-100\,000\,000 ≤ x_{i}, y_{i} ≤ 100\,000\,000$), denoting the coordinates of consecutive vertices of the polygon $ A $ (in the clockwise order). In the third line there are $ m $ pairs of integers $(x_i, y_i)$ ($-100\,000\,000 ≤ x_{i}, y_{i} ≤ 100\,000\,000$) denoting the coordinates of consecutive vertices of the polygon $ B $ (in the clockwise order).

Output Format

The first and only line should contain one integer - doubled area of $ A + B $.

Example

Input

4 4
0 0 0 1 2 1 2 0
0 0 0 2 1 2 1 0

Output

18
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.