← Home
```go
package main

import (
	"fmt"
	"io"
	"math/big"
	"math/bits"
	"os"
	"sort"
)

type Uint128 struct {
	hi uint64
	lo uint64
}

func add128(a, b Uint128) Uint128 {
	lo := a.lo + b.lo
	hi := a.hi + b.hi
	if lo < a.lo {
		hi++
	}
	return Uint128{hi, lo}
}

func mul64(a, b uint64) Uint128 {
	hi, lo := bits.Mul64(a, b)
	return Uint128{hi, lo}
}

func sqSum(x, y int64) Uint128 {
	ux := uint64(x)
	if x < 0 {
		ux = uint64(-x)
	}
	uy := uint64(y)
	if y < 0 {
		uy = uint64(-y)
	}

	x2 := mul64(ux, ux)
	y2 := mul64(uy, uy)
	return add128(x2, y2)
}

func cmp128(a, b Uint128) int {
	if a.hi > b.hi {
		return 1
	}
	if a.hi < b.hi {
		return -1
	}
	if a.lo > b.lo {
		return 1
	}
	if a.lo < b.lo {
		return -1
	}
	return 0
}

func (u Uint128) String() string {
	hi := new(big.Int).SetUint64(u.hi)
	hi.Lsh(hi, 64)
	lo := new(big.Int).SetUint64(u.lo)
	hi.Add(hi, lo)
	return hi.String()
}

type Vector struct {
	x, y   int64
	rx, ry int64
}

type Key struct {
	x, y int64
}

func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func gcd(a, b int64) int64 {
	a = abs(a)
	b = abs(b)
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func half(v Vector) int {
	if v.ry > 0 || (v.ry == 0 && v.rx > 0) {
		return 0
	}
	return 1
}

func less(a, b Vector) bool {
	ha := half(a)
	hb := half(b)
	if ha != hb {
		return ha < hb
	}
	return a.rx*b.ry-a.ry*b.rx > 0
}

func main() {
	content, err := io.ReadAll(os.Stdin)
	if err != nil {
		return
	}
	pos := 0
	nextInt := func() int64 {
		for pos < len(content) && content[pos] <= ' ' {
			pos++
		}
		if pos >= len(content) {
			return 0
		}
		var res int64 = 0
		for pos < len(content) && content[pos] > ' ' {
			res = res*10 + int64(content[pos]-'0')
			pos++
		}
		return res
	}

	n := int(nextInt())
	if n == 0 {
		fmt.Println("0")
		return
	}

	groupSum := make(map[Key]*Vector)

	for i := 0; i < n; i++ {
		a := nextInt()
		b := nextInt()
		c := nextInt()
		d := nextInt()
		x := a - b
		y := c - d
		if x == 0 && y == 0 {
			continue
		}
		g := gcd(x, y)
		k := Key{x / g, y / g}

		if v, exists := groupSum[k]; exists {
			v.x += x
			v.y += y
		} else {
			groupSum[k] = &Vector{x: x, y: y, rx: k.x, ry: k.y}
		}
	}

	var V []Vector
	for _, v := range groupSum {
		V = append(V, *v)
	}

	if len(V) == 0 {
		fmt.Println("0")
		return
	}

	sort.Slice(V, func(i, j int) bool {
		return less(V[i], V[j])
	})

	Total := Vector{0, 0, 0, 0}
	for _, v := range V {
		Total.x += v.x
		Total.y += v.y
	}

	var maxVal Uint128

	update := func(S Vector) {
		sq := sqSum(S.x, S.y)
		if cmp128(sq, maxVal) > 0 {
			maxVal = sq
		}
		compX := Total.x - S.x
		compY := Total.y - S.y
		sqComp := sqSum(compX, compY)
		if cmp128(sqComp, maxVal) > 0 {
			maxVal = sqComp
		}
	}

	update(Vector{0, 0, 0, 0})

	k := len(V)
	V2 := make([]Vector, 2*k)
	copy(V2, V)
	copy(V2[k:], V)

	end := 0
	sumL := Vector{0, 0, 0, 0}

	for i := 0; i < k; i++ {
		if end <= i {
			end = i + 1
			sumL = Vector{0, 0, 0, 0}
		}
		for end < i+k {
			cross := V2[i].rx*V2[end].ry - V2[i].ry*V2[end].rx
			if cross > 0 {
				sumL.x += V2[end].x
				sumL.y += V2[end].y
				end++
			} else {
				break
			}
		}

		var O Vector
		if end < i+k {
			cross := V2[i].rx*V2[end].ry - V2[i].ry*V2[end].rx
			dot := V2[i].rx*V2[end].rx + V2[i].ry*V2[end].ry
			if cross == 0 && dot < 0 {
				O = V2[end]
			}
		}

		Z := V2[i]

		S1 := sumL
		S2 := Vector{x: sumL.x + Z.x, y: sumL.y + Z.y}
		S3 := Vector{x: sumL.x + O.x, y: sumL.y + O.y}
		S4 := Vector{x: S2.x + O.x, y: S2.y + O.y}

		update(S1)
		update(S2)
		update(S3)
		update(S4)

		if end > i+1 {
			sumL.x -= V2[i+1].x
			sumL.y -= V2[i+1].y
		}
	}

	fmt.Println(maxVal.String())
}
```