#P6796. 「StOI-2」好多表达式

「StOI-2」好多表达式

Background

This problem is the first problem of the second open contest of StOI, StOI Round2.

Note: If this number has multiple digits, it will not be split apart. By LHQing, 14:09.

:)

Problem Description

Given an expression consisting only of digits, +, and *, find the sum of the values of all its subexpressions, modulo 998,244,353998,244,353.

A subexpression of an expression is defined as an expression formed by a consecutive segment of numbers and the operators between them.

If you still cannot understand, you can refer to the sample explanation.

Input Format

The first line contains a positive integer nn, which denotes the number of numbers in the expression.

The next line contains the expression consisting of nn positive integers and n1n - 1 operators, with spaces between numbers and operators.

Output Format

Output one number, which is the final answer.

3
1 + 2 * 3
22
6
1 * 1 * 4 * 5 * 1 * 4
414
3
16 + 750 + 7
3069

Hint

Sample Explanation

The given expression has a total of six subexpressions: 11, 22, 33, 1+21+2, 2×32 \times 3, 1+2×31+2 \times 3. Their values are 11, 22, 33, 33, 66, 77, and the sum is 2222.


Constraints

For 20%20\% of the testdata: 1n10001 \leq n \leq 1000.
For another 20%20\% of the testdata: there is no +.
For another 20%20\% of the testdata: there is only one +.
For another 20%20\% of the testdata: there is only one *.
For 100%100\% of the testdata: 1n1051 \leq n \leq 10^{5}, all numbers are at most 10910^{9}, and the operators only include + and *.

Output Format

Translated by ChatGPT 5