Love Rescue
Contest: Codeforces Round 464 (Div. 2)
Difficulty rating: 1600
Tags: dfs and similar, dsu, graphs, greedy, strings

Valya and Tolya are an ideal pair, but they quarrel sometimes. Recently, Valya took offense at her boyfriend because he came to her in t-shirt with lettering that differs from lettering on her pullover. Now she doesn't want to see him and Tolya is seating at his room and crying at her photos all day long.

This story could be very sad but fairy godmother (Tolya's grandmother) decided to help them and restore their relationship. She secretly took Tolya's t-shirt and Valya's pullover and wants to make the letterings on them same. In order to do this, for one unit of mana she can buy a spell that can change some letters on the clothes. Your task is calculate the minimum amount of mana that Tolya's grandmother should spend to rescue love of Tolya and Valya.

More formally, letterings on Tolya's t-shirt and Valya's pullover are two strings with same length n consisting only of lowercase English letters. Using one unit of mana, grandmother can buy a spell of form (c1, c2) (where c1 and c2 are some lowercase English letters), which can arbitrary number of times transform a single letter c1 to c2 and vise-versa on both Tolya's t-shirt and Valya's pullover. You should find the minimum amount of mana that grandmother should spend to buy a set of spells that can make the letterings equal. In addition you should output the required set of spells.

Input format:
The first line contains a single integer n (1 ≤ n ≤ 105) — the length of the letterings.

The second line contains a string with length n, consisting of lowercase English letters — the lettering on Valya's pullover.

The third line contains the lettering on Tolya's t-shirt in the same format.

Output format:
In the first line output a single integer — the minimum amount of mana t required for rescuing love of Valya and Tolya.

In the next t lines output pairs of space-separated lowercase English letters — spells that Tolya's grandmother should buy. Spells and letters in spells can be printed in any order.

If there are many optimal answers, output any.

Constraints:
Time limit: 2.0 s
Memory limit: 256.0 MB

Note:
In first example it's enough to buy two spells: ('a','d') and ('b','a'). Then first letters will coincide when we will replace letter 'a' with 'd'. Second letters will coincide when we will replace 'b' with 'a'. Third letters will coincide when we will at first replace 'b' with 'a' and then 'a' with 'd'.

Example input:
3
abb
dad

Example output:
2
a d
b a

Example input:
8
drpepper
cocacola

Example output:
7
l e
e d
d c
c p
p o
o r
r a

Editorial:
Let's build a graph with 26 vertices representing the 26 letters of English alphabet. When we buy a spell of form (c1, c2), add an edge between vertices c1 and c2. It's easy to see, that it is possible to change a letter a to a letter b if and only if there is a path between corresponding vertices in the graph. So our task is to add the minimum possible number of edges such that characters s1[i] and s2[i] are in one connected component for each i (here s1 and s2 are the given strings).
Let's now take an empty graph and add edges between vertices s1[i] and s2[i] for each i. These edges, as we already know, add constraints on the final graph (these letters should be in a single connected component in the final graph). Let's compute the number of connected components in the graph — let it be k. Let's consider one connected component, let its size be xi. Note that the spell we should buy should connect all these vertices in a single component. We can do this using at least xi - 1 edges, and the edges that suit us are any spanning tree of this component, that can be found using a dfs, or just connect one vertex of this component to all the others. So the total number of spells is $$\sum_{i=1}^{k}(x_i-1)=\sum_{i=1}^{k}x_i-k=n-k$$. This is the answer to the problem.