def argmax_pair(array, key):
    """Find an (unordered) pair of indices that maximize the given function"""
    n = len(array)
    mi, mj, m = None, None, None
    for i in range(n):
        for j in range(i+1, n):
            k = key(array[i], array[j])
            if not m or k > m:
                mi, mj, m = i, j, k
    return mi, mj