Problem Statement
Given is a sequence of N digits a1a2ldotsaN, where each element is 1, 2, or 3. Let xi,j defined as follows:
- x1,j:=aj quad (1leqjleqN)
- xi,j:=∣xi−1,j−xi−1,j+1∣ quad (2leqileqN and 1leqjleqN+1−i)
Find xN,1.
Constraints
- 2leqNleq106
- ai=1,2,3 (1leqileqN)
Input is given from Standard Input in the following format:
N
a1a2ldotsaN
Output
Print xN,1.
4
1231
Sample Output 1
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
Sample Output 2
0