##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
3
3 1 5 2
4 1 2 3 4
8 4 1 1 1 14 2 27 4
11
30
189

Sam and AmShZ had always dreamed of Flying to the Moon, but as you might guess, this dream had never come true. When Santa Claus noticed their wish, he tried to help them, but he himself was facing a serious problem delivering gifts all around the world. So Sam and AmShZ decided to help Santa Claus, and in return Santa would fulfill their wish. Now Santa Claus asks Sam and AmShZ to place the gifts into his sleigh to reduce some of his workload. Sam and AmShZ act as follows:
If they receive gifts from Santa with weights , in order to reduce the weight of the sleigh, they discard some of them (possibly none, possibly all) and put the rest into the sleigh. More precisely, they choose a subset of the numbers from to , and the gifts whose indices are in are placed into the sleigh.
They define the complexity of an array of gifts as the smallest non-negative integer such that, for every possible way Sam and AmShZ choose some gifts, sum of weights of gifts inside sleigh is not equal to . they denote this value (complexity of the array) by . (note that sum of weights of an empty set of gifts is 0).
On the other hand, Santa Claus has gifts in his warehouse with weights . but he has not yet decided which ones to give to Sam and AmShZ. However, he is certain that he will choose a contiguous subarray of the gifts.
Now, in order to have an estimate of how difficult the gifts they will receive might be, Sam and AmShZ ask you to compute the sum of the complexities of all contiguous subarrays of the gifts in Santa Claus’s warehouse, and output it modulo .
Actually, you should output following value modulo :
Case 1:
.
(Because Sam and AmShZ can choose empty subset for total weight , and only first gift for total weight , but they can't choose a subset with total weight ).
.
.
.
.
So we have .