PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000043. Phép thuật hòa hợp chữ cái (Love Rescue)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 ss and tt of equal length nn, 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 (a,b)(a,b). 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 nn, followed by strings ss and tt on the second and third lines.

Output

Print the minimum spell count kk, then kk lines each containing two lowercase letters. Any optimal solution is accepted.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20; ∣s∣=∣t∣=n|s|=|t|=n; characters belong to a–z.
  • Subtask 2 (30 points): 1≤n≤30001\le n\le3000; ∣s∣=∣t∣=n|s|=|t|=n; characters belong to a–z.
  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; ∣s∣=∣t∣=n|s|=|t|=n; 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.