Kim’s Quest

시간 제한3초메모리 제한2048 MB

요약
길이가 3 이상인 부분수열 중 연속한 세 원소의 합이 항상 짝수인 것의 개수를 998244353으로 나눈 나머지를 구한다.
난이도

보통10점 중 5점

유형
동적 계획법, 조합론, 수학
정답자
아직 제출이 없습니다

문제

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 a_ia\_i (1≤i≤n1 \le i \le n) of length nn, its subsequence of length mm is equal to a_b_1,a_b_2,…,a_b_ma\_{b\_1}, a\_{b\_2}, \ldots, a\_{b\_m} and is uniquely defined by a set of mm indices b_jb\_j, such that 1≤b_1<b_2<…<b_m≤n1 \le b\_1 < b\_2 < \ldots < b\_m \le n. Subsequences given by different sets of indices b_jb\_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 998,244,353998\\,244\\,353.

입력

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 a_ia\_i --- the elements of the sequence (1≤a_i≤2⋅1051 \le a\_i \le 2 \cdot 10^5).

출력

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

힌트

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 4,991,221,765=5×998,244,3534\\,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 998,244,353998\\,244\\,353.

예제5

  1. 예제 1

    입력
    3
    1 2 3
    
    예상 출력
    1
    
  2. 예제 2

    입력
    5
    2 8 2 6 4
    
    예상 출력
    16
    
  3. 예제 3

    입력
    5
    5 7 1 3 5
    
    예상 출력
    0
    
  4. 예제 4

    입력
    11
    3 1 4 1 5 9 2 6 5 3 6
    
    예상 출력
    386
    
  5. 예제 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
    
    예상 출력
    0