#C6960. Minimum Insertions to Form an Anagram

    ID: 50778 Type: Default 1000ms 256MiB

Minimum Insertions to Form an Anagram

Minimum Insertions to Form an Anagram

Given two strings s1 and s2, determine the minimum number of characters that must be inserted into s2 so that it becomes an anagram of s1. In other words, after the insertions, the frequency of every character in s2 should match its frequency in s1.

The task can be formulated mathematically as follows:

$$\text{ans} = \sum_{c \in \text{alphabet}} \max(0, \text{count}_{s1}(c) - \text{count}_{s2}(c))$$

Note: You are only allowed to insert characters into s2. You cannot remove or modify any existing character in s2.

inputFormat

The input consists of two lines:

  • The first line contains the string s1.
  • The second line contains the string s2 (possibly empty).

outputFormat

Output a single integer representing the minimum number of characters that must be inserted into s2 to make it an anagram of s1.

## sample
anagram
manga
2