class Strings {

    public static String removeFrozenBrackets(String input)
    {
        String unfrozen = FROZEN_PATTERN.matcher(input).replaceAll(String.valueOf(FROZEN_START));
        if (input.length() == unfrozen.length())
        {
            return input; // input is not frozen
        }
        StringBuilder out = new StringBuilder();
        OpenBrackets openBrackets = new OpenBrackets();
        for (char c : unfrozen.toCharArray())
        {
            switch (c)
            {
                case FROZEN_START:
                    openBrackets.addStartBracket();
                    openBrackets.increaseAll();
                    break;
                case '<':
                    openBrackets.increaseAll();
                    out.append(c);
                    break;
                case '>':
                    openBrackets.decreaseAll();
                    if (!openBrackets.removeLastIfClosed())
                    {
                        out.append(c);
                    }
                    break;
                default:
                    out.append(c);
                    break;
            }
        }
        return out.toString();
    }

    private  Strings();

}