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()))
MOD=10**9+7
x=dict()
y=dict()
flag=True

if N%2==0:
    for i in range(1,N,2):
        x[i]=0
    for i in range(N):
        if A[i] in x:
            x[A[i]]+=1
        else:
            y[A[i]]=1
    for idx in x:
        if idx==0:
            if x[idx]<1:
                flag=False
            continue
        if x[idx]!=2:
            flag=False
    ans=1
    if flag:
        for idx in x:
            ans=ans*x[idx]
    else:
        print(0)
        exit()
    ans=ans%MOD
    print(ans)

else:
    for i in range(0,N,2):
        x[i]=0
    for i in range(N):
        if A[i] in x:
            x[A[i]]+=1
        else:
            y[A[i]]=1
    for idx in x:
        if idx ==0:
            if x[idx]<1:
                flag=False
            continue
        if x[idx]!=2:
            flag=False
    ans=1
    if flag:
        for idx in x:
            ans=ans*x[idx]
    else:
        print(0)
        exit()
    ans=ans%MOD
    print(ans)

Submission status: Accepted

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

def check(n, a):
    for i in range(n):
        if not a[i*2]==a[i*2+1]:
            return print(0)
    return print((2**n)%(10**9+7))

if len(set(a))==(n+1)//2:
    a = sorted(a)
    if n % 2:
        del a[0]
        check(int((n-1)/2), a)
    else:
        check(int(n/2), a)
else:
    print(0)

Submission status: Accepted

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

a.sort(reverse = True)
# aがあるべきパターンになってるかチェック
if n % 2 == 1:
  del(a[-1])
r = 1
turn = 0
start = n - 1
check = True

for i in range(0, len(a)):
  turn += 1  
  if a[i] != start:
    r = 0
  if turn > 1:    
    turn = 0
    start -= 2

if not r:
  print(0)
else:
  # aがあるべきパターンならありうる組み合わせの数を計算
  r = 2**(n//2) % (10**9 + 7)
  print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
if N%2==1:
    collect=list(range(0,N))[::2]*2
    collect.remove(0)
elif N % 2 == 0:
    collect = list(range(1, N))[::2] * 2

collect.sort()
if collect!=A:
    print(0)
else:
    print(2**(N//2)%(10**9+7))

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
n = N-1
for i in range(N//2):
  if A[2*i]!=n or A[2*i+1]!=n:
    print(0)
    exit()
  n -= 2
  
if N&1 and A[-1]!=0:
  print(0)
  exit()

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

Submission status: Accepted

Solution code:
import collections

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

b = collections.Counter(a)
c = b.most_common()
c.sort(key=lambda x: x[0])
cnt = 1
if n % 2 == 1:
    cnt = 0

for i, j in c:
    # print(i, j)
    if cnt == 0:
        if j != 1:
            print(0)
            exit()
        else:
            cnt += 2
    else:
        if i != cnt or j != 2:
            print(0)
            exit()
        else:
            cnt += 2

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
n=int(input())
l=list(input().split())
c=collections.Counter(l)
if n%2==0:
  f=all(x==2 for x in c.values())
else:
  g=c.pop("0")==1
  f=all(x==2 for x in c.values()) and g
print(2**(n//2)%1000000007 if f==True else 0)

Submission status: Accepted

Solution code:
MOD=10**9+7
class Fp(int):
    def __new__(self,x=0):return super().__new__(self,x%MOD)
    def inv(self):return self.__class__(super().__pow__(MOD-2,MOD))
    def __add__(self,value):return self.__class__(super().__add__(value))
    def __sub__(self,value):return self.__class__(super().__sub__(value))
    def __mul__(self,value):return self.__class__(super().__mul__(value))
    def __floordiv__(self,value):return self.__class__(self*self.__class__(value).inv())
    def __pow__(self,value):return self.__class__(super().__pow__(value%(MOD-1), MOD))
    __radd__=__add__
    __rmul__=__mul__
    def __rsub__(self,value):return self.__class__(-super().__sub__(value))
    def __rfloordiv__(self,value):return self.__class__(self.inv()*value)
    def __iadd__(self,value):self=self+value;return self
    def __isub__(self,value):self=self-value;return self
    def __imul__(self,value):self=self*value;return self
    def __ifloordiv__(self,value):self=self//value;return self
    def __ipow__(self,value):self=self**value;return self
    def __neg__(self):return self.__class__(super().__neg__())


N = int(input())
A = sorted(map(int, input().split()))
ans = Fp(1)
if N & 1:
    if all(a == (i + 1) // 2 * 2 for i, a in enumerate(A)):
        for i in range(N//2):
            ans *= 2
    else:
        ans = 0
else:
    if all(a == i // 2 * 2 + 1 for i, a in enumerate(A)):
        for i in range(N//2):
            ans *= 2
    else:
        ans = 0
print(ans)

Submission status: Accepted

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

if N % 2 == 1:
  cnt = set()
  for (key, value) in Counter(A).items():
    if key == 0:
      if value != 1:
        print(0)
        exit()

    else:

      if key % 2 != 0 or value != 2:
        print(0)
        exit()

      cnt.add(key)

else:
  cnt = set()
  for (key, value) in Counter(A).items():
    if key % 2 != 1 or value != 2:
      print(0)
      exit()

    cnt.add(key)

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

print(2 ** len(cnt) % mod)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from math import ceil

def solve(n, A):
    p = 10 ** 9 + 7
    nums = {n - 2 * i - 1: 0 for i in range(ceil(n / 2))}
    for a in A:
        if (a not in nums) or (a == 0 and nums[a] == 1) or (nums[a] == 2):
            return 0
        nums[a] += 1
    ret = 1
    for _ in range(n // 2):
        ret = (ret * 2) % p
    return ret

_n = int(input())
_A = map(int, input().split())
print(solve(_n, _A))

Submission status: Accepted

Solution code:
import collections

MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
ap = [0 for _ in range(N)]

for a in A:
	ap[a] += 1
	
flg = 1
if N % 2 == 0:
	for i in range(1, N, 2):
		if ap[i] != 2:
			flg = 0
			break
			
else:
	if ap[0] != 1:
		flg = 0
	else:
		for i in range(2, N, 2):
			if ap[i] != 2:
				flg = 0
				break
				
# print(*ap)			
	
if not flg:
	print(0)
else:
	if N % 2 == 0:
		ans = pow(2, N // 2, MOD)
	else:
		ans = pow(2, (N - 1) // 2, MOD)
		
	print(ans)

Submission status: Accepted

Solution code:
from collections import Counter


def is_feasible(N, cntA):
    if N % 2 == 0:
        if len(cntA) != N // 2:
            return False

        for i in range(1, N, 2):
            if cntA[i] != 2:
                return False

        return True
    else:
        if len(cntA) != (N + 1) // 2:
            return False

        for i in range(0, (N + 1) // 2, 2):
            if i == 0:
                if cntA[i] != 1:
                    return False
            else:
                if cntA[i] != 2:
                    return False

        return True


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

if is_feasible(N, cntA) is False:
    print(0)
else:
    if N % 2 == 0:
        ans = 1
        for i in range(N // 2):
            ans *= 2
            ans %= MOD
        print(ans % MOD)
    else:
        ans = 1
        for i in range(N // 2):
            ans *= 2
            ans %= MOD
        print(ans % MOD)

Submission status: Accepted

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

def main():
    d = {}
    for a in A:
        if a not in d:
            d[a] = 0
        d[a] += 1
    ks =  all(map(lambda k: k % 2 == 0, d.keys())) or all(map(lambda k: k % 2 != 0, d.keys()))
    if 0 in d:
        d[0] += 1
    vs = all(map(lambda v: v == 2, d.values()))

    if ks and vs:
        n = N if N % 2 == 0 else N - 1
        n //= 2
        ans = 1
        for _ in range(n):
            ans *= 2
            ans %= 1000000007
    else:
        ans = 0
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
*a, = map(int, input().split())
a.sort()
ok = True
t = 1
if N % 2 == 1:
    if a.pop(0) != 0:
        ok = False
    t = 2

if ok:
    for i in range(0, len(a), 2):
        if t != a[i] or t != a[i+1]:
            ok = False
            break
        t += 2

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

Submission status: Accepted

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


cnt = [0] * n
for x in a:
  cnt[x] += 1

ok = True
for i in range(0, n):
  if n % 2 == 1 and i % 2 == 0:
    if i == 0 and cnt[i] != 1 or i > 0 and cnt[i] != 2:
      ok = False
  elif n % 2 == 0 and i % 2 == 1:
    if cnt[i] != 2:
      ok = False

if not ok:
  print(0)
else:
  res = 1
  for i in range(0, n // 2):
    res *= 2
    res %= 1000000007
  print(res)

Submission status: Accepted

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

import collections

c = collections.Counter(a)
f = 0
for i in c.items():
    if n % 2 != 0 and i[0] == 0 and i[1] == 1:
        pass
    elif i[1] == 2:
        pass
    else:
        f = 1
        break
if f == 1:
    print(0)
else:
    print((2 ** (n // 2)) % (10 ** 9 + 7))

Submission status: Accepted

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

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

if N%2 == 1 and A[-1] != 0:
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
amari = 10**9 + 7
ans = []
han = 0

if N % 2 == 0:
    han = 1
else:
    han = 0
    A.insert(0,0)


ans = list(int(i) for i in range(han,N,2))
ans += ans
ans.sort()

if ans == A:
    print(2**(N//2) % amari)
else:
    print("0")

Submission status: Accepted

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

counter = [0 for i in range(N)]

flag = True
for i in A:
  counter[i] += 1
  
for i in range(N):
  if counter[i] > 2:
    flag = False
if counter[0] > 1:
  flag = False
  
if flag:
  if N % 2 == 0:
    print(2**(N//2) % base)
  else:
    print(2**((N-1)//2) % base)
else:
  print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import collections


input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    c = collections.Counter(A)

    mod = 1
    if N & 1:
        mod = 0

    for k in c.keys():
        if mod == 0 and k == 0:
            continue

        if k % 2 != mod:
            print(0)
            break
        elif c[k] != 2:
            print(0)
            break
    else:
        print(pow(2, N // 2, 10 ** 9 + 7))



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    c = Counter(A)
    flag = True
    if N % 2 == 0:
        for i in range(1, N, 2):
            if c[i] != 2:
                flag = False
        if flag == False:
            print(0)
            return
    else:
        for i in range(0, N, 2):
            if i == 0:
                if c[i] != 1:
                    flag = False
            elif c[i] != 2:
                flag = False
        if flag == False:
            print(0)
            return
    print(pow(2, N//2, MOD))
    return


def main():

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    N = int(input())
    A = list(map(int,input().split()))
    INF = 10**9+7
    
    c = collections.Counter(A)
    ans = True
    if N%2 == 0:
        for i in range(N//2):
            if c[2*i+1] != 2:
                ans = False
    else:
        for i in range(N//2):
            if c[2*i+2] != 2:
                ans = False
        if c[0] != 1:
            ans = False
            
    if ans:
        print(pow(2,(N//2),INF))
    else:
        print(0)
        

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

numbers = Counter(list(range(not N % 2, N, 2)) * 2)
if N % 2:
    numbers[0] = 1
if Counter(A) == numbers:
    print(pow(2, (N // 2), int(10 ** 9 + 7)))
else:
    print(0)

Submission status: Accepted

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

if n == 1:
  if aList[0] != 0:
    print(0)
  else:
    print(1)
  exit(0)
if n % 2 != 0:
  if aList[0] != 0 and aList[1] == 0:
    print(0)
    exit(0)
  else:
    aList.pop(0)

for i in range(0,n-1,2):
  if i == 0:
    if aList[i] != aList[i+1]:
      print(0)
      exit(0)
  else:
    if aList[i] != aList[i+1] and aList[i] == aList[i-1]:
      print(0)
      exit(0)

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

print(int(result))

Submission status: Accepted

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

A_dict = dict()
if N % 2 == 0:
    for i in range(1, N, 2):
        A_dict[i] = 0
else:
    for i in range(0, N, 2):
        A_dict[i] = 0

for a in A:
    if a not in A_dict:
        print(0)
        exit()
    else:
        A_dict[a] += 1

for k, v in A_dict.items():
    if k == 0:
        if v != 1:
            print(0)
            exit()
    else:
        if v != 2:
            print(0)
            exit()
            
mod = 10**9+7
print(2 ** (N // 2) % mod)

Submission status: Accepted

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

N = int(input())
A = [int(x) for x in input().split()]
mod = 7 + 10 ** 9
from collections import Counter
c = Counter(A)
if N % 2 == 1:
    if c[0] != 1:
        print(0)
        sys.exit()
    for i in range(1, N):
        if i % 2 == 0 and c[i] != 2:
            print(0)
            sys.exit()
        elif i % 2 == 1 and c[i] != 0:
            print(0)
            sys.exit()
    print((2 ** (N // 2)) % mod)
else:
    for i in range(N):
        if i % 2 == 0 and c[i] != 0:
            print(0)
            sys.exit()
        elif i % 2 == 1 and c[i] != 2:
            print(0)
            sys.exit()
    print((2 ** (N // 2)) % mod)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
if n%2==1:
    a.append(0)
a.sort()

odd=tuple(a[::2])
even=tuple(a[1::2])

if odd==even:
    ans=2**(n//2)
    ans%=mod
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = LI()
    dic = collections.Counter()
    for a in A:
        dic[a] += 1
    even = False
    if N % 2 == 0:
        even = True
    cnt = 1
    n_element = 0
    if not even:
        for key, val in dic.items():
            if key == 0:
                continue
            if key % 2 > 0:
                cnt = 0
                break
            if val != 2:
                cnt = 0
                break
            n_element += 1

        for i in range(n_element):
            cnt = cnt * 2 % mod
        if dic[0] != 1:
            cnt = 0
    else:
        for key, val in dic.items():
            if key % 2 == 0:
                cnt = 0
                break
            if val != 2:
                cnt = 0
                break
            n_element += 1

        for i in range(n_element):
            cnt = cnt * 2 % mod
    print(cnt)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    mod = 10 ** 9 + 7

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

    ctr = [0] * n
    for x in a:
        ctr[x] += 1

    if n % 2 == 1:
        if ctr[0] != 1:
            print(0)
            return
        for i in range(1, n):
            if (i % 2 == 0 and ctr[i] != 2) or (i % 2 == 1 and ctr[i] != 0):
                print(0)
                return

    else:
        for i in range(n):
            if (i % 2 == 0 and ctr[i] != 0) or (i % 2 == 1 and ctr[i] != 2):
                print(0)
                return

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if n%2 == 0:
    r = range(1,n,2)
else:
    if dct[0] != 1:
        print(ans)
        exit()
    r = range(2,n,2)

for i in r:
    if dct[i] != 2:
        print(ans)
        exit()

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
c=Counter(a)
flg=True
if n%2==1:
    if c[0]!=1:
        print(0)
        exit()
for i in range(n//2):
    if c[i*2+n%2+1]!=2:
        flg=False
        break
ans=1
mod=10**9+7
if flg:
    for i in range(n//2):
        ans*=2
        ans%=mod
    print(ans)
else:
    print(0)

Submission status: Accepted

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

from collections import Counter

ctr = Counter(A)

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(0+(n%2^1),n,2):
    if i == 0 and c.get(0,0) != 1:
        print(0)
        exit()
    elif i > 0 and c.get(i,0) != 2:
        print(0)
        exit()
print(2**(n//2) % mod)

Submission status: Accepted

Solution code:
import collections
mod = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
a = collections.Counter(A)
a = a.most_common()[::-1]

if N % 2 == 0:
    for i in range(len(a)):
        if a[i][0] % 2 == 1 and a[i][1] == 2:
            pass
        else:
            print(0)
            exit()
    ans = (2 ** (N // 2)) % mod

else:
    for i in range(len(a)):
        if a[i][0] == 0:
            if a[i][1] == 1:
                pass
            else:
                print(0)
                exit()
        else:
            if a[i][0] % 2 == 0 and a[i][1] == 2:
                pass
            else:
                print(0)
                exit()
    ans = (2 ** (N // 2)) % mod 
print(ans)

Submission status: Accepted

Solution code:
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
l = []
for i  in range(N):
    l.append(abs(N-2*i-1))
l.sort()
A.sort()
if l != A:
    ans = 0
else:
    ans = pow(2,N//2,mod)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
from collections import Counter
if N%2 == 0:
    for e in A:
        if e%2 == 0:
            print(0)
            exit()
else:
    for e in A:
        if e%2 == 1:
            print(0)
            exit()
L = Counter(A)
ans = 1
mod = 10**9+7
for key,value in L.items():
    if N%2 == 1 and key == 0 and value > 1:
        print(0)
        exit()
    if value > 2:
        print(0)
        exit()
    ans *= value%mod
print(ans%mod)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
mod = int(1e+9 + 7)
p = 0
D = {N-1-2*i: 0 for i in range((N+1)//2)}
for i in A:
  if i in D:
    D[i] += 1
s = 0
if sum(D[i] for i in D) == N and max(D[i] for i in D) == 2:
  if 0 in D:
    if D[0] == 1:
      s = 1
  else:
    s = 1
elif N == 1 and 0 in D:
  s = 1
if s == 1:
  p = 1
  for i in range(N//2):
    p *= 2
    p %= mod
print(p)

Submission status: Accepted

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

c = collections.Counter(a)
for k, v in c.items():
    if n%2 == 0:
        if v != 2:
            print(0)
            quit()
    else:
        if k != 0 and v != 2 or k == 0 and v != 1:
            print(0)
            quit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

MODBY = 7 + 10**9

N = int(input())
A_list = [int(e) for e in input().split()]

c = collections.Counter(A_list)

if N%2 == 0:
    for j in c.items():
        if j[1] != 2 or j[0]%2 != 1:
            print(0)
            break
    else:
        print(2**(N//2)%MODBY)
elif N%2 == 1:
    if c[0] != 1:
        print(0)
    else:
        for j in c.items():
            if (j[1] != 2 and j[0] != 0) or j[0]%2 != 0:
                print(0)
                break
        else:
            print(2**(N//2)%MODBY)

Submission status: Accepted

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

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

C = Counter(A)
ans = 1
if N % 2 == 0:
    for i in range(1, N, 2):
        if C[i] != 2:
            print(0)
            exit()
        ans *= 2
        ans %= MOD
else:
    if C[0] != 1:
        print(0)
        exit()
    for i in range(2, N, 2):
        if C[i] != 2:
            print(0)
            exit()
        ans *= 2
        ans %= MOD
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

A.sort()
if N % 2 == 0:
    B = list(range(1, N, 2)) * 2
else:
    B = [0] + list(range(2, N, 2)) * 2
B.sort()

if A != B:
    print(0)
else:
    result = 1
    for i in range(N // 2):
        result *= 2
        result %= 1000000007
    print(result)

Submission status: Accepted

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


A_hash = {}

for i in A:
    if i in A_hash:
        A_hash[i] += 1
    else:
        A_hash[i] = 1

count = 0
for k, v in A_hash.items():
    if k == 0:
        continue
    if A_hash[k] != 2:
        print(0)
        exit()
    else:
        count += 1


ans = 1
for i in range(count):
    ans = ans * 2 % 1000000007
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
table = [0] * N
res = 1
mod = 10 ** 9 + 7
def no():
  print(0)
  exit(0)
for i in range(N):
  if a[i] >= N: no()
  table[a[i]] += 1
if table[0] != N % 2: no()
for i in range((N + 1) % 2, N, 2):
  if table[i] != 2:
    if i != 0: no()
  res *= table[i]
  res %= mod
print(res)

Submission status: Accepted

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

A.sort(reverse=True)
ans = 2 ** (N//2)
for i in range(N-1):
    if (i%2 != 0):
        continue
    else:
        if(A[i] != N-(i+1) or A[i+1] != N-(i+1)):
            ans = 0

if (N%2 != 0 and A[-1] != 0):
    ans = 0

print(ans%(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: # 0を2個にする
  A.append(0)

A.sort()
od = tuple(A[::2])
ev = tuple(A[1::2])
# Ai と Biで、ある値の登場する回数が等しくなかった場合、明らかに答えは 0 
if od == ev:
  comb = (2**(N//2)) % MOD
  print(comb)
else:
  # 左右対称じゃなく報告と矛盾
  print(0)

Submission status: Accepted

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

from collections import defaultdict
dic = defaultdict(int)
if n % 2 == 0:
   for a in al:
      dic[a] += 1
   for i in range(n//2):
      if dic[i*2+1] == 2:
         pass
      else:
         break
   else:
      print(2**(n//2)%(10**9+7))
      import sys
      sys.exit()
   print(0)
   import sys
   sys.exit()
else:
   for a in al:
      dic[a] += 1
   for i in range(n//2):
      if i == 0:
         if dic[i] == 1:
            pass
         else:
            break
      else:
         if dic[i*2] == 2:
            pass
         else:
            break
   else:
      print(2**(n//2)%(10**9+7))
      import sys
      sys.exit()
   print(0)
   import sys
   sys.exit()