## CEOI '19 Practice P1 - Count Squares

View as PDF

Points: 7 (partial)
Time limit: 1.8s
Memory limit: 512M

Problem type

Alice took a clean sheet of paper and drew horizontal and vertical lines onto the paper.

The horizontal lines have -coordinates , and the vertical lines have -coordinates .

Given these coordinates, count the number of squares that appeared on the paper.

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

#### Input

The first line of input contains the integers and .

The second line of input contains a strictly increasing sequence consisting of space-separated integers: .

The third line of input contains a strictly increasing sequence consisting of space-separated integers: .

All horizontal and vertical coordinates are between and , inclusive.

#### Output

Output a single line with a single integer: the total number of squares.

#### Sample Input

3 4
0 1 3
1 2 4 8

#### Sample Output

3

#### Note

In the example there is one square, one square, and one square.