To start, we get from (*) that f4(n)=f(f3(n))=f(f(n+1)+1) and f4(n+1)=f3(f(n+1))=f(f(n+1)+1)+1 thus f4(n)+1=f4(n+1). I. Let us denote by Ri the range of fi; note that R0=Z⩾0 since f0 is the identity function. Obviously, R0⊇R1⊇… Next, from (2) we get that if a∈R4 then also a+1∈R4. This implies that Z⩾0\R4 - and hence Z⩾0\R1 - is finite. In particular, R1 is unbounded. Assume that f(m)=f(n) for some distinct m and n. Then from (∗) we obtain f(m+1)= f(n+1); by an easy induction we then get that f(m+c)=f(n+c) for every c⩾0. So the function f(k) is periodic with period ∣m−n∣ for k⩾m, and thus R1 should be bounded, which is false. So, f is injective. II. Denote now Si=Ri−1\Ri; all these sets are finite for i⩽4. On the other hand, by the injectivity we have n∈Si⟺f(n)∈Si+1. By the injectivity again, f implements a bijection between Si and Si+1, thus ∣S1∣=∣S2∣=…; denote this common cardinality by k. If 0∈R3 then 0=f(f(f(n))) for some n, thus from (*) we get f(n+1)=−1 which is impossible. Therefore 0∈R0\R3=S1∪S2∪S3, thus k⩾1. Next, let us describe the elements b of R0\R3=S1∪S2∪S3. We claim that each such element satisfies at least one of three conditions (i)b=0,(ii)b=f(0)+1, and (iii) b−1∈S1. Otherwise b−1∈Z⩾0, and there exists some n>0 such that f(n)=b−1; but then f3(n−1)=f(n)+1=b, so b∈R3. This yields 3k=∣S1∪S2∪S3∣⩽1+1+∣S1∣=k+2, or k⩽1. Therefore k=1, and the inequality above comes to equality. So we have S1={a}, S2={f(a)}, and S3={f2(a)} for some a∈Z⩾0, and each one of the three options (i), (ii), and (iii) should be realized exactly once, which means that {a,f(a),f2(a)}={0,a+1,f(0)+1}. III. From (3), we get a+1∈{f(a),f2(a)} (the case a+1=a is impossible). If a+1=f2(a) then we have f(a+1)=f3(a)=f(a+1)+1 which is absurd. Therefore f(a)=a+1 Next, again from (3) we have 0∈{a,f2(a)}. Let us consider these two cases separately. Case 1. Assume that a=0, then f(0)=f(a)=a+1=1. Also from (3) we get f(1)=f2(a)= f(0)+1=2. Now, let us show that f(n)=n+1 by induction on n; the base cases n⩽1 are established. Next, if n⩾2 then the induction hypothesis implies n+1=f(n−1)+1=f3(n−2)=f2(n−1)=f(n), establishing the step. In this case we have obtained the first of two answers; checking that is satisfies (*) is straightforward. Case 2. Assume now that f2(a)=0; then by (3) we get a=f(0)+1. By (4) we get f(a+1)= f2(a)=0, then f(0)=f3(a)=f(a+1)+1=1, hence a=f(0)+1=2 and f(2)=3 by (4). To summarize, f(0)=1,f(2)=3,f(3)=0. Now let us prove by induction on m that (1) holds for all n=4k,4k+2,4k+3 with k⩽m and for all n=4k+1 with k<m. The base case m=0 is established above. For the step, assume that m⩾1. From (*) we get f3(4m−3)=f(4m−2)+1=4m. Next, by (2) we have f(4m)=f4(4m−3)=f4(4m−4)+1=f3(4m−3)+1=4m+1. Then by the induction hypothesis together with (*) we successively obtain f(4m−3)=f3(4m−1)=f(4m)+1=4m+2,f(4m+2)=f3(4m−4)=f(4m−3)+1=4m+3,f(4m+3)=f3(4m−3)=f(4m−2)+1=4m, thus finishing the induction step. Finally, it is straightforward to check that the constructed function works: f3(4k)=4k+7=f(4k+1)+1,f3(4k+1)=4k+4=f(4k+2)+1,f3(4k+2)=4k+1=f(4k+3)+1,f3(4k+3)=4k+6=f(4k+4)+1.