This page is still under construction.

Parts of this page are still being built. What you see may change.

Crop Circles

Time limit8sMemory limit256 MB

Summary
Count how many pairs of given circles touch at exactly one point.
Level

Medium7 of 10

Topics
Geometry, Sorting
Solved
No attempts yet

Problem

Many Byteotian farmers will remember last summer for a long time. Not because of an unusually rich harvest, nor the opposite (drought and hail), but because of the mysterious circles that appeared across many wheat fields. As Byteotia's expert on all kinds of unusual problems, Byteasar decided to investigate the circle phenomenon scientifically. He inspected the fields carefully and noticed that each circle was formed by flattening the grain over a disk-shaped region. Every two circles meet in at most one point; in particular, no circle lies entirely inside another.

Byteasar suspects that the circles are messages sent by beings from beyond Byteotia. Understanding their language will be very hard, but for now he has built a database of circle arrangements and is analyzing them statistically. The more interesting data he collects, the better. He has asked you to write a program that, for a given arrangement, reports how many pairs of circles share a common point.

Input

The first line contains an integer nn (1≤n≤500 0001 \le n \le 500\,000), the number of circles in the arrangement. Each of the next nn lines describes one circle. The ii-th such line contains three integers xix_i, yiy_i, rir_i (−109≤xi,yi≤109-10^9 \le x_i, y_i \le 10^9, 1≤ri≤1091 \le r_i \le 10^9), meaning that the ii-th circle has its center at (xi,yi)(x_i, y_i) and radius rir_i.

Output

Print a single integer: the number of pairs of circles that share a common point (that is, pairs that touch at exactly one point).

Hint

Example arrangement

Examples1

  1. Example 1

    Input
    4
    0 0 5
    8 6 5
    -6 8 5
    2 14 5
    
    Expected output
    4