Obviously there was a problem with the test cases or something of the KTH97 problem from October Lunchtime. However, there’s a much more fundamental problem as well.
According to the editorial, the solution for this problem is based on FFT (Fast Fourier Transform)
According to the problem setting guidelines, the problems for Lunchtime contest are supposed to be “strictly restricted to IOI syllabus”. However, according to section 5.3 of the IOI syllabus, FFT is strictly excluded from it.