For any two coprime positive integers $p, q$, define $f(i)$ to be the remainder of $p\cdot i$ divided by $q$ for $i = 1, 2,\ldots,q -1$. The number $i$ is called a[b] large [/b]number (resp. [b]small[/b] number) when $f(i)$ is the maximum (resp. the minimum) among the numbers $f(1), f(2),\ldots,f(i)$. Note that $1$ is both large and small. Let $a, b$ be two fixed positive integers. Given that there are exactly $a$ large numbers and $b$ small numbers among $1, 2,\ldots , q - 1$, find the least possible number for $q$.
[i]
Proposed by usjl[/i]
1. **Restate the problem with new variables**: Let \( m \) and \( n \) replace \( p \) and \( q \) respectively, where \(\gcd(m, n) = 1\). Define \( R(x, y) \) as the unique integer in \([0, y)\) such that \( y \mid x - R(x, y) \). We need to find the smallest \( n \) such that there are exactly \( a \) large numbers and \( b \) small numbers among \( 1, 2, \ldots, n-1 \).

2. **Construction**: We propose \( m = b \) and \( n = ab + 1 \). We need to show that this construction satisfies the conditions of the problem.

3. **Define peaks and valleys**: Let \( a(m, n) \) denote the number of peaks (large numbers) in \( R(mt, n) \) as \( t \) goes from \( 1 \) to \( n-1 \). Similarly, let \( b(m, n) \) denote the number of valleys (small numbers) in \( R(mt, n) \).

4. **Symmetry in peaks and valleys**: Observe that \( R(mt, n) + R(-mt, n) = n \). This implies that if \( t \) is a peak in the sequence \( R(mt, n) \), it must be a valley in the sequence \( R(-mt, n) \), and vice versa.

5. **Claim**: Suppose \( 0 < m < \frac{n}{2} \). We have \( a(-m, n) = a(-m, n-m) \) and \( a(m, n) = a(m, n-m) + 1 \).

6. **Proof of the claim**:
    - To prove \( a(m, n) = a(m, n-m) + 1 \), note that \( t = 1, \ldots, \left\lfloor \frac{n}{m} \right\rfloor \) are all peaks. Let \( S_t = \{ x \mid x \equiv t \pmod{m} \} \). As we traverse the sequence \( R(mt, n) \) from \( 1 \) to \( n-1 \), we go through \( S_0, S_{-n}, S_{-2n}, \ldots \) in ascending order. There is at most one peak in each \( S_{-n}, S_{-2n}, \ldots \), and these peaks do not depend on \( n \) as long as \( n \pmod{m} \) is fixed.
    - The proof for \( a(-m, n) = a(-m, n-m) \) is analogous. We go through each \( S_j \) in descending order, and each \( |S_j| \ge 2 \), so we can remove one element from each.

7. **Induction on \( a + b \)**: We proceed by strong induction on \( a + b \) to prove that the answer for \( a, b \) is \( ab + 1 \). The base case, \( (1, 1) \), is trivial.

8. **Symmetry in \( a \) and \( b \)**: Note that \( f(b, a) = f(a, b) \) because if \( a(m, n) = a \) and \( b(m, n) = b \), then it must follow that \( a(-m, n) = b \) and \( b(-m, n) = a \).

9. **Inductive step**: Suppose \( m \) satisfies \( a(m, f(a, b)) = a \) and \( b(m, f(a, b)) = b \). If \( m < \frac{f(a, b)}{2} \), we replace \( m \) with \( -m \) and focus on \( f(b, a) = f(a, b) \). In this case, \( m \ge b \) because the number of valleys is at most \( m \). Therefore, \( f(a, b) - m \) satisfies \( a(m, f(a, b) - m) = a - 1 \) and \( b(m, f(a, b) - m) = b \). Thus, \( f(a, b) \ge m + f(a-1, b) \ge b + (a-1)b + 1 = ab + 1 \), completing the induction.

The final answer is \( \boxed{ ab + 1 } \).