Tanya loves Painting

0

0 votes
Problem

Tanya loves painting from her very childhood. She had just bought a square white canvas which is like a grid of size NxN. Each cell of grid is of size 1x1 and is denoted by a pair (x, y) called the index of the cell, where x is the row number of the grid and y is the column number of the grid. The rows are numbered from top to bottom from 1 to N while the columns are numbered from left to right from 1 to N.

Tanya is actually bored of the conventional painting style, she finds all those brushes and paint color messy. So she tries some crazy idea to paint the canvas by pasting rectangular pieces of paper on the canvas.

To perform one such paste Tanya first marks two cells on the grid of the canvas and then cuts out a piece of paper of either black or white color and of the same size that fits into the rectangle marked by the two cells.

She pastes K such pieces of paper. After painting the canvas in the above manner, Tanya went to play with her friends. Meanwhile her little sister Rosy saw the wonderful painting of Tanya and began counting the total number of white cells on the painting. As Rosy was too young and the canvas could be very big, help Rosy count the number of white cells in the painting.

NOTE: The two cells marked by the Tanya will not be in the same row or column.

Input:

The first line consists of 2 numbers N and K, the dimension of the canvas and the number of papers Tanya pastes on the canvas respectively. K lines follow.

Each of the next K lines consist of x1, y1, x2, y2, c where (x1, y1) and (x2, y2) are the indexes of the two cells Tanya marks on the grid of canvas, and c is a symbol either 'b' or 'w' ('b' stands for black and 'w' stands for white)

Output:

The number of white cells after all pasting K pieces of paper.

Constraints:

1 <= N <= 1000

1 <= K <= 3000

1 <= x1, y1, x2, y2 <= N

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Finaly the canvas looks like this and hence the answer is 7

b b b w

b b w w

b b w w

b b w w

Editor Image

?