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 math

a,b,h,m = list(map(int,input().split()))
h = h % 12
theta = m*5.5 - h*30
arc = a** 2 + b**2 - 2*a*b*math.cos(math.radians(theta))
print(arc**0.5)

Solution (Python):
import math

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

x_1 = a * math.cos(-h * math.pi / 6 - m * math.pi / 360)
y_1 = a * math.sin(-h * math.pi / 6 - m * math.pi / 360)

x_2 = b * math.cos(-m * math.pi / 30)
y_2 = b * math.sin(-m * math.pi / 30)

print(((x_2 - x_1) ** 2 + (y_2 - y_1) ** 2) ** 0.5)

Solution (Python):
import numpy as np

A, B, H, M = input().split(" ")

A = int(A)
B = int(B)
H = int(H)
M = int(M)

minute = 60*H + M
theta_A = 2*np.pi * (minute/720)
theta_B = 2*np.pi * (M/60)

jisin = np.array([A*np.sin(theta_A), A*np.cos(theta_A)])
hunsin = np.array([B*np.sin(theta_B), B*np.cos(theta_B)])

kyori = np.sqrt(np.sum((jisin-hunsin)**2))

print(kyori)

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

Solution (Python):
from math import cos, sin,pi, sqrt
A,B, H, M = [float(_n) for _n in input().split()]

n = pi * (60*H+M)/360
ax = A * cos(n)
ay = A * sin(n)
bx = B * cos(pi*M/30.)
by = B * sin(pi*M/30.)
print(sqrt((bx-ax)**2.0+(by-ay)**2.0))

Solution (Python):
import math

A,B,H,M = map(int,input().split())
theta = (H/6 - 11*M/360)*math.pi
print(math.sqrt(A**2 + B**2 - 2*A*B*math.cos(theta)))

Solution (Python):
import math

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

kakudo = 360-abs((60*H+M)*0.5-M*6)
k = math.radians(kakudo)
if(kakudo != 180):
    ans = A**2+B**2-2*A*B*math.cos(k)
    print(ans**0.5)
else:
    print(A+B)

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


Ax = A * math.sin(M * math.pi / 30)
Ay = A * math.cos(M * math.pi / 30)


Bx = B * math.sin(H * math.pi / 6 + M * math.pi / 360)
By = B * math.cos(H * math.pi / 6 + M * math.pi / 360)



ans = math.sqrt((Ax - Bx)**2 + (Ay - By)**2)
print(ans)

Solution (Python):
import math
a, b, h , m = map(int,input().split())
x = abs(30*h + 0.5*m-6*m) 
x = min(x, 360-x)

cos = math.cos(math.radians(x)) 

ans = (a**2+b**2 -2*a*b*cos)**(1/2)
print(ans)

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

h = H + M / 60

t = 360 * h / 12
c = M * 6

k = abs(t - c)

ans2 = A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(k))
ans = math.sqrt(ans2)

print(ans)

Solution (Python):
def resolve():
    import math
    a,b,h,m=map(int,input().split())
    A=30*(h+m/60)
    B=m*6
    dif=abs(A-B)
    if dif>=180:
        dif=360-dif
    print((((b-a*math.cos(math.radians(dif))))**2+(a*math.sin(math.radians(dif)))**2)**(1/2))

if __name__ == '__main__':
    resolve()

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

a, b, h, m = map(int, input().split())
r_a = m/60
r_b = (h+m/60)/12
if r_a > r_b:
    r = (r_a - r_b) * 2 * pi
else:
    r = (r_b - r_a) * 2 * pi

c = sqrt(pow(a, 2) + pow(b, 2) -(2*a*b*cos(r)))
print(c)

Solution (Python):
import math
A,B,H,M = map(int,input().split())
short = math.radians(M*6)
long = math.radians((H*60+M)/2)
ans = (A**2+B**2-2*A*B*math.cos(long - short))**(1/2)
print(ans)

Solution (Python):
import math
A, B, H, M = map(int, input().split())
p = math.pi
s = 2*p*M/60
t = 2*p*(60*H+M)/720
u = s - t
C = math.sqrt(A**2+B**2-2*A*B*math.cos(u))
print(C)

Solution (Python):
def main():
    import math
    pi=math.pi
    import sys
    A,B,H,M=list(map(int,sys.stdin.readline().split()))

    large_deg=((2*pi/12)*((H+M/60)%12))
    small_deg=((2*pi/60)*(M%60))

    deg=abs(large_deg-small_deg)

    if deg>=pi:
        deg=2*pi-deg
    print(math.sqrt(A**2+B**2-2*A*B*math.cos(deg)))
    

main()

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

min=60*h+m

ax=a*math.sin(math.radians(360*min/720))
ay=a*math.cos(math.radians(360*min/720))

bx=b*math.sin(math.radians(360*m/60))
by=b*math.cos(math.radians(360*m/60))

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

Solution (Python):
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

import math

a,b,h,m = LI()

b_x = b*math.cos(math.radians(6*m))
b_y = b*math.sin(math.radians(6*m))
a_x = a*math.cos(math.radians(30*h + m/2))
a_y = a*math.sin(math.radians(30*h + m/2))

l = math.sqrt(pow(b_x - a_x,2) + pow(b_y - a_y,2))
print(l)

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

Solution (Python):
import math

A, B, H, M = map(int, input().split())
long_angle = M / 60 * 360
if H == 12:
    H = 0
short_angle = H / 12 * 360 + M / 60 * 30
angle = abs(long_angle - short_angle)
cos = math.cos(math.radians(angle))
print((A ** 2 + B ** 2 - 2 * A * B * cos) ** 0.5)

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

import numpy as np
t=60*h+m
w1=2*np.pi/(12*60)
w2=2*np.pi/60

delta=(w1-w2)*t

ans=np.sqrt(a**2+b**2-2*a*b*np.cos(delta))

print(ans)

Solution (Python):
import math

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

jihari = 30 * H + 1 / 2 * M
hunhari = 6 * M 

theta = abs(jihari - hunhari)
thetarad = math.radians(theta)

l = math.sqrt(A**2 + B**2 - 2 * A * B * math.cos(thetarad))

print(l)

Solution (Python):
import math

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

angle_h = 30*h + 0.5*m
angle_m = 6*m

vertex_c = abs(angle_h - angle_m)
if (vertex_c > 180):
    vertex_c = 360 - vertex_c

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

print(c**(1/2))

Solution (Python):
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions
import sys
data = [int(s) for s in stdin.readline().rstrip().split()]
a = data[0]
b = data[1]
h = data[2]
m = data[3]


barc = m * 6.0
aarc = h * 30.0 + m * 0.5
diff = abs(aarc-barc)

if diff >= 180:
    diff = 360-diff

res = (a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(diff)))**(1/2)
print(res)

Solution (Python):
import math
A,B,H,M=list(map(int,input().split()))
move = 60*H+M
a_move = math.radians(move/720*360)
b_move = math.radians(M/60*360)

ax = A*math.cos(a_move)
ay = A*math.sin(a_move)
bx = B*math.cos(b_move)
by = B*math.sin(b_move)

ans = math.sqrt(math.pow(ax-bx,2) + math.pow(ay-by,2))
print(ans)

Solution (Python):
import math
A,B,H,M=input().split()
A=int(A)
B=int(B)
H=int(H)
M=int(M)
pi=math.pi
if (1<=A<=1000)and(1<=B<=1000)and(0<=H<=11)and(0<=M<=59):
    a=(pi/6)*(M/60)+2*pi*(H/12)
    b=(M/60)*2*pi
    c=b-a
    d=(A**2+B**2-2*A*B*math.cos(c))**(1/2)
    print(d)

Solution (Python):
import math
A, B, H, M = map(int, input().split())
AB = min(H*30 - M*(5.5), 360 - (H*30 - M*(5.5)))
print((A**2 + B**2 - 2*A*B*math.cos(math.radians(AB))) **(1/2))

Solution (Python):
import math 

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

m_deg = 360/60*M


h_deg = 360/(12*60)*(H*60+M)


a2 = A**2 + B**2 -2*A*B*math.cos(math.radians(abs(h_deg - m_deg)))
print(math.sqrt(a2))

Solution (Python):
import math
a,b,H,M=map(int,input().split())
theta=abs(30*H+0.5*M-6*M)*math.pi/180
ans=math.sqrt(a**2+b**2-2*a*b*math.cos(theta))
print(ans)

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

Solution (Python):
import math
a,b,H,M = map(int, input().split())
c2 = a**2 + b**2 - 2*a*b*math.cos(2*math.pi*((30*H- (11/2)*M)/360))
print(math.sqrt(c2))

Solution (Python):
import math

(A,B,H,M) = map(int,input().split())
A_deg = 30*H+M*0.5
B_deg = M*6
deg = max(A_deg - B_deg,B_deg -A_deg)
cosdeg = math.cos(math.radians(deg))
ans = math.sqrt(A**2+B**2-2*A*B*cosdeg)
print(ans)

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

theta_M = M*6
theta_H = H*30 + M*0.5

theta = abs(theta_M - theta_H)
if theta > 180:
  theta = 360 - theta
  
import math
x = A**2 + B**2 - 2 * A * B * math.cos(math.radians(theta))
x = math.sqrt(x)
print(x)

Solution (Python):
import math

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


theta1 = 360.0/12.0*H + 360.0/12.0/60.0*M
theta2 = 360.0/60.0*M

theta = abs(theta1-theta2)

c = A**2 + B**2 - 2.0*A*B*math.cos(math.radians(theta))

print(math.sqrt(c))

Solution (Python):
import math
A, B, H ,M = map(int , input().split())
T = 60 * H + M
omega1 = math.pi / 360
omega2 = math.pi / 30
theta = omega1*T - omega2*T
c = math.cos(theta)
l = math.sqrt(A**2 + B**2 - 2*A*B*c)
print(l)

Solution (Python):
import sys
import math  
import bisect  
import queue  


def input():
    return sys.stdin.readline().rstrip()


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

    h = 30 * H + M * 0.5
    m = 6 * M
    theta = max(h, m) - min(h, m)
    theta = min(theta, 360 - theta)

    res2 = A ** 2 + B ** 2 - 2 * A * B * math.cos(theta / 180 * math.pi)
    print(res2 ** 0.5)


if __name__ == '__main__':
    main()

Solution (Python):
import math

A, B, H, M = map(int, input().split())
theta = (2*math.pi / 12) * H + (2*math.pi / (12*60)) * M - (2*math.pi / 60) * M
C = (A**2 + B**2 - 2*A*B*math.cos(theta))**(1/2)
print(C)

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

a,b,h,m=map(int,input().split())
angh=pi*(60*h+m)/360
angm=pi*m/30

hx=a*cos(angh)
hy=a*sin(angh)
mx=b*cos(angm)
my=b*sin(angm)

d=sqrt((hx-mx)**2+(hy-my)**2)
print(d)

Solution (Python):
import math
a, b, h, m = [int(i) for i in input().split()]

theta = abs((30*h + m/2) - 6*m)
print(math.sqrt(a*a + b*b - 2*a*b*math.cos(math.radians(theta))))

Solution (Python):
import math

A,B,H,M = map(int,input().split())
hun = H * 60 + M

long = 6 * M
short = 0.5 * hun

rad = abs(long-short)
if rad > 180:
  rad = 360 - rad

if rad != 90 or 180:
  print(math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(rad))))
elif rad == 90:
   print(math.sqrt(A**2 + B**2))
else:
  print(A+B)

Solution (Python):

import sys
import math


def solve(A: int, B: int, H: int, M: int):
    
    theta = max(0.5 * (60 * H + M), 6 * M) - min(0.5 * (60 * H + M), 6 * M)
    th = min(theta, 360 - theta)
    csth = math.cos(math.radians(th))
    print(math.sqrt(pow(A,2) + pow(B,2) - 2 * A * B * csth))
    return



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))  
    solve(A, B, H, M)

if __name__ == '__main__':
    main()

Solution (Python):

import sys

def f(b, c, th):
    '''
    >>> from math import pi
    >>> f(3, 4, pi / 2)
    5.0
    '''
    from math import cos
    return pow(b ** 2 + c ** 2 - 2 * b * c * cos(th), 0.5)


def solve(A: int, B: int, H: int, M: int):
    from math import pi
    m = M / 60
    h = (60 * H + M) / (12 * 60)
    return f(A, B, abs(h - m) * 2 * pi)



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))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    test()
    main()

Solution (Python):
import math

A,B,H,M=list(map(int,input().split()))
H_rad=(H+M/60)/12*2
M_rad=M/60*2
c=math.sqrt(A**2+B**2-A*B*2*math.cos((H_rad-M_rad)*math.pi))
print(c)

Solution (Python):
import random
import math
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
yes = lambda: print("Yes")
no = lambda: print("No")
I = lambda: list(input())
J = lambda x: "".join(x)
II = lambda: int(input())
SI = lambda: input()

a,b,h,m = MI()
h*=5
h+=m/12
al = abs(h-m)*6
ans = math.sqrt(a**2+b**2-2*a*b*math.cos(al*math.pi/180))
print(ans)

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

sa=(H*30+M*0.5)-M*6

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

print(c)

Solution (Python):
import math

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

if (h * 60 + m) > 0:
    th = 2.0 * math.pi / (12 * 60) * (h * 60 + m)
else:
    th = 0.0
xh = a * math.cos(th)
yh = a * math.sin(th)

if m > 0:
    tm = 2.0 * math.pi / 60 * m
else:
    tm = 0.0
xm = b * math.cos(tm)
ym = b * math.sin(tm)

d = ((xh - xm) ** 2 + (yh - ym) ** 2) ** 0.5
print(d)

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

import math


if h >= 12:
    h -= 12
h_angle = 30*h + 30*(m/60)
m_angle = 6*m

angle = abs(h_angle -m_angle)
if angle > 180:
    angle = 360 -angle
cos = math.cos(math.radians(angle))
ans_sq = a**2 + b**2 - 2*a*b*cos
print(abs(math.sqrt(ans_sq)))

Solution (Python):
import math
a, b, h, m = map(int, input().split())
if abs(6 * m - 0.5 * m - 30 * h) > 180:
    aida_kaku = 360 - abs(6 * m - 0.5 * m- 30 * h)
else:
    aida_kaku = abs(6 * m - 0.5 * m - 30 * h)

aida_rad = math.radians(aida_kaku)
c_2 = a ** 2 + b ** 2 - 2 * a * b * math.cos(aida_rad)
print(math.sqrt(c_2))

Solution (Python):

import sys
input = sys.stdin.readline
import math

a, b, h, m = map(int, input().split())
deg_h = (h * 120 + m * 2) % 1440
deg_m = (m * 24) % 1440
diff = (deg_h - deg_m) % 1440
if deg_h >= deg_m:
    diff = deg_h - deg_m
else:
    diff = deg_m - deg_h
if 1440 - diff < diff:
    diff = 1440 - diff
c_sqr = a*a + b*b - 2.0 * a * b * math.cos(diff / 1440 * math.pi * 2)
print(math.sqrt(c_sqr))

Solution (Python):
a,b,h,m = map(int,input().split())
time = 60*h + m
tansin = 1/2 * time
tyousin = 6 * m

do = min(abs(tansin - tyousin) , 360 - abs(tansin - tyousin))
import math
if do == 180:
  print(a + b)
else:
  c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(do)))
  print(c)

Solution (Python):
import math
A,B,H,M= map(int,input().split())
baseangle = abs(6*M -(60*H+M)/2)
angle = min(baseangle,360-baseangle)

cosine = math.cos(math.radians(angle))

ans = (A**2 + B**2 - 2*A*B*cosine)**0.5

print(ans)

Solution (Python):
import math

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

t=60*H+M

s1=2*math.pi*(t/60)/12
s2=2*math.pi*(t%60)/60

x1=A*math.cos(s1)
y1=A*math.sin(s1)

x2=B*math.cos(s2)
y2=B*math.sin(s2)

ans=math.sqrt((x2-x1)**2+(y2-y1)**2)

print(ans)

Solution (Python):
import math

A, B, H, M = [int(x) for x in input().split()]

total_time_sec = H * 60 * 60 + M * 60

t1 = (2 * math.pi * total_time_sec) / (12 * 60 * 60)
t2 = (2 * math.pi * total_time_sec) / (60 * 60)

dist = math.sqrt(A*A + B*B - 2 * A * B * math.cos(t1 - t2))
print(dist)

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

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

x1, y1 = -sin(-theta1)*a, cos(-theta1)*a
x2, y2 = -sin(-theta2)*b, cos(-theta2)*b
x = x1-x2
y = y1-y2
ans = sqrt(x*x + y*y)
print(ans)

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

def main():
    A, B, H, M = map(int, readline().rstrip().split())
    rad_b = M / 60 * 360
    rad_a = H / 12 * 360 + 30 * (M / 60)
    rad_diff = min(rad_a - rad_b, 360 - (rad_a - rad_b))
    res = A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(rad_diff))
    print(math.sqrt(res))


if __name__ == '__main__':
    main()

Solution (Python):
import math
a,b,h,m = map(int ,input().split())
deg = 2*math.pi*abs((h+m/60)/12-m/60)
if deg > math.pi:
    deg = 2*math.pi-deg
c = abs((a**2+b**2-2*a*b*math.cos(deg))**0.5)
print(c)

Solution (Python):
import math

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

X = A**2 + B**2 - 2*A*B*math.cos(math.radians(5.5*M - 30*H))

print(math.sqrt(X))

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

Solution (Python):
import math

def num():
    return int(input())


def nums():
    return map(int,input().split())

a,b,h,m = nums()
t = h*60 + m
th = (t/2)-(6*m)

res = a**2 + b**2 -2*a*b*math.cos(math.radians(th))
print(res**(1/2))

Solution (Python):
import math

pi = math.pi
A, B, H, M = map(int, input().split())
theta_h = 2 * pi * (H + M / 60) / 12
theta_m = 2 * pi * M / 60
x_h = A * math.cos(theta_h)
y_h = A * math.sin(theta_h)
x_m = B * math.cos(theta_m)
y_m = B * math.sin(theta_m)
d = math.sqrt((x_h - x_m) ** 2 + (y_h - y_m) ** 2)
result = d
print(result)

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd, cos, radians
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True



def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret



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

x = (h * 60 + m) / 2
y = m * 6
z = max(x, y) - min(x, y)
ans = sqrt(a ** 2 + b ** 2 - 2 * a * b * cos(radians(z)))
print(ans)

Solution (Python):
import math
a,b,h,m = list(map(int,input().split()))
xa,ya = a*math.sin(-h*math.pi/6 - m*math.pi/360), a*math.cos(-h*math.pi/6 - m*math.pi/360)
xb,yb = b*math.sin(-m*math.pi/30), b*math.cos(-m*math.pi/30)
print(((xa-xb)**2+(ya-yb)**2)**(1/2))

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

import math


x = 2 * math.pi * (h + m / 60) / 12
y = 2 * math.pi * m / 60

t = abs(x - y)




print(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(t)))

Solution (Python):
import numpy as np

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

h_theta = np.pi *(H+M/60) /6
m_theta = np.pi * M/30

h = np.array([A*np.cos(h_theta), A*np.sin(h_theta)])
m = np.array([B*np.cos(m_theta), B*np.sin(m_theta)])

ans = np.linalg.norm(h-m)

print(ans)

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

alpha = 360/12*(12-H-M/60)
beta = 360/60*(60-M)
the = abs(alpha - beta)
the = min(the, 360-the)
C = (A**2+B**2-2*A*B*math.cos(math.radians(the)))**0.5
print (C)

Solution (Python):
import math

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

a_deg = h*30 + m*0.5
b_deg = m*6

deg = max(a_deg-b_deg,b_deg-a_deg)

cos = math.cos(math.radians(deg))

c2 = a*a + b*b - 2*a*b*cos

print(math.sqrt(c2))

Solution (Python):
import math
[A,B,H,M]=[int(i)for i in input().split()]

totalhun=H*60+M
zisinkakudo=totalhun/720*360
hunsinkakudo = M * 6

aidanokakudo=min(zisinkakudo-hunsinkakudo,360-(zisinkakudo-hunsinkakudo))
c=(A**2+B**2-2*A*B*math.cos(math.radians(aidanokakudo)))**(0.5)
print(c)

Solution (Python):
import numpy as np
a, b, h, m = list(map(int, input().split()))
theta = np.abs(2 * np.pi * (h/12 + m/60 /12 - m/60))
if theta > np.pi:
    theta = 2 * np.pi - theta

ans = np.sqrt(a ** 2 + b ** 2 - 2 * a * b * np.cos(theta))
print(ans)

Solution (Python):
import math

a,b,h,m = [int(i) for i in input().split()]

s = m/60*2*math.pi
t = h/12*2*math.pi+m/60*math.pi/6

if abs(s-t) <= math.pi:
    print(math.sqrt(a**2+b**2-2*a*b*math.cos(abs(s-t))))
else:
    print(math.sqrt(a**2+b**2-2*a*b*math.cos(2*math.pi - abs(s-t))))

Solution (Python):
import math

def cin(): 
	return map(int,input().split())

def cino(test=False): 
    if not test:
        return int(input())
    else: 
        return input()

def cina(): 
  return list(map(int,input().split()))

def ssplit(): 
    return list(input().split())

def printlist(l): 
    for i in l:
        print(i,end=" ")

def calangle(h,m):
    hour_angle = 0.5 * (h * 60 + m) 
    minute_angle = 6 * m 
          
    
    angle = abs(hour_angle - minute_angle) 
        
    
    
    angle = min(360 - angle, angle) 
        
    return angle 

def main():
    a,b,c,d = cin()
    ans = math.sqrt(a**2 + b**2  - 2*a*b*math.cos(calangle(c,d)*(math.pi/180)))
    print(ans)

if __name__=="__main__":
    main()

Solution (Python):

import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortedresult:
        div.sort()
    return div

A, B, H, M = ri_()
kaku = 6 * M - (30 * H + 30 * M / 60)
print(sqrt(A ** 2 + B ** 2 - 2 * A * B * cos(math.radians(kaku))))

Solution (Python):

import numpy as np
import math
a, b, h, m = map(int,input().split())

theta_long = (0.5 * ((h*60)+m) ) % 360
theta_short = (6 * m ) % 360

theta = min(abs(theta_long-theta_short),360-abs(theta_long-theta_short))


x_2 = a**2 + b**2 - 2*a*b*math.cos(math.radians(theta))

print(math.sqrt(x_2))

Solution (Python):
import math

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

short = h/12+(m/60*1/12)
long = m/60

diff = abs(long-short)
ans = diff*360

if ans > 180:
    ans = 360-ans

total = a**2 + b**2 - 2*a*b*math.cos(math.radians(ans))
print(total**(1/2))

Solution (Python):
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    from math import cos,radians
    P = 10**9+7
    INF = 10**9+10
    A,B,H,M = LMIIS()
    argA = M/60*360
    argB = (H/12+M/12/60)*360
    
    

    print((A**2+ B**2 - 2*A*B*cos(radians(abs(argA-argB))))**0.5)

    
main()

Solution (Python):
import math

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

rshort = h * 30 + m * 0.5
rlong = m * 6

kakudo = min(abs(rlong-rshort), 360-abs(rlong-rshort))

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

Solution (Python):
import math

A, B, H, M = [int(n) for n in input().split()]

theta_H = (math.pi / 6)*(H + M/60)
theta_M = (math.pi/30)*M

def to_rect(r,theta):
    return (r*math.cos(theta), r*math.sin(theta))

def dist(tuple1,tuple2):
    return math.sqrt((tuple1[0] - tuple2[0])**2 + (tuple1[1] - tuple2[1])**2)

print(dist(to_rect(A,theta_H), to_rect(B,theta_M)))

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

theta_a = 2 * math.pi * ( h + m / 60 ) / 12
theta_b = 2 * math.pi * m / 60

print( math.sqrt( a ** 2 + b ** 2 - 2 * a * b * math.cos( theta_a - theta_b ) ) )

Solution (Python):
import math
a,b,h,m=map(int,input().split())
t1=math.radians(30*h+0.5*m)
t2=math.radians(6*m)
x1,y1=a*math.cos(t1),a*math.sin(t1)
x2,y2=b*math.cos(t2),b*math.sin(t2)
ans=math.sqrt((x2-x1)**2+(y2-y1)**2)
print(ans)

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

Solution (Python):
import math
def getDegree(H,M):
  H_deg = H / 12 * 360 + M / 60 * (360/12)
  M_deg = M / 60 * 360
  return min([abs(H_deg-M_deg),abs(360-(H_deg-M_deg))])

A,B,H,M=map(int, input().split())
cc = A**2 + B**2 - 2*A*B*math.cos(getDegree(H,M)/360*2*math.pi)
print(cc**0.5)

Solution (Python):
def resolve():
    import math
    a, b, h, m = map(int, input().split())
    a_deg = h / 12 * 360 + m / 60 * 30
    b_deg = m / 60 * 360
    print(math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(min(360 - abs(a_deg - b_deg), abs(a_deg - b_deg))))))

resolve()

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

hour = (h + m / 60) / 12 * math.pi * 2
minute = m / 60 * math.pi * 2

x = a * math.sin(hour) - b * math.sin(minute)
y = a * math.cos(hour) - b * math.cos(minute)
print(math.hypot(x, y))

Solution (Python):
import math
a,b,h,m=map(int,input().split())
t=math.radians(abs((60*h-11*m)/2))
print((a**2+b**2-2*a*b*math.cos(t))**0.5)

Solution (Python):
import math

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

a_ang = 2*(h/12 + m/60/12)*math.pi
b_ang = 2*(m/60)*math.pi

ans = math.sqrt(((a*math.sin(a_ang)-b*math.sin(b_ang))**2)+((a*math.cos(a_ang)-b*math.cos(b_ang))**2))
print(ans)

Solution (Python):
import math
pi = math.pi
a, b, h, m = map(int, input().split())
theta1 = pi * h / 6 + pi * m / 360
theta2 = pi * m / 30
x1 = a * math.cos(theta1)
y1 = a * math.sin(theta1)
x2 = b * math.cos(theta2)
y2 = b * math.sin(theta2)
l = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
print(l)

Solution (Python):
import numpy as np
from scipy.spatial.distance import euclidean

a, b, h, m = map(int, input().split())
M = h*60 + m
A = np.array([np.cos(2*M*np.pi/720),np.sin(2*M*np.pi/720)]) * a
B = np.array([np.cos(2*M*np.pi/60),np.sin(2*M*np.pi/60)]) * b
ans = euclidean(A,B)
print(ans)

Solution (Python):
import sys
import math
import numpy as np
from collections import Counter, defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


inf = float("inf")
mod = 10 ** 9 + 7

a, b, h, m = MI()

hc = 30 * h + 0.5 * m
mc = 6 * m

d = abs(hc - mc)
if d >= 180:
    d = 360 - d


print(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(d))))

Solution (Python):
import math
A,B,H,M = map(int,input().split())
p = abs(30*(H + M/60) - 6*M)
q = math.radians(p)
r = math.cos(q)
ans = (A**2 + B**2 - 2*A*B*r)**(1/2)
print(ans)

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

ji = (360/12*h) + (360/12/60*m)
hun = 360/60*m
cosC = math.cos(math.radians(abs(ji-hun)))

ans = math.sqrt(a**2 + b**2 - 2*a*b*cosC)
print(ans)

Solution (Python):
import math
A, B, H, M = map(int, input().split())
tmp_h = 360*((H*60+M)/720)
tmp_m = 360*(M/60)
target = max(tmp_h,tmp_m)-min(tmp_h,tmp_m)
target = min(target,360-target)
ans = math.sqrt(A**2+B**2-2*A*B*(math.cos(math.radians(target))))
print(ans)

Solution (Python):
import math

A, B, H, M = map(int, input().split())
H_mod = H % 12
hour_angle = 30 * H_mod + 30 * M / 60
min_angle = 6 * M
theta = abs(hour_angle - min_angle)
theta = min(theta, 360 - theta)
C = A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(theta))
print(C ** (1 / 2))

Solution (Python):
import math

s,l,h,m = map(int,input().split())

mr = m*6
hr = h*30 + m*0.5

ans = math.sqrt(s*s + l*l - 2*s*l*math.cos(math.radians(abs(hr-mr))))

print(ans)

Solution (Python):
import math

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

x=360*(m/60)
y=360*((h+m/60)/12)
rad=abs(x-y)
ans=pow(a,2)+pow(b,2)-2*a*b*math.cos(math.radians(rad))
print(pow(ans,0.5))