output_description: Print x_{N,1}.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      a_1a_2\ldotsa_N
attempt: # -*- coding: utf-8 -*-
  """
  Created on Sat Mar 21 20:58:03 2020
  
  @author: naoki
  """
  
  # f = open("C:/Users/naoki/Desktop/Atcoder/input.txt")
  N = int(input())
  a = list(map(int, list(input())))
  
  flag1 = [-100, -100]
  flag2 = [-100, -100]
  flag3 = [-100, -100]
  
  for i in range(N // 2):
      if a[i] == 2:
          flag1[0] = i
      if a[N - i - 1] == 2:
          flag1[1] = N - i - 1
      if (a[i] == 1 and a[i + 1] == 3) or (a[i] == 3 and a[i + 1] == 1):
          flag2[0] = i
      if (a[N - i - 1] == 1 and a[N - i - 2] == 3) or (
          a[N - i - 1] == 3 and a[N - i - 2] == 1
      ):
          flag2[1] = N - i - 1
  
      if flag1[0] >= 0 and flag1[1] >= 0:
          b = []
          b.extend(a[0 : flag1[0] + 1])
          b.extend(a[flag1[1] :])
          break
      if flag2[0] >= 0 and flag2[1] >= 0:
          b = []
          b.extend(a[0 : flag2[0] + 1])
          b.extend(a[flag2[1] - 1 :])
          break
  else:
      b = a
  last = []
  if b[0] != b[1]:
      last.append(b[0])
  for i in range(len(b) - 1):
      if b[i] != b[i + 1]:
          last.append(b[i + 1])
  
  for i in range(len(last) - 1):
      for p in range(len(last) - i - 1):
          last[p] = abs(last[p + 1] - last[p])
  if len(last) > 0:
      print(last[0])
  else:
      print(0)
  
problem_description: 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}.
samples: [{"input": "4\n    1231", "output": "1\n    \n\nx_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.\n\nx_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.\n\nx_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.\n\nFinally, x_{4,1} = |0-1| = 1, so the answer is 1.\n\n* * *"}, {"input": "10\n    2311312312", "output": "0"}]