The final position in this sequence is legal. (See Baibikov, "Length records in 'Last single moves?' problems", A15.) It is remarkable in being the lightest-known position in which the last 17 single-moves can be determined, neither king is in check and it is not specified whose move it is. "Lightness" is decided primarily by the number of pieces and pawns in the diagram position. (Baibikov had a further method of determining which of two positions is the lighter if they have the same number, but that needn't concern us here.)
It can be deduced from the board position that White moved last. While White got into position, Black needed to use up four turns pushing the h7 pawn. Therefore if Black had another turn, Black would have to make another pawn push, beyond the diagram position. Therefore the diagram position is legal with Black to move but illegal with White to move. Similarly, if the black pawn were put on h4 instead of h3, the position would be illegal because Black must have spent only 3 turns pushing the pawn, thus failing to give White enough moves to get into position.
[Title "Dmitri Baibikov"]
[fen "8/Ppp4p/rp6/1k6/n7/KPP5/pPP4P/1b6 w - - 0 1"]
[StartFlipped "0"]
[StartPly "17"]
1. h3 {White must spend 4 turns moving this pawn to h6, so must not use the two-square option} Ka5 {unpinning Black's knight} 2. h4 Nc5 3. h5 Ne6 4. h6 Ng7 5. hxg7 h6 {Black must spend 4 turns moving this pawn to h3, so must not use the two-square option} 6. g8=N h5 7. Nf6 {Ne7? h4 8. Nc6+??} h4 8. Nd7 h3 9. Nb8
White has 7 units, so Black has made 9 captures. White's a-pawn has always been on a2 or b3. So the black bishop on b1 is not the original c8 bishop, but one created by a promotion a2xb1=B. So this black pawn and the one now on a2 are Black's d and e pawns, which have made 3+4=7 captures to reach a2. Together with a2xb1 and a7xb6, this makes 9, accounting for Black's captures of all White's 9 missing units. (These include the c1 bishop. Thus White made the capture d2xc3 when that bishop was still at home on c1, to be captured later by a black pawn.)
Black has 8 units, so White has made 8 captures. White pawns have made at least 6 captures axb3, dxc3, exdxcxbxa, accounting for all but 2 of White's 8 captures. Black's a-pawn has always been on a7 or b6, so White captured e2xd3xc4xb5xa6.
So White's f, g, h pawns can't have captured more than twice between them. One captured on g7 then promoted to wNb8, and two are missing. All Black's 9 captures were on the queenside, by pawns. So White's two missing pawns promoted so as to get to the queenside to get captured. Black's f, g, h pawns had nothing to capture and so never left their files, and the h-pawn is still on the h-file. So, for White's h-pawn to avoid Black's h-pawn and promote, it had to capture to the g-file. If neither White's f nor g-pawn captured, White's f-pawn couldn't have passed Black's f-pawn and so couldn't have promoted. So one of White's f and g-pawns captured, only once, and this means that all White's captures were by pawns.
Suppose that White's latest capture (the one within the scope of my diagram) was not h6xNg7 but f6xNg7. Then White's earlier moves were by a pawn on the f-file. Black's f-pawn isn't in the diagram, so what happened to it? It had nothing to capture, so never left the f-file. It couldn't have promoted, because White's f-pawn was in the way. But it couldn't have got captured, because 6 of White's 8 captures were on the queenside and the other two were fxNg7 and hxPg (to let White's g and h-pawns promote).
So White's latest capture was h6xNg7. Now the kingside pawns that are on the board are on the same file, so the above difficulty doesn't arise. White played either fxPg or gxPf, then White's f and g-pawns and Black's remaining f or g-pawn promote without capture.