Codeforces Round 155 (Div. 2)
C
Anagram
Codeforces
1800
原题
← BD →
翻译中…

String $*x*$ is an anagram of string $*y*$, if we can rearrange the letters in string $*x*$ and get exact string $*y*$. For example, strings "DOG" and "GOD" are anagrams, so are strings "BABA" and "AABB", but strings "ABBAC" and "CAABA" are not.

翻译中…

You are given two strings $*s*$ and $*t*$ of the same length, consisting of uppercase English letters. You need to get the anagram of string $*t*$ from string $*s*$. You are permitted to perform the replacing operation: every operation is replacing some character from the string $*s*$ by any other character. Get the anagram of string $*t*$ in the least number of replacing operations. If you can get multiple anagrams of string $*t*$ in the least number of operations, get the lexicographically minimal one.

翻译中…

The lexicographic order of strings is the familiar to us "dictionary" order. Formally, the string $*p*$ of length $*n*$ is lexicographically smaller than string $*q*$ of the same length, if $*p*_{1} = *q*_{1}$, $*p*_{2} = *q*_{2}$, ..., $*p*_{*k* - 1} = *q*_{*k* - 1}$, $*p*_{*k*} < *q*_{*k*}$ for some $*k*$ ($1 ≤ *k* ≤ *n*$). Here characters in the strings are numbered from 1. The characters of the strings are compared in the alphabetic order.

翻译中…

Input

翻译中…

The input consists of two lines. The first line contains string $*s*$, the second line contains string $*t*$. The strings have the same length (from $1$ to $10^{5}$ characters) and consist of uppercase English letters.

翻译中…

Output

翻译中…

In the first line print $*z*$ — the minimum number of replacement operations, needed to get an anagram of string $*t*$ from string $*s*$. In the second line print the lexicographically minimum anagram that could be obtained in $*z*$ operations.

翻译中…

Note

翻译中…

The second sample has eight anagrams of string $*t*$, that can be obtained from string $*s*$ by replacing exactly two letters: "ADBADC", "ADDABC", "CDAABD", "CDBAAD", "CDBADA", "CDDABA", "DDAABC", "DDBAAC". These anagrams are listed in the lexicographical order. The lexicographically minimum anagram is "ADBADC".

翻译中…

样例

Input #1
ABA
CBA
Output #1
1
ABC
InputCopy OutputCopy
Input #2
CDBABC
ADCABD
Output #2
2
ADBADC
InputCopy OutputCopy
题目信息
题号
254C
时间限制
1 s
内存限制
256 MB
标签
贪心
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。