Yep, i was at uni and i don't have a compiler there, it should be the other way around
*(ib+=*ia==*ib)=*ia++
which means the target will only increment when the values are equal.
Notice the target iterator ib will the last result value, meaning you cut of the last numbers, also ib<&both[MAX_LENGTH_BOTH] not ia