JZPFOR - Formula 3D

There are n lattice points in the 3D space. One point can get to another if and only if their Euclid distance is 1. Find out the number of simple cycles (that has length > 2). The number of points with same x coordinates do not exceed 8. 

Input

First line, n. 

Following are n lines, each describes one point, no two points share same coordinates. 

n<=400, coordinates in range [-10^9, 10^9] (inclusive).

Output

One number, the required answer mod 1000000007. 

Example

Input:
8
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1

Output:
28

Added by:sevenkplus
Date:2011-06-29
Time limit:0.100s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:own problem

hide comments
2022-08-23 11:50:39 [Rampage] Blue.Mary
In my opinion this kind of problem should use multiple test cases and longer time limit rather than 0.1 second for each test.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.