#K9801. Battleship Hits Counter

    ID: 39110 Type: Default 1000ms 256MiB

Battleship Hits Counter

Battleship Hits Counter

You are given a grid of size \(N \times M\). In this grid, several battleships have been placed. Each battleship is positioned either horizontally or vertically and is described by its starting and ending coordinates \((r_1, c_1)\) and \((r_2, c_2)\). All coordinates are 1-indexed.

You are also given a list of guesses, where each guess is a coordinate on the grid. A guess counts as a hit if it falls on any cell occupied by a battleship. Your task is to count the total number of hits.

Note: Ships are guaranteed to be either horizontal (i.e., \(r_1 = r_2\)) or vertical (i.e., \(c_1 = c_2\)).

inputFormat

The input is provided via standard input (stdin) in the following format:

  1. The first line contains two integers \(N\) and \(M\), representing the number of rows and columns of the grid.
  2. The second line contains an integer \(S\), the number of ships.
  3. The next \(S\) lines each contain four integers \(r_1\), \(c_1\), \(r_2\), \(c_2\) representing a ship's starting and ending coordinates.
  4. The following line contains an integer \(G\), the number of guesses.
  5. The next \(G\) lines each contain two integers \(r\) and \(c\) denoting the coordinates of a guess.

outputFormat

Output a single integer on standard output (stdout): the total number of hits. A hit is counted if a guess corresponds to any cell occupied by a ship.

## sample
8 8
3
1 2 1 4
2 3 2 5
4 5 6 5
5
1 2
2 4
4 5
4 6
1 3
4