## 1. Abridged problem statement

Given a spherical planet of radius `R` centered at the origin and two scanner points outside the sphere, compute the total surface area of the sphere from which at least one scanner is directly visible.

A scanner sees exactly the spherical cap facing it, bounded by the tangent circle from the scanner to the sphere.

Input:

```text
R
x1 y1 z1
x2 y2 z2
```

Output the visible surface area, rounded to 3 decimal digits.

---

## 2. Detailed editorial

### Visibility from one scanner

Let the planet be a sphere of radius `R` centered at the origin.

Suppose a scanner is at point `p`, with distance from the center:

```text
d = |p|
```

Let:

```text
u = p / d
```

be the unit vector from the center toward the scanner.

A point `x` on the sphere is visible from the scanner if the segment from `x` to the scanner does not pass through the planet.

The boundary of visibility is the tangent circle from the scanner to the sphere. This tangent circle lies in a plane perpendicular to `u`.

The visible cap is:

```text
{x on sphere : (x / R) · u >= R / d}
```

So on the unit sphere, it is a spherical cap with angular radius:

```text
alpha = acos(R / d)
```

The area of a spherical cap of angular radius `alpha` on a sphere of radius `R` is:

```text
2πR²(1 - cos(alpha))
```

Since:

```text
cos(alpha) = R / d
```

the cap area is:

```text
2πR²(1 - R / d)
```

---

### Union of two visible regions

Each scanner sees one spherical cap.

Let the two caps have angular radii:

```text
alpha, beta
```

and let the angular distance between their centers be:

```text
theta
```

Then the answer is:

```text
area(cap1 ∪ cap2)
= area(cap1) + area(cap2) - area(cap1 ∩ cap2)
```

So the key task is computing the intersection area of two spherical caps.

---

### Cases for two caps

The two caps are disks on the sphere.

#### Case 1: disjoint caps

If:

```text
theta >= alpha + beta
```

the caps do not overlap.

So:

```text
intersection = 0
```

#### Case 2: one cap inside the other

If:

```text
theta + min(alpha, beta) <= max(alpha, beta)
```

then the smaller cap is fully contained inside the larger cap.

So the intersection is just the area of the smaller cap.

#### Case 3: partial overlap

Otherwise, the intersection is a spherical lens bounded by two small-circle arcs.

Let:

```text
cos(alpha) = ca
cos(beta)  = cb
cos(theta) = ct
```

Also:

```text
sin(alpha) = sa
sin(beta)  = sb
sin(theta) = st
```

For the lens, define:

```text
psi_a
```

as half the angular span of the intersection arc along cap `a`'s boundary, measured around the axis of cap `a`.

Similarly define:

```text
psi_b
```

for cap `b`.

Using spherical trigonometry:

```text
cos(psi_a) = (cos(beta) - cos(alpha) cos(theta)) / (sin(alpha) sin(theta))

cos(psi_b) = (cos(alpha) - cos(beta) cos(theta)) / (sin(beta) sin(theta))
```

Also define `gamma` as the angle between the two boundary tangent directions at an intersection point. Then:

```text
cos(gamma) = (cos(theta) - cos(alpha) cos(beta)) / (sin(alpha) sin(beta))
```

By applying Gauss-Bonnet to the spherical lens on the unit sphere, its area is:

```text
2(π - gamma) - 2 psi_a cos(alpha) - 2 psi_b cos(beta)
```

For a sphere of radius `R`, multiply by `R²`:

```text
intersection =
R² [2(π - gamma) - 2 psi_a cos(alpha) - 2 psi_b cos(beta)]
```

Finally:

```text
answer = area1 + area2 - intersection
```

All `acos` arguments should be clamped into `[-1, 1]` to avoid floating-point errors.

Complexity is `O(1)`.

---

## 3. Provided C++ solution with detailed comments

```cpp
#include <bits/stdc++.h> // Include almost all standard C++ library headers.

using namespace std; // Avoid writing std:: before standard library names.

// Overload output operator for pairs.
// This is a general helper, although not essential for this solution.
template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second; // Print first and second separated by space.
}

// Overload input operator for pairs.
// This is also a general helper.
template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second; // Read first and second values.
}

// Overload input operator for vectors.
// Reads every element of an already-sized vector.
template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) { // Iterate over all vector elements by reference.
        in >> x;     // Read one element.
    }
    return in;       // Return the stream to allow chaining.
};

// Overload output operator for vectors.
// Prints all elements separated by spaces.
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {     // Iterate over all vector elements.
        out << x << ' '; // Print each element followed by a space.
    }
    return out;          // Return the stream to allow chaining.
};

// Coordinate type used for 3D geometry.
// double precision is enough for this problem.
using coord3_t = double;

// Mathematical constant pi.
const coord3_t PI = acos((coord3_t)-1.0);

// Structure representing a point or vector in 3D.
struct Point3 {
    coord3_t x, y, z; // Cartesian coordinates.

    // Dot product of this vector with another vector p.
    coord3_t dot(const Point3& p) const {
        return x * p.x + y * p.y + z * p.z;
    }

    // Euclidean norm, i.e. vector length.
    coord3_t norm() const {
        return sqrt(dot(*this)); // Length is sqrt(v · v).
    }

    // Input operator for Point3.
    friend istream& operator>>(istream& in, Point3& p) {
        return in >> p.x >> p.y >> p.z; // Read x, y, z.
    }
};

// Radius of the planet.
coord3_t R;

// Scanner positions.
Point3 p1, p2;

// Read input.
void read() {
    cin >> R >> p1 >> p2; // Read radius, first scanner, second scanner.
}

void solve() {
    // Distance from the planet center to scanner 1.
    coord3_t d1 = p1.norm();

    // Distance from the planet center to scanner 2.
    coord3_t d2 = p2.norm();

    // For scanner 1, cos(alpha) = R / d1,
    // where alpha is the angular radius of its visible cap.
    coord3_t cos_a = R / d1;

    // For scanner 2, cos(beta) = R / d2.
    coord3_t cos_b = R / d2;

    // sin(alpha), computed from cos(alpha).
    // max protects against tiny negative values caused by floating-point error.
    coord3_t sin_a = sqrt(max(0.0, 1.0 - cos_a * cos_a));

    // sin(beta), similarly.
    coord3_t sin_b = sqrt(max(0.0, 1.0 - cos_b * cos_b));

    // Angular radius alpha of cap 1.
    coord3_t alpha = acos(cos_a);

    // Angular radius beta of cap 2.
    coord3_t beta = acos(cos_b);

    // cos(theta), where theta is the angle between scanner direction vectors.
    coord3_t cos_t = p1.dot(p2) / (d1 * d2);

    // Clamp cos(theta) into valid acos range [-1, 1].
    cos_t = max((coord3_t)-1.0, min((coord3_t)1.0, cos_t));

    // sin(theta), computed safely from cos(theta).
    coord3_t sin_t = sqrt(max(0.0, 1.0 - cos_t * cos_t));

    // Angle theta between the two cap centers.
    coord3_t theta = acos(cos_t);

    // Area of first visible cap:
    // 2πR²(1 - cos(alpha)).
    coord3_t area1 = 2 * PI * R * R * (1 - cos_a);

    // Area of second visible cap.
    coord3_t area2 = 2 * PI * R * R * (1 - cos_b);

    // Area of intersection between the two caps.
    coord3_t intersection = 0.0;

    // If the distance between cap centers is at least the sum of radii,
    // the caps are disjoint or only tangent.
    if(theta >= alpha + beta) {
        intersection = 0.0; // No positive-area overlap.
    }

    // If one cap is fully contained in the other.
    else if(theta + min(alpha, beta) <= max(alpha, beta)) {
        // Intersection is the smaller cap.
        // The smaller angular radius corresponds to the smaller cap area.
        intersection = 2 * PI * R * R * (1 - (alpha < beta ? cos_a : cos_b));
    }

    // Otherwise, the caps partially overlap and form a spherical lens.
    else {
        // Helper lambda to clamp a cosine value into [-1, 1].
        auto clamp_cos = [](coord3_t c) {
            return max((coord3_t)-1.0, min((coord3_t)1.0, c));
        };

        // Half-span angle of the arc from cap 1's boundary
        // that contributes to the lens.
        coord3_t psi_a =
            acos(clamp_cos((cos_b - cos_a * cos_t) / (sin_a * sin_t)));

        // Half-span angle of the arc from cap 2's boundary.
        coord3_t psi_b =
            acos(clamp_cos((cos_a - cos_b * cos_t) / (sin_b * sin_t)));

        // Angle between the boundary tangent directions at each intersection point.
        coord3_t gamma =
            acos(clamp_cos((cos_t - cos_a * cos_b) / (sin_a * sin_b)));

        // Spherical lens area from Gauss-Bonnet, scaled by R².
        intersection =
            R * R * (2 * (PI - gamma) - 2 * psi_a * cos_a - 2 * psi_b * cos_b);
    }

    // Union area = area1 + area2 - intersection.
    // Print rounded to exactly 3 digits after decimal point.
    cout << fixed << setprecision(3) << area1 + area2 - intersection << '\n';
}

int main() {
    // Speed up standard input/output.
    ios_base::sync_with_stdio(false);

    // Untie cin from cout for faster input.
    cin.tie(nullptr);

    // This problem has exactly one test case.
    int T = 1;

    // Multiple-test input is not used here.
    // cin >> T;

    // Process test cases.
    for(int test = 1; test <= T; test++) {
        read();  // Read one test case.
        solve(); // Solve it.
    }

    return 0; // Successful program termination.
}
```

---

## 4. Python solution with detailed comments

```python
import math
import sys


def clamp(x, lo=-1.0, hi=1.0):
    """
    Clamp x into the interval [lo, hi].

    This is important before calling acos(), because floating-point
    computations can produce values such as 1.0000000000000002.
    """
    return max(lo, min(hi, x))


def dot(a, b):
    """
    Dot product of two 3D vectors.
    """
    return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]


def norm(a):
    """
    Euclidean length of a 3D vector.
    """
    return math.sqrt(dot(a, a))


def main():
    # Read all input numbers.
    data = sys.stdin.read().strip().split()

    # If input is empty, do nothing.
    if not data:
        return

    # First value is the radius of the planet.
    R = float(data[0])

    # Next three values are coordinates of scanner 1.
    p1 = (
        float(data[1]),
        float(data[2]),
        float(data[3]),
    )

    # Last three values are coordinates of scanner 2.
    p2 = (
        float(data[4]),
        float(data[5]),
        float(data[6]),
    )

    # Mathematical constant pi.
    pi = math.pi

    # Distances from the center of the planet to each scanner.
    d1 = norm(p1)
    d2 = norm(p2)

    # For a scanner at distance d, the visible spherical cap has
    # angular radius alpha satisfying cos(alpha) = R / d.
    cos_a = R / d1
    cos_b = R / d2

    # Compute the corresponding sines safely.
    sin_a = math.sqrt(max(0.0, 1.0 - cos_a * cos_a))
    sin_b = math.sqrt(max(0.0, 1.0 - cos_b * cos_b))

    # Angular radii of the two visible caps.
    alpha = math.acos(clamp(cos_a))
    beta = math.acos(clamp(cos_b))

    # Angle theta between scanner direction vectors.
    cos_t = dot(p1, p2) / (d1 * d2)
    cos_t = clamp(cos_t)

    # sin(theta), computed safely.
    sin_t = math.sqrt(max(0.0, 1.0 - cos_t * cos_t))

    # Actual angle theta.
    theta = math.acos(cos_t)

    # Area of each spherical cap:
    # area = 2πR²(1 - cos(radius_angle)).
    area1 = 2.0 * pi * R * R * (1.0 - cos_a)
    area2 = 2.0 * pi * R * R * (1.0 - cos_b)

    # Compute intersection area of the two caps.
    if theta >= alpha + beta:
        # Caps are disjoint or tangent.
        intersection = 0.0

    elif theta + min(alpha, beta) <= max(alpha, beta):
        # One cap lies completely inside the other.
        # Intersection equals the smaller cap.
        if alpha < beta:
            intersection = area1
        else:
            intersection = area2

    else:
        # Partial overlap: the intersection is a spherical lens.

        # Half-angle span of the arc from cap 1's boundary.
        psi_a = math.acos(
            clamp((cos_b - cos_a * cos_t) / (sin_a * sin_t))
        )

        # Half-angle span of the arc from cap 2's boundary.
        psi_b = math.acos(
            clamp((cos_a - cos_b * cos_t) / (sin_b * sin_t))
        )

        # Angle between boundary tangent directions at an intersection point.
        gamma = math.acos(
            clamp((cos_t - cos_a * cos_b) / (sin_a * sin_b))
        )

        # Lens area from Gauss-Bonnet on the unit sphere,
        # then scaled by R².
        intersection = R * R * (
            2.0 * (pi - gamma)
            - 2.0 * psi_a * cos_a
            - 2.0 * psi_b * cos_b
        )

    # Union area by inclusion-exclusion.
    answer = area1 + area2 - intersection

    # Print rounded to 3 digits after the decimal point.
    print(f"{answer:.3f}")


if __name__ == "__main__":
    main()
```

---

## 5. Compressed editorial

Each scanner sees a spherical cap. If the scanner is at distance `d` from the sphere center, then the cap angular radius `a` satisfies:

```text
cos(a) = R / d
```

and its area is:

```text
2πR²(1 - R / d)
```

Let the two caps have angular radii `a`, `b`, and let the angle between scanner direction vectors be `t`.

The answer is:

```text
area1 + area2 - intersection
```

If:

```text
t >= a + b
```

then `intersection = 0`.

If:

```text
t + min(a, b) <= max(a, b)
```

then one cap is inside the other, and `intersection` is the smaller cap area.

Otherwise, the intersection is a spherical lens. Let:

```text
ca = cos(a), cb = cos(b), ct = cos(t)
sa = sin(a), sb = sin(b), st = sin(t)
```

Then:

```text
psi_a = acos((cb - ca ct) / (sa st))
psi_b = acos((ca - cb ct) / (sb st))
gamma = acos((ct - ca cb) / (sa sb))
```

The lens area is:

```text
R² * (2(π - gamma) - 2 psi_a ca - 2 psi_b cb)
```

Clamp all `acos` arguments to `[-1, 1]`.

The solution is constant time, `O(1)`.