import re


def flatten(char_sequences, indices=False):
    """
    Function to split and flatten character sequences

    Args:
        char_sequences (list[str]): character sequences
        indices (bool): True to return a list of indices

    Returns:
        flat (list[str]): flattened arguments character sequences
        indices (list[int]): optional list of indices
    """
    flat = []
    if indices:
        indices = []
        for i, speech in enumerate(char_sequences):
            split = re.split(r"\r\n|\n|\r|\n\r", speech)
            for j, segment in enumerate(split):
                if segment != "":
                    flat.append(segment)
                    indices.append([i, j])
        # return both lists
        return indices, flat
    else:
        for speech in char_sequences:
            split = re.split(r"\r\n|\n|\r|\n\r", speech)
            for segment in split:
                if segment != "":
                    flat.append(segment)
        return flat