Score : 600 points
You are given N integers. The i-th integer is a_i. Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied:
Input is given from Standard Input in the following format:
N a_1 : a_N
Print the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied.
4 1 1 1 2
18
We can only paint the integers so that the lengths of the sides of the triangle will be 1, 2 and 2, and there are 18 such ways.
6 1 3 2 3 5 2
150
20 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4
563038556