logo AlgoBeat OnlineJudge
登录 注册

#212507. [NERC2023] Kim's Quest

内存限制:1024 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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 () of length , its subsequence of length is equal to and is uniquely defined by a set of indices , such that . Subsequences given by different sets of indices 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 .

输入格式

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 one number --- the number of Harmonious Subsequences, modulo .

样例

样例输入 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

数据范围与提示

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 , hence the output is zero as a result of finding its remainder after dividing by the number .