We denote
Xmax(f,g)=k=1∑3000max{f(f(k)),f(g(k)),g(f(k)),g(g(k))},
Xmin(f,g)=k=1∑3000min{f(f(k)),f(g(k)),g(f(k)),g(g(k))},
and X(f,g)=Xmax(f,g)−Xmin(f,g). Moreover, for a finite set T, we denote the number of its elements by ∣T∣.
First, we will prove that the answer is at most 6000000. When the bijection f is the identity map, for any bijection g on S, we have f∘g=g∘f. For any a∈S, since the function f∘f is bijective, the equation f(f(x))=a for x has at most one solution. The same is true for the bijections f∘g=g∘f and g∘g. Therefore, the equation max{f(f(x)),f(g(x)),g(f(x)),g(g(x))}=a for x has at most three solutions. Hence we have
Xmax(f,g)≤3×3000+3×2999+⋯+3×2001=k=2001∑30003k,
and similarly,
Xmin(f,g)≥3×1+3×2+⋯+3×1000=k=1∑10003k.
Therefore,
X(f,g)≤k=2001∑30003k−k=1∑10003k=6000000.
Hence, the answer is at most 6000000.
In the following, we will prove that X=6000000 satisfies the condition. We denote
S1={1,2,…,1000},S2={1001,1002,…,2000},S3={2001,2002,…,3000}.
Additionally, for a,b∈{1,2,3}, let Sa,b={x∈Sa∣f(x)∈Sb} and na,b=∣Sa,b∣. Now, for any x∈S, there exists exactly one pair (a,b)∈{1,2,3}2 such that x∈Sa,b.
Lemma. For any bijection f on S, there exists a partition {Z1,Z2,…,Z1000} of S satisfying the following condition:
For any 1≤i≤1000, ∣Zi∣=3 and when a1,a2,a3 denote the elements of Zi in ascending order, we have a1∈S1,a2∈S2 and a3∈S3. In addition, exactly one element of {f(a1),f(a2),f(a3)} belongs to Sb for every b∈{1,2,3}.
Proof. Assume that there exists a tuple (A1,B1,A2,B2,A3,B3) of non-negative integers satisfying the equations:
A1+B1A3+B2A2+B3=n1,1,=n2,1,=n3,1,A2+B2A1+B3A3+B1=n1,2,=n2,2,=n3,2,A3+B3A2+B1A1+B2=n1,3,=n2,3,=n3,3.(∗)
Then, we have a partition {Z1,…,Z1000} of S which satisfies the condition in the lemma and the following condition:
For each Zi={a1,a2,a3} with a1<a2<a3, define a permutation σi of {1,2,3} such that ak∈Sk,σi(k) for k=1,2,3. Then the number of Zi such that (σi(1),σi(2),σi(3)) is equal to (1,2,3), (1,3,2), (2,3,1), (2,1,3), (3,1,2), and (3,2,1) is equal to A1,B1,A2,B2,A3 and B3, respectively.
Hence it is sufficient to prove that a tuple (A1,B1,A2,B2,A3,B3) satisfying the equations (∗) exists.
Without loss of generality, we can assume that n1,1 is the smallest among nine integers na,b (a,b∈{1,2,3}). Setting
(A1,B1,A2,B2,A3,B3)=(n1,1,0,n2,3,n3,3−n1,1,n3,2,n2,2−n1,1),
this is a tuple of non-negative integers by the minimality of n1,1, and satisfies the first, fifth, sixth, eighth, and ninth equations in (∗). Furthermore, for any a∈{1,2,3}, we have
na,1+na,2+na,3n1,a+n2,a+n3,a=∣Sa∣=1000,=∣{x∈S∣f(x)∈Sa}∣=1000.
Thus, we find that the tuple satisfies the second, third, fourth, and seventh equations in (∗):
A2+B2=n2,3+n3,3−n1,1=(n1,3+n2,3+n3,3)−(n1,1+n1,2+n1,3)+n1,2=n1,2,
A3+B3=n3,2+n2,2−n1,1=(n1,2+n2,2+n3,2)−(n1,1+n1,2+n1,3)+n1,3=n1,3,
A3+B2=n3,2+n3,3−n1,1=(n3,1+n3,2+n3,3)−(n1,1+n2,1+n3,1)+n2,1=n2,1,
A2+B3=n2,3+n2,2−n1,1=(n2,1+n2,2+n2,3)−(n1,1+n2,1+n3,1)+n3,1=n3,1,
which completes the proof. ■
Let us consider Zj={a1,a2,a3} with a1<a2<a3. Then a1∈S1, a2∈S2 and a3∈S3. For each i∈{1,2,3}, we define ki by f(ki)=ai. Since g(ki)=h(f(ki))=h(ai)=ai+1, we obtain
max{f(f(ki)),f(g(ki)),g(f(ki)),g(g(ki))}=max{f(ai),f(ai+1),g(ai),g(ai+1)}=max{f(ai),f(ai+1),h(f(ai)),h(f(ai+1))},
where a4=a1. Let us define F1,F2,F3 by {f(a1),f(a2),f(a3)}={F1,F2,F3} and F1<F2<F3. By the condition of the lemma, we have F1∈S1, F2∈S2 and F3∈S3. Furthermore, we have h(F1)∈S2, h(F2)∈S3 and h(F3)∈S1, by the definition of h. Therefore, we obtain
i=1∑3max{f(f(ki)),f(g(ki)),g(f(ki)),g(g(ki))}=max{F1,F2,h(F1),h(F2)}+max{F2,F3,h(F2),h(F3)}+max{F3,F1,h(F3),h(F1)}=h(F2)+max{F3,h(F2)}+F3≥h(F2)+21(F3+h(F2))+F3=23F3+23h(F2).(∗∗)
Every element of S appears exactly once as a1,a2 or a3 for some Zj. Since f is bijective, the same is true for k1,k2 or k3. Furthermore, since f and h are both bijections, each element of S3 appears exactly once as F3, and as h(F2), for some Zj. Hence, by taking sums of both sides of (∗∗) for Z1,…,Z1000, we have
Xmax(f,g)≥23k=2001∑3000k+23k=2001∑3000k=k=2001∑30003k.
Similarly, we have Xmin(f,g)≤∑k=110003k. Therefore, we can conclude that
X(f,g)≥k=2001∑30003k−k=1∑10003k=6000000.
This completes the proof that X=6000000 satisfies the condition, hence the answer is 6000000.