def invert_binary(binary, d):
for i in range(1, d+1):
binary = binary[:i] + str(1 - int(binary[i-1])) + binary[i:]
return binary
data=[]
N = int(input())
for _ in range(N):
d = int(input())
binary = "1"
result = invert_binary(binary, d)
data.append(result[d-1])
for i in range(N):
print(data[i])
def factorial(n):
result = 1
for i in range(1, n + 1):
result *= i
return result
def calculate_placement_number(N, K, placement):
placement_number = 0
available_numbers = list(range(1, N + 1))
for i in range(K):
position = placement[i]
index = available_numbers.index(position)
placement_number += index * factorial(N - i - 1)
available_numbers.pop(index)
return placement_number + 1
N, K = map(int, input().split())
placement = list(map(int, input().split()))
placement_number = calculate_placement_number(N, K, placement)
print(placement_number)