eolymp
bolt
Try our new interface for solving problems

Vectors

Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB

On the plane, given a set of points (x, y), where x and y – integer, 1xM, 1yN. With each point out exactly one of the following vectors: (-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1). Each vector connects one integer point of the plane with another. For example, if the point (2, 5) leaves the vector (1, 1), it connects this point with the (3, 6), but not vice versa.

Sequence of two or more points in the plane a_1, a_2, , a_k is called a cycle if each point a_i is joined to a vector a_i_{+1} (1i k-1), and a_k is connected with the vector a_1. Cycles are considered different if they differ by at least one vertex.

Write a program that according to the vectors coming out of the plane, finds a number of different cycles.

Giriş verilənləri

The first line contains two integers N (1N 100) and M (1M 100). Each of the subsequent N lines contains M pairs (ie, 2×M numbers). A pair of x, which is in line y defines a vector at (x, y).

Ouput

Print one integer - the number of cycles formed by the vectors.

Nümunə

Giriş verilənləri #1
2 4 
-1 1 -1 1 -1 0 0 1
1 0 1 0 0 -1 0 -1
Çıxış verilənləri #1
2
Müəllif Shamil Yagiyayev
Mənbə 2004 XVII All-Ukrainian Informatics Olympiad, Kharkov, March 28 - April 3, Round 1