File with minimum energy 1 10 20 30 40 2 20 30 45 50 Another file 1 10 11 50 50 2 20 21 60 60 Do you want: R 11 30 R 21 5 30 = (50 + 50) - (30 + 40) 5 = (60 + 60) - (45 + 50) I just put 'R' since I don't know what that value should be.