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

from collections import Counter
cnt = Counter(a)
ans = 0
for i in range(n - 1, -1, -2):
    if cnt[i] == 2:
        ans += 1
        continue
    if i == 0 and cnt[i] == 1:
        break
    else:
        print(0)
        exit()
M = 10 ** 9 + 7
print((2 ** ans)%M)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    A = list(map(int, rl().split()))
    MOD = 10 ** 9 + 7
    
    counter = Counter(A)
    if N % 2 == 0:
        for n in range(1, N, 2):
            if counter[n] != 2:
                print(0)
                return
    else:
        if counter[0] != 1:
            print(0)
            return
        for n in range(2, N, 2):
            if counter[n] != 2:
                print(0)
                return
    print(pow(2, N // 2, MOD))


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

import collections
c = collections.Counter(a)
m=0
for i in range(n//2):
    if n//2==n/2:
        if c[n-1-2*i]!=2:
            m=1
    else:
        if (i!=n//2-1 and c[n-1-2*i]!=2):
            m=1
        if (i==n//2 and c[n-1-2*i]!=1):
            m=1
if m==0:
    print(2**(n//2)%(10**9+7))
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import copy
from collections import deque
stdin = sys.stdin

mod = 10**9+7

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

n = ni()
a_list = na()

c = {abs((n-1-i)-i): 0 for i in range(n//2 + 1)}

for a in a_list:
    if a not in c or c[a]==2:
        print(0)
        exit(0)
    c[a] += 1

cnt = 1
for k,v in c.items():
    if v==2 or k==0:
        cnt *= v
        cnt %= mod
    else:
        print(0)
        exit(0)

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

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


# ===CODE===


def main():
    n = ni()
    a = na()

    c = collections.Counter(a)

    ans = True
    odd = n % 2

    if odd:
        if 0 in c.keys():
            c[0] += n % 2
    for i in range(0 + odd ^ 1, n, 2):
        if i not in c.keys():
            ans = False
            break
        if c[i] != 2:
            ans = False
            break

    if ans:
        print(2 ** (n // 2) % MOD)
    else:
        print(0)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
b=[0]*-~n
for i in a:
  b[i]+=1
print(0 if b[0]!=n%2 or max(b)>2 or 1 in b[1:] else pow(2,b.count(2),10**9+7))

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
b=[0]*-~n
for i in a:
  b[i]+=1
print(0 if b[0]!=n%2 or max(b)>2 or 1 in b[1:] else pow(2,b.count(2))%(10**9+7))

Submission status: Accepted

Solution code:
import sys
from collections import Counter

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

if len(arr) % 2 == 0:
    if 0 in arr:
        print(0)
        sys.exit()
else:
    if arr.count(0) != 1:
        print(0)
        sys.exit()
    else:
        arr.remove(0)

cnt = Counter(arr)

values = list(cnt.values())

if values.count(2) != len(values):
    print(0)
    sys.exit()

mod = 10**9 + 7

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

Submission status: Accepted

Solution code:
from collections import*
n, *a = map(int, open(0).read().split())
c = Counter(a)
MOD = 10**9+7
if n%2:
    if c.get(0, 0) != 1 or any(c.get(i, 0) != 2 for i in range(2, n, 2)):
        exit(print(0))
    print(2 ** (n // 2) % MOD)
else:
    if any(c.get(i, 0) != 2 for i in range(1, n, 2)):
        exit(print(0))
    print(2 ** (n // 2) % MOD)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
mod = 10**9+7
L = list(map(int,input().split()))
from collections import Counter
L = Counter(L)
#print(L)
cnt_2 = 0
cnt_0 = 0
else1 = 0
for k,v in L.items():
    if v == 2:
        cnt_2 +=1
    elif k == 0 :
        cnt_0 +=v
    else:
        else1 +=1
#print(cnt_2,cnt_0)
if else1 != 0:
    print(0)
elif n%2 == 1 and cnt_0 == 1:
    print(2**cnt_2%mod)
elif n%2 == 1 and cnt_0 != 1:
    print(0)
elif n%2 == 0 and cnt_0 != 0:
    print(0)
elif n%2 == 0 and cnt_0 == 0:
    print(2**cnt_2%mod)

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
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 and v != 1:
        print(0)
        exit()
    if k != 0 and v != 2:
        print(0)
        exit()
    ans *= v
print(ans % MOD)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 1
if n % 2:
    # 0.2,2,,4,4,6,6..
    if a[0] == 0:
        for i in range(n // 2):
            if a[i * 2 + 1] == a[i * 2 + 1] and a[i * 2 + 1] == i * 2 + 2:
                pass
            else:
                ans = 0
                break
    else:
        ans = 0
else:
    for i in range(n // 2):
        if a[i * 2 + 1] == a[i * 2] and a[i * 2 + 1] == i * 2 + 1:
            pass
        else:
            ans = 0
            break
if ans == 0:
    print(ans)
else:
    print(pow(2, n // 2, 10 ** 9 + 7))

Submission status: Accepted

Solution code:
import collections

MOD = pow(10, 9)+7

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
from collections import deque

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

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

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

print(power(2,ans,mod))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict

mod = 10**9 + 7

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

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

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

print(ans % mod)

Submission status: Accepted

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

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


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

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

main()

Submission status: Accepted

Solution code:
from collections import Counter


P = 10 ** 9 + 7

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

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

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:
        if N % 2 == 0:
            if v != 0:
                print(0)
                exit()
        else:
            if v != 1:
                print(0)
                exit()
    else:
        if v!= 2:
            print(0)
            exit()
import math
print(pow(2, math.floor(N/2), 10**9 + 7))

Submission status: Accepted

Solution code:
import sys
from collections import Counter


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


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

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

MOD = 10**9+7

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

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

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## const ##
MOD=10**9+7
## libs ##
import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def main():
    n = II()
    aa = MII()
    aa.sort()
    bb = []
    for i in range(n%2+1,n,2):
        bb += [i, i]
    if n%2==1:
        bb = [0] + bb
    if aa != bb:
        print(0)
        return None
    print((2**(n//2))%MOD)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## libs ##
import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def main():
    n = II()
    aa = MII()
    aa.sort()
    DIV = 10**9+7
    if n%2==1:
        bb = [0]
        for i in range(2,n,2):
            bb.append(i)
            bb.append(i)
    else:
        bb = []
        for i in range(1,n,2):
            bb.append(i)
            bb.append(i)
    if aa != bb:
        print(0)
        return None

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from collections import Counter

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

sys.setrecursionlimit(10 ** 7)

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

from collections import Counter

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


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

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

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

Submission status: Accepted

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

m=10**9+7

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

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

print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/arc066/tasks/arc066_a/

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

c = collections.Counter(li)
#print(c)
# Counter({'a': 4, 'c': 2, 'b': 1})
#print(c.items())
# dict_items([('a', 4), ('b', 1), ('c', 2)])
count_list = list(c.items())
count_list.sort()
keys = set(c.keys())
#print(keys,{i for i in range(n) if i%2 == 1})
#print(count_list)
flag = True
if n%2 == 1:
    if keys != {i for i in range(n) if i%2 == 0}:
        print(0)
        exit()
    for i,c in enumerate(count_list):
        #print(c[0],c[1])
        if c[0] == 0:
            if c[1]!=1:
                flag = False
        else:
            if c[1]!=2:
                flag = False
else:
    if keys != {i for i in range(n) if i%2 == 1}:
        print(0)
        exit()
    for i in count_list:
        if i[1] != 2:
            flag = False
if not flag:
    print(0)
    exit()

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

Submission status: Accepted

Solution code:
n=int(input())

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

a.sort()

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

Submission status: Accepted

Solution code:
from collections import Counter

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

Submission status: Accepted

Solution code:
from collections import Counter

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

Submission status: Accepted

Solution code:
from collections import Counter

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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