This page is still under construction.

Parts of this page are still being built. What you see may change.

Holstein Fence

Time limit1sMemory limit256 MB

Summary
Enclose the most Holsteins in an axis-aligned rectangle with no Guernsey inside, breaking ties by smallest area.
Level

Medium6 of 10

Topics
Brute force, Sorting, Geometry
Solved
No attempts yet

Problem

There are NN cows (1≤N≤5001 \le N \le 500) standing on the plane at distinct points. Each cow is either a Holstein or a Guernsey.

The farmer wants to build a rectangular fence with sides parallel to the coordinate axes so that it encloses only Holsteins and no Guernsey at all. A cow on the boundary of the fence counts as enclosed.

Among all such fences, pick the one that encloses the most Holsteins, and among those, pick the one with the smallest area. Report the number of enclosed Holsteins and that area. A fence of width or height 00 is allowed.

Input

The first line contains NN.

Each of the next NN lines contains two integers xx, yy (0≤x,y≤10000 \le x, y \le 1000) and one character. (x,y)(x, y) is where the cow stands, and the character gives the breed: H for a Holstein, G for a Guernsey.

No two cows stand at the same point, and at least one cow is a Holstein.

Output

On the first line, print the maximum number of Holsteins that a fence enclosing no Guernsey can enclose.

On the second line, print the smallest area among those fences.

Examples3

  1. Example 1

    Input
    5
    1 1 H
    2 2 H
    3 3 G
    4 4 H
    6 6 H
    
    Expected output
    2
    1
    
  2. Example 2

    Input
    1
    0 0 H
    
    Expected output
    1
    0
    
  3. Example 3

    Input
    7
    0 0 H
    1 0 H
    0 1 H
    5 5 G
    10 10 H
    20 10 H
    10 20 H
    
    Expected output
    3
    1