← Home
package main

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

const eps = 1e-9
const mergeEps = 1e-8
const onCircleEps = 1e-7

type Circle struct {
	x, y, r float64
}

type Point struct {
	x, y float64
}

type DSU struct {
	p, sz []int
}

func NewDSU(n int) *DSU {
	p := make([]int, n)
	sz := make([]int, n)
	for i := 0; i < n; i++ {
		p[i] = i
		sz[i] = 1
	}
	return &DSU{p: p, sz: sz}
}

func (d *DSU) Find(x int) int {
	if d.p[x] != x {
		d.p[x] = d.Find(d.p[x])
	}
	return d.p[x]
}

func (d *DSU) Union(a, b int) {
	ra, rb := d.Find(a), d.Find(b)
	if ra == rb {
		return
	}
	if d.sz[ra] < d.sz[rb] {
		ra, rb = rb, ra
	}
	d.p[rb] = ra
	d.sz[ra] += d.sz[rb]
}

func dist(a, b Point) float64 {
	return math.Hypot(a.x-b.x, a.y-b.y)
}

func circleIntersections(c1, c2 Circle) []Point {
	dx := c2.x - c1.x
	dy := c2.y - c1.y
	d := math.Hypot(dx, dy)

	if d < eps {
		return nil
	}
	if d > c1.r+c2.r+eps {
		return nil
	}
	if d < math.Abs(c1.r-c2.r)-eps {
		return nil
	}

	a := (c1.r*c1.r - c2.r*c2.r + d*d) / (2 * d)
	h2 := c1.r*c1.r - a*a
	if h2 < -eps {
		return nil
	}
	if h2 < 0 {
		h2 = 0
	}

	xm := c1.x + a*dx/d
	ym := c1.y + a*dy/d

	if h2 <= eps {
		return []Point{{xm, ym}}
	}

	h := math.Sqrt(h2)
	rx := -dy * h / d
	ry := dx * h / d

	return []Point{
		{xm + rx, ym + ry},
		{xm - rx, ym - ry},
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n int
	fmt.Fscan(in, &n)

	circles := make([]Circle, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &circles[i].x, &circles[i].y, &circles[i].r)
	}

	dsu := NewDSU(n)
	var raw []Point

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			pts := circleIntersections(circles[i], circles[j])
			if len(pts) > 0 {
				dsu.Union(i, j)
				raw = append(raw, pts...)
			}
		}
	}

	var uniq []Point
	for _, p := range raw {
		found := false
		for _, q := range uniq {
			if dist(p, q) <= mergeEps {
				found = true
				break
			}
		}
		if !found {
			uniq = append(uniq, p)
		}
	}

	k := make([]int, n)
	for _, p := range uniq {
		for i := 0; i < n; i++ {
			if math.Abs(math.Hypot(p.x-circles[i].x, p.y-circles[i].y)-circles[i].r) <= onCircleEps {
				k[i]++
			}
		}
	}

	V := len(uniq)
	E := 0
	for i := 0; i < n; i++ {
		if k[i] == 0 {
			V++
			E++
		} else {
			E += k[i]
		}
	}

	comp := 0
	seen := make(map[int]bool)
	for i := 0; i < n; i++ {
		r := dsu.Find(i)
		if !seen[r] {
			seen[r] = true
			comp++
		}
	}

	F := E - V + comp + 1
	fmt.Fprintln(out, F)
}