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:
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 and len(Count)==n//2:
        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)

Submission status: Accepted

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

mod=10**9+7

A.sort()
f=True
if N%2==1:
    if A[0]!=0:
        f=False
    else:
        for i in range(1,N,2):
            if not (A[i]==2*(i+1)//2 and A[i+1]==2*(i+1)//2):
                f=False
                break
elif N%2==0:
    for i in range(0,N,2):
        if not (A[i]==2*(i//2)+1 and  A[i+1]==2*(i//2)+1):
            f=False
            break

if f:
    print(2**(N//2)%mod)
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter

mod = int(1e9 + 7)
n = int(input())
A = list(map(int, input().split()))
c = Counter(A)

if n % 2 == 1:
    # 誰かは真ん中にいる or 0は1人のみ
    if 0 not in c or c[0] != 1:
        print(0)
        exit()

# 偶数: 5, 3, 1, 1, 3, 5 -> 1, 3, 5をカウント (n//2)
# 奇数: 4, 2, 0, 2, 4 -> 2, 4をカウント (n//2)
for i in range(n // 2):
    x = i * 2 + (1 if n % 2 == 0 else 2)
    if x not in c or c[x] != 2:
        print(0)
        exit()

# (左から右) × 2(左右対称)
print(pow(2, n // 2, mod))

Submission status: Accepted

Solution code:
from collections import Counter
lim=10**9+7
N=int(input())
A=[int(i) for i in input().split()]
if N % 2 == 0:
    if Counter(A) == {2*i+1:2 for i in range(N//2)}:
        print(pow(2,(N//2),lim))
    else:
        print(0)
else:
    if Counter(A) == {2*i if i>0 else 0:2 if i>0 else 1 for i in range((N+1)//2)}:
        print(pow(2,(N-1)//2,lim))
    else:
        print(0)

Submission status: Accepted

Solution code:
from collections import Counter
lim=10**9+7
N=int(input())
A=[int(i) for i in input().split()]
if N % 2 == 0:
    if Counter(A) == {2*i+1:2 for i in range(N//2)}:
        print(2**(N//2)%lim)
    else:
        print(0)
else:
    if Counter(A) == {2*i if i>0 else 0:2 if i>0 else 1 for i in range((N+1)//2)}:
        print(2**((N-1)//2)%lim)
    else:
        print(0)

Submission status: Accepted

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

a.sort()

if n%2==0:
    a.sort()
    for i in range(n//2):
        if a[i*2]!=a[i*2+1] or a[i*2]!=2*i+1 or a[i*2+1]!=2*i+1:
            print(0)
            exit()
    print(pow(2,n//2,10**9+7))
else:
    a.append(0)
    a.sort()
    for i in range(n//2):
        if a[i*2]!=a[i*2+1] or a[i*2]!=i*2 or a[i*2+1]!=i*2:
            print(0)
            exit()
    print(pow(2,n//2,10**9+7))

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
MOD = 10**9+7
A = list(map(int,input().split()))
c = Counter(A)
flag = True
if N%2 == 0:
    for i in range(1,int(N/2),2):
        if c[i] != 2:
            flag = False
else:
    if c[0] != 1:flag = False
    for i in range(2,int(N/2),2):
        if c[i] != 2:
            flag = False





if flag:print(2**(N//2)%MOD)
else:print(0)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
MOD = 10**9+7
CA = Counter(A)
ans = 0
if N % 2 == 0:
    if all(CA[2*i+1] == 2 for i in range(N//2)):
        ans = pow(2, N//2, MOD)
else:
    if CA[0] == 1 and all(CA[2*i+2] == 2 for i in range(N//2)):
        ans = pow(2, N//2, MOD)
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from collections import Counter
from math import factorial

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    l = [0] * n
    for i in range(n):
        l[i] = abs(n-2*i-1)
    if sorted(v) != sorted(l):
        print(0)
        return
    c = dict(Counter(l))
    ans = 1
    d = 10**9 + 7
    for v in c.values():
        ans *= factorial(v) % d
    print(ans % d)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n= input()
a=list(map(int,input().split()))
b=set()
b.update(a)
if(int(n)%2==0):
    q=len(b)
else:
    q=len(b)-1
if ( int(q)!= int(int(n)/2) or list(a).count(0) >1):
    print(0)
else:
    print(2**q%(10**9+7))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
l = [0]* n
for a_ in a:
    l[a_] += 1
mod = 10 ** 9 + 7
if n % 2 == 1:
    if l[0] == 1 and l[2::2] == [2] * (n // 2):
        print(2 ** (n // 2) % mod)
    else:
        print(0)
else:
    if l[1::2] == [2] * (n // 2):
        print(2 ** (n // 2) % mod)
    else:
        print(0)

Submission status: Accepted

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

a.sort()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    mod=10**9+7
    n=int(input())
    a = list(map(int,input().split()))
    a.sort()
    if n%2==0:
        check=[]
        for i in range(n//2):
            check.append(i*2+1)
            check.append(i*2+1)
        if a!=check:
            print(0)
            return
        ans=1
        for _ in range(n//2):
            ans=(ans*2)%mod
        print(ans)
    else:
        check=[0]
        for i in range(n//2):
            check.append((i+1)*2)
            check.append((i+1)*2)
        if a!=check:
            print(0)
            return
        ans=1
        for _ in range(n//2):
            ans=(ans*2)%mod
        print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

check = True
A = sorted(A)
if N % 2 == 0:
    for i in range(N):
        if i % 2 == 0 and A[i] != i + 1:
            check = False
        if i % 2 == 1 and A[i] != i:
            check = False

if N % 2 != 0:
    for i in range(N):
        if i % 2 == 0 and A[i] != i:
            check = False
        if i % 2 == 1 and A[i] != i + 1:
            check = False

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

Submission status: Accepted

Solution code:
def solve() -> int:
    from collections import defaultdict

    mod = 10 ** 9 + 7

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

    d = defaultdict(int)

    for a_ in a:
        d[a_] += 1
        if d[a_] > 2:
            return 0

    q, r = divmod(n, 2)
    if r == 1:
        if d[0] != 1:
            return 0
        cur = 2
        while cur < n:
            if d[cur] != 2:
                return 0
            cur += 2
        return (1 << q) % mod
    else:
        cur = 1
        while cur < n:
            if d[cur] != 2:
                return 0
            cur += 2
        return (1 << q) % mod


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

Submission status: Accepted

Solution code:
mod=10**9+7
N=int(input())
A=sorted(map(int,input().split()),reverse=True)

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

Submission status: Accepted

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

A.sort()
flag = True
for i in range(N):
  if N%2 == 0:
    if A[i] != (i//2)*2+1:
      flag = False
      break
  else:
    if A[i] != ((i+1)//2)*2:
      flag = False
      break
print(2**(N//2) % MOD if flag else 0)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
A.sort()


if N%2==1:
    if A[0]!=0:
        print(0)
        exit()
    for i in range(1,N)[::2]:
        if A[i]==-int(-i//2)*2 and A[i+1]==-int(-i//2)*2:
            pass
        else:
            print(0)
            exit()
    print(2**(N//2)%(10**9+7))
else:
    for i in range(N)[::2]:
        if A[i]==-int(-i//2)*2+1 and A[i+1]==-int(-i//2)*2+1:
            pass
        else:
            print(0)
            exit()
    print(2**(N//2)%(10**9+7))

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
    A_c = Counter(A)
    for k,v in A_c.items():
        if k == 0 and v != 1:
            return print(0)
        elif k != 0 and v != 2:
            return print(0)
    else:
        print(2 ** (N//2) % MOD)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    for i in range(N):
        if len(A)%2 == 0: # 1,1,3,3,...
            if A[i] != 1 + i//2*2:
                print(0)
                return
        else: # 0,2,2,4,4...
            if A[i] != (i+1)//2*2:
                print(0)
                return
    ans = 1
    for _ in range(N//2):
        ans *= 2
        ans %= 10**9+7
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

cntA = Counter(A)

if N % 2 == 0:
    for i in range(1, N, 2):
        if cntA[i] != 2:
            print(0)
            exit()
        cntA[i] = 0
    if max(cntA.values()) > 0:
        print(0)
        exit()
    print(pow(2, N // 2, MOD))
else:
    for i in range(2, N, 2):
        if cntA[i] != 2:
            print(0)
            exit()
        cntA[i] = 0
    if cntA[0] != 1:
        print(0)
        exit()
    cntA[0] = 0
    if max(cntA.values()) > 0:
        print(0)
        exit()
    print(pow(2, N // 2, MOD))

Submission status: Accepted

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

if all(a%2 for a in A):
    for i in range(1,N,2):
        if ctr[i] != 2:
            print(0)
            exit()
    else:
        print(pow(2,N//2,MOD))
elif all(a%2==0 for a in A):
    if ctr[0] != 1:
        print(0)
        exit()
    for i in range(2,N,2):
        if ctr[i] != 2:
            print(0)
            exit()
    else:
        print(pow(2,N//2,MOD))
else:
    print(0)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    # print(a)
    if(n % 2 == 0):
        for i in range(n-1):
            if i % 2 == 0 and a[i] != a[i+1] or i % 2 == 1 and a[i]+2 != a[i+1]:
                print(0)
                exit(0)
        print(2**(n//2) % (10**9+7))
        exit(0)
    if a[0] != 0:
        print(0)
        exit(0)
    for i in range(1, n-1):
        if i % 2 == 0 and a[i]+2 != a[i+1] or i % 2 == 1 and a[i] != a[i+1]:
            print(0)
            exit(0)
    print(2**((n-1)//2) % (10**9+7))
    exit(0)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    n = int(input())
    a = list(map(int, input().split(' ')))
    if n%2 == 1:
        a.append(0)
    a.sort()
    for i in range(n-1):
        if i%2 == 0:
            if a[i] == a[i+1]:
                continue
            else:
                print(0)
                sys.exit()
        else:
            if a[i]+2 == a[i+1]:
                continue
            else:
                print(0)
                sys.exit()
    result = 2 ** (n//2)
    print(result % (10**9+7))
if __name__ == '__main__':
    main()

Submission status: Accepted

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

a.sort()
if n%2 == 0:
    for i in range(n-1):
        if i%2 == 0:
            if a[i] == a[i+1]:
                continue
            else:
                print(0)
                sys.exit()
        else:
            if a[i]+2 == a[i+1]:
                continue
            else:
                print(0)
                sys.exit()
    result = 2 ** (n//2)
    print(result % (10**9+7))
else:
    if a[0] == 0:
        for i in range(1, n-1):
            if i%2 == 1:
                if a[i] == a[i+1]:
                    continue
                else:
                    print(0)
                    sys.exit()
            else:
                if a[i]+2 == a[i+1]:
                    continue
                else:
                    print(0)
                    sys.exit()
        result = 2**((n-1)//2)
        print(result %(10**9+7))
    else:
        print(0)
        sys.exit()

Submission status: Accepted

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

A.sort()

if(N%2==0):
    for i in range(N//2):
        if((A[i*2]!=(1+i*2))|(A[2*i+1]!=(1+i*2))):
            print(0)
            exit()
    print((2**(N//2)) % int(1e9+7))

else:
    if(A[0]!=0):
            print(0)
            exit()
    for i in range(N//2):
        if((A[i*2+1]!=((i+1)*2))|(A[i*2+2]!=((i+1)*2))):
            print(0)
            exit()
    print((2**(N//2)) % int(1e9+7))

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
start = 1 if N % 2 == 0 else 0
if N % 2 == 0:
    if counter[start] != 2:
        print(0)
        exit()
else:
    if counter[start] != 1:
        print(0)
        exit()

for i in range(start+2, N, 2):
    if counter[i] != 2:
        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 & 1:
    if A[0] == 0:
        for i in range(1, N, 2):
            if A[i] != (i+1):
                print(0)
                exit()
    else:
        print(0)
        exit()
else:
    for i in range(0, N, 2):
        if A[i] != (i+1):
            print(0)
            exit()
print(pow(2, N//2, 10**9+7))

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:
import collections

N=int(input())
A_data=list(map(int,input().split()))
mod=10**9+7

A=collections.Counter(A_data)

if N%2==1:
    if not A[0]==1:
        print(0)
        exit()
    else:
        for i in range(2,N,2):
            if not A[i]==2:
                print(0)
                exit()

elif N%2==0:
    for i in range(1,N,2):
        if not A[i]==2:
            print(0)
            exit()

print(2**(N//2)%mod)

Submission status: Accepted

Solution code:
import collections

N=int(input())
A_data=list(map(int,input().split()))
mod=10**9+7

A=collections.Counter(A_data)

f=True
if N%2==1:
    if not A[0]==1:
        ans=0
    else:
        for i in range(2,N,2):
            if not A[i]==2:
                ans=0
                f=False
                break
        if f==True:
            ans=2**((N-1)//2)%mod
elif N%2==0:
    for i in range(1,N,2):
        if not A[i]==2:
            ans=0
            f=False
            break
    if f==True:
        ans=2**(N//2)%mod

print(ans)

Submission status: Accepted

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

table = collections.defaultdict(int)

for x in A:
    table[x] += 1

for x in table:
    if x != 0 and table[x] != 2:
        print(0)
        exit(0)

    elif N % 2 == 1:
        if x == 0 and table[x] != 1:
            print(0)
            exit(0)

    else:
        if x == 0:
            print(0)
            exit(0)

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter
N = int(input())
A = [int(_) for _ in input().split()]

counter = Counter(A)

if N % 2 == 0:
    for n in range(1, N, 2):
        if counter[n] == 2:
            continue
        else:
            print(0)
            sys.exit()

elif N % 2 == 1:
    if counter[0] == 1:
        for n in range(2, N, 2):
            if counter[n] == 2:
                continue
            else:
                print(0)
                sys.exit()
    else:
        print(0)
        sys.exit()
MOD = 10 ** 9 + 7
ans = 1
for n in range(N // 2):
    ans *= 2
    ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort()
    if a[0] == 0:
        t = 2
        for i in range(2, n, 2):
            if a[i] != a[i-1] or a[i] != t:
                print(0)
                exit()
            t += 2
        print((2 ** ((len(a) - 1) // 2)) % (10 ** 9 + 7))
    else:
        t = 1
        for i in range(1, n, 2):
            if a[i] != a[i-1]:
                print(0)
                exit()
            t += 2
        print((2 ** (len(a) // 2)) % (10 ** 9 + 7))


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

f=True
if N%2!=0:
	idx=1
	x=2
	if A[0]!=0:f=False
else:
	idx=0
	x=1

for i in range(N//2):
	if A[idx]!=x or A[idx+1]!=x:
		f=False
	idx+=2
	x+=2

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

Submission status: Accepted

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

L=[0]*N
for a in A:
  L[a]+=1
#print(L)

if N%2==1:
  if L[0]==1 and L[2::2]==[2]*(N//2):
    print(2**(N//2)%(10**9+7))
  else:
    print(0)
else:
  if L[1::2]==[2]*(N//2):
    print(2**(N//2)%(10**9+7))
  else:
    print(0)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
l = list(map(int, input().split()))
l.sort()
L = np.array(l)
flag = False
if N%2==1:
    if np.all(L-np.arange(N)-np.array([0]+[1,0]*(N//2))==0):
        flag = True
    else:
        print(0)
else:
    if np.all(L-np.arange(N)-np.array([1,0]*(N//2))==0):
        flag = True
    else:
        print(0)
if flag:
    a=1
    for i in range(N//2):
        a = (a*2)%(10**9+7)
    print(a)

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(a)
for k, v in c.items():
    if (k != 0 and v != 2) or (k == 0 and (n % 2 == 0 or v != 1)):
        print(0)
        break
else: print((2 ** (n//2)) % (10**9+7))

Submission status: Accepted

Solution code:
from collections import*;n,*a=map(int,open(0).read().split());r=1
for k,v in Counter(a).items():r*=(0,1,2)[(n%2==v==k+1<2)+(0<(n+k)%2==v-1)*2]
print(r%(10**9+7))

Submission status: Accepted

Solution code:
from collections import Counter
n,*a=map(int,open(0).read().split())
r=1
for k,v in Counter(a).items():
	if (n+k)%2 and v==2:
		r*=2
	elif n%2 and k==0 and v==1:
		pass
	else:
		r=0
		break
print(r%(10**9+7))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
tru = 0
acount = Counter(a)
if n == 1:
         if acount[0] == 1 :
                  print(1)
         else:
                  print(0)
elif n % 2 == 1:
         for i in range (1,n//2+1):
                  if acount[i*2] != 2:
                           print(0)
                           exit()
         else:
                  if acount[0] != 1:
                           print(0)
                           exit()
                  else:
                           print((2 ** (n//2) ) % (10 ** 9 + 7))
else:
         for j in range(1,n//2+1):
                  if acount[j*2-1] != 2:
                           print(0)
                           exit()
         else:
                  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:
    e=n//2
    cor=[0]+[2*i for i in range(1,e+1)]*2
    cor.sort()
    if a==cor:
        ans=1
        for i in range(e):
            ans*=2
            ans%=mod
        print(ans)
    else:print(0)
else:
    e=n//2
    cor=[2*i+1 for i in range(e)]*2
    cor.sort()
    if a==cor:
        ans=1
        for i in range(e):
            ans*=2
            ans%=mod
        print(ans)
    else:print(0)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(map(int, input().split()))
INF = 10 ** 9 + 7

S = []
if N % 2 == 0:
    for i in range(N//2):
        S.extend([2*i+1] * 2)
else:
    S.append(0)
    for i in range(N//2):
        S.extend([2*i+2] * 2)

if A != S:
    print(0)
    exit()

print((2 ** (N//2)) % INF)

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort()
    cnt = 0
    if n % 2 == 0:
        m = 1
        for i in range(1, n, 2):
            if not a[i] == a[i - 1] == m:
                print(0)
                exit()
            m += 2
            cnt += 1
    else:
        m = 0
        for i in range(0, n, 2):
            if i == 0:
                if not a[i] == m:
                    print(0)
                    exit()
            else:
                if not a[i] == a[i-1] == m:
                    print(0)
                    exit()
                cnt += 1
            m += 2
    print((2 ** cnt) % (10 ** 9 + 7))


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
f = True
if N%2 == 1:
  for i in range(N):
    if A[i] != ((i+1)//2)*2:
      f = False
      break
else:
  for i in range(N):
    if A[i] != (i//2)*2 + 1:
      f = False
      break
m = N//2
if f:
  print((2**m)%1000000007)
else:
  print(0)

Submission status: Accepted

Solution code:
import collections

n = int(input())
mod = 10 ** 9 + 7
a = list(map(int, input().split()))
ac = collections.Counter(a)
if n % 2:
    for i in ac.items():
        if i[0] == 0:
            if i[1] != 1:
                print(0)
                exit()
        else:
            if i[1] != 2:
                print(0)
                exit()
    print(2 ** (n // 2) % mod)
else:
    for i in ac.values():
        if i != 2:
            print(0)
            exit()
    print(2 ** (n // 2) % mod)

Submission status: Accepted

Solution code:
import sys

MOD = 1000000007

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

if(N%2 == 0):
    a.sort()
    for i in range(N//2):
        n = 2*i + 1
        if(a[2*i] != n or a[2*i + 1] != n):
            print(0)
            sys.exit()
    print((2 ** (N//2)) % MOD)
else:
    a.sort()
    if(a.count(0) != 1):
        print(0)
        sys.exit()
    for i in range((N-1)//2):
        n = 2*i + 2
        if(a[2*i + 1] != n or a[2*i + 2] != n):
            print(0)
            sys.exit()
    print((2 ** ((N-1)//2)) % MOD)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a = sorted(list(map(int, input().split())), reverse=True)
    MOD = int(1e9) + 7
    ok = True
    ans = 1
    for i in range(N):
        # print(a[i], N - 1 - i//2)
        if a[i] != N - 1 - 2 * (i//2):
            ok = False
            break
        elif i&1 == 1:
            ans *= 2
            ans %= MOD
    if not ok:
        print(0)
    else:
        print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
MOD = int(1e9+7)
N = int(input())
A = list(map(int, input().split()))
if N % 2 == 0:
    B = [0] * N
    for i in range(N // 2):
        B[2*i] = 2*i+1
        B[2*i+1] = 2*i+1
    if sorted(A) != B:
        print(0)
    else:
        ans = 1
        for i in range(N // 2):
            ans = ans * 2 % MOD
        print(ans)
else:
    B = [0] * N
    for i in range((N-1) // 2):
        B[2 * i + 1] = 2 * i + 2
        B[2 * i + 2] = 2 * i + 2
    if sorted(A) != B:
        print(0)
    else:
        ans = 1
        for i in range((N-1) // 2):
            ans = ans * 2 % MOD
        print(ans)

Submission status: Accepted

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

if N%2 == 1:
    for i in range(N):
        if A[i] == ((i+1)//2) * 2:
            pass
        else:
            check = 1
else:
    for i in range(N):
        if A[i] == (i//2) * 2 + 1:
            pass
        else:
            check = 1

if check == 0:
    ans = 1
    for i in range(N//2):
        ans *= 2
        ans %= 1000000007
else:
    ans = 0

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def is_valid(A):
    counts = {}
    for a in A:
        if a in counts:
            counts[a] += 1
        else:
            counts[a] = 1
    if len(A) % 2 == 1:
        if counts[0] != 1:
            return False
        
        for i in range(1, len(A) // 2 + 1):
            if 2 * i not in counts or counts[2 * i] != 2:
                return False
        return True
    else:
        for i in range(1, len(A) // 2 + 1):
            if 2 * i - 1 not in counts or counts[2 * i - 1] != 2:
                return False
        return True
    return True
        
if is_valid(A):
    print(2 ** (N // 2) % 1000000007)
else:
    print(0)

Submission status: Accepted

Solution code:
# 2019/08/11

from collections import Counter

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

c=Counter(a)

if c.most_common(1)[0][1]>2 or c[0]>1:
    print(0)
    exit()

for k,v in c.items():
    if k!=0 and v!=2:
        print(0)
        exit()
    if n%2==k%2:
        print(0)
        exit()
        
print(2**(n//2)%(10**9+7))

Submission status: Accepted

Solution code:
import collections
import math

mod = int(1e9 + 7)
n = int(input())
a = list(map(int,input().split()))

c = collections.Counter(a)
if n%2 == 0:
    check = True
    for i in range(n//2):
        if c[1+2*i] != 2:
            check = False
    if check:
        print(pow(2,n//2,mod))
    else:
        print(0)
else:
    if c[0] == 1:
        check = True
    else:
        check = False
    for i in range(1,n//2+1):
        if c[2*i] != 2:
            check = False
    if check:
        print(pow(2,n//2,mod))
    else:
        print(0)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
k = [0] * N
j = (N-1) % 2
for a in A:
    if a % 2 != j:
        print(0)
        break
    elif a == 0 and k[0] == 1:
        print(0)
        break
    elif k[a] == 2:
        print(0)
        break
    else:
        k[a] += 1
else:
    ans = 1
    i = 0
    while(i<(N-1)//2+j):
        ans *= 2
        ans %= 10**9+7
        i += 1
    print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#ARC66C
import sys

n=int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

a=[]
for i in range(0,(n+1)//2):
	a.append(0)
for i in range(0,n):
	a[hoge[i]//2]+=1

if(a[0]%2!=n%2):
	print(0)
else:
	for i in range(1,(n+1)//2):
		if(a[i]!=2):
			print(0)
			sys.exit()
	print((max(a[0],1)*pow(2,(n-1)//2))%1000000007)