Under construction

Still being built. Things may change

Color Weakness

Interview

Time limit1sMemory limit128 MB

Summary
Count connected R, G, B regions in an N by N grid twice, once normally and once with R and G merged.
Level

Easy3 of 10

Topics
BFS, Matrix
Solved
No attempts yet

Problem

People with red-green color weakness barely distinguish red from green. The regions they see in a picture can differ from what others see.

Each cell of an N×NN \times N grid is painted R (red), G (green), or B (blue). A region is a set of cells connected through up, down, left, or right adjacency with the same color. For color-weak vision, R and G count as the same color.

Given the picture, output the number of regions for normal vision and for color-weak vision.

Input

  • Line 1: integer NN (1≤N≤1001 \le N \le 100).
  • Next NN lines: the N×NN \times N picture.

Output

Print two integers separated by a space: region counts for normal vision and for color-weak vision.

Examples6

  1. Example 1

    Input
    5
    RRRBB
    GGBBB
    BBBRR
    BBRRR
    RRRRR
    
    Expected output
    4 3
    
  2. Example 2

    Input
    1
    R
    
    Expected output
    1 1
    
  3. Example 3

    Input
    2
    RG
    GR
    
    Expected output
    4 1
    
  4. Example 4

    Input
    3
    RBR
    GRG
    GGB
    
    Expected output
    7 3
    
  5. Example 5

    Input
    4
    RRRG
    RBBG
    GBRB
    RBBR
    
    Expected output
    8 5
    
  6. Example 6

    Input
    6
    RBBRGB
    GBBRBR
    GGBRRB
    GBBGGB
    RRBRBG
    BRBRRB
    
    Expected output
    16 11