TSS '19 CC P3 - Counting Squares

View as PDF

Submit solution

Points: 7
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Given N horizontal lines and M vertical lines, count the number of squares in the grid. For example, a horizontal line could be y = 3 or y = 1, etc. Furthermore, vertical lines could be x = 2 or x = 5. The lines of the cartesian grid will never start at a negative position in both the y-axis and x-axis.

The whole boundary of the square has to be drawn. The inside of the square does not have to be empty.

Input Specification

The first line of input will contain 2 integers, N and M (0 \le N, M \le 1200).

The next line of input will contain N integers a_i, indicating that the line y = a_i exists.

The next line of input will contain M integers b_i, indicating that the line x = b_i exists.

0 \le a_i, b_i \le 10^5

Output Specification

Output the total number of squares.

Sample Input

3 4
0 1 3
1 2 4 8

Sample Output

3

There is one 1 \times 1 square, one 2 \times 2 square, and one 3 \times 3 square.


Comments

There are no comments at the moment.