Meteor Shower


Submit solution

Points: 1
Time limit: 1.5s
Memory limit: 256M

Author:
Problem type
Allowed languages
C++, Java, Python

BOOM! POW! CRACK!

As your rocket rapidly escapes Earth, you find yourself racing through the asteroid belt — your rocket's hull pelted with flying chunks of stone. You didn't think the asteroid belt was so dense! Either way, you need to stop your ship from breaking apart!

The side of your skip is represented as an n \times m grid. A sequence of n events occur. Either:

  1. HIT x1 y1 x2 y2: An asteroid will strike the rectangular patch on your ship between (x_1, y_1) (top-left corner) and (x_2, y_2) (bottom-right corner), dealing 1 damage to each cell in the patch.

  2. SCAN x1 y1 x2 y2: You scan the rectangular patch on your ship between (x_1, y_1) (top-left corner) and (x_2, y_2) (bottom-right corner), reporting how much total damage their is to this area.

You need to stay on top of things. Handle all the events, and you might just survive!

Input

The first line consists of two integers n (2 \leq n \leq 500) and m (2 \leq m \leq 500), the size of your rocket's hull.

The next line consists of a single integer v (1 \leq v \leq 10^4), the number of events that will occur.

The next v lines describe the events in the order they occur. They are in one of the two forms described above:

  • HIT x1 y1 x2 y2
  • SCAN x1 y1 x2 y2

where (0 \leq x_1, x_2 \leq n-1) and (0 \leq y_1, y_2 \leq m-1).

Output

For each SCAN query, output the total amount of damage to your rocket in the scanned patch.\

Fixes

  • Maximal cases have been added to this question to filter out brute-force submissions.

Example

Input 1
3 3
6
SCAN 0 0 2 2
HIT 0 0 1 1
HIT 0 2 2 2
SCAN 1 1 2 2
HIT 1 1 2 2
SCAN 0 0 1 2
Output 1
0
3
8

See below for how the events are processed.

Input 2
4 4
5
HIT 0 0 3 3
SCAN 0 0 3 3
HIT 1 1 1 1
HIT 2 2 2 2
SCAN 0 0 3 3
Output 2
16
18

Comments

There are no comments at the moment.