All problems

Problem 522

Maximum Number of Balloons

Easy · 10 pts · String, Hash Table, Counting

Problem

You are given a string of lowercase letters. Each letter can be used at most once. Find how many copies of the word balloon you can build from these letters. The word balloon needs one b, one a, two l, two o and one n, so count each letter and take the smallest of count(b), count(a), count(l) / 2, count(o) / 2 and count(n), rounding the halves down.

Input

A single string T of lowercase English letters.

Output

Print the maximum number of times the word balloon can be formed.

Constraints

1 <= |T| <= 100000

Example input

loonbalxballpoon

Example output

2

Explanation

The letters of loonbalxballpoon include b ×2, a ×2, l ×4, o ×4 and n ×2. Each balloon needs b, a, n once and l, o twice, so exactly 2 copies can be built.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Count Binary Substrings Next: Detect Capital