def METHOD_NAME(graph: nx.DiGraph, pattern: nx.DiGraph, subgraph: Dict[str, str]) -> bool:
    """
    Checks out whether the matched subgraph has:
    1) External predecessors of starting nodes.
    2) External successors of the last nodes.
    3) External successors or predecessors of the nodes which are not starting and last.
    If any of these conditions is True, than returns False, otherwise - True.
    The checks are skipped for NON_PATTERN_NODE_TYPE.
    Example:
    This subgraph matching is not strict.
    (conv2d + BN + ReLU pattern):
            ...
             |
          (conv2d)
             |------\
            (BN)    |
             |      |
           (RELU)   |
             |      |
           (cat)----/
             |
            ...
    :param graph: The model graph.
    :param pattern: The matched pattern.
    :param subgraph: A subgraph of the model graph including the nodes outside the pattern.
    :return: If any of three conditions is True than returns False, otherwise - True.
    """
    starting_nodes = []
    last_nodes = []
    for node in pattern.nodes:
        if not pattern.pred[node] and pattern.succ[node]:
            starting_nodes.append(node)
        if pattern.pred[node] and not pattern.succ[node]:
            last_nodes.append(node)
    for node_from_graph, node_from_pattern in subgraph.items():
        if GraphPattern.NON_PATTERN_NODE_TYPE in pattern.nodes[node_from_pattern].get(GraphPattern.METATYPE_ATTR, []):
            continue
        predecessors_keys = graph.pred[node_from_graph].keys()
        successor_keys = graph.succ[node_from_graph].keys()
        has_external_successors = any(successor_key not in subgraph for successor_key in successor_keys)
        has_external_predcessors = any(predecessor_key not in subgraph for predecessor_key in predecessors_keys)
        if node_from_pattern in starting_nodes and has_external_successors:
            return False
        if node_from_pattern in last_nodes and has_external_predcessors:
            return False
        if (node_from_pattern not in last_nodes and node_from_pattern not in starting_nodes) and (
            has_external_successors or has_external_predcessors
        ):
            return False
    return True