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:
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():
    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)
    if S[0]==S[-1]:
        print(0)
    else:
        print(1)
    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())
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]:
            continue
        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 = list(map(int, list(input())))

while len(a)>1:
    b = []
    for i in range(1, len(a)):
        if a[i]!=a[i-1]:
            b.append(abs(a[i]-a[i-1]))
    a = b.copy()
if len(a)==0:
    print(0)
else:
    print(a[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
count = 0
a = []
for i in range(n-1):
	a.append(abs(int(s[i])-int(s[i+1])))
if len(a) == 1:
	print(a[0])
else:
	print(abs(a[0]-a[-1]))

Submission status: Wrong Answer

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

if len(a) == 1 :
    print(a)
    exit()

a = a.replace("11", "1")
a = a.replace("22", "2")
a = a.replace("33", "3")

b = ""
for i in range(len(a)-1) :
    if abs(int(a[i]) - int(a[i+1])) == 1 :
        b += "1"
    elif abs(int(a[i]) - int(a[i+1])) == 2 :
        b += "2"

b = b.replace("11", "1")
b = b.replace("22", "2")

if len(b) == 1 :
    print(b)
elif len(b) == 2 :
    print(1)
else :
    print(0)

Submission status: Wrong Answer

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

A = []
for _ in a:
    A.append(int(_))

while len(A) > 1:
    newA = []
    for i in range(len(A) - 1):
        res = abs(A[i]-A[i+1])
        if res > 0:
            newA.append(res)
    A = newA

if A == []:
    print(0)
else:
    print(A[0])

Submission status: Wrong Answer

Solution code:
a=int(input())
b=input()
b=list(map(int,b))
j=1
l=[]
d=0
k=0
for j in range(a):
 for i in range(a-1):
    c=b[i]-b[i+1]
    if c<0:
        c=-c
    b[i]=c
 v=b[:-j]
print(v[0])

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans=[]
cnt=0
zcnt=0
temp=0
for i in range(n-1):
    now = s[i+1]
    prev = s[i]
    if now == prev:
        kouho='0'
        zcnt+=1
    else:
        if (now=='3' and prev=='1') or (now=='1' and prev=='3'):
            kouho='2'
            temp=2
            if ans!=[]:
                if ans[-1]=='1':
                    cnt+=1
                    
        else:
            kouho='1'
            temp=1
            if ans!=[]:
                if ans[-1]=='2':
                    cnt+=1
    ans.append(kouho)
nagasa=len(ans)
if nagasa-zcnt==1:
    print(temp)
else:
    print(cnt%2)

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, d in enumerate(A):
    cnt += pow(2, i) if d == 1 else 0

cnt %= 4
print(1 if cnt == 0 or cnt == 3 else 0)

Submission status: Wrong Answer

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)


def main():
    n=int(input())
    a=list(map(int,input()))
    ans=0
    if n<=5:
        ans=ret(a)
    else:
        moji=a[0]
        b=[0]
        temp=0
        kaburi=0
        for i in range(1,n):
            if a[i]!=moji:
                if kaburi==0:
                    if b[-1]!=moji:
                        b.append(moji)
                        temp += 1
                kaburi=0
                moji=a[i]
                if i==n-1 and b[-1]!=moji:
                    b.append(a[i])

            else:
                kaburi=1
            if temp>=10:
                break


        ans=ret(b[1:])
    print(ans)

if __name__ == "__main__":

    main()

Submission status: Wrong Answer

Solution code:
def work(s):
    t = []

    for i in range(len(s) - 1):
        if s[i] != 0:
            t.append(abs(s[i] - s[i + 1]))

    if len(t) == 1:
        print(t[0])
        return
    elif len(t) == 0:
        print("0")
        return
    else:
        work(t)


n = int(input())
s = input()

lst = []

for i in range(n):
    lst.append(int(s[i]) - 1)

work(lst)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N=int(stdin.readline().rstrip())
A = list(stdin.readline().rstrip())
An=[int(x) for x in A]
An = [abs(An[x]-An[x+1]) for i in range(N-1) for x in range(N-i-1) ]
print(An[0])

Submission status: Wrong Answer

Solution code:
import sys; sys.setrecursionlimit(2147483647); input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log
from collections import Counter, defaultdict, deque
from operator import itemgetter
INF = float('inf'); MOD = 10**9+7
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(MI())
def LIR(n): return [LI() for i in range(n)]
def IS(): return input().rstrip()

def main():
    N = I(); a = IS()
    x = [int(a[i]) for i in range(N)]
    while len(x) > 1:
        x = [abs(x[i]-x[i+1]) for i in range(len(x)-1) if x[i]!=x[i+1]]
    if len(x) == 0: print(0)
    else: print(x[0])

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import copy
import math
import fractions

import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
import numpy as np
from decimal import *
sys.setrecursionlimit(10 ** 6)

def CalcList(list):
    bfnum = -1
    afterList =[]
    for i in list:
        if bfnum == -1:
            bfnum = i
        else:
            now = abs(i -bfnum)
            if now >0:
                afterList.append(now)
            bfnum = i
    return afterList

def CheckList(list):
    bfnum = -1
    count = 0
    afterList =[]
    for i in list:
        if bfnum == -1:
            bfnum = i
            afterList.append(i)
        else:
            if i == bfnum:
                count = count +1
                if count < 3:
                    afterList.append(i)
            else:
                afterList.append(i)
    return afterList


if __name__ == '__main__':
    n = int(input())
    s = input()
    list =list(map(lambda x: int(x), s))

    while(len(list) >1):
        list = CalcList(list)

    if len(list) ==0:
        print(0)
    else:
        print(list[0])

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    a = list(input())
    a = list(map(int, a))
    import collections
    c = collections.defaultdict(int)
    count = 0
    b = []
    for i, x in enumerate(a):
        if i > 0 and a[i-1] == x:
            continue
        else:
            c[x] += 1
            b.append(x)
    for x in c:
        if c[x] > 1:
            count += 1
    if count > 1:
        print(0)
    else:
        if len(b) == 4:
            t1 = abs(abs(b[0]-b[1]) - abs(b[1]-b[2]))
            t2 = abs(abs(b[1]-b[2]) - abs(b[2]-b[3]))
            print(abs(t1-t2))

        elif len(b) == 3:
            t1 = abs(abs(b[0]-b[1]) - abs(b[1]-b[2]))
            print(t1)
        elif len(b) == 2:
            print(abs(b[0] - b[1]))
        else:
            print(b[0])


main()

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

L = [int(s) for s in input()]

a = np.array(L)
for i in range(N-1):
  a = np.abs(a[1:]-a[:-1])
  print(a)
print(a[0])

Submission status: Wrong Answer

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

a = a.replace("11", "1")
a = a.replace("22", "2")
a = a.replace("33", "3")

b = ""
for i in range(len(a)-1) :
    if abs(int(a[i]) - int(a[i+1])) == 1 :
        b += "1"
    elif abs(int(a[i]) - int(a[i+1])) == 2 :
        b += "2"

b = b.replace("11", "1")
b = b.replace("22", "2")

if len(b) == 1 :
    print(b)
elif len(b) == 2 :
    print(1)
else :
    print(0)

Submission status: Wrong Answer

Solution code:
def myfunc(length,a):
    if length > 1:
        b = []
        if length % 2 == 0:
            for i in range(length//2):
                b.append(abs(a[i*2]-a[i*2+1]))
        else:
            for i in range(length-1):
                b.append(abs(a[i]-a[i+1]))
            
        myfunc(len(b),b)
  
    elif length == 1:
        print(a[0])
        return 
    
n = int(input())
a = input()
c =[]
for i in range(len(a)):
    c.append(int(a[i]))

myfunc(len(c),c)

Submission status: Wrong Answer

Solution code:
n = int(input())
A=[map(int, input().split())]

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]))
      list(B)
list(A)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input()
print(1)

Submission status: Wrong Answer

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)


def main():
    n=int(input())
    a=list(map(int,input()))
    ans=0
    if n<=5:
        ans=ret(a)
    else:
        moji=a[0]
        b=[0]
        temp=0
        kaburi=0
        for i in range(1,n):
            if a[i]!=moji:
                if kaburi==0:
                    if b[-1]!=moji:
                        b.append(moji)
                        temp += 1
                kaburi=0
                moji=a[i]
                if i==n-1 and b[-1]!=moji:
                    b.append(a[i])

            else:
                kaburi=1
            if temp>=10:
                break


        ans=ret(b)
    print(ans)

if __name__ == "__main__":

    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input()
print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,list(input())))
l1=A.copy()

for i in range(2,n+1):
    l2 = [0]*n
    for j in range(n+1-i):
        l2[j] = abs(l1[j] - l1[j+1])
    l1 = l2.copy()
    print(l2)

print(l1[0])

Submission status: Wrong Answer

Solution code:
import sys
import copy
import math
import fractions

import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
import numpy as np
from decimal import *
sys.setrecursionlimit(10 ** 6)

def CalcList(list):
    bfnum = -1
    afterList =[]
    for i in list:
        if bfnum == -1:
            bfnum = i
        else:
            now = abs(i -bfnum)
            if now >0:
                afterList.append(now)
            bfnum = i
    return afterList

def CheckList(list):
    bfnum = -1
    count = 0
    afterList =[]
    for i in list:
        if bfnum == -1:
            bfnum = i
            afterList.append(i)
        else:
            if i == bfnum:
                count = count +1
                if count < 3:
                    afterList.append(i)
            else:
                afterList.append(i)
    return afterList


if __name__ == '__main__':
    n = int(input())
    s = input()
    list =list(map(lambda x: int(x), s))

    while(len(list) >1):
        list =  CheckList(list)
        list = CalcList(list)

    if len(list) ==0:
        print(0)
    else:
        print(list[0])

Submission status: Wrong Answer

Solution code:
def main():
    import numpy as np
    import sys
    input = sys.stdin.readline

    N = int(input())
    a = input()[:-1]
    la = []
    lc = 0
    for c in a:
        if lc != c:
          la.append(int(c))
          lc = c
    la = np.array(la)

    na, nd = np.abs, np.diff
    def f(l1):
        return na(nd(l1))

    while(len(la)>1):
       la =  f(la)

    print(*la)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
print(3)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

def next(A):
    B=[]
    for i in range(1,len(A)):
        B.append(abs(A[i]-A[i-1]))
    return B

A=next(A)

if len(A)<=5:
    while len(A)>1:
        A=next(A)
    print(A[0])

else:
    if sum(A)%2==1:
        print(1)
    elif 1 in A:
        print(0)
    else:
        if A==A[::-1]:
            print(0)
        else:
            print(2)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input()))
while a:
	a=[abs(x-y) for x,y in zip(a,a[1:]) if x!=y]
	if len(a)==1:
		print(a[0])
		exit()
print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(input())
aa = int((a[0]))
bb = int(a[N-1])

print(abs(aa-bb))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans=[]
cnt=0
for i in range(n-1):
    now = s[i+1]
    prev = s[i]
    if now == prev:
        prev=now
    else:
        if (now=='3' and prev=='1') or (now=='1' and prev=='3'):
            kouho='2'
            if ans!=[]:
                if ans[-1]=='1':
                    cnt+=1
        else:
            kouho='1'
            if ans!=[]:
                if ans[-1]=='2':
                    cnt+=1
        ans.append(kouho)
nagasa=len(ans)
if nagasa==1:
    print(ans[0])
else:
    print(cnt%2)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
n = int(input())
nums = int(input())
str_list = list(str(nums))
nums_list = []
for i in str_list:
  nums_list.append(int(i))

def keisan(nums_list):
  result = []
  for i in range(len(nums_list)-1):
    tmp = nums_list[i] - nums_list[i+1]
    if tmp < 0:
      tmp = -tmp
    result.append(tmp)
  return result

while len(nums_list) > 1:
  nums_list = keisan(nums_list)
  if len(nums_list) == nums_list.count(nums_list[0]):
    nums_list = []
    nums_list.append(0)
  
print(nums_list[0])

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
a=[int(c) for c in s]
b=a
ans=[]
for j in range(n):
    #print(b)
    for i in range(len(b)):
        if i+1<len(b):
            ans.append(abs(b[i]-b[i+1]))
    b=ans

print(ans[-1])
#print(a)

Submission status: Wrong Answer

Solution code:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
S=input()
ans=int(S[0])
A=[abs(1-ans),abs(2-ans),abs(3-ans)]
for i in range(1,n):
  s=int(S[i])
  ans=abs(ans-A[s-1])
  for j in range(3):
    A[j]=abs(A[j]-s)
print(ans)

Submission status: Wrong Answer

Solution code:


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    N=I()
    a2=input()
    a=[]
    for i in range(len(a2)):
        a.append(int(a2[i]))
    
    def calc(L):
        L1=list(L)
        nL=len(L)
        if nL%2==1:
            for i in range(nL-1):
                L1[i]=abs(L[i]-L[i+1])
            L1.pop()
                
            return L1
        else:
            L2=[]
            for i in range(0,nL,2):
                L2.append(abs(L[i]-L[i+1]))
            return L2

    while len(a)!=1:
        a=calc(a)    
    
    print(a[0])
                
        
    
main()

Submission status: Wrong Answer

Solution code:
n = int(input())
x_list = [int(x) for x in input()]
  
while True:
  if len(x_list) <= 1:
    break
  lst = []
  pre_num = -1
  for j in range(len(x_list)-1):
    num = abs(x_list[j]-x_list[j+1])
    if num == pre_num:
      continue
    else:
      lst.append(num)
      pre_num = num
  
  x_list = lst
  
if len(x_list) == 1:
  print(x_list[0])
else:
  print(0)

Submission status: Wrong Answer

Solution code:
def work(s):
    t = []

    for i in range(len(s) - 1):
        a = abs(s[i] - s[i + 1])
        if a != 0:
            t.append(a)

    if len(t) == 1:
        print(t[0])
        return
    elif len(t) == 0:
        print("0")
        return
    else:
        work(t)


n = int(input())
s = input()

lst = []

for i in range(n):
    lst.append(int(s[i]) - 1)

work(lst)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input().strip()
X = []
for c in S:
    X.append(int(c)%2)

N=N-1
i = 0
Y = []
while N:
    if N%2:
        Y.append(i)
    i += 1
    N=N//2

#print(Y)
C = [0]
for y in Y[::-1]:
    y = 2**y
#    print(y)
    tmp = []
    for c in C:
        tmp.append(c+y)
    for t in tmp:
        C.append(t)
#print(sorted(C))
r = 0
for c in C:
    r = r^X[c]
print(r)

Submission status: Wrong Answer

Solution code:
def pascal_parity(N):
    if N & -N == N:
        return [1] * N
    else:
        n = N - (1<<(N.bit_length()-1))
        p = pascal_parity(n)
        return p + [0]*(N-2*n) + p

N = int(input())
A = list(map(int, input()))
if 1 in A:
    if sum(A) % 2 == 1:
        print(1)
    else:
        print(0)
else:
    P = pascal_parity(N)
    pa = 0
    for p, a in zip(P, A):
        if p==1 and a==2:
            pa += 1
    if pa % 2 == 1:
        print(2)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
#  --*-coding:utf-8-*--

N = int(input())
S = input()
A = [int(c) for c in S]

n = N
while n > 1:
    n2 = 0
    for i in range(n-1):
        d = abs(A[i] - A[i+1])
        if d > 0:
            A[n2] = d
            n2 += 1

    n = n2

print(A[0] if n > 0 else 0)

Submission status: Wrong Answer

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

if N < 5:
    for i in range(N):
        for j in range(N-1-i):
            seq.append(abs(seq[int(1+j+i*N-i*(i-1)*0.5)] -
                           seq[int(j+i*N-i*(i-1)*0.5)]))
    print(seq[int(N*(N+1)*0.5-1)])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input()))
while a:
	f=a[-1]
	a=[abs(x-y) for x,y in zip(a,a[1:]) if x!=y]
print(f)

Submission status: Wrong Answer

Solution code:
N = int(input())
a_list = [int(a) for a in input().strip()]

while len(a_list) > 1:
#	print(a_list)
	new_a_list = []
	prev_a = -1
	for a in a_list:
		if a != 0:
			if prev_a != -1 and prev_a != a:
				new_a_list.append(abs(prev_a - a))
			prev_a = a
	a_list = new_a_list

if len(a_list) == 0:
	print(0)
else:
	print(a_list[0])

Submission status: Wrong Answer

Solution code:

N = int(input())
A = list(map(int, list(input().strip())))
tri = [A]
for i in range(min(N-1, 5)):
    nx = []
    nw = tri[-1]
    for j in range(1,len(nw)):
        nx.append(abs(nw[j]-nw[j-1]))
    tri.append(nx)
if N < 5:
    print(tri[-1][0])
    exit()

if len(tri[3]) % 2 == 0:
    tar = tri[4]
else:
    tar = tri[3]

if tar[0] ^ tar[1]:
    print(1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:

N = int(input())
A = list(map(int, list(input().strip())))
tri = [A]
for i in range(min(N-1, 5)):
    nx = []
    nw = tri[-1]
    for j in range(1,len(nw)):
        nx.append(abs(nw[j]-nw[j-1]))
    tri.append(nx)
if N <= 5:
    print(tri[-1][0])
    exit()

if len(tri[3]) % 2 == 0:
    tar = tri[4]
else:
    tar = tri[3]

if tar[0] ^ tar[1]:
    print(1)
else:
    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():
    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)
    if N%2==0:
        S2 = [0]*(N-2)
        for i in range(N - 2):
            S2[i] = abs(S[i] - S[i+1])
        S = S2
    if Counter(S)[0] % 2 == 0:
        print(0)
    else:
        print(1)
    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(map(int, list(input().strip())))
tri = [A]
for i in range(min(N-1, 9)):
    nx = []
    nw = tri[-1]
    for j in range(1,len(nw)):
        nx.append(abs(nw[j]-nw[j-1]))
    tri.append(nx)
if N <= 10:
    print(tri[-1][0])
    exit()

if len(tri[3]) % 2 == 0:
    tar = tri[4]
else:
    tar = tri[3]

if tar[0] ^ tar[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)]

cnt = 0
for a, b in zip(A, A[1:]):
    cnt += a != b

print(cnt % 2)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

def next(A):
    B=[]
    for i in range(1,len(A)):
        B.append(abs(A[i]-A[i-1]))
    return B

A=next(A)

if len(A)<=5:
    while len(A)>1:
        A=next(A)
    print(A[0])

else:
    if len(A)%2==0:
        A=next(A)

    if sum(A)%2==1:
        print(1)
    elif 1 in A:
        print(0)
    else:
        X=[A[0],A[len(A)//2],A[-1]]

        Y=[[0,2,2],[0,0,2],[2,0,0],[2,2,0]]

        if X in Y:
            print(2)
        else:
            print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in list(input())]
while True:
    take = 2**(len(str(bin(n))[2:])-1)
    for i in range(0, n-take+1):
        a.append(sum(a[i:take+i])%2)
    del a[0:n]
    n = n-take+1
    if n == 1:
        break
print(a[0])

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(c) for c in input()]
for i in range(N-1):
    B=[]
    for i in range(len(A)-1):
        x=abs(A[i+1]-A[i])
        if x:
            B.append(x)
    A=B
    if len(A)<2:
        break
print(A[-1] if A else 0)

Submission status: Wrong Answer

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

mod = 10**9+7
l = 10**6 + 3

M = [1]  # i!のmod
m = 1
for i in range(1, l):
    m = (m * i) % mod
    M.append(m)

def pow(x, y, mod):  # x**y の mod を返す関数
    ans = 1
    while y > 0:
        if y % 2 == 1:
            ans = (ans * x) % mod
        x = (x**2) % mod
        y //= 2
    return ans

def inv(x, mod):  # x の mod での逆元を返す関数
    return pow(x, mod-2, mod)

# print(inv(8,13))

MI = [0] * (l-1) +[inv(M[l-1], mod)]  # i!の逆元
for i in range(l-2, -1, -1):
    MI[i] = MI[i+1] * (i+1) % mod

def C(x, y):  # コンビネーション
    if y < 0 or y > x:
        return 0
    elif x > l:  # O(min(y, x-y))
        y = min(y, x-y)
        ans = 1
        for i in range(x, x-y, -1):
            ans = (ans * i) % mod
        return (ans * MI[y]) % mod
    else:  # O(1)
        ans = M[x]
        ans = (ans * MI[y]) % mod
        return (ans * MI[x-y]) % mod


# print(C(3,2))
ans = 0
# print(s)
if s.count("2") == 0:
    # print(s)
    for i in range(n):
        if s[i] == "3":
            ans += C(n-1, i)%2
    # print(ans)
    print(2 * (ans%2))
else:
    for i in range(n):
        if s[i] == "2":
            ans += C(n-1, i)%2
    print(ans%2)

Submission status: Wrong Answer

Solution code:
import numpy as np
x=np.random.choice([0,0,0,0,0,0,1,1,1,2])
print(x)

Submission status: Wrong Answer

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

i=[]
while j > 0:
    i.append(j%10)
    j //= 10 
i.reverse()
print(i)

n=N-1

while n!=0:
  for l in range(n):
    i[l]=abs(i[l]-i[l+1])
  n-=1
  print(i)
print(i[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
    for i in range(N-1):
        inp = np.diff(inp)
    return inp[0]

#n_1 = arr_rev.count(1)
#n_2 = arr_rev.count(2)
#n_3 = arr_rev.count(3)


print(chanto(arr_rev))