← Home
write a go solution for K. Kim's Questtime limit per test3 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputIn 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_i (1<=i<=n) of length n, its subsequence of length m is equal to a_b_1,a_b_2,ldots,a_b_m and is uniquely defined by a set of m indices b_j, such that 1<=b_1<b_2<ldots<b_m<=n. Subsequences given by different sets of indices b_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,353.InputThe first line contains a single integer n — the length of the sequence (3<=n<=2*10^5).The second line contains n space-separated integers a_i — the elements of the sequence (1<=a_i<=2*10^5).OutputOutput one number — the number of Harmonious Subsequences, modulo 998,244,353.ExamplesInput31 2 3Output1
Input52 8 2 6 4Output16
Input55 7 1 3 5Output0
Input113 1 4 1 5 9 2 6 5 3 6Output386
Input54
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
Output0
NoteIn 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=5x998,244,353, hence the output is zero as a result of finding its remainder after dividing by the number 998,244,353.. Output only the code with no comments, explanation, or additional text.