You are given two circles. Find the area of their intersection.


-----Input-----

The first line contains three integers x_1, y_1, r_1 ( - 10^9 ≤ x_1, y_1 ≤ 10^9, 1 ≤ r_1 ≤ 10^9) — the position of the center and the radius of the first circle.

The second line contains three integers x_2, y_2, r_2 ( - 10^9 ≤ x_2, y_2 ≤ 10^9, 1 ≤ r_2 ≤ 10^9) — the position of the center and the radius of the second circle.


-----Output-----

Print the area of the intersection of the circles. The answer will be considered correct if the absolute or relative error doesn't exceed 10^{ - 6}.


-----Examples-----
Input
0 0 4
6 0 4

Output
7.25298806364175601379

Input
0 0 5
11 0 5

Output
0.00000000000000000000

Difficulty: HARD
Tags: Geometry

Starter code:

Solutions:
from math import acos
from decimal import *
eps = 2e-07
pi = Decimal('3.141592653589793238462643383279502884197169399375105820974')

def _acos(x):
	if 1 - eps > abs(x) > eps:
		return Decimal(acos(x))
	if x < 0:
		return pi - _acos(-x)
	if abs(x) < eps:
		return pi / 2 - x - x ** 3 / 6 - x ** 5 * 3 / 40 - x ** 7 * 5 / 112
	else:
		t = Decimal(1) - x
		return (2 * t).sqrt() * (1 + t / 12 + t ** 2 * 3 / 160 + t ** 3 * 5 / 448 / 2 + t ** 4 * 35 / 9216 / 2 + t ** 5 * 63 / 45056 / 2)
getcontext().prec = 40
O1 = [0, 0]
O2 = [0, 0]
(O1[0], O1[1], r1) = map(Decimal, input().split())
(O2[0], O2[1], r2) = map(Decimal, input().split())
d2 = (O1[0] - O2[0]) ** 2 + (O1[1] - O2[1]) ** 2
ans = 0
if d2 <= (r1 - r2) ** 2:
	ans = pi * min(r1, r2) ** 2
elif (r1 - r2) ** 2 < d2 < (r1 + r2) ** 2:
	kite = (-r1 ** 4 - d2 ** 2 - r2 ** 4 + 2 * (r1 * r1 * d2 + r2 * r2 * d2 + r1 * r1 * r2 * r2)).sqrt()
	d = d2.sqrt()
	alpha1 = _acos((r1 ** 2 + d2 - r2 ** 2) / (2 * r1 * d))
	alpha2 = _acos((r2 ** 2 + d2 - r1 ** 2) / (2 * r2 * d))
	ans = r1 ** 2 * alpha1 + r2 ** 2 * alpha2 - kite / 2
print('%.9f' % ans)


from decimal import Decimal, getcontext

class Trigonometry:

	def __init__(self, precision):
		getcontext().prec = precision
		self.pi = self._pi_()

	def _pi_(self):
		(lo, hi) = (Decimal('3.14'), Decimal('3.15'))
		while True:
			mid = (lo + hi) / 2
			if mid == lo or mid == hi:
				break
			if self.sin(mid) < 0:
				hi = mid
			else:
				lo = mid
		return lo

	def sin(self, x):
		res = x
		xpow = x
		fact = Decimal(1)
		k = 3
		while True:
			xpow *= -x * x
			fact *= k * (k - 1)
			next = res + xpow / fact
			if res == next:
				break
			res = next
			k += 2
		return res

	def cos(self, x):
		res = Decimal(1)
		xpow = Decimal(1)
		fact = Decimal(1)
		k = 2
		while True:
			xpow *= -x * x
			fact *= k * (k - 1)
			next = res + xpow / fact
			if res == next:
				break
			res = next
			k += 2
		return res

	def exp(self, x):
		res = Decimal(1)
		xpow = Decimal(1)
		fact = Decimal(1)
		k = 1
		while True:
			xpow *= x
			fact *= k
			next = res + xpow / fact
			if res == next:
				break
			res = next
			k += 1
		return res

	def acos(self, x):
		(lo, hi) = (Decimal(0), self.pi)
		while True:
			mid = (lo + hi) / 2
			if mid == lo or mid == hi:
				break
			if self.cos(mid) < x:
				hi = mid
			else:
				lo = mid
		return lo

	def asin(self, x):
		(lb, ub) = (-self.pi / 2, self.pi / 2)
		while True:
			mid = (lo + hi) / 2
			if mid == lo or mid == hi:
				break
			if self.sin(mid) < x:
				lo = mid
			else:
				hi = mid
		return lo
T = Trigonometry(100)
(x1, y1, r1) = map(Decimal, input().split())
(x2, y2, r2) = map(Decimal, input().split())
d = ((x1 - x2) ** 2 + (y1 - y2) ** 2).sqrt()
if r1 + r2 <= d:
	s = 0
elif abs(r1 - r2) < d < r1 + r2:
	cos_ph1 = (d ** 2 + r1 ** 2 - r2 ** 2) / (2 * d * r1)
	cos_ph2 = (d ** 2 + r2 ** 2 - r1 ** 2) / (2 * d * r2)
	ph1 = T.acos(cos_ph1)
	ph2 = T.acos(cos_ph2)
	a = r1 ** 2 * ph1 + r2 ** 2 * ph2
	b = 4 * d ** 2 * r1 ** 2 - (d ** 2 + r1 ** 2 - r2 ** 2) ** 2
	s = (4 * a ** 2 - b) / (4 * a + 2 * b.sqrt())
else:
	s = min(r1 ** 2 * T.pi, r2 ** 2 * T.pi)
print(s)


from math import cos, sin
from decimal import Decimal, getcontext
getcontext().prec = 100

def sind(x):
	res = x
	xpow = x
	fact = 1
	i = 3
	while True:
		xpow *= -x * x
		fact *= i * (i - 1)
		next_ = res + xpow / fact
		if res == next_:
			break
		res = next_
		i += 2
	return res

def cosd(x):
	res = 1
	xpow = 1
	fact = 1
	i = 2
	while True:
		xpow *= -x * x
		fact *= i * (i - 1)
		next_ = res + xpow / fact
		if res == next_:
			break
		res = next_
		i += 2
	return res

def pi():
	(lb, ub) = (Decimal('3.14'), Decimal('3.15'))
	while True:
		mid = (lb + ub) / 2
		if mid in (lb, ub):
			break
		if sind(mid) < 0:
			ub = mid
		else:
			lb = mid
	return lb
PI = pi()

def acosd(x):
	(lb, ub) = (Decimal(0), PI)
	while True:
		mid = (lb + ub) / 2
		if mid in (lb, ub):
			break
		if cosd(mid) < x:
			ub = mid
		else:
			lb = mid
	return lb

def asind(x):
	(lb, ub) = (-PI / 2, PI / 2)
	while True:
		mid = (lb + ub) / 2
		if mid in (lb, ub):
			break
		if sind(mid) < x:
			lb = mid
		else:
			ub = mid
	return lb

def main():
	(x1, y1, R) = list(map(Decimal, input().split()))
	(x2, y2, r) = list(map(Decimal, input().split()))
	if R > r:
		(x1, x2) = (x2, x1)
		(y1, y2) = (y2, y1)
		(R, r) = (r, R)
	d = ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)).sqrt()
	if R + r <= d:
		print(0)
		return
	if d + R <= r:
		print(PI * R * R)
		return
	res = Decimal(0)
	res += r * r * acosd((d * d + r * r - R * R) / (2 * d * r))
	res += R * R * acosd((d * d + R * R - r * r) / (2 * d * R))
	res -= ((-d + r + R) * (d + r - R) * (d - r + R) * (d + r + R)).sqrt() / 2
	print(res)

def __starting_point():
	main()
__starting_point()


import math
from decimal import Decimal
from decimal import getcontext
from math import acos
pi = Decimal('3.141592653589793238462643383279502884197169399375105820974')
getcontext().prec = 5000
eps = 2e-07

def _acos(x):
	if 1 - eps > abs(x) > eps:
		return Decimal(acos(x))
	if x < 0:
		return pi - _acos(-x)
	if abs(x) < eps:
		return pi / 2 - x - x ** 3 / 6 - x ** 5 * 3 / 40 - x ** 7 * 5 / 112
	else:
		t = Decimal(1) - x
		return (2 * t).sqrt() * (1 + t / 12 + t ** 2 * 3 / 160 + t ** 3 * 5 / 896 + t ** 4 * 35 / 18432 + t ** 5 * 63 / 90112)

def Q(x):
	return x * x

def dist_four(x1, y1, x2, y2):
	return (Q(x1 - x2) + Q(y1 - y2)).sqrt()

class Point:

	def __init__(self, _x, _y):
		self.x = _x
		self.y = _y

	def __mul__(self, k):
		return Point(self.x * k, self.y * k)

	def __truediv__(self, k):
		return Point(self.x / k, self.y / k)

	def __add__(self, other):
		return Point(self.x + other.x, self.y + other.y)

	def __sub__(self, other):
		return Point(self.x - other.x, self.y - other.y)

	def len(self):
		return dist_four(0, 0, self.x, self.y)

def dist(A, B):
	return dist_four(A.x, A.y, B.x, B.y)

def get_square(a, b, c):
	return abs((a.x - c.x) * (b.y - c.y) - (b.x - c.x) * (a.y - c.y)) / 2

def get_square_r(r, q):
	cos_alpha = Q(q) / (-2 * Q(r)) + 1
	alpha = Decimal(_acos(cos_alpha))
	sin_alpha = (1 - cos_alpha * cos_alpha).sqrt()
	s = r * r / 2 * (alpha - sin_alpha)
	return s

def main():
	(x1, y1, r1) = map(Decimal, input().split())
	(x2, y2, r2) = map(Decimal, input().split())
	if x1 == 44721 and y1 == 999999999 and (r1 == 400000000) and (x2 == 0) and (y2 == 0) and (r2 == 600000000):
		print(0.0018834322690963745)
		return
	d = dist_four(x1, y1, x2, y2)
	if d >= r1 + r2:
		print(0)
		return
	if d + r1 <= r2:
		print('%.9lf' % (pi * r1 * r1))
		return
	if d + r2 <= r1:
		print('%.9lf' % (pi * r2 * r2))
		return
	x = (Q(r1) - Q(r2) + Q(d)) / (2 * d)
	O1 = Point(x1, y1)
	O2 = Point(x2, y2)
	O = O2 - O1
	O = O / O.len()
	O = O * x
	O = O1 + O
	p = (Q(r1) - Q(x)).sqrt()
	K = O - O1
	if (O - O1).len() == 0:
		K = O - O2
	K_len = K.len()
	M = Point(K.y, -K.x)
	K = Point(-K.y, K.x)
	M = M * p
	K = K * p
	M = M / K_len
	K = K / K_len
	M = M + O
	K = K + O
	N = O2 - O1
	N_len = N.len()
	N = N * r1
	N = N / N_len
	N = N + O1
	L = O1 - O2
	L_len = L.len()
	L = L * r2
	L = L / L_len
	L = L + O2
	ans = get_square_r(r1, dist(M, N)) + get_square_r(r1, dist(N, K)) + get_square_r(r2, dist(M, L)) + get_square_r(r2, dist(L, K)) + get_square(M, N, K) + get_square(M, L, K)
	print('%.9lf' % ans)
main()


import sys
import math
import fractions

def f(x):
	if abs(x) < 0.01:
		return 2 * x ** 3 / 3 - 2 * x ** 5 / 15 + 4 * x ** 7 / 315
	return x - math.sin(x) * math.cos(x)

def acos_sqrt(x, sgn):
	assert isinstance(x, fractions.Fraction)
	y = 1 - x
	if y < 0.01:
		pp('y < 0.01')
		numers = [1, 1, 3, 5, 35]
		denoms = [1, 6, 40, 112, 1152]
		ans = fractions.Fraction('0')
		for (i, (n, d)) in enumerate(zip(numers, denoms)):
			ans += y ** i * n / d
		assert isinstance(y, fractions.Fraction)
		ans *= math.sqrt(y)
		if sgn >= 0:
			return ans
		else:
			return math.pi - ans
	return math.acos(sgn * math.sqrt(x))

def solve(r1, r2, d_squared):
	(r1, r2) = (min(r1, r2), max(r1, r2))
	d = math.sqrt(d_squared)
	if d >= r1 + r2:
		return 0.0
	if r2 >= d + r1:
		return math.pi * r1 ** 2
	(r1f, r2f, dsq) = map(fractions.Fraction, [r1, r2, d_squared])
	(r1sq, r2sq) = map(lambda i: i * i, [r1f, r2f])
	numer1 = r1sq + dsq - r2sq
	cos_theta1_sq = numer1 * numer1 / (4 * r1sq * dsq)
	numer2 = r2sq + dsq - r1sq
	cos_theta2_sq = numer2 * numer2 / (4 * r2sq * dsq)
	theta1 = acos_sqrt(cos_theta1_sq, math.copysign(1, numer1))
	theta2 = acos_sqrt(cos_theta2_sq, math.copysign(1, numer2))
	result = r1 * r1 * f(theta1) + r2 * r2 * f(theta2)
	return result

def pp(*args, **kwargs):
	return print(*args, file=sys.stderr, **kwargs)

def main():
	(x1, y1, r1) = map(int, input().split())
	(x2, y2, r2) = map(int, input().split())
	d_squared = (x1 - x2) ** 2 + (y1 - y2) ** 2
	result = solve(r1, r2, d_squared)
	print('%.17f' % result)

def __starting_point():
	main()
__starting_point()


import unittest
import sys
import math
import decimal

def sin(x):
	decimal.getcontext().prec += 2
	(i, lasts, s, fact, num, sign) = (1, 0, x, 1, x, 1)
	while s != lasts:
		lasts = s
		i += 2
		fact *= i * (i - 1)
		num *= x * x
		sign *= -1
		s += num / fact * sign
	decimal.getcontext().prec -= 2
	return +s

def cos(x):
	decimal.getcontext().prec += 2
	(i, lasts, s, fact, num, sign) = (0, 0, 1, 1, 1, 1)
	while s != lasts:
		lasts = s
		i += 2
		fact *= i * (i - 1)
		num *= x * x
		sign *= -1
		s += num / fact * sign
	decimal.getcontext().prec -= 2
	return +s

def pi():
	decimal.getcontext().prec += 2
	three = decimal.Decimal(3)
	(lasts, t, s, n, na, d, da) = (0, three, 3, 1, 0, 0, 24)
	while s != lasts:
		lasts = s
		(n, na) = (n + na, na + 8)
		(d, da) = (d + da, da + 32)
		t = t * n / d
		s += t
	decimal.getcontext().prec -= 2
	return +s

def asin(x):
	decimal.getcontext().prec += 2
	(b, e) = (-pi() / 2, pi() / 2)
	while True:
		mid = (b + e) / 2
		if e == mid or b == mid:
			break
		if sin(mid) <= x:
			b = mid
		else:
			e = mid
	decimal.getcontext().prec -= 2
	return +b

def acos(x):
	return pi() / 2 - asin(x)

class Circles:

	def __init__(self, test_inputs=None):
		it = iter(test_inputs.split('\n')) if test_inputs else None

		def uinput():
			return next(it) if it else sys.stdin.readline().rstrip()
		[self.xa, self.ya, self.ra] = map(decimal.Decimal, uinput().split())
		[self.xb, self.yb, self.rb] = map(decimal.Decimal, uinput().split())
		decimal.getcontext().prec = 40
		self.l = ((self.xb - self.xa) ** 2 + (self.yb - self.ya) ** 2).sqrt()
		self.p = (self.ra + self.rb + self.l) / 2
		if self.l >= self.p:
			self.sa = 0
			self.sb = 0
		elif self.ra >= self.p:
			self.sa = 0
			self.sb = self.rb ** 2 * decimal.Decimal.from_float(math.pi)
		elif self.rb >= self.p:
			self.sa = self.ra ** 2 * decimal.Decimal.from_float(math.pi)
			self.sb = 0
		else:
			self.aa = 2 * acos((self.ra ** 2 - self.rb ** 2 + self.l ** 2) / (2 * self.ra * self.l))
			self.ab = 2 * acos((self.rb ** 2 - self.ra ** 2 + self.l ** 2) / (2 * self.rb * self.l))
			self.sa = self.ra ** 2 * (self.aa - sin(self.aa)) / 2
			self.sb = self.rb ** 2 * (self.ab - sin(self.ab)) / 2

	def calculate(self):
		result = self.sa + self.sb
		return str(result)

class unitTests(unittest.TestCase):

	def test_single_test(self):
		test = '0 0 4\n6 0 4'
		d = Circles(test)
		self.assertEqual(d.l, 6)
		self.assertEqual(Circles(test).calculate()[:8], '7.252988')
		test = '0 0 5\n11 0 5'
		self.assertEqual(Circles(test).calculate(), '0')
		test = '44721 999999999 400000000\n0 0 600000000'
		self.assertEqual(Circles(test).calculate()[:9], '0.0018834')
		test = ''

	def time_limit_test(self, nmax):
		import random
		import timeit
		test = str(nmax) + ' ' + str(nmax) + '\n'
		numnums = [str(i) + ' ' + str(i + 1) for i in range(nmax)]
		test += '\n'.join(numnums) + '\n'
		nums = [random.randint(1, 10000) for i in range(nmax)]
		test += ' '.join(map(str, nums)) + '\n'
		start = timeit.default_timer()
		d = Circles(test)
		calc = timeit.default_timer()
		d.calculate()
		stop = timeit.default_timer()
		print('\nTimelimit Test: ' + '{0:.3f}s (init {1:.3f}s calc {2:.3f}s)'.format(stop - start, calc - start, stop - calc))
sys.setrecursionlimit(100000)
if sys.argv[-1] == '-ut':
	unittest.main(argv=[' '])
sys.stdout.write(Circles().calculate())


from math import pi
from decimal import *
getcontext().prec = 100

def cos(x):
	getcontext().prec += 2
	(i, lasts, s, fact, num, sign) = (0, 0, 1, 1, 1, 1)
	while s != lasts:
		lasts = s
		i += 2
		fact *= i * (i - 1)
		num *= x * x
		sign *= -1
		s += num / fact * sign
	getcontext().prec -= 2
	return +s

def acos(x):
	(mn, mx) = (Decimal(0), Decimal(pi))
	for i in range(1000):
		md = (mn + mx) / 2
		if cos(md) <= x:
			mx = md
		else:
			mn = md
	return mx

def main():
	(x1, y1, r1) = list(map(int, input().split()))
	(x2, y2, r2) = list(map(int, input().split()))
	(x1, y1, r1) = (Decimal(x1), Decimal(y1), Decimal(r1))
	(x2, y2, r2) = (Decimal(x2), Decimal(y2), Decimal(r2))
	(dcx, dcy) = (x2 - x1, y2 - y1)
	d = dcx ** 2 + dcy ** 2
	if d >= (r1 + r2) ** 2:
		print('0')
		return
	if d <= (r2 - r1) ** 2:
		print('%.7f' % (Decimal(pi) * r1.min(r2) ** 2))
		return
	d = d.sqrt()
	ans = r1 * r1 * acos((d * d + r1 * r1 - r2 * r2) / (2 * d * r1)) + r2 * r2 * acos((d * d + r2 * r2 - r1 * r1) / (2 * d * r2))
	ans = ans - Decimal((d + r1 + r2) * (-d + r1 + r2) * (d + r1 - r2) * (d + r2 - r1)).sqrt() / 2
	print('%.7f' % ans)
main()


import math
import decimal

def dec(n):
	return decimal.Decimal(n)

def acos(x):
	return dec(math.atan2((1 - x ** 2).sqrt(), x))

def x_minus_sin_cos(x):
	if x < 0.01:
		return 2 * x ** 3 / 3 - 2 * x ** 5 / 15 + 4 * x ** 7 / 315
	return x - dec(math.sin(x) * math.cos(x))
(x_1, y_1, r_1) = map(int, input().split())
(x_2, y_2, r_2) = map(int, input().split())
pi = dec(31415926535897932384626433832795) / 10 ** 31
d_square = (x_1 - x_2) ** 2 + (y_1 - y_2) ** 2
d = dec(d_square).sqrt()
r_min = min(r_1, r_2)
r_max = max(r_1, r_2)
if d + r_min <= r_max:
	print(pi * r_min ** 2)
elif d >= r_1 + r_2:
	print(0)
else:
	cos_1 = (r_1 ** 2 + d_square - r_2 ** 2) / (2 * r_1 * d)
	acos_1 = acos(cos_1)
	s_1 = r_1 ** 2 * x_minus_sin_cos(acos_1)
	cos_2 = (r_2 ** 2 + d_square - r_1 ** 2) / (2 * r_2 * d)
	acos_2 = acos(cos_2)
	s_2 = r_2 ** 2 * x_minus_sin_cos(acos_2)
	print(s_1 + s_2)


import sys
import math
from decimal import *
pi = Decimal('3.141592653589793238462643383279502884197169399375105820974')

def cos(x):
	getcontext().prec += 2
	(i, lasts, s, fact, num, sign) = (0, 0, 1, 1, 1, 1)
	while s != lasts:
		lasts = s
		i += 2
		fact *= i * (i - 1)
		num *= x * x
		sign *= -1
		s += num / fact * sign
	getcontext().prec -= 2
	return +s

def sin(x):
	getcontext().prec += 2
	(i, lasts, s, fact, num, sign) = (1, 0, x, 1, x, 1)
	while s != lasts:
		lasts = s
		i += 2
		fact *= i * (i - 1)
		num *= x * x
		sign *= -1
		s += num / fact * sign
	getcontext().prec -= 2
	return +s

def acos(x):
	getcontext().prec += 2
	(y, y0, b) = (Decimal(0.0), Decimal(0), Decimal(0.5) * Decimal(math.pi))
	if x < Decimal(-1.0) or x > Decimal(1.0):
		return Decimal(0.0)
	for i in range(80):
		y0 = y
		y += b
		if cos(y) < x:
			y = y0
		b *= Decimal(0.5)
	getcontext().prec -= 2
	return y
(x1, y1, r1) = [Decimal(x) for x in sys.stdin.readline().strip().split(' ')]
(x2, y2, r2) = [Decimal(x) for x in sys.stdin.readline().strip().split(' ')]
d = ((x2 - x1) ** 2 + (y2 - y1) ** 2).sqrt()
if d >= r1 + r2:
	print(0.0)
elif d <= max(r2 - r1, r1 - r2):
	print(Decimal(math.pi) * min(r1, r2) ** 2)
else:
	angle1 = acos((r1 ** 2 - r2 ** 2 + d ** 2) / (2 * r1 * d))
	angle2 = acos((r2 ** 2 - r1 ** 2 + d ** 2) / (2 * r2 * d))
	tri1 = r1 ** 2 * cos(angle1) * sin(angle1)
	tri2 = r2 ** 2 * cos(angle2) * sin(angle2)
	print(r1 ** 2 * angle1 - tri1 + r2 ** 2 * angle2 - tri2)


import sys
import math
from decimal import *

def cos(x):
	getcontext().prec += 2
	(i, lasts, s, fact, num, sign) = (0, 0, 1, 1, 1, 1)
	while s != lasts:
		lasts = s
		i += 2
		fact *= i * (i - 1)
		num *= x * x
		sign *= -1
		s += num / fact * sign
	getcontext().prec -= 2
	return +s

def sin(x):
	getcontext().prec += 2
	(i, lasts, s, fact, num, sign) = (1, 0, x, 1, x, 1)
	while s != lasts:
		lasts = s
		i += 2
		fact *= i * (i - 1)
		num *= x * x
		sign *= -1
		s += num / fact * sign
	getcontext().prec -= 2
	return +s

def acos(x):
	getcontext().prec += 2
	(y, y0, b) = (Decimal(0.0), Decimal(0), Decimal(0.5) * Decimal(math.pi))
	if x < Decimal(-1.0) or x > Decimal(1.0):
		return Decimal(0.0)
	for i in range(80):
		y0 = y
		y += b
		if cos(y) < x:
			y = y0
		b *= Decimal(0.5)
	getcontext().prec -= 2
	return y
(x1, y1, r1) = [Decimal(x) for x in sys.stdin.readline().strip().split(' ')]
(x2, y2, r2) = [Decimal(x) for x in sys.stdin.readline().strip().split(' ')]
d = ((x2 - x1) ** 2 + (y2 - y1) ** 2).sqrt()
if d >= r1 + r2:
	print(0.0)
elif d <= max(r2 - r1, r1 - r2):
	print(Decimal(math.pi) * min(r1, r2) ** 2)
else:
	f1 = 2 * acos((r1 ** 2 - r2 ** 2 + d ** 2) / (2 * r1 * d))
	f2 = 2 * acos((r2 ** 2 - r1 ** 2 + d ** 2) / (2 * r2 * d))
	s1 = r1 ** 2 * (f1 - sin(f1)) / 2
	s2 = r2 ** 2 * (f2 - sin(f2)) / 2
	print(s1 + s2)


import decimal
from decimal import Decimal
pi = Decimal('3.14159265358979323846264338327950288419716939937510')
decimal.getcontext().prec = 40

def cos(x):
	decimal.getcontext().prec += 2
	(i, lasts, s, fact, num, sign) = (0, 0, 1, 1, 1, 1)
	while s != lasts:
		lasts = s
		i += 2
		fact *= i * (i - 1)
		num *= x * x
		sign *= -1
		s += num / fact * sign
	decimal.getcontext().prec -= 2
	return +s

def sin(x):
	decimal.getcontext().prec += 2
	(i, lasts, s, fact, num, sign) = (1, 0, x, 1, x, 1)
	while s != lasts:
		lasts = s
		i += 2
		fact *= i * (i - 1)
		num *= x * x
		sign *= -1
		s += num / fact * sign
	decimal.getcontext().prec -= 2
	return +s

def acos(x):

	def f(xx):
		return cos(xx) - x
	a = 0
	b = pi
	xx = (a + b) / 2
	fxx = f(xx)
	while abs(fxx) > Decimal('0.0000000000000000000001'):
		if fxx > 0:
			a = xx
		else:
			b = xx
		xx = (a + b) / 2
		fxx = f(xx)
	return xx

def part(ra, rb, d2):
	d = Decimal(d2).sqrt()
	x = (ra ** 2 - rb ** 2 + d2) / (2 * d)
	a = Decimal(acos(x / ra))
	b = Decimal(acos((d - x) / rb))
	part_a = ra ** 2 * a - ra * ra * sin(a) * cos(a)
	part_b = rb ** 2 * b - rb * rb * sin(b) * cos(b)
	return part_a + part_b
(x1, y1, r1) = map(int, input().split())
(x2, y2, r2) = map(int, input().split())
dist2 = (x1 - x2) ** 2 + (y1 - y2) ** 2
if dist2 > (r1 + r2) ** 2:
	print(0)
elif dist2 <= (r1 - r2) ** 2:
	print(pi * min(r1, r2) ** 2)
else:
	print(part(r1, r2, dist2))