Problem:
 Score : 300 points    Problem Statement There are N people, conveniently numbered 1 through N .
They were standing in a row yesterday, but now they are unsure of the order in which they were standing.
However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person.
According to their reports, the difference above for person i is A_i .  Based on these reports, find the number of the possible orders in which they were standing.
Since it can be extremely large, print the answer modulo 10^9+7 .
Note that the reports may be incorrect and thus there may be no consistent order.
In such a case, print 0 .      Constraints  1≦N≦10^5  0≦A_i≦N-1         Input The input is given from Standard Input in the following format:  N  A_1  A_2  ...  A_N       Output Print the number of the possible orders in which they were standing, modulo 10^9+7 .        Sample Input 1 5
2 4 4 0 2      Sample Output 1 4  There are four possible orders, as follows:   2,1,4,5,3  2,5,4,1,3  3,1,4,5,2  3,5,4,1,2        Sample Input 2 7
6 4 0 2 4 0 2      Sample Output 2 0  Any order would be inconsistent with the reports, thus the answer is 0 .       Sample Input 3 8
7 5 1 1 7 3 5 3      Sample Output 3 16

Solution (Python):
import collections

MOD = pow(10, 9)+7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    Acount = collections.Counter(A)
    Aitem = list(zip(*Acount.items()))
    ans = 1
    flag = True
    if N == 1:
        if Acount[0] != 1:
            flag = False
    elif N%2 == 0:
        if set(Aitem[1]) != {2}:
            flag = False
        for a in Aitem[0]:
            if a%2 == 0:
                flag = False
                break
    else:
        if set(Aitem[1]) != {1, 2}:
            flag = False
        if Acount[0] != 1:
            flag = False
        for a in Aitem[0]:
            if a%2 == 1:
                flag = False
                break
    if flag:
        for a in Aitem[1]:
            ans = (ans * a)%MOD
    else:
        ans = 0
    print(ans%MOD)

if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter
mod = 10**9+7
n = int(input())
A = list(map(int,input().split()))
dic = dict(Counter(A))
for k,v in dic.items():
    if n%2==0:
        if v!=2 or k==0:
            print(0)
            break
    else:
        if k!=0 and v!=2:
            print(0)
            break
        elif k==0 and v!=1:
            print(0)
            break
else:
    if n%2==0:
        print(2**len(dic)%mod)
    else:
        print(2**(len(dic)-1)%mod)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
d = 0

if n % 2 == 0:
    for i in range(n//2):
        d += (2*i + 1) * 2
    if d != sum(a):
        print(0)
        exit()
else:    
    for i in range(1, n//2+1):
        d += 4 * i
    if d != sum(a):
        print(0)
        exit()

print(2**(n//2) % (10**9+7))

Solution (Python):
from collections import Counter
MOD = 10**9+7
n = int(input())
a = list(map(int, input().split()))
count = Counter(a)
if n % 2 == 0:
    for i in range(1, n, 2):
        if i not in count or count[i] != 2:
            print(0)
            exit()
    print(pow(2, n//2, MOD))
else:
    for i in range(2, n, 2):
        if i not in count or count[i] != 2:
            print(0)
            exit()
    if 0 not in count or count[0] != 1:
        print(0)
        exit()
    print(pow(2, (n-1)//2, MOD))

Solution (Python):




import math
import sys
import bisect
import heapq  
from collections import deque

inf = 10 ** 15
mod = 10 ** 9 + 7

def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod

n = int(input())
evenflag = n%2==0
a = list(map(int, input().split()))
kouho = [0 for i in range(n)]
for num in a:
    if (evenflag and num%2==0) or (not evenflag and num%2==1):
        print(0)
        sys.exit()
    x = (n-1+num)//2
    y = n-1-x
    kouho[min(x,y)]+=1
ans = 0
if n%2 == 1:
    if kouho[n//2] != 1:
        print(0)
        sys.exit()
for i in range(n//2):
    if kouho[i] == 2:
        ans+=1
    else:
        print(0)
        sys.exit()

print(power(2,ans,mod))

Solution (Python):
MOD = 10**9 + 7
def main():
  N = int(input())
  A = list(map(int, input().split()))
  A = sorted(A)
  flag = True
  if N % 2 == 1:
    for i in range(N//2 + 1):
      if i == 0:
        if A[i] != 0:
          flag = False
          break
      else:
        if A[2*i-1] != 2*i or A[2*i] != 2*i:
          flag = False
          break
  else:
    for i in range(N//2):
      if A[2*i] != 2*i+1 or A[2*i+1] != 2*i +1:
        flag = False
        break
  if flag:
    print(pow(2, N//2, MOD))
  else:
    print(0)
if __name__ == "__main__":
  main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
if n % 2 == 1:
    if a[0] != 0:
        print(0)
        exit()
    a = a[1:]

for idx, i in enumerate(a):
    if n % 2 == 0:
        if (idx//2)*2 + 1 != i:
            print(0)
            exit()
    else:
        if ((idx//2)+1)*2 != i:
            print(0)
            exit()
    
print(divmod(pow(2, n//2),(10**9)+7)[1])

Solution (Python):
from collections import defaultdict

mod = 10**9 + 7

n = int(input())
a = list(map(int, input().split()))

cnt = defaultdict(int)
for i in range(n):
    cnt[a[i]//2] += 1

ans = 1
for i, v in cnt.items():
    if v % 2 == 1 and i != 0:
        print(0)
        exit()
    else:
        ans *= v % mod

print(ans % mod)

Solution (Python):
def main():
    from sys import stdin
    input = lambda : stdin.readline().rstrip()
    N = int(input())
    diff = [0] * N
    A = map(int,input().split())
    for a in A:
        diff[a] += 1

    r = N % 2
    if r == 1 and diff[0] != 1:
        print(0)
        return


    for i in range(r,N,2):
        if not diff[i] == 0:
            print(0)
            return

    ans = 1
    for i in range(r+1,N,2):
        if diff[i] == 2:
            ans = ans * 2 % (10**9+7)
        else:
            print(0)
            return
    print(ans)

main()

Solution (Python):
from collections import Counter


P = 10 ** 9 + 7

N = int(input())
numbers = [int(x) for x in input().split()]

def solve():
  counter = Counter(numbers)
  
  if N % 2 == 0:
    if all([counter[i] == 2 for i in range(1, N, 2)]):
      return (2 ** (N // 2)) % P
    else:
      return 0
  else:
    if all([counter[i] == 2 for i in range(2, N, 2)]) and counter[0] == 1:
      return (2 ** (N // 2)) % P
    else:
      return 0
    
print(solve())

Solution (Python):

from collections import Counter


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


c = Counter(A)
for k,v in c.items():
    if k == 0:
        if N % 2 == 0:
            if v != 0:
                print(0)
                exit()
        else:
            if v != 1:
                print(0)
                exit()
    else:
        if v!= 2:
            print(0)
            exit()
import math
print(pow(2, math.floor(N/2), 10**9 + 7))

Solution (Python):
import sys
from collections import Counter


def main():
  n, *lst = map(int, sys.stdin.read().split())
  lst = sorted(Counter(lst).items())
  l = len(lst)
  mod = 10 ** 9 + 7
  if n % 2:
    for i in range(l):
      if not i:
        if lst[i][0] or lst[i][1] != 1:
          print(0)
          quit()
      elif lst[i][0] != i * 2 or lst[i][1] != 2:
        print(0)
        quit()
  else:
    for i in range(l):
      if lst[i][0] != i * 2 + 1 or lst[i][1] != 2:
        print(0)
        quit()
  print((1 << (n >> 1)) % mod)


if __name__ == '__main__':
  main()

Solution (Python):
import sys

n, *lst = map(int, sys.stdin.read().split())
lst.sort()
mod = 10 ** 9 + 7
if n % 2:
  for i in range(1, n):
    if lst[i] != (i + 1) // 2 * 2:
      print(0)
      quit()
else:
  for i in range(n):
    if lst[i] != i // 2 * 2 + 1:
      print(0)
      quit()
print((1 << (n >> 1)) % mod)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))

MOD = 10**9+7

l = -((-N)//2)
c = [0] *l
flg = True
for a in A:
    if (N-a)%2 == 1:
        b = (N-a)//2
        if b < l+1:
            c[b] += 1
        else:
            flg = False
    else:
        flg = False

if N % 2 == 1:
    for i in range(l):
        if i == l-1:
            flg &= (c[i] == 1)
        else:
            flg &= (c[i]==2)
else:
    for i in range(l):
        flg &= (c[i] ==2)
if flg:
    print(pow(2,N//2,MOD))
else:
    print(0)

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]

def to_bin(x: int) -> str: return format(x, 'b') 
def to_oct(x: int) -> str: return format(x, 'o') 
def to_hex(x: int) -> str: return format(x, 'x') 
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res

MOD=10**9+7

import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left

def main():
    n = II()
    aa = MII()
    aa.sort()
    bb = []
    for i in range(n%2+1,n,2):
        bb += [i, i]
    if n%2==1:
        bb = [0] + bb
    if aa != bb:
        print(0)
        return None
    print((2**(n//2))%MOD)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]

def to_bin(x: int) -> str: return format(x, 'b') 
def to_oct(x: int) -> str: return format(x, 'o') 
def to_hex(x: int) -> str: return format(x, 'x') 
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res

import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left

def main():
    n = II()
    aa = MII()
    aa.sort()
    DIV = 10**9+7
    if n%2==1:
        bb = [0]
        for i in range(2,n,2):
            bb.append(i)
            bb.append(i)
    else:
        bb = []
        for i in range(1,n,2):
            bb.append(i)
            bb.append(i)
    if aa != bb:
        print(0)
        return None

    if n==1: print(1)
    elif n==2: print(2)
    elif n==3: print(2)
    else: print((2**(n//2))%DIV)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from collections import Counter

N = int(sys.stdin.readline().strip())
A = list(map(int, sys.stdin.readline().strip().split()))

counter = Counter(A)
if N % 2 == 1:
    if 0 not in counter or counter[0] != 1:
        print(0)
        sys.exit()
       
if len(counter) != (N+1) // 2:
    print(0)
    sys.exit()

for (pos, count) in counter.items():
    if N % 2 == 1 and pos % 2 == 1:
        print(0)
        sys.exit()
    elif N % 2 == 0 and pos % 2 == 0:
        print(0)
        sys.exit()
        
    if pos != 0 and count != 2:
        print(0)
        sys.exit()

print((2**(N//2)) % (10**9 + 7))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
for ind, i in enumerate(a):
    if n%2==0 and i!=ind//2*2+1:
        print(0)
        exit()
    if n%2==1 and i!=(ind+1)//2*2:
        print(0)
        exit()
print(pow(2, n//2, 10**9+7))

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import Counter

def modpow(n, p, m):
    if p == 0:
        return 1
    if p % 2 == 0:
        t = modpow(n, p // 2, m)
        return t * t % m
    return n * modpow(n, p - 1, m) % m


n = ni()
a = na()
co = Counter(a)

ok = True
if n % 2 == 0:
    cur = 1
    l = [(k, v) for k, v in co.items()]
    l.sort()
    for k, v in l:
        if k != cur or v != 2:
            ok = False
        cur += 2
else:
    cur = 0
    l = [(k, v) for k, v in co.items()]
    l.sort()
    for k, v in l:
        if cur == 0:
            if k != cur or v != 1:
                ok = False
        else:
            if k != cur or v != 2:
                ok = False
        cur += 2

if ok:
    print(modpow(2, n // 2, mod))
else:
    print(0)

Solution (Python):
n = int(input())
a_input = sorted(list(map(int,input().split())))
x = 10**9+7

if n%2==0:
    tmp = 1
    for i in range(0,n,2):
        if a_input[i]==a_input[i+1] and tmp==a_input[i]:
            tmp+=2
        else:
            print(0);exit()

else:
    tmp=2
    for i in range(1,n-1,2):
        if a_input[i]==a_input[i+1] and tmp==a_input[i]:
            tmp+=2
        else:
            print(0);exit()

print(pow(2,n//2,x))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()

if a[0]==0:
    a.remove(0)
    sta=0
else:
    sta=1
for i in range(1,len(a),2):
    if a[i]!=a[i-1] or a[i]%2!=sta or a[i]!=i+1-sta:
        print(0)
        exit()
ans=2**(len(a)//2)
print(ans%(10**9+7))

Solution (Python):
A=int(input())
import collections
l=list(map(int,input().split()))
l=collections.Counter(l)
if A%2==1:
   if l[0]!=1:
      print(0)
      exit()
   for i in range(1,A//2+1):
      if l[i*2] != 2:
         print(0)
         exit()
   print(2 ** (A//2)%(10**9+7))
else:
   for i in range(1,A,2):
      if l[i] != 2:
         print(0)
         exit()
   print(2 ** (A//2)%(10**9+7))

Solution (Python):
from collections import Counter

p=10**9+7
N=int(input())
A = list(map(int,input().split()))
c=Counter(A)

for item in c:
  if c[item]>2:
    print(0)
    exit()
  if item==0:
    if c[item]>1:
      print(0)
      exit()
else:
  ans = pow(2,N//2,p)
  
print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
table=[[0,0]]

m=10**9+7

ans=pow(2,N//2,m)
A.sort()

if N%2==0:
    if A[0]!=1:
        ans=0
    else:
        for i in range(N):
            if A[i]!=i+1-i%2:
                ans=0
else:
    if A[0]!=0:
        ans=0
    else:
        for i in range(1,N):
            if A[i]!=i+i%2:
                ans=0

print(ans)

Solution (Python):


n = int(input())
nums = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 1
d = {}
if n % 2 == 1:
    for i in range(0, n, 2):
        d[i] = 0
    d[0] += 1
else:
    for i in range(1, n, 2):
        d[i] = 0
f = True
for num in nums:
    if num not in d:
        print(0)
        break
    d[num] += 1
else:
    for v in d.values():
        if v != 2:
            print(0)
            break
    else:
        ans = pow(2, n // 2, mod)
        print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
a=sorted(list(map(int,input().split())))
if n%2==0:
    l=[]
    for i in range(n//2):
        l.append(i*2+1)
        l.append(i*2+1)
else:
    l=[0]
    for i in range(n//2):
        l.append((i+1)*2)
        l.append((i+1)*2)

if a==l:
    print(pow(2,n//2,1000000007))
else:
    print(0)

Solution (Python):
import math
N = int(input())
A = sorted([int(i) for i in input().split()])
mod = 10**9 + 7

if N % 2 == 0:
    if A == [i//2*2+1 for i in range(N)]:
        print(2**(N//2) % mod)
    else:
        print(0)
else:
    if A == [math.ceil(i/2)*2 for i in range(N)]:
        print(2**(N//2) % mod)
    else:
        print(0)

Solution (Python):
N=int(input())
A=[int(a) for a in input().split()]
cnt=[0 for _ in range(N//2 if N%2==0 else N//2+1)]
ans=0
for a in A:
  cnt[a//2]+=1
if N%2==0:
  if all(c==2 for c in cnt):
    ans=pow(2,N//2,10**9+7)
else:
  if cnt[0]==1 and all(c==2 for c in cnt[1:]):
    ans=pow(2,N//2,10**9+7)
print(ans)

Solution (Python):
import collections
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)
p = sorted(c.items())
ans = 1
if n % 2 == 0:
    for i in range(n//2):
        if p[i][0] != 2*i+1 or p[i][1] != 2:
            print(0)
            exit()
elif n % 2 == 1:
    for i in range(n//2 + 1):
        if i == 0:
            if p[i][0] != 0 or p[i][1] != 1:
                print(0)
                exit()
        elif p[i][0] != 2*i or p[i][1] != 2:
            print(0)
            exit()

print((2**(n//2))%(10**9+7))

Solution (Python):
import collections
n = int(input())
li = list(map(int,input().split()))

c = collections.Counter(li)




count_list = list(c.items())
count_list.sort()
keys = set(c.keys())


flag = True
if n%2 == 1:
    if keys != {i for i in range(n) if i%2 == 0}:
        print(0)
        exit()
    for i,c in enumerate(count_list):
        
        if c[0] == 0:
            if c[1]!=1:
                flag = False
        else:
            if c[1]!=2:
                flag = False
else:
    if keys != {i for i in range(n) if i%2 == 1}:
        print(0)
        exit()
    for i in count_list:
        if i[1] != 2:
            flag = False
if not flag:
    print(0)
    exit()

ans_tmp = 0
if n%2 == 1:
    ans_tmp = 2**((n-1)//2)
else:
    ans_tmp = 2**(n//2)
print(ans_tmp%(10**9+7))

Solution (Python):
n=int(input())

a=[int(x) for x in input().split()]

a.sort()

ans=True
if n%2==0:
  for i in range(n//2):
    if a[i*2]!= 2*i+1 or a[i*2+1]!=2*i+1:
      ans=False
else:
  if a[0]!=0:
    ans=False
  for i in range(n//2):
    if a[i*2+1]!=i*2+2 or a[i*2+1]!=i*2+2:
      ans=False
      
      
if(ans):
  print(2**(n//2)%1000000007)
else:
  print(0)

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
h = Counter()
for x in a:
    h[x] += 1
f = True
for k, v in h.most_common():
    if n % 2 == 1 and k == 0:
        if v != 1:
            f = False
            break
    elif v != 2:
        f = False
        break
MOD = 1000000007
def mpow(n, p, mod):
    r = 1
    while p > 0:
        if p & 1 == 1:
            r = r * n % mod
        n = n * n % mod
        p >>= 1
    return r
print(mpow(2, n // 2, MOD) if f else 0)

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
h = Counter()
for x in a:
    h[x] += 1
f = True
for k, v in h.most_common():
    if n % 2 == 1 and k == 0:
        if v != 1:
            f = False
            break
    elif v != 2:
        f = False
        break
MOD = 1000000007
def mpow(n, p, mod):
    r = 1
    while p > 0:
        if p & 1 == 1:
            r = r * n % mod
        n = n * n % mod
        p >>= 1
    return r
print(mpow(2, int(n / 2), MOD) if f else 0)

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
h = Counter()
for x in a:
    h[x] += 1
f = True
for k, v in h.items():
    if n % 2 == 1 and k == 0:
        if v != 1:
            f = False
            break
    elif v != 2:
        f = False
        break
MOD = 1000000007
def mpow(n, p, mod):
    r = 1
    while p > 0:
        if p & 1 == 1:
            r = r * n % mod
        n = n * n % mod
        p >>= 1
    return r
print(mpow(2, int(n / 2), MOD) if f else 0)

Solution (Python):
n=int(input())
a=sorted(list(map(int,input().split())))
mod=10**9+7
if n%2==1:
    for i in range(n):
        if a[i]!=2*((i+1)//2):
            print(0)
            exit()
    print((2**(n//2))%mod)
else:
    for i in range(n):
        if a[i]!=(((i//2)+1)*2)-1:
            print(0)
            exit()
    print((2**(n//2))%mod)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
mod = 10 ** 9 + 7

cnt = Counter(a)
if n % 2 == 0:
    for i, j in cnt.items():
        if j != 2 or not(1 <= i <= n - 1) :
            print(0)
            exit()
else:
    for i, j in cnt.items():
        if i == 0:
            if j != 1:
                print(0)
                exit()
        else:
            if j != 2 or not(1 <= i <= n - 1):
                print(0)
                exit()

num = n // 2
ans = pow(2, num, mod)
print(ans)

Solution (Python):
mod = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
a.sort()
if n % 2 == 0:
    val = 1
    for i in range(0, n-1, 2):
        if a[i] == a[i+1] == val:
            val += 2
            continue
        print(0)
        exit()
if n % 2 == 1:
    if a[0] != 0:
        print(0)
        exit()
    val = 2
    for i in range(1, n-1, 2):
        if a[i] == a[i+1] == val:
            val += 2
            continue
        print(0)
        exit()
ans = 1
for i in range(n//2): ans *= 2
print(ans % mod)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
if n%2==0:
    b=[0 for i in range(n//2)]
    k=n//2
    for i in range(n):
        if a[i]//2>k:
            print(0)
            break
        else:
            if b[a[i]//2-1]>1:
                print(0)
                break
            else:
                b[a[i]//2-1]+=1
    else:
        print(pow(2,n//2,10**9+7))
else:
    b=[0 for i in range(n//2+1)]
    for i in range(n):
        if a[i]//2>n//2+1:
            print(0)
            break
        elif a[i]==0:
            if b[0]==1:
                print(0)
                break
            else:
                b[0]+=1
        else:
            if b[a[i]//2]>1:
                print(0)
                break
            else:
                b[a[i]//2]+=1
    else:
        print(pow(2,n//2,10**9+7))

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]

a.sort()
ans = True
if n%2:
  key=0
  if a[0] != key:
    ans = False
  p = 1
else:
  key=1
  if a[0] != key or a[1] != key:
    ans = False
  p = 2

for i in range(p, n):
  if i%2 == n%2:
    key += 2
  if a[i] != key:
    ans = False
    break

if ans:
  print(pow(2, n//2, 10**9+7))
else:
  print(0)

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
key = True
if n%2:
  key = False
ans = True
for i in range(n):
  if key:
    if a[i] != (i//2)*2+1:
      ans = False
      break
  else:
    if a[i] != ((i+1)//2)*2:
      ans = False
      break

if ans:
  print(pow(2, n//2, pow(10, 9)+7))
else:
  print(0)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
from collections import Counter
cnt = Counter(a)

if n % 2 == 0:
    for i in range(1, n, 2):
        if cnt[i] != 2:
            print(0)
            quit()
else:
    if cnt[0] != 1:
        print(0)
        quit()
    for i in range(2, n, 2):
        if cnt[i] != 2:
            print(0)
            quit()
mod = 10 ** 9 + 7
print(2 ** (n // 2) % mod)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = sorted(list(map(int, input().split())))

    if n % 2 != 0:
        for i in range(n):
            if i == 0:
                if A[i] != 0:
                    print(0)
                    break
            else:
                if i % 2 != 0:
                    if A[i] - A[i - 1] != 2:
                        print(0)
                        break
                else:
                    if A[i] != A[i - 1]:
                        print(0)
                        break
        else:
            res = pow(2, n // 2, mod)
            print(res)
    else:
        for i in range(n):
            if i == 0:
                if A[i] != 1:
                    print(0)
                    break
            else:
                if i % 2 == 0:
                    if A[i] - A[i - 1] != 2:
                        print(0)
                        break
                else:
                    if A[i] != A[i - 1]:
                        print(0)
                        break
        else:
            res = pow(2, n // 2, mod)
            print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys
import math  
import bisect  
import queue  


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


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    order = []
    for a in A:
        order.append(((N + 1 + a) // 2, (N + 1 - a) // 2))

    cnt = {}
    for o in order:
        if o not in cnt:
            cnt[o] = 1
        else:
            cnt[o] += 1

    ans = 1
    MOD = 1000000007
    for k, v in cnt.items():
        if k[0] == k[1] and v > 1:
            ans = 0
            break
        elif v > 2:
            ans = 0
            break
        else:
            ans *= v
            ans %= MOD
    print(ans)

Solution (Python):
from collections import Counter
import sys
MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int,input().split()))

b = Counter(a)

ans = 1
if n % 2 == 0:
    for i in range(1,n,2):
        if b[i] == 2:
            ans = ans * 2 % MOD
        else:
            print(0)
            sys.exit()
            
else:
    if b[0] == 1:
        for i in range(2,n,2):
            if b[i] == 2:
                ans = ans * 2 % MOD
            else:
                print(0)
                sys.exit()
    else:
        print(0)
        sys.exit()
        
print(ans)

Solution (Python):
import sys

input = sys.stdin.readline

P = 10 ** 9 + 7


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()

    if N % 2 == 0:
        is_ok = True
        for i in range(N//2):
            if not A[2*i] == A[2*i+1] == (2*i+1):
                is_ok = False
        if is_ok:
            ans = pow(2, N//2, P)
        else:
            ans = 0

    else:
        is_ok = True
        if not A[0] == 0:
            is_ok = False
        for i in range((N-1)//2):
            if not A[2*(i+1)-1] == A[2*(i+1)] == 2*(i+1):
                is_ok = False
        if is_ok:
            ans = pow(2, (N-1)//2, P)
        else:
            ans = 0

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter
import sys
MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int,input().split()))

b = Counter(a)

ans = 1
if n % 2 == 0:
    for i in range(1,n,2):
        if b[i] == 2:
            ans = ans * 2 % MOD
        else:
            print(0)
            sys.exit()
            
else:
    if b[0] == 1:
        for i in range(2,n,2):
            if b[i] == 2:
                ans = ans * 2 % MOD
            else:
                print(0)
                sys.exit()
    else:
        print(0)
        sys.exit()
        
print(ans)

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
key = True
if n%2:
  key = False
ans = True
for i in range(n):
  if key:
    if a[i] != (i//2)*2+1:
      ans = False
      break
  else:
    if a[i] != ((i+1)//2)*2:
      ans = False
      break

if ans:
  print(pow(2, n//2, pow(10, 9)+7))
else:
  print(0)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

n = int(readline())
a = list(map(int, readline().split()))
counter = sorted(list(Counter(a).items()))
if n % 2 == 1:
    if counter[0] != (0, 1):
        print(0)
        exit()
    else:
        memo = 2
        counter.pop(0)
else:
    memo = 1
for k, v in counter:
    if memo != k or v != 2:
        print(0)
        exit()
    memo += 2
mod = 10 ** 9 + 7
print(pow(2, len(counter), mod))

Solution (Python):
from collections import defaultdict
def solve():
    N = int(input())
    A = list(map(int,input().split()))
    MOD = 10 ** 9 + 7

    d = defaultdict(int)

    for a in A:
        d[a] += 1
    
    num = 1
    if N % 2 != 0:
        if d[0] != 1:
            print(0)
            return
        num = 2
    
    while num < N:
        if d[num] != 2:
            print(0)
            return
        num += 2
    
    print(pow(2,N//2,MOD))
                
if __name__ == '__main__':
    solve()

Solution (Python):
from collections import Counter
M = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))
ac = Counter(A)

def validate():
    uniq = N // 2
    if N % 2 == 1:
        uniq += 1
        if ac[0] != 1:
            return False
    if len(ac) != uniq:
        return False
    for k, v in ac.items():
        if k == 0 and v == 1:
            continue
        if v != 2:
            return False
        if N % 2 == k % 2:
            return False
    return True


def solve():
    if not validate():
        return 0
    return pow(2, N//2, M)


print(solve())

Solution (Python):
from collections import defaultdict

N=int(input())
A=list(map(int,input().split()))
if N%2==0:
    check={2*i+1:2 for i in range(0,N//2)}
else:
    check={2*i:2 for i in range(0,N//2+1)}
    check[0]=1

data=defaultdict(int)
for i in range(0,N):
    data[A[i]]+=1

if data==check:
    print(pow(2,N//2,10**9+7))
else:
    print(0)

Solution (Python):
from collections import defaultdict
mod = 10**9+7
n = int(input())
a = list(map(int,input().split()))
dic = defaultdict(int)
for i in range(n):
    dic[a[i]] += 1
if n % 2 == 0:
    for i in range(n//2):
        if dic[2*i+1] != 2:
            print(0)
            exit()
else:
    for i in range(n//2):
        if dic[2*i+2] != 2:
            print(0)
            exit()
        if dic[0] != 1:
            print(0)
            exit()
print(pow(2,(n//2),mod))