I don't get the output for IDXSUM

Hello, as the title says, I don’t understand the expected output for the IDXSUM problem.

Let’s focus on the second test case from the example.
For M = 3, N = 5, P = “nan”, we are supposed to get S0 = 555099525.

With my code, I get S0 = 152974748, so I wrote a bruteforce code in an attempt to debug.
As I understand it, S0 is the sum of indices of all 5-letter strings that do not end with ‘n’, mod 998,244,353.
So I wrote the following:

int numStrings = 11881376; // 26^5
int res = 0;
char lastLetter = 'a';
for(int i = 0; i < numStrings; ++i)
{
	if(lastLetter != 'n')
		res = (res + i) % 998244353;

	if(lastLetter == 'z')
		lastLetter = 'a';
	else
		++lastLetter;
}
cerr << res << endl;

The output is 152974748.

Am I misunderstanding something in the problem statement?

See the problem clearly, according to your understanding, strings like "???na" are not calculate, here "?" refers to any lowercase letter.
So look at the problem description again and you’ll see what I’m talking about.

1 Like

Right, for some reason I was reversing the pattern’s prefix when looking for it as a suffix… I can’t believe I didn’t realize that before. :smile:
Thanks for the help, it was driving me crazy!