We denote ci=ai−i, then 0≤c1≤c2≤...≤cn≤100−n, bi=ci or bi=ci+n for all i=1,n. Then, ci+n≤cn+n=an≤100. Note that among the three consecutive numbers ci,ci+1 and ci+2, at least two are different, because otherwise, at least two out of three numbers bi,bi+1 and bi+2 would be the same, which contradicts problem statement. Hence, ci+2≥ci+1.
Thus, cn≥cn−2+1≥⋯≥21(n−1). On the other hand, cn≤100−n. Thus, 21(n−1)≤cn≤100−n⇒n≤67. Now we show an example for n=67:
c1=c2=0, c3=c4=1, …, c65=c66=32 and c67=33,
b1=0, b2=67, b3=1, b4=68, …, b65=32, b66=99 and b67=33,
therefore, ai=ci+i.