Solution:
The required polynomials are all polynomials of an even degree d≥2, and all polynomials of odd degree d≥3 with negative leading coefficient.
Part I. We begin by showing that any (non-constant) polynomial S(x) not listed above is not (A,B)-nice for some pair (A,B) with either ∣A∣=∣B∣=2, or ∣A∣=∣B∣=3.
If S(x) is linear, then so are all the polynomials appearing on the board. Therefore, none of them will be (A,B)-nice, say, for A={1,2,3} and B={1,2,4}, as desired.
Otherwise, degS=d≥3 is odd, and the leading coefficient is positive. In this case, we make use of the following technical fact, whose proof is presented at the end of the solution.
Claim. There exists a positive constant T such that S(x) satisfies the following condition:
S(b)−S(a)≥b−a whenever b−a≥T
Fix a constant T provided by the Claim. Then, an immediate check shows that all newly appearing polynomials on the board also satisfy (∗) (with the same value of T ). Therefore, none of them will be (A,B)-nice, say, for A={0,T} and B={0,T/2}, as desired.
Part II. We show that the polynomials listed in the Answer satisfy the requirements. We will show that for any a1<a2<⋯<an and any b1≤b2≤⋯≤bn there exists a polynomial f(x) satisfying f(ai)=bσ(i) for all i=1,2,…,n, where σ is some permutation.
The proof goes by induction on n≥2. It is based on the following two lemmas, first of which is merely the base case n=2; the proofs of the lemmas are also at the end of the solution.
Lemma 1. For any a1<a2 and any b1,b2 one can write down on the board a polynomial F(x) satisfying F(ai)=bi,i=1,2.
Lemma 2. For any distinct numbers a1<a2<⋯<an one can produce a polynomial F(x) on the board such that the list F(a1),F(a2),…,F(an) contains exactly n−1 distinct numbers, and F(a1)=F(a2).
Now, in order to perform the inductive step, we may replace the polynomial S(x) with its shifted copy S(C+x) so that the values S(ai) are pairwise distinct. Applying Lemma 2 , we get a polynomial f(x) such that only two among the numbers ci=f(ai) coincide, namely c1 and c2. Now apply Lemma 1 to get a polynomial g(x) such that g(a1)=b1 and g(a2)=b2. Apply the inductive hypothesis in order to obtain a polynomial h(x) satisfying h(ci)=bi−g(ai) for all i=2,3,…,n. Then the polynomial h(f(x))+g(x) is a desired one; indeed, we have h(f(ai))+g(ai)=h(ci)+g(ai)=bi for all i=2,3,…,n, and finally h(f(a1))+g(a1)= h(c1)+g(a1)=b2−g(a2)+g(a1)=b1.
It remains to prove the Claim and the two Lemmas.
Proof of the Claim. There exists some segment Δ=[α′,β′] such that S(x) is monotone increasing outside that segment. Now one can choose α≤α′ and β≥β′ such that S(α)<minx∈ΔS(x) and S(β)>maxx∈ΔS(x). Therefore, for any x,y,z with x≤α≤y≤β≤z we get S(x)≤S(α)≤S(y)≤S(β)≤S(z).
We may decrease α and increase β (preserving the condition above) so that, in addition, S′(x)>3 for all x∈/[α,β]. Now we claim that the number T=3(β−α) fits the bill.
Indeed, take any a and b with b−a≥T. Even if the segment [a,b] crosses [α,β], there still is a segment [a′,b′]⊆[a,b]\(α,β) of length b′−a′≥(b−a)/3. Then
S(b)−S(a)≥S(b′)−S(a′)=(b′−a′)⋅S′(ξ)≥3(b′−a′)≥b−a
for some ξ∈(a′,b′).
Proof of Lemma 1. If S(x) has an even degree, then the polynomial T(x)=S(x+a2)−S(x+a1) has an odd degree, hence there exists x0 with T(x0)=S(x0+a2)−S(x0+a1)=b2−b1. Setting G(x)=S(x+x0), we see that G(a2)−G(a1)=b2−b1, so a suitable shift F(x)=G(x)+(b1−G(a1)) fits the bill.
Assume now that S(x) has odd degree and a negative leading coefficient. Notice that the polynomial S2(x):=S(S(x)) has an odd degree and a positive leading coefficient. So, the polynomial S2(x+a2)−S2(x+a1) attains all sufficiently large positive values, while S(x+a2)−S(x+a1) attains all sufficiently large negative values. Therefore, the two-variable polynomial S2(x+a2)−S2(x+a1)+S(y+a2)−S(y+a1) attains all real values; in particular, there exist x0 and y0 with S2(x0+a2)+S(y0+a2)−S2(x0+a1)−S(y0+a1)=b2−b1. Setting G(x)=S2(x+x0)+S(x+y0), we see that G(a2)−G(a1)=b2−b1, so a suitable shift of G fits the bill.
Proof of Lemma 2. Let Δ denote the segment [a1;an]. We modify the proof of Lemma 1 in order to obtain a polynomial F convex (or concave) on Δ such that F(a1)=F(a2); then F is a desired polynomial. Say that a polynomial H(x) is good if H is convex on Δ.
If degS is even, and its leading coefficient is positive, then S(x+c) is good for all sufficiently large negative c, and S(a2+c)−S(a1+c) attains all sufficiently large negative values for such c. Similarly, S(x+c) is good for all sufficiently large positive c, and S(a2+c)−S(a1+c) attains all sufficiently large positive values for such c. Therefore, there exist large c1<0<c2 such that S(x+c1)+S(x+c2) is a desired polynomial. If the leading coefficient of H is negative, we similarly find a desired polynomial which is concave on Δ.
If degS≥3 is odd (and the leading coefficient is negative), then S(x+c) is good for all sufficiently large negative c, and S(a2+c)−S(a1+c) attains all sufficiently large negative values for such c. Similarly, S2(x+c) is good for all sufficiently large positive c, and S2(a2+c)−S2(a1+c) attains all sufficiently large positive values for such c. Therefore, there exist large c1<0<c2 such that S(x+c1)+S2(x+c2) is a desired polynomial.