ASCII Figure

Time limit1sMemory limit128 MB

Summary
Given a grid picture drawn with '.', '/', and '\' forming one closed polygon from diagonal cell segments, compute the polygon's area.
Level

Medium5 of 10

Topics
Geometry, Matrix, Simulation
Solved
No attempts yet

Problem

A single closed polygon is drawn on a grid using three characters: ., /, and \. Each character represents one 1x1 unit square in the picture.

  • . is an empty cell.
  • / is the diagonal segment joining that cell's bottom-left corner to its top-right corner.
  • \ is the diagonal segment joining that cell's top-left corner to its bottom-right corner.

These diagonal segments connect to form one closed polygon. Write a program that computes the area of the drawn polygon.

Input

The first line contains the picture's height h and width w, separated by a space. (2 <= h, w <= 100)

Each of the next h lines contains w characters (., /, \) describing the picture.

The picture contains exactly one polygon; no two edges cross, and the polygon does not touch itself.

Output

Print the area of the polygon as an integer on the first line.

Examples3

  1. Example 1

    Input
    4 4
    /\/\
    \../
    .\.\
    ..\/
    
    Expected output
    8
    
  2. Example 2

    Input
    2 2
    /\
    \/
    
    Expected output
    2
    
  3. Example 3

    Input
    4 4
    ./\.
    /..\
    \../
    .\/.
    
    Expected output
    8