Problem:
Persimmon
As autumn deepens, the persimmon tree in our garden has borne fruit again this year. However, the weather was not good this year, so there were only three fruits. The sun shone from the top of the persimmon tree and created shadows on the ground, which were circular and overlapped or separated depending on the position of the sun.
Write a program which reads the information about the shadows of each of the three persimmon fruits and finds the area of the shadows. The shadows of the three persimmon fruits all have the same radius.
Input
The input is given in the following form
$r$
$x_1$ $y_1$
$x_2$ $y_2$
$x_3$ $y_3$
In the first line, the radius of the circle representing the shade of the three persimmon fruits $r$ ($1 \leq r \leq 500$) is given as an integer. In the next three lines, the coordinates $x_i,y_i$ ($0 \leq x_i,y_i \leq 500$) of the center of the $i$-th circle are given as integers. The coordinates of the centers of all the circles are different (if $i \ne j$, then $x_i \ne x_j$ or $y_i \ne y_j$).
Output
Output the shaded area of the persimmon fruit as a real number in a line. The error must not exceed plus or minus 0.00001.
Sample Input and Output
Sample Input 1
2
0 0
2 0
1 5
Sample Output 1
32.7856330486
Sample Input 2
3
3 2
5 2
4 5
Sample Output 2
55.2157319565

Submitted solutions:

code_snippet: #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

double R;
double X[3], Y[3];
const double STEP{1.75 * 1e-5};
double U[3], D[3];

double calc(double x) {
    for (int i{} ; i < 3 ; i++) {
        if (std::abs(x - X[i]) > R) U[i] = D[i] = 0;
        else {
            double v{sqrt(R * R - std::abs(x - X[i]) * std::abs(x - X[i]))};
            U[i] = Y[i] + v;
            D[i] = Y[i] - v;
        }
    } 
    double res{};
    for (int bit{1} ; bit < (1 << 3) ; bit++) {
        double d{-1e18}, u{1e18};
        for (int i{} ; i < 3 ; i++) if (bit & (1 << i)) {
            d = std::max(d, D[i]);
            u = std::min(u, U[i]);
        }
        res += (__builtin_popcount(bit) & 1 ? 1 : -1) * std::max<long double>(0, u - d);
    }
    return res;
}


int main() {
    std::cin >> R;
    for (int i{} ; i < 3 ; i++) std::cin >> X[i] >> Y[i];
    double ans{};
    double min{*std::min_element(X, X + 3)};
    double max{*std::max_element(X, X + 3)};
    for (double x{min - R} ; x <= max + R ; x += STEP) {
        ans += STEP * calc(x);
    }
    std::cout << std::fixed << std::setprecision(8) << ans << '\n';
}
accuracy: 0.4230769230769231
time_ms: 870
memory_kb: 3584
final_rank: 9

code_snippet: #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

double R;
double X[3], Y[3];
const double STEP{2e-5};
double U[3], D[3];

double calc(double x) {
    for (int i{} ; i < 3 ; i++) {
        if (std::abs(x - X[i]) > R) U[i] = D[i] = 0;
        else {
            double v{sqrt(R * R - std::abs(x - X[i]) * std::abs(x - X[i]))};
            U[i] = Y[i] + v;
            D[i] = Y[i] - v;
        }
    } 
    double res{};
    for (int bit{1} ; bit < (1 << 3) ; bit++) {
        double d{-1e18}, u{1e18};
        for (int i{} ; i < 3 ; i++) if (bit & (1 << i)) {
            d = std::max(d, D[i]);
            u = std::min(u, U[i]);
        }
        res += (__builtin_popcount(bit) & 1 ? 1 : -1) * std::max<long double>(0, u - d);
    }
    return res;
}


int main() {
    std::cin >> R;
    for (int i{} ; i < 3 ; i++) std::cin >> X[i] >> Y[i];
    double ans{};
    double min{*std::min_element(X, X + 3)};
    double max{*std::max_element(X, X + 3)};
    for (double x{min - R} ; x <= max + R ; x += STEP) {
        ans += STEP * calc(x);
    }
    std::cout << std::fixed << std::setprecision(8) << ans << '\n';
}
accuracy: 0.4230769230769231
time_ms: 760
memory_kb: 3516
final_rank: 8

code_snippet: #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

double R;
double X[3], Y[3];
const double STEP{3e-5};
double U[3], D[3];

double calc(double x) {
    for (int i{} ; i < 3 ; i++) {
        if (std::abs(x - X[i]) > R) U[i] = D[i] = 0;
        else {
            double v{sqrt(R * R - std::abs(x - X[i]) * std::abs(x - X[i]))};
            U[i] = Y[i] + v;
            D[i] = Y[i] - v;
        }
    } 
    double res{};
    for (int bit{1} ; bit < (1 << 3) ; bit++) {
        double d{-1e18}, u{1e18};
        for (int i{} ; i < 3 ; i++) if (bit & (1 << i)) {
            d = std::max(d, D[i]);
            u = std::min(u, U[i]);
        }
        res += (__builtin_popcount(bit) & 1 ? 1 : -1) * std::max<long double>(0, u - d);
    }
    return res;
}


int main() {
    std::cin >> R;
    for (int i{} ; i < 3 ; i++) std::cin >> X[i] >> Y[i];
    double ans{};
    double min{*std::min_element(X, X + 3)};
    double max{*std::max_element(X, X + 3)};
    for (double x{min - R} ; x <= max + R ; x += STEP) {
        ans += STEP * calc(x);
    }
    std::cout << std::fixed << std::setprecision(8) << ans << '\n';
}
accuracy: 0.4230769230769231
time_ms: 510
memory_kb: 3572
final_rank: 6

code_snippet: #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

double R;
double X[3], Y[3];
const double STEP{5e-5};
double U[3], D[3];

double calc(double x) {
    for (int i{} ; i < 3 ; i++) {
        if (std::abs(x - X[i]) > R) U[i] = D[i] = 0;
        else {
            double v{sqrt(R * R - std::abs(x - X[i]) * std::abs(x - X[i]))};
            U[i] = Y[i] + v;
            D[i] = Y[i] - v;
        }
    } 
    double res{};
    for (int bit{1} ; bit < (1 << 3) ; bit++) {
        double d{-1e18}, u{1e18};
        for (int i{} ; i < 3 ; i++) if (bit & (1 << i)) {
            d = std::max(d, D[i]);
            u = std::min(u, U[i]);
        }
        res += (__builtin_popcount(bit) & 1 ? 1 : -1) * std::max<long double>(0, u - d);
    }
    return res;
}


int main() {
    std::cin >> R;
    for (int i{} ; i < 3 ; i++) std::cin >> X[i] >> Y[i];
    double ans{};
    double min{*std::min_element(X, X + 3)};
    double max{*std::max_element(X, X + 3)};
    for (double x{min - R} ; x <= max + R ; x += STEP) {
        ans += STEP * calc(x);
    }
    std::cout << std::fixed << std::setprecision(8) << ans << '\n';
}
accuracy: 0.4230769230769231
time_ms: 300
memory_kb: 3516
final_rank: 5

code_snippet: #include <bits/stdc++.h>

double R;
double X[3], Y[3];
const double STEP{5e-5};
double U[3], D[3];

double calc(double x) {
    for (int i{} ; i < 3 ; i++) {
        if (std::abs(x - X[i]) > R) U[i] = D[i] = 0;
        else {
            double v{sqrt(R * R - std::abs(x - X[i]) * std::abs(x - X[i]))};
            U[i] = Y[i] + v;
            D[i] = Y[i] - v;
        }
    } 
    double res{};
    for (int bit{1} ; bit < (1 << 3) ; bit++) {
        double d{-1e18}, u{1e18};
        for (int i{} ; i < 3 ; i++) if (bit & (1 << i)) {
            d = std::max(d, D[i]);
            u = std::min(u, U[i]);
        }
        res += (__builtin_popcount(bit) & 1 ? 1 : -1) * std::max<long double>(0, u - d);
    }
    return res;
}


int main() {
    std::cin >> R;
    for (int i{} ; i < 3 ; i++) std::cin >> X[i] >> Y[i];
    double ans{};
    double min{*std::min_element(X, X + 3)};
    double max{*std::max_element(X, X + 3)};
    for (double x{min - R} ; x <= max + R ; x += STEP) {
        ans += STEP * calc(x);
    }
    std::cout << std::fixed << std::setprecision(8) << ans << '\n';
}
accuracy: 0.4230769230769231
time_ms: 620
memory_kb: 3568
final_rank: 7

code_snippet: #include <bits/stdc++.h>

double R;
double X[3], Y[3];
const double STEP{8e-5};
double U[3], D[3];

double calc(double x) {
    for (int i{} ; i < 3 ; i++) {
        if (std::abs(x - X[i]) > R) U[i] = D[i] = 0;
        else {
            double v{sqrt(R * R - std::abs(x - X[i]) * std::abs(x - X[i]))};
            U[i] = Y[i] + v;
            D[i] = Y[i] - v;
        }
    } 
    double res{};
    for (int bit{1} ; bit < (1 << 3) ; bit++) {
        double d{-1e18}, u{1e18};
        for (int i{} ; i < 3 ; i++) if (bit & (1 << i)) {
            d = std::max(d, D[i]);
            u = std::min(u, U[i]);
        }
        res += (__builtin_popcount(bit) & 1 ? 1 : -1) * std::max<long double>(0, u - d);
    }
    return res;
}


int main() {
    std::cin >> R;
    for (int i{} ; i < 3 ; i++) std::cin >> X[i] >> Y[i];
    double ans{};
    double min{*std::min_element(X, X + 3)};
    double max{*std::max_element(X, X + 3)};
    for (double x{min - R} ; x <= max + R ; x += STEP) {
        ans += STEP * calc(x);
    }
    std::cout << std::fixed << std::setprecision(8) << ans << '\n';
}
accuracy: 0.38461538461538464
time_ms: 60
memory_kb: 3604
final_rank: 11

code_snippet: #include <bits/stdc++.h>

double R;
double X[3], Y[3];
const double STEP{9e-5};
double U[3], D[3];

double calc(double x) {
    for (int i{} ; i < 3 ; i++) {
        if (std::abs(x - X[i]) > R) U[i] = D[i] = 0;
        else {
            double v{sqrt(R * R - std::abs(x - X[i]) * std::abs(x - X[i]))};
            U[i] = Y[i] + v;
            D[i] = Y[i] - v;
        }
    } 
    double res{};
    for (int bit{1} ; bit < (1 << 3) ; bit++) {
        double d{-1e18}, u{1e18};
        for (int i{} ; i < 3 ; i++) if (bit & (1 << i)) {
            d = std::max(d, D[i]);
            u = std::min(u, U[i]);
        }
        res += (__builtin_popcount(bit) & 1 ? 1 : -1) * std::max<long double>(0, u - d);
    }
    return res;
}


int main() {
    std::cin >> R;
    for (int i{} ; i < 3 ; i++) std::cin >> X[i] >> Y[i];
    double ans{};
    for (double x{-1000} ; x <= 1000 ; x += STEP) {
        ans += STEP * calc(x);
    }
    std::cout << std::fixed << std::setprecision(8) << ans << '\n';
}
accuracy: 0.6153846153846154
time_ms: 930
memory_kb: 3568
final_rank: 2

code_snippet: #include <bits/stdc++.h>

double R;
double X[3], Y[3];
const double STEP{1e-4};
double U[3], D[3];

double calc(double x) {
    for (int i{} ; i < 3 ; i++) {
        if (std::abs(x - X[i]) > R) U[i] = D[i] = 0;
        else {
            double v{sqrt(R * R - std::abs(x - X[i]) * std::abs(x - X[i]))};
            U[i] = Y[i] + v;
            D[i] = Y[i] - v;
        }
    } 
    double res{};
    for (int bit{1} ; bit < (1 << 3) ; bit++) {
        double d{-1e18}, u{1e18};
        for (int i{} ; i < 3 ; i++) if (bit & (1 << i)) {
            d = std::max(d, D[i]);
            u = std::min(u, U[i]);
        }
        res += (__builtin_popcount(bit) & 1 ? 1 : -1) * std::max<long double>(0, u - d);
    }
    return res;
}


int main() {
    std::cin >> R;
    for (int i{} ; i < 3 ; i++) std::cin >> X[i] >> Y[i];
    double ans{};
    for (double x{-1000} ; x <= 1000 ; x += STEP) {
        ans += STEP * calc(x);
    }
    std::cout << std::fixed << std::setprecision(8) << ans << '\n';
}
accuracy: 0.2692307692307692
time_ms: 810
memory_kb: 3568
final_rank: 12

code_snippet: #include <bits/stdc++.h>

long double R;
long double X[3], Y[3];
const long double STEP{2e-4};
long double U[3], D[3];

long double calc(long double x) {
    for (int i{} ; i < 3 ; i++) {
        if (std::abs(x - X[i]) > R) U[i] = D[i] = 0;
        else {
            long double v{sqrtl(R * R - std::abs(x - X[i]) * std::abs(x - X[i]))};
            U[i] = Y[i] + v;
            D[i] = Y[i] - v;
        }
    } 
    long double res{};
    for (int bit{1} ; bit < (1 << 3) ; bit++) {
        long double d{-1e18}, u{1e18};
        for (int i{} ; i < 3 ; i++) if (bit & (1 << i)) {
            d = std::max(d, D[i]);
            u = std::min(u, U[i]);
        }
        res += (__builtin_popcount(bit) & 1 ? 1 : -1) * std::max<long double>(0, u - d);
    }
    return res;
}


int main() {
    std::cin >> R;
    for (int i{} ; i < 3 ; i++) std::cin >> X[i] >> Y[i];
    long double ans{};
    for (long double x{-1000} ; x <= 1000 ; x += STEP) {
        ans += STEP * calc(x);
    }
    std::cout << std::fixed << std::setprecision(8) << ans << '\n';
}
accuracy: 0.038461538461538464
time_ms: 770
memory_kb: 3476
final_rank: 20

code_snippet: #pragma region Macros

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,fma,abm,mmx,avx,avx2")

#include <boost/geometry.hpp>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/point_xy.hpp>

#include <bits/stdc++.h>
using namespace std;

#define pb emplace_back
#define endl '\n'

#pragma endregion

namespace bg = boost::geometry;
namespace bgsg = boost::geometry::strategy::buffer;

typedef bg::model::d2::point_xy<float> point;
typedef bg::model::box<point> box;
typedef bg::model::polygon<point> polygon;

signed main() {
    cout << fixed << setprecision(10);

    float r, x1, y1, x2, y2, x3, y3; // この問題はrが共通
    cin >> r >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    point c1(x1, y1), c2(x2, y2), c3(x3, y3);

    int points_per_circle = 1300000; //この個数の点で近似している? 最低3
    bgsg::distance_symmetric<float> distance_strategy(r);
    bgsg::join_round join_strategy(points_per_circle);
    bgsg::end_round end_strategy(points_per_circle);
    bgsg::point_circle circle_strategy(points_per_circle);
    bgsg::side_straight side_strategy;

    bg::model::multi_polygon<polygon> C1, C2, C3;

    bg::buffer(c1, C1, distance_strategy, side_strategy, join_strategy, end_strategy, circle_strategy);
    bg::buffer(c2, C2, distance_strategy, side_strategy, join_strategy, end_strategy, circle_strategy);
    bg::buffer(c3, C3, distance_strategy, side_strategy, join_strategy, end_strategy, circle_strategy);


    bg::model::multi_polygon<polygon> C4;
    bg::union_(C1.front(), C2.front(), C4);

    bg::model::multi_polygon<polygon> C5;
    bg::union_(C3.front(), C4.front(), C5);

    float U = 0; // 和集合の面積
    int sz = C5.size();
    for (int i = 0; i < sz; i++) {
        U += bg::area(C5[i]);
    }
    cout << U << endl;
}
accuracy: 0.07692307692307693
time_ms: 860
memory_kb: 244948
final_rank: 16

code_snippet: #pragma region Macros

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,fma,abm,mmx,avx,avx2")

#include <boost/geometry.hpp>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/point_xy.hpp>

#include <bits/stdc++.h>
using namespace std;

#define pb emplace_back
#define endl '\n'

#pragma endregion

namespace bg = boost::geometry;
namespace bgsg = boost::geometry::strategy::buffer;

typedef bg::model::d2::point_xy<double> point;
typedef bg::model::box<point> box;
typedef bg::model::polygon<point> polygon;

signed main() {
    cout << fixed << setprecision(10);

    double r, x1, y1, x2, y2, x3, y3; // この問題はrが共通
    cin >> r >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    point c1(x1, y1), c2(x2, y2), c3(x3, y3);

    int points_per_circle = 1000000;
    // 何? 72や90にしているのも見る。この個数の点で近似している? 最低3っぽい
    bgsg::distance_symmetric<double> distance_strategy(r);
    bgsg::join_round join_strategy(points_per_circle);
    bgsg::end_round end_strategy(points_per_circle);
    bgsg::point_circle circle_strategy(points_per_circle);
    bgsg::side_straight side_strategy;

    bg::model::multi_polygon<polygon> C1, C2, C3;

    bg::buffer(c1, C1, distance_strategy, side_strategy, join_strategy, end_strategy, circle_strategy);
    bg::buffer(c2, C2, distance_strategy, side_strategy, join_strategy, end_strategy, circle_strategy);
    bg::buffer(c3, C3, distance_strategy, side_strategy, join_strategy, end_strategy, circle_strategy);


    bg::model::multi_polygon<polygon> C4;
    bg::union_(C1.front(), C2.front(), C4);

    bg::model::multi_polygon<polygon> C5;
    bg::union_(C3.front(), C4.front(), C5);

    double U = 0; // 和集合の面積
    int sz = C5.size();
    for (int i = 0; i < sz; i++) {
        U += bg::area(C5[i]);
    }
    cout << U << endl;
}
accuracy: 0.07692307692307693
time_ms: 480
memory_kb: 159924
final_rank: 15

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#line 1 "f.cpp"
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define repp(i,n,m) for (int i = m; i < int(n); ++i)
#define reb(i,n) for (int i = int(n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,int>;
using PL = pair<ll,ll>;

template<class T>istream &operator>>(istream &is,vector<T> &v){for(auto &e:v)is>>e;return is;}

template<typename T1, typename T2>void print(pair<T1,T2> a);
template<typename T>void print(vector<T> v);
template<typename T>void print(vector<vector<T>> v);
void print(){ putchar(' '); }
void print(bool a){ printf("%d", a); }
void print(int a){ printf("%d", a); }
void print(long a){ printf("%ld", a); }
void print(long long a){ printf("%lld", a); }
void print(char a){ printf("%c", a); }
void print(char a[]){ printf("%s", a); }
void print(const char a[]){ printf("%s", a); }
void print(long double a){ printf("%.15Lf", a); }
void print(const string& a){ for(auto&& i : a) print(i); }
void print(unsigned int a){ printf("%u", a); }
template<class T> void print(const T& a){ cout << a;}
int out(){ putchar('\n'); return 0; }
template<class T> int out(const T& t){ print(t); putchar('\n'); return 0; }
template<class Head, class... Tail> int out(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); return 0; }
template<typename T1,typename T2>void print(pair<T1,T2> a){print(a.first);print(),print(a.second);}
template<typename T>void print(vector<T> v){for(auto ite=v.begin();ite!=v.end();){print(*ite);if(++ite!=v.end())print();}}
template<typename T>void print(vector<vector<T>> v){for(auto ite=v.begin();ite!=v.end();){print(*ite);if(++ite!=v.end())out();}}

template<typename T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}

void fast_io(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);}

namespace noya2{

const int INF = 1001001007;
const long long mod1 = 998244353;
const long long mod2 = 1000000007;
const long long inf = 2e18;
const long double pi = 3.14159265358979323;
const long double eps = 1e-7;
vector<int> dx = {0,1,0,-1,1,1,-1,-1};
vector<int> dy = {1,0,-1,0,1,-1,-1,1};
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string NUM = "0123456789";
void o(){out("!?");}
void yn(bool f){out(f ? "Yes" : "No");}
void YN(bool F){out(F ? "YES" : "NO");}
template<typename T>bool range(T a,T b,T x){return (a<=x&&x<b);}
template<typename T>bool rrange(T a,T b,T c,T d,T x,T y){return (range(a,c,x)&&range(b,d,y));}

} // namespace noya2
using namespace noya2;


void solve(){
    ld r; cin >> r;
    int n = 3;
    vector<ld> xs(n), ys(n);
    rep(i,n) cin >> xs[i] >> ys[i];
    const int m = 2e7;
    const ld d = ld(1500) / ld(m);
    const ld le = -500;
    const ld ri = 1000;
    ld sum = 0;
    rep(t,m){
        ld x = le + d * (ld(t) + 0.5);
        vector<pair<ld,int>> vec;
        rep(i,n){
            ld rem = r * r - (x - xs[i]) * (x - xs[i]);
            if (rem > 0){
                ld sqr = sqrtl(rem);
                ld ly = ys[i] - sqr;
                ld ry = ys[i] + sqr;
                vec.emplace_back(ly,1);
                vec.emplace_back(ry,-1);
            }
        }
        sort(all(vec));
        int cnt = 0;
        ld lx = -1e7;
        for (auto p : vec){
            if (cnt > 0){
                ld rx = p.first;
                if (rx > lx) sum += (rx - lx) * d;
            }
            lx = p.first;
            cnt += p.second;
        }
    }
    out(sum);
}

int main(){
    fast_io();
    int t = 1; //cin >> t;
    while(t--) solve();
}
accuracy: 0.5
time_ms: 940
memory_kb: 3608
final_rank: 3

code_snippet: #line 1 "f.cpp"
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define repp(i,n,m) for (int i = m; i < int(n); ++i)
#define reb(i,n) for (int i = int(n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,int>;
using PL = pair<ll,ll>;

template<class T>istream &operator>>(istream &is,vector<T> &v){for(auto &e:v)is>>e;return is;}

template<typename T1, typename T2>void print(pair<T1,T2> a);
template<typename T>void print(vector<T> v);
template<typename T>void print(vector<vector<T>> v);
void print(){ putchar(' '); }
void print(bool a){ printf("%d", a); }
void print(int a){ printf("%d", a); }
void print(long a){ printf("%ld", a); }
void print(long long a){ printf("%lld", a); }
void print(char a){ printf("%c", a); }
void print(char a[]){ printf("%s", a); }
void print(const char a[]){ printf("%s", a); }
void print(long double a){ printf("%.15Lf", a); }
void print(const string& a){ for(auto&& i : a) print(i); }
void print(unsigned int a){ printf("%u", a); }
template<class T> void print(const T& a){ cout << a;}
int out(){ putchar('\n'); return 0; }
template<class T> int out(const T& t){ print(t); putchar('\n'); return 0; }
template<class Head, class... Tail> int out(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); return 0; }
template<typename T1,typename T2>void print(pair<T1,T2> a){print(a.first);print(),print(a.second);}
template<typename T>void print(vector<T> v){for(auto ite=v.begin();ite!=v.end();){print(*ite);if(++ite!=v.end())print();}}
template<typename T>void print(vector<vector<T>> v){for(auto ite=v.begin();ite!=v.end();){print(*ite);if(++ite!=v.end())out();}}

template<typename T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}

void fast_io(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);}

namespace noya2{

const int INF = 1001001007;
const long long mod1 = 998244353;
const long long mod2 = 1000000007;
const long long inf = 2e18;
const long double pi = 3.14159265358979323;
const long double eps = 1e-7;
vector<int> dx = {0,1,0,-1,1,1,-1,-1};
vector<int> dy = {1,0,-1,0,1,-1,-1,1};
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string NUM = "0123456789";
void o(){out("!?");}
void yn(bool f){out(f ? "Yes" : "No");}
void YN(bool F){out(F ? "YES" : "NO");}
template<typename T>bool range(T a,T b,T x){return (a<=x&&x<b);}
template<typename T>bool rrange(T a,T b,T c,T d,T x,T y){return (range(a,c,x)&&range(b,d,y));}

} // namespace noya2
using namespace noya2;


void solve(){
    ld r; cin >> r;
    int n = 3;
    vector<ld> xs(n), ys(n);
    rep(i,n) cin >> xs[i] >> ys[i];
    const int m = 2e7;
    const ld d = ld(1500) / ld(m);
    const ld le = -500;
    const ld ri = 1000;
    ld sum = 0;
    rep(t,m){
        ld x = le + d * (ld(t) + 0.5);
        vector<pair<ld,int>> vec;
        rep(i,n){
            ld rem = r * r - (x - xs[i]) * (x - xs[i]);
            if (rem > 0){
                ld ly = ys[i] - sqrtl(rem);
                ld ry = ys[i] + sqrtl(rem);
                vec.emplace_back(ly,1);
                vec.emplace_back(ry,-1);
            }
        }
        sort(all(vec));
        int cnt = 0;
        ld ix = -1e7;
        for (auto p : vec){
            if (cnt > 0){
                ld lx = ix;
                ld rx = p.first;
                if (rx > lx) sum += (rx - lx) * d;
            }
            ix = p.first;
            cnt += p.second;
        }
    }
    out(sum);
}

int main(){
    fast_io();
    int t = 1; //cin >> t;
    while(t--) solve();
}
accuracy: 0.5
time_ms: 990
memory_kb: 3540
final_rank: 4

code_snippet: #line 1 "f.cpp"
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define repp(i,n,m) for (int i = m; i < int(n); ++i)
#define reb(i,n) for (int i = int(n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,int>;
using PL = pair<ll,ll>;

template<class T>istream &operator>>(istream &is,vector<T> &v){for(auto &e:v)is>>e;return is;}

template<typename T1, typename T2>void print(pair<T1,T2> a);
template<typename T>void print(vector<T> v);
template<typename T>void print(vector<vector<T>> v);
void print(){ putchar(' '); }
void print(bool a){ printf("%d", a); }
void print(int a){ printf("%d", a); }
void print(long a){ printf("%ld", a); }
void print(long long a){ printf("%lld", a); }
void print(char a){ printf("%c", a); }
void print(char a[]){ printf("%s", a); }
void print(const char a[]){ printf("%s", a); }
void print(long double a){ printf("%.15Lf", a); }
void print(const string& a){ for(auto&& i : a) print(i); }
void print(unsigned int a){ printf("%u", a); }
template<class T> void print(const T& a){ cout << a;}
int out(){ putchar('\n'); return 0; }
template<class T> int out(const T& t){ print(t); putchar('\n'); return 0; }
template<class Head, class... Tail> int out(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); return 0; }
template<typename T1,typename T2>void print(pair<T1,T2> a){print(a.first);print(),print(a.second);}
template<typename T>void print(vector<T> v){for(auto ite=v.begin();ite!=v.end();){print(*ite);if(++ite!=v.end())print();}}
template<typename T>void print(vector<vector<T>> v){for(auto ite=v.begin();ite!=v.end();){print(*ite);if(++ite!=v.end())out();}}

template<typename T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}

void fast_io(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);}

namespace noya2{

const int INF = 1001001007;
const long long mod1 = 998244353;
const long long mod2 = 1000000007;
const long long inf = 2e18;
const long double pi = 3.14159265358979323;
const long double eps = 1e-7;
vector<int> dx = {0,1,0,-1,1,1,-1,-1};
vector<int> dy = {1,0,-1,0,1,-1,-1,1};
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string NUM = "0123456789";
void o(){out("!?");}
void yn(bool f){out(f ? "Yes" : "No");}
void YN(bool F){out(F ? "YES" : "NO");}
template<typename T>bool range(T a,T b,T x){return (a<=x&&x<b);}
template<typename T>bool rrange(T a,T b,T c,T d,T x,T y){return (range(a,c,x)&&range(b,d,y));}

} // namespace noya2
using namespace noya2;


void solve(){
    ld r; cin >> r;
    int n = 3;
    vector<ld> xs(n), ys(n);
    rep(i,n) cin >> xs[i] >> ys[i];
    const int m = 5e6;
    const ld d = ld(1500) / ld(m);
    const ld le = -500;
    const ld ri = 1000;
    ld sum = 0;
    rep(t,m){
        ld x = le + d * (ld(t) + 0.5);
        vector<pair<ld,int>> vec;
        rep(i,n){
            ld rem = r * r - (x - xs[i]) * (x - xs[i]);
            if (rem > 0){
                ld ly = ys[i] - sqrtl(rem);
                ld ry = ys[i] + sqrtl(rem);
                vec.emplace_back(ly,1);
                vec.emplace_back(ry,-1);
            }
        }
        sort(all(vec));
        int cnt = 0;
        ld ix = -1e7;
        for (auto p : vec){
            if (cnt > 0){
                ld lx = ix;
                ld rx = p.first;
                if (rx > lx) sum += (rx - lx) * d;
            }
            ix = p.first;
            cnt += p.second;
        }
    }
    out(sum);
}

int main(){
    fast_io();
    int t = 1; //cin >> t;
    while(t--) solve();
}
accuracy: 0.07692307692307693
time_ms: 50
memory_kb: 3532
final_rank: 14

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <stack>
#include <numeric>
#include <algorithm>
using namespace std;
using ll = long long;
//#include <atcoder/all>
//using namespace atcoder;
//using mint = modint998244353;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int r;
    cin >> r;
    vector<vector<int>> a(3, vector<int>(2));
    rep(i, 3) rep(j, 2) cin >> a[i][j];
    double x = -500;
    const double dx = 1e-5;
    double ans = 0;
    vector<double> le(3), ri(3);
    while (x < 1000)
    {
        rep(i, 3)
        {
            const double s = abs(x - a[i][0]);
            if (s > r)
            {
                le[i] = ri[i] = 0;
                continue;
            }
            const double y = sqrt(r * r - s * s);
            le[i] = a[i][1] - y;
            ri[i] = a[i][1] + y;
        }
        for (int i = 0; i < 3; i++)
            for (int j = 2; j > i; j--)
                if (le[i] > le[j])
                    swap(le[i], le[j]), swap(ri[i], ri[j]);
        for (int i = 0; i < 3;)
        {
            int j = i + 1;
            double has1 = le[i];
            double has2 = ri[i];
            while (j != 3 && has2 >= le[j])
            {
                has2 = max(has2, ri[j]);
                j++;
            }
            ans += has2 - has1;
            i = j;
        }
        x += dx;
    }
    cout << ans * dx << endl;
    return 0;
}
accuracy: 0.4230769230769231
time_ms: 950
memory_kb: 3548
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define sqr(x) ((x)*(x))
#define maxrec 64


int n = 3;
double r, x[10], y[10];

vector<pair<double, double> >Merge(vector<pair<double, double> >v)
{
	double eps = 1e-8;
	
    if (v.empty()) return {};
    sort(v.begin(), v.end());
    vector<pair<double, double> > ret;
    int n = v.size();
    for (int i=0; i<n; )
	{
        double L = v[i].first;
        double R = v[i].second;
        int j = i;
        while ((j + 1 < n) && (v[j + 1].first < R + eps))
		{
            j++;
            R = max(R, v[j].second);
        }
        ret.push_back(make_pair(L, R));
        i = j + 1;
    }
    return ret;
}

double f(double X, double eps = 1e-8)
{
    vector<pair<double, double> > Cir, Mgc;
    for (int i=1; i<=n; i++)
	{
        if ((X > x[i] - r + eps) && (X < x[i] + r - eps))
		{
            double d = sqrt(sqr(r) - sqr(X - x[i]));
            Cir.push_back(make_pair(y[i] - d, y[i] + d));
        }
    }
    
    Mgc = Merge(Cir);	
    double ret = 0;
    for (auto &t : Mgc) {
        ret += t.second - t.first;
    }
    return ret;
}

double Adaptive(double l, double r, double m, double eps, double s, double fl, double fr, double fm, int lim)
{
    double h = (r - l) / 12;
    double u = ldexp(l + m, -1), v = ldexp(m + r, -1);
    double fu = f(u), fv = f(v);
    double sl = (fl + fm + ldexp(fu, 2)) * h, sr = (fm + fr + ldexp(fv, 2)) * h, s2 = sl + sr;
    if ((lim <= 0) || (fabs(s2 - s) <= eps)) return s2 + (s2 - s) / 15;
    eps = ldexp(eps, -1); --lim;
    
    return  Adaptive(l, m, u, eps, sl, fl, fm, fu, lim) + Adaptive(m, r, v, eps, sr, fm, fr, fv, lim);
}

double Simpson(double l, double r, double eps = 1e-8)
{
	double m = ldexp(l + r, -1);
    double fl = f(l), fm = f(m), fr = f(r);
    return Adaptive(l, r, m, eps * 63, (r - l) / 6 * (fl + fr + ldexp(fm, 2)), fl, fr, fm, maxrec);
}

int main()
{
	vector<pair<double, double> > Cir, Mgc;
	double eps = 1e-8;
	
	scanf("%lf", &r);
	
	for (int i=1; i<=n; i++)
	{
		scanf("%lf%lf", &x[i], &y[i]);
		Cir.push_back(make_pair(x[i] - r, x[i] + r));
	}
	
	Mgc = Merge(Cir);
	double Res = 0;
	for (auto &t:Mgc) Res += Simpson(t.first, t.second);
	
	printf("%.10lf\n", Res);
}
accuracy: 1
time_ms: 890
memory_kb: 3560
final_rank: 1

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



struct Point{
	Point(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}

	Point(){
		x = y = 0.0;
	}

	Point operator + (Point p){ return Point(x+p.x,y+p.y); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){ return Point(a*x,a*y); }
	Point operator / (double a){ return Point(x/a,y/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator<(const Point &p) const{

		if(fabs(x-p.x) > EPS){

			return x < p.x;
		}else{

			return y < p.y;
		}
	}

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}


	void debug(){

		printf("(%.3lf,%.3lf)\n",x,y);
	}

	double x,y;
};

typedef Point Vector;

struct Line{
	Line(){

	}
	Line(Point a,Point b){
		p[0] = a;
		p[1] = b;
	}
	/*void outPut(){

		printf("(%.3lf,%.3lf)-(%.3lf,%.3lf)\n",p[0].x,p[0].y,p[1].x,p[1].y);
	}*/
	Point p[2];
};

struct Circle{
	Point center;
	double r;
};

Circle C[3];


double calc_dist(Point A,Point B){

	return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}


double norm(Vector a){
	return a.x*a.x+a.y*a.y;
}

double abs(Vector a){
	return sqrt(norm(a));
}

double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

double dot(Vector a,Vector b){
    return a.x*b.x + a.y*b.y;
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

/*
 * p0を基準点として、p1から見てp2が
 * 反時計回り側にあれば
 * COUNTER_CLOCKWISE
 * */
int ccw(Point p0,Point p1,Point p2){

	Vector a = p1 - p0;
	Vector b = p2 - p0;

	if(cross(a,b) > EPS)return COUNTER_CLOCKWISE;
	if(cross(a,b) < -EPS)return CLOCKWISE;
	if(dot(a,b) < -EPS)return ONLINE_BACK;
	if(a.norm() < b.norm())return ONLINE_FRONT;

	return ON_SEGMENT;
}


Point project(Line l,Point p){

	Vector base = l.p[1]-l.p[0];
	double r = dot(p-l.p[0],base)/norm(base);
	return l.p[0]+base*r;
}

//円と直線の交点を求める関数
vector<Point> getCrossPoints(Circle c,Line l){

	vector<Point> ret;

	Vector pr = project(l,c.center);
	Vector e = (l.p[1]-l.p[0])/abs(l.p[1]-l.p[0]);

	double base;

	if(fabs(c.r*c.r-norm(pr-c.center)) < EPS){

		base = 0;
	}else{
		base = sqrt(c.r*c.r-norm(pr-c.center));
	}

	ret.push_back(Point(pr+e*base));
	ret.push_back(Point(pr-e*base));

	return ret;
}


Point calc_minus(Point a,Point b){
    Point ret;

    ret.x = a.x-b.x;
    ret.y = a.y-b.y;

    return ret;
}

double calc_len(Vector a){
    return sqrt(a.x*a.x+a.y*a.y);
}

//線分ではなく直線と点の距離
double getDistanceLP(Line l,Point p){
    return fabs(cross(calc_minus(l.p[1],l.p[0]),calc_minus(p,l.p[0]))/calc_len(calc_minus(l.p[1],l.p[0])));
}

int main(){

	double R;
	scanf("%lf",&R);

	double left = HUGE_NUM,right = -HUGE_NUM;

	for(int i = 0; i < 3; i++){

		scanf("%lf %lf",&C[i].center.x,&C[i].center.y);
		C[i].r = R;

		left = min(left,C[i].center.x-R);
		right = max(right,C[i].center.x+R);
	}

	double diff = 0.0002;
	double NUM = 10000;

	double ans = 0;

	for(double x = left; x <= right; x += diff){

		Line tmp_line = Line(Point(x,-NUM),Point(x,NUM));

		vector<Point> P;

		for(int i = 0; i < 3; i++){

			double tmp_dist = fabs(x-C[i].center.x);

			if(tmp_dist > R+EPS)continue;

			vector<Point> vec = getCrossPoints(C[i],tmp_line);
			for(int a = 0; a < vec.size(); a++){

				P.push_back(vec[a]);
			}
		}

		sort(P.begin(),P.end());

		for(int i = 1; i < P.size(); i++){

			if(P.size() == 2){

				ans += (P[i].y-P[i-1].y)*diff;
				continue;
			}

			Point mid = (P[i]+P[i-1])/2;
			bool FLG = false;
			for(int a = 0; a < 3; a++){

				if(calc_dist(C[a].center,mid) <= R+EPS){

					FLG = true;
					break;
				}
			}

			if(FLG){

				ans += (P[i].y-P[i-1].y)*diff;
			}
		}
	}

	printf("%.12lf\n",ans);

	return 0;
}
accuracy: 0.038461538461538464
time_ms: 10
memory_kb: 3200
final_rank: 17

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



enum Type{
	Top,
	Under,
};

struct Point{
	Point(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}

	Point(){
		x = y = 0.0;
	}

	Point operator + (Point p){ return Point(x+p.x,y+p.y); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){ return Point(a*x,a*y); }
	Point operator / (double a){ return Point(x/a,y/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator<(const Point &p) const{

		if(fabs(x-p.x) > EPS){

			return x < p.x;
		}else{

			return y < p.y;
		}
	}

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}


	void debug(){

		printf("(%.3lf,%.3lf)\n",x,y);
	}

	double x,y;
};

typedef Point Vector;

struct Line{
	Line(){

	}
	Line(Point a,Point b){
		p[0] = a;
		p[1] = b;
	}
	/*void outPut(){

		printf("(%.3lf,%.3lf)-(%.3lf,%.3lf)\n",p[0].x,p[0].y,p[1].x,p[1].y);
	}*/
	Point p[2];
};

struct Circle{
	Point center;
	double r;
};

struct Info{
	Info(Point arg_p,Type arg_type,int arg_index){
		p = arg_p;
		type = arg_type;
		index = arg_index;
	}
	bool operator<(const struct Info& arg) const{

		return p < arg.p;
	}
	Point p;
	Type type;
	int index;
};

Circle C[3];


double calc_dist(Point A,Point B){

	return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}


double norm(Vector a){
	return a.x*a.x+a.y*a.y;
}

double abs(Vector a){
	return sqrt(norm(a));
}

double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

double dot(Vector a,Vector b){
    return a.x*b.x + a.y*b.y;
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

/*
 * p0を基準点として、p1から見てp2が
 * 反時計回り側にあれば
 * COUNTER_CLOCKWISE
 * */
int ccw(Point p0,Point p1,Point p2){

	Vector a = p1 - p0;
	Vector b = p2 - p0;

	if(cross(a,b) > EPS)return COUNTER_CLOCKWISE;
	if(cross(a,b) < -EPS)return CLOCKWISE;
	if(dot(a,b) < -EPS)return ONLINE_BACK;
	if(a.norm() < b.norm())return ONLINE_FRONT;

	return ON_SEGMENT;
}


Point project(Line l,Point p){

	Vector base = l.p[1]-l.p[0];
	double r = dot(p-l.p[0],base)/norm(base);
	return l.p[0]+base*r;
}

//円と直線の交点を求める関数
vector<Point> getCrossPoints(Circle c,Line l){

	vector<Point> ret;

	Vector pr = project(l,c.center);
	Vector e = (l.p[1]-l.p[0])/abs(l.p[1]-l.p[0]);

	double base;

	if(fabs(c.r*c.r-norm(pr-c.center)) < EPS){

		base = 0;
	}else{
		base = sqrt(c.r*c.r-norm(pr-c.center));
	}

	ret.push_back(Point(pr+e*base));
	ret.push_back(Point(pr-e*base));

	return ret;
}


Point calc_minus(Point a,Point b){
    Point ret;

    ret.x = a.x-b.x;
    ret.y = a.y-b.y;

    return ret;
}

double calc_len(Vector a){
    return sqrt(a.x*a.x+a.y*a.y);
}

//線分ではなく直線と点の距離
double getDistanceLP(Line l,Point p){
    return fabs(cross(calc_minus(l.p[1],l.p[0]),calc_minus(p,l.p[0]))/calc_len(calc_minus(l.p[1],l.p[0])));
}

int main(){

	double R;
	scanf("%lf",&R);

	double left = HUGE_NUM,right = -HUGE_NUM;

	for(int i = 0; i < 3; i++){

		scanf("%lf %lf",&C[i].center.x,&C[i].center.y);
		C[i].r = R;

		left = min(left,C[i].center.x-R);
		right = max(right,C[i].center.x+R);
	}

	double diff = 0.00005;
	double NUM = 10000;

	double ans = 0;

	for(double x = left; x <= right; x += diff){

		Line tmp_line = Line(Point(x,-NUM),Point(x,NUM));

		vector<Info> P;

		for(int i = 0; i < 3; i++){

			double tmp_dist = getDistanceLP(tmp_line,C[i].center);
			if(tmp_dist > R+EPS)continue;

			vector<Point> vec = getCrossPoints(C[i],tmp_line);

			if(vec[0].y > vec[1].y){

				swap(vec[0],vec[1]);
			}
			P.push_back(Info(vec[0],Under,i));
			P.push_back(Info(vec[1],Top,i));
		}

		if(P.size() == 0)continue;

		sort(P.begin(),P.end());

		double pre = -1;
		int sum = 0;

		for(int i = 0; i < P.size(); i++){

			if(i == 0){

				sum = 1;
				pre = P[i].p.y;
				continue;
			}
			if(sum > 0){

				ans += (P[i].p.y-pre)*diff;
			}
			if(P[i].type == Under){

				sum++;
			}else{

				sum--;
			}
			pre = P[i].p.y;
		}
	}

	printf("%.12lf\n",ans);

	return 0;
}
accuracy: 0.11538461538461539
time_ms: 140
memory_kb: 3200
final_rank: 13

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



enum Type{
	Top,
	Under,
};

struct Point{
	Point(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}

	Point(){
		x = y = 0.0;
	}

	Point operator + (Point p){ return Point(x+p.x,y+p.y); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){ return Point(a*x,a*y); }
	Point operator / (double a){ return Point(x/a,y/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator<(const Point &p) const{

		if(fabs(x-p.x) > EPS){

			return x < p.x;
		}else{

			return y < p.y;
		}
	}

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}


	void debug(){

		printf("(%.3lf,%.3lf)\n",x,y);
	}

	double x,y;
};

typedef Point Vector;

struct Line{
	Line(){

	}
	Line(Point a,Point b){
		p[0] = a;
		p[1] = b;
	}
	/*void outPut(){

		printf("(%.3lf,%.3lf)-(%.3lf,%.3lf)\n",p[0].x,p[0].y,p[1].x,p[1].y);
	}*/
	Point p[2];
};

struct Circle{
	Point center;
	double r;
};

struct Info{
	Info(Point arg_p,Type arg_type){
		p = arg_p;
		type = arg_type;
	}
	bool operator<(const struct Info& arg) const{

		return p < arg.p;
	}
	Point p;
	Type type;
};

Circle C[3];


double calc_dist(Point A,Point B){

	return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}


double norm(Vector a){
	return a.x*a.x+a.y*a.y;
}

double abs(Vector a){
	return sqrt(norm(a));
}

double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

double dot(Vector a,Vector b){
    return a.x*b.x + a.y*b.y;
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

/*
 * p0を基準点として、p1から見てp2が
 * 反時計回り側にあれば
 * COUNTER_CLOCKWISE
 * */
int ccw(Point p0,Point p1,Point p2){

	Vector a = p1 - p0;
	Vector b = p2 - p0;

	if(cross(a,b) > EPS)return COUNTER_CLOCKWISE;
	if(cross(a,b) < -EPS)return CLOCKWISE;
	if(dot(a,b) < -EPS)return ONLINE_BACK;
	if(a.norm() < b.norm())return ONLINE_FRONT;

	return ON_SEGMENT;
}


Point project(Line l,Point p){

	Vector base = l.p[1]-l.p[0];
	double r = dot(p-l.p[0],base)/norm(base);
	return l.p[0]+base*r;
}

//円と直線の交点を求める関数
vector<Point> getCrossPoints(Circle c,Line l){

	vector<Point> ret;

	Vector pr = project(l,c.center);
	Vector e = (l.p[1]-l.p[0])/abs(l.p[1]-l.p[0]);

	double base;

	if(fabs(c.r*c.r-norm(pr-c.center)) < EPS){

		base = 0;
	}else{
		base = sqrt(c.r*c.r-norm(pr-c.center));
	}

	ret.push_back(Point(pr+e*base));
	ret.push_back(Point(pr-e*base));

	return ret;
}


Point calc_minus(Point a,Point b){
    Point ret;

    ret.x = a.x-b.x;
    ret.y = a.y-b.y;

    return ret;
}

double calc_len(Vector a){
    return sqrt(a.x*a.x+a.y*a.y);
}

//線分ではなく直線と点の距離
double getDistanceLP(Line l,Point p){
    return fabs(cross(calc_minus(l.p[1],l.p[0]),calc_minus(p,l.p[0]))/calc_len(calc_minus(l.p[1],l.p[0])));
}

int main(){

	double R;
	scanf("%lf",&R);

	double left = HUGE_NUM,right = -HUGE_NUM;

	for(int i = 0; i < 3; i++){

		scanf("%lf %lf",&C[i].center.x,&C[i].center.y);
		C[i].r = R;

		left = min(left,C[i].center.x-R);
		right = max(right,C[i].center.x+R);
	}

	double diff = 0.00001;
	double NUM = 10000;

	double ans = 0;

	for(double x = left; x <= right; x += diff){

		Line tmp_line = Line(Point(x,-NUM),Point(x,NUM));

		vector<Info> P;

		for(int i = 0; i < 3; i++){

			double tmp_dist = getDistanceLP(tmp_line,C[i].center);
			if(tmp_dist > R+EPS)continue;

			vector<Point> vec = getCrossPoints(C[i],tmp_line);

			if(vec[0].y > vec[1].y){

				swap(vec[0],vec[1]);
			}
			P.push_back(Info(vec[0],Under));
			P.push_back(Info(vec[1],Top));
		}

		if(P.size() == 0)continue;

		sort(P.begin(),P.end());

		for(int i = 1; i < P.size(); i++){

			if(P[i].type == Under && P[i-1].type == Top)continue;

			ans += (P[i].p.y-P[i-1].p.y)*diff;
		}
	}

	printf("%.12lf\n",ans);

	return 0;
}
accuracy: 0.038461538461538464
time_ms: 260
memory_kb: 3172
final_rank: 19

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



enum Type{
	Top,
	Under,
};

struct Point{
	Point(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}

	Point(){
		x = y = 0.0;
	}

	Point operator + (Point p){ return Point(x+p.x,y+p.y); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){ return Point(a*x,a*y); }
	Point operator / (double a){ return Point(x/a,y/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator<(const Point &p) const{

		if(fabs(x-p.x) > EPS){

			return x < p.x;
		}else{

			return y < p.y;
		}
	}

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}


	void debug(){

		printf("(%.3lf,%.3lf)\n",x,y);
	}

	double x,y;
};

typedef Point Vector;

struct Line{
	Line(){

	}
	Line(Point a,Point b){
		p[0] = a;
		p[1] = b;
	}
	/*void outPut(){

		printf("(%.3lf,%.3lf)-(%.3lf,%.3lf)\n",p[0].x,p[0].y,p[1].x,p[1].y);
	}*/
	Point p[2];
};

struct Circle{
	Point center;
	double r;
};

struct Info{
	Info(Point arg_p,Type arg_type){
		p = arg_p;
		type = arg_type;
	}
	bool operator<(const struct Info& arg) const{

		return p < arg.p;
	}
	Point p;
	Type type;
};

Circle C[3];


double calc_dist(Point A,Point B){

	return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}


double norm(Vector a){
	return a.x*a.x+a.y*a.y;
}

double abs(Vector a){
	return sqrt(norm(a));
}

double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

double dot(Vector a,Vector b){
    return a.x*b.x + a.y*b.y;
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

/*
 * p0を基準点として、p1から見てp2が
 * 反時計回り側にあれば
 * COUNTER_CLOCKWISE
 * */
int ccw(Point p0,Point p1,Point p2){

	Vector a = p1 - p0;
	Vector b = p2 - p0;

	if(cross(a,b) > EPS)return COUNTER_CLOCKWISE;
	if(cross(a,b) < -EPS)return CLOCKWISE;
	if(dot(a,b) < -EPS)return ONLINE_BACK;
	if(a.norm() < b.norm())return ONLINE_FRONT;

	return ON_SEGMENT;
}


Point project(Line l,Point p){

	Vector base = l.p[1]-l.p[0];
	double r = dot(p-l.p[0],base)/norm(base);
	return l.p[0]+base*r;
}

//円と直線の交点を求める関数
vector<Point> getCrossPoints(Circle c,Line l){

	vector<Point> ret;

	Vector pr = project(l,c.center);
	Vector e = (l.p[1]-l.p[0])/abs(l.p[1]-l.p[0]);

	double base;

	if(fabs(c.r*c.r-norm(pr-c.center)) < EPS){

		base = 0;
	}else{
		base = sqrt(c.r*c.r-norm(pr-c.center));
	}

	ret.push_back(Point(pr+e*base));
	ret.push_back(Point(pr-e*base));

	return ret;
}


Point calc_minus(Point a,Point b){
    Point ret;

    ret.x = a.x-b.x;
    ret.y = a.y-b.y;

    return ret;
}

double calc_len(Vector a){
    return sqrt(a.x*a.x+a.y*a.y);
}

//線分ではなく直線と点の距離
double getDistanceLP(Line l,Point p){
    return fabs(cross(calc_minus(l.p[1],l.p[0]),calc_minus(p,l.p[0]))/calc_len(calc_minus(l.p[1],l.p[0])));
}

int main(){

	double R;
	scanf("%lf",&R);

	double left = HUGE_NUM,right = -HUGE_NUM;

	for(int i = 0; i < 3; i++){

		scanf("%lf %lf",&C[i].center.x,&C[i].center.y);
		C[i].r = R;

		left = min(left,C[i].center.x-R);
		right = max(right,C[i].center.x+R);
	}

	double diff = 0.00005;
	double NUM = 10000;

	double ans = 0;

	for(double x = left; x <= right; x += diff){

		Line tmp_line = Line(Point(x,-NUM),Point(x,NUM));

		vector<Info> P;

		for(int i = 0; i < 3; i++){

			double tmp_dist = getDistanceLP(tmp_line,C[i].center);
			if(tmp_dist > R+EPS)continue;

			vector<Point> vec = getCrossPoints(C[i],tmp_line);

			if(vec[0].y > vec[1].y){

				swap(vec[0],vec[1]);
			}
			P.push_back(Info(vec[0],Under));
			P.push_back(Info(vec[1],Top));
		}

		if(P.size() == 0)continue;

		sort(P.begin(),P.end());

		for(int i = 1; i < P.size(); i++){

			if(P[i].type == Under && P[i-1].type == Top)continue;

			ans += (P[i].p.y-P[i-1].p.y)*diff;
		}
	}

	printf("%.12lf\n",ans);

	return 0;
}
accuracy: 0.038461538461538464
time_ms: 50
memory_kb: 3204
final_rank: 18