#DSU0000043. Phép thuật hòa hợp chữ cái (Love Rescue)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Phép thuật hòa hợp chữ cái (Love Rescue)
Love Rescue
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given two strings and of equal length , consisting only of lowercase English letters. You want the strings to become identical at every position.
You may purchase a kind of spell for a pair of distinct letters . Once purchased, the spell lets you replace any occurrence of a with b, or b with a, in either string, as many times as desired. Several purchased spells may be combined. You pay for the number of distinct letter pairs purchased, not for the number of substitutions performed.
Find the minimum number of spell types needed to make the strings equal. Also output a set of letter pairs achieving that minimum. Any optimal set is accepted by the problem statement.
Input
The first line contains , followed by strings and on the second and third lines.
Output
Print the minimum spell count , then lines each containing two lowercase letters. Any optimal solution is accepted.
Subtasks
- Subtask 1 (20 points): ; ; characters belong to
a–z. - Subtask 2 (30 points): ; ; characters belong to
a–z. - Subtask 3 (50 points): ; ; characters belong to
a–z.
Examples
Input
3
abb
dad
Output
2
a d
b a
Explanation
The spells a d and b a connect the three required letters, so each corresponding position can be made equal.