Variable X with SNAP and ROLLBACK

Python Hard 3 views
Back to Questions

Problem Description

You have one variable x starting at 0. You get q commands: SET v, ADD v, MUL v, SNAP, ROLLBACK. SNAP saves current x. ROLLBACK restores x to the last saved SNAP and removes that SNAP. If there is no SNAP, ROLLBACK does nothing. Output final x.

Input Format

First line q. Next q lines commands.

Output Format

One integer final x.

Sample Test Case

Input:
8 ADD 5 SNAP MUL 3 ADD 2 ROLLBACK ADD 1 ROLLBACK SET 10
Output:
10

Constraints

1

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev