Under construction

Still being built. Things may change

Gadget Construction

Time limit1sMemory limit1024 MB

Summary
Count subsets of at least 4 cogs whose convex hull alternates colors around its vertices, with interior cogs of any color, modulo 1e9+7.
Level

Hard8 of 10

Topics
Geometry, Dynamic programming, Combinatorics
Solved
No attempts yet

Statement

Grigory is an engineer who loves developing drones and geometry. He solves most problems himself, but today he faces one that his skills alone cannot solve. You are his best sidekick, and your task is to help him.

There are nn cogs on the Cartesian plane. The ii-th cog is at (xi,yi)(x_i, y_i) and has color cic_i. If cic_i is b, the cog is black. If cic_i is w, the cog is white. No three cogs lie on the same line.

Grigory chooses a subset SS of 44 or more of the nn cogs. He then places a loop of chains around the cogs. The loop satisfies two conditions. Every cog in SS either touches the loop or lies inside it. The total length of the chains is minimal.

Consider the cogs in SS that touch the loop. Any two cogs that are adjacent on the loop must have different colors, or the gadget does not work. A cog in SS that does not touch the loop may have any color.

How many different sets SS can Grigory choose to build a properly working gadget? Since the answer can be very large, print it modulo 109+710^9+7.

Input

The first line contains an integer nn. Each of the next nn lines contains two integers xix_i, yiy_i and a character cic_i, which give the coordinates and color of the ii-th cog.

Output

Print the number of valid sets SS modulo 109+710^9+7.

Constraints

4≤n≤5004 \le n \le 500. For every ii, −108≤xi,yi≤108-10^8 \le x_i, y_i \le 10^8, and cic_i is b or w. For i≠ji \ne j, (xi,yi)≠(xj,yj)(x_i, y_i) \ne (x_j, y_j). No three cogs lie on the same line.

Examples3

  1. Example 1

    Input
    4
    0 0 w
    1 0 b
    1 1 w
    0 1 b
    
    Expected output
    1
    
  2. Example 2

    Input
    6
    0 0 w
    0 4 b
    1 2 w
    3 2 b
    4 0 b
    4 4 w
    
    Expected output
    9
    
  3. Example 3

    Input
    4
    0 0 b
    1 0 w
    1 1 w
    0 1 b
    
    Expected output
    0