#C4341. Calculate Remaining Fuel

    ID: 47869 Type: Default 1000ms 256MiB

Calculate Remaining Fuel

Calculate Remaining Fuel

You are given an initial fuel quantity \(F_0\) and a sequence of events. Each event is represented by a string token: T<amount> for a travel event and R<amount> for a refuel event. In a travel event, if the current fuel is at least amount (i.e. \(fuel \geq amount\)), then the fuel decreases by amount; otherwise, the event is skipped. In a refuel event, the fuel increases by amount.

Your task is to determine the remaining fuel after processing all events.

inputFormat

Input is read from standard input (stdin). The first line contains an integer representing the initial fuel (F_0). The second line contains a string of events separated by spaces.

outputFormat

Output the remaining fuel as an integer on a single line to standard output (stdout).## sample

100
T20 T30 R10 T50
10