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:


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    N=I()
    a=list(map(int,list(input())))
    
    def calc(L):
        L1=list(L)
        nL=len(L)
        if nL%2==1:
            for i in range(nL-1):
                L1[i]=abs(L[i]-L[i+1])
            L1.pop()
                
            return L1
        else:
            L2=[]
            for i in range(0,nL,2):
                L2.append(abs(L[i]-L[i+1]))
            return L2

    while len(a)!=1:
        a=calc(a)    
    
    print(a[0])
                
        
    
main()

Submission status: Wrong Answer

Solution code:
l = int(input())

array = [int(i) for i in list(str(input()))]

arrayTwo = []
for i in range(1,l):
    arrayTwo.append([])
    for k in range(0,l-i):
        arrayTwo[i-1].append(abs(array[i]-array[k]))

print(arrayTwo[l-2][0])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, list(input().strip())))
tri = [A]
for i in range(min(N-1, 5)):
    nx = []
    nw = tri[-1]
    for j in range(1,len(nw)):
        nx.append(abs(nw[j]-nw[j-1]))
    tri.append(nx)
if N < 5:
    print(tri[-1][0])
    exit()

if len(tri[-1]) % 2 == 0:
    tar = tri[-2]
else:
    tar = tri[-1]

if tar[0] ^ tar[1]:
    print(1)
else:
    print(0)

Submission status: Wrong Answer

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

ue = abs(a[0]-a[1])
sita = 0
for i in range(1, n-1):
    ima = a[i]
    tugi = a[i+1]
    sita = abs(ima-tugi)
    ue = abs(ue-sita)
print(ue)

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(0 if A[0] == A[-1] else 1)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=list(input())
if N==2:
  print(abs(int(L[0])-int(L[1])))
else:
  x=int(L[0])
  y=int(L[1])
  z=int(L[2])
  print(abs(abs(x-y)-abs(y-z)))

Submission status: Wrong Answer

Solution code:
N = int(input())						# 5

g = [ [] for _ in range(N+1) ]			#=> [[], [], [], [], [], [], [], []]
g=[]

g.append(input())

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

	g.append(x)

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

Submission status: Wrong Answer

Solution code:
n=int(input())
l=input()
if n>=4:
    print(0)
else:
    h=[0]*n
    for i in range(0,n):
        h[i]=int(l[i])
    d=[[0 for _ in range(n)] for k in range(n)]
    for i in range(n):
        d[0][i]=h[i]
    for i in range(1,n):
        for j in range(0,n-i):
            d[i][j]=abs(d[i-1][j]-d[i-1][j+1])
    print(d[n-1][0])

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, list(input())))
C = A[:]
while len(C) > 1:
  B = [abs(i-j) for i, j in zip(C, C[1:]) if abs(i-j) != 0]
  C = B[:]
if C:
  print(C[0])
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
from math import *
n=int(input())
a=list(input().rstrip())
for i in range(len(a)):
    a[i]=int(a[i])
print(abs(abs(a[0]-a[1])-abs(a[n-1]-a[n-2])) if n>2 else abs(a[0]-a[1]))

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
s=input()
x=[0,0,0]
for i in range(n):
    p=int(s[i])-1
    x[p]+=1

if x[1]==0:
    if x[2]>0:
        if x[2]==1: print(2)
        else: print(0)
    else:
        print(0)
    sys.exit()


for i in range(3):
    if x[i]!=0: p=i

if x[p]==1: print(1)
else: print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input()))
if n<=10:
	for i in range(n-1):
		a=[abs(x-y) for x,y in zip(a,a[1:])]
	print(a[0])
else:
	print(0)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
s=input()
x=[0,0,0]
for i in range(n):
    p=int(s[i])-1
    x[p]+=1

if x[1]==0:
    if x[2]>0:
        if x[2]==1: print(1)
        else: print(0)
    else:
        print(0)
    sys.exit()


for i in range(3):
    if x[i]!=0: p=i

if x[p]==1: print(1)
else: print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
s='1'*10**6
prev=s[0]
ans=[]
for i in range(n-1):
    now = s[i+1]
    if now == prev:
        prev=0
    else:
        if (now=='3' and prev=='1') or (now=='1' and prev=='3'):
            kouho='2'
        else:
            kouho='1'
        if ans==[]:
            ans.append(kouho)
        elif ans[-1]==kouho:
            ans.pop()
        else:
            ans.append(kouho)
nagasa=len(ans)
if nagasa%2==1 or ans==[]:
    print(0)
else:
    print(1)

Submission status: Wrong Answer

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

while len(x) >= 2:
    w=[]
    for j in range(len(x)-1):
        v=abs(x[j]-x[j+1])
        if v != 0:
            w.append(v)
    x=w

print(x[0] if len(x) != 0 else 0)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=input()
# N = 10
# A = "2311312312"
X = [[ int(a) for a in list(A)]]
# print(X)
for i in range(2,N+1):
  # print(X)
  # print("i:",i)
  x = []
  for j in range(1,len(X[-1])):
    nx = abs(X[i-2][j-1] - X[i-2][j])
    if nx==0:
      continue
    x.append( abs(X[i-2][j-1] - X[i-2][j]) )
    # print("  j:", j, X[i-2][j-1], X[i-2][j])
  if len(x)==0:
    print(0)
    break
  if len(x)==1:
    print(x[0])
    break
  X.append(x)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
s=input()
x=[0,0,0]
for i in range(n):
    p=int(s[i])-1
    x[p]+=1

if x[1]==0:
    if x[2]>0:
        if x[2]==1: print(1)
        else: print(0)
    else:
        print(0)


for i in range(3):
    if x[i]!=0: p=i

if x[p]==1: print(1)
else: print(0)

Submission status: Wrong Answer

Solution code:
print("3")

Submission status: Wrong Answer

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)


def main():
    n=int(input())
    a=list(map(int,input()))
    ans=0
    if n<=20:
        ans=ret(a)
    else:
        moji=0
        if a[0]==a[1]:
            moji=a[0]
            a[0]=0
        for i in range(1,n):
            if a[i]==moji:
                moji=a[i]
                a[i]=0
                a[i-1]=0
            else:
                moji=a[i]
        b=[]
        temp=0
        for i in range(n):
            if a[i]!=0:
                b.append(a[i])
                temp+=1
            if temp>=20:
                break
        ans=ret(b)
    print(ans)

if __name__ == "__main__":

    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

A = input()

def check(k):
    return bin(k).count('1')+bin(N-k-1).count('1')-bin(N-1).count('1') == 0


res = 0
for k,a in enumerate(A):
    if check(k):
        res = abs(res-int(a)+1)
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
ints = [int(c) for c in input()]
while len(ints) > 1:
    new = []
    for i in range(1, len(ints)):
        a = abs(ints[i-1] - ints[i])
        if a > 0:
            new.append(a)
    ints = new
if len(ints) == 1:
    print(ints[0])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(c) - 1 for c in input()]

def f(i, j):
    if i == 1:
        return A[j - 1]
    return abs(f(i - 1, j) - abs(f(i - 1, j + 1)))


# if N == 2:
    # print(abs(A[0] - A[1]))

# if N == 3:
#     print(abs(A[0] - A[1]))
if N < 100:
    print(f(N, 1))
    exit()



# 0を消す
A = [a for a in A if a != 0]

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
a=[int(c) for c in s]
b=a
ans=[]
while len(ans)!=1:
    for i in range(len(b)-1):
        if i+1<len(b):
            ans.append(abs(b[i]-b[i+1]))
        b=ans
print(ans[0])

Submission status: Wrong Answer

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

    for i in range(len(s) - 1):
        a = abs(s[i] - s[i + 1])
        if a != 0:
            t.append(a)

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


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

lst = []

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

work(lst)

Submission status: Wrong Answer

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)


def main():
    n=int(input())
    a=list(map(int,input()))
    ans=0
    if n<=5:
        ans=ret(a)
    else:
        moji=0
        if a[0]==a[1]:
            moji=a[0]
            a[0]=0
        for i in range(1,n):
            if a[i]==moji:
                moji=a[i]
                a[i]=0
                a[i-1]=0
            else:
                moji=a[i]
        b=[]
        temp=0
        for i in range(n):
            if a[i]!=0:
                b.append(a[i])
                temp+=1
            if temp>=5:
                break
        ans=ret(b)
    print(ans)

if __name__ == "__main__":

    main()

Submission status: Wrong Answer

Solution code:
import math

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


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

def chanto(arr_rev):
    inp = arr_rev
    for i in range(N-1):
        out = [calc(inp[x], inp[x+1]) for x in range(len(inp)-1)]
        inp = out
    return inp[0]

if arr_rev.count(2) % 2 == 1:
    if arr_rev.count(1) != arr_rev.count(3):
        print(1)
    else:
        print(0)
else:
    print(chanto(arr_rev))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
x=[0,0,0]
for i in range(n):
    p=int(s[i])-1
    x[p]+=1

for i in range(3):
    if x[i]!=0: p=i

if x[p]==1: print(1)
else: print(0)

Submission status: Wrong Answer

Solution code:
N=int(input())
num = int(input())
num = str(num)
list_num = list(num)
list_num = [int(s) for s in list_num]
length=N-1
answer=list_num

for count in range(N-1):
    for count_x in range(length):
        answer[count_x]=abs(answer[count_x]-answer[count_x+1])
        count_x+=1
    answer.pop(count_x)
    length-=1
    count+=1

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
from math import *
n=int(input())
a=list(input().rstrip())
for i in range(len(a)):
    a[i]=int(a[i])
print(abs(abs(a[0]-a[1])-abs(a[n-1]-a[n-2])))

Submission status: Wrong Answer

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

for _ in range(3):
    A = [abs(A[i] - A[i + 1]) for i in range(len(A) - 1)]

print(sum([a % 2 for a in A]) % 2)

Submission status: Wrong Answer

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

    for i in range(len(s) - 1):
        a = abs(s[i] - s[i + 1])
        if a != 0:
            t.append(a)

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


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

lst = []

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

work(lst)

Submission status: Wrong Answer

Solution code:
n = int(input())
num = list(input())
a = [[0]*n]*n
a[0] = [int(s) for s in num]

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

print(a[n-1][1])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(c) - 1 for c in input()]

# 0を消す
A = [a for a in A if a != 0]

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

else:
    if len(A) == 1:
        print(1)
    else:
        print(0)

Submission status: Wrong Answer

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

for _ in range(2):
    A = [abs(A[i] - A[i + 1]) for i in range(len(A) - 1)]

print(sum([a % 2 for a in A]) % 2)

Submission status: Wrong Answer

Solution code:
import math

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


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

def chanto(arr_rev):
    inp = arr_rev
    for i in range(N-1):
        out = [calc(inp[x], inp[x+1]) for x in range(len(inp)-1)]
        inp = out
    return inp[0]

if arr_rev.count(2) % 2 == 1:
    print(1)
else:
    print(chanto(arr_rev))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input()]
def pascal_parity(n):
    def cnt2(m):
        a = m & -m
        return a.bit_length() - 1
    S = [0] * (n+1)
    for i in range(1, n):
        S[i] = S[i-1] + cnt2(n+1-i) - cnt2(i)
    return [1 if s == 0 else 0 for s in S]

def calc(L):
    return [abs(L[i] - L[i-1]) for i in range(1, len(L))]

def calc_all(L):
    for i in range(len(L)-1):
        L = calc(L)
    return L[0]

if N <= 5:
    print(calc_all(A))
else:
    A = calc(A)
    pp = pascal_parity(N-1)
    s = sum([a * pp[i] for i, a in enumerate(A)])
    if 1 in A:
        print(s % 2)
    else:
        print(s % 4)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
A = list(map(int,str(S)))
for j in range(N):
	for i in range(N-1):
		k=A[i]-A[i+1]
		A[i]=abs(k)
print(A[0])

Submission status: Wrong Answer

Solution code:
vec1=[]
M=0
N=int(input())
M=N
vec1=list(map(int,input()))
for j in range(N-3):
  for i in range(M-2):
    vec1[i]=abs(vec1[i]-vec1[i+1])
  M-=1
print(vec1[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
count = 0
a = []
for i in range(n-1):
	a.append(abs(int(s[i])-int(s[i+1])))
b = set(a)
if len(b) in [1,3]:
	print(0)
elif 1 in b:
	print(1) 
else:
	print(2)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(c) - 1 for c in input()]

# 0を消す
A = [a for a in A if a != 0]

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

        print(0)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
A = np.array(list(map(int, list(input()))))

A = np.abs(np.diff(A))

tmp = 0
for i in range(len(A) - 1):
    # print(A[i], A[i+1])
    tmp += A[i+1] - A[i]

# print(tmp)
tmp = abs(tmp) % 3

if tmp == 0:
    print(0)
elif tmp == 1:
    print(1)
else:
    print(2)

Submission status: Wrong Answer

Solution code:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
S=input()
if n==2:
  print(abs((int(S[0])-int(S[1]))))
else:
  a,b,c,d=int(S[0]),int(S[1]),int(S[-2]),int(S[-1])
  ans=abs(abs(a-b)-abs(c-d))
  print(ans)

Submission status: Wrong Answer

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

if N == 2:
  print(a[0])
else:
  tmp1 = [a[i] for i in range(N)]	# 初期値
  tmp2 = []
  for i in range(1,N):
    tmp2 = []
    for j in range(0,N-i):
      tmp2.append(abs(tmp1[j]-tmp1[j+1]))
    tmp1 = tmp2
  print(tmp2[0])

Submission status: Wrong Answer

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

for _ in range(1):
    A = [abs(A[i] - A[i + 1]) for i in range(len(A) - 1)]


cnt = 0
prev = 0
for a in A:
    if a == 1 and prev == 0:
        cnt += 1
    if a == 2:
        cnt += 1
    prev = a

print(1 if cnt % 2 == 0 else 0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input()
if n%2==1:
	print(abs(int(a[0])-int(a[-1])))
else:
	x=[]
	for i in range(n-1):
		x.append(abs(int(a[i])-int(a[i+1])))
	print(abs(x[0]-x[-1]))

Submission status: Wrong Answer

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

for _ in range(3):
    A = [abs(A[i] - A[i + 1]) for i in range(len(A) - 1)]

cnt = 0
prev = 0
for a in A:
    if a == 1 and prev == 0:
        cnt += 1
    if a == 2:
        cnt += 1
    prev = a

print(1 if cnt % 2 == 1 else 0)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    A = input().rstrip('\n')
    A = [int(a) for a in A]

    while len(A) > 1:
        A_new = []
        for i in range(len(A) - 1):
            x = abs(A[i] - A[i+1])
            if x:
                A_new.append(x)
        A = A_new
        if len(A) == 0:
            print(0)
            exit()
    print(A[0])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import random

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

for _ in range(2):
    A = [abs(A[i] - A[i + 1]) for i in range(len(A) - 1)]

print(1 if sum(A) % 2 == 1 else 0)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(i) for i in input()]
while len(l)>1:
    t=l[:]
    l=[]
    i=1
    while len(t)>i:
        if t[i-1]!=t[i]:
            l.append(abs(t[i-1]-t[i]))
        i+=1
if len(l)==0:
    print(0)
else:
    print(l[0])

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    A = input().rstrip('\n')
    A = [int(a) for a in A]

    while len(A) > 1:
        AA = [0]
        for a in A:
            if AA[-1] != a:
                AA.append(a)
        A_new = []
        for i in range(1, len(AA) - 1):
            x = abs(AA[i] - AA[i+1])
            if x:
                A_new.append(x)
        A = A_new
        if len(A) == 0:
            print(0)
            exit()
    print(A[0])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
print("1")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, list(input())))
result = 0
for _ in range(n):
    nex = []
    for i in range(len(a)-1):
        p = abs(a[i]-a[i+1])
        if p != 0:
            nex.append(p)
    if len(nex) == 0:
        break
    elif len(nex) == 1:
        result = nex[0]
        break
    a = nex
print(result)

Submission status: Wrong Answer

Solution code:
t = int(input())
s = input()
l1 =[list(map(int,s))]
for i in range(0,t-1):
    x = []
    print(l1)
    for j in range(0,len(l1[i]) - 1):
        n = abs(l1[i][j]-l1[i][j+1])
        x.append(n)
    l1.append(x)
print(l1[-1][0])

Submission status: Wrong Answer

Solution code:
n=int(input())
b=int(input())
a=list(map(int,str(b)))
for i in range(1,n+1):
  for j in range(n+1-i):
    a[j-1]=abs(a[j-1]-a[j])
print(a[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input()))
b = sum(a)
if b%2==0:
  print(int(0))
else:
  print(int(1))

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
x = map(int, list(raw_input()))
y = [-1 for i in range(N)]

#print "x=",x, "y=",y

for i in range(N-1):
    #print "i=",i
    if i % 2 == 0:
        for j in range(N-i-2):
            #print "j=",j
            y[j] = abs(x[j]-x[j+1])
    else:
        for j in range(N-i-2):
            x[j] = abs(y[j]-y[j+1])

if N % 2 == 0:
    print (y[0])
else:
    print (x[0])

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N = inputI()
s_ = list(inputS())

s = []

for i in range(N-1):
  s.append(abs(int(s_[i])-int(s_[i+1])))
  
if set(s)=={0,2}:
  print(abs(s[0]-s[-1]))
else:
  print(abs(s[0]%2-s[-1]%2))

Submission status: Wrong Answer

Solution code:
print("2")

Submission status: Wrong Answer

Solution code:
t = int(input())
s = input()
l1 =[list(map(int,s))]
for i in range(0,t):
    x = []
    print(l1)
    for j in range(0,len(l1[i]) - 1):
        n = abs(l1[i][j]-l1[i][j+1])
        x.append(n)
    l1.append(x)
print(l1[-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
b=[abs(int(s[i])-int(s[i+1]))for i in range(n-1)]
print(sum(b)%3)

Submission status: Wrong Answer

Solution code:
n=int(input())
if n>=10:
  print("0")
else:
  print("1")

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N = inputI()
s_ = list(inputS())

s = []

for i in range(N-1):
  s.append(abs(int(s_[i])-int(s_[i+1])))
  
if set(s)=={0,2}:
  print(abs(s[0]-s[-1]))
else:
  print(abs(s[0]%22-s[-1]%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()))
    temp = []
    for i in range(1,len(a)):
        temp.append(abs(a[i]-a[i-1]))
    print(min(temp))





# 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: Time Limit Exceeded

Solution code:

n=int(input())
a=list(map(lambda x:int(x)-1,list(input())))
def slv(n,a):
    v=a[0]
    if all(v==x for x in a):return 0
    # 答えの偶奇を求める
    chk=0
    tmp=1
    tmpmod=1
    for i in range(n):
        x=a[i]%2
        chk+=a[i]*tmp
        chk%=2
        tmp*=n-1-i
        tmp//=i+1
    if chk:return 1
    if 1 in a:return 0
    a=[x//2 for x in a]
    return slv(n,a)*2

#n=pow(10,5)
#a=[i%3 for i in range(n)]
print(slv(n,a))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from functools import reduce
from itertools import starmap
from operator import xor, mul
N = int(input())
A = list(map(int ,input().strip()))

def solve(A):
    A = [abs(x-y) for x,y in zip(A,A[1:])]
    n = len(A)
    coef = 1
    for i in range(n-1):
        coef = coef ^ (coef << 1)
    coef = map(int, bin(coef)[2:])
    if 1 in A:
        B = [x % 2 for x in A]
        ans = reduce(xor, starmap(mul, zip(B,coef)))
    else:
        B = [x // 2 for x in A]
        ans = reduce(xor, starmap(mul, zip(B,coef)))*2
    return ans 

print(solve(A))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = list(input())
L = [int(x) for x in L]

while len(L) >1:
    for i in range(len(L)-1):
        L[i] = abs(L[i+1]-L[i])
    L.pop()
    
print(L[0])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [int(x) for x in input()]

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