Under construction

Still being built. Things may change

Candles and Shadows

Time limit1sMemory limit512 MB

Summary
Given a convex red polygon that contains a convex blue polygon, find the shadow area cast by the blue polygon for each candle position.
Level

Hard8 of 10

Topics
Geometry, Binary search, Math
Solved
No attempts yet

Problem

A red convex polygon with NN vertices (A1,B1),(A2,B2),⋯ ,(AN,BN)(A_1, B_1), (A_2, B_2), \cdots, (A_N, B_N) and a blue convex polygon with MM vertices (C1,D1),(C2,D2),⋯ ,(CM,DM)(C_1, D_1), (C_2, D_2), \cdots, (C_M, D_M) are given. As the figure shows, the blue polygon lies completely inside the red polygon.

Figure 1. A red polygon containing a blue polygon

Let SS be the region inside the red polygon that is not inside or on the boundary of the blue polygon. As the figure shows, placing a candle at a point of SS lights the yellow region, and the gray region casts a shadow.

Figure 2. The lit region and the shadow region

Given the polygons and the position of the candle, write a program that computes the area of the shadow region.

Input

The first line contains three positive integers NN, MM, and QQ, separated by spaces. They are the number of vertices of the red polygon, the number of vertices of the blue polygon, and the number of queries.

The next NN lines give the vertices of the red polygon in counterclockwise order. Line (i+1)(i+1) contains two integers AiA_i and BiB_i separated by a space (1≤i≤N1 \le i \le N).

Starting from line (N+2)(N+2), the next MM lines give the vertices of the blue polygon in counterclockwise order. Line (N+i+1)(N+i+1) contains two integers CiC_i and DiD_i separated by a space (1≤i≤M1 \le i \le M).

Starting from line (N+M+2)(N+M+2), the next QQ lines describe the queries. Line (N+M+i+1)(N+M+i+1) contains two integers XiX_i and YiY_i, meaning that in the ii-th query the candle is placed at (Xi,Yi)(X_i, Y_i). All QQ queries are independent of each other.

Output

Print the answer to each query on its own line, in order.

If the candle is outside the red polygon or on its boundary, print OUT.

If the candle is inside the blue polygon or on its boundary, print IN.

Otherwise, print the area of the shadow region. An absolute or relative error up to 10−610^{-6} is allowed.

Constraints

All input data satisfy the following conditions.

  • 3≤N≤1053 \le N \le 10^5
  • 3≤M≤1053 \le M \le 10^5
  • 1≤Q≤1051 \le Q \le 10^5
  • −106≤Ai≤106-10^6 \le A_i \le 10^6 (1≤i≤N1 \le i \le N)
  • −106≤Bi≤106-10^6 \le B_i \le 10^6 (1≤i≤N1 \le i \le N)
  • −106≤Ci≤106-10^6 \le C_i \le 10^6 (1≤i≤M1 \le i \le M)
  • −106≤Di≤106-10^6 \le D_i \le 10^6 (1≤i≤M1 \le i \le M)
  • −106≤Xi≤106-10^6 \le X_i \le 10^6 (1≤i≤Q1 \le i \le Q)
  • −106≤Yi≤106-10^6 \le Y_i \le 10^6 (1≤i≤Q1 \le i \le Q)

Examples1

  1. Example 1

    Input
    4 4 3
    -4 -4
    4 -4
    4 4
    -4 4
    -1 -1
    1 -1
    1 1
    -1 1
    0 0
    3 3
    6 6
    
    Expected output
    IN
    16.5
    OUT