#K66172. Counting Rainbow Subsequences

    ID: 32362 Type: Default 1000ms 256MiB

Counting Rainbow Subsequences

Counting Rainbow Subsequences

You are given a string s consisting of uppercase letters that represent colored beads. Each bead is one of the seven colors in the sequence \( R\,O\,Y\,G\,B\,I\,V \). Your task is to determine the maximum number of subsequences that can be extracted from s, where each subsequence exactly matches the pattern ROYGBIV in order.

A subsequence is a sequence that can be derived from the original string by removing some or no characters without changing the order of the remaining characters. Note that the characters forming one subsequence do not need to be contiguous in the original string.

Input Constraints: The input string will contain only the characters R, O, Y, G, B, I, and V, and its length can be assumed to be positive.

inputFormat

The input is read from standard input. It contains a single line:

  1. A string s representing the sequence of colored beads.

outputFormat

Output a single integer: the maximum number of subsequences forming the pattern ROYGBIV that can be extracted from the input string, printed to standard output.

## sample
ROYGBIVROYGBIV
2