Under construction

Still being built. Things may change

Kim's Quest

Interview

Time limit3sMemory limit2048 MB

Summary
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 aia_i (1≤i≤n1 \le i \le n) of length nn, a subsequence of length mm is ab1,ab2,…,abma_{b_1}, a_{b_2}, \ldots, a_{b_m}, uniquely defined by a set of mm indices bjb_j with 1≤b1<b2<…<bm≤n1 \le b_1 < b_2 < \ldots < b_m \le n. 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 998 244 353998\,244\,353.

Input

The first line contains a single integer nn, the length of the sequence (3≤n≤2⋅1053 \le n \le 2 \cdot 10^5).

The second line contains nn space-separated integers aia_i, the elements of the sequence (1≤ai≤2⋅1051 \le a_i \le 2 \cdot 10^5).

Output

Output one number, the number of Harmonious Subsequences modulo 998 244 353998\,244\,353.

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 4 991 221 765=5×998 244 3534\,991\,221\,765 = 5 \times 998\,244\,353, so the output is zero after taking the remainder modulo 998 244 353998\,244\,353.

Examples5

  1. Example 1

    Input
    3
    1 2 3
    
    Expected output
    1
    
  2. Example 2

    Input
    5
    2 8 2 6 4
    
    Expected output
    16
    
  3. Example 3

    Input
    5
    5 7 1 3 5
    
    Expected output
    0
    
  4. Example 4

    Input
    11
    3 1 4 1 5 9 2 6 5 3 6
    
    Expected output
    386
    
  5. Example 5

    Input
    54
    2 1 1 1 1 2 1 2 2 2 2 1 1 1 2 1 1 2 2 1 2 2 2 2 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 1 2 2 2 2 2 1 1 1 2 2 1 2 1 1
    
    Expected output
    0