There's mistake in editorial of 1661F?
See my comment: There's inconsistency in tutorial and solution code of 1661F.
Codeforces Round 946 Solution Discussion