Problem:


Score : 700 points

Problem Statement

Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3.
Let x_{i,j} defined as follows:

x_{1,j} := a_j \quad (1 \leq j \leq N)

x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i)

Find x_{N,1}.

Constraints

2 \leq N \leq 10^6

a_i = 1,2,3 (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N
a_1a_2\ldotsa_N

Output

Print x_{N,1}.

Sample Input 1

4
1231

Sample Output 1

1

x_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.

x_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.

x_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.

Finally, x_{4,1} = |0-1| = 1, so the answer is 1.

Sample Input 2

10
2311312312

Sample Output 2

0



Sample input:
4
1231


Sample output:
1

Submission status: Wrong Answer

Solution code:
n = int(input())
a = 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)
    c = comb(n-2, i-1)
    ans += c * abs(e1 - e2) * (-1) ** (i % 2 + 1)
    ans %= mod

print(ans)

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
    if n < 100000:
        print(2)

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 = tuple(map(int, input()))

ans = 0
positive = 1

for i in range(N-1):
  if i == 0 or i == (N-2):
    k = 1
  else:
    k = N - 2
  if positive:
    ans += k * abs(A[i] - A[i+1])
  else:
    ans -= k * abs(A[i] - A[i+1])
  positive = not positive

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

for i in range(n-1):
    for j in range(len(a) - 1):
        a[j] = abs(a[j] - a[j + 1])
    
    if len(a) == 2:
        print(a[0])
        sys.exit()

    a.pop()
    a = [i for i in a if i != 0]

    if len(a) == 0:
        print(0)
        sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

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

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = input().rstrip()
    b = a[0]
    for i in range(1, n):
        #print(b)
        c = a[i]
        b += c
        for j in reversed(range(len(b)-1)):
            b = b[:j] + str(abs(int(b[j]) - int(b[j+1]))) + b[j+1:]
        l = 1
        f = False
        r = 1
        while r < len(b):
            if f and b[r] != "0":
                if r - l > 1:
                    b = b[:l] + b[r:]
                f = False
            elif not f and b[r] == "0":
                l = r
                f = True
            r += 1
    #print(b)
    print(b[0])

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from random import randint
n=int(input())
s=input()
if set(list(s))=={"1","3"}:print(randint(0,1)*2)
else:print(randint(0,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((A.count(1) - A.count(0) + 1) % 2)

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


"""         
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""

if __name__=="__main__":resolve()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(input())
if set(a) == {"1", "3"}:
    print(2)
    exit()
for i in a:
    i = int(i)
    i -= 1
    i = str(i)
while a:
    try:
        a.remove("0")
    except:
        break
a = "".join(a)
print((a.count("12") + a.count("21")) % 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)]

print((A.count(1) - A.count(0)) % 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)

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

# main()
print(main())

Submission status: Wrong Answer

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

flag = 0
result = 5

for i in range(N):
    if int(a[i]) == 2:
        flag = 1

if flag == 0:
    a_1 = (int(a[0]) - 1) // 2
    a_2 = (int(a[1]) - 1) // 2
    b_2 = (int(a[N - 2]) - 1) // 2
    b_1 = (int(a[N - 1]) - 1) // 2
else:
    a_1 = (int(a[0]) - 1) % 2
    a_2 = (int(a[1]) - 1) % 2
    b_2 = (int(a[N - 2]) - 1) % 2
    b_1 = (int(a[N - 1]) - 1) % 2

if N % 2 == 1:
    if a_1 == b_1:
        result = 0
    else:
        result = 1
elif N % 2 == 0:
    if (a_1 + a_2 + b_1 + b_2) % 2 == 0:
        result = 0
    elif (a_1 + a_2 + b_1 + b_2) % 2 == 1:
        result = 1
if flag == 0:
    print(result * 2)
elif flag == 1:
    print(result)

Submission status: Wrong Answer

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

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 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:
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())
List = list(input())
arr = []

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

ans = []

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

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

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

Submission status: Wrong Answer

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

    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())
A = list(map(int, input()))
A = [abs(A[i] - A[i + 1]) % 2 for i in range(len(A) - 1)]

print((sum(A) + len(A) + 1) % 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)]

print((sum(A) + len(A)) % 2)

Submission status: Wrong Answer

Solution code:
from random import randint
print(randint(0,2))

Submission status: Wrong Answer

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

sp = len(''.join(set(a)))
if sp == 1:
    print(0)
elif sp == 2:
    if a[0] == '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 a[0] == '1':
        add = 1
    else:
        add = 0
    if a[-1] == '1':
        add = add+1
    else:
        add = 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:
n = int(input())
x_list = [int(x) for x in input()]

def delete(lst):
  if len(lst) <= 1:
    return lst
  return_lst = []
  
  start = lst[0]
  end = lst[-1]
  s_count = 0
  e_count = 0
  
  for v in lst:
    if v == start:
      s_count += 1
    else:
      break
  
  if s_count == len(lst):
    return [0]
  
  for v in reversed(lst):
    if v == end:
      e_count += 1
    else:
      break
  
  pre_num = -1
  for v in lst[s_count:-1*e_count]:
    if v == pre_num:
      continue
    else:
      return_lst.append(v)
      pre_num = v
   
  return [start for _ in range(s_count)] + return_lst + [end for _ in range(e_count)] 
   
while True:
  if len(x_list) <= 1:
    break
  x_list = [abs(x_list[j]-x_list[j+1]) for j in range(len(x_list)-1)]
  x_list = delete(x_list)

print(x_list[0])

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(4100000)
N= int(input())
an=  [int(x) for x in list(input())]

#print(an)
#print(len(an))

#if len(an)==1:
#    print(an[0])
#    exit()

ans_array=[]
def calc(prm):
    global ans_array
    bn=[]
    hasZero=False
    hasOne=False
    hasTwo=False
    threeKind = False
    for i in range(len(prm)-1):
        b = abs(prm[i]-prm[i+1])
        if b==0:
            hasZero=True
        elif b==1:
            hasOne=True
        else:
            hasTwo=True
        bn.append(b)
    if len(bn)==1:
        #print("要素数が1だよ")
        #print(bn)
        ans_array=bn
        return
    elif hasZero and hasOne and hasTwo:
        threeKind=True
        #print("3種類あるよ")
        #print(bn)
        calc(bn)
    else:
        #print("2種類以下だよ")
        #print(bn)
        ans_array=bn
        return
calc(an)

if len(ans_array)==1:
    print(ans_array[0])
else:
    ans_array2=[]
    for i in range(len(ans_array)-1):
        b = abs(ans_array[i]-ans_array[i+1])
        ans_array2.append(b)
    #print(ans_array2)
    if len(ans_array2)==1:
        print(ans_array2[0])
    else:
        appears=[]
        num_zero = ans_array2.count(0)
        num_one = ans_array2.count(1)
        num_two = ans_array2.count(2)
        appears.append(num_one)
        appears.append(num_zero)
        appears.append(num_two)
        appears.sort()
        max= appears[0]
        #if max == len(ans_array2):
        #    print(0)
        #    exit()
        minor = appears[1]
        if minor==0:
            print(ans_array2[0])
        elif (len(ans_array2)%2==0) and (minor%2==0):
            print(0)
        elif (len(ans_array2)%2==1) and (minor%2==1):
            if num_zero==0:
                print(1)
            else:
                print(0)
        else:
            if num_zero==0:
                print(1)
            elif num_one==0:
                print(2)
            else:
                print(1)

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 -= 1
A %= 2
bl = False
if 1 not in set(A):
    bl = True
while N%4 != 1:
    A = np.abs(np.diff(A))
    N -= 1

if N == 1:
    result = A[0]
else:
    result = abs(A[-1] - A[0])
print(result * 2 if bl else result)

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

# main()
print(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 == 0:continue
            else:
                u = abs(s-t)
                if u != 0:b += str(u)
                else:
                    if i+1 == l-1:continue
                    elif int(a[i+2]) == 0:continue
                    else:b += str(u)
        l = len(b)
        if l == 0:print(0);exit()
        elif l == 1:print(int(b));exit()
        a = b

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

print(A.count(3) % 2)

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:
        print(2)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
import sys

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

for i in range(n-1):
    for j in range(len(a) - 1):
        a[j] = abs(a[j] - a[j + 1])
    
    if len(a) == 1:
        print(a[0])
        sys.exit()

    a.pop()
    a = [i for i in a if i != 0]

    if len(a) == 0:
        print(0)
        sys.exit()

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)-1
  if alist[i]==0:
    cnt[0] += 1
  elif alist[i]==1:
    cnt[1] += 1
  else:
    cnt[2] += 1
count = 0
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 = 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)
elif a1 == 1 and a3 >= 2:
  print(1)
elif a1 >= 2 and a3 == 1:
  print(1)
else:
  print(0)

Submission status: Wrong Answer

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

if len(A) == 1:
    print(A[0])
    exit()

cnt = A[0] + A[-1]
for i in range(len(A)):
    if A[i: i + 4] == [0, 1, 1, 0]:
        cnt += 1
print(cnt % 2)

Submission status: Wrong Answer

Solution code:
mod=10**9+7
def inv(a,m):
    b=m
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return lastx % m

n=int(input())
s=input()
frac=[1]
for i in range(1,n+1):
    frac.append(frac[-1]*i%mod)

fracinv=[inv(frac[i],mod) for i in range(n+1)]

ans=0
for i in range(n):
    if int(s[i])==1:
        ans+=(frac[n]*fracinv[i]*fracinv[n-i])%mod
        ans%=2
print(ans)

Submission status: Wrong Answer

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

    while len(a) % 2 == 0 and len(a) > 2:
        na = []
        for a1, a2 in zip(a, a[2:]):
            if a1 % 2 == a2 % 2:
                na.append(0)
            else:
                na.append(1)
        a = na

    if len(a) % 2 == 1:
        if a[0] % 2 == a[-1] % 2:
            print(0)
        else:
            print(1)
    else:
        if len(a) == 1:
            print(a[0])
        else:
            print(abs(a[0] - a[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())
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 c == 1 and ((N-1)-cnt-1)%2 == 0:
  print(2)  
elif b == 1 and cnt%2 == 0:
  print(1)
elif b == 1 and ((N-1)-cnt-1)%2 == 0:
  print(1)  
elif b == 2 and a%2 == 1 and cnt == 0:
  print(1)
elif b == 2 and a%2 == 1 and cnt == N-3:
  print(1)
elif b == 2 and (cnt > 2 or (N-1)-2-cnt > 2):
  print(1)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
    
N = int(input())
s = input()

#A 1,0,1
#B 0,1,0
#C 0,1,2

# 2312>A
# 23121>A 23122>B 23123>A
# 1231>B
# 12311>A 12312>B 12313>A
# 111>C
# 1111>C 1112>B 1113>C

#1>C
#2>A
#3>B

if s[0] == '1':
    x = 'c'
elif s[0] == '2':
    x = 'a'
else:
    x = 'b'

len_s = len(s)
li = [['a','b','a'],['a','b','a'],['c','b','c']]

for i in range(len_s-2):
    if x == 'a':
        x = li[0][int(s[i+1])-1]
    elif x == 'b':
        x = li[1][int(s[i+1])-1]
    else:
        x = li[2][int(s[i+1])-1]
    

#A 1,0,1
#B 0,1,0
#C 0,1,2
lii = [[1,0,1],[0,1,0],[0,1,2]]
if x == 'a':
    print(lii[0][int(s[-1])-1])
elif x == 'b':
    print(lii[1][int(s[-1])-1])
else:
    print(lii[2][int(s[-1])-1])

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=sum([(temp[j+1]-temp[j]) for j in range(len(temp)-1) if (temp[j+1]-temp[j])!=0])
    print(abs(ans))


"""         
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""

if __name__=="__main__":resolve()

Submission status: Wrong Answer

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

sp = len(''.join(set(a)))
if sp == 1:
    print(0)
elif sp == 2:
    if a[0] == '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 a[0] == '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 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])
  return 0

# main()
print(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)
elif a1 == 1 and a3 >= 2:
  print(1)
elif a1 >= 2 and a3 >= 1:
  print(1)
else:
  print(0)

Submission status: Wrong Answer

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

a_1 = (int(a[0]) - 1) % 2
a_2 = (int(a[1]) - 1) % 2
b_2 = (int(a[N - 2]) - 1) % 2
b_1 = (int(a[N - 1]) - 1) % 2

flag = 0
result = 5

for i in range(N):
    if int(a[i]) == 2:
        flag = 1

if N % 2 == 1:
    if a_1 == b_1:
        result = 0
    else:
        result = 1
elif N % 2 == 0:
    if (a_1 + a_2 + b_1 + b_2) % 2 == 0:
        result = 0
    elif (a_1 + a_2 + b_1 + b_2) % 2 == 1:
        result = 1
if flag == 0:
    print(result * 2)
elif flag == 1:
    print(result)