Problem:
 Score: 300 points    Problem Statement  Consider an analog clock whose hour and minute hands are A and B centimeters long, respectively.  An endpoint of the hour hand and an endpoint of the minute hand are fixed at the same point, around which each hand rotates clockwise at constant angular velocity. It takes the hour and minute hands 12 hours and 1 hour to make one full rotation, respectively.  At 0 o'clock, the two hands overlap each other. H hours and M minutes later, what is the distance in centimeters between the unfixed endpoints of the hands?      Constraints   All values in input are integers.  1 \leq A, B \leq 1000  0 \leq H \leq 11  0 \leq M \leq 59         Input  Input is given from Standard Input in the following format:  A  B  H  M       Output  Print the answer without units. Your output will be accepted when its absolute or relative error from the correct value is at most 10^{-9} .        Sample Input 1 3 4 9 0      Sample Output 1 5.00000000000000000000  The two hands will be in the positions shown in the figure below, so the answer is 5 centimeters.        Sample Input 2 3 4 10 40      Sample Output 2 4.56425719433005567605  The two hands will be in the positions shown in the figure below. Note that each hand always rotates at constant angular velocity.

Solution (Python):
import sys
import math
stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  


A, B, H, M = na()

anglea = H * 30 + M * 0.5
angleb = M * 6

angle = abs(anglea - angleb)
if angle > 180:
    angle = 360 - angle

C2 = A * A + B * B - 2 * A * B * math.cos(math.radians(angle))

print(math.sqrt(C2))

Solution (Python):
from decimal import Decimal as dec
import math

def main():
    a, b, h, m = map(int, input().split())
    mr = 6*m
    hr = 30*h+dec(mr/12)
    x = dec((a**2 + b**2 - 2*a*b*math.cos(math.radians(abs(dec(hr-mr)))))**0.5)
    print(x)
    
    

if __name__ == "__main__":
    main()

Solution (Python):
import math
a,b,h,m = map(int, open(0).read().split())
rm = m / 60 * 360
rh = h / 12 * 360 + (30 / 60 * m)
r = min(rh-rm, 360-(rh-rm))
y = r * (math.pi / 180)
c = a**2 + b**2 - (2 * a * b * math.cos(y))
ans = math.sqrt(c)
print(ans)

Solution (Python):
import math
A, B, H, M = map(int, input().split())

ra = H*30 + 0.5*M
rb = M*6
rc = abs(ra-rb)
if rc > 180:
    rc = 360 - rc
c2 = A**2 + B**2 - 2*A*B* math.cos(math.radians(rc))
print(c2**(0.5))

Solution (Python):
import math

A,B,H,M=map(int,input().split())
H_deg=360/12*H+360/12/60*M
M_deg=360/60*M
if M_deg==0:
  M_deg=360
rsq=(A*A+B*B)-(2*A*B)*math.cos(math.radians(abs(H_deg-M_deg)))
print('{:.20f}'.format(math.sqrt(rsq)))

Solution (Python):
import math

a, b, h, m = map(int, input().split())

th1 = 2 * math.pi * (h / 12 + m / 720)
th2 = 2 * math.pi * m / 60
th = abs(th1 - th2)
ans = math.sqrt(a * a + b * b - 2 * a * b * math.cos(th))
print(ans)

Solution (Python):
import math
A,B,H,M=map(int, input().split())
a=math.pi
b=math.cos(a*((60*H-11*M)/360))
Z=A**2+B**2-2*A*B*b
print(Z**(1/2))

Solution (Python):
import math

a, b, h, m = map(int, input().split())
h_posi = 30*h + 0.5*m
m_posi = 6*m

kakudo = abs(h_posi - m_posi)
kakudo = min(kakudo, 360-kakudo)
cos = round(math.cos(math.radians(kakudo)), 18)

print((a**2 + b**2 - 2*a*b*cos)**0.5)

Solution (Python):
import sys
import math


def int1(x): return int(x) - 1
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def mi1(): return map(int1, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def lli(rows_number): return [li() for _ in range(rows_number)]


if __name__ == "__main__":
    a, b, h, m = mi()
    hsita = 360*(h+m/60)/12
    msita = 360*m/60
    if abs(hsita-msita) >= 180:
        sita = math.radians(360-abs(hsita-msita))
    else:
        sita = math.radians(abs(hsita-msita))
    ans = math.sqrt(a**2 + b**2 - 2*a*b*(math.cos(sita)))
    print(ans)

Solution (Python):
import math
 
A, B, H, M = map(int, input().split())
 
th_h = 360 // 12 * H + 360 / 12 / 60 * M
th_m = 360 // 60 * M
 
ans = A ** 2 + B ** 2 - 2*A*B*math.cos(math.radians(abs(th_h - th_m)))
print(math.sqrt(ans))

Solution (Python):
import math

A, B, H, M = map(int, input().split())

th_h = 360 // 12 * H + 360 / 12 / 60 * M
th_m = 360 // 60 * M

ans = A ** 2 + B ** 2 - 2*A*B*math.cos(math.radians(abs(th_h - th_m)))
print(math.sqrt(ans))

Solution (Python):
import math
import numpy as np
a, b, h, m = map(int, input().split())
h1 = 30 * h + m / 2
m1 = 6 * m
theta = abs(h1 - m1)
if theta > 180:
  theta = 360 - theta

theta = theta * (np.pi / 180)
c = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * np.cos(theta))
print(c)

Solution (Python):
import math
A,B,H,M=map(int,input().split())

pi=math.pi
ta=(H/12+M/720)*2*pi
tb=M/60*2*pi
if ta>=tb:
    t=ta-tb
else:
    t=tb-ta
if t>pi:
    t=2*pi-t

if t==0:
    print(abs(A-B))
elif t==pi:
    print(A+B)
else:
    ret=A**2+B**2-2*A*B*math.cos(t)
    ret=math.sqrt(ret)
    print(ret)

Solution (Python):
a,b,h,m= map(int,input().split())
import math

th_h = (h+m/60)/12 *2*math.pi
th_m = m/60 *2*math.pi
c2 = a**2+b**2-2*a*b*math.cos(abs(th_h-th_m) )

print(math.sqrt(c2))

Solution (Python):
import math



a, b, h, m = map(int, input().split())


b_degree = 6 * m




a_degree = 30 * h + m / 60 * 30




if a_degree > b_degree:
    degree1 = a_degree - b_degree
    degree2 = 360 - degree1
    degree = min(degree1, degree2)
    length = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(degree)))
elif a_degree < b_degree:
    degree = b_degree - a_degree
    length = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(degree))) 
else:
    length = abs(b - a)

print(length)

Solution (Python):
import math

A, B, H, M = map(int, input().split())

diff = abs(30 * H + 0.5 * M - 6 * M)
rad = math.radians(diff)
ans = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(rad))

print(ans)

Solution (Python):
import math

A, B, H, M = map(int, input().split())

arg = abs(30*H - 5.5*M)
if arg > 180:
  arg = 360 - arg

arg = math.radians(arg) 

print((A**2 + B**2 -2*A*B*math.cos(arg))**0.5)

Solution (Python):
import math
A,B,H,M = map(int,input().split(' '))

ans = (A**2 + B**2 - 2*A*B*math.cos(math.radians(abs((H+M/60)*30-M*6))))**(1/2)

print(ans)

Solution (Python):
import math
A, B, H, M = map(int, input().split())
theta = abs((M/60)*math.pi*2-((H/12+M/720)*math.pi*2))
ans=A*A+B*B-(2*A*B*math.cos(theta))
ans=math.sqrt(ans)
print(ans)

Solution (Python):
A,B,h,M = list(map(int,input().split()))

import math
H = h + M/60 
cos = math.cos(math.radians(6*abs(5*H-M)))
print(math.sqrt(A ** 2 + B ** 2 - 2*A*B*cos))

Solution (Python):
import sys
from math import cos, sqrt, pi

read = sys.stdin.read
readline = sys.stdin.readline

A, B, H, M = map(int, read().split())
deg = abs(360 / 60 * M - 360 / 12 / 60 * (M + 60 * H))
answer = sqrt(A ** 2 + B ** 2 - 2 * A * B * cos(deg / 180 * pi))
print(answer)

Solution (Python):
from math import cos
from math import radians as rad
from math import degrees as dig
from math import sqrt as r

A, B, H, M = map(int, input().split())

H_ = H * 30 + (M / 60 * 30)
M_ = M * 6

if abs(H_ - M_) < 180:
    HM_rad = rad(abs(H_ - M_))
else:
    HM_rad = rad(360 - abs(H_ - M_))



ans = r(A ** 2 + B ** 2 - 2 * A * B * cos(HM_rad))
print(ans)

Solution (Python):
from math import radians, cos, sqrt
A, B, H, M = map(int, input().split())

angle_hour = 360 * ((60 * H + M) / (60 * 12))
angle_minute = 360 * (M / 60)

angle_between = abs(angle_hour - angle_minute)
angle_between = min(angle_between, 360 - angle_between)
angle_between = radians(angle_between)

ans = A ** 2 + B ** 2 - 2 * A * B * cos(angle_between)
print(sqrt(ans))

Solution (Python):
import numpy as np

a, b, h, m = map(int, input().split())
theta1 = np.pi * (30 * h + m / 2) / 180
theta2 = np.pi * m / 30
x1 = a * np.sin(theta1)
x2 = b * np.sin(theta2)
y1 = a * np.cos(theta1)
y2 = b * np.cos(theta2)
ans = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** (0.5)
print(ans)

Solution (Python):
import sys
import itertools

import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, h, m = map(int, input().split())

degreeA = h * 30 + m/2
degreeB = m * 6
degree = abs(degreeA - degreeB) % 360

radian = (degree * (math.pi / 180))
ans = a ** 2 + b ** 2 - 2 * a * b * math.cos(radian)
print(math.sqrt(ans))

Solution (Python):
import math
a,b,h,m = map(int, input().split())

h_angle = 30*h + 0.5*m
m_angle = 6*m
diff_angle = abs(h_angle - m_angle)

if diff_angle > 180:
    diff_angle = 360 - diff_angle

cosC = math.cos(math.radians(diff_angle))
x = a**2 + b**2 - 2*a*b*cosC
ans = math.sqrt(x)
print(ans)

Solution (Python):


import copy
import random
import bisect 
import fractions 
import math
import sys
import collections
from decimal import Decimal 
mod = 10**9+7
sys.setrecursionlimit(mod) 

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

A, B, H, M = LI()

pi = math.pi
h_p = [A * math.cos(2 * pi * (H * 60 + M) / 720), A * math.sin(2 * pi * (H * 60 + M) / 720)]
m_p = [B * math.cos(2 * pi * M / 60), B * math.sin(2 * pi * M / 60)]


length = ((h_p[0] - m_p[0])**2 + (h_p[1] - m_p[1])**2)**0.5
print(length)

Solution (Python):
import math
A,B,H,M=[int(i) for i in input().split()]
thetaH=2.0*math.pi*(H+M/60)/12
thetaM=2.0*math.pi*M/60

L2=(A*math.cos(thetaH)-B*math.cos(thetaM))**2+(A*math.sin(thetaH)-B*math.sin(thetaM))**2
L=math.sqrt(L2)

print(L)

Solution (Python):
import math
import sys

A, B, H, M = map(int, input().split(' '))

if H == 0 and M == 0:
    print(max(A, B) - min(A, B))
    sys.exit()


H_deg = 30
M_deg = 360


M_rad = math.radians(M_deg * M / 60)


H_rad = math.radians(H_deg * (H + M / 60))


if M_rad < H_rad:
    rad = (H_rad - M_rad)
else:
    rad = (M_rad - H_rad)

if rad >= math.pi:
    rad = math.radians(360) - rad

if rad == 0:
    print(A + B)
else:
    
    C_2 = A**2 + B**2 - 2 * A * B * math.cos(rad)
    print(math.sqrt(C_2))

Solution (Python):
import math
a, b, h, m = map(int, input().split())
kakudo = abs(h*30+1/2*m-m*6)
print(math.sqrt((a**2+b**2-2*a*b*math.cos(math.radians(kakudo)))))

Solution (Python):
import math 
a, b, h, m = map(int,input().split())


h_degree = h * 30 + 30 * m / 60
m_degree = m * 6

degree = abs(h_degree - m_degree)
cosc = math.cos(math.radians(degree))

c = a**2 + b**2 - 2*a*b*cosc

print(c**0.5)

Solution (Python):
A,B,H,M = list(map(int,input().split()))

import math

l = H*360/12 + M*30/60
s = M*360/60
ang = abs(l-s)
c = A**2 + B**2 -2*B*A*math.cos(math.radians(ang))
print(math.sqrt(c))

Solution (Python):
import math
a,b,h,m = map(int,input().split())
m_rad = (m * math.pi) / 30
h_rad = ((60*h+m)*math.pi)/360
rad = abs(h_rad -m_rad)
ans = math.sqrt(a**2+b**2-2*a*b*math.cos(rad))
print(ans)

Solution (Python):
import math
a,b,h,m = map(int,input().split())
k = 30*(h+m/60) - 6*m
c =(a**2 + b**2 -2*a*b* math.cos(math.radians(k)))**(1/2)
print(c)

Solution (Python):
import math

a,b,h,m=map(int,input().split())
h=math.radians((h+m/60)*360/12)
m=math.radians(m*360/60)

print((a**2+b**2-2*a*b*math.cos(h-m))**0.5)

Solution (Python):
a, b, h, m = map(int, input().split())

rad = abs((30*h+0.5*m)-6*m)
if rad > 180:
	rad = 360 - rad

import math

c = a*a + b*b -2*a*b*math.cos(math.radians(rad))

print(math.sqrt(c))

Solution (Python):
import math

a, b, h, m = map(int, input().split())

c1 = 6 * m
c2 = 30 * h + m / 2

c0 = abs(c1-c2)
c0 = min(c0, 360-c0)

ans = (a*a + b*b - 2*math.cos(math.radians(c0))*a*b) ** 0.5

print(ans)

Solution (Python):
import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    a,b,h,m = I2()
    x = m/60
    y = h/12 + m/60/12
    
    rad = math.pi*(y-x)*2
    ans = a**2+b**2-2*a*b*math.cos(rad)
    print(math.sqrt(ans))

Solution (Python):
from math import pi, cos, sin, sqrt

A, B, H, M = map(int, input().split())

A_th = ((H / 12) + (M / 60) / 12) * 2 * pi
B_th = (M / 60) * 2 * pi
A_x, A_y = A * cos(A_th), A * sin(A_th)
B_x, B_y = B * cos(B_th), B * sin(B_th)

print(sqrt(((A_x - B_x) ** 2 + (A_y - B_y) ** 2)))

Solution (Python):
import math

def main():
    A, B, H, M = map(int, input().split())

    sita = M*6
    fai = 0.5*(60*H + M)

    arufa = abs(sita - fai)
    if arufa > 180:
        arufa = 360 - arufa

    
    arufa = math.radians(arufa)
    
    
    

    ans = float(A**2 + B**2) - 2*A*B*(math.cos(arufa))
    
    ans = math.sqrt(ans)

    return ans

print(main())

Solution (Python):
a = input().split()
A = int(a[0])
B = int(a[1])
H = int(a[2])
M = int(a[3])
import math
aa = 30 * H + 0.5 * M
bb = M * 6
z = aa - bb
ans = (A**2 + B**2 - 2*A*B*math.cos(math.radians(z)))**(1/2)

print(ans)

Solution (Python):
import math

a,b,h,m=map(int,input().split())
ang=abs(0.5*(60*h+m)-6*m)
print(math.sqrt(a**2+b**2-2*a*b*math.cos(math.pi*ang/180)))

Solution (Python):
import math
A,B,H,M = map(int, input().split())
elapsed = H*60+M
ma = (elapsed%60)*6
ha = elapsed*0.5
theta = abs(ha-ma)
dist = math.sqrt(A*A+B*B-2*A*B*math.cos(theta*(math.pi)/180))
print(dist)

Solution (Python):
import math

A, B, H, M = (int(i) for i in input().split())

rad = math.pi * 2 * (H / 12 + (M / 60) / 12 - M / 60)

rsq = A**2 + B**2 - 2 * A * B * math.cos(rad)

print(math.sqrt(rsq))

Solution (Python):
import math
A, B, H, M = map(int, input().split())
sh = math.pi * (H + M / 60) / 6
sm = math.pi * M / 30
s = abs(sh - sm)
C = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(s))
print(C)

Solution (Python):
import math
A, B, H, M = map(int, input().split())
sh = math.pi * (H + M / 60) / 6
sm = math.pi * M / 30
s = abs(sh - sm)
C = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(s))
print(C)

Solution (Python):
import math
a, b, h, m = map(int, input().split())
angle_a = ((60 * h + m)/360)* math.pi
angle_b = (m / 30) * math.pi
l = a**2 + b**2 - 2*a*b*math.cos(angle_a-angle_b)
ans = l**0.5
print(ans)

Solution (Python):
import math
a, b, h, m = map(int, input().split())

theta_m = 2*math.pi*m/60.0
theta_h = 2*math.pi * (h+m/60.0)/12.0
ans = (a**2+b**2-2*a*b*math.cos(theta_h-theta_m))**(1/2.0)
print(ans)

Solution (Python):
import math
def main():
    a,b,h,m = map(int,input().split())
    angle = 180 - abs(180 - abs(m * 6 - (h * 30 + m * 0.5)))
    ans = math.sqrt((a*a + b*b) - (2 * a * b)*math.cos(math.radians(angle)))
    print(round(ans,9))






main()

Solution (Python):
import math
from decimal import Decimal
pi = Decimal("3.141592653589793238462643383279502884")
A, B, H, M =  map(int, input().split())
time = H * 60 + M
H_rad = (2* pi / (60*12)) * time 
M_rad = (2* pi / 60) * time
rad = abs(H_rad-M_rad) % (2 * pi)
C = math.sqrt(A**2 + B**2 - 2 * A * B * math.cos(rad))
print(f'{C:.10f}')

Solution (Python):
import math

A, B, H, M = map(int, input().split())

x = abs(6 * M - (30 * H + 0.5 * M))
if x > 180:
    x = 360 - x

c = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(x)))

print(c)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
h_ang=30*(h+m/60)
m_ang=360*(h+m/60)
ang=(h_ang-m_ang)%360
ang=(ang/180)*math.pi
l=(a**2+b**2-2*b*a*math.cos(ang))**0.5
print(l)

Solution (Python):
import math

a, b, h, m = map(int, input().split())


angle_a = (30*h+m/2) * math.pi /180

angle_b = m/30 * math.pi

coordinate_a = [a * math.cos(angle_a), a * math.sin(angle_a)]
coordinate_b = [b * math.cos(angle_b), b * math.sin(angle_b)]

diff_a_b = [abs(coordinate_a[0]-coordinate_b[0]),
            abs(coordinate_a[1]-coordinate_b[1])]

square = [diff_a_b[0]**2,diff_a_b[1]**2]
print(math.sqrt(abs(square[0]+square[1])))

Solution (Python):
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'

    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(n,base=2):
    rt=[]
    for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
 
YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase

input=lambda: sys.stdin.readline().rstrip()
 
class Tree:
    def __init__(self,inp_size=None,ls=None,init=True,index=0):
        self.LCA_init_stat=False
        self.ETtable=[]
        if init:
            if ls==None:
                self.stdin(inp_size,index=index)
            else:
                self.size=len(ls)+1
                self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def stdin(self,inp_size=None,index=1):
        if inp_size==None:
            self.size=int(input())
        else:
            self.size=inp_size
        self.edges,_=GI(self.size,self.size-1,index=index)
        return
    
    def listin(self,ls,index=0):
        self.size=len(ls)+1
        self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def __str__(self):
        return  str(self.edges)
 
    def dfs(self,x,func=lambda prv,nx,dist:prv+dist,root_v=0):
        q=deque()
        q.append(x)
        v=[-1]*self.size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==-1:
                    q.append(nb)
                    v[nb]=func(v[c],nb,d)
        return v
 
    def EulerTour(self,x):
        q=deque()
        q.append(x)
        self.depth=[None]*self.size
        self.depth[x]=0
        self.ETtable=[]
        self.ETdepth=[]
        self.ETin=[-1]*self.size
        self.ETout=[-1]*self.size
        cnt=0
        while q:
            c=q.pop()
            if c<0:
                ce=~c
            else:
                ce=c
                for nb,d in self.edges[ce]:
                    if self.depth[nb]==None:
                        q.append(~ce)
                        q.append(nb)
                        self.depth[nb]=self.depth[ce]+1
            self.ETtable.append(ce)
            self.ETdepth.append(self.depth[ce])
            if self.ETin[ce]==-1:
                self.ETin[ce]=cnt
            else:
                self.ETout[ce]=cnt
            cnt+=1
        return
    
    def LCA_init(self,root):
        self.EulerTour(root)
        self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf)
        self.LCA_init_stat=True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.LCA_init(root)
        xin,xout=self.ETin[x],self.ETout[x]
        yin,yout=self.ETin[y],self.ETout[y]
        a=min(xin,yin)
        b=max(xout,yout,xin,yin)
        id_of_min_dep_in_et=self.st.query_id(a,b+1)
        return self.ETtable[id_of_min_dep_in_et]
 
class SparseTable: 
    def __init__(self,ls,init_func=min,init_idl=float('inf')):
        self.func=init_func
        self.idl=init_idl
        self.size=len(ls)
        self.N0=self.size.bit_length()
        self.table=[ls[:]]
        self.index=[list(range(self.size))]
        self.lg=[0]*(self.size+1)
        
        for i in range(2,self.size+1):
            self.lg[i]=self.lg[i>>1]+1
 
        for i in range(self.N0):
            tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)]
            tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)]
            self.table+=[tmp]
            self.index+=[tmp_id]
    
    
    def query(self,l,r):
        if r>self.size:r=self.size
        
        N=self.lg[r-l]
        return self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))])
    
    
    def query_id(self,l,r):
        if r>self.size:r=self.size
        
        N=self.lg[r-l]
        a,b=self.index[N][l],self.index[N][max(0,r-(1<<N))]
        if self.table[0][a]==self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))]):
            b=a
        return b
    
    def __str__(self):
        return str(self.table[0])
 
    def print(self):
        for i in self.table:
            print(*i)
 
class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]
 
    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo
 
show_flg=False
show_flg=True
ans=0

a,b,h,m=LI()
P=math.pi*2
t1=(h/12+m/60/12)*P
x,y=a*math.cos(t1),a*math.sin(t1)


t2=(m/60)*P
u,v=b*math.cos(t2),b*math.sin(t2)

ans=((x-u)**2+(y-v)**2)**0.5

print(ans)

Solution (Python):
import math
a,b,h,m = map(int, input().split())
rad = math.pi *2* (-h/12 - (m/60)/12 + m/60)
rs = float(a*a + b*b) - float(2*a*b) * math.cos(rad)
print(math.sqrt(rs))

Solution (Python):
import math


A, B, H, M = map(int, input().split())

Tp = (H * 60 + M) / (12 * 60) * (2 * math.pi)
Tq = M / 60 * (2 * math.pi)
Px = A * math.sin(Tp)
Py = A * math.cos(Tp)
Qx = B * math.sin(Tq)
Qy = B * math.cos(Tq)

print(math.sqrt((Px - Qx) ** 2 + (Py - Qy) ** 2))

Solution (Python):

import math

A ,B ,H ,M = map(int,input().split())
x = A*math.sin(math.radians(30*(H+M/60)))-B*math.sin(math.radians(6*M))
y = A*math.cos(math.radians(30*(H+M/60)))-B*math.cos(math.radians(6*M))
print((x**2+y**2)**(0.5))

Solution (Python):
import math

a, b, h, m = list(map(int, input().split()))

h += m / 60

print(math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(11 / 6 * math.pi * h)))

Solution (Python):
import math

a, b, h, m = list(map(int, input().split()))

h += m / 60

rh = 2 * math.pi * h
rm = 1 / 6 * math.pi * h

print(math.sqrt((a * math.cos(rh) - b * math.cos(rm))
                ** 2 + (a * math.sin(rh) - b * math.sin(rm))**2))

Solution (Python):
import math
a,b,h,m = map(int, input().split())
rad = math.pi * 2 * (h/12 + (m/60)/12 - m/60)
rs = float(a*a + b*b) - float(2*a*b) * math.cos(rad)
print(math.sqrt(rs))

Solution (Python):
def resolve():
	import math
	A, B, H, M = map(int, input().split())
	l = (360/60)*M 
	s = (360/12)*H + (360/12/60)*M 
	theta = max(l, s) - min(l, s)
	theta = min(theta, 360-theta)
	ans = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(theta)))
	print(ans)
resolve()

Solution (Python):


import numpy as np

def main():
    a, b, h, m = map(int, input().split())

    tyo = m * 6
    tan = h * 30 + m * 0.5
    deg = abs(tyo-tan)
    
    c = np.sqrt(a**2+b**2-2*a*b*np.cos(np.deg2rad(deg)))
    print(c)

if __name__ == '__main__':
    main()

Solution (Python):
from math import cos, sqrt, pi
a, b, h, m = map(int, input().split())

ang_a = pi * h / 6 + pi * m / 360

ang_b = pi * m / 30

ang = abs(ang_a-ang_b)

c = sqrt(a**2 + b**2 - 2*a*b*cos(ang))
print(c)

Solution (Python):
from math import cos, pi, sqrt
A, B, H, M = map(int, input().split())

theta_h = H / 12 * 2*pi + (2*pi) / 12 * (M / 60)
theta_m = M / 60 * 2*pi
theta = abs(theta_h - theta_m)
print(sqrt(A**2 + B**2 - 2*A*B*cos(theta)))

Solution (Python):
import math
A, B, H, M = map(int, input().split())

a = (60 * H + M) / 2
b = 6 * M
r = min(abs(a-b), 360-abs(a-b))

c = math.sqrt(A**2+B**2 - 2*A*B*math.cos(math.radians(r)))

print(c)

Solution (Python):
def resolve():
    import math
    A, B, H, M = map(int, input().split())
    sita = abs(H*30+M*0.5-M*6)
    if sita > 180:
        sita = 360 - sita
    print(math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(sita))))
resolve()

Solution (Python):

import math
A,B,H,M = map(int,input().split())
theta = math.radians(30*H+0.5*M-6*M)
ans = (A**2+B**2-2*A*B*math.cos(theta))**0.5
print(ans)

Solution (Python):
import math

A,B,H,M = map(int,input().split())

co_hour = [math.cos(((H*60 + M)/360 - 1/2) * math.pi) * A , math.sin(((H*60 + M)/360 - 1/2) * math.pi) * A]
co_min = [math.cos(((M/30 - 1/2) * math.pi)) * B, math.sin(((M/30 - 1/2) * math.pi)) * B]

x = co_hour[0] - co_min[0]
y = co_hour[1] - co_min[1]

Answer = math.sqrt(x * x + y * y)

print(Answer)

Solution (Python):
import math

def colon():
    input_value = [int(i) for i in input().split()]
    hour_hand = input_value[0]
    minute_hand = input_value[1]

    hour = input_value[2]
    minute = input_value[3]

    degree = (((hour * 60 + minute) * 360)/720) - ((minute * 360)/60)
    cos = math.cos(math.radians(degree))

    answer = math.sqrt((hour_hand ** 2) + (minute_hand ** 2) - (2 * hour_hand * minute_hand * cos))
    print(answer)

colon()

Solution (Python):
from math import pi, cos, sqrt
from sys import stdin

a,b,h,m = map(int,stdin.readline().rstrip().split())

l = 2*pi*m/60
s = 2*pi*(h+m/60)/12
theta = s-l
ans = sqrt(a**2+b**2-2*a*b*cos(theta))
print(ans)

Solution (Python):

import sys
import math


def solve(A: int, B: int, H: int, M: int):
    ax = A * math.cos((H+M/60) * 2 * math.pi / 12)
    ay = A * math.sin((H+M/60) * 2 * math.pi / 12)
    bx = B * math.cos(M * 2 * math.pi / 60)
    by = B * math.sin(M * 2 * math.pi / 60)

    return math.sqrt((ax - bx)**2 + (ay - by)**2)



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    H = int(next(tokens))  
    M = int(next(tokens))  
    print(solve(A, B, H, M))


if __name__ == '__main__':
    main()

Solution (Python):
import math
a,b,h,m = map(int,input().split())
k = h*30+m/12*6-m*6
print(math.sqrt(a*a+b*b-2*a*b*math.cos(math.pi/180*k)))

Solution (Python):
import math
A,B,H,M=map(int,input().split())
Atheta=2*math.pi*(60*H+M)/720
Btheta=2*math.pi*M/60
theta=Atheta-Btheta
ans=math.sqrt(A**2+B**2-2*A*B*math.cos(theta))
print(ans)

Solution (Python):
import math
a,b,h,m = map(int,input().split())
print(math.sqrt(a**2+b**2-2*a*b*math.cos(math.pi*((h+m/60)/6-m/30))))

Solution (Python):
import math
from decimal import Decimal
a, b, H, M = map(Decimal, input().split())

H = (H/Decimal(12) + M/Decimal(720))*Decimal(math.pi)*Decimal(2)
M = (M/Decimal(60))*Decimal(math.pi)*Decimal(2)
c = a**Decimal(2)+b**Decimal(2)-a*b*Decimal(2)*Decimal(math.cos(H-M))
print(math.sqrt(c))

Solution (Python):
import math


a, b, h, m = map(int, input().split())

pi = math.pi

theta1 = -2*(h/12+m/60/12)*pi + pi/2
theta2 = -2*m/60*pi + pi/2

x1 = a * math.cos(theta1)
y1 = a * math.sin(theta1)

x2 = b * math.cos(theta2)
y2 = b * math.sin(theta2)

d = ((x1-x2)**2 + (y1-y2)**2)**0.5

print(d)

Solution (Python):
import math
a, b, h, m = map(int, input().split())
c = (h + m / 60) * math.pi / 6 - m * math.pi / 30
print(math.sqrt(a **2 + b **2 - 2 * a * b * math.cos(c)))

Solution (Python):
import math

a, b, h, m = map(int, input().split())


hour_hand = h * 30 + m / 2

minute_hand = m * 6
deg = minute_hand - hour_hand
rad = math.radians(deg)

c2 = a ** 2 + b ** 2 - 2 * a * b * math.cos(rad)
print(math.sqrt(c2))

Solution (Python):
import math
A = list(map(int,input().split()))
C2 = A[0]**2+A[1]**2-2*A[0]*A[1]*math.cos(math.pi*2*abs(A[2]/12+A[3]/60/12-A[3]/60))
print('{:.20f}'.format(math.sqrt(C2)))

Solution (Python):
import numpy as np
import sys



def xnxn(n=0, flag="v"):
    """
    args:
        int n: a number of lows to read
    example:
        input   1
        retrun  1

        input   1 2 3
        return  [1,2,3]
        input   1 2 3
                4
        return  [[1,2,3],
                [4]]
    """
    if n == 0:
        temp = list(map(int, input().split()))
        if len(temp) == 1:
            if flag == "l":
                return temp
            else:
                return temp[0]
        elif len(temp) > 1:
            return temp
    else:
        temp = [list(map(int, input().split())) for _ in range(n)]
        return temp


def sp_xnxn(n=0):
    """
    args:
        int n: a number of lows to read
    example
        input   1
        retrun  [1]

        input   123
        return  [1,2,3]

        input   123
                4
        return  [[1,2,3],
                [4]]
    """
    if n == 0:
        return [int(k) for k in xsxs()]
    else:
        return [[int(k) for k in xsxs()] for _ in range(n)]


def xsxs(n=0):
    """
    args:
        int n: a number of lows to read
    example:
        input   AA
        retrun  AA

        input   A BBB CC
        return  ["A","BBB","CC"]

        input   A BB CCC
                D
        return  [["A","BBB","CC"],
                ["D"]]
    """
    if n == 0:
        temp = list(input().split())
        if len(temp) == 1:
            return temp[0]
        elif len(temp) > 1:
            return temp
    else:
        return [list(input().split()) for _ in range(n)]


def sp_xsxs(n=0):
    """
    args:
        int n: a number of lows to read
        example:
            input   A
            retrun  ["A"]

            input   ABC
            return  ["A","B","C"]

            input   ABC
                    D
            return  [["A","B","C"],
                    ["D"]]
    """
    if n == 0:
        return [s for s in xsxs()]
    else:
        return [[s for s in xsxs()] for _ in range(n)]


a, b, h, m = xnxn()

ans = np.sqrt(a ** 2 + b ** 2 - 2 * a * b *
              np.cos(2 * np.pi * (1 / 60 * m - 1 / (12*60) * (60*h+m))))

print(ans)

Solution (Python):
import math
A,B,H,M=map(int,input().split())
a=A**2
b=B**2
c=A*B*2
h=math.pi*2*(H/12+M/720-M/60)
z=a+b-c*math.cos(h)
print(math.sqrt(z))