#K82312. Longest Balanced Subsequence

    ID: 35948 Type: Default 1000ms 256MiB

Longest Balanced Subsequence

Longest Balanced Subsequence

You are given a string s consisting only of the characters a and b. A subsequence is considered balanced if it contains an equal number of a's and b's. Your task is to determine and output the length of the longest balanced subsequence that can be extracted from s.

Note that a subsequence is a sequence that can be derived from the string by removing zero or more characters without changing the order of the remaining characters. The length of the longest balanced subsequence can be computed using the formula:

$$ L = 2 \times \min(\text{count}_a,\; \text{count}_b) $$

where count_a and count_b are the number of a's and b's in the string, respectively.

inputFormat

The input consists of a single line containing the string s composed only of the characters a and b. The input should be read from standard input (stdin).

outputFormat

Output a single integer representing the length of the longest balanced subsequence, printed to standard output (stdout).

## sample
abba
4