QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 512 MB مجموع النقاط: 100

#9629. Little C's Mysterious Figure

الإحصائيات

For a positive integer $n$, a $3^n \times 3^n$ 01-matrix $A_n$ is defined as follows: If $3^{n-1} \le i < 2 \times 3^{n-1}$ or $3^{n-1} \le j < 2 \times 3^{n-1}$, then $$A_n(i, j) = \begin{cases} 1, & n = 1 \\ A_{n-1}(i \bmod 3^{n-1}, j \bmod 3^{n-1}), & n \ge 2 \end{cases}$$ where $x \bmod y$ denotes the remainder of $x$ divided by $y$. Otherwise, $A_n(i, j) = 0$.

Here, $A_n(i, j)$ denotes the element in the $i$-th row and $j$-th column of matrix $A_n$, with both row and column indices starting from 0.

Given a positive integer $n$, Little C has two digit strings of length $n$, where each digit is one of $0, 1, 2$, representing two ternary numbers $n_1, n_2$ (which may contain leading zeros). You need to help Little C find the value of $A_n(n_1, n_2)$.

Input

The first line contains a positive integer $n$ ($1 \le n \le 10^5$). The next two lines each contain a digit string of length $n$, representing the ternary numbers $n_1$ and $n_2$, respectively.

Output

Output a single integer representing the value of $A_n(n_1, n_2)$.

Examples

Input 1

2
20
01

Output 1

0

Note 1

In fact, for $n=2$: $$A_2 = \begin{pmatrix} 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 1 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 1 & 0 & 0 & 1 & 0 \\ 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\ 0 & 1 & 0 & 0 & 1 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 1 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \end{pmatrix}$$ The input digit strings correspond to $n_1 = 6$ and $n_2 = 1$, thus $A_2(n_1, n_2) = 0$.

Input 2

3
102
011

Output 2

1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.