#P10442. Maximized Equal Anagram

    ID: 12451 Type: Default 1000ms 256MiB

Maximized Equal Anagram

Maximized Equal Anagram

Given two strings s and t, you are allowed to delete some characters from both strings and then reorder the remaining characters arbitrarily such that after processing, s becomes equal to t. Your task is to find the maximum possible length of the string s after these operations.

You can prove that the answer is given by:

$$\sum_{c}\min(\text{freq}_s(c),\; \text{freq}_t(c))$$

where freqs(c) and freqt(c) denote the frequency of the character c in s and t respectively.

inputFormat

The input consists of two lines. The first line contains the string s, and the second line contains the string t.

outputFormat

Output a single integer representing the maximum possible length of the string s (which is equal to the length of t) after performing the allowed operations.

sample

abc
bcd
2