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):
N = int(input())
A = list(map(int,input().split()))

A = list(sorted(A))
flag = 0
for i in range(N//2-1):
    if N % 2 == 1:
        if A[2*i+1]==A[2*i+2] and A[2*i+1] == 2*i+2:
            pass;
        else:
            flag = -1
            break;
    if N % 2 == 0:
        if A[2*i]==A[2*i] and A[2*i+1] == 2*i+1:
            pass;
        else:
            flag = -1
            break;
if flag == 0:
    ans = 2**(N//2)%(10**9+7)
    print (ans)
else:
    print(0)

Solution (Python):

from collections import Counter


def main():
    n = int(input())
    a = tuple(map(int, input().rstrip().split()))
    MOD = 10 ** 9 + 7
    s = (n // 2) * 2
    l = (n + 1) // 2
    if sum(a) == s * l:
        print(2 ** (n // 2) % MOD)
    else:
        print(0)


if __name__ == "__main__":
    main()

Solution (Python):

from collections import Counter


def main():
    n = int(input())
    a = tuple(map(int, input().rstrip().split()))
    MOD = 10 ** 9 + 7
    s = (n // 2) * 2
    l = (n + 1) // 2
    p = l if n % 2 == 0 else l - 1
    if sum(a) == s * l:
        print(2 ** p % MOD)
    else:
        print(0)


if __name__ == "__main__":
    main()

Solution (Python):

from collections import Counter


def main():
    n = int(input())
    a = sorted(Counter(map(int, input().rstrip().split())).items())
    MOD = 10 ** 9 + 7
    if n % 2 == 1 and a[0][1] != 1:
        print(0)
    elif not all(i[1] == 2 for i in a[1:]):
        print(0)
    else:
        if n % 2 == 0:
            print(2 ** len(a) % MOD)
        else:
            print(2 ** (len(a) - 1) % MOD)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
L = [int(v) for v in input().split()]
m = [set() for _ in range(N)]

t = N - 1
for i in range(N):
    v = L[i]
    e = (t + v) // 2
    s = t - e
    
    m[s].add(i)
    m[e].add(i)
    
l = set()
for v in m:
    if len(v) == 0:
        print("0")
        exit()
    elif len(v) == 1:
        v = list(v)
        if v[0] in l:
            print("0")
            exit()
        
        l.add(v[0])
        
c = (N - len(l)) // 2
print(2 ** c % (10 ** 9 + 7))

Solution (Python):
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

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

A = np.array(A)
c = np.bincount(A)
e = np.bincount(abs(np.arange(N - 1, -N, -2)))
if c.shape == e.shape and all(c == e):
    print(pow(2, N // 2, 10 ** 9 + 7))
else:
    print(0)

Solution (Python):
import sys

mod = 10**9 + 7

n = int(input())
li = list(map(int,input().split()))
li.sort()
cnt = 0

if n % 2 == 1:
    for i,s in enumerate(li):
        if i == 0 :
            if s != 0:
                print(0)
                sys.exit()
        else:
            if i % 2 == 1:
                if i + 1 != s:
                    print(0)
                    sys.exit()
            else:
                if i != s:
                    print(0)
                    sys.exit()
    res = (n-1)//2
    print((2**res)%mod)
    
else:
    for i,s in enumerate(li):
        if i % 2 == 1:
            if i != s:
                print(0)
                sys.exit()
        else:
            if i + 1 != s:
                print(0)
                sys.exit()

    res = n//2
    print((2**res)%mod)

Solution (Python):
from collections import Counter

N = int(input())
*A, = map(int, input().split())
MOD = 10**9 + 7
cnt = Counter(A)
if N % 2 == 0:
    for i in range(1, N+1, 2):
        if cnt[i] != 2:
            print(0)
            break
    else:
        print(pow(2, N//2, MOD))
else:
    if cnt[0] != 1:
        print(0)
    else:
        for i in range(2, N+1, 2):
            if cnt[i] != 2:
                print(0)
                break
        else:
            print(pow(2, N//2, MOD))

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

flag = True
if N%2 == 0:
    for i in range(N//2):
        if A[2 * i] == 2 * i+1 and A[2 * i+1] == 2 * i+1:
            pass
        else:
            flag = False
else:
    if A[0] == 0:
        pass
    else:
        flag = False
    for i in range((N)//2):
        
        if A[2 * i+1] == 2 * (i+1) and A[2 * i+2] == 2 * (i+1):
            pass
            
        else:
            
            flag = False

if flag:
    print ((2 ** (N//2))%(7 + 10 ** 9))
else:
    print (0)

Solution (Python):
import sys
import math
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
mod = 10 ** 9 + 7


A.sort()


check = 0
if N % 2 == 1:
    for i in range(1,N + 1):
        if A[i-1] != math.floor(i/2) * 2:
            check = 1
            break
if N %2 == 0:
    for i in range(N):
        if A[i] != math.floor(i/2) * 2 + 1:
            check = 1
            break

if check == 1:
    ans = 0
    print(ans)
    sys.exit()

if N % 2 == 1:
    jou = (N-1)/2
else:
    jou = N/2

ans = 1
for i in range(int(jou)):
    ans = (ans * 2) % mod

print(ans)

Solution (Python):

import numpy as np
MOD = 10**9 + 7
N = int(input())
A = np.array([int(x) for x in input().split()])

left = np.arange(N)
right = N-1-left
cnt_1 = np.bincount(np.abs(left-right))
cnt_2 = np.bincount(A)

if cnt_1.shape != cnt_2.shape or (cnt_1 != cnt_2).any():
  answer = 0
else:
  answer = pow(2, N//2, MOD)
  
print(answer)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
l=[0 for i in range(n)]
for x in a:
    l[x] += 1
p = [(0 if i % 2 == 0 else 2) for i in range(n // 2 * 2)]
if n % 2 == 1: p = [1] + p
if l != p:
    print(0)
    import sys
    sys.exit()


def mod_power(x, a, p):
    if a == 0:
        return 1
    t = mod_power(x, a // 2, p)
    if a % 2 == 0:
        return t * t % p
    else:
        return x * t * t % p

ans = 1




print(mod_power(2,n//2,10**9+7))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
l=[0 for i in range(n)]
for x in a:
    l[x] += 1
p = [(0 if i % 2 == 0 else 2) for i in range(n // 2 * 2)]
if n % 2 == 1: p = [1] + p
if l != p:
    print(0)
    import sys
    sys.exit()


def mod_power(x, a, p):
    if a == 0:
        return 1
    t = mod_power(x, a // 2, p)
    if a % 2 == 0:
        return t * t
    else:
        return x * t % p * t

ans = 1
for i in range(n // 2):
    ans *= 2
    ans %= 10 ** 9 + 7
print(ans)

Solution (Python):

N = int(input())

can_flg = True

lst_A = input().split()

for i in range(len(lst_A)):
    lst_A[i] = int(lst_A[i])

lst_A.sort()

while 1:
    if len(lst_A) % 2 == 1:
        if lst_A[0] != 0:
            can_flg = False
            break
        for i in range(1, len(lst_A), 2):
            if not((lst_A[i] == (i + 1)) and (lst_A[i + 1] == (i + 1))):
                can_flg = False
                break
    else:
        for i in range(0, len(lst_A), 2):
            if not ((lst_A[i] == (i + 1)) and (lst_A[i + 1] == (i + 1))):
                can_flg = False
                break
    break

if can_flg == True:
    ans = 2 ** (len(lst_A) // 2)
    ans = ans % (10 ** 9 + 7)
else:
    ans = 0

print(ans)

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

if n % 2 == 0:
    kakeru = n
else:
    kakeru = n + 1

if sum(int_a) == kakeru * (n // 2):
    syou = n // 2
    answer = 2 ** syou
    print(answer % ((10 ** 9) + 7))
else:
    print("0")

Solution (Python):
n = int(input())
a = input().split()
int_a =[]
for i in range(len(a)):
    int_a.append(int(a[i]))
if n % 2 == 0:
    kakeru = n
else:
    kakeru = n + 1

if sum(int_a) == kakeru * (n // 2):
    syou = n // 2
    answer = 2 ** syou
    print(answer % ((10 ** 9) + 7))
else:
    print("0")

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

Solution (Python):
def power_func(a,n,p):
  bi=str(format(n,"b"))
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

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

A.sort()
mod = int(1e9+7)

if N % 2 == 1:
  for i in range(N):
    if not ((i+1) // 2) *2 == A[i]:
      print(0)
      exit()
  else:
    ans = power_func(2, (N-1)//2, mod)
    print(ans)
else:
  for i in range(N):
    if not (i // 2) *2 + 1 == A[i]:
      print(0)
      exit()
  else:
    ans = power_func(2, N//2, mod)
    print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
if n % 2 == 0:
    a_ = [[a[i],a[i+1]] for i in range(0,n,2)]
    for i,j in enumerate(a_):
        j_ = j[0]
        k_ = j[1]
        if  (i*2+1) != j_ or (i*2+1) != k_:
            print(0)
            break
    else:
        r = (2 ** (n//2))%((10**9)+7)
        print(int(r))
else:
    if a[0] == 0:
        a_ = [[a[i],a[i+1]] for i in range(1,n,2)]
        for i,j in enumerate(a_,start=1):
            j_ = j[0]
            k_ = j[1]
            if i*2 != j_ or i*2 != k_:
                print(0)
                break
        else:
            r = (2**((n-1)//2))%((10**9)+7)
            print(int(r))
    else:
        print(0)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

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

def main():
  n=I()
  l=LI()

  l.sort()

  if n%2==0:
    for i in range(n//2):
      if l[i]!=i//2*2+1:
        return 0
  else:
    if l[0]!=0:
      return 0
    for i in range(1,n):
      if -(-i//2)*2!=l[i]:
        return 0
  return pow(2,n//2)%mod

print(main())

Solution (Python):
from itertools import accumulate
from bisect import bisect, bisect_left
from functools import reduce
from itertools import accumulate, product
from operator import itemgetter, xor
from math import sqrt
from random import randint, random
from heapq import heappop, heappush

from fractions import gcd
from collections import Counter, deque, defaultdict

import sys

from sys import setrecursionlimit
setrecursionlimit(10**9)

def inpl(): return list(map(int, input().split()))
MOD = 10**9 + 7
N = int(input())
A = inpl()
C = Counter(A)
OK = True

if (N%2) and (C[0] != 1):
    OK = False
for i in range(N//2):
    if C[2*(i+1) -1 + N%2] != 2:
        OK = False

print(pow(2, N//2, MOD)*OK)

Solution (Python):

"""考え方
・Nが奇数の時、
0が一個と、
2, 4, 6, ..., K (< N)が2個ずつ

・Nが偶数の時、
1, 3, ... K (< N)が2個ずつ

"""
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10**9+7

    dic = {}
    for a in A:
        if not a in dic:
            dic[a] = 0
        dic[a] += 1
    
    if N%2 == 0:
        
        for i in range(N):
            num = i*2+1
            if num > N:
                break

            if not num in dic:
                print(0)
                return

            if dic[num] == 2:
                continue
            else:
                print(0)
                return
        print((2**i)%MOD)
        return
    else:
        
        i = -1
        while True:
            i += 1
            num = i*2
            if num > N:
                break
            
            if not num in dic:
                print(0)
                return
            
            if num == 0 and dic[num] == 1:
                continue
            elif num != 0 and dic[num] == 2:
                continue
            else:
                print(0)
                return
        print((2**(i-1))%MOD)
        return
        

if __name__ == "__main__":
    solve()

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

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

Solution (Python):

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


a.sort()
flag = True
if n %2==1:
    for n,v in enumerate(a):
        if n==0:
            if v != 0:
                flag=False
                break
        else:
            if v!=((n+1)//2)*2:
                flag=False
                break
else:
    for n,v in enumerate(a):
        if v!=(n//2)*2+1:
            flag=False
            break
if flag:
    print(2**(len(a)//2)%(10**9+7))
else:
    print(0)

Solution (Python):
n = int(input())
response_list = [ int(v) for v in input().split() ]

ans = 0

mod = 10**9+7


if n % 2 == 0:
	right_list = [ 2*(i//2+1)-1 for i in range(n) ]
else:
	right_list = [ 2*((i+1)//2) for i in range(n) ]

if sorted(response_list) == right_list:

	if n % 2 == 0:
		ans = pow(2,n//2,mod)
	else:
		ans = pow(2,(n-1)//2,mod)

print(ans)

Solution (Python):
from collections import Counter

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

K = Counter(A).most_common()
flag = True

for i in range(len(K)):
    if K[i][1] != 2:
        if K[i][0] == 0 and K[i][1] == 1:
            continue
        else:
            flag = False

if flag:
    print((2 ** (N // 2)) % (10 ** 9 + 7))
else:
    print(0)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

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

def main():
  n=I()
  l=LI()

  l.sort()

  if n%2==0:
    for i in range(n):
      if (i//2)*2+1!=l[i]:
        return 0
    return pow(2,n//2)%mod

  else:
    if l[0]!=0:
      return 0
    l=l[1:]
    for i in range(n-1):
      if (i//2)*2+2!=l[i]:
        return 0
    return pow(2,n//2)%mod

print(main())

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

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

def main():
  n=I()
  l=LI()

  l.sort()

  if n%2==0:
    for i in range(n):
      if (i//2)*2+1!=l[i]:
        return 0
    return pow(2,n//2)%mod

  else:
    if l[0]!=0:
      return 0
    l.remove(0)
    for i in range(n-1):
      if (i//2)*2+2!=l[i]:
        return 0
    return pow(2,n//2)%mod

print(main())

Solution (Python):
a=1000000007
n=int(input())
l=list(map(int,input().split()))
l.sort()
if n%2==1:
  if l[0]!=0:
    print(0)
    exit()
  else:
    l.remove(0)
    sh=2
    f=0
    for i in l:
      if f==0:
        if i!=sh:
          print(0)
          exit()
        else:
          f=1
      else:
        if i!=sh:
          print(0)
          exit()
        else:
          sh+=2
          f=0
  sh=(n-1)//2
  b=1
  for i in range(sh):
    b*=2
    b%=a
  print(b)
else:
  sh=1
  f=0
  for i in l:
    if f==0:
      if i!=sh:
        print(0)
        exit()
      else:
        f=1
    else:
      if i!=sh:
        print(0)
        exit()
      else:
        sh+=2
        f=0
  sh=n//2
  b=1
  for i in range(sh):
    b*=2
    b%=a
  print(b)

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

A.sort()
flag = True

if N%2==1:
    b=[0]
    for i in range(1, N):
        c=i
        if i%2==1:
            c += 1
        b.append(c)
    if A != b:
        print(0)
    else:
        if N==1:
            print(1)
        else:
            ans = 2
            for i in range((N-1)//2-1):
                ans *= 2
                ans = ans % (10**9+7)
            print(ans)
    
else:
    d=[]
    for i in range(N):
        e=i
        if i%2==0:
            e += 1
        d.append(e)
    
    if A != d:
        print(0)
    else:
        ans = 2
        for i in range(N//2-1):
            ans *= 2
            ans = ans % (10**9+7)
        print(ans)

Solution (Python):

import math



MOD = 1000000007
def solve_odd(an):
  l = len(an)
  dif = (l+1)%2
  
  for i in range(l):
    if math.ceil((i+dif)/2)*2 != an[i]+dif:
      return 0
  ans = 1  
  
  for _ in range(l//2):
    ans = (ans*2) % MOD
  return ans


N = int(input())
An = list(map(int, input().split()))
An = sorted(An)
print(solve_odd(An))

Solution (Python):
N = int(input())
if N == 1:
    print(1)
    exit()
A = list(map(int, input().split()))
A = sorted(A)[::-1]
memo = [0 for i in range(N)]
memo[0] = N-1
memo[1] = N-1
if N % 2 == 0:
    for i in range(2, N):
        memo[i] = memo[i-2]-2
        if memo[i] != A[i]:
            print(0)
            exit()
else:
    for i in range(2, N-1):
        memo[i] = memo[i-2]-2
        if memo[i] != A[i]:
            print(0)
            exit()



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

Solution (Python):
N=int(input())
A=map(int,input().split())
if N%2==0:
  if sorted(A)==sorted([i*2+1 for i in range(N//2)]*2):
    print(2**(N//2) % (10**9+7))
  else:
    print('0')
else:
  if sorted(A)==sorted([(j+1)*2 for j in range(N//2)]*2+[0]):
      print(2**(N//2) % (10**9+7))
  else:
    print('0')

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) 

from collections import Counter

N = int(input())
A = [int(i) for i in input().split()]

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

if ans == 0:
    print(ans)
else:
    print(2**cnt%mod)

Solution (Python):
from collections import Counter
N, *A = map(int, open(0).read().split())
l = [v for _, v in sorted(Counter(A).items())]
if all(v == 2 for v in l[N % 2:]) and (N % 2 == 0 or l[0] == 1):
    print(2 ** (N // 2) % (10 ** 9 + 7))
else:
    print(0)

Solution (Python):
from collections import Counter
n = int(input())
A = Counter(map(int, input().split()))
A[0] = 2
mod = 10 ** 9 + 7


def n_power_m_mod(n, m, mod):
    ret = 1
    for _ in range(m):
        ret *= n
        ret %= mod
    return ret


if all(v == 2 for v in A.values()):
    print(n_power_m_mod(2, n//2, mod))
else:
    print(0)

Solution (Python):
from collections import defaultdict


def is_valid(xs):
    d = defaultdict(lambda: 0)
    for x in xs:
        d[x] += 1

    if len(xs) % 2 == 0:
        for v in range(1, len(xs), 2):
            if d[v] != 2:
                return False
    else:
        if d[0] != 1:
            return False
        for v in range(2, len(xs), 2):
            if d[v] != 2:
                return False

    return True


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

if is_valid(xs):
    print(2 ** (n // 2) % 1000000007)
else:
    print(0)

Solution (Python):
n=int(input())
arr=list(map(int,input().split()))
if n%2==1:
  cnt=[0]*(n//2+1)
  for i in range(n):
    cnt[arr[i]//2]+=1
  if cnt[0]==1 and cnt.count(2)==n//2:
    print((2**(n//2))%(10**9+7))
  else:
    print(0)
else:
  cnt=[0]*(n//2)
  for i in range(n):
    cnt[(arr[i]-1)//2]+=1
  if cnt.count(2)==n//2:
    print((2**(n//2))%(10**9+7))
  else:
    print(0)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
flag = True
if N % 2 == 1:
  
  if A[0] == 0:
    for i in range(1, N, 2):
      if A[i] != i+1 or A[i+1] != i+1:
        flag = False
        break
    if flag:
      ans = 2**(N//2) % (10**9+7)
else:  
  
  if A[0] != 0:
    for i in range(0, N, 2):
      if A[i] != i+1 or A[i+1] != i+1:
        flag = False
        break
    if flag:
      ans = 2**(N//2) % (10**9+7)
print(ans)

Solution (Python):
from collections import defaultdict

MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for ai in a:
    d[ai] += 1
ans = 1
if n % 2:
    for k, v in d.items():
        if k > 0 and v == 2:
            ans *= 2
        elif k == 0 and v == 1:
            ans *= 1
        else:
            ans = 0
            break
        ans = ans % MOD
else:
    for v in d.values():
        if v == 2:
            ans *= 2
        else:
            ans = 0
            break
        ans = ans % MOD
print(ans)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]

MOD = 10 ** 9 + 7

ex = []
if N % 2 == 1:
    ex.append(0)
    for i in range(1, N//2 + 1):
        ex.append(i*2)
        ex.append(i*2)
    ans = 2 ** (N//2)
    ans %= MOD
else:
    for i in range(N//2):
        ex.append(i*2 + 1)
        ex.append(i*2 + 1)
    ans = 2 ** (N//2)
    ans %= MOD

A.sort()
if A != ex:
    ans = 0


print(ans)

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

Solution (Python):
N=int(input())
A=sorted(map(int,input().split()))
mod=10**9+7
cnt = [0]*N
for a in A:
    if (1+a+N)%2:
        print(0)
        break
    cnt[a]+=1
    if cnt[a]>2:
        print(0)
        break
else:
    if cnt[0]>1:
        print(0)
    elif cnt[1:].count(1)>1:
        print(0)
    else:
        ans = 1
        for _ in range(N//2): ans=(ans*2)%mod
        print(ans)

Solution (Python):
from collections import defaultdict

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

c = defaultdict(int)
for a in A:
    c[a] += 1

if N % 2 == 0:
    probable = True
    for i in range(1, N, 2):
        if c[i] != 2:
            probable = False
    ans = 2 ** (N // 2) % (10 ** 9 + 7) if probable else 0
else:
    probable = True
    if c[0] != 1:
        probable = False
    for i in range(2, N, 2):
        if c[i] != 2:
            probable = False
    ans = 2 ** ((N - 1) // 2) % (10 ** 9 + 7) if probable else 0
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
flag = True
if N % 2 == 1:
  
  if A[0] == 0:
    for i in range(1,N,2):
      if A[i] != i+1 or A[i+1] != i+1:
        flag = False
        break
    if flag: ans = 2**(N//2) % (10**9 + 7)

else:
  
  if A[0] != 0:
    for i in range(0,N,2):
      if A[i] != i+1 or A[i+1] != i+1:
        flag = False
        break
    if flag: ans = 2**(N//2) % (10**9 + 7)
    
print(ans)

Solution (Python):
import math
N = int(input())


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

A.sort()
ans = 0
flag = True
if N % 2 == 1:
  
  if A[0] == 0:
    for i in range(1,N,2):
      if A[i] != i+1 or A[i+1] != i+1:
        flag = False
        break
  
    if flag: ans = 2**(N//2) % (10**9 + 7)

else:
  if A[0] != 0:
    for i in range(0,N,2):
      if A[i] != i+1 or A[i+1] != i+1:
        flag = False
        break
  
    if flag: ans = 2**(N//2) % (10**9 + 7)
    
    
    
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))

if N % 2 == 1:
    if A.count(0) != 1:
        print(0)
        quit()

c = {}
for e in A:
    if e == 0:
        continue
    if e in c.keys():
        c[e] += 1
    else:
        c[e] = 1
if all([x == 2 for x in c.values()]):
    print(2**(N//2)%(10**9+7))
else:
    print(0)

Solution (Python):
def main():
	N = int(input())
	A = list(map(int, input().split()))
	DIV = 10**9+7
	ans = 0
	lie = False
	count = [0]*N
	odd = N % 2 == 1
	for i in range(N):
		if A[i] > N-1:
			lie = True
			break
		if (A[i]%2 == 0) ^ odd:
			lie = True
			break
		count[A[i]] += 1
		if count[A[i]] > 2:
			lie = True
			break

	if odd and count[0] != 1:
		lie = True
	if not(odd) and count[0] > 0:
		lie = True

	if lie:
		print(0)
	else:
		print((2**(N//2))%DIV)


if __name__ == '__main__':
	main()

Solution (Python):
n = int(input())
odd = n % 2 == 1

if sorted(list(input().split())) == ["0"] * odd + sorted([str(i) for i in range(1 + odd, n, 2)] * 2):
    cnt = 1
    for i in range(n//2):
        cnt *= 2
        cnt = cnt % (10 ** 9 + 7)
    print(cnt)
else:
    print(0)

Solution (Python):


def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist


def possibility_check(n, alist):
    alist.sort()

    if n % 2:
        even = [x for x in range(2, n) if x % 2 == 0]
        comp = [0] + even + even
        comp.sort()

    else:
        odd = [x for x in range(1, n) if x % 2 == 1]
        comp = odd + odd
        comp.sort()

    if alist == comp:
        return True
    else:
        return False


def submit():
    n, alist = read_input()

    if possibility_check(n, alist):
        
        ans = 1
        for i in range(n // 2):
            ans *= 2
            if ans > 10**9 + 7:
                ans %= (10**9 + 7)
        print(ans)
    else:
        print(0)


if __name__ == '__main__':
    submit()

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

if n%2==0:
    if sorted(a) != [(k//2)*2+1 for k in range(n)]:
        print(0)
    else:
        ans = 2**(n//2)
        print(ans % (10**9+7))
else:
    if sorted(a)!= [0]+[(k//2+1)*2 for k in range(n-1)]:
        print(0)
    else:
        ans = 2**(n//2)
        print(ans % (10**9+7))

Solution (Python):
from collections import Counter

N = int(input())
A = [int(i) for i in input().split()]
c = Counter(A)

flg = 0
if N % 2:
    if c[0] != 1:
        flg = 1
    else:
        for i in range(2, N, 2):
            if c[i] != 2:
                flg = 1
                break
else:
    for i in range(1, N, 2):
        if c[i] != 2:
            flg = 1
            break

if flg:
    ans = 0
else:
    ans = 2 ** (N//2) % (10**9+7)

print(ans)

Solution (Python):
from collections import Counter
N = int(input())
A = sorted(Counter(list(map(int, input().split()))).items(), key=lambda x: x[0])
if len(A) != (N + 1) // 2:
    print(0)
    exit()
if N % 2 == 1:
    if A[0][0] != 0 or A[0][1] != 1:
        print(0)
        exit()
    for (a, n), i in zip(A[1:], range(2, N + 1, 2)):
        if a != i or n != 2:
            print(0)
            exit()
else:
    for (a, n), i in zip(A, range(1, N + 1, 2)):
        if a != i or n != 2:
            print(0)
            exit()
print(2 ** (N // 2) % (10 ** 9 + 7))

Solution (Python):
MOD = 10**9 + 7
from collections import Counter
n = int(input())
a = [int(item) for item in input().split()]
cnt = Counter(a)

if n % 2 == 1:
    for i in range(n//2):
        if i == 0:
            if cnt[i] != 1:
                print(0)
                exit()
        else:
            if cnt[i*2] != 2:
                print(0)
                exit()
    print(pow(2, len(cnt)-1, MOD))
else:
    for i in range(n//2):
        if cnt[1 + i*2] != 2:
            print(0)
            exit()
    print(pow(2, len(cnt), MOD))

Solution (Python):
import sys
from collections import defaultdict

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    MOD = 10**9 + 7
    d = defaultdict(lambda: 0)
    for a in A:
        d[a] += 1
        if d[a] >= 3:
            return 0

    if not (d[0] == 0 or d[0] == 1):
        return 0

    cnt = 0
    A = set(A)
    for a in A:
        if a == 0:
            continue

        if d[a] != 2:
            return 0
        else:
            cnt += 1

    return (2**cnt) % MOD


if __name__ == '__main__':
    print(main())

Solution (Python):
n=int(input())
A=[int(i) for i in input().split()]
B=[]
if n%2==0:
  for i in range(n//2):
    B.append(2*i+1)
    B.append(2*i+1)
  print(pow(2,n//2,10**9+7) if B==sorted(A) else 0)
else:
  B=[0]
  for i in range((n-1)//2):
    B.append(2*(i+1))
    B.append(2*(i+1))
  print(pow(2,(n-1)//2,10**9+7) if B==sorted(A) else 0)

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

if N % 2: 
    T = [int(i+1) //2 * 2 for i in range(N)]
    if sorted(A) == T:
        print (2**(N//2) % (10 ** 9 + 7))
    else: 
        print(0)
        
else: 
    T = [int(i // 2 * 2 + 1)  for i in range(N)]
    if sorted(A) == T:
        print (2**(N//2) % (10 ** 9 + 7))
    else: 
        print(0)

Solution (Python):
import collections
import sys
l = int(input())
inputs = [int(j) for j in input().split(' ')]
cs = collections.Counter(inputs)
if l % 2 == 0:
  for v,c in cs.items():
    if v % 2 == 0 or c != 2:
      print(0)
      sys.exit()
else:
  for v,c in cs.items():
    if v % 2 != 0 or (c != 2 and v != 0):
      print(0)
      sys.exit()
print(2**int(l/2)%(10**9+7))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

dic = {}
def power(x, y):
   if y == 0:
       return 1
   elif y == 1:
       return x % mod
   elif y % 2 == 0:
       return power(x, y/2) ** 2 % mod
   else:
       return power(x, (y-1)/2) ** 2 * x % mod

for i in range(N):
	if not A[i] in dic:
		dic[A[i]] = 1
	else:
		dic[A[i]] += 1

if N%2 == 0: 
	for i in range(N//2):
		if N-1-2*i not in dic:
			print(0)
			break
		elif dic[N-1-2*i] != 2:
			print(0)
			break
		else:
			pass
	else:
		print(power(2,(N//2)))
else: 
	if A.count(0) != 1:
		print(0)
	else:
		for i in range(N//2-1):
			if N-1-2*i not in dic:
				print(0)
				break
			elif dic[N-1-2*i] != 2:
				print(0)
				break
			else:
				pass
		else:
			print(power(2,(N//2)))

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]

import itertools
count = 0
check = [int(abs((N-i+1)- i)) for i in range(1,N+1)]
flag = sorted(A) == sorted(check)
if flag:
    print(2 ** (N//2) % (10 ** 9 + 7))
else:
    print(0)