You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α. [Image] 

Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.


-----Input-----

The first line contains three integers w, h, α (1 ≤ w, h ≤ 10^6; 0 ≤ α ≤ 180). Angle α is given in degrees.


-----Output-----

In a single line print a real number — the area of the region which belongs to both given rectangles.

The answer will be considered correct if its relative or absolute error doesn't exceed 10^{ - 6}.


-----Examples-----
Input
1 1 45

Output
0.828427125

Input
6 4 30

Output
19.668384925



-----Note-----

The second sample has been drawn on the picture above.

Source: codeforces | Difficulty: HARD
Tags: Geometry


Solutions:
from math import sin, cos, tan, atan, pi

def main():
	(w, h, a) = map(int, input().split())
	a = min(a, 180 - a) * pi / 180
	if h > w:
		(h, w) = (w, h)
	if h * (1 + cos(a)) < w * sin(a):
		res = h * h / sin(a)
	else:
		res = h * w - ((w - h * tan(a / 2)) ** 2 * tan(a) + (h - w * tan(a / 2)) ** 2 * tan(a)) / 4
	print('{:.9f}'.format(res))
main()


from math import *
(w, h, alpha) = [int(x) for x in input().strip().split()]
if alpha > 90:
	alpha = 180 - alpha
if w < h:
	(w, h) = (h, w)
c = cos(alpha * pi / 180.0)
s = sin(alpha * pi / 180.0)
t = tan(alpha * pi / 360.0)
print(h * h / s) if t > h / w else print((w * h - (w * w + h * h) / 2 * tan(alpha * pi / 360.0)) / c)


from math import sin, cos, tan
PI = 3.141592653589793
[w, h, a] = [int(i) for i in input().split()]
if h > w:
	(h, w) = (w, h)
if a > 90:
	a = 180 - a
if a == 0:
	print(w * h)
else:
	b = a * PI / 180
	w = w / 2.0
	h = h / 2.0
	if tan(b / 2) >= h / w:
		print(4 * h * h / sin(b))
	else:
		ans = 4 * w * h
		m = -1 / tan(b)
		c = w * sin(b) + w * cos(b) / tan(b)
		ans = ans - (h - m * w - c) * (w - (h - c) / m)
		m = tan(b)
		c = h * cos(b) + h * sin(b) * tan(b)
		ans = ans - (h + m * w - c) * ((h - c) / m + w)
		print(ans)


from math import sin, cos, pi, atan2
(w, h, a) = tuple(map(int, input().split()))
if a in [0, 180]:
	print(w * h)
elif a == 90:
	print(min(w, h) ** 2)
else:
	a *= pi / 180
	w /= 2
	h /= 2
	base = [(w, h), (-w, h), (-w, -h), (w, -h)]
	rot = [(x * cos(a) - y * sin(a), x * sin(a) + y * cos(a)) for (x, y) in base]
	pol = []
	for (i, j) in zip(range(-1, 3), range(4)):
		t = (w - rot[i][0]) / (rot[j][0] - rot[i][0])
		if 0 <= t <= 1:
			pol.append((w, rot[i][1] + (rot[j][1] - rot[i][1]) * t))
		t = (-w - rot[i][0]) / (rot[j][0] - rot[i][0])
		if 0 <= t <= 1:
			pol.append((-w, rot[i][1] + (rot[j][1] - rot[i][1]) * t))
		t = (h - rot[i][1]) / (rot[j][1] - rot[i][1])
		if 0 <= t <= 1:
			pol.append((rot[i][0] + (rot[j][0] - rot[i][0]) * t, h))
		t = (-h - rot[i][1]) / (rot[j][1] - rot[i][1])
		if 0 <= t <= 1:
			pol.append((rot[i][0] + (rot[j][0] - rot[i][0]) * t, -h))
	pol.sort(key=lambda x: atan2(*x))
	print('%0.9f' % (sum([abs(pol[i][0] * pol[j][1] - pol[i][1] * pol[j][0]) for (i, j) in zip(range(-1, len(pol) - 1), range(len(pol)))]) / 2))


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)
(w, h, a) = map(int, input().split())
if a == 0 or a == 180:
	print(w * h)
else:
	(w, h) = (max(w, h), min(w, h))
	if a > 90:
		a = 180 - a
	a = a * math.pi / 180
	if h * (1 + math.cos(a)) < w * math.sin(a):
		print(pow(h, 2) / math.sin(a))
	else:
		x = h - w * ((math.cos(a) + 1) / math.sin(a))
		t = math.tan(a) - (math.cos(a) + 1) * (math.cos(a) + 1) / (math.cos(a) * math.sin(a))
		x = x / t
		x = abs(x)
		b2 = w - x - x / math.cos(a)
		b2 = abs(b2)
		h2 = b2 / math.tan(a)
		h2 = abs(h2)
		h1 = h - h2 - h2 / math.cos(a)
		h1 = abs(h1)
		tbm = x * h1 + b2 * h2
		print(h * w - tbm)


import math
(w, h, a) = list(map(int, input().strip().split()))
if h > w:
	(w, h) = (h, w)
if a > 90:
	a = 90 - (a - 90)
a = math.radians(a)
if a < 2 * math.atan2(h, w):
	area = w * h
	s = w / 2 - h / 2 * math.tan(a / 2)
	bigger_area = 0.5 * s * s * math.tan(a)
	s = h / 2 - w / 2 * math.tan(a / 2)
	lower_area = 0.5 * s * s * math.tan(a)
	print(area - 2 * bigger_area - 2 * lower_area)
else:
	print(h * h / math.sin(a))


from math import radians, cos, sin, atan2

def rotate(point, alpha):
	x = point[0]
	y = point[1]
	return (x * cos(alpha) - y * sin(alpha), x * sin(alpha) + y * cos(alpha))

def crs(a, b):
	return a[0] * b[1] - a[1] * b[0]

def m(end, start):
	return (end[0] - start[0], end[1] - start[1])

def area(poly):
	ret = 0
	n = len(poly)
	for i in range(n):
		j = (i + 1) % n
		ret += crs(poly[i], poly[j])
	return abs(ret) / 2.0

def intersect(a, b, c, d):
	r = crs(m(c, d), m(a, d)) * crs(m(c, d), m(b, d)) <= 0
	r &= crs(m(b, a), m(c, a)) * crs(m(b, a), m(d, a)) <= 0
	if not r:
		return None
	x1 = a[0]
	y1 = a[1]
	x2 = c[0]
	y2 = c[1]
	dx1 = b[0] - a[0]
	dx2 = d[0] - c[0]
	dy1 = b[1] - a[1]
	dy2 = d[1] - c[1]
	if dx2 * dy1 == dx1 * dy2:
		return None
	t = ((x1 - x2) * dy2 + (y2 - y1) * dx2) / (dx2 * dy1 - dx1 * dy2)
	return (x1 + t * dx1, y1 + t * dy1)
(w, h, alpha) = list(map(int, input().split()))
if alpha == 0 or alpha == 180:
	print(w * h)
else:
	alpha = radians(alpha)
	pnt = []
	pnt.append((w / 2, h / 2))
	pnt.append((-w / 2, h / 2))
	pnt.append((-w / 2, -h / 2))
	pnt.append((w / 2, -h / 2))
	pnt2 = []
	for p in pnt:
		pnt2.append(rotate(p, alpha))
	pnt2.append(pnt2[0])
	pnt.append(pnt[0])
	points_total = []
	for st in range(4):
		for en in range(4):
			t = intersect(pnt[st], pnt[st + 1], pnt2[en], pnt2[en + 1])
			if t != None:
				points_total.append(t)
	points_total = sorted(points_total, key=lambda x: atan2(x[1], x[0]))
	print(area(points_total))


import sys
import math

def read_input(input_path=None):
	if input_path is None:
		f = sys.stdin
	else:
		f = open(input_path, 'r')
	(w, h, a) = map(int, f.readline().split())
	return (w, h, a)

def sol(w, h, a):
	if h > w:
		(w, h) = (h, w)
	if a > 90:
		a = 90 - (a - 90)
	a = math.radians(a)
	if a < 2 * math.atan2(h, w):
		area = w * h
		s = w / 2 - h / 2 * math.tan(a / 2)
		bigger_area = 0.5 * s * s * math.tan(a)
		s = h / 2 - w / 2 * math.tan(a / 2)
		lower_area = 0.5 * s * s * math.tan(a)
		res = area - 2 * bigger_area - 2 * lower_area
	else:
		res = h * h / math.sin(a)
	return [f'{res}']

def solve(input_path=None):
	return sol(*read_input(input_path))

def main():
	for line in sol(*read_input()):
		print(f'{line}')
main()


import math
from decimal import *
getcontext().prec = 40
EPS = Decimal(1e-21)
PI = Decimal(3.141592653589793)

def labs(x):
	if x < 0:
		return -x
	return x

class Point:

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

	def Add(self, p):
		self.x += p.x
		self.y += p.y

	def Sub(self, p):
		self.x -= p.x
		self.y -= p.y

	def Scale(self, v):
		self.x *= v
		self.y *= v

	def Rotate(self, angle):
		newX = self.x * Decimal(math.cos(angle)) - self.y * Decimal(math.sin(angle))
		newY = self.x * Decimal(math.sin(angle)) + self.y * Decimal(math.cos(angle))
		self.x = newX
		self.y = newY

	def Equals(self, p):
		if Decimal(labs(p.x - self.x)) < EPS and Decimal(labs(p.y - self.y)) < EPS:
			return True
		return False

class Line:

	def __init__(self, start, end):
		self.start = start
		self.end = end

	def GetIntersection(self, l):
		a = Point(self.start.x, self.start.y)
		b = Point(self.end.x, self.end.y)
		c = Point(l.start.x, l.start.y)
		d = Point(l.end.x, l.end.y)
		ab = Point(self.end.x, self.end.y)
		cd = Point(l.end.x, l.end.y)
		ab.Sub(a)
		cd.Sub(c)
		k = Decimal((cd.x * (a.y - c.y) + cd.y * (c.x - a.x)) / (ab.x * cd.y - ab.y * cd.x))
		ab.Scale(k)
		a.Add(ab)
		return a

class Polygon:

	def __init__(self, vertices):
		self.vertices = vertices

	def GetArea(self):
		area = Decimal(0)
		for i in range(0, len(self.vertices)):
			area += self.vertices[i].x * self.vertices[(i + 1) % len(self.vertices)].y - self.vertices[(i + 1) % len(self.vertices)].x * self.vertices[i].y
		return Decimal(labs(area)) / Decimal(2)
(x, y, alpha) = input().split()
x = Decimal(x)
y = Decimal(y)
if x < y:
	tmp = x
	x = y
	y = tmp
alpha = Decimal(alpha)
singleArea = x * y
if alpha > 90:
	alpha = Decimal(180) - alpha
if alpha == 0:
	print(singleArea)
	return
alpha = alpha * PI / Decimal(180)
a = Point(x / Decimal(2), y / Decimal(2))
b = Point(x / Decimal(2), -y / Decimal(2))
c = Point(-x / Decimal(2), -y / Decimal(2))
d = Point(-x / Decimal(2), y / Decimal(2))
e = Point(a.x, a.y)
f = Point(b.x, b.y)
g = Point(c.x, c.y)
h = Point(d.x, d.y)
e.Rotate(alpha)
f.Rotate(alpha)
g.Rotate(alpha)
h.Rotate(alpha)
ab = Line(a, b)
bc = Line(b, c)
cd = Line(c, d)
da = Line(d, a)
ef = Line(e, f)
fg = Line(f, g)
gh = Line(g, h)
he = Line(h, e)
area = 0
if a.Equals(f):
	t1 = Polygon([he.GetIntersection(da), e, f])
	t2 = Polygon([fg.GetIntersection(bc), g, h])
	area = singleArea - t1.GetArea() - t2.GetArea()
elif f.y > a.y:
	p1 = Polygon([he.GetIntersection(da), e, f, fg.GetIntersection(da)])
	p2 = Polygon([fg.GetIntersection(bc), g, h, he.GetIntersection(bc)])
	area = singleArea - p1.GetArea() - p2.GetArea()
else:
	t1 = Polygon([da.GetIntersection(he), e, ef.GetIntersection(da)])
	t2 = Polygon([ef.GetIntersection(ab), f, fg.GetIntersection(ab)])
	t3 = Polygon([fg.GetIntersection(bc), g, gh.GetIntersection(bc)])
	t4 = Polygon([gh.GetIntersection(cd), h, he.GetIntersection(cd)])
	area = singleArea - t1.GetArea() - t2.GetArea() - t3.GetArea() - t4.GetArea()
print(area)


from math import *
from sys import stdin, stdout
io = stdin.readline().split()
w = float(io[0])
h = float(io[1])
a = float(io[2])
if a > 90:
	a = 180 - a
if a == 0:
	print(w * h)
elif a == 90:
	print(min(w, h) ** 2)
else:
	a = a * pi / 180.0
	if w < h:
		(w, h) = (h, w)
	corner_x = cos(a) * (w / 2.0) + sin(a) * (h / 2.0)
	if corner_x >= w / 2:
		x0 = w / 2.0 + (h / 2.0 - h / 2.0 / cos(a)) * (cos(a) / sin(a))
		y0 = h / 2.0 - (tan(a) * (-w / 2.0) + h / 2.0 / cos(a))
		x1 = w / 2.0 - (h / 2.0 - w / 2.0 / sin(a)) * -tan(a)
		y1 = h / 2.0 - (-cos(a) / sin(a) * (w / 2.0) + w / 2.0 / sin(a))
		print(w * h - x1 * y1 - x0 * y0)
	else:
		y = tan(a) * (w / 2.0) - h / 2.0 / cos(a) + h / 2.0
		y0 = y - h
		x0 = y * tan(pi / 2.0 - a)
		print(w * h - (y0 * tan(pi / 2.0 - a) + x0) * h)


from math import cos, pi, sin, atan
(W, H, b) = map(float, input().split())
a = b / 180 * pi
if W < H:
	X = W
	W = H
	H = X
if a > 0.5 * pi:
	a = 0.5 * pi - (a - 0.5 * pi)
opp = W * H
if a == 0:
	eindopp = W * H
elif a > atan(H / W) * 2:
	Schuin = H / sin(a)
	eindopp = Schuin * H
else:
	y = -2 * cos(a) - cos(a) ** 2 - 1 + sin(a) ** 2
	hks = (W * sin(a) - H * cos(a) - H) / y
	hgs = (H - hks - hks * cos(a)) / sin(a)
	eindopp = opp - hks * sin(a) * hks * cos(a) - hgs * sin(a) * hgs * cos(a)
print(round(eindopp, 9))


import math
(w, h, alpha) = list(map(lambda x: int(x), input().split(' ')))
if alpha > 90:
	alpha = 180 - alpha
if alpha == 0:
	print(w * h)
elif alpha == 90:
	print(min(w, h) ** 2)
else:
	limit = 2 * math.degrees(math.atan(h / w))
	if limit > 90:
		limit = 180 - limit
	c = math.cos(math.radians(alpha))
	s = math.sin(math.radians(alpha))
	if alpha >= limit:
		print(min(w, h) ** 2 / s)
	else:
		print(w * h - (c - 1) * (4 * w * h * s - 2 * (w ** 2 + h ** 2)) / (4 * s * c))


mas = list(map(int, input().split()))
w = mas[0]
h = mas[1]
alf = mas[2]
import math
sina = abs(math.sin(alf / 180 * math.pi))
cosa = abs(math.cos(alf / 180 * math.pi))
sinb = h / (w ** 2 + h ** 2) ** 0.5
cosb = w / (w ** 2 + h ** 2) ** 0.5
sin2b = 2 * sinb * cosb
if sin2b >= sina:
	diskr = (cosa + 1) ** 2 - sina ** 2
	disc = w * (cosa + 1) - h * sina
	disf = h * (cosa + 1) - w * sina
	c = disc / diskr
	f = disf / diskr
	res = w * h - (c ** 2 + f ** 2) * sina * cosa
elif alf == 90:
	res = min(w, h) ** 2
else:
	res = min(h ** 2 / sina, w ** 2 / sina)
print(res)


import math

def rot_by_a(p, a):
	return (p[0] * math.cos(a) - p[1] * math.sin(a), p[0] * math.sin(a) + p[1] * math.cos(a))
(h, w, alpha) = map(int, input().split())
if h > w:
	(h, w) = (w, h)
if alpha > 90:
	alpha = 180 - alpha
ang = math.radians(alpha)
b = 2 * math.atan(h / w)
if alpha == 0:
	print(h * w)
elif alpha == 90:
	print(h * h)
elif ang > b:
	side = h / math.sin(ang)
	print(side * h)
else:
	left_top = (w / 2, h / 2)
	rot_left_top = rot_by_a(left_top, ang)
	tri_h = rot_left_top[1] - left_top[1]
	tri_base = tri_h / math.tan(ang) + tri_h / math.tan(math.pi / 2 - ang)
	longer_cathetus = tri_base * math.cos(ang)
	smaller_tri_smaller_cathetus = w - tri_base - longer_cathetus
	smaller_tri_longer_cathetus = smaller_tri_smaller_cathetus / math.tan(ang)
	print(w * h - tri_base * tri_h - smaller_tri_smaller_cathetus * smaller_tri_longer_cathetus)