Codeforces Round 464 (Div. 2)
D
Love Rescue
Codeforces
1600
原题
← CE →
翻译中…

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 $(*c*_{1}, *c*_{2})$ (where $*c*_{1}$ and $*c*_{2}$ are some lowercase English letters), which can arbitrary number of times transform a single letter $*c*_{1}$ to $*c*_{2}$ 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

翻译中…

The first line contains a single integer $*n*$ ($1 ≤ *n* ≤ 10^{5}$) — 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

翻译中…

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.

翻译中…

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'.

翻译中…

样例

Input #1
3
abb
dad
Output #1
2
a d
b a
InputCopy OutputCopy
Input #2
8
drpepper
cocacola
Output #2
7
l e
e d
d c
c p
p o
o r
r a
InputCopy OutputCopy
题目信息
题号
939D
时间限制
2 s
内存限制
256 MB
标签
DFS 及类似
并查集
图论
贪心
字符串

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