Problem Description

You start with balance 0. Commands: COIN x (add to balance) and BUY p (try to buy item price p). If balance>=p print OK and reduce balance, else print NEED. At end print final balance.

Input Format

First line q. Next q lines: COIN x or BUY p.

Output Format

Outputs for BUY lines, then last line BAL balance.

Sample Test Case

Input:
6 COIN 10 BUY 7 BUY 7 COIN 5 BUY 7 BUY 1
Output:
OK NEED OK OK BAL 0

Constraints

1

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev Next