Eating Pringles


Submit solution

Points: 1
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Alan loves Pringles. He has a machine that dispenses Pringles one by one into a infinite capacity Pringle tube. The machine has unlimited Pringles of the following flavours:

  • Original (O)
  • Salt & Vinegar (V)
  • Chicken Salt (C)
  • Sour Cream & Onion (S)
  • Chicago Style Deep Dish Pizza (P)

Alan can eats Pringles from the top of the tube in batches of 1 - 9 at a time. He's interested in recording the flavour of the last Pringle he eats in each batch since that's the taste that lingers.

Note: Sometimes Alan wants to eat more Pringles than there are in the tube. In those cases, he is smart enough to stop at the last Pringle and not eat through the bottom of the tube.

Input Specification

The first line contains a single integer \(L\).

The second line contains a string of length \(L\). Each character is either a flavour of Pringle (O, V, C, S or P) dispensed into the tube, or a digit 1 - 9 representing a batch of Pringles Alan wishes to eat.

Output Specification

A string on a single line consisting of the last flavour of each batch of Pringles Alan eats.

Note: For a given batch, only output the last flavour if \(\ge 1\) Pringle(s) were eaten.

Bounds

This problem has two test sets. The first is the sample cases, the second has the following bounds:

  • \( 1\le L \le 10^6\)

Sample Case 1

Input
4
OCV2
Output
C

Sample Case 2

Input
6
PPS1V2
Output
SP

Sample Case 3

Input
10
S3POCV2SP3
Output
SCO

Explanations

  • Sample Case 1: Flavours O -> C -> V are dispensed and then Alan eats 2 from the top (V and C). The last flavour is hence C.
  • Sample Case 2: Flavour S is eaten for the first batch. For the second batch, the flavours V and then P are eaten (remember S was eaten so cannot be reaten).
  • Sample Case 3: For the first batch, Alan only eats the flavour S Pringle despite wanting to eat 3.

Comments

There are no comments at the moment.