#P14600. [NWRRC 2025] Asynchronous Processor

[NWRRC 2025] Asynchronous Processor

题目描述

You are given a program consisting of nn instructions executed by a processor with a single integer register AA, initially equal to 00. Each instruction is one of two types:

  • + v\texttt{+ v} --- performs A:=A+vA := A + v;
  • = v\texttt{= v} --- performs A:=vA := v.

The instructions in the program are numbered from 11 to nn. Each instruction ii initially has timestamp ii.

Some instructions are marked as asynchronous\textit{asynchronous}. If instruction ii is asynchronous, its timestamp can be changed to any real\textbf{real} number greater than ii.

After all timestamp adjustments, all timestamps must be distinct. The processor then executes the instructions in order of increasing timestamp.

Determine the number of distinct final values of AA that can be obtained after all instructions have been executed, considering all possible choices of asynchronous instruction timestamps.

输入格式

The first line contains an integer nn, denoting the number of instructions in the program (1n20001 \le n \le 2000).

The ii-th of the following nn lines describes instruction ii and contains three tokens. The first token is either +\texttt{+} or =\texttt{=}, denoting the type of the instruction. The second token is an integer vv, denoting the argument of the instruction (1v5001 \le v \le 500). Finally, the third token is either async\texttt{async} if the instruction is marked as asynchronous, or sync\texttt{sync} otherwise.

输出格式

Print the number of distinct final values AA can take after executing the program.


2

30

提示

In the first test, the program execution starts with instruction 11 setting AA to 11. Then, instructions 22 and 33 are executed in one of the two orders:

  • if = 2\texttt{= 2} is executed before + 3\texttt{+ 3}, AA will be equal to 55;
  • if + 3\texttt{+ 3} is executed before = 2\texttt{= 2}, AA will be equal to 22.

Thus, there are two possible values of AA at the end: 55 and 22.