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

if n <= 100:
    for nn in range(n-1):
        aa = [ab(aa[i]-aa[i+1]) for i in range(n-nn-1)]
    print(aa[0])

else:
    ans = 0
    for i, a in enumerate(aa):
        p = parity(n-1, i)
        print(i, a, p, ans)
        if p == 1:
            ans = ans - a
            if ans < 0:
                ans *= -1
    print(ans)

Submission status: Wrong Answer

Solution code:

N = int(input())
a = list(input())
for i in range(N):
    a[i] = int(a[i])

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

    return output

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

    return count%2

a = process(a)


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

Submission status: Wrong Answer

Solution code:
N=int(input())

s=list(input())

b=[]

while True:
    for i in range(len(s)-1):

        a=abs(int(s[i])-int(s[i+1]))
        b.append(a)
    print(b)
    s=b
    b=[]
    if len(s)>1:
        continue
    elif len(s)==1:
        print(s[0])
        break

Submission status: Wrong Answer

Solution code:
N=10**6
mod=1000000007
fac=[1]*(N+1)
for i in range(1,N+1):
    fac[i]=fac[i-1]*i%mod
inv_fac=[1]*(N+1)
inv_fac[N]=pow(fac[N],mod-2,mod)
for i in range(N-1,0,-1):
    inv_fac[i]=inv_fac[i+1]*(i+1)%mod
def nCr(n,r):
    if n<0 or r<0 or r>n:
        return 0
    return fac[n]*inv_fac[r]%mod*inv_fac[n-r]%mod

n=int(input())
A=list(input())
for i in range(n):
  	A[i]=int(A[i])
AA=[0]*(n-1)
flag=0
for i in range(n-1):
    AA[i]=abs(A[i+1]-A[i])
    if AA[i]==1:
        flag=1
if flag==0:
    for i in range(n-1):
        AA[i]//=2
ans=0
for i in range(n-1):
    ans=(ans+nCr(n-2,i)*AA[i])%2
if flag==1:
    print(ans)
else:
    print(ans*2)

Submission status: Wrong Answer

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

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

ans = []

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 2回目で0か2しかない場合と1がある場合
# 1がある時は2は0に変換して良い
N = ir()
A = np.array(list(map(int, sr())))
A = np.abs(np.diff(A))
N -= 1
bl = False
if 1 not in set(A):
    bl = True
if N&1:
    A = np.abs(np.diff(A))

cnt = np.count_nonzero(A) % 2
print(cnt * 2 if bl else cnt)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

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

import numpy as np

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

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

b = np.array(a)

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

print(b[0])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N=int(input())
a = input()
b = list(a)
c =list(map(int,b))
d= []
for s in range(N-1):
  r = abs(c[s] -c[s+1])
  d.append(r)
for i in range(N-1):
  for p in range(N-i):
    l = abs(d[-N+1] - d[-N+2])
    d.append(l)
print(d[-1])

Submission status: Wrong Answer

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

sp = len(''.join(set(a)))
if sp == 1:
    print(0)
elif sp == 2:
    a =  a.replace('0', '')
    a = str(int(a) - int(len(a)*'1'))
    if  not "2" in a:
        if a.count("1") % 2 == 1:
            print(1)
        else:
            print(0)
    elif not "1" in a:
        if a.count("2") % 2 == 1:
            print(2)
        else:
            print(0)
    else:
        a = str(int(a) - int(len(a) * '1'))
        if a.count("1") % 2 == 1:
            print(1)
        else:
            print(0)
else:
    a =  a.replace('0', '')
    a = str(int(a) - int(len(a)*'1'))
    b = a.replace('0', '')
    b = str(int(b) - int(len(b) * '1'))
    if b.count("1") % 2 == 1:
        print(1)
    else:
        print(0)

Submission status: Wrong Answer

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# main()
print(main())

Submission status: Wrong Answer

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



def c(n,k):
  return 1 if(k<=0 or n<=k) else c(n-1, k-1) + c(n-1, k)


for i in range(N):
  B = [c(i,j) for j in range(i+1)]


#print(B)
##N = 奇数
ans = 0
for m in range(N):
    ans =+ (-1)**(m+1)*(B[m]*A[m])
    #print(ans)
print(abs(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x)-1 for x in input()]

am = [a[i] % 2 for i in range(n)]

tmp = 0
ans = am[0] % 2

for i in range(1, n):
    ind = 0
    k = (n-i) & -(n-i)
    while k > 1:
        k = k // 2
        ind += 1
    kk = i & -i
    while kk > 1:
        kk = kk // 2
        ind -= 1
    tmp += ind
    if tmp == 0:
        ans += am[i]
        ans %= 2

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

# あとは0か2かの判定！

if (0 in a) and (1 not in a) and (2 in a) and a != a[::-1]:
    print(2)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
sys.setrecursionlimit(1000000)
# N = int(input())
# numbers = input()
# input_arr = np.array([int(i) for i in numbers])


input_arr = np.random.choice(3, 3000)
def memoize(f): #メモ化関数
    table = {}
    def func(*args):
        if not len(args) in table:
            table[len(args)] = f(*args)
        return table[len(args)]
    return func

@memoize
def myfunc(arr):
    if(len(arr)) == 1:
        return arr[0]
    # print(arr)
    return myfunc(np.abs(arr[1:] - arr[:-1]))

print(myfunc(input_arr))

Submission status: Wrong Answer

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

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

ans = []

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

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

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

Submission status: Wrong Answer

Solution code:
class PERM_COMB_MOD():
    # http://drken1215.hatenablog.com/entry/2018/06/08/210000
    def __init__(self, max_n=510000, mod=10**9+7):
        self.fac = [0]*max_n
        self.finv = [0]*max_n
        self.inv = [0]*max_n
        self.fac[0] = self.fac[1] = 1
        self.finv[0] = self.finv[1] = 1
        self.inv[1] = 1
        self.max = max_n
        self.mod = mod
        self._maesyori()

    def _maesyori(self):
        for i in range(2,self.max):
            self.fac[i] = self.fac[i-1] * i % self.mod
            self.inv[i] = self.mod - self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.finv[i] = self.finv[i-1] * self.inv[i] % self.mod

    def comb(self, n, k):
        if n < k : return 0
        if n < 0 or k < 0:return 0
        return self.fac[n] * (self.finv[k] * self.finv[n-k] % self.mod) % self.mod

n = int(input())
a = list(map(lambda x: int(x)-1, input()))

f = 1 in a
if f:
    a = [int(i==1) for i in a]
else:
    a = [int(i==2) for i in a]

ans = 0
PCM = PERM_COMB_MOD(n+100, mod=2)
for i in range(n):
    ans += PCM.comb(n-1,i)*a[i]

ans %= 2
if not f:
    ans *= 2

print(ans)

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
mod = 3
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
def p(n,r):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
a = list(input())

po = 0
for i in range(n):
    if i == 0 or i == n-1:
        po = abs(po-2*(int(a[i])))
    else:
        po = abs(po-(int(a[i])))
    po %= 3
print(-po % 3)

Submission status: Wrong Answer

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

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

    
        kuri=kuri-1

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

Submission status: Wrong Answer

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

a_ = [0]*(N-1)
for i in range(N-1):
    a_[i] = abs(a[i]-a[i+1])

print(sum(a_)%3)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if len(a) == 1 :
    print(a)
    exit()
elif len(set(a)) == 1 :
    print(0)
    exit()

b = ""
for i in range(1,len(a)) :
    b += str(abs(int(a[i]) - int(a[i-1])))

b = b.replace("010", "")
b = b.replace("020", "")
b = b.replace("0", "")

if len(b) == 1 :
    print(b)
    exit()
elif len(set(b)) == 1 :
    print("0")
    exit()

c = 0
for i in range(1,len(b)) :
    if b[i] != b[i-1] :
        c += 1

if c == 1 :
    print(1)
else :
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
array = []
array += input()
array = list(map(int,array))
while len(array) != 1:
    start = 0
    end = 0
    for i in range(len(array)-1):
        if(abs(array[i]-array[i+1])):
            pass
        else:
            end = i
            for j in range(start,end):
                array[j] = 0
            start = end
    array.pop()
print(array[0])

Submission status: Wrong Answer

Solution code:
num = int(input())
a = list(input())
a_i = [int(i) for i in a]

def calcabs(list):
    result = []
    for x in range(len(list)):
        val = abs(list[x] - list[x - 1])
        tempcount = 0
        if x == 0: continue
        elif val == 0: 
            tempcount += 1
        else: 
            if len(result) == 0: result.append(val)
            else: 
                for x in range(tempcount):
                    result.append(0)
                result.append(val)
    return result

while len(a_i) > 1:
    a_i = calcabs(a_i)
if len(a_i) == 0: print(0)
elif len(a_i) == 1: print(a_i[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
array = []
array += input()
array = list(map(int,array))
while len(array) != 1:
    start = 0
    end = 0
    for i in range(len(array)-1):
        if(abs(array[i]-array[i+1])):
            pass
        else:
            end = i
            for j in range(start,end):
                array[j] = 0
            start = end
    array.pop()
print(array)

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 or i in (0,len(A)-2):
            B.append(x)
    A=B
    if len(A)<2:
        break
print(A[-1] if A else 0)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

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

import numpy as np

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

if n > 1000:
    a = a[:1000]
    n = 1000

b = np.array(a)

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

print(b[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input()
if len(''.join(set(a))) == 1:
    print(0)
else:
    a =  a.replace('0', '')
    a = str(int(a) - int(len(a)*'1'))
    if  not "2" in a:
        if a.count("1") % 2 == 1:
            print(1)
        else:
            print(0)
    elif not "1" in a:
        if a.count("2") % 2 == 1:
            print(2)
        else:
            print(0)
    else:
        b = a.replace('0', '')
        b = str(int(b) - int(len(b) * '1'))
        if b.count("1") % 2 == 1:
            print(1)
        else:
            print(0)

Submission status: Wrong Answer

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

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

if len(A) <= 100:
    while len(A) > 1:
        A = [abs(A[i] - A[i + 1]) % 2 for i in range(len(A) - 1)]
    print(A[0])
    exit()

print(sum(A) % 2)

Submission status: Wrong Answer

Solution code:
N=int(input())

s=list(input())

b=[]

while True:
    for i in range(len(s)-1):
        print(i)
        a=abs(int(s[i])-int(s[i+1]))
        b.append(a)
 
    s=b
    b=[]
    if len(s)>1:
        continue
    elif len(s)==1:
        print(s)
        break

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, mod=10**9+7):
        self.__mod = mod
        self.fac = [1] * (n+1)
        self.ifac = [1] * (n+1)
        for i in range(2, n+1): self.fac[i] = self.fac[i-1] * i % mod
        self.ifac[n] = pow(self.fac[n], mod-2, mod)
        for i in range(n, 1, -1): self.ifac[i-1] = self.ifac[i] * i % mod

    def choose(self, n, r):
        if r < 0 or r > n: return 0
        return (self.fac[n] * self.ifac[n-r] % self.__mod) * self.ifac[r] % self.__mod

    def multichoose(self, u, k):
        return (self.fac[u+k-1] * self.ifac[u-1] % self.__mod) * self.ifac[k] %self.__mod

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input()))
if N == 2:
    print(abs(a[0]-a[1]))
    exit()
a1 = [abs(a[i]-a[i+1]) for i in range(N-1)]
if 1 in a1:
    s = 0
    for i in range(len(a1)//2):
        if a1[i] % 2 != a1[len(a1)-i-1] % 2:
            s += 1
    print(s % 2)
else:
    s = 0
    for i in range(len(a1)//2):
        if a1[i] != a1[len(a1)-i-1]:
            s += 1
    print((s % 2) * 2)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input()))
S=A[:];p=0
for i in range(1,N):
  S[i-1]=abs(S[i-1]-S[i])
  if S[i-1]==2:
    p=p+1
print(0 if p%2==0 else 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(input())
A = []
for i in a:
  A.append(int(i))
if n % 4 == 1:
  print(abs(A[0]-A[-1]))
elif n % 4 == 2:
  if n == 2:
    print(abs(A[0]-A[1]))
    exit()
  x = abs(A[0]-A[-2])
  y = abs(A[1]-A[-1])
  print(abs(x-y))
elif n % 4 == 3:
  if n == 3:
    print(abs(A[0]-A[1]))
    exit()
  x = abs(A[0]-A[-3])
  y = abs(A[2]-A[-1])
  print(abs(x-y))
else:
  if n == 4:
    x = abs(A[0]-A[2])
    y = abs(A[1]-A[3])
    print(abs(x-y))
  else:
    b = []
    for i in range(4):
      b.append(abs(A[i]-A[i-4]))
    x = abs(b[0]-b[2])
    y = abs(b[1]-b[3])
    print(abs(x-y))

Submission status: Wrong Answer

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

if len(A) % 2 == 1:
    print((A[-1] + 1) % 2)
else:
    print(sum(A) % 2)

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

    a_next.append(a[0])
    a_next.append(a[1])
    for i in range(2, len(a)-2):
        if a[i] != 0:
            a_next.append(a[i])
    if len(a) > 3:
        a_next.append(a[-2])
    if len(a) > 2:
        a_next.append(a[-1])

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

Submission status: Wrong Answer

Solution code:
N=input()
N = int(N)
a = input()
b = list(a)
c =list(map(int,b))
d= []
for s in range(N-1):
  r = abs(c[s] -c[s+1])
  d.append(r)
for i in range(N-1):
  for p in range(N-i):
    l = abs(d[-N+1] - d[-N+2])
    d.append(l)
    print(d)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np


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


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


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

A = np.array([int(a) for a in A])
if N <= 100:
    for i in range(N - 1):
        A = calc(A)
    print(A[0])

else:
    print(0)

Submission status: Wrong Answer

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# main()
print(main())

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
if n == 2:
	print(abs(int(s[0])-int(s[1])))
else:
	count = 0
	a = []
	for i in range(n-1):
		a.append(abs(int(s[i])-int(s[i+1])))
	c = a.count(1)
	q = a.count(2)
	ss = set(a)
	if ss == {0,2} and q == 1:
		print(2)
	else:
		if c%2 == 1 or q%2 == 1 or len(ss) == 3:
			print(1)
		else:
			print(0)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(input())
for i in range(N):
    a[i]=int(a[i])
#print(a)
while len(a)>2:
    A=[]
    for i in range(1,len(a)):
        if i==1:
            A.append(abs(a[i]-a[i-1]))
        elif abs(a[i]-a[i-1])!=A[-1]:
            A.append(abs(a[i]-a[i-1]))
            
    #print(A)
    a=A
if len(a)==1:
    print(a[0])
else:
    print(abs(a[0]-a[1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = input()
x_list = []

pre_num = -1
con_flg = False
count = 0

for i,v in enumerate(x):
  v = int(v)
  if pre_num == v:
    if i == 1 or i == n-1:
    	x_list.append(v)
    count += 1
    continue
  else:
    x_list.append(v)
    pre_num = v

if count == n-1:
  con_flg = True
  
while True:
  if len(x_list) <= 1:
    if con_flg:
      x_list[0] = 0
    break
  lst = []
  pre_num = -1
  count = 0
  for i,j in enumerate(range(len(x_list)-1)):
    num = abs(x_list[j]-x_list[j+1])
    if num == pre_num:
      if i == 1 or i == len(x_list)-2:
        lst.append(num)
      count += 1
      continue
    else:
      lst.append(num)
      pre_num = num
      
  if count == len(x_list)-2 and len(x_list) != 2:
    con_flg = True
    
  x_list = lst
  
if len(x_list) == 1:
  print(x_list[0])
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
a = input()
b = list(a)
c = [int(s) for s in b]
k = 1
for j in range(N):
  if N-k % 2 == 0:
    for i in range(int((N-k)/2)):
      for x in range(3):
        if c[i] - c[i+1] == x or c[i+1] - c[i] == x:
          c[i] = x
        if c[N-k-i] -c[N-k-i-1] == x or c[N-k-i-1] - c[N-k-i] == x:
          c[N-k-i] = x
  else:
    for i in range(int((N-k)/2)):
      for x in range(3):
        if c[i] - c[i+1] == x or c[i+1] - c[i] == x:
          c[i] = x
        if c[N-k-i] -c[N-k-i-1] == x or c[N-k-i-1] - c[N-k-i] == x:
          c[N-k-i-1] = x
        if c[int((N-k)/2)] - c[int((N-k)/2+1)] == x or c[int((N-k)/2+1)] - c[int((N-k)/2)] == x:
          c[int((N-k)/2)]
  k = k+1
print (c[0])

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) == 1 and b.count(0) == N-2:
        print(2)
    else:
        print(ans % 2)

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

Submission status: Wrong Answer

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

def parity(n, r):
    # the 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)

ans = 0
for i, a in enumerate(aa):
    if parity(n-1, i) == 1:
        ans = ans - a
        if ans < 0:
            ans *= -1
print(ans)

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(input())
for i in range(N):
    a[i]=int(a[i])
#print(a)
while len(a)>2:
    num=a[0]
    A=[]
    for i in range(1,len(a)):
        if i==1:
            A.append(abs(a[i]-a[i-1]))
        elif abs(a[i]-a[i-1])!=A[-1]:
            A.append(abs(a[i]-num))
            
    #print(A)
    a=A
if len(a)==1:
    print(a[0])
else:
    print(abs(a[0]-a[1]))

Submission status: Wrong Answer

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

print(sum(A) % 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 = [ int(i) for i in str_list ]
tuples = tuple(nums_list)
from functools import lru_cache

@lru_cache(maxsize=100000)
def keisan(t):
  nums_list = list(t)
  result = [ abs(nums_list[i] - nums_list[i+1]) for i in range(len(nums_list)-1) ]
  if len(result) == result.count(result[0]):
    tmp = []
    tmp.append(0)
    return tmp
  if len(result) > 1:
    return keisan(tuple(result))
  else:
    return result

nums_list = keisan(tuples)  
print(nums_list[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
if n == 2:
	print(abs(int(s[0])-int(s[1])))
else:
	count = 0
	a = []
	for i in range(n-1):
		a.append(abs(int(s[i])-int(s[i+1])))
	c = a.count(1)
	q = a.count(2)
	ss = set(a)
	if ss == {0,2} and q == 1:
		print(2)
	else:
		if c%2 == 1 or q%2 == 1:
			print(1)
		else:
			print(0)

Submission status: Wrong Answer

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

for j in range(1,N):
    for i in range(N-j):
        min = abs(l[i] - l[i+1])
        del l[0]
        l.append(min)
        
ans = l[0]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(input())
count = N-1

for n in range(1,N):
    num = 0
    flag = True
    for i in range(count):
        a[i] = abs(int(a[i])-int(a[i+1]))
        if a[i] == 1:
            num += 1
        elif a[i] == 2 or a[i] == 3:
            flag = False
    a.pop(-1)
    if flag == True:
        break
    count -= 1

if num%2 == 0:
    print(0)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(input())
for i in range(N):
    a[i]=int(a[i])
#print(a)
while len(a)>2:
    num=a[0]
    A=[]
    for i in range(1,len(a)):
        if i==1:
            A.append(abs(a[i]-a[i-1]))
        elif a[i]-a[i-1]!=A[-1]:
            A.append(abs(a[i]-num))
            
    #print(A)
    a=A
if len(a)==1:
    print(a[0])
else:
    print(abs(a[0]-a[1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(input())
ans = abs(abs(int(a[0]) - int(a[1])) - abs(int(a[-2]) - int(a[-1])))
print(ans)