You are given a sequence of n integers a1,a2,…,an and an integer v. Consider every pair (ai,aj) of elements of the sequence with i<j.
Among those pairs, find the ones whose sum ai+aj is closest to v, that is, the pairs that minimize ∣ai+aj−v∣, and print how many pairs reach that smallest distance. A sum equal to v has distance 0.
Pairs are distinguished by position. Two pairs that hold the same values at different indices count separately.