Score : 700 points
Problem Statement
Given is a sequence of N digits a1a2…aN, where each element is 1, 2, or 3.
Let xi,j defined as follows:
- x1,j:=aj (1≤j≤N)
- xi,j:=∣xi−1,j−xi−1,j+1∣ (2≤i≤N and 1≤j≤N+1−i)
Find xN,1.
Constraints
- 2≤N≤106
- ai=1,2,3 (1≤i≤N)
Input is given from Standard Input in the following format:
N
a1a2…aN
Output
Print xN,1.
4
1231
1
x1,1,x1,2,x1,3,x1,4 are respectively 1,2,3,1.
x2,1,x2,2,x2,3 are respectively ∣1−2∣=1,∣2−3∣=1,∣3−1∣=2.
x3,1,x3,2 are respectively ∣1−1∣=0,∣1−2∣=1.
Finally, x4,1=∣0−1∣=1, so the answer is 1.
10
2311312312
0