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

#DSU0000046. Gán chữ cái thành chữ số (Digit Assignment)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Gán chữ cái thành chữ số (Digit Assignment)

Digit Assignment

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Two records describe the same positive integer containing exactly nn digits. Each record is a string of length nn containing digits 0–9 and uppercase letters A–Z representing unreadable digits.

Assign a digit from 00 to 99 to each letter that appears. Every occurrence of the same letter, in either record, must receive the same digit. Different letters may receive the same digit. Existing numerical characters must remain unchanged.

After replacement, the two records must become exactly the same digit string, and the first digit must not be 0 so that it represents an nn-digit positive integer. At least one valid assignment is guaranteed. Count the number of distinct integers obtainable, not the number of letter assignments when several assignments produce the same integer.

Input

Line 1 contains nn; lines 2 and 3 contain s1,s2s_1,s_2, each of length nn, using only 0–9 and A–Z.

Output

Print the count of valid nn-digit positive integers. The result may exceed 32-bit integers.

Subtasks

  • Subtask 1 (20 points): 1≤n≤31\le n\le3; ∣s1∣=∣s2∣=n|s_1|=|s_2|=n; characters belong to 0–9 or A–Z; at least one valid assignment exists.
  • Subtask 2 (30 points): 1≤n≤91\le n\le9; ∣s1∣=∣s2∣=n|s_1|=|s_2|=n; characters belong to 0–9 or A–Z; at least one valid assignment exists.
  • Subtask 3 (50 points): 1≤n≤181\le n\le18; ∣s1∣=∣s2∣=n|s_1|=|s_2|=n; characters belong to 0–9 or A–Z; at least one valid assignment exists.

Examples

Input

3
XXX
YYY

Output

9

Explanation

Letters X and Y must represent the same digit, which cannot be zero in the first position: 9 possibilities.