#P1912K. Kim's Quest

Kim's Quest

Description

In the long-forgotten halls of Kombinatoria's ancient academy, a gifted mathematician named Kim is faced with an unusual challenge. They found an old sequence of integers, which is believed to be a cryptic message from the legendary Kombinatoria's Oracle, and Kim wants to decipher its hidden meaning.

Kim's mission is to find specific patterns within the sequence, known as Harmonious Subsequences. These are extraordinary subsequences where the sum of every three consecutive numbers is even, and each subsequence must be at least three numbers in length.

Given a sequence aia_i (1in1 \le i \le n) of length nn, its subsequence of length mm is equal to ab1,ab2,,abma_{b_1}, a_{b_2}, \ldots, a_{b_m} and is uniquely defined by a set of mm indices bjb_j, such that 1b1<b2<<bmn1 \le b_1 < b_2 < \ldots < b_m \le n. Subsequences given by different sets of indices bjb_j are considered different.

There's a twist in Kim's quest: the number of these Harmonious Subsequences could be overwhelming. To report the findings effectively, Kim must calculate the total number of these subsequences, presenting the answer as a remainder after dividing by the number 998244353998\,244\,353.

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

The second line contains nn space-separated integers aia_i — the elements of the sequence (1ai21051 \le a_i \le 2 \cdot 10^5).

Output one number — the number of Harmonious Subsequences, modulo 998244353998\,244\,353.

Input

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

The second line contains nn space-separated integers aia_i — the elements of the sequence (1ai21051 \le a_i \le 2 \cdot 10^5).

Output

Output one number — the number of Harmonious Subsequences, modulo 998244353998\,244\,353.

样例输入 1

3
1 2 3

样例输出 1

1

样例输入 2

5
2 8 2 6 4

样例输出 2

16

样例输入 3

5
5 7 1 3 5

样例输出 3

0

样例输入 4

11
3 1 4 1 5 9 2 6 5 3 6

样例输出 4

386

样例输入 5

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

样例输出 5

0

Note

In the provided input data for the fifth sample, the sequence of numbers is split into three separate lines for clarity, but it should be understood that in the actual test data, the sequence is given in one line. The actual number of Harmonious Subsequences in this example is 4991221765=5×9982443534\,991\,221\,765 = 5 \times 998\,244\,353, hence the output is zero as a result of finding its remainder after dividing by the number 998244353998\,244\,353.