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:
mod = int(1e9) + 7
n = int(input())
a = list(map(int, input().split()))
lis = [0] * n
for i in a:
    lis[i] += 1
for i in range(1,n):
    if lis[i] % 2 == 1:
        print(0)
        exit()

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

Submission status: Accepted

Solution code:
import math
n=input()
mod = int(1e9) + 7
a=list(map(int,raw_input().split()))
if(len(a)%2==0 and a.count(0)>0):
    print(0)
elif(len(a)%2!=0 and a.count(0)>1):
    print(0)
else:    
    l=[0]*n
    b=set(a)
    for i in a:
        l[i] +=1
    for i in range(1,len(a)):
        if(l[i]%2==1):
            print(0)
            exit()
    if(a.count(0)):
        print(pow(2,len(b)-1,mod))
    else:
        print(pow(2,len(b),mod))

Submission status: Accepted

Solution code:
def modpow(val, n, mod):
    ret = 1
    while n:
        if n & 1:
            ret = (ret * val) % mod
        val = (val * val) % mod
        n = n >> 1
    return ret

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

a_list.sort()

if n % 2 != 0:
    if a_list[0] != 0:
        print(0)
        exit()
    else:
        a_list = a_list[1:]

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

print(modpow(2, len(a_list) // 2, (10 ** 9) + 7))

Submission status: Accepted

Solution code:
from collections import Counter
MOD = 10**9 + 7
N = int(input())
A = list(map(int,input().split()))
C = Counter(A)
ans = 1
if N%2 == 1:
    if C[0] != 1:
        print(0)
        exit(0)
    else:
        for e in C:
            if e == 0:
                pass
            elif C[e] != 2:
                print(0)
                exit(0)
            else:
                ans *= 2
                ans %= MOD
else:
    for e in C:
        if C[e] != 2:
            print(0)
            exit(0)
        else:
            ans *= 2
            ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

from collections import Counter
ca = Counter(a)
d = n % 2
if d == 1:
    z = ca.pop(0) if 0 in ca else 0
    if z != 1:
        print(0)
        exit()

for i in range(1 + d, n + d, 2):
    if ca[i] != 2:
        print(0)
        exit()

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

Submission status: Accepted

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())

mod = 10**9+7

A = sorted(A)
is_possible = True
if N%2 == 0:
    for i in range(N/2):
        if A[2*i] != 2*i+1 or A[2*i+1] != 2*i+1:
            is_possible = False
else:
    for i in range(1, (N+1)/2):
        if A[2*i-1] != 2*i or A[2*i] != 2*i:
            is_possible = False

if is_possible:
    ans = 1
    for i in range(N/2):
        ans = ans*2%mod
    print ans
else:
    print 0

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
Alist = list(map(int, input().split()))
Ac = Counter(Alist)
mod = 10**9+7
if N%2==0:
    for i in range(1, N, 2):
        if Ac[i] != 2:
            print(0)
            break
    else:
        print(pow(2, (N//2), mod))
else:
    if Ac[0] != 1:
        print(0)
    else:
        for i in range(2, N, 2):
            if Ac[i] != 2:
                print(0)
                break
        else:
            print(pow(2, (N//2), mod))

Submission status: Accepted

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

x = n%2 + 1
for i in range(n)[n%2+2::2]:
    if a[i] != a[i+1] or a[i] - x != 2:
        print(0)
        exit()
    x = a[i]
    
print(2**(n//2) % (10**9+7))

Submission status: Accepted

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

if n%2:
    a = a[1:]

x = n%2 + 1
for i in range(len(a))[::2]:
    if a[i] != x:
        print(0)
        exit()
    x += 2

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
mod = pow(10,9)+7
B = [0]*N
for a in A:B[a]+=1
if max(B)>2:print(0)
elif N%2 and B[0]>1:print(0)
else:print(pow(2,N//2,mod))

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
AC = Counter(list(map(int, input().split())))
if N % 2 == 1:
    if N == 1:
        ans = AC[0] == 1
    else:
        ans = AC[0] == 1
        for k, v in AC.most_common(N//2):
            if k > N-1 or k % 2 != 0 or v != 2:
                ans = False
                break
else:
    ans = True
    for k, v in AC.most_common():
        if k > N or k % 2 == 0 or v != 2:
            ans = False
            break
if ans:
    print(pow(2, N//2, 10**9+7))
else:
    print(0)

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    A = LI()
    S = defaultdict(int)
    for a in A:
        S[a]+=1
        if S[a]>=3:
            print(0)
            return
    if S[0]>=2:
        print(0)
        return 
    print(pow(2,N//2,mod))

    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
if n % 2 == 1 and a[0] != 0:
    print(0)
    exit()
for i in range(n % 2, n, 2):
    if a[i] != a[i + 1] or a[i] != i + 1:
        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

if n%2 == 1:
    m = (n+1)//2
    l =[0]*m
    for i in range(n):
        if (n-A[i]-1)%2 != 0:
            print(0)
            exit()
        else:
            id = (n-A[i]-1)//2
            l[id] += 1
    #print(l)
    ans = 1
    for i in range(m):
        #print(i, ans)
        if i != m -1:
            if l[i] != 2:
                print(0)
                exit()
            else:
                ans *= l[i]
                ans %= mod
        else:
            if l[i] != 1:
                print(0)
                exit()
            else:
                ans *= l[i]
                ans %= mod
    print(ans)

else:
    m = n//2
    l =[0]*m
    for i in range(n):
        if (n-A[i]-1)%2 != 0:
            print(0)
            exit()
        else:
            id = (n-A[i]-1)//2
            l[id] += 1
    #print(l)
    ans = 1
    for i in range(m):
        #print(i, ans)
        if l[i] != 2:
            print(0)
            exit()
        else:
            ans *= l[i]
            ans %= mod
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
num = [0] * N
ng = False
for i in range(N):
    num[A[i]] += 1
for i in range(1, N):
    if N % 2:
        if i % 2 and num[i]:
            ng = True
        elif i % 2 == 0 and num[i] != 2:
            ng = True
    else:
        if i % 2 == 0 and num[i]:
            ng = True
        elif i % 2 and num[i] != 2:
            ng = True
if N % 2 and A.count(0) != 1:
    ng = True
if N % 2 == 0 and A.count(0) > 0:
    ng = True
ans = pow(2, N // 2, 1000000007)
if ng:
    ans = 0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

MOD = 10**9+7

from collections import Counter
 
for key,count in sorted(Counter(A).items(), key=lambda x:x[0]):
    if key == 0 and N % 2 == 1:
        continue
    if count == 2 and key % 2 != N % 2:
        continue
    print(0)
    exit()
 
# 0は1つだけだから
if N % 2 == 1:
    N -= 1
 
print(2 ** (N//2) % MOD)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
if n % 2 == 1:
    if a[0] != 0:
        print(0)
        exit()
    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] != i + 1:
            print(0)
            exit()
print(2 ** (n // 2) % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
def main():
    N=int(input())
    A=list(map(int,input().split()))
    t={}
    flag=True
    for i in range(N):
        if str(A[i]) not in t:
            t[str(A[i])]=1
        elif t[str(A[i])]==1:
            t[str(A[i])]=2
        elif t[str(A[i])]==2:
            flag=False
            break
    if flag==False:
        print(0)
    if flag and N%2==1:
        if t["0"]!=1:
            print(0)
            flag=False
        if flag:
            count_zero=0
            for v in t.values():
                if v==1:
                    count_zero+=1
                    if count_zero>=2:
                        print(0)
                        flag=False
                        break
        if flag:
            print((2**(N//2))%1000000007)

    elif flag and N%2==0:
        for v in t.values():
            if v==1:
                print(0)
                flag=False
                break
        if flag:
            print((2**(N//2))%1000000007)
    
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
import collections
d=collections.defaultdict(int)
for i in a:
    d[i]+=1
mod=(10**9)+7

if n%2==0:
    x=[i for i in d.keys()]
    x=sorted(x)
    for i in range(len(x)):
        if i==0 and (x[i]!=1 or d[x[i]]!=2):
            print(0)
            exit()
        elif i>=1:
            if x[i]-x[i-1]!=2 or d[x[i]]!=2:
                print(0)
                exit()
    print((2**len(x))%mod)
else:
    x=[i for i in d.keys()]
    x=sorted(x)
    if x[0]!=0 or d[x[0]]!=1:
        print(0)
        exit()
    x=x[1:]
    for i in range(len(x)):
        if i==0 and (x[i]!=2 or d[x[i]]!=2):
            print(0)
            exit()
        elif i>=1:
            if x[i]-x[i-1]!=2 or d[x[i]]!=2:
                print(0)
                exit()
    print((2**len(x))%mod)

Submission status: Accepted

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

x = N // 2
ans = pow(2, x, mod)

c = Counter(A)
if N & 1:
    for i in range(0, N, 2):
        if i == 0 and c[i] == 1:
            continue
        if c[i] == 2:
            continue
        ans = 0
else:
    for i in range(1, N, 2):
        if c[i] == 2:
            continue
        ans = 0

print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    MOD = 10**9 + 7
    from collections import Counter
    c = Counter(A)
    # print(c)
    for k, v in c.items():
        if k != 0 and v != 2:
            return print(0)
    if N & 1 and c[0] != 1:
        return print(0)

    if N & 1:
        ma = max(A)//2
    else:
        ma = (max(A) + 1)//2
    print(pow(2, ma, MOD))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]

mod = 10**9+7
A.sort()
if N%2 == 1:
    if A[0] == 0:
        ans = 1
        i = 1
        while i < N-1:
            if A[i] == A[i+1] and A[i] == i+1:
                ans *= 2
                ans %= mod
                i += 2
            else:
                ans = 0
                break
    else:
        ans = 0
else:
    ans = 1
    i = 0
    while i < N:
        if A[i] == A[i+1] and A[i] == i+1:
            ans *= 2
            ans %= mod
            i += 2
        else:
            ans = 0
            break
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr0=limii()

arr=Counter(arr0)

ai=list(arr.items())
ai.sort()
if n%2==0:
    cnt=0
    for p,i in enumerate(range(1,n,2)):

        if ai[p][0]==i and ai[p][1]==2:
            cnt+=1
    if cnt==n//2:
        print((2**(n//2))%mod)
    else:
        print(0)
else:
    cnt=0
    for p,i in enumerate(range(0,n,2)):
        if p==0:
            if ai[p][0]==i and ai[p][1]==1:
                cnt+=1
        else:        
            if ai[p][0]==i and ai[p][1]==2:
                cnt+=1
    if (n+1)//2==cnt:
        print((2**(cnt-1))%mod)
    else:
        print(0)

Submission status: Accepted

Solution code:
# coding: utf-8
from math import ceil
N = int(input())
mod = 10**9 + 7
A = list(map(int, input().split()))
A.sort()
flag = True
if len(set(A)) != ceil(N / 2):
    flag = False
if N % 2 == 1:
    if A[0] != 0:
        flag = False
    else:
        for i in range(1, N, 2):
            if A[i] != A[i+1] or A[i] % 2 == 1:
                flag = False
else:
    for i in range(N, 2):
        if A[i] != A[i+1] or A[i] % 2 == 0:
            flag = False
ans = 1
if flag:
    for i in range(N//2):
        ans *= 2
        ans %= mod
else:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
A.sort()
mod = 7 + 10 ** 9
count = 1
if N % 2 == 0:
    for i, a in enumerate(A):
        if a != 2 * (i // 2) + 1: 
            count = 0
            break
        if i % 2 == 1:
            count *= 2
            count %= mod
else:
    for i, a in enumerate(A):
        if a != 2 * ((i + 1) // 2):
            count = 0
            break
        if i % 2 == 1:
            count *= 2
            count %= mod
print(count)

Submission status: Accepted

Solution code:
N = int(input())

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

data = [0] * N
possible = True
MOD = 10**9+7

for a in A:
	data[a] += 1

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

if possible:
	if N % 2 == 0:
		num = N // 2
	else:
		num = (N-1)//2
	ans = 1
	for i in range(num):
		ans = ans * 2 % MOD
		ans %= MOD

	print(ans)
else:
	print(0)

Submission status: Accepted

Solution code:
import collections


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


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

c = collections.Counter(A)

if n % 2 == 0:
    for i in range(1, n, 2):
        if c[i] != 2:
            print(0)
            break
    else:
        calc_ans(n)
else:
    for i in range(0, n, 2):
        if (i == 0 and c[i] != 1) or (i != 0 and c[i] != 2):
            print(0)
            break
    else:
        calc_ans(n)

Submission status: Accepted

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

if n%2==1:
    sentou = a.pop(0)
    if sentou!=0:
        print("0")
        exit()
    nxt=2
else:
    nxt=1

ans=1
i=0
while i < len(a):
    if a[i] == nxt and a[i+1] == nxt:
        ans*=2
        ans%=10**9+7
        nxt+=2
        i+=2
    else:
        print("0")
        exit()
print(ans)

Submission status: Accepted

Solution code:
import sys
from numpy import *
n, *a = map(int, sys.stdin.read().split())
a = int_(bincount(a, [1] * n, n))
print(pow(2, n // 2, 10 ** 9 + 7) if not a[0] > (n & 1) and all([x == 2 or x == 0 for x in a[1:]]) else 0)

Submission status: Accepted

Solution code:
import sys

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

mod = 10 ** 9 + 7

count = [0] * N
for i in a:
    count[i] += 1
count[0] += 1
for i in count[1-N%2::2]:
    if i != 2:
        print(0)
        sys.exit()
s = N // 2
print(pow(2, s, mod))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys


N, *A = map(int, open(0).read().split())
MOD = 10 ** 9 + 7

A.sort()

ret = 1
if N % 2 == 0:
  for i, (a1, a2) in enumerate(zip(*[iter(A)]*2)):
    i = 2*i + 1
    if i == a1 and i == a2:
      ret *= 2
      ret %= MOD
    else:
      print(0)
      sys.exit()
else:
  if A[0] != 0:
    print(0)
    sys.exit()
  else:
      for i, (a1, a2) in enumerate(zip(*[iter(A[1:])]*2), 1):
        i *= 2
        if i == a1 and i == a2:
          ret *= 2
          ret %= MOD
        else:
          print(0)
          sys.exit()
          
print(ret)

Submission status: Accepted

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

ans = 1
A.sort()
if N % 2 == 1 and not A.count(0) == 1:
    ans = 0

s = -1
if N % 2 == 1:
    A.remove(0)
    s = 2
else:
    s = 1

for i in range(0, len(A), 2):
    if A[i] == A[i + 1] == s:
        ans *= 2
    else:
        ans = 0
    s += 2
    
print(ans % 1000000007)

Submission status: Accepted

Solution code:
n = int(input())

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

dic1 = dict()
oe = 1
if n%2 == 1:
    oe = 0
for i in range(oe,n,2):
    dic1[i] = 0

for i in lst1:
    if i in dic1:
        dic1[i] += 1
    else:
        print(0)
        exit()

if oe == 0:
    if dic1[0] != 1:
        print(0)
        exit()

ans = 1
for i in dic1.values():
    if i == 2:
        ans*=2
    elif i == 0 or i > 2:
        ans = 0
        break
print(ans%(10**9+7))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7

def main():
    N = cin.int()
    A = cin.mapInt()
    A.sort()
    ans = 1
    for i in range(N % 2,N,2):
        if A[i] == A[i + 1] and A[i] == i + 1:
            ans *= 2
            ans %= MOD
        else:
            ans = 0
    print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7

def main():
    N = cin.int()
    A = cin.mapInt()
    A.sort()
    ans = 1
    if N % 2 == 0:
        for i in range(0,N,2):
            if A[i] == A[i + 1] and A[i] == i + 1:
                ans *= 2
                ans %= MOD
            else:
                ans = 0
    else:
        if A[0] != 0:
            ans = 0
        for i in range(1,N,2):
            if A[i] == A[i + 1] and A[i] == i + 1:
                ans *= 2
                ans %=MOD
            else:
                ans = 0
    print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

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

if N % 2 == 1:
  B = [0] * N
  for i in range(1,N):
    b = math.ceil(i / 2) * 2
    B[i] = b
else:
  B = [0] * N
  for i in range(N):
    b = math.floor(i / 2) * 2 + 1
    B[i] = b

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
import sys

n = int(input())
C = Counter(list(map(int, input().split())))

if n % 2 == 0:
    for key in C.keys():
        if C[key] != 2:
            print(0)
            sys.exit()
    print(pow(2,n//2,10**9+7))
else:
    for key in C.keys():
        if key == 0:
            if C[key] != 1:
                print(0)
                sys.exit()
        else:
            if C[key] != 2:
                print(0)
                sys.exit()
    print(pow(2,n//2,10**9+7))

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
A=[int(a) for a in input().split()]
MOD=10**9+7

C=Counter(A)
i=1+(N&1)
while i<=N-1:
    if C[i]!=2:
        print(0)
        exit()
    i+=2

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

Submission status: Accepted

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

if N % 2 == 0:
    A_list = []
    for i in range(1, N, 2):
        A_list.extend([i, i])
else:
    A_list = [0]
    for i in range(2, N, 2):
        A_list.extend([i, i])
if A != A_list:
    print(0)
else:
    print(2**(N//2) % (10**9+7))

Submission status: Accepted

Solution code:
N, *A = map(int, open(0).read().split())
A = sorted(A)
MOD = 1000000007
if N & 1 != 0:
  K = 2
  F = True
  for i in range(1, N, 2):
    if A[i] != A[i+1] or A[i] != K:
      F = False
      break
    K += 2
  if A[0] != 0:
    F = False
  print(2 ** (N // 2) % MOD if F else 0)
else:
  K = 1
  F = True
  for i in range(0, N, 2):
    if A[i] != A[i+1] or A[i] != K:
      F = False
      break
    K += 2
  print(2 ** (N // 2) % MOD if F else 0)

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    a.sort()
    t = 0
    if n % 2 == 0:
        t = 1
    for i in range(n):
        if i % 2 == n % 2 and i != 0:
            t += 2
        if a[i] != t:
            print(0)
            exit()
    print((2 ** (n // 2)) % mod)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from collections import Counter
MOD = 10**9+7
N = int(input())
A = [int(i) for i in input().split()]
f0 = False
b = N & 1 ^ 1
c = Counter(A)
ans = 1
for n in range(N-1, 0, -2):
    if c[n] != 2:
        break
    ans *= 2
    ans %= MOD
else:
    if c[0] == N & 1:
        print(ans)
        exit()
print(0)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
dd = collections.defaultdict(int)
correct = []
if n % 2 == 1:
    correct.append(0)
    for i in range((n - 1) // 2):
        correct.append(2 * i + 2)
        correct.append(2 * i + 2)
else:
    correct.append(1)
    correct.append(1)
    for i in range(n // 2):
        correct.append(2 * i + 3)
        correct.append(2 * i + 3)
a.sort()
correct.sort()
for i in range(n):
    if a[i] != correct[i]:
        print(0)
        exit()
for i in range(n):
    dd[str(a[i])] += 1
ans = 1
for k in dd.keys():
    if dd[k] >= 2:
        ans *= 2
        ans %= 10 ** 9 + 7
print(ans)

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    cnt = [0] * N
    for A in map(int, input().split()):
        if A < N and (N + A) % 2 == 1 and (A > 0 and cnt[A] < 2 or A == 0 and cnt[A] < 1):
            cnt[A] += 1
        else:
            return 0
    return pow(2, N // 2, 10**9 + 7)
print(solve())

Submission status: Accepted

Solution code:
from collections import Counter
mod = 10 ** 9 + 7
n = int(input())
l = [int(i) for i in input().split()]
c = Counter(l)

if c.most_common()[0][1] > 2:
    print(0)
elif c.most_common()[-1][1] == 1 and c[0] != 1:
    print(0)
elif n % 2 == 1 and c[0] != 1:
    print(0)
else:
    print(2 ** (len(c)-1) % mod if n % 2 == 1 else 2 ** len(c) % mod)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
mod=10**9+7
n=int(input())
A=list(map(int,input().split()))
Count=sorted(Counter(A).items())
cnt=0
if n%2==1:
    if Count.pop(0)[1]==1:
        point=2
        for v,m in Count:
            if v==point and m==2:
                cnt +=1
                point +=2
        print((2**cnt)%mod)
    else:print(0);exit()
else:
    point=1
    for v,m in Count:
        if v==point and m==2:
            cnt +=1
            point +=2
        else:print(0);exit()
    print((2**cnt)%mod)