Under construction

Still being built. Things may change

Tangram

Time limit8sMemory limit512 MB

Summary
Given a simple polygon whose edges run horizontally, vertically, or diagonally, decide whether all seven tangram pieces can tile it without overlap.
Level

Hard8 of 10

Topics
Backtracking, Geometry, Implementation
Solved
No attempts yet

Problem

Chen, your pretty sister, has been stuck on a tangram puzzle for an hour and came to you for help. The tangram is a puzzle rooted in China. The goal is to form a given shape using all seven pieces. Each piece can be placed anywhere, and rotated and flipped in any way, but pieces cannot overlap.

The seven pieces are:

  • Two small right triangles (edge lengths 25225\sqrt{2}, 25225\sqrt{2}, and 5050)
  • One medium right triangle (edge lengths 5050, 5050, and 50250\sqrt{2})
  • Two big right triangles (edge lengths 50250\sqrt{2}, 50250\sqrt{2}, and 100100)
  • One square (side length 25225\sqrt{2})
  • One parallelogram (side lengths 25225\sqrt{2} and 5050)

Given the shape of a polygon PP, determine whether PP can be made by using all seven pieces. You may assume the following.

  • Each edge of PP is parallel to the xx-axis, the yy-axis, the line y=xy = x, or the line y=−xy = -x.
  • PP is connected and has no hole. PP is a simple polygon, so its edges do not cross or touch each other.

Input

The first line contains an integer NN (3≤N≤303 \le N \le 30), the number of vertices of PP. Each of the next NN lines gives a vertex of PP in clockwise order. Each line contains four non-negative integers aa, bb, cc, and dd, separated by spaces. The vertex is at (a+b2,c+d2)(a + b\sqrt{2}, c + d\sqrt{2}). No coordinate exceeds 1000.

Output

Print "Yes" on a line if PP can be made with the seven pieces. Otherwise, print "No".

Examples2

  1. Example 1

    Input
    4
    0 0 0 0
    0 0 100 0
    100 0 100 0
    100 0 0 0
    
    Expected output
    Yes
    
  2. Example 2

    Input
    4
    0 50 0 0
    0 0 0 50
    0 50 0 100
    0 100 0 50
    
    Expected output
    Yes