A friend of yours wrote a program that compares every pair of n items exactly once. The program first prints 1 and compares item 1 with items 2,3,4,…,n. It then prints 2 and compares item 2 with items 3,4,5,…,n. It goes on the same way until every pair has been compared exactly once. If it compares item x with item y, it never compares item y with item x later, and it never compares an item with itself.
Your friend wants to know the moment the program is halfway done. If the total number of comparisons is odd, that is the moment it performs the middle comparison. If the total is even, that is the moment it performs the first of the two middle comparisons.
Find the last number printed when the program is halfway done.
Earlier items take part in more comparisons than later ones, so the answer is not n/2.