from dataclasses import dataclass
from typing import Optional


@dataclass
class Node[T]:
    mark: T
    left: 'Optional[Node[T]]' = None
    right: 'Optional[Node[T]]' = None


type Tree[T] = Optional[Node[T]]


def insert[T](t: Tree[T], value: T) -> Tree[T]:
    if t is None:
        return Node(value)

    if value < t.mark:
        t.left = insert(t.left, value)
    else:
        t.right = insert(t.right, value)

    return t
