def find_pos(mydict, n, keys):
    """
    Find the bag and local position of the overall nth element in one set of a
    dictionary.

    Parameters
    ----------
    mydict : dictionary
        Dictionary with array_like values. Each such array_like must have the
        same shape except for the first dimension.
    n : int
        The global position of the wanted instance.
    keys : list
        keys for each bag used for the ordering to look for instance n.

    Returns
    ----------
    key : key
        Dictionary with array_like values corresponding to the given keys.
    l : int

    """
    n_ = -1
    for k, key in enumerate(keys):
        n_ += len(mydict[key])

        if n_ == n:
            return (key, len(mydict[key]) - 1)
        elif n_ > n:
            return (key, n - n_ + len(mydict[key]) - 1)
        else:
            continue