## CEOI '19 Practice P1 - Count Squares

View as PDF

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

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

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.

3 4
0 1 3
1 2 4 8

3

#### Note

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