시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB47171551.724%

문제

N개의 꼭짓점을 가진 단순 다각형 (Simple Polygon)이 무한한 사각 격자판에 그려져 있다. 단순 다각형은, 두 개의 인접한 변이 오직 하나의 공통된 꼭짓점을 지나고, 이러한 변이 아니라면 교차하거나, 접하지 않는다. 모든 꼭짓점은 정수 좌표를 가진다.

이러한 다각형이 주어지면, 다각형 내부에 격자 선분의 길이를 구하면 된다.

입력

첫째 줄에 꼭짓점의 개수 N이 주어진다. 둘째 줄부터 N개의 줄에는 두 정수 x와 y가 주어진다. 이 좌표는 하나의 꼭짓점이다. 꼭짓점은 시계방향 또는 반시계 방향으로 주어지며, 모든 꼭짓점은 서로 다르다.

출력

첫째 줄에, 다각형 내부의 격자 선분의 길이를 출력하면 된다.

정답과의 절대/상대 오차는 10-6까지 허용된다.

제한

  • 3 ≤ N ≤ 100 000
  • −500 000 000 ≤ x, y ≤ 500 000 000

예제 입력 1

3
5 1
2 4
1 1

예제 출력 1

10.0

예제 입력 2

5
0 0
-2 2
-2 -1
2 -2
2 0

예제 출력 2

12.5

W3sicHJvYmxlbV9pZCI6IjI0MjkiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWFlMzhcdWM3NzQiLCJkZXNjcmlwdGlvbiI6IjxwPk5cdWFjMWNcdWM3NTggXHVhZjJkXHVjOWQzXHVjODEwXHVjNzQ0IFx1YWMwMFx1YzljNCBcdWIyZThcdWMyMWMgXHViMmU0XHVhYzAxXHVkNjE1IChTaW1wbGUgUG9seWdvbilcdWM3NzQgXHViYjM0XHVkNTVjXHVkNTVjIFx1YzBhY1x1YWMwMSBcdWFjYTlcdWM3OTBcdWQzMTBcdWM1ZDAgXHVhZGY4XHViODI0XHVjODM4IFx1Yzc4OFx1YjJlNC4gXHViMmU4XHVjMjFjIFx1YjJlNFx1YWMwMVx1ZDYxNVx1Yzc0MCwgXHViNDUwIFx1YWMxY1x1Yzc1OCBcdWM3NzhcdWM4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