Problem:


Score : 700 points

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}.

Sample Input 1

4
1231

Sample 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.

Sample Input 2

10
2311312312

Sample Output 2

0



Sample input:
4
1231


Sample output:
1

Submission status: Wrong Answer

Solution code:
n=int(input(''))
m=input('')
s=[]
for a in range(n):
    s.append(int(m[a]))


kuri=n-1
for a in range(n-1):
    kake=1
    for b in range(kuri):
        if s[b]==0 or s[b]==1:
            kake=kake*1
        else:
            kake=kake*0
            break
    if kake==0:
        for b in range(kuri):
            if s[b]==s[b+1]:
                s[b]=0
            elif s[b]*s[b+1]==2:
                s[b]=1
            elif s[b]*s[b+1]==3:
                s[b]=2
            elif s[b]*s[b+1]==6:
                s[b]=1
            else:
                if s[b]==0:
                    s[b]=s[b+1]

    
            kuri=kuri-1
    else:
        ki=0
        for b in range(kuri):
            if s[b]%2==1:
                ki=ki+1
    
        if ki%2==1:
            s[0]=1
        else:
            s[0]=0
        break

    if kake==1:
        break

print(s[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
aa = list(map(lambda x: int(x)-1, list(input())))

def parity(n, r):
    # parity of n choose r
    # via https://math.stackexchange.com/questions/233269/odd-and-even-numbers-in-pascals-triangle-sierpinskis-triangle
    if n <= 1:
        return 1
    if r == 1:
        return n % 2
    if r == 0:
        return 1
    if n % 2 == 0 and r % 2 != 0:
        return 0
    return parity(n//2, r//2)

def ab(x):
    if x < 0:
        return -x
    return x

if n == 2:
    print(ab(aa[0]-aa[1]))
else:
    aa = [ab(aa[i]-aa[i+1]) for i in range(n-1)][:n-1]
    n -= 1
    ans = 0

    for i, a in enumerate(aa):
        p = parity(n-1, i)
        if p == 1:
            ans = ab(ans - a)
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = input()

if '2' in As:
    print(1)
else:
    print(2)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, list(input().strip())))

tri = []
t = []
for i in range(N):
    if i == 0:
        t.append(A[i])
    elif A[i] != A[i-1]:
        t.append(A[i])
if len(set(t)) == 1:
    print(0)
    exit()
tri.append(t)

while len(tri[-1]) > 1:
    nx = []
    nx2 = []
    nw = tri[-1]
    for j in range(1,len(nw)):
        _abs = abs(nw[j]-nw[j-1])
        if j == 1:
            nx.append(_abs)
            nx2.append(_abs)
        else:
            nx2.append(_abs)
            if nx[-1] != _abs:
                nx.append(_abs)
    if len(nx2) > 1 and len(set(nx)) == 1:
        print(0)
        exit()
    tri.append(nx)

if tri[-1] == []:
    print(0)
else:
    if len(tri[-1]) == 2:
        print(tri[-1][0]-tri[-1][1])
    else:
        print(tri[-1][0])

Submission status: Wrong Answer

Solution code:
def examA():
    def bfs_grid(h, w, s, maze):
        distance = [[inf] * w for _ in range(h)]

        def bfsg():
            queue = deque()
            if maze[s[0]][s[1]]=="#":
                queue.append((s, 1))
                distance[s[0]][s[1]] = 1
            else:
                queue.append((s,0))
                distance[s[0]][s[1]] = 0
            while len(queue):
                [y, x],st = queue.popleft()
                for i in range(2):
                    nx, ny = x + [1, 0][i], y + [0, 1][i]
                    if (0 <= nx < w and 0 <= ny < h):
                        cur = deepcopy(distance[y][x])
                        if st==0 and maze[ny][nx]=='#':
                            cur += 1
                        if distance[ny][nx] <= cur:
                            continue
                        if maze[ny][nx]=='#':
                            queue.append(((ny, nx),1))
                        else:
                            queue.append(((ny, nx), 0))
                        distance[ny][nx] = cur
            return distance

        return bfsg()
    H, W = LI()
    S = [SI()for _ in range(H)]
    L = bfs_grid(H,W,[0,0],S)
    ans = L[-1][-1]
    #print(L)
    print(ans)
    return

def examB():
    def judge(a,b):
        if a%2==0 and b%2==1:
            return 0
        if a==0 and b==0:
            return 1
        return judge(a//2,b//2)
    N = I()
    A = SI()
    if A[0]=="3":
        flag = True
        for s in A[1:]:
            if s!="1":
                flag = False
                break
        if flag:
            print(2)
            return
    if A[-1]=="3":
        flag = True
        for s in A[:N-2]:
            if s!="1":
                flag = False
                break
        if flag:
            print(2)
            return
    S = [0]*(N-1)
    for i in range(N-1):
        S[i] = abs(int(A[i])-int(A[i+1]))
    #print(S)
    cur = S[0]
    for i,s in enumerate(S[1:],start=1):
        if s==1 and judge(N-2,i)==1:
            cur ^= 1
        #print(cur)
    if cur==1:
        print(1)
    else:
        print(0)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examB()

"""

"""

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import numpy as np

n = ni()
a = list(map(int, list(ns())))
#n = 10**5
#a = [2]*(10**5)

if n > 1000:
    #a = a[:1000]
    #n = 1000
    print(0)
    exit()

b = np.array(a)

for i in range(n-1):
    b = np.abs(b[1:]-b[:-1])

print(b[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
As = input()

if '2' in As:
    print(0)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(str(input()))
b=list(reversed(a))

l=len(a)
if a[0:l//2]==b[0:l//2]:
  print(0)
  exit()

def x_number(s):
  if len(s) > 1:
    X=[]
    l=len(s)-1
    for i in range(l):
      x=abs(int(s[i])-int(s[i+1]))
      if x != 0:
        X.append(x)
  else:
    if len(s)==0:
      return 0
    return s[0]
  return x_number(X)

print(x_number(a))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input()
count = 0
top = 0
bottom = 0
left = 0
for i in range(N-1):
    chk = abs(int(a[i+1]) - int(a[i]))
    if chk != 0:
        if count == 0  :
            count += 1
            now = chk
            flag = 0
            left = chk
        else:
            if now != chk:
                count += 1
                now = chk
            else:
                flag = 1
    else:
        if i == 0:
            top = 1
        if i == N-2:
            bottom = 1
if count == 0:
    print(0)
elif count == 1:
    if flag == 1:
        if top + bottom == 1:
            print(now)
        else:
            print(0)
    else:
        if top + bottom == 2:
            print(0)
        else:
            print(now)
else:
    if count == 2:
        if left == 1 and top == 1 and bottom == 0:
            print(0)
        elif left == 2 and top == 0 and bottom == 1:
            print(0)
        else:
            print(1)
    else:
        if count %2 == 0:
            if left == 2 and top == 1:
                print(1)
            elif  left == 1 and bottom == 1:
                print(1)
            else:
                print(0)

        else:
            if left == 1:
                print(0)
            else:
                if top + bottom == 1:
                    print(1)
                else:
                    print(0)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
import sys
sys.setrecursionlimit(10000000)

#const
dxdy=((1,0),(0,1))
# my functions here!
def pin(type=int):
    return map(type,input().rstrip().split())
    

"""絶対TLEする！A問題のpython回答はこちら！！！！

def sx(h,w,ans,flag=0):#depth-first? search functionを障害物を消しながら行う
    global res
    res+=1
    #print(res)
    
    if h>=H or w>=W:
        #print("そとやんけ！")
        return#迷路の外におる
    if h==H-1 and w==W-1:
        if maze[h][w]=="#":ans+=1-flag
        if dp[h][w]>=ans:
            dp[h][w]=ans        
       # print("end")
        return
    if maze[h][w]==".":#普通のサーチする
        if dp[h][w]>=ans:
            dp[h][w]=ans
            for d in dxdy:
                sx(h+d[0],w+d[1],ans)
    else:
        ans+=(1-flag)
        if dp[h][w]>=ans:
            dp[h][w]=ans
            for d in dxdy:
                sx(h+d[0],w+d[1],ans,1)
    
        
def resolve():
    
    global anss ,dp,H,W,maze
    global res
    res=0
    H,W=pin()
    dp=[[(H+W)]*W for _ in range(H)]
    
    maze=tuple(tuple(input())for i in range(H))
    
    sx(0,0,0,0)
    #print(min(anss),len(anss),res)
    anss=[]
    print(dp[H-1][W-1])
    
"""
#B

def resolve():
    N,=pin()
    list_x=[int(i) for i in tuple(input())]
    #print(list_x)
    temp=[abs(list_x[i+1]- list_x[i]) for i in range(N-1) if list_x[i+1]-list_x[i]!=0]

    ans=sum([(temp[j+1]-temp[j]) for j in range(len(temp)-1) if (temp[j+1]-temp[j])!=0])
    print(ans)


"""         
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""

if __name__=="__main__":resolve()

Submission status: Wrong Answer

Solution code:
N = int(input())
As = input()

if '2' in As:
    print(1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input()))
A = [abs(A[i] - A[i + 1]) % 2 for i in range(len(A) - 1)]

if len(A) == 1:
    print(A[0])
    exit()

cnt = A[0] + A[-1]
for i in range(len(A)):
    if A[i: i + 3] == [0, 1, 0]:
        cnt += 1
    if A[i: i + 3] == [1, 0, 1]:
        cnt -= 1

print(cnt % 2)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N = int(input())
a = np.array([int(x) for x in list(input().strip())])

for _ in range(N):
    b = a[:-1] - a[1:]
    a = np.apply_along_axis(abs, 0, b)

if len(a):
    print(a[0])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = input()

if '2' in As:
    print(0)
else:
    print(2)

Submission status: Wrong Answer

Solution code:
s=int(input())
t=input()
a=0
for i in range(s-1):
  b=int(t[i+1])
  c=int(t[i])
  a=a+abs(b-c)
print(a%3)

Submission status: Wrong Answer

Solution code:
def examA():
    def bfs_grid(h, w, s, maze):
        distance = [[inf] * w for _ in range(h)]

        def bfsg():
            queue = deque()
            if maze[s[0]][s[1]]=="#":
                queue.append((s, 1))
                distance[s[0]][s[1]] = 1
            else:
                queue.append((s,0))
                distance[s[0]][s[1]] = 0
            while len(queue):
                [y, x],st = queue.popleft()
                for i in range(2):
                    nx, ny = x + [1, 0][i], y + [0, 1][i]
                    if (0 <= nx < w and 0 <= ny < h):
                        cur = deepcopy(distance[y][x])
                        if st==0 and maze[ny][nx]=='#':
                            cur += 1
                        if distance[ny][nx] <= cur:
                            continue
                        if maze[ny][nx]=='#':
                            queue.append(((ny, nx),1))
                        else:
                            queue.append(((ny, nx), 0))
                        distance[ny][nx] = cur
            return distance

        return bfsg()
    H, W = LI()
    S = [SI()for _ in range(H)]
    L = bfs_grid(H,W,[0,0],S)
    ans = L[-1][-1]
    #print(L)
    print(ans)
    return

def examB():
    def judge(a,b):
        if a%2==0 and b%2==1:
            return 0
        if a==0 and b==0:
            return 1
        return judge(a//2,b//2)
    N = I()
    A = SI()
    if A[0]=="3":
        flag = True
        for s in A[1:]:
            if s!="1":
                flag = False
                break
        if flag:
            print(2)
            return
    if A[-1]=="3":
        flag = True
        for s in A[:N-2]:
            if s!="1":
                flag = False
                break
        if flag:
            print(2)
            return
    S = [0]*(N-1)
    for i in range(N-1):
        S[i] = abs(int(A[i])-int(A[i+1]))
    #print(S)
    cur = 0
    if S[0]==1:
        cur = 1
    for i,s in enumerate(S[1:],start=1):
        if s==1 and judge(N-2,i)==1:
            cur ^= 1
        #print(cur)
    if cur==1:
        print(1)
    else:
        print(0)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examB()

"""

"""

Submission status: Wrong Answer

Solution code:
import sys
import random

n = int(sys.stdin.readline().rstrip())
*s, = map(int, list(sys.stdin.readline().rstrip()))

def main():
    return random.randrange(3)

if __name__ == "__main__":
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input(''))
m=input('')
s=[]
for a in range(n):
    s.append(int(m[a]))


kuri=n-1
for a in range(n-1):
    kake=1
    for b in range(kuri):
        if s[b]==0 or s[b]==1:
            kake=kake*1
        else:
            kake=kake*0
            break
    if kake==0:
        for b in range(kuri):
            if s[b]==s[b+1]:
                s[b]=0
            elif s[b]*s[b+1]==2:
                s[b]=1
            elif s[b]*s[b+1]==3:
                s[b]=2
            elif s[b]*s[b+1]==6:
                s[b]=1
            else:
                if s[b]==0:
                    s[b]=s[b+1]

    
            kuri=kuri-1
    else:
        ki=0
        for b in range(n):
            if s[b]%2==1:
                ki=ki+1
    
        if ki%2==1:
            s[0]=1
        else:
            s[0]=0
        break

    if kake==1:
        break

print(s[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input()

sp = len(''.join(set(a)))
if sp == 1:
    print(0)
elif sp == 2:
    if a[0] == '1':
        add = 1
    else:
        add = 0
    if a[-1] == '1':
        add = add+1
    else:
        add = add
    a = a.replace('1', '')
    if  not "3" in a:
        if (len(a)+add) % 2 == 1:
            print(1)
        else:
            print(0)
    elif not "2" in a:
        if (len(a)+add) % 2 == 1:
            print(2)
        else:
            print(0)
    else:
        if len(a) % 2 == 1:
            print(1)
        else:
            print(0)
else:
    a =  a.replace('1', '')
    if a[0] == '2':
        add = 1
    else:
        add = 0
    a = a.replace('2', '')
    if (len(a)+add) % 2 == 1:
        print(1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N = int(input())
a = np.array([int(x) for x in list(input().strip())])

for _ in range(2):
    b = a[:-1] - a[1:]
    a = np.apply_along_axis(abs, 0, b)

if len(a):
    print(a[0])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)

def main():
    n = int(input())
    a = list(input())
    print(0)
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
a = [int(S[i]) for i in range(N)]

from collections import Counter
c = Counter(a)
if c[3] == 1 and c[2]==0 and (a[0] ==3 or a[-1] ==3):
  print(2)
elif c[1] == 1 and c[2]==0 and (a[0] ==1 or a[-1] ==1):
  print(2)
else:
  if N == 2:
    print(abs(a[0]-a[1]))
  else:
    a = [abs(a[i+1]-a[i]) for i in range(N-1)]
    cd = Counter(a[1:-1])
    cde = Counter(a[0:1] + a[-1:])
    if ((cd[1] * 2) + cde[1])%2 ==1:
      print(1)
    else:
      print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input()))
A = [abs(A[i] - A[i + 1]) % 2 for i in range(len(A) - 1)]

if len(A) == 1:
    print(A[0])
    exit()

cnt = A[0] + A[-1]
for i in range(len(A)):
    if A[i: i + 3] == [0, 1, 0]:
        cnt += 1

print(cnt % 2)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, list(input())))

print(1)

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
a = [int(i) for i in list(input())]

for i in range(n-1):
    for j in range(len(a) - 1):
        a[j] = abs(a[j] - a[j + 1])
    
    a = [i for i in a if i != 0]
    if len(a) == 1:
        print(a[0])
        sys.exit()
    elif len(a) == 0:
        print(0)
        sys.exit()
    a.pop()

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, list(input())))
a = [x[0]]
prev = x[0]
for i in range(1, n):
        if prev!=x[i]: a.append(x[i])
        prev = x[i]
if len(a)==1:
        print(0)
        exit()



b = []
prev = first = a[0]
inc = a[0]<a[1]
cnt = 1
for i in range(1, len(a)):
        if inc:
                if prev<a[i]: cnt += 1
                else:
                        if cnt==3: b.append(2 * (i!=len(a)))
                        else: b.append(prev-first)
                        first = prev
                        inc = False
                        cnt = 2
        else:
                if prev>a[i]: cnt += 1
                else:
                        if cnt==3: b.append(2 * (i!=len(a)))
                        b.append(first-prev)
                        first = prev
                        inc = True
                        cnt = 2
        prev = a[i]
if inc: b.append(prev-first)
else: b.append(first-prev)


prev = b[0]
cnt = 0
for i in range(1, len(b)):
        cnt += (prev!=b[i])
        prev = b[i]


if cnt: print(cnt%2)
elif len(b)==1: print(b[0])
else: print(0)

Submission status: Wrong Answer

Solution code:
def solve(arr):
    while len(arr) >= 2:
        arr = [abs(arr[i+1] - arr[i]) for i in range(len(arr)-1)]
    return arr[0]

def solveSmart(arr): 
    N = len(arr)
    if N <= 7:
        return solve(arr)
    S = 0
    for i in range(N//2):
        if i == 0 or (i == 2 and N % 2 == 0) or ((N - 1) % (i + 2) >= i):
            S += arr[i]
            S += arr[N-1-i]
    return S % 2

def solveNormal(arr):
    while len(arr) >= 2:
        arr = [abs(arr[i+1] - arr[i]) for i in range(len(arr) - 1)]
        bad = False
        for i in range(len(arr)):
            if arr[i] != 2: continue
            if i - 1 >= 0 and arr[i-1] == 0: bad = True
            if i + 1 < len(arr) and arr[i+1] == 0: bad = True
        if not bad:
            for i in range(len(arr)):
                if arr[i] == 2: arr[i] = 0
            return solveSmart(arr)

N = int(input())
arr = list(map(int, input()))
print(solveNormal(arr))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
def keisan(a,b):
    return abs(a-b)
if n>=4:
    prev=-1
    cnt=0
    for c in range(n-2):
        p3=int(s[c])
        p2=int(s[c+1])
        p1=int(s[c+2])
        kouho=keisan(keisan(p1,p2), keisan(p2,p3))
        if kouho == prev:
            cnt+=0
        else:
            cnt+=1
        prev=kouho
    print(kouho%2)
else:
    if n==3:
        p,q,r=int(s[2]),int(s[1]),int(s[0])
        ans=keisan(keisan(p,q), keisan(q,r))
    if n==2:
        p,q=int(s[1]),int(s[0])
        ans=keisan(p,q)
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input()))
A = [abs(A[i] - A[i + 1]) % 2 for i in range(len(A) - 1)]

cnt = A[0]
for i in range(len(A)):
    if A[i: i + 3] == [0, 1, 0]:
        cnt += 1

print(cnt % 2)

Submission status: Wrong Answer

Solution code:
from random import randrange, seed
seed()

N = int(input())
As = input()

if '2' in As:
    print(randrange(2))
else:
    print(2*randrange(2))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input()
b = []
for i in range(N-1):
    b.append(abs(int(A[i])-int(A[i+1])))
S = 0
p = 0
for i in range(N-1):
    if p == 0:
        S += b[i]
    n = N - 2 - i
    k = i + 1
    if n == 0:
        break
    else:
        while n % 2 == 0:
            p += 1
            n //= 2
        while k % 2 == 0:
            p -= 1
            k //= 2

if S % 2:
    print(1)
else:
    if b[0] == 2:
        for i in range(1,N-1):
            if b[i] != 0:
                break
        else:
            print(2)
            exit()
        for i in range(1,N-2):
            if b[i] != 2:
                break
        else:
            if b[-1] == 0:
                print(2)
                exit()
    elif b[N-2] == 2:
        for i in range(N-2):
            if b[i] != 0:
                break
        else:
            print(2)
            exit()
        for i in range(N-3):
            if b[i] != 2:
                break
        else:
            if b[0] == 0:
                print(2)
                exit()
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
List = list(input())
arr = []

for i in range(N):
  a = int(List[i])
  arr.append(a)
    
arr.sort()

ans = []

for i in range(N-1):
  b = arr[i+1] - arr[i]
  ans.append(b)

cnt = 0
for i in range(N-1):
  if ans[-(i+1)] == 0:
    cnt += 1
  else:
    break
    
cnt2 = 0
for i in range(N-2):
  if ans[i] == 1 and ans[i+1] == 1:
    cnt2 += 1
  
a = ans.count(0)
b = ans.count(1)
c = ans.count(2)

if b == 0 and c == 0:
  print(0)
elif c == 1 and cnt%2 == 0:
  print(2)
elif c == 1 and ((N-1)-cnt-1)%2 == 0:
  print(2)  
elif b == 1 and cnt%2 == 0:
  print(1)
elif b == 1 and ((N-1)-cnt-1)%2 == 0:
  print(1)  
elif b == 2 and a%2 == 1 and cnt == 0:
  print(1)
elif b == 2 and a%2 == 1 and cnt == N-3:
  print(1)
elif b == 2 and cnt2 == 1 and (cnt > 2 or (N-1)-2-cnt > 2):
  print(1)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
queue = list(input())
num_queue = [int(i) for i in queue]
ans_queue = []
for i in range(N - 1):
	for j in range(len(num_queue) - 1):
		ans_queue.append(abs(num_queue[j] - num_queue[j + 1]))
    
	num_queue = ans_queue
	print(num_queue)
	ans_queue = []
print(num_queue[0])

Submission status: Wrong Answer

Solution code:
import math
import numpy as np

N = int(input())
arr_rev = list(map(int, list(input())))
arr_rev.reverse()
arr_rev = np.array(arr_rev)


def calc(a, b):
    return abs(-a + b)


def chanto(arr_rev):
    inp = arr_rev
    diff_1 = np.array([calc(inp[x], inp[x + 1]) for x in range(len(inp) - 1)])
    if diff_1[0] != 0 and diff_1[len(diff_1) - 1] != 0:

        diff_1_nonz = diff_1[diff_1 > 0]

        if len(diff_1_nonz) == 0:  # all zero
            return 0
        if len(diff_1_nonz) == 1:  # only single value
            return diff_1_nonz[0]

        return (diff_1_nonz[0] + diff_1_nonz[len(diff_1_nonz) - 1]) % 2
    else:
        tmp = diff_1[diff_1 > 0]
        if np.all(tmp == 2):
            return 2
        else:
            if len(tmp[tmp == 1]) % 2 == 1 and len(diff_1) % 2 == 0:
                return 1
            elif len(tmp[tmp == 1]) % 2 == 1 and len(diff_1) % 2 != 0:
                return 0
            elif len(tmp[tmp == 1]) % 2 == 0 and len(diff_1) % 2 == 0:
                return 0
            else:
                return 1


print(chanto(arr_rev))

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
a = [int(i) for i in list(input())]

for i in range(n-1):
    for j in range(len(a) - 1):
        a[j] = abs(a[j] - a[j + 1])
    
    a.pop()
    a = [i for i in a if i != 0]
    if len(a) == 1:
        print(a[0])
        sys.exit()
    elif len(a) == 0:
        print(0)
        sys.exit()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input()))
A = [abs(A[i] - A[i + 1]) % 2 for i in range(len(A) - 1)]

cnt = 0
for i in range(len(A)):
    if A[i: i + 3] == [0, 1, 0]:
        cnt += 1

print(cnt % 2)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(4100000)
N= int(input())
an=  [int(x) for x in list(input())]

#print(an)
#print(len(an))

#if len(an)==1:
#    print(an[0])
#    exit()

ans_array=[]
def calc(prm):
    global ans_array
    bn=[]
    hasZero=False
    hasOne=False
    hasTwo=False
    threeKind = False
    for i in range(len(prm)-1):
        b = abs(prm[i]-prm[i+1])
        if b==0:
            hasZero=True
        elif b==1:
            hasOne=True
        else:
            hasTwo=True
        bn.append(b)
    if len(bn)==1:
        #print("要素数が1だよ")
        #print(bn)
        ans_array=bn
        return
    elif hasZero and hasOne and hasTwo:
        threeKind=True
        #print("3種類あるよ")
        #print(bn)
        calc(bn)
    else:
        #print("2種類以下だよ")
        #print(bn)
        ans_array=bn
        return
calc(an)

if len(ans_array)==1:
    print(ans_array[0])
else:
    ans_array2=[]
    for i in range(len(ans_array)-1):
        b = abs(ans_array[i]-ans_array[i+1])
        ans_array2.append(b)
    #print(ans_array2)
    if len(ans_array2)==1:
        print(ans_array2[0])
    else:
        appears=[]
        num_zero = ans_array2.count(0)
        num_one = ans_array2.count(1)
        num_two = ans_array2.count(2)
        appears.append(num_one)
        appears.append(num_zero)
        appears.append(num_two)
        appears.sort()
        max= appears[0]
        #if max == len(ans_array2):
        #    print(0)
        #    exit()
        minor = appears[1]
        if minor==0:
            print(ans_array2[0])
        elif (len(ans_array2)%2==0) and (minor%2==0):
            print(0)
        elif (len(ans_array2)%2==1) and (minor%2==1):
            print(0)
        else:
            if num_zero==0:
                print(1)
            elif num_one==0:
                print(2)
            else:
                print(1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input()))
A = [abs(A[i] - A[i + 1]) % 2 for i in range(len(A) - 1)]

cnt = 0
for i in range(len(A)):
    if A[i: i + 4] == [0, 1, 0]:
        cnt += 1

print(cnt % 2)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input()
b = []
for i in range(N-1):
    b.append(abs(int(A[i])-int(A[i+1])))
S = 0
p = 0
for i in range(N-1):
    if p == 0:
        S += b[i]
    n = N - 2 - i
    k = i + 1
    if n == 0:
        break
    else:
        while n % 2 == 0:
            p += 1
            n //= 2
        while k % 2 == 0:
            p -= 1
            k //= 2

if S % 2:
    print(1)
else:
    if b[0] == 2:
        for i in range(1,N-1):
            if b[i] != 0:
                break
        else:
            print(2)
            exit()
        for i in range(1,N-2):
            if b[i] != 2:
                break
        else:
            if b[-1] == 0:
                print(2)
                exit()
    elif b[N-2] == 2:
        for i in range(N-2):
            if b[i] != 0:
                print(0)
        else:
            print(2)
            exit()
        for i in range(N-3):
            if b[i] != 2:
                break
        else:
            if b[0] == 0:
                print(2)
                exit()
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input()

sp = len(''.join(set(a)))
if sp == 1:
    print(0)
elif sp == 2:
    if a[0] == '1':
        add = 1
    else:
        add = 0
    a = a.replace('1', '')
    if  not "3" in a:
        if (len(a)+add) % 2 == 1:
            print(1)
        else:
            print(0)
    elif not "2" in a:
        if (len(a)+add) % 2 == 1:
            print(2)
        else:
            print(0)
    else:
        if len(a) % 2 == 1:
            print(1)
        else:
            print(0)
else:
    a =  a.replace('1', '')
    if a[0] == '2':
        add = 1
    else:
        add = 0
    a = a.replace('2', '')
    if (len(a)+add) % 2 == 1:
        print(1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()


def solve(N, S):
    xs = list(map(int, S))
    while 1 < len(xs):
        ys = []
        count = 0
        found_2 = False
        for i in range(len(xs) - 1):
            val = abs(xs[i + 1] - xs[i])
            if 0 < val:
                ys.extend([0] * (count % 3))
                ys.append(val)
                if val == 2:
                    found_2 = True
                count = 0
            else:
                count += 1
        xs = ys + [0] * (count % 3)
        if not found_2:
            i = 0
            while i + 3 < len(xs) and (xs[i], xs[i + 1], xs[i + 2]) == (1, 1, 0):
                i += 3
            xs = xs[i:]
    return xs[0] if xs else 0


print(solve(N, S))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input()

print(abs(int(a[0]) - int(a[-1])))

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
x = [int(i) for i in s]
for _ in range(N-1):
    y = []
    for i in range(len(x)-1):
        z = abs(x[i] - x[i+1])
        if z != 0:
            y.append(z)
    x=y[:]
    if len(x) == 1:
        print(y[0])
        break
    if len(x) == 0:
        print(0)
        break

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()

dic = {}
dic['10'] = '1'
dic['20'] = '2'
dic['30'] = '3'
dic['11'] = '0'
dic['22'] = '0'
dic['33'] = '0'
dic['12'] = '1'
dic['21'] = '1'
dic['23'] = '1'
dic['32'] = '1'
dic['13'] = '2'
dic['31'] = '2'

if s[-1] != '0':
  s = s.replace('0','')
else:
  s = s.replace('0','')+'0'
  
while len(s)>=2:  
  s = ''.join([dic[s[i:i+2]] for i in range(len(s)-1)])
  if s[-1] != '0':
    s = s.replace('0','')
  else:
    s = s.replace('0','')+'0'
  
if len(s)>0:
  print(int(s))
else:
  print(0)