Here are 2 solutions of the same problem: 20274603, 20298628. The only difference between them is two-dimensional array last. In first case it was last[MAXN][MAXQ], and in the second one — last[MAXQ][MAXN]. MAXN = 103 + 7, MAXQ = 105 + 7. I iterated only over that dimension, which has size MAXN. The first code is about 5 times slower. Could anyone please explain why? Thanks in advance.