← Home
```go
package main

import (
	"bufio"
	"fmt"
	"os"
)

const hashSize = 1 << 19

var hashKeys [hashSize]int64

func hash(k int64) int {
	k ^= k >> 32
	k *= 0x85ebca6b
	k ^= k >> 13
	k *= 0xc2b2ae35
	k ^= k >> 16
	return int(k & (hashSize - 1))
}

func insert(x, y int32) {
	k := (int64(x+1) << 32) | int64(y+1)
	idx := hash(k)
	for hashKeys[idx] != 0 && hashKeys[idx] != k {
		idx = (idx + 1) & (hashSize - 1)
	}
	hashKeys[idx] = k
}

func exists(x, y int32) bool {
	if x < 0 || x > 100000 || y < 0 || y > 100000 {
		return false
	}
	k := (int64(x+1) << 32) | int64(y+1)
	idx := hash(k)
	for {
		if hashKeys[idx] == k {
			return true
		}
		if hashKeys[idx] == 0 {
			return false
		}
		idx = (idx + 1) & (hashSize - 1)
	}
}

type Point struct {
	x, y int32
}

var R [100005][]int32
var C [100005][]int32
var points []Point

func getInt(r *bufio.Reader) int32 {
	c, err := r.ReadByte()
	for err == nil && c <= ' ' {
		c, err = r.ReadByte()
	}
	if err != nil {
		return 0
	}
	var res int32 = 0
	for err == nil && c > ' ' {
		res = res*10 + int32(c-'0')
		c, err = r.ReadByte()
	}
	return res
}

func main() {
	r := bufio.NewReaderSize(os.Stdin, 65536)
	n := getInt(r)
	if n == 0 {
		return
	}
	points = make([]Point, n)
	for i := int32(0); i < n; i++ {
		x := getInt(r)
		y := getInt(r)
		points[i] = Point{x, y}
		R[y] = append(R[y], x)
		C[x] = append(C[x], y)
		insert(x, y)
	}

	ans := int64(0)
	for _, p := range points {
		x, y := p.x, p.y
		if len(R[y]) <= len(C[x]) {
			for _, x2 := range R[y] {
				if x2 > x {
					d := x2 - x
					if exists(x, y+d) && exists(x2, y+d) {
						ans++
					}
				}
			}
		} else {
			for _, y2 := range C[x] {
				if y2 > y {
					d := y2 - y
					if exists(x+d, y) && exists(x+d, y2) {
						ans++
					}
				}
			}
		}
	}
	fmt.Println(ans)
}
```