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())
a = list(input())
for i in range(N):
    a[i] = int(a[i])

def process(seq):
    n = len(seq)
    output = [0 for i in range(n-1)]
    
    for i in range(n-1):
        output[i] = abs(seq[i]-seq[i+1])

    return output

def check(seq):
    count = 0
    if len(seq) == 1:
        if seq[0] == 0:
            return 0
        else:
            return 1
    if len(seq) == 2:
        if seq[0] == seq[1]:
            return 0
        else:
            return 1
    for i in range(len(seq)-2):
        if seq[i] != seq[i+2]:
            count += 1

    return count%2

a = process(a)


if 2 in a and (not 1 in a):
    
    print(2*check(a))
else:
    for i in range(len(a)):
        if a[i] == 2:
            a[i]=0
    print(check(a))

Submission status: Wrong Answer

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

def intlist(s):
    l = []
    for c in s:
        l.append(int(c))
    return l

def cut(list):
    l = [list[0]]
    compressed = False
    for i in range(1, len(list)):
        if list[i] != list[i-1]:
            l.append(list[i])
        else:
            compressed = True
    if len(l) == 1 and compressed:
        l.append( l[0] )
    return l


X = intlist(S)
while len(X) > 1:
    next = []
    for i in range(len(X)-1):
        v = abs(X[i] - X[i+1])
        #if v > 0:
        next.append(v)
    X = cut(next)

if len(next) > 0:
    print(next[0])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np


def input():
    return sys.stdin.readline().strip()


def calc(A):
    B = np.abs(A[1:] - A[:-1])
    return B


N = int(input())
A = input()

A = np.array([int(a) for a in A])
if N <= 100:
    for i in range(N - 1):
        A = calc(A)
    print(A[0])
else:
    for i in range(100):
        A = calc(A)
        # print(A)
        if A[0] == 1 and np.sum(A[1:]) == 0:
            print(1)
            sys.exit()
        elif np.sum(A) == 0:
            print(0)
            sys.exit()
    print(0)

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:
        print(0)
    else:
        if top == bottom:
            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:
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)
        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:
#!/usr/bin/env python3
from collections import deque
N = int(input())
a = str(input())

a = [int(a[i]) for i in range(N)]
cnt = 0
b = deque()

for i in range(N-1):
    if abs(a[i] - a[i+1]) != 0:
        b.append(abs(a[i] - a[i+1]))
        if len(b) != 1 and b[-1] != b[-2]:
            cnt += 1
if len(b) == 1:
    print(b[0])
    exit()

if cnt != 1:
    print(0)
else:
    print(1)

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 b == 1 and cnt%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:
# coding: utf-8
N=int(input())
A=list(map(int,input()))


if N<=4:
    B=[[] for i in range(N)]
    B[0]=A
    for i in range(N):
        for j in range(N-1-i):
            B[i+1].append(abs(B[i][j]-B[i][j+1]))
    
    print(B[N-1][0])
    
else:
    B=[]
    if N%2==1:
        for i in range(1,N):
            B.append(abs(A[i-1]-A[i]))
    else:
        C=[]
        for i in range(1,N):
            C.append(abs(A[i-1]-A[i]))
        for i in range(1,N-1):
            B.append(abs(C[i-1]-C[i]))
    
    flg0=False
    flg2=False
    cnt1=0
    cnt2=0
    
    for i in range(len(B)):
        if B[i]==1:
            cnt1+=1
        elif B[i]==2:
            cnt2+=1
    
    if cnt1==len(B)//2:
        print(0)
    elif cnt1==0 and cnt2!=len(B)//2 and cnt2>0:
        print(2)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
if set(list(s))=={"1","3"}:print(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 1
        if a==0 and b==0:
            return 0
        return judge(a//2,b//2)
    N = I()
    A = SI()
    print(2)
    return
    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,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:
N = int(input())
a = list(input())
for i in range(N):
    a[i] = int(a[i])

def process(seq):
    n = len(seq)
    output = [0 for i in range(n-1)]
    
    for i in range(n-1):
        output[i] = abs(seq[i]-seq[i+1])

    return output

def check(seq):
    count = 0
    if len(seq) == 2:
        if seq[0] == seq[1]:
            return 0
        else:
            return 1
    for i in range(len(seq)-2):
        if seq[i] != seq[i+2]:
            count += 1

    return count%2

a = process(a)


if 2 in a and (not 1 in a):
    
    print(2*check(a))
else:
    for i in range(len(a)):
        if a[i] == 2:
            a[i]=0
    print(check(a))

Submission status: Wrong Answer

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

iter = N-1
while True:
    B = []
    for i in range(iter):
        b = abs(A[i]-A[i+1])
        B.append(b)
    if B[0] != 0 and B[-1] != 0:
        break
print(abs(B[0]-B[-1]))

Submission status: Wrong Answer

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list -- START --
def summarize_list(sl):
  # sl=sorted(l)

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append(a)
      a=x
      c=1
  res.append(a)

  return res
# Summarize count of factor within list --- END ---

def main():
  n=I()
  _l=list(S())

  if n==2:
    return abs(int(_l[0])-int(_l[1]))

  if _l.count('3')!=0:
    l=[]
    for i in range(n-1):
      x=abs(int(_l[i])-int(_l[i+1]))
      if x!=0:
        l.append(x)
  
    if len(l)==0:
      return 0
  
    ll=copy.deepcopy(l)

  else:
    ll=[]
    for x in _l:
      ll.append(int(x))

  # # TLE
  # while True:
  #   if len(l)==1:
  #     # return l[0]
  #     print(l[0])
  #     break
  #   a=[]
  #   x=-1
  #   for i in range(len(l)-1):
  #     b=abs(int(l[i+1])-int(l[i]))
  #     if x!=b:
  #       a.append(b)
  #   l=a

  ans=summarize_list(ll)
  # print(ans)
  # print(ll)

  if len(ans)==2:
    return 1
  return 0

# main()
print(main())

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
if set(list(s))=={"1","3"}:print(2)

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 1
        if a==0 and b==0:
            return 0
        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,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 numpy as np
import math
import itertools

N = int(input())
lines = [int(n) for n in list(input())]

for i in range(N):
  next_lines = []
  for j in range(N-i):
    x = np.abs(lines[j-1] - lines[j])
    next_lines.append(x)
  lines = next_lines

print(lines[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input()
X = []

for a in A:
    X.append(int(a))

Y =[]
while len(X) > 1:
    Y =[]
    for i in range(len(X)):
        if i != 0:
            Y.append(abs(X[i] - X[i - 1]))
    X = Y

print(X)

Submission status: Wrong Answer

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

tri = [A]
# 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)
        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:
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]:
    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 b == 1 and cnt%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:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list -- START --
def summarize_list(sl):
  # sl=sorted(l)

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append(a)
      a=x
      c=1
  res.append(a)

  return res
# Summarize count of factor within list --- END ---

def main():
  n=I()
  _l=list(S())

  if n==2:
    return abs(int(_l[0])-int(_l[1]))

  if _l.count('3')!=0:
    l=[]
    for i in range(n-1):
      x=abs(int(_l[i])-int(_l[i+1]))
      if x!=0:
        l.append(x)
  
    if len(l)==0:
      return 0
  
    ll=l

  else:
    ll=[]
    for x in _l:
      ll.append(int(x))

  # # TLE
  # while True:
  #   if len(l)==1:
  #     # return l[0]
  #     print(l[0])
  #     break
  #   a=[]
  #   x=-1
  #   for i in range(len(l)-1):
  #     b=abs(int(l[i+1])-int(l[i]))
  #     if x!=b:
  #       a.append(b)
  #   l=a

  ans=summarize_list(ll)
  # print(ans)
  # print(ll)

  if len(ans)==2:
    return 1
  return 0

# main()
print(main())

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())])
a = a[np.nonzero(a)]

while len(a) > 1:
    b = a[:-1] - a[1:]
    a = np.apply_along_axis(abs, 0, b)
    a = a[np.nonzero(a)]

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

Submission status: Wrong Answer

Solution code:
n = int(input())
 
numlist = list(input())

l_numlist = len(numlist)

while l_numlist > 1:
 
    for a in range(0, l_numlist-1):
        d = int(numlist[a]) - int(numlist[a+1])
        if not d == 0:
            numlist.append(abs(d))
 
    numlist = numlist[l_numlist:]
    l_numlist = len(numlist)
if numlist == []:
  print(0)
else:
  print(numlist[0])

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)
        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:
N = int(input())
a = list(input())
for i in range(N):
    a[i] = int(a[i])

def process(seq):
    n = len(seq)
    output = [0 for i in range(n-1)]
    
    for i in range(n-1):
        output[i] = abs(seq[i]-seq[i+1])

    return output

def check(seq):
    count = 0
    for i in range(len(seq)-2):
        if seq[i] != seq[i+2]:
            count += 1

    return count%2

a = process(a)


if 2 in a and (not 1 in a):
    
    print(2*check(a))
else:
    for i in range(len(a)):
        if a[i] == 2:
            a[i]=0
    print(check(a))

Submission status: Wrong Answer

Solution code:
import copy
import numpy as np

N = int(input())
seq = list(map(int, input()))
seq = np.array(seq)
def get_sub_seq(li1):
    li2 = copy.copy(li1)
    li1 = np.delete(li1, -1)
    li2 = np.delete(li2, 0)
    new = li1 - li2
    new = list(map(abs, new))
    return new
if len(seq) > 1:
    seq = get_sub_seq(seq)
print(seq[0])

Submission status: Wrong Answer

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

c = [1 for _ in range(3)]
while c[0]*c[1]*c[2] > 0:
    b = []
    c = [0 for _ in range(3)]
    for i in range(1,len(a)):
        b.append(abs(a[i]-a[i-1]))
        c[b[-1]] += 1
    a = b.copy()

if c[0]!=0:
    print(0)
else:
    print(c.index(max(c)))

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    S = input().strip()

    if N == 2:
        print(abs(int(S[0]) - int(S[1])))
        return
    if N == 3:
        print(abs(abs(int(S[0]) - int(S[1])) - abs(int(S[1]) - int(S[2]))))
        return


    A = []
    for a, b in zip(S, S[1:]):
        A.append(abs(int(a) - int(b)))

    print(abs(A[0] - A[-1]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input()
A=[]
for i in range(n):
  A.append(int(a[i]))

def list(L):
  if len(L)==1:
    print(L[0])
  else:
    m = len(L)
    B=[]
    for i in range(m-1):
      B.append(abs(L[i+1]-L[i]))
    if len(set(B))==1:
      print(0)
    else:
      list(B)
list(A)

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())])

while len(a) > 1:
    a = a[np.nonzero(a)]
    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 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:
                return 1
            else:
                return 0


print(chanto(arr_rev))

Submission status: Wrong Answer

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

dic = {}
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'

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

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    a = input()
    l = N
    while l > 1:
        b = ""
        for i in range(l-1):
            s,t = int(a[i]),int(a[i+1])
            if s == t:continue
            else:u = abs(s-t);b+=str(u)
        l = len(b)
        if l == 0:print(0);exit()
        elif l == 1:print(int(b));exit()
        a = b

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

N = int(input())
A = list(map(int,input()))

def func(x):
    if len(x) == 1:
        return x[0]
    if len(x)%2 == 1:
        for i in range(len(x)-1):
            x[i] = abs(x[i]-x[i+1])
        x.pop()
    return abs(func(x[:len(x)//2]) - func(x[len(x)//2:]))

print(func(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:
        print(0)
    else:
        if top == bottom:
            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 top + bottom == 1:
            print(1)
        else:
            print(0)

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(t) > 1 and len(set(t)) == 1:
    print(0)
    exit()
tri.append(t)

while len(tri[-1]) > 1:
    nx = []
    nw = tri[-1]
    for j in range(1,len(nw)):
        _abs = abs(nw[j]-nw[j-1])
        if j == 1:
            nx.append(_abs)
        else:
            if nx[-1] != _abs:
                nx.append(_abs)
    if len(nx) > 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:
# coding: utf-8
import numpy as np


def solve(*args: str) -> str:
    n = int(args[0])
    A = np.array([ord(a)-48 for a in args[1]])

    for i in range(n-1):
        A = np.abs(A[:-1]-A[1:])
        if A.max() <= 1:
            A[0] ^= sum(A[1::2]) % 2
            break

    return str(A[0])


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Wrong Answer

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

print(0)

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 = []
    nw = tri[-1]
    for j in range(1,len(nw)):
        _abs = abs(nw[j]-nw[j-1])
        if j == 1:
            nx.append(_abs)
        else:
            if nx[-1] != _abs:
                nx.append(_abs)
    if 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:
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())])

while len(a) > 1:
    b = a[:-1] - a[1:]
    a = np.apply_along_axis(abs, 0, b)
    a = a[np.nonzero(a)]

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

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(str(input()))
x = [int(i) for i in x]

for i in range(n+5):
    tmp = []
    for j in range(1,len(x)):
        if x[j]==x[j-1] and len(tmp) > 0:
            if tmp[-1]==0:
                tmp.pop(-1)
        else:
            tmp.append(abs(x[j]-x[j-1]))
    x = tmp
    if len(x)==1:
        print(x[0])
        exit()
    elif len(x)==0:
        print(0)
        exit()

Submission status: Wrong Answer

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


def c(s):
    result = ''
    for i in range(len(s) - 1):
        result += str(abs(int(s[i]) - int(s[i + 1])))
    return result.strip('0')


while len(a) <= 1:
    a = c(a)

if len(a) == 0:
    print(0)
else:
    print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
a =str(input())
alist = [0] * N
cnt = [0] * 3
for i, a in enumerate(a):
  alist[i] = int(a)
  if int(a)==0:
    cnt[0] += 1
  elif int(a)==1:
    cnt[1] += 1
  else:
    cnt[2] += 1

count = 0
if N % 2==0:
  for i in range(N-1):
    x = alist[i]
    y = alist[i+1]
    if (x-y) == 0:
      alist[i] = 0
    elif ((x-y)==1) or ((y-x)==1):
      alist[i] = 1
    else:
      alist[i] = 2
  N = N-1
for i in range(0,N,2):
  count += alist[i]
if cnt[1]>0:
  if N % 4 == 3:
    print(count % 2)
  else:
    print((count+1) % 2)
else:
  if N % 4 == 3:
    print(count % 4)
  else:
    print((count+2) % 4)

Submission status: Wrong Answer

Solution code:
def calc(array, N):
    for i in range(N):
        array = [abs(x-y) for x, y in zip(array[:-1], array[1:])]
    print(array[0])
def main():
    N = int(input())
    array = [0 for i in range(N+1)]
    s = input()
    for j in range(N):
        array[j+1] = int(s[j])
    calc(array, N)
if __name__ == "__main__":
    main()

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:
                print(0)
                break
        else:
            print(2)
    elif b[N-2] == 2:
        for i in range(N-2):
            if b[i] != 0:
                print(0)
                break
        else:
            print(2)
    else:
        print(0)