AtCoder Grand Contest 043
B
123 Triangle
AtCoder
⌀ 1945
原题
← AC →
翻译中…

Problem Statement

翻译中…

Given is a sequence of $N$ digits $a_1a_2\ldots a_N$, where each element is $1$, $2$, or $3$. Let $x_{i,j}$ defined as follows:

翻译中…
  • $x_{1,j} := a_j$ $\quad$ ($1 \leq j \leq N$)
  • $x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} |$ $\quad$ ($2 \leq i \leq N$ and $1 \leq j \leq N+1-i$)
翻译中…

Find $x_{N,1}$.

翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 10^6$
  • $a_i = 1,2,3$ $(1 \leq i \leq N)$
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
a_1a_2\ldotsa_N

翻译中…

Output

翻译中…

Print $x_{N,1}$.

翻译中…

样例

Input #1
4
1231
Output #1
1
$x_{1,1},x_{1,2},x_{1,3},x_{1,4}$ are respectively $1,2,3,1$. $x_{2,1},x_{2,2},x_{2,3}$ are respectively $|1-2| = 1,|2-3| = 1,|3-1| = 2$. $x_{3,1},x_{3,2}$ are respectively $|1-1| = 0,|1-2| = 1$. Finally, $x_{4,1} = |0-1| = 1$, so the answer is $1$.
Input #2
10
2311312312
Output #2
0
题目信息
题号
agc043_b
时间限制
2 s
内存限制
1024 MB

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