cswork / OAOpen practice workspace

IBMOA #27

Get Final String

Estimated MediumJudge-ready

Topics (AI-labelled)Stacks & HeapsStrings

Repeatedly delete the contiguous substring AWS from the string until no more deletions are possible, and output the remaining string; output -1 if it is empty.

Input

One line containing a string of uppercase English letters, 1≤length≤100000.

Output

Output the final string; output -1 if it is empty.

Example 1

Input:

AWAWSSG

Output:

G

Example 2

Input:

AWS

Output:

-1

Example 3

Input:

XYZ

Output:

XYZ

Example notes

The examples give G, -1 and XYZ respectively.

Editorial

Loading solution…