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:
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase

def main():
    n =int(input())
    a = list(map(int,input()))
    n = len(a)
    if n<=10000:
        new = a.copy()
        for i in range(n-1):
            new1 = new.copy()
            for j in range(1,n-i):
                new[j] = abs(new1[j]-new1[j-1])
            # print(new)
            new.pop(0)
            # print(new)
        print(new[0])
    else:
        print(1)
        # m = 99
        # for i in range(1,len(a)):
        #     m = min(m,abs(a[i]-a[i-1]))
        # print(m)





# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

before_list = a_list
for y in range(1, n):
    next_list = ''
    if y == 1:
        next_value = abs(int(a_list[0]) - int(a_list[-1]))
        next_list += str(next_value)
    else:
        next_value = abs(int(before_list[0]) - int(before_list[-1]))
        next_list += str(next_value)

    before_list = next_list
    next_list = ''

print(before_list[0])

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    a = list(map(int,list(input())))
    dp = [[[0] * 4 for _ in range(4)] for _ in range(4)]

    for i in range(1,4):
        for j in range(1,4):
            for k in range(1,4):
                tmp = abs(abs(i-j) - abs(j-k))
                dp[i][j][k] = tmp
    ans = 0
    for i in range(1,N-1):
        ans = abs(ans - dp[a[i-1]][a[i]][a[i+1]])
    print(ans)





if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input()
b = []
for i in range(N-1):
    b.append(abs(int(A[i])-int(A[i+1])))
S = 0
p = 0
for i in range(N-1):
    if p == 0:
        S += b[i]
    n = N - 2 - i
    k = i + 1
    if n == 0:
        continue
    while n % 2 == 0:
        p += 1
        n //= 2
    while k % 2 == 0:
        p -= 1
        k //= 2

if S % 2:
    print(1)
else:
    twos = 0
    for i in range(1,N-1):
        if b[i] == 1:
            print(0)
            break
        elif b[i] == 2:
            twos += 1
            if twos > 1:
                print(0)
                break
    else:
        if twos == 1:
            print(2)
        else:
            print(1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase

def main():
    n =int(input())
    a = list(map(int,input()))
    n = len(a)
    if n<=10000:
        new = a.copy()
        for i in range(n-1):
            new1 = new.copy()
            for j in range(1,n-i):
                new[j] = abs(new1[j]-new1[j-1])
            # print(new)
            new.pop(0)
            # print(new)
        print(new[0])
    else:
        print(0)
        # m = 99
        # for i in range(1,len(a)):
        #     m = min(m,abs(a[i]-a[i-1]))
        # print(m)





# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

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:continue
            else:u = abs(s-t);b+=str(u)
        l = len(b)
        if l == 0:print(0);exit()
        a = b
    print(int(b))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def intlist(s):
    l = []
    for c in s:
        l.append(int(c))
    return l

X = intlist(S)
while len(X) > 1:
    next = []
    for i in range(len(X)-1):
        v = abs(X[i] - X[i+1])
        if v > 0:
            next.append(v)
    X = next

if len(next) > 0:
    print(next[0])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
a_ = list(map(int, list(str(input()))))
a = []
for i in range(1, len(a_)):
  a.append(abs(a_[i]-a_[i-1])%2)
n = (N-1)//2

print((sum(a[:n])+sum(a[-n:]))%2)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase

def main():
    n =int(input())
    a = list(map(int,input()))
    n = len(a)
    if n<=1000:
        new = a.copy()
        for i in range(n-1):
            new1 = new.copy()
            for j in range(1,n-i):
                new[j] = abs(new1[j]-new1[j-1])
            # print(new)
            new.pop(0)
            # print(new)
        print(new[0])
    else:
        print(0)
        # m = 99
        # for i in range(1,len(a)):
        #     m = min(m,abs(a[i]-a[i-1]))
        # print(m)





# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())-1
a=input()
l=[None]*N
for i in range(N):
    l[i]=abs(int(a[i+1])-int(a[i]))
for i in range(19,0,-1):
    if N>2**i:
        t=2**i
        N-=t
        lb=[None]*N
        for i in range(N):
            if l[i+t//2]==1 and l[i]+l[i+t]==2:
                lb[i]=0
            else:
                lb[i]=abs(l[i]-l[i+t])
        l=lb
        print(l)
if len(l)==1:
    print(l[0])
else:
    print(abs(l[0]-l[1]))

Submission status: Wrong Answer

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

pre_num = -1
con_flg = False
count = 0

for v in x:
  v = int(v)
  if pre_num == 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 j in range(len(x_list)-1):
    num = abs(x_list[j]-x_list[j+1])
    if num == pre_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:
def calc2(array):
    temp = []
    for x, y in zip(array[:-1], array[1:]):
        temp.append(abs(x-y))
    if len(temp) == 1:
        print(temp[0])
    else:
        calc2(temp)
def main():
    N = int(input())
    array = [0 for i in range(N+1)]
    s = input()
    for j in range(N):
        array[j+1] = int(s[j])
    calc2(array)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#import copy
N = int(input())
An = list(map(int,list(input())))
#print(An)
def solve(n):
    previous_num = -1
    insert_idx = 0
    for i in range(n-1):
        current_num = abs(An[i]-An[i+1])
        if current_num == previous_num:
            continue
        An[insert_idx] = current_num
        previous_num = current_num
        insert_idx += 1
    if insert_idx == 1:
        An[1] = An[0]
    return insert_idx

current_n = N
while 2 < current_n:
    current_n = solve(current_n)
print(abs(An[1]-An[0]))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input()
ans = ""
for i in range(N-1):
    chk = abs(int(a[i+1]) - int(a[i]))
    if chk != 0:
        if len(ans) == 0 :
            ans += str(chk)
        else:
            if ans[-1] != str(chk):
                ans += str(chk)
if len(ans) == 1:
    print(ans)
elif len(ans) == 0:
    print(0)
else:
    if len(ans) %2 == 0:
        print(1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
s_ = input()
s = "".join([str(int(x)-1) for x in s_])

if len(s) % 2 == 1:
    if "1" not in s:
        if (int(s[0]) - int(s[-1])) == 0:
            print(0)
            exit()
        else:
            print(2)
            exit()

    if abs(int(s[0]) - int(s[-1])) % 2 == 0:
        print(0)
    else:
        print(1)
elif len(s) == 2:
    print(abs(int(s[0])-int(s[1])))
else:
    if "1" not in s:
        if (int(s[0]) + int(s[1]) + int(s[-2]) + int(s[-1])) %4 == 0:
            print(0)
            exit()
        else:
            print(2)
            exit()

    if (int(s[0]) + int(s[1]) + int(s[-2]) + int(s[-1])) %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 a[i]!=num:
            A.append(abs(a[i]-num))
    #print(A)
    a=A
if len(a)==0:
    print(0)
else:
    print(a[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
st = input()
if n==1:
    print(st[0])
elif n==2:
    print(abs(int(st[1])-int(st[0])))
else:
    ans1 = abs(int(st[1])-int(st[0]))
    ans2 = abs(int(st[-1])-int(st[-2]))
    print(abs(ans2-ans1))

Submission status: Wrong Answer

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

num = [int(x) for x in list(str(A))]
length = len(num)
count_stopper = len(num)

print(num)

cnt = 1
a = 0
big_count = 0
new = []
while big_count != length-1:
    while cnt != count_stopper:
        print(cnt)
        print(count_stopper)
        a = 0
        a = num[cnt - 1] - num[cnt]
        new.append(abs(a))
        cnt += 1
    cnt = 1
    num = new
    new = []
    big_count += 1
    count_stopper -= 1
    print(num)

print(num[0])

Submission status: Wrong Answer

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

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

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

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


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

lst = []

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

work(lst)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

N = int(input())

if N > 20:
  print(0)
  sys.exit()

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, list(input())))
x = [max(a[i], a[i+1]) - min(a[i], a[i+1]) for i in range(N-1)]

def make_x(l):
	n = len(l)
	if n == 1:
		return l
	l2 = [l[0]]
	cnt = 1
	for i in range(1, n):
		if l[i] != l2[-1]:
			l2.append(l[i])
			cnt += 1
	if cnt == 1:
		return [0]
	return l2

def next_x(l):
	n = len(l)
	return [max(l[i], l[i+1]) - min(l[i], l[i+1]) for i in range(n-1)]

while len(x) > 1:
	x = make_x(next_x(x))
print(x[0])

Submission status: Wrong Answer

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


def solve(N, S):
    xs = list(map(int, S))
    while 1 < len(xs):
        ys = []
        for i in range(len(xs) - 1):
            val = abs(xs[i + 1] - xs[i])
            if 0 < val:
                ys.append(val)
        xs = ys
    return xs[0] if xs else 0


print(solve(N, S))

Submission status: Wrong Answer

Solution code:
def calc(P):
    #Pはリスト
    Q=[]
    for str in A:
        if str=="1":
            Q.append("0")
        elif str=="2":
            Q.append("1")
        else:
            Q.append("2")
    return Q

def solve(P):
    #Pはリスト
    #print(P)
    N=len(P)
    if N>1:
        Q=[]
        for i in range(N-1):
            if   abs( int(P[i])-int(P[i+1]) )==0:
                pass
            elif abs( int(P[i])-int(P[i+1]) )==1:
                Q.append("1")
            else:
                Q.append("2")
        return solve(Q)
    elif N==0:
    	return(0)
    else:
        return P[0]

N=int(input())
A=input()
B=list(A)

#print(A)
#print(B) 
short=calc(B)
#print(short)

ans=solve(short)
print(ans)

Submission status: Wrong Answer

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

a = int(input())

A =  [int(i) for i in list(input())]

print(A)

x = [[ 0 for j in range(a)] for i in range(a)]

for j in range(a):
    x[0][j] = A[j]

for i in range(1, a):
    for j in range(a-1):
        x[i][j] = abs(x[i-1][j] - x[i-1][j+1])

print(x[a-1][0])

Submission status: Wrong Answer

Solution code:
import numpy as np

N=int(input())
A = input()
a = np.array([int(A[i]) for i in range(len(A))])
while len(a) !=1:
  a = np.absolute(np.diff(np.absolute(a),1))
  print(a)
  if len(a) == 1:
    print(a[0])

Submission status: Wrong Answer

Solution code:
class Binary_Indexed_Tree():
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)

    def add(self, i, x):
        i += 1
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def get(self, i):
        return self.sum_range(i, i)

    def sum(self, i):
        i += 1
        ret = 0
        while i:
            ret += self.data[i]
            i &= i-1
        return ret

    def sum_range(self, l, r):
        return self.sum(r)-self.sum(l-1)

    def lower_bound(self, w):
        if w<=0:
            return 0
        i = 0
        k = 1<<(self.n.bit_length())
        while k:
            if i+k <= self.n and self.data[i+k] < w:
                w -= self.data[i+k]
                i += k
            k >>= 1
        return i

n = int(input())
a = list(map(lambda x: int(x)-1, input()))
b = a[:]
if 1 in b:
    BIT = Binary_Indexed_Tree(n+1)
    for i, ai in enumerate(a):
        x = i
        if ai == 1:
            BIT.add(i, 1)
        else:
            s = BIT.sum(i)
            if s == 0:
                continue
            i = BIT.lower_bound(s)
        s = BIT.sum(i)
        if s > 1:
            j = BIT.lower_bound(s-1)
            for k in range(j+1, i):
                BIT.add(k,1)
            BIT.add(j, -1)
        else:
            for k in range(i):
                BIT.add(k,1)
    ans = BIT.get(0)
else:
    BIT = Binary_Indexed_Tree(n+1)
    a = [int(i==2) for i in a]
    for i, ai in enumerate(a):
        x = i
        if ai == 1:
            BIT.add(i, 1)
        else:
            s = BIT.sum(i)
            if s == 0:
                continue
            i = BIT.lower_bound(s)
        s = BIT.sum(i)
        if s > 1:
            j = BIT.lower_bound(s-1)
            for k in range(j+1, i):
                BIT.add(k,1)
            BIT.add(j, -1)
        else:
            for k in range(i):
                BIT.add(k,1)
    ans = BIT.get(0)
    ans *= 2

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

N = int(input())

if N > 15:
  print(0)
  sys.exit()

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

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

Submission status: Wrong Answer

Solution code:
num = int(input())
a = list(input())
a_i = [int(i) for i in a]
first = []
for x in range(num):
    if x == 0: continue
    elif abs(a_i[1] - a_i[0]) == 0: continue
    else: 
        val = abs(a_i[1] - a_i[0])
        if len(first) == 0: first.append(val)
        else: first.append(val)
if len(first) == 1: print(first[0])
else:
    second = []
    for x in range(len(first)):
        if x == 0: continue
        elif abs(a_i[1] - a_i[0]) == 0: continue
        else: 
            val = abs(first[1] - first[0])
            if len(second) == 0: second.append(val)
            else: second.append(val)
    if len(second) == 1: print(second[0])
    else: print(0)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

N = int(input())

if N > 12:
  print(0)
  sys.exit()

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

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

Submission status: Wrong Answer

Solution code:
def calc2(array):
    temp = []
    for x, y in zip(array[:-1], array[1:]):
        temp.append(abs(x-y))
    if len(temp) == 1:
        return temp[0]
    else:
        return(calc2(temp))
def main():
    N = int(input())
    array = [0 for i in range(N+1)]
    s = input()
    for j in range(N):
        array[j+1] = int(s[j])
    print(calc2(array))
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
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:
    appears=[]
    num_zero = ans_array.count(0)
    num_one = ans_array.count(1)
    num_two = ans_array.count(2)
    appears.append(num_one)
    appears.append(num_zero)
    appears.append(num_two)
    appears.sort()
    minor = appears[1]
    if (len(ans_array)%2==0) and (minor%2==0):
        print(0)
    elif (len(ans_array)%2==1) and (minor%2==1):
        print(0)
    else:
        print(max(ans_array))

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 = a[0]
for i in range(1,len(a)) :
    if a[i] != a[i-1] :
        b += a[i]

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

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

N = int(input())

if N > 9:
  print(0)
  sys.exit()

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input()
if  not "1" in a:
    a = str(int(a) - int(N * '2'))
else:
    a = str(int(a) - int(N*'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 = a.zfill(N)
    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())))
C = A[:]
lenc = len(C)

while lenc > 1:
  B = [abs(i-j) for itr, (i, j) in enumerate(zip(C, C[1:])) if (abs(i-j) != 0 or itr == lenc-2)]
  C = B[:]
  lenc = len(C)
if C:
  print(C[0])
else:
  print(0)

Submission status: Wrong Answer

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

pre_num = -1
for v in x:
  v = int(v)
  if pre_num == v:
    continue
  else:
    x_list.append(v)
    pre_num = v
  
con_flg = False
while True:
  if len(x_list) <= 1:
    if con_flg:
      x_list[0] = 0
    break
  lst = []
  pre_num = -1
  count = 0
  for j in range(len(x_list)-1):
    num = abs(x_list[j]-x_list[j+1])
    if num == pre_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:
N = int(input())
x_1 = list(input())

def a(x):
    result = list()
    if len(x) <= 1:
        return x
    
    for i in range(len(x)-1):
        result.append(abs(int(x[i])-int(x[i+1])))
    kaeri = a(result)
    return kaeri

print(a(x_1))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

N = int(input())

if N > 10:
  print(0)
  sys.exit()

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

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

Submission status: Wrong Answer

Solution code:
import math
import numpy as np

N = int(input())
arr_rev = list(map(int, list(input())))
arr_rev.reverse()
arr_rev = np.array(arr_rev)

def calc(a, b):
    return abs(-a + b)

def chanto(arr_rev):
    inp = arr_rev
    diff_1 = [calc(inp[x], inp[x+1]) for x in range(len(inp)-1)]
    return np.sum(diff_1) %2 

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


print(chanto(arr_rev))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, list(input())))
C = A[:]
lenc = len(C)

while lenc > 1:
  B = [abs(i-j) for itr, (i, j) in enumerate(zip(C, C[1:])) if (abs(i-j) != 0 or itr == lenc-2)]
  print(B)
  C = B[:]
  lenc = len(C)
if C:
  print(C[0])
else:
  print(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())))
b = np.array(a)

if n > 10**4:
    ans = 1 if abs(a[0]-a[-1])==1 else 0
    print(ans)
    exit()

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

print(b[0])

Submission status: Wrong Answer

Solution code:
import random
print(random.randint(0,3))

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:
        if r % 2 != 0:
            return 0
        else:
            return parity(n//2, r//2)
    else:
        return parity(n//2, r//2)

# for nn in range(15):
#     ar = []
#     for i in range(nn+1):
#         ar.append(parity(nn, i))
#     print(ar)

# n = 10**6
# for i in range(n+1):
#     parity(n,i)

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

myfunc(n,c)

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

  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

  # # TLE
  # while True:
  #   if len(l)==1:
  #     return l[0]
  #   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(l)
  # print(ans)
  # print(l)
  if len(ans)==2:
    return 1
  return 0

# main()
print(main())

Submission status: Wrong Answer

Solution code:
N = int(input())
a_list = list(map(int, list(input())))
print(abs(abs(a_list[0] - a_list[1]) - abs(a_list[-1] - a_list[-2])))

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 = a[0]
for i in range(1,len(a)) :
    if a[i] != a[i-1] :
        b += a[i]

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

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
import copy
import math
import fractions

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

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

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


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

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

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