101954: [AtCoder]ABC195 E - Lucky 7 Battle

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $500$ points

Problem Statement

We have a string $S$ of length $N$ consisting of 0, $\ldots$, 9, and a string $X$ of length $N$ consisting of A and T. Additionally, there is a string $T$, which is initialized to an empty string.

Takahashi and Aoki will play a game using these. The game consists of $N$ rounds. In the $i$-th round $(1\leq i \leq N)$, the following happens:

  • If $X_i$ is A, Aoki does the operation below; if $X_i$ is T, Takahashi does it.
  • Operation: append $S_i$ or 0 at the end of $T$.

After $N$ operations, $T$ will be a string of length $N$ consisting of 0, $\ldots$, 9. If $T$ is a multiple of $7$ as a base-ten number (after removing leading zeros), Takahashi wins; otherwise, Aoki wins.

Determine the winner of the game when the two players play optimally.

Constraints

  • $1 \leq N \leq 2\times 10^5$
  • $S$ and $X$ have a length of $N$ each.
  • $S$ consists of 0, $\ldots$, 9.
  • $X$ consists of A and T.

Input

Input is given from Standard Input in the following format:

$N$
$S$
$X$

Output

If Takahashi wins when the two players play optimally, print Takahashi; if Aoki wins, print Aoki.


Sample Input 1

2
35
AT

Sample Output 1

Takahashi

In the $1$-st round, Aoki appends 3 or 0 at the end of $T$. In the $2$-nd round, Takahashi appends 5 or 0 at the end of $T$.

If Aoki appends 3, Takahashi can append 5 to make $T$ 35, a multiple of $7$.

If Aoki appends 0, Takahashi can append 0 to make $T$ 00, a multiple of $7$.

Thus, Takahashi can always win.


Sample Input 2

5
12345
AAAAT

Sample Output 2

Aoki

Sample Input 3

5
67890
TTTTA

Sample Output 3

Takahashi

Sample Input 4

5
12345
ATATA

Sample Output 4

Aoki

Input

题意翻译

给定长度为 $N$($1 \le N \le 2 \times 10^5$)的字符串 $S$(由数字 $0 \sim 9$ 组成),现在 Takahashi 要和 Aoki 进行 $N$ 轮游戏,第 $i$ 轮游戏可以让数字 $T$(初始时 $T=0$)变成 $10T$ 或 $10T+S_i$。 若游戏结束时 $T$ 是 $7$ 的倍数,则 Takahashi 获胜,否则 Aoki 获胜。 现在给了你字符串 $X$,在第 $i$ 轮时若 $X_i$ 为 $A$ 则由 Aoki 行动,为 $T$ 则由 Takahashi 行动,两人都会按照最优策略行动,问最后谁会获胜。

加入题单

算法标签: