```go
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
r := bufio.NewReader(os.Stdin)
n := readInt(r)
if n < 4 {
fmt.Println(0)
return
}
type Point struct {
x, y int
}
points := make([]Point, n)
cols := make([][]int, 100005)
rows := make([][]int, 100005)
pointsMap := make(map[int64]struct{}, n)
for i := 0; i < n; i++ {
x := readInt(r)
y := readInt(r)
points[i] = Point{x, y}
cols[x] = append(cols[x], y)
rows[y] = append(rows[y], x)
pointsMap[int64(x)<<32|int64(y)] = struct{}{}
}
ans := 0
for _, p := range points {
x, y := p.x, p.y
if len(cols[x]) < len(rows[y]) {
for _, y2 := range cols[x] {
if y2 > y {
d := y2 - y
if _, ok := pointsMap[int64(x+d)<<32|int64(y)]; ok {
if _, ok := pointsMap[int64(x+d)<<32|int64(y2)]; ok {
ans++
}
}
}
}
} else {
for _, x2 := range rows[y] {
if x2 > x {
d := x2 - x
if _, ok := pointsMap[int64(x)<<32|int64(y+d)]; ok {
if _, ok := pointsMap[int64(x2)<<32|int64(y+d)]; ok {
ans++
}
}
}
}
}
}
fmt.Println(ans)
}
func readInt(r *bufio.Reader) int {
var n int
var c byte
var err error
for {
c, err = r.ReadByte()
if err != nil {
return 0
}
if c >= '0' && c <= '9' {
break
}
}
n = int(c - '0')
for {
c, err = r.ReadByte()
if err != nil || c < '0' || c > '9' {
break
}
n = n*10 + int(c-'0')
}
return n
}
```