cswork / OAOpen practice workspace

Goldman SachsOA #24

Chairs Requirement

Estimated EasyJudge-ready

Topics (AI-labelled)Simulation

Given several simulations of employees coming and going, find the minimum number of chairs that must be bought for each simulation. Initially there are no chairs; employees always use an empty chair first, and one chair is bought whenever no empty chair is available. C means a new employee enters, R means an employee temporarily goes to the meeting room, U means an employee returns from the meeting room, and L means an employee leaves permanently. Added by this site: every simulation is a valid event sequence; when R/L is performed, at least one employee is in the office, and when U is performed, at least one employee is in the meeting room. Employees are not distinguished; only the headcount states above need to be respected.

The problem meaning, function, and constraints are the same as in the original Goldman Sachs #24 statement. The guarantee that every simulation sequence is valid is an input guarantee added by this site to make the output unique, not a condition stated in the original.

Input

The first line contains n; each of the next n lines contains one simulation string consisting only of C, R, U, L. 1≤n≤100, 1≤length of each string≤10000.

Output

Output n integers in input order, separated by spaces; each is the minimum number of chairs to buy for that simulation.

Example 1

Input:

1
C

Output:

1

Example 2

Input:

1
CCCRLCC

Output:

3

Example 3

Input:

1
CCRRCRUU

Output:

2

Editorial

Loading solution…