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



Sample input:
5
2 4 4 0 2


Sample output:
4

Submission status: Accepted

Solution code:
n=int(input())
A=sorted((map(int,input().split())))
G=sorted([2*(i+1) for i in range(n//2)]*2+[0])
K=sorted([(2*i+1) for i in range(n//2)]*2)
if n%2:
	if A!=G:
		print(0)
		exit()
else:
	if A!=K:
		print(0)
		exit()
print(2**(n//2)%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7

C = dict(Counter(A))

ans = 1
if N%2==0:
    for i in range(N//2):
        if C.get(i*2+1) == 2:
            ans *= 2
            ans %= mod
        else:
            ans = 0
            break
else:
    if C[0] == 1:
        for i in range(N//2):
            if C.get(i*2+2) == 2:
                ans *= 2
                ans %= mod
            else:
                ans = 0
                break
    else:
        ans = 0

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A=[int(x) for x in input().split()]
H= True
A.sort()
if N%2==0:
  for i in range(N):
    if A[i] != 2*(i//2)+1:
      H=False
else:
  if A[0]!=0:
    H=False
  for i in range(1,N):
    if A[i]!=2*((i-1)//2)+2:
      H=False
print(2**(N//2)%(10**9+7) if H else '0')

Submission status: Accepted

Solution code:
MOD=1000000007
N=int(input())
a=[int(_) for _ in input().split()]
cnt=[0]*N
if N%2==0:
    for i in range(N):
        cnt[a[i]]+=1
    f=True
    for i in range(N):
        if i%2==0 and cnt[i]!=0:
            f=False
        elif i%2==1 and cnt[i]!=2:
            f=False
    if f:
        res=1
        for i in range(N//2):
            res=(res*2)%MOD
        print(res)
    else:
        print(0)
elif N%2==1:
    for i in range(N):
        cnt[a[i]]+=1
    f=True
    for i in range(N):
        if i==0 and cnt[i]!=1:
            f=False
        elif i!=0 and i%2==0 and cnt[i]!=2:
            f=False
        elif i%2==1 and cnt[i]!=0:
            f=False
    if f:
        res=1
        for i in range((N-1)//2):
            res=(res*2)%MOD
        print(res)
    else:
        print(0)

Submission status: Accepted

Solution code:
def examC(mod):
    N = I()
    A = LI()
    num = (N+1)%2
    loop = (N+1)//2
    cur = int(1)
    L = [0]*loop
    if num==0:
        L[0] +=1
    for i in range(N):
        L[A[i]//2] += 1
        if L[A[i]//2]>=3:
            cur = int(0)
            break
    for _ in range(N//2):
        cur = (cur*2)%mod
    print(cur)





import sys
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC(mod)

Submission status: Accepted

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

mod = 10**9 + 7

b = set(a)

if n%2==0:
    check = len([ i for i in a if i%2==1 ])
    if check==n and len(b)==(n//2):
        ans = 2**(n//2) % mod
        print(ans)
        exit()
    else:
        print(0)
        exit()
else:
    check = len([ i for i in a if i%2==0 ])
    if check==n and len(b)==((n+1)//2) and a.count(0)==1:
        ans = 2**((n-1)//2) % mod
        print(ans)
        exit()
    else:
        print(0)
        exit()

Submission status: Accepted

Solution code:
N = int(input())
box = list(map(int, input().split()))

if N%2==1:
    check = [1] + [2]*N
else:
    check = [2] + [2]*N
    
for i in box:
    check[i] -= 1

cnt = 0

for i in box:
    if check[i] == 0:
        cnt += 1
    else:
        print(0)
        break

if cnt == len(box):
    print(2**(N//2)%(10**9+7))

Submission status: Accepted

Solution code:
INF = 10**9 + 7

n = int(input())
a = list(map(int, input().split()))
if n%2==0:
    p = [0]*(n//2)
    for i in range(n):
        x = (a[i]-1)//2
        p[x]+=1
    m = len(p)
    for i in range(m):
        if p[i]!=2:
            print(0)
            exit()
    ans = (2**m)%INF
    print(ans)
else:
    p = [0]*(((n-1)//2)+1)
    for i in range(n):
        x = a[i]//2
        p[x]+=1
    m = len(p)
    if p[0]!=1:
        print(0)
        exit()
    for i in range(1,m):
        if p[i]!=2:
            print(0)
            exit()
    m -=1
    ans = (2**m)%INF
    print(ans)

Submission status: Accepted

Solution code:
import math
N = int(input())
A = list(map(int,input().split()))
flag=True
if N%2 == 0:
  if 0 in A or len(set(A)) != N//2:
    flag=False
else:
  if len([0 for a in A if a==0])!=1 or len(set(A))!=N//2+1:
    flag=False
if flag:
  print(2**(N//2)%(10**9+7))
else:
  print(0)

Submission status: Accepted

Solution code:
n = int(input())
L = [int(i) for i in input().split()]
L.sort()

def out_detect(n,L):
  flag = 0
  if n%2 == 0:
    for i in range(n):
      if L[i] != -(-(i+1)//2)*2-1:
        flag = 1
        break
  else:
    if L[0] != 0:
      flag = 1
      return (flag)
    for i in range(1,n):
      if L[i] != (-(-i//2)*2):
        flag = 1
        break
  return (flag)

if out_detect(n,L) == 1:
  print(0)
else:
  if n%2 == 0:
    out = pow(2,n//2)
  else:
    out = pow(2,(n-1)//2)
  print(out%(pow(10,9)+7))

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

if N % 2 == 0:
    for i in range(1, N // 2 + 1):
        if d[2 * i - 1] == 2:
            d[2 * i - 1] = 0
else:
    for i in range(1, N // 2 + 1):
        if d[2 * i] == 2:
            d[2 * i] = 0
    if d[0] == 1:
        d[0] = 0
if sum(d.values()) != 0:
        print(0)
else:
    print(2 ** (N // 2) % (10**9 + 7))

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
set_A = set(A)

ans = 1

if n%2==0:
  if n//2 != len(set(A)):
    ans = 0
else:
  if A.count(0)!=1:
    ans = 0
  
  set_A.remove(0)
  if (n-1)//2 != len(set_A):
    ans = 0
      
if ans!=0:
  ans = 2**(len(set_A))

print(ans%(10**9+7))

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
n=N//2
MOD=10**9+7
ans=(2**n)%MOD

import sys
if N==1:
    print(1)
    sys.exit()

f=1
if N%2==1:
    for i in range(N):
        if A[i] != 2*(-(-i//2)):
            f=0
            break
else:
    for i in range(N):
        if A[i] != 1+(i//2)*2:
            f=0
            break

print([0,ans][f])

Submission status: Accepted

Solution code:
INF = int(1e9+7)


def main():
    N, *An = map(int, open(0).read().split())
    An.sort()
    if N % 2:
        if [0] + [i for i in range(2, N, 2) for j in range(2)] == An:
            print(2 ** (N // 2) % INF)
            return
    else:
        if [i for i in range(1, N, 2) for j in range(2)] == An:
            print(2 ** (N // 2) % INF)
            return
    print(0)
    return


main()

Submission status: Accepted

Solution code:
from functools import reduce
INF = int(1e9+7)


def main():
    N, *An = map(int, open(0).read().split())
    An.sort()
    if N % 2:
        if [0] + [i for i in range(2, N, 2) for j in range(2)] == An:
            print(reduce(lambda x, y: (x << 1) % INF, range(N // 2), 1))
            return
    else:
        if [i for i in range(1, N, 2) for j in range(2)] == An:
            print(reduce(lambda x, y: (x << 1) % INF, range(N // 2), 1))
            return
    print(0)
    return


main()

Submission status: Accepted

Solution code:
n = int(input())
A = sorted(list(map(int,input().split())))

if n%2 == 0:
    for i in range(n):
        if A[i] != (i//2)*2+1:
            print(0)
            break
    else: print(2**(n//2)%1000000007)

else:
    for i in range(n):
        if A[i] != ((i+1)//2)*2:
            print(0)
            break
    else: print(2**(n//2)%1000000007)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
if N == 1:
    print(1)
    exit(0)

elif N % 2 == 0:
    for i in range(0,N//2+1,2):
        if A[i] == A[i+1]:
            continue
        else:
            print(0)
            exit(0)
else:
    for i in range(1,N//2+2,2):
        if A[i] == A[i+1]:
            continue
        else:
            print(0)
            exit(0)
print(2**(N//2)%(10**9+7))

Submission status: Accepted

Solution code:
MOD = 1000000007
n = int(input())
l = list(map(int,input().split()))
a = {}
for i in l:
    if i in a:
        a[i] += 1
    else:
        a[i] = 1

cur = 1 if n % 2 == 0 else 0

ok = True
while cur < n:
    x = 1 if cur == 0 else 2
    if not cur in a or a[cur] != x:
        ok = False
        break
    cur += 2

ans = 0
if ok:
    ans = 1
    for _ in range(n // 2):
        ans = ans * 2 % MOD

print(ans)

Submission status: Accepted

Solution code:
MOD = 1000000007
n = int(input())
l = list(map(int,input().split()))
a = {}
for i in l:
    if i in a:
        a[i] += 1
    else:
        a[i] = 1

cur = 1 if n % 2 == 0 else 0

ok = True
while cur < n:
    x = 1 if cur == 0 else 2
    if cur in a and a[cur] != x:
        ok = False
        break
    cur += 2

ans = 0
if ok:
    ans = 1
    for _ in range(n // 2):
        ans = ans * 2 % MOD

print(ans)

Submission status: Accepted

Solution code:
INFTY = 10**9+7
N = int(input())
A = list(map(int,input().split()))
C = {}
for i in range(N):
    if A[i] not in C:
        C[A[i]] = 0
    C[A[i]] += 1
if N%2==0:
    flag = 0
    for i in range(1,N,2):
        if i in C and C[i]==2:
            pass
        else:
            flag = 1
            break
else:
    flag = 0
    for i in range(2,N,2):
        if i in C and C[i]==2:
            pass
        else:
            flag = 1
            break
    if 0 not in C or C[0]!=1:
        flag = 1
cnt = 0
if flag==0:
    cnt = 1
    for i in range(N//2):
        cnt = (cnt*2)%INFTY
print(cnt)

Submission status: Accepted

Solution code:
mod = 10 ** 9 + 7
N = int(input())
A = [int(a) for a in input().split()]
A.sort()

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

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

print(order_count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter
MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    counter = Counter(A)

    if N%2==0:
        for value in counter.values():
            if value%2!=0:
                print(0)
                return 
        
        print(2**(N//2)%MOD)
    else:
        for key,value in counter.items():
            if (value%2!=0 and int(key)!=0) or (value%2==0 and int(key)==0):
                print(0)
                return 
        
        print(2**((N-1)//2)%MOD)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
d={}
for i in range(n):
  d[i]=0
for i in l:
  d[i]+=1
b=True
if n%2==1:
  if d[0]!=1:
    b=False
  for i in range(1,n//2+1):
    if d[i*2]!=2:
      b=False
else:
  for i in range(n//2):
    if d[i*2+1]!=2:
      b=False
if b:
  print((2**(n//2))%(10**9+7))
else:
  print(0)

Submission status: Accepted

Solution code:
n=int(input())
c=[0]*n
mod=1000000007
l=list(map(int,input().split()))
for i in l:
    c[i]+=1
if n%2==0:
    for i in range(n):
        if i%2==1:
            if c[i]!=2:
                print(0)
                exit()
    print((2**(n//2))%mod)
else:
    for i in range(n):
        if i==0:
            if c[i]!=1:
                print(0)
                exit()
        elif i%2==0:
            if c[i]!=2:
                print(0)
                exit()
    print((2**(n//2))%mod)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 0
if n%2==1:
  a.remove(0)
if a[0::2]==a[1::2]:
  ans = 2**(n//2)%(10**9+7)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
c=Counter(a)
if (1 in c.values() and c[0]!=1) or 3 in c.values():
    print(0)
else:
    if n%2==0:
        print((2**(n//2))%(10**9+7))
    else:
        print((2**((n-1)//2))%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
B = []
if N % 2 == 0:
    i_max = N // 2
    for i in range(1, i_max + 1):
        B.append(2 * i - 1)
        B.append(2 * i - 1)
else:
    i_max = (N - 1) // 2
    B.append(0)
    for i in range(1, i_max + 1):
        B.append(2 * i)
        B.append(2 * i)

if A == B:
    ans = (2 ** i_max) % (10**9 + 7)
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
# C - Lining Up

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

if N%2 == 0:
    tmp = []
    tmp2 = 1
    while tmp2 <= N-1:
        tmp.extend([tmp2, tmp2])
        tmp2 += 2
        
    if A != tmp:
        print(0)
    else:
        print((2**(N//2))%(10**9+7))
    
else:
    tmp = [0]
    tmp2 = 2
    while tmp2 <= N-1:
        tmp.extend([tmp2, tmp2])
        tmp2 += 2
        
    if A != tmp:
        print(0)
    else:
        print((2**((N-1)//2))%(10**9+7))

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
nums = {}
nums2 = {}
mod = 10**9 +7
for i in range(1,n+1):
    left = i -1
    right = n -i
    a = abs(left - right)
    if a in nums:
        nums[a] +=1
    else:
        nums[a] = 1

for a in A:
    if a in nums2:
        nums2[a] +=1
    else:
        nums2[a] = 1

if nums==nums2:
    if n%2==1:
        print(2**(len(nums)-1)%mod)
    else:
        print(2**(len(nums))%mod)
else:
    print(0)

Submission status: Accepted

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

for a in A:
  if a in checklist and checklist[a] in {1,2}:
    checklist[a] -= 1
  else:
    print(0)
    exit()
print(int(2**(N//2))%1000000007)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
mod = 10**9+7
#並びが可能なら、2**(N//2)
#無理なら0
opt = {}
for i in range(N):
  a = abs((N-i-1)-i)
  if a not in opt :
    opt[a] = 1
  else :
    opt[a] += 1 
for i in range(N):
  if A[i] not in opt or opt[A[i]] == 0 :
    print(0)
    exit()
  else:
    opt[A[i]] -= 1 
ans = (2**(N//2))%mod
print(ans)

Submission status: Accepted

Solution code:
def exp(n):
    if n == 0:
        return 1
    elif n == 1:
        return 2
    if n % 2 == 0:
        tmp = exp(n // 2) % 1000000007
        return (tmp * tmp) % 1000000007
    else:
        tmp = exp(n // 2) % 1000000007
        return (2 * tmp * tmp) % 1000000007
n = int(input())
ar = list(map(int, input().split()))
ar.sort()
if n % 2 == 0:
    curr = 1
    valid = True
    for i in range(1, n, 2):
        if ar[i] == ar[i - 1] == curr:
            curr += 2
            continue
        else:
            valid = False
            break
    if valid:
        print(exp(n // 2))
    else:
        print(0)
else:
    curr = 2
    valid = True
    if ar[0] != 0:
        valid = False
    else:
        for i in range(2, n, 2):
            if ar[i] == ar[i-1] == curr:
                curr += 2
                continue
            else:
                valid = False
                break
    if valid:
        print(exp(n // 2))
    else:
        print(0)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))

counter = collections.Counter(a)
ans = 1
for k, v in counter.items():
    if k != 0:
        if v == 2:
            ans *= 2
        if v == 1:
            ans = 0
            break
print(ans % (10**9 + 7))

Submission status: Accepted

Solution code:
from functools import reduce

if __name__ == "__main__":
    n = int(input())
    a = [int(x) for x in input().split()]
    x = [0]*n
    """if n % 2 == 0:
        for i in a:
            if i % 2 != 1:
                print(0)
                exit()
    else:
        for i in a:
            if i % 2 != 0:
                print(0)
                exit()"""
    for i in a:
        if i == 0 and x[i] == 1:
            print(0)
            exit()
        elif x[i] == 2:
            print(0)
            exit()
        else:
            x[i] += 1
    print(reduce(lambda x, y: x * y if y != 0 else x, x, 1) % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
from functools import reduce

if __name__ == "__main__":
    n = int(input())
    a = [int(x) for x in input().split()]
    x = [0]*n
    if n % 2 == 0:
        for i in a:
            if i % 2 != 1:
                print(0)
                exit()
    else:
        for i in a:
            if i % 2 != 0:
                print(0)
                exit()
    for i in a:
        if i == 0 and x[i] == 1:
            print(0)
            exit()
        elif x[i] == 2:
            print(0)
            exit()
        else:
            x[i] += 1
    print(reduce(lambda x, y: x * y if y != 0 else x, x, 1) % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
n=int(input())
a= list(map(int, input().split()))
a.sort()
ans=True
if n%2==0:
    for i in range(n//2):
        if a[2*i]!=a[2*i+1]:
            ans=False
    if ans:
        print((2**(n//2))%(1000000007))
    else:
        print(0)
else:
    for i in range(n//2):
        if a[2*i+1]!=a[2*i+2]:
            ans=False
    if ans:
        print((2**(n//2))%(1000000007))
    else:
        print(0)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def main():
  n = ni()
  a = na()
  mod = int(1e9+7)

  if n % 2 == 0 and len(set(a)) == n // 2:
    print(2 ** (n // 2) % mod)
  elif n % 2 == 1 and a.count(0) == 1:
    print(2 ** ((n - 1) // 2) % mod)
  else:
    print(0)
main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
test = [abs(n - (2*k + 1)) for k in range(n)]
if(sorted(a) == sorted(test)):
	print(pow(2, int(n/2)) % (pow(10,9) + 7))
else:
	print(0)

Submission status: Accepted

Solution code:
N = int(input().strip())
A = list(map(int, input().strip().split()))
x = N//2

C = [0]*N
for a in A:
    C[a]+=1

if N % 2 == 0:
    for i,c in enumerate(C):
        if i % 2 == 0:
            continue
        if C[i] != 2 :
            print("0")
            exit()
else:
    for i,c in enumerate(C):
        #print(i,c)
        if i % 2 == 1:
            continue
        if i == 0:
            if C[i] != 1:
                print("0")
                exit()
            else:
                continue
        elif C[i] != 2 :
            print("0")
            exit()

print((2**x)%int(1.0e9+7))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n = int(input())

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

a.sort()
if len(a) %2 == 1:
    odd = True
    now = 0
    if a[0] != 0:
        print(0)
        exit()
    now += 2
    for i in range(1,len(a)//2 + 1 , 2):
        if a[i] != now or a[i+1] != now:
            print(0)
            exit()
        now += 2
        
else:
    odd = False
    now = 1
    for i in range(0,len(a)//2 + 1,2):
        if a[i] != now or a[i+1] != now:
            print(0)
            exit()
        now += 2

print(2**(len(a)//2) %(10**9+7))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
flag = True
if N % 2 == 0:
    if 0 in A or len(set(A)) != N//2:
        flag = False
else:
    if len([0 for a in A if a == 0]) != 1 or len(set(A)) != N//2+1:
        flag = False
if flag:
    print(2**(N//2) % (10**9+7))
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for x in a:
    d[x] += 1
b = [i for i in range(n)[::-1]]
if not all([d[i] == 2, d[i] == 1][n % 2 and i == 0] for i in b[::2]):
    print(0)
else:
    ans = 1
    for v in d.values():
        ans = ans * v % (10**9+7)
    print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for x in a:
    d[x] += 1
b = [i for i in range(n)[::-1]]
e = all(d[i] == 2 if n % 2 == 0 else d[i] ==
        1 if i == 0 else d[i] == 2 for i in b[::2])
if not e:
    print(0)
    exit()
ans = 1
for v in d.values():
    ans = ans * v % (10**9+7)
print(ans)

Submission status: Accepted

Solution code:
import collections
DIVISOR = 10 ** 9 + 7

def check(n, a_count):
    if n % 2 == 1:
        if set(a_count.keys()) == set(range(0, n, 2)):
            if a_count[0] == 1 and all([a_count[key] == 2 for key in a_count if key != 0]):
                ans = (2 ** (n // 2)) % DIVISOR
                return ans
                
    else:
        if set(a_count.keys()) == set(range(1, n, 2)):
            if all([a_count[key] == 2 for key in a_count]):
                ans = (2 ** (n // 2)) % DIVISOR
                return ans
    return 0


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

a_count = collections.Counter(a)
print(check(n, a_count))

Submission status: Accepted

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

ans = 1

for i, v in a.items():
    if i == 0:
        if v != 1:
            print(0)
            exit()
    elif v != 2:
        print(0)
        exit()
    else:
        ans = ans * 2 % (10 ** 9 + 7)
print(ans)

Submission status: Accepted

Solution code:
import collections as coll
n=int(input())
a=list(map(int,input().split()))
if a.count(0)>1:
    print('0')
    exit()
x=10**9+7
f=0
s=coll.defaultdict(int)
for i in range(n):
    if n%2:
        if a[i]%2: f=1
    else:
        if a[i]%2==0: f=1
    s[a[i]]+=1
    if s[a[i]]>2: f=1
    if f==1:
        print('0')
        exit()
ans=1
for i in range(1,n//2+1): ans=ans*2%x
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
a = list(Counter(A).values())
mod = 10 ** 9 + 7

if N % 2 == 0:
    if a.count(2) == N // 2:
        ans = 1
        for i in range(N // 2):
            ans = ans * 2 % mod
        print(ans)
    else:
        print(0)
else:
    if a.count(2) == N // 2 and A.count(0) == 1:
        ans = 1
        for i in range(N // 2):
            ans = ans * 2 % mod
        print(ans)
    else:
        print(0)

Submission status: Accepted

Solution code:
from collections import Counter
MOD = 1000000007
N = int(input())
A = map(int, input().split())
c = Counter(A)
if N % 2 == 0:
    for i in range(1, N, 2):
        if c[i] != 2:
            print(0)
            exit()
    ans = 2 ** (N // 2) % MOD
else:
    if c[0] != 1:
        print(0)
        exit()
    for i in range(2, N, 2):
        if c[i] != 2:
            print(0)
            exit()
    ans = 2 ** (N // 2) % MOD
print(ans)

Submission status: Accepted

Solution code:
import collections

n = int(input())
a = list(map(int, input().split()))
li = collections.Counter(a)
key = set(li.keys())
flag = True
mod = (10**9)+7

if n % 2:
    num = set(list(range(0,n,2)))#n-1
    if len(key ^ num) != 0:
        flag = False

    for i in li:
        if i == 0 and li[i] != 1:
            flag = False

        elif i != 0 and li[i] != 2:
            flag = False

    if flag:
        print((2**((n-1)//2))%mod)
    else:
        print(0)
else:
    num = set(list(range(1,n,2)))
    if len(key ^ num) != 0:
        flag = False

    for i in li:
        if li[i] != 2:
            flag = False
    if flag:
        print((2**(n//2))%mod)
    else:
        print(0)

Submission status: Accepted

Solution code:
import collections
n = int(input())
list_a = list(map(int, input().split(" ")))
count = collections.Counter(list_a)

flag = True
for key, value in count.items():
  if value == 2 or (key == 0 and value == 1):
    pass
  else:
    flag = False
    break

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
out = 0
if n == 1:
    if a[0] != 0:
        out = 1
elif a[0] == 0:
    if n%2 == 0:
        out = 1
    else:
        for i in range(1,n//2+1):
            if a[2*i-1] == a[2*i] and a[2*i] == 2*i:
                None
            else:
                out = 1
elif a[0] == 1:
    if n%2 == 1:
        out = 1
    else:
        for i in range(n//2):
            if a[2*i] == a[2*i+1] == 2*i+1:
                None
            else:
                out = 1
else:
    out = 1
if out:
    print(0)
else:
    a = 1
    for i in range(n//2):
        a *= 2
        a = a%(10**9+7)
    print(a)

Submission status: Accepted

Solution code:
n = int(input())
ls = sorted(map(int, input().split()))
MOD = 10**9 + 7
ok = True
if n % 2 == 0:
    for i in range(n // 2):
        i *= 2
        ok = ls[i] == ls[i + 1] == i + 1
        if not ok:
            break
else:
    ok = ls[0] == 0
    for i in range(n // 2):
        i *= 2
        ok = ls[i + 1] == ls[i + 2] == i + 2
        if not ok:
            break
if not ok:
    print(0)
else:
    print(2**(n // 2) % MOD)

Submission status: Accepted

Solution code:
def main():
  mod=1000000007
  n=int(input())
  a=sorted(list(map(int,input().split())))
  if n%2==0:
    if a==[x//2*2+1 for x in range(n)]:
      print(2**(n//2)%mod)
      return
  else:
    if a==[0]+[x//2*2+2 for x in range(n-1)]:
      print(2**(n//2)%mod)
      return
  print(0)

main()

Submission status: Accepted

Solution code:
from sys import stdin
from collections import Counter
mod = 10**9+7
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
ans = 2**(N//2)
if N % 2 == 0:
    for i in A:
        if i % 2 == 0:
            ans = 0
    for j in Counter(A).values():
        if j != 2:
            ans = 0
else:
    for i in A:
        if i % 2 != 0:
            ans = 0
    for j,k in Counter(A).items():
        if j != 0 and k != 2:
            ans = 0
    if Counter(A)[0] != 1:
        ans = 0
print(ans%mod)

Submission status: Accepted

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

from collections import Counter

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

c = Counter(a)
ans = 1
mod = 10 ** 9 + 7
for k, v in c.items():
    if k == 0:
        num = 1
    else:
        num = 2

    if v == num:
        ans *= v
        ans %= mod
    else:
        ans = 0
        break

print(ans)

Submission status: Accepted

Solution code:
from math import ceil
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
CA = Counter(A)
SCA = sorted(CA.items(), key=lambda x:x[0])

if len(CA) != ceil(N / 2):
  print(0)
  exit()

if N % 2 == 0:
  for i, j in zip(SCA, range(ceil(N / 2))):
    if not (i[0] == 1 + j * 2 and i[1] == 2):
      print(0)
      exit()
else:
  for i, j in zip(SCA, range(ceil(N / 2))):
    if j == 0:
      if not (i[0] == j * 2 and i[1] == 1 ):
        print(0)
        exit() 
    else:  
      if not (i[0] == j * 2 and i[1] == 2 ):
        print(0)
        exit()
print((2 ** (N // 2)) % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
n = int(input())
A = [int(x) for x in input().split()]

Bi = []
if n % 2 == 0:
    half_Bi = list(range(1, n, 2))
    Bi = half_Bi + half_Bi
else:
    half_Bi = list(range(2, n, 2))
    Bi = half_Bi + half_Bi
    Bi.append(0)

A.sort()
Bi.sort()
if A != Bi:
    print(0)
    exit()

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