def orderIter(arr, reverse=False):
    """generate order of given array. e.g. the index of smallest item come first
  """
    ad = {}
    for i, v in enumerate(arr):
        if v not in ad:
            ad[v] = []
        ad[v].append(i)
    a = sorted(ad, reverse=reverse)
    for v in a:
        for i in ad[v]:
            yield i
