ChatDOJ, Inc. wants to offer a wide range of AI models to free users as well, to broaden the market for AI services and help the public become more familiar with AI. Of course, being able to prominently display the number of free models in the company's advertising materials also played a part.
The problem is that the operating budget for the free-service server cannot be as generous as the advertising budget, so the company must choose carefully which models to offer.
To use a model developed by ChatDOJ, Inc., all of the files that make up that model must be stored on the server. Thanks to the company's outstanding technology, if several models use the same file, that file only needs to be stored once.
A developer reviewed the company's model update history and organized the changes to the file configuration as follows. A file configuration is an ordered list of files and is initially empty.
1 s: Create a new file of size bytes and append it to the file configuration. The new file is distinct from every file created previously.2: Remove the last file from the file configuration. This operation is never performed when the file configuration is empty.3: Register a new model that uses all files in the file configuration. Models are assigned version numbers starting from in registration order. The file configuration remains the same.Changing the file configuration after registering a model does not change the files that make up the registered model. A file removed from the file configuration is still needed to offer any registered model that uses it.
Multiple models may be registered with the same file configuration, and each is counted as a separate model. Neither removing a file nor registering a model is allowed when the file configuration is empty.
After receiving the developer's operation log, the person in charge of the free service decided that announcing availability separately for each model would be a nuisance, and that offering all models created during a particular period would be easier for customers to remember. The models offered for free would therefore be chosen to have consecutive version numbers.
The free-service server can store files with a total size of at most bytes. Find the maximum number of models with consecutive version numbers that can be offered while keeping the total size of the files stored on the server at most bytes.
The first line contains the number of operations and the server's storage capacity , separated by a space.
The next lines give the operations in the order they were performed. Each line has one of the forms 1 s, 2, and 3.
Print the maximum number of models with consecutive version numbers that can be offered within the storage capacity. If no model can be offered, print .
In the first example, number the files from through in creation order. Their sizes are bytes, respectively. Each model requires the following files.
2 and 3 never occur when the file configuration is empty.3 occurs at least once.To offer models through , it is enough to store files . Their total size is bytes, so models can be offered. Offering consecutive models requires bytes for models through , bytes for models through , or bytes for models through . Therefore, the answer is .
In the second example, models and use the same single file. Models and each use a single file that is distinct from that shared file and from each other's file. All three files have size bytes. Offering models through requires bytes, whereas offering all four models requires bytes. The answer is .
In the third example, the only model requires files totaling bytes, so no model can be offered.