Equal Adjacent Elements

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

Hello sir, I am very interested in coding.. But I am not able to get the solution to a problem. Can you help me??

An array of integers is bad if it contains a pair of equal adjacent elements. An array is good if it is not bad.

You are given a good array. How many ways are there to remove its elements one by one, concatenating the left and right part after each removal, such that at no point the array is bad? Two ways are different if there is a step on which indices of removed elements differ.

For example, after the removal of 11 from a good array \[2,1,2]\[2, 1, 2] it becomes a bad array \[2,2]\[2, 2] and after the removal of 55 from a good array \[1,2,3,4,5,6]\[1, 2, 3, 4, 5, 6] it becomes \[1,2,3,4,6]\[1, 2, 3, 4, 6] and stays good.

Output the answer congruent to the real one modulo 998244353. Formally, if the real answer is yy and your answer is xx, it will be considered correct if 263x<263-2^{63} \leq x < 2^{63} and xyx-y is divisible by 998244353.

입력

The first line contains a single integer nn (1n5001 \leq n \leq 500), the number of elements in the array.

The second line contains nn integers a_ia\_i (1a_in1 \leq a\_i \leq n), elements of the array.

출력

Output a single integer --- the answer to the problem modulo 998244353.

힌트

In the first example all elements are distinct, so it's impossible to get a bad array at some point. That's why there are 3!=63! = 6 ways to remove all the elements.

In the fourth example the real answer is 11 because there is only one way to remove the only element. The given answer 998244352-998244352 is congruent to 11 modulo 998244353, so it is correct too.

In the fifth example the real answer is 22.

Sorry for my bad English.