Source: USAMO-2020-P4
Category: Extremal Problems

Problem: Suppose that $(a_1, b_1), (a_2, b_2), \cdots, (a_100, b_100)$ are distinct ordered pairs of nonnegative integers. Let $N$ denote the number of pairs of integers $(i, j)$ satisfying $1 \leq i < j \leq 100$ and $|aibj − aj bi| = 1. Determine the largest possible value of Nover all possible choices of the 100 ordered pairs.

Answer: The answer is $197$. In general, if $100$ is replaced by $n \geq 2$ the answer is $2n − 3$.

Reference solution:
The answer is $197$. In general, if $100$ is replaced by $n \ge 2$, the answer is $2n-3$.

Let $P_i = (a_i, b_i)$ be a point in the coordinate plane, and let $O = (0,0)$. The condition $|a_i b_j - a_j b_i| = 1$ is equivalent to the condition that the area of $\triangle O P_i P_j$ is exactly $1/2$. We wish to maximize the number of such triangles. Call a triangle with area $1/2$ and one vertex at $O$ *good*.

\paragraph{Construction of $197$ pairs.}
It suffices to use the $100$ points $(1,0)$ and $(k,1)$ for $k=1, 2, \dots, 99$. Notice that:
\begin{itemize}
\item There are $98$ good triangles with vertices $(0,0)$, $(k,1)$, and $(k+1,1)$ for $k=1, \dots, 98$.
\item There are $99$ good triangles with vertices $(0,0)$, $(1,0)$, and $(k,1)$ for $k=1, \dots, 99$.
\end{itemize}
This yields a total of $98 + 99 = 197$ good triangles.

\paragraph{Proof that $197$ pairs is optimal.}
We proceed by induction on $n$ to show the upper bound of $2n-3$. The base case $n=2$ is evident, yielding at most $2(2)-3 = 1$ good triangle. 

For the inductive step, suppose (without loss of generality) that the point $P = P_n = (a,b)$ is the farthest away from the origin $O$ among all $n$ points.

\begin{claim*}
This farthest point $P = P_n$ is part of at most two good triangles.
\end{claim*}

\begin{proof}
We must have $\gcd(a,b) = 1$ for $P$ to be in any good triangles at all, since otherwise any divisor of $\gcd(a,b)$ would also divide $2[OPQ] = |a b_Q - b a_Q| = 1$. 

Consider the locus of all points $Q$ for which $[OPQ] = 1/2$. This locus consists of two parallel lines passing with slope $OP$. Since $\gcd(a,b)=1$, the distance between consecutive lattice points on each of these two lines is exactly $\sqrt{a^2+b^2} = OP$. Indeed, if one of the points is $(u,v)$, then the others on the line are $(u \pm a, v \pm b)$ where the signs match.

Because $P$ is chosen to be the farthest point from $O$ among all given points, any valid point $Q$ must lie inside the quarter-circle in the first quadrant centered at $O$ with radius $OP$. Since the given points have nonnegative coordinates and $P \neq O$ implies $a,b \ge 0$ with at least one strictly positive, moving from $(u,v)$ by adding $(a,b)$ strictly increases the distance from the origin. Specifically, $(u+a)^2 + (v+b)^2 = u^2+v^2 + a^2+b^2 + 2(au+bv) \ge OP^2 + u^2+v^2 > OP^2$. Consequently, only two lattice points on this locus (at most one on each line) actually lie inside the quarter-circle centered at $O$ with radius $OP$. Thus, across both lines, there are at most two valid lattice points $Q$ available among the given points. This proves the claim.
\end{proof}

This claim allows us to complete the induction by simply deleting $P_n$. We lose at most $2$ good triangles, and by the inductive hypothesis, the remaining $n-1$ points form at most $2(n-1)-3$ good triangles. Thus, the $n$ points form at most $2(n-1)-3 + 2 = 2n-3$ good triangles.

For $n=100$, the maximum number of good triangles is $2(100)-3 = 197$.

Grading guidelines:
(Partial) 1. Reformulated the condition |a_ib_j-a_jb_i|=1 as: the triangle with vertices O=(0,0), P_i, P_j has area 1/2 (equivalently the vectors form a unimodular pair). 2. Gave a construction producing N=197 (e.g. using (1,0) and (k,1) for k=1,…,99, and correctly counted 99+98 pairs with determinant ±1). 3. Proved a nontrivial upper bound step such as: if P=(a,b) participates in a good pair then gcd(a,b)=1, or described/derived the two parallel lines of integer points Q satisfying |ab_Q-ba_Q|=1. (Almost) 1. Proved the general upper bound N≤2n−3 by deleting a farthest point P and showing it can be in at most two good pairs, but left a localized gap in justifying “at most two” (e.g. incomplete argument about lattice spacing on the locus lines or why only one point per line can lie within the radius OP). 2. Completed the induction and obtained N≤197 for n=100, but did not give (or miscounted slightly) a matching construction attaining 197. 3. Gave the correct construction and the induction framework, but omitted checking a boundary case (e.g. when a=0 or b=0, or when gcd(a,b)>1 implying no good pairs), or made a small determinant/strict-inequality error in the distance comparison for excluding further points on the locus.

Construction task:
For n = 10, construct an array of 10 ordered pairs of nonnegative integers that maximizes the number of pairs (i, j) satisfying 1 <= i < j <= 10 and |a_i * b_j - a_j * b_i| = 1.

Requirements for the construction:
- Provide exactly 10 distinct ordered pairs.
- Represent the ordered pairs as a Python list of lists (e.g., [[a1, b1], [a2, b2], ..., [a10, b10]]).
- Ensure all integers are nonnegative.
- The construction must achieve the maximum possible value of N for n = 10.
- Include exactly one construction block and put ONLY the Python literal list between the tags:
<construct>
</construct>
- Do not use code fences. Do not put any extra text inside <construct>...</construct>.

Reference construction:
[[1, 0], [1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1], [9, 1]]

Verifier code:
import sys
import ast

def main():
    """
    Verifier script for the combinatorics-construction task.
    This script reads a construction of 10 ordered pairs of nonnegative integers
    and verifies that they maximize the number of pairs (i, j) satisfying 
    |a_i * b_j - a_j * b_i| = 1.
    """
    try:
        # Read the raw input from stdin
        raw_input = sys.stdin.read().strip()
        if not raw_input:
            print("Error: No input provided.")
            return
        
        # Parse the Python literal list
        try:
            data = ast.literal_eval(raw_input)
        except Exception as e:
            print(f"Error parsing construction: {e}")
            return

        # Verify the structure: a list of exactly 10 elements
        if not isinstance(data, list):
            print("Error: The construction must be a list.")
            return
        
        if len(data) != 10:
            print(f"Error: Expected exactly 10 pairs, found {len(data)}.")
            return
        
        pairs = []
        for i, item in enumerate(data):
            # Verify each element is a list or tuple of exactly 2 elements
            if not isinstance(item, (list, tuple)) or len(item) != 2:
                print(f"Error: Element at index {i} is not a pair (list or tuple of length 2).")
                return
            
            # Verify each coordinate is an integer (and not a boolean subclass)
            if not all(isinstance(x, int) and not isinstance(x, bool) for x in item):
                print(f"Error: Element at index {i} contains non-integer values.")
                return
            
            # Verify all integers are nonnegative
            if not all(x >= 0 for x in item):
                print(f"Error: Element at index {i} contains negative integers.")
                return
            
            pairs.append(tuple(item))
        
        # Verify that all 10 pairs are distinct
        if len(set(pairs)) != 10:
            print("Error: The 10 pairs are not distinct.")
            return
        
        # Calculate N: the number of pairs (i, j) with 0 <= i < j < 10 satisfying |a_i*b_j - a_j*b_i| = 1
        n_count = 0
        n = len(pairs)
        for i in range(n):
            for j in range(i + 1, n):
                a_i, b_i = pairs[i]
                a_j, b_j = pairs[j]
                # Calculate the absolute difference of the cross-product
                if abs(a_i * b_j - a_j * b_i) == 1:
                    n_count += 1
        
        # The theoretical maximum for n=10 is 2n - 3 = 17
        expected_n = 17
        if n_count == expected_n:
            print("True")
        else:
            print(f"Error: N_count is {n_count}, but the maximum value for n=10 is {expected_n}.")

    except Exception as e:
        # Catch-all for any unexpected runtime errors
        print(f"Error: {e}")

if __name__ == "__main__":
    main()