# Problem Description
The problem involves calculating the length of a line segment (red dashed line) on an analog clock after a certain duration has passed. The initial time is given along with the lengths of the hour and minute hands. The goal is to determine the length of the red dashed line, which connects the initial position of the minute hand to the new position of the hour hand after a specified number of minutes.

# Visual Facts
1. **Initial Time and Hand Positions**:
   - The initial time is given in hours (h) and minutes (m).
   - The orange arrow represents the hour hand.
   - The green arrow represents the minute hand.

2. **Time Progression**:
   - The time progresses by a specified number of minutes (k).

3. **Hand Movements**:
   - The minute hand moves 6 degrees per minute.
   - The hour hand moves 0.5 degrees per minute.

4. **Red Dashed Line**:
   - The red dashed line connects the initial position of the minute hand to the new position of the hour hand after k minutes.

# Visual Patterns
1. **Angle Calculation**:
   - The initial position of the hour hand can be calculated as θ_{h_{initial}} = h*30 + m*0.5 degrees.
   - The initial position of the minute hand can be calculated as θ_{m_{initial}} = m*6 degrees.
   - The new position of the hour hand after k minutes can be calculated as θ_{h_{final}} = θ_{h_{initial}} + k*0.5 degrees.
   - The new position of the minute hand after k minutes can be calculated as θ_{m_{final}} = (m + k)*6 degrees.

2. **Angle Between Initial and Final Positions**:
   - The angle between the initial position of the minute hand and the final position of the hour hand is θ = |θ_{m_{initial}} - θ_{h_{final}}|.

3. **Law of Cosines**:
   - To find the length of the red dashed line, we use the law of cosines:
   red_length = \sqrt{a^2 + b^2 - 2ab cos(θ)}
   where a is the length of the minute hand, b is the length of the hour hand, and θ is the angle between the initial position of the minute hand and the final position of the hour hand.

# Solution
import math


def solution(h: int, m: int, a: int, b: int, k: int) -> float:
    """
    Given an initial time (in 12-hour format) and the lengths of the orange and green arrows,
    calculate the distance between the initial minute hand and the hour hand after k minutes.

    Parameters:
        h (int): Hour.
        m (int): Minute.
        a (int): Length of the orange arrow (hour hand).
        b (int): Length of the green arrow (minute hand).
        k (int): Duration passed (in minutes).

    Returns:
        float: Distance between the initial minute hand and the hour hand after k minutes (rounded to two decimal places).
    """
    # Calculate the new time for the hour hand
    total_minutes = h * 60 + m + k
    new_h = (total_minutes // 60) % 12
    new_m = total_minutes % 60

    # Calculate the angles
    initial_minute_angle = m * 6  # 6 degrees per minute for the initial minute hand
    hour_angle = (new_h % 12) * 30 + new_m * 0.5  # 30 degrees per hour + 0.5 degrees per minute

    # Convert angles to radians
    minute_angle_rad = math.radians(initial_minute_angle)
    hour_angle_rad = math.radians(hour_angle)

    # Convert to Cartesian coordinates
    # Initial minute hand
    minute_x = b * math.cos(minute_angle_rad)
    minute_y = b * math.sin(minute_angle_rad)

    # New hour hand after k minutes
    hour_x = a * math.cos(hour_angle_rad)
    hour_y = a * math.sin(hour_angle_rad)

    # Calculate the distance between the two points
    distance = math.sqrt((minute_x - hour_x) ** 2 + (minute_y - hour_y) ** 2)

    return round(distance, 2)


# Test Script
def test():
    test_cases = [
        (2, 0, 3, 4, 60, 5.0),
        (3, 0, 4, 3, 180, 7.0),
        (3, 0, 2, 7, 40, 7.91),
        (4, 20, 6, 8, 70, 5.67),
        (6, 0, 6, 8, 150, 11.17),
        (8, 22, 5, 9, 137, 13.97),
        (7, 12, 4, 6, 29, 9.83),
        (1, 56, 2, 7, 173, 8.97),
        (1, 56, 3, 4, 104, 6.46),
        (0, 56, 3, 4, 84, 5.16),
    ]

    for h, m, a, b, k, expected_output in test_cases:
        try:
            output = solution(h, m, a, b, k)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`h`: {h}\n"
                f"`m`: {m}\n"
                f"`a`: {a}\n"
                f"`b`: {b}\n"
                f"`k`: {k}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message

        if output != expected_output:
            error_message = (
                f"The following Test Case failed:\n"
                f"`h`: {h}\n"
                f"`m`: {m}\n"
                f"`a`: {a}\n"
                f"`b`: {b}\n"
                f"`k`: {k}\n\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {expected_output}"
            )
            assert False, error_message

test()