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())
aa = list(map(lambda x: int(x)-1, list(input())))

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

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

ans = 0
for i, a in enumerate([a % 2 for a in aa]):
    p = parity(n-1, i)
    if p == 1:
        ans = ab(ans - a)

if ans == 1:
    print(1)
    exit(0)

if 1 in aa:
    print(2)
    exit(0)

ans = 0
for i, a in enumerate([a // 2 for a in aa]):
    p = parity(n-1, i)
    if p == 1:
        ans = ab(ans - a)
print(ans * 2)

Submission status: Wrong Answer

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

ans = []
for r in range(n - 1):
    if (n - 2)^ r ^ (n - 2 - r) == 0:
        ans.append(int(a[r]))

res = 0
for i in ans:
    res = abs(res - i)
print(res)

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
for i in range(1, n):
    ans += comb(n-2, i-1)
    ans %= mod

if ans % 2 == 0 and "2" in a:
    ans = 0

print(ans)

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]
    if len(temp)==1:
        print(temp[0])
        return
    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
sys.setrecursionlimit(10**9)

N = int(input())
A = list(map(int,input()))
X = 1 in A

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[:]

if X:
    A[0] %= 2
print(A[0])

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

N = int(input())
a = input()
# a = '1' * N
if '2' in a:
    flg = False
else:
    flg = True

def bit_count(i):
    res = 0
    while ((i>0) and (i&1 == False)):
        i  >>=1
        res += 1
        # print(i)
    return res

f = [0]
for i in range(N//2):
    f.append(f[-1] + bit_count(N-1-i) - bit_count(i+1))

def nCr(n, r):
    if r > n-r: r = n-r
    if f[r] == 0:   # 奇数
        return 1
    else:
        return 0

ans = 0
for i in range(N):
    now = int(a[i]) - 1     # 全体を1引いても同じ
    if flg:
        now //= 2
    if now%2:
        # print(i, nCr(N-1, i))
        ans += now * (nCr(N-1, i) % 2)
        ans %= 2
# print(f)
print(ans)

Submission status: Wrong Answer

Solution code:
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------


from collections import defaultdict
d = defaultdict(str)

d['00']='0'
d['01']='1'
d['02']='2'
d['03']='3'

d['10']='1'
d['11']='0'
d['12']='1'
d['13']='2'

d['20']='2'
d['21']='1'
d['22']='0'
d['23']='1'

d['30']='3'
d['31']='2'
d['32']='1'
d['33']='0'


#p(d)

x=""
iLen=2
iLenMax=5

L=[]
for k, v in d.items():
	if len(k)==iLen: L.append([k,v])

while iLen<iLenMax:
	di=list(L)
	L=[]
	for k, v in di:
		#p(k,v)
		if len(k)<iLen: continue
		for c01 in ['0','1','2','3']:
			x = k+c01
			
			while len(x)>1:
				a = v
				b = d[x[1:-1]]
				x = a+b
			
			d[k+c01]=x
			L.append([k+c01,x])

	iLen+=1

##p(d)
#for k, v in d.items():
#	if len(k)>11: p(k,v)


#-------------------------------------------------------------------
N = int(input())						# 5

s = input()

if len(s)<iLenMax:

	g=[]
	g.append(s)

	z=0
	#for i in range(N):
	for j in range(N-1):
		s = g[j]
		x=""
		for k in range(1,len(s)):
			a = int(s[k-1])
			b = int(s[k-0])
			c = abs(a-b)
			x = x + str(c)

		g.append(x)

	#p(g)
	print(g[N-1])

else:

	z = s

#	p(z,len(z))
	while len(z)>1:

		iLen = min(iLenMax, len(z))
#		p("iLen, len(z), ",iLen, len(z))
		y=""
		for i in range(len(z)-iLen+1):
			a=b=e=f=h=""
			
			a = z[i+0:i+0+iLen]
			b = z[i+1:i+1+iLen]
			
			e = str(d[a])
			f = str(d[b])
			
			h = e+f
			y = y + d[h]
#			p("i,a,b,e,f,h,y, ",i,a,b,e,f,h,y)
		
		z=y

	print(z)

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=="2":
                flag = False
                break
        if flag:
            print(2)
            return
    if A[-1]=="3":
        flag = True
        for s in A[:N-2]:
            if s=="2":
                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:
print(2)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
a = input()
if n == 2:
  print(abs(int(a[0])-int(a[1])))
  sys.exit()

key = [0]*(n-1)
judge = False
for i in range(n-1):
  key[i] = abs(int(a[i])-int(a[i+1]))
  if key[i] == 1:
    judge = True

comb = 1
ans = 0
for i in range(n-1):
  ans += comb*key[i]
  ans %= 2
  comb *= (n-3-i)
  comb *= pow(i+1, 7, 2)
if ans == 0 and judge == False:
  ans = 2
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    a = list(map(int, list(input())))
    if N == 2:
        print(abs(a[0]-a[1]))
        exit()
    a.sort(reverse=True)

    idx = []
    lis = [0]*(N-2)
    for i in range(N-2):
        lis[i] = abs(a[i]-2*a[i+1]+a[i+2])
    l = []
    for n in lis:
        if n != 0:
            l.append(n)
    if not l:
        print(0)
        exit()
    while len(l) >= 2:
        next_l = []
        for i in range(len(l)-1):
            next_l.append(abs(l[i]-l[i+1]))
        l = next_l.copy()
    print(l[0])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
print(0)

Submission status: Wrong Answer

Solution code:
def calc(x, y):
  if x-y == 0:
    return 0
  elif (((x-y)==1) or(x-y)==-1):
    return 1
  else:
    return 2
  
N = int(input())
a =str(input())
alist = [0] * N
cnt = [0] * 3
for i, a in enumerate(a):
  alist[i] = int(a)-1
  if alist[i]==0:
    cnt[0] += 1
  elif alist[i]==1:
    cnt[1] += 1
  else:
    cnt[2] += 1
count = 0
if N<4:
  for j in range(N-1):
    for i in range(N-j-1):
      alist[i] = calc(alist[i],alist[i+1])
  print(alist[0])
  exit()
                      
for j in range((N+1)%4):
  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:
  print(count % 2)
else:
  print(count % 4)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(input())
a_n = [int(s) for s in a]#配列を全て数値に変更
point = n - 2#配列の代入を始める場所
for i in range(point):
    for ii in range(point+1):
        #print('ii:{:.3f}'.format(a_n[ii]))
        #print('ii+1:{:.3f}'.format(a_n[ii+1]))
        a_n[ii] = abs(a_n[ii] - a_n[ii+1])

    point =- 1
print(a_n[0])

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    a = list(map(int, list(input())))
    if N == 2:
        print(abs(a[0]-a[1]))
        exit()
    a.sort(reverse=True)

    idx = []
    lis = [0]*(N-2)
    for i in range(N-2):
        lis[i] = abs(a[i]-2*a[i+1]+a[i+2])
    l = []
    for n in lis:
        if n != 0:
            l.append(n)
    if not l:
        print(0)
        exit()
    # while len(l) >= 2:
    #     next_l = []
    #     for i in range(len(l)-1):
    #         next_l.append(abs(l[i]-l[i+1]))
    #     l = next_l.copy()
    print(l[0])

if __name__ == '__main__':
    main()

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)]
b = deque()
flag = False
cnt = 0
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]:
            flag = True
            cnt += 1
    if i != N-2:
        flag = False
if len(b) == 1:
    print(b[0])
    exit()

if flag and cnt == 1:
    print(1)
else:
    print(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] == "1":
            count = count +1
            i = i +1
        else:
            return count

def count_02(a):
    i = 0
    count = 0
    for i in range(0, N):
        if a[i] == "2":
            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:

    a =  a.replace('1', '')
    if count_02(a)%2 == 1:
        add = 1
    else:
        add = 0

    a = a.replace('2', '')
    if (len(a)+add) % 2 == 1:
        print(1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
    
def solve(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:
        c = [x//2 for x in b]
        n = len(c)-1
        s = sum(c[1:-1]) % 2
        k = (s * n) % 2
        return (c[0] ^ c[-1] ^ k)*2


print(solve(S))

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] == "1":
            count = count +1
            i = i +1
        else:
            return count

def count_02(a):
    i = 0
    count = 0
    for i in range(0, N):
        if a[i] == "2":
            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 count_02(a)%2 == 1:
        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
i=int(input())
s=input()
if s[0]=="1" and s[1]=="1":
  s="1"+s.lstrip("1")
if s[-1] == "1":
  if len(s)>1:
    if s[-2] == "1":
      s=s.rstrip("1") + "1"
if len(s) <=1:
  print(s)
  sys.exit( )
a=[]
for k in range(len(s)-1):
  b=abs((int(s[k])-int(s[k+1])))
  a.append(b)
while len(a)>1:
  c=[]
  d=0
  for k in range(len(a)-1):
    b=abs(a[k]-a[k+1])
    if d==0:
      if len(c) == 1:
        if b == 0 and c[0] == 0:
          continue
        else:
          d=1
          c.append(b)
      else:
        c.append(b)
        d=1
    else:
      c.append(b)
    #str(abs(int(s[k])-int(s[k+1])))
    #print(a[k])
  #print("".join(a))
  a=c
  #s="".join(a)
  #s="1"
print(str(a[0]))

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
for i, (e1, e2) in enumerate(zip(a, a[1:]), 1):
    e1 = int(e1)
    e2 = int(e2)
    if e1 < e2:
        idx = 0
    else:
        idx = 1
    c = comb(n-2, i-1)
    ans += c * abs(e1 - e2) * (-1) ** idx
    ans %= mod
    idx += 1

print(ans)

Submission status: Wrong Answer

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

N = int(input())
X = list(map(int,input()))
A = []
for i in range(N):
    A.append(X[i]%2)
if not 1 in X:
    if min(X) == 0 and max(X) == 2:
        print(2)
        exit()
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:

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[:-1]))

print(ans)

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] == 1:
            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', '')

    a = a.replace('2', '')
    if (len(a)+add) % 2 == 1:
        print(1)
    else:
        print(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()
flag = False
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
            flag = True
    if i != N-2:
        flag = False
if len(b) == 1:
    print(b[0])
    exit()

if not flag:
    print(0)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

N = int(input())
a = list(input())
a = list(map(int, a))
a.sort()
if 1 in a:
    if 2 in a:
        if 3 in a:
            l = a.index(2) - 1
            r = a.index(3) - 1
            if r - l == 1:
                print(1)
            else:
                print(0)
        else:
            print(1)
    else:
        if 3 in a:
            print(2)
        else:
            print(0)
else:
    if 2 in a:
        if 3 in a:
            print(1)
        else:
            print(0)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
import random
print(random.randint(0, 1) % 2)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
s=input()
for i in range(n):
    a.append(int(s[i]))
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=[i for i in b]
if a:
    print(a[0])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import random
l=[0,1,2]
print(random.choice(l))

Submission status: Wrong Answer

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

N = int(input())
X = list(map(int,input()))
A = []
for i in range(N):
    A.append(X[i]%2)

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:
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
if flag:
    print(c%2)
else:
    if c%2 == 1:
        print(2)
    else:
        print(0)

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)
l2=list(l1)
if len(l1)==1:
    print(int("0"))
else:
    print(l2[-1]-l2[-2])

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] == 1:
            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:
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 array[i] - array[i+1] != 0:
        p = 0
        i = 1000000000000000
if p % 2 == 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 = 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 = 0
else:
    idx = 1

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())
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 N == 2:
  print(abs(a[0]-a[1]))
else:
  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:
def main():
  n = int(input())
  a = list(map(int,input()))
  k=0
  for j in range(n):
    for i in range(n-j):
      a.append(abs(a[i+j+k]-a[i+j+1+k]))
    #print(a)
    if j==0:
      k+=n-1
    else:
      k+-n-j
  print(a[-1])    
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input()
a1 = 0
a2 = 0
a3 = 0
for i in range(n):
  if a[i] == "1":
    a1 += 1
  elif a[i] == "3":
    a3 += 1
if n == 2 and a1 == 1 and a3 == 1:
  print(2)
elif a == "213" or a == "132" or a == "231" or a == "312":
  print(1)
elif a1 == 1 and a3 == 0:
  print(1)
elif a1 == 0 and a3 == 1:
  print(1)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(input())
a_n = [int(s) for s in a]#配列を全て数値に変更
point = n - 2#配列の代入を始める場所
all_c = int((n-1)*(n-1+1)/2)#計算回数
for i in range(point):
    for ii in range(point,-1,-1):
        a_n[ii] =- a_n[ii+1]
        all_c =- 1
        

    point =- 1
print(a_n[0])

Submission status: Wrong Answer

Solution code:
from random import randint
n=int(input())
s=input()
t=s
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(t))=={"1","3"}:print(randint(0,1)*2)
else:print(randint(0,1))

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 or cnt2==len(B):
        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()
# a = '1' * N

def bit_count(i):
    res = 0
    while ((i>0) and (i&1 == False)):
        i  >>=1
        res += 1
        # print(i)
    return res

f = [0]
for i in range(N//2):
    f.append(f[-1] + bit_count(N-1-i) - bit_count(i+1))

def nCr(n, r):
    if r > n-r: r = n-r
    if f[r] == 0:   # 奇数
        return 1
    else:
        return 0

ans = 0
for i in range(N):
    now = int(a[i])
    if now%2:
        # print(i, nCr(N-1, i))
        ans += now * (nCr(N-1, i) % 2)
        ans %= 2
# print(f)
print(ans)

# # print(nCr(1000000, 500000))
# n = 25
# for i in range(n):
#     res = nCr(n-1, i)
#     if res%2:
#         print(i, res)

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-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 l_numlist == 0:
  print(0)
elif l_numlist == 1:
  print(numlist[0])
else:
  print(abs(int(numlist[0]) - int(numlist[1])))