def count_ranges(a):
    """
    Assumes binary array of 1 and 0 as input. Calculate longest ranges of 1's.

    :param a: array with binary values
    :return: [end_pos, length] of ranges in array
    """
    ranges = []
    count = 0
    for i, v in enumerate(a):
        if v == 1:  # same as previous value
            count += 1
        else:
            if count > 1:
                ranges.append([i, count])  # [end, length]
            count = 0
    return ranges