Codeforces Round 729 (Div. 2)
D
Priority Queue
Codeforces
2200
原题
← CE1 →
翻译中…

You are given a sequence $A$, where its elements are either in the form + x or -, where $x$ is an integer.

翻译中…

For such a sequence $S$ where its elements are either in the form + x or -, define $f(S)$ as follows:

翻译中…
  • iterate through $S$'s elements from the first one to the last one, and maintain a multiset $T$ as you iterate through it.
  • for each element, if it's in the form + x, add $x$ to $T$; otherwise, erase the smallest element from $T$ (if $T$ is empty, do nothing).
  • after iterating through all $S$'s elements, compute the sum of all elements in $T$. $f(S)$ is defined as the sum.
翻译中…

The sequence $b$ is a subsequence of the sequence $a$ if $b$ can be derived from $a$ by removing zero or more elements without changing the order of the remaining elements. For all $A$'s subsequences $B$, compute the sum of $f(B)$, modulo $998\,244\,353$.

翻译中…

Input

翻译中…

The first line contains an integer $n$ ($1\leq n\leq 500$) — the length of $A$.

翻译中…

Each of the next $n$ lines begins with an operator + or -. If the operator is +, then it's followed by an integer $x$ ($1\le x \lt 998\,244\,353$). The $i$-th line of those $n$ lines describes the $i$-th element in $A$.

翻译中…

Output

翻译中…

Print one integer, which is the answer to the problem, modulo $998\,244\,353$.

翻译中…

Note

翻译中…

In the first example, the following are all possible pairs of $B$ and $f(B)$:

翻译中…
  • $B=$ {}, $f(B)=0$.
  • $B=$ {-}, $f(B)=0$.
  • $B=$ {+ 1, -}, $f(B)=0$.
  • $B=$ {-, + 1, -}, $f(B)=0$.
  • $B=$ {+ 2, -}, $f(B)=0$.
  • $B=$ {-, + 2, -}, $f(B)=0$.
  • $B=$ {-}, $f(B)=0$.
  • $B=$ {-, -}, $f(B)=0$.
  • $B=$ {+ 1, + 2}, $f(B)=3$.
  • $B=$ {+ 1, + 2, -}, $f(B)=2$.
  • $B=$ {-, + 1, + 2}, $f(B)=3$.
  • $B=$ {-, + 1, + 2, -}, $f(B)=2$.
  • $B=$ {-, + 1}, $f(B)=1$.
  • $B=$ {+ 1}, $f(B)=1$.
  • $B=$ {-, + 2}, $f(B)=2$.
  • $B=$ {+ 2}, $f(B)=2$.
翻译中…

The sum of these values is $16$.

翻译中…

样例

Input #1
4
-
+ 1
+ 2
-
Output #1
16
InputCopy OutputCopy
Input #2
15
+ 2432543
-
+ 4567886
+ 65638788
-
+ 578943
-
-
+ 62356680
-
+ 711111
-
+ 998244352
-
-
Output #2
750759115
InputCopy OutputCopy
题目信息
题号
1542D
时间限制
3 s
内存限制
512 MB
标签
组合数学
动态规划
模拟
数学
三分

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。