Kim's Quest
InterviewTime limit3sMemory limit2048 MB
Count the subsequences of length at least 3 in which every three consecutive elements have an even sum, modulo 998244353.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Math
- Solved
- No attempts yet
Problem
In the long-forgotten halls of Kombinatoria's ancient academy, a gifted mathematician named Kim faces an unusual challenge. Kim found an old sequence of integers, believed to be a cryptic message from the legendary Kombinatoria's Oracle, and wants to decipher its hidden meaning.
Kim's mission is to find specific patterns within the sequence, called Harmonious Subsequences. A Harmonious Subsequence is one in which the sum of every three consecutive numbers is even, and it has at least three numbers.
Given a sequence () of length , a subsequence of length is , uniquely defined by a set of indices with . Subsequences given by different index sets are considered different.
The number of these subsequences can be very large. Kim must report the total number of Harmonious Subsequences modulo .
Input
The first line contains a single integer , the length of the sequence ().
The second line contains space-separated integers , the elements of the sequence ().
Output
Output one number, the number of Harmonious Subsequences modulo .
Hint
In the statement's fifth sample, the sequence is split across three lines for readability, but in the actual test data it is given on one line. The actual number of Harmonious Subsequences there is , so the output is zero after taking the remainder modulo .