#165Medium
Forest queries
Time: 1 s · Memory: 256 MB
- Prefix sums
Statement
You are given an map of a forest: * is a tree, . is empty. Rows are numbered from top to bottom and columns from left to right, from to . For every query find the number of trees in a rectangle.
Input format
The first line contains and (, ). The next lines contain the map. The next lines contain , , , (, ) — the top-left and bottom-right cells of the rectangle (row, column).
Output format
For every query print one number on a separate line.
Examples
Input
4 3 .*.. *.** **.. **** 2 2 3 4 3 1 3 1 1 1 2 2
Output
3 1 2
Note
2D prefix sums: is the number of trees in the rectangle from to , . A query is answered by inclusion–exclusion: .
Counting cells in every query is — operations.
Source: CSES, problem 1652.
