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:
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    iS = input().rstrip()

    S = []
    for i in range(N-1):
        S.append(abs(int(iS[i])-int(iS[i+1])))
    N -= 1

    f = FactorialUtils(N)
    n1 = n2 = 0
    for i in range(N):
        t = f.choose(N-1,i)
        #print(t,S[i])
        if S[i] == 1: n1 += t
        elif S[i] == 2: n2 += t
    if n1&1 and n2&1: print(1)
    elif n1&1: print(1)
    elif n2&1: print(2)
    else: print(0)
    #print(n1,n2)

class FactorialUtils:
    def __init__(self, n):
        self.fac = [1] * (n+1)
        for i in range(2, n+1): self.fac[i] = self.fac[i-1] + (i&(-i)).bit_length()

    def choose(self, n, r):
        if r < 0 or r > n: return 0
        return 2 if (self.fac[n] - self.fac[n-r] - self.fac[r]) > 0 else 1

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input()
al = []
for i in range(n-1):
    al.append(abs(int(a[i])-int(a[i+1])))
if n == 2:
    print(al[0])
else:
    if 1 in al:
        q = 1
    else:
        q = 2
        for i in range(n-1):
            if al[i] == 2:
                al[i] = 1
    p = 0
    le = len(al)
    if n % 2 == 0:
        p += al[le//2]
    for i in range(le//2):
        p = (p + (al[le//2-1-i]-al[le//2+i+(le%2)])) % 2
    print(p*q)

Submission status: Wrong Answer

Solution code:
N = input()
a = int(input())
print(a%3)

Submission status: Wrong Answer

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

mod = 3
MAX = 10 ** 6

fact = [1] * (MAX + 1)
for i in range(1, MAX + 1):
    fact[i] = (fact[i-1] * i) % mod

inv = [1] * (MAX + 1)
for i in range(2, MAX + 1):
    inv[i] = inv[mod % i] * (mod - mod // i) % mod


def comb(n, k):
    return fact[n] * inv[n - k] * inv[k] % mod


ans = 0
if a[0] <= a[1]:
    idx = 1
else:
    idx = 0

for i, (e1, e2) in enumerate(zip(a, a[1:]), 1):
    e1 = int(e1)
    e2 = int(e2)
    c = comb(n-2, i-1)
    ans += c * abs(e1 - e2) * (-1) ** (idx % 2 + 1)
    ans %= mod
    idx += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input().strip()
al = list(map(int, a))
al2 = [abs(al[i] - al[i + 1]) for i in range(len(al) - 1)]
# replace 2 to 0 if contains 1
if len(al2) % 2 == 0:
    al2 = [abs(al2[i] - al2[i + 1]) for i in range(len(al2) - 1)]


def guchoku(b):
    def calc(i, j):
        if i == 0:
            return b[j]
        return abs(calc(i - 1, j) - calc(i - 1, j + 1))

    return calc(len(b) - 1, 0)

"""
3
311231 > 2
"""
flag = False
if al2.count(1) or al2.count(2)==0:
    flag = True

flag = True
if flag and sum(al2) % 2:
    print(1)
elif flag:
    print(0)

# print("g",guchoku(al))
# guchoku([a for i, a in enumerate(al2) if i == 0 or i > N - 1 or (al2[i] == al2[i + 1] or al2[i - 1] == al2[i])]))
# while len(al2) > 1:
#     al2 = [abs(al2[i] - al2[i + 1]) for i in range(len(al2) - 1)]
#     if al2.count(1)
#         print(al2)
# print(al2[0] if len(al2) else 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:
        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 and bottom == 0:
                print(1)
            elif  left == 1 and bottom == 1 and top == 0:
                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:
from random import randint
n=int(input())
s=input()
if n<10000:
  s=list(map(int,list(s)))
  while len(s)!=1:
    s=[abs(s[i]-s[i+1])for i in range(len(s)-1)]
  print(s[0])
  exit()
if set(list(s))=={"1","3"}:print(randint(0,1)*2)
else:print(randint(0,1))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
#sys.setrecursionlimit(150000)


def solve(N: int, a: "List[int]"):
    #print(N,a)
    c=[0,0,0]
    for i in range(N-1):
        a[1][i]=abs(a[0][i]-a[0][i+1])
        c[a[1][i]]+=1

    if (c[1]==0 and 
        (N%2==0 or
          (N%2==1 and 
            (
              (c[0]==1 and (a[1][0]==0 or a[1][N-1]==0)) or 
              (c[2]==1 and (a[1][0]==2 or a[1][N-1]==2))
            )
          )
        )):
        print(2)
    #elif c[1]!=0 and (c[0]!=0 or c[2]!=0):
    #    print(1)
    else:
        print(0)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = next(tokens)
    a=[[0]*N for _ in range(2)]
    for i in range(N):
        a[0][i]=int(s[i])
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
print('2')

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb
import math

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


def zip(num):
  count = 1
  result = []
  for i in range(len(num)-1):
        if num[i] == num[i+1]:
           count = count + 1
        
        else:
           result.append(num[i])
           count = 1
  if len(result) == 0:
    return [0] 
  result.append(num[len(num)-1]) 

  return result
while len(num) != 1:
  num = zip(num)
  if len(num) == 1:
    break
  num = [abs(num[i]-num[i+1]) for i in range(len(num)-1)]
print(num[0])

Submission status: Wrong Answer

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

sp = len(''.join(set(a)))
def count_0(a):
    i = 0
    count = 0
    for i in range(0, N):
        if a[i] == 0:
            count = count +1
            i = i +1
        else:
            return count
if sp == 1:
    print(0)
elif sp == 2:
    if count_0(a)%2 ==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:
    if count_0(a)%2 ==1:
        add = 1
    else:
        add = 0

    a =  a.replace('1', '')
    if a[0] == '2':
        add = add+1
    else:
        add = 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,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

mod = 10**9+7 #出力の制限

# a = cmb(n,r)
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""
n = onem()
N = n

a = input().split()[0]
a = list(map(int,a))
po = 0
po = abs(abs(a[-1]-a[-2]) - abs(a[1]-a[0]))
print(po%3)

Submission status: Wrong Answer

Solution code:
from itertools import product
from time import time
#N = int(input())
#S = input()
N = 10
S = "2311312312"
#N = 10**5
#S = "1"*N

def unique(S):
    return [S[i] for i in range(len(S)) if i == 0 or S[i-1] != S[i]]

    
def solve(S):
    a = list(map(int,S))
    b = [abs(x-y) for x,y in zip(a,a[1:])]
    c = [x % 2 for x in b]
    if max(c) > 0:
        n = len(c)-1
        s = sum(c[1:-1]) % 2
        k = (s * n) % 2
        return c[0] ^ c[-1] ^ k
    else:
        b=unique(b)
        cnt2 = b.count(2)
        if cnt2 == 1:
            return 2
        else:
            return 0


print(solve(S))

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 N==2:
        ans = abs(int(A[1])-int(A[0]))
        print(ans)
        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)==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:
from itertools import product


def read():
    N = int(input())
    A = map(int, list(input()))
    return N, A


def compress(N, A, chunk=16):
    buf = 0
    b = list()
    digits = list()
    for i, a in enumerate(A):
        buf = (buf << 2) | a
        if (i+1) % chunk == 0 or i == N-1:
            b.append(buf)
            d = (N % chunk) if i == N-1 else chunk
            digits.append(d)
            buf = 0
    return b, digits

def solve(N, A):
    chunk = 11
    B, digits = compress(N, A, chunk=chunk)
    mask = (1 << (chunk * 2 - 2)) - 1
    for j in range(N):
        for i in range(len(B)):
            # [1, chunk]
            x = B[i]
            # [2, chunk+1]
            if i == len(B) - 1:
                y = ((B[i] << 2) & mask)
            else:
                y = ((B[i] << 2) & mask) + (B[i+1] & 0x11)
            u = (x ^ y) >> 2
            B[i] = u
    return B[0] & 0x11

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Wrong Answer

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

def mod2_pascal(n):
    res = []
    for r in range(n+1):
        res.append(1 if n == (r | (n-r)) else 0)
    return res

b = []

if N >= 3:
    for i in range(N-1):
        b.append(abs(a[i]-a[i+1]))
    mod2_line = mod2_pascal(N-2)
    ans = 0
    for i in range(N-1):
        if mod2_line[i] == 1:
            ans += b[i]
    if b.count(2) % 2 == 1 and b.count(0) == N-1 - b.count(2):
        print(2)
    else:
        print(ans % 2)

else:
    print(abs(a[1]-a[0]))

Submission status: Wrong Answer

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

from collections import Counter

b = [abs(a[i+1]-a[i]) for i in range(N-1)]
c = Counter(b)
if c[1] == 0 and c[2]==1 and (b[0] ==2 or b[-1] ==2):
  print(2)
elif c[1] == 0 and c[0]==1 and (b[0] ==0 or a[-1] ==0):
  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:
# 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=True
    cnt1=0
    cnt2=0
    
    for i in range(len(B)):
        if B[i]==1:
            cnt1+=1
        elif B[i]==2:
            cnt2+=1
    
    for i in range(len(B)//2):
        if B[i]!=B[-1-i]:
            flg0=False
    
    if cnt1==len(B)//2 or flg0:
        print(0)
    elif cnt1==0 and cnt2!=len(B)//2 and cnt2>0 and cnt2!=len(B):
        print(2)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input()
x = []
x.extend([int(i) for i in a])

if len(x) > 1:
    x = [abs(x[i] - x[i + 1]) for i in range(len(x) - 1)]


# もし1と0だけだったら簡単そう
# 2は012を210にする効果しかない
# もし2を0として考えて、答えが0になるなら、
# 2が偶数個ならば0, 2が奇数個ならば2といえそうでいえない
# 1が混ざっている条件で最後の答えが2になることはあり得ない->2を0と考えてよい
MOD = 10 ** 9 + 7
tmp_nck = 1
if 1 in x:
    flag = True
    x = [1 if i == 1 else 0 for i in x]
else:
    flag = False
    x = [1 if i == 2 else 0 for i in x]
c=0
n=len(x)
if x[0]==1:
    c+=1
for i in range(1,n):
    tmp_nck*=(n-i+1) *pow(i-1, MOD -2, MOD)
    tmp_nck%MOD
    if x[i] == 1:
        c+=tmp_nck

print(c%2)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

mod = 10**9+7 #出力の制限

# a = cmb(n,r)
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""
n = onem()
N = n

a = input().split()[0]
a = list(map(int,a))
po = 0
po = abs(abs(a[0]-a[-2]) - abs(a[1]-a[-1]))
print(po%3)

Submission status: Wrong Answer

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

b = [abs(a[i+1]-a[i])for i in range(n-1) if a[i+1]!=a[i]]
if len(b)==0:
        print(0)
        exit()
cnt = 0
prev = b[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(0)
else: print(b[0])

Submission status: Wrong Answer

Solution code:

def conv(ar,n):
    ans = []
    for i in range(n):
        ans.append(int(ar[i]))
    return ans
def main(array):
    ans = 0
    for i in range(len(array)-1):
        if array[i] - array[i+1] == 2 or array[i+1] - array[i] == 2:
            ans = ans + 1
    print(ans % 2)
n = int(input())
array = conv(input(),n)

p = 0
for i in range(len(array)-1):
    if array[i] - array[i+1] == 2 or array[i+1] - array[i] == 2:
        p = p+1
if p == 1:
    print(2)
else:
    if array[0] == 2:
        if array[-1] == 2:
            print(0)
        elif array[-1] == 1 or array[-1] == 3:
            print(1)
    elif array[0] == 1:
        if array[-1] == 2:
            print(1)
        else:
            print(main(array))
        
        
    elif array[0] == 3:
        if array[-1] == 2:
            print(1)
        else:
            print(main(array))

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

print(1 if len(A) >= 10000 else 0)

Submission status: Wrong Answer

Solution code:

N = int(input())
n_list = list(input())



def f(N,n_list):
    sym=True
    half = N//2

    for i in range(half):
        pre = str(abs(int(n_list[i])-2))
        post = str(abs(int(n_list[-(i+1)])-2))
        if pre!=post:
            sym = False
    if sym:
        ans=0
    else:
        if "2" in n_list:
            ans=1
        else:
            ans=2
    return ans 

if N%2==1:
    ans = f(N,n_list)
else:
    ans = abs(f(N-1,n_list[1:]) - f(N-1,n_list[:-2]))

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    *a, = map(int, input())

    if N <= 10 ** 4:
        while len(a) > 1:
            *a, = (0 if a1 % 2 == a2 % 2 else 1 for a1, a2 in zip(a, a[1:]))
        print(a[0])
    else:
        if len(a) % 2 == 0:
            *a, = (0 if a1 % 2 == a2 % 2 else 1 for a1, a2 in zip(a, a[1:]))

        if a[0] % 2 == a[-1] % 2:
            print(0)
        else:
            print(1)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

Submission status: Wrong Answer

Solution code:
N = int(input())
x = input()
for _ in range(N-1):
    y = []
    for i in range(len(x)-1):
        z = abs(int(x[i]) - int(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()


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 % 6))
                ys.append(val)
                if val == 2:
                    found_2 = True
                count = 0
            else:
                count += 1
        xs = ys + [0] * (count % 6)
        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:
print('1')

Submission status: Wrong Answer

Solution code:
import numpy as np
 
N=int(input())
A = input()
a = np.array([int(A[i]) for i in range(N)])
while len(a) >1:
  a = np.absolute(np.diff(np.absolute(a),1))
  if (np.amax(a) - np.amin(a)) == 0:
    print(0)
    break
  if (np.amax(a) - np.amin(a)) == 1:
    if list(a) == list(a).reverse():
      print(0)
      break
    else:
      print(1)
      break
  if len(a) == 1:  
    print(a[0])
    break

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 len(tmp) == 0:  # all zero
            return 0
        if len(tmp) == 1:  # only single value
            return tmp[0]

        if np.all(tmp == 2):
            return 2
        else:
            if diff_1[0] == 0 and diff_1[len(diff_1)-1] == 0:
                if len(tmp[tmp == 1]) % 2 == 1 and len(diff_1) % 2 == 0:
                    return 0
                elif len(tmp[tmp == 1]) % 2 == 1 and len(diff_1) % 2 != 0:
                    return 1
                elif len(tmp[tmp == 1]) % 2 == 0 and len(diff_1) % 2 == 0:
                    return 1
                else:
                    return 0
            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:
n = int(input())
 
numlist = list(input())

l_numlist = len(numlist)

while l_numlist > 2:
 
    for a in range(0, l_numlist-2):
        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 l_numlist == 0:
  print(0)
elif l_numlist == 1:
  print(numlist[0])
else:
  print(abs(int(numlist[0]) - int(numlist[1])))

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):
    if j+1<len(b):
        if b[j]==0 or b[j+1]==0:
            ans.append(max(b[j],b[j+1]))
        else:
            ans.append(abs(b[j]-b[j+1]))
    b=ans
    if len(ans)>1:
        ans=[]

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

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=([abs(temp[j+1]-temp[j]) for j in range(len(temp)-1) if (temp[j+1]-temp[j])!=0])
    temp=ans
    print(len(ans)%2)
"""         
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""

if __name__=="__main__":resolve()

Submission status: Wrong Answer

Solution code:
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    iS = input().rstrip()

    S = []
    for i in range(N-1):
        S.append(abs(int(iS[i])-int(iS[i+1])))
    N -= 1

    f = FactorialUtils(N)
    n1 = n2 = 0
    for i in range(N):
        t = f.choose(N-1,i)
        #print(t,S[i])
        if S[i] == 1: n1 += t
        elif S[i] == 2: n2 += t
    if n1&1 and n2&1: print(1)
    elif n1&1: print(1)
    elif n2&1: print(2)
    else: print(0)
    #print(n1,n2)

class FactorialUtils:
    def __init__(self, n):
        self.fac = [1] * (n+1)
        for i in range(2, n+1): self.fac[i] = self.fac[i-1] + (i&(-i))

    def choose(self, n, r):
        if r < 0 or r > n: return 0
        return 2 if (self.fac[n] - self.fac[n-r] - self.fac[r]) > 0 else 1

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import copy

def main():

    n = int(input())
    a = list(input())
    a_1 = []
    flg = 1
    z = 0
    while flg == 1:
        a_1 = []
        z= 0
        for i, aa in enumerate(a):
            ia = int(aa)
            if i+1 == len(a):
                break

            ia2 = int(a[i+1])
            if i == 0:
                a_1.append(abs(ia-ia2))
            else:
                if abs(ia-ia2) == a_1[-1]:
                    z=1
                    continue
                else:
                    a_1.append(abs(ia-ia2))
        a = a_1.copy()
        if len(a_1) == 1:
            if z == 1:
                print(0)
            else:
                print(a_1[0])
            return


if __name__ == '__main__':
    main()

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

  ll=[0]+ll

  # # 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 abs(ans[0]-ans[-1])
  elif len(ans)==3:
    return abs(ans[0]-ans[1])
  return 0

# main()
print(main())

Submission status: Wrong Answer

Solution code:
a=int(input())
b=input()
b=list(map(int,b))
l=[]
for i in range(len(b)-1):
    c = abs(b[i] - b[i + 1])
    l.append(c)
l1=set(l)
print(l1)
l2=list(l1)
if len(l1)==1:
    print(int("0"))
else:
    print(l2[0])

Submission status: Wrong Answer

Solution code:
import sys
print('0')
sys.exit()

Submission status: Wrong Answer

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

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

while len(A) > 1:
    if len(A) % 2 == 1:
        for i in range(len(A)-1):
            A[i] = abs(A[i]-A[i+1])
        A.pop()
    B = []
    for i in range(len(A)//2):
        B.append(abs(A[i*2]-A[i*2+1]))
    A = B[:]
print(A[0])

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

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

a_new = a
a = []
while len(a_new) != 1 and len(a_new) != 0:
    a = a_new
    a_new = []
    a_next = []

    n = len(a)
    start = 0
    while True:
        if a[start] == 0:
            a_next.append(a[start])
            start += 1
            if start == n:
                start -= 1
                break
        else:
            break
    
    a_end = []
    end = 0
    while True:
        if a[n-end-1] == 0:
            a_end.append(a[n-end-1])
            end += 1
            if end == n:
                end -= 1
                break
        else:
            break

    for i in range(start, n-end):
        if a[i] != 0:
            a_next.append(a[i])
    
    if start+end < n:
        a_next.extend(a_end[::-1])
    else:
        a_next = []

    for i in range(len(a_next)-1):
        a_new.append(abs(a_next[i]-a_next[i+1]))

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