Proplem in mapping the indeces

Hi,
In the code below I have 2 nested loops, with the inner loop starts from the index of the outer loop till the end. You can think of it as I am trying to find ll the combinations. So if we have 'm' rows, we will have m(m+1)/2 possible combination. I want to map 'i' & 'g' to indices that covers that range starting from 0 to ( (m(m+1)/2) - 1).