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

mod=10**9+7

def isExist():
    if n%2==0:
        for i in range(1, n, 2):
            if c[i]==2:
                continue
            else:
                return False
    elif n%2==1:
        for i in range(0, n, 2):
            if i==0 and c[i]==1:
                continue
            elif c[i]==2:
                continue
            else:
                return False
    return True

if isExist():
    ans=1
    for _ in range(int(n*0.5)):
        ans*=2
        ans%=mod
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc050/tasks/arc066_a
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n = int(input())
    al = list(map(int, input().split()))
    al.sort()

    if len(al) % 2 == 1:  # odd
        if al[0] != 0:
            print(0)
            return
        al = al[1:]

    for i in range(0, len(al), 2):
        if al[i] != al[i+1]:
            print(0)
            return

    mod = 10**9 + 7
    print(2 ** (len(al) // 2) % mod)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-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 _pf(s): return print(s, flush=True)

N = _I()
A = LI()

"""
5
2 4 4 0 2

2なら、
xOxxx
xxxOx
の2通りしかない
N=9なら
xxxOxxxxx
xxxxxOxxx
の2通りしかない
4なら
Oxxxxと
xxxxO
しかない
これらをもとに確かめていく


Nが奇数の時
3
2 0 2
とすると成り立つ
4のとき
3 1 1 3
まずこれでできない場合をはじける

計算するまでもないのか。

2 4 4 0 2なら
前か後ろか、前か後ろかをかけるだけなので4

"""
if N == 1:
    if A[0] == 0:
        print(1)
    else:
        print(0)
    exit()

A.sort()

if N % 2 == 0:
    correct = list(range(1, N+1, 2))
    correct = correct + correct
    correct.sort()
else:
    # 奇数時
    correct = list(range(0, N+1, 2))
    correct = correct + correct
    correct.sort()
    correct = correct[1:]
if correct == A:
    ans = 2**(N//2)
    print(ans%mod)
else:
    print(0)

Submission status: Accepted

Solution code:
a=10**9+7
#print(a)
n=int(input())
s=list(map(int,input().split()))
s.sort()
t=n//2
ans=0
if n%2==0:
  check=[2*i+1 for i in range(t)]
  check*=2
  check.sort()
  

else:
  check=[2*i for i in range(t+1)]
  check*=2
  check.sort()
  check.remove(0)
  #print(check)

if check==s:
  ans=(2**t)%a
print(ans)

Submission status: Accepted

Solution code:
import collections

N = int(input())
A = list(map(int,input().split(' ')))
C = collections.Counter(A)
L = C.most_common()

if N % 2 == 0:
  for i, j in L:
    if j == 2:
      pass
    else:
      print(0)
      exit()
else:
   for i, j in L:
    if j == 2:
      pass
    else:
      if i == 0:
        pass
      else:
        print(0)
        exit()
print(int((2**(N//2) % (10**9+7))))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    base = []
    base_flg = []
    tmp = N // 2
    
    if N % 2 == 1:
        for i in range(0,N,2):
            base.append(i)
            base_flg.append(False)
    else:
        for i in range(1,N,2):
            base.append(i)
            base_flg.append(False)
            
    dic = {}
    for i in A:
        if i in dic:
            dic[i] += 1
        else:
            dic[i] = 1
            
    for k, v in dic.items():
        if k in base:
            if v == 2 and k != 0:
                ind = base.index(k)
                if base_flg[ind] == False:
                    base_flg[ind] = True
                else:
                    print(0)
                    sys.exit()
            else:
                if k == 0 and v == 1:
                    ind = base.index(k)
                    if base_flg[ind] == False:
                        base_flg[ind] = True
                    else:
                        print(0)
                        sys.exit()
                else:
                    print(0)
                    sys.exit()
        else:
            print(0)
            sys.exit()
            
    for i in base_flg:
        if i == False:
            print(0)
            sys.exit()
            
    tmp = N // 2    
    print((2**tmp) % 1000000007)
    
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
from collections import Counter

MOD = 10 ** 9 + 7

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

C = Counter(A)

b = 1 if N % 2 == 0 else 0

for key, value in C.items():
    if b == 0 and key == b and value != 1:
        print(0)
        exit()

    if key != b and value != 2:
        print(0)
        exit()
    b += 2

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

Submission status: Accepted

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

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

else:
  b=[0]+a
  for i in range(0,(n+1)//2+1,2):
    if not b[i]==b[i+1]==i:
      print("0")
      exit(0)
  print(2**((n-1)//2)%(10**9+7))

Submission status: Accepted

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

if n%2==0:
  if 0 in a or len(set(a))!=n//2:flag=False
else:
  if len([0 for x in a if x==0])!=1 or len(set(a))!=n//2+1:flag=False

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

Submission status: Accepted

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

n = N // 2
c = N - 1
for _ in range(n):
  a, b = A.pop(), A.pop()
  if (a != c) or (b != c):
    print(0)
    exit()
  c -= 2
      
if N % 2 == 1 and A[0] != 0:
    print(0)
    exit()
  
print(pow(2, n, (10**9 + 7)))

Submission status: Accepted

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

if A == cr_A:
	if N > 1:
		print((2**(N//2))%(10**9 + 7))
	else:
		print(1)
else:
	print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
ai=[int(x) for x in input().split()]
#print(len(set(ai)), -(-n // 2))
if (ai.count(0)==0 or ai.count(0)==1) and len(set(ai))==-(-n//2):
    ans=1
    for i in range(n//2):
        ans*=2
        ans%=10**9+7
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
Ns = [0]*N
for A in As:
  Ns[A] += 1
#print(Ns)
r = 1
if N%2 == 1:
  if Ns[0] > 1:
    r = 0
  for i in range(1, N):
    if i%2 == 1 and Ns[i] > 0:
      r = 0
    if i%2 == 0 and Ns[i] > 2:
      r = 0
    if i%2 == 0 and (Ns[i] == 1 or Ns[i] == 2):
      r = (r*2)%1000000007
if N%2 == 0:
  for i in range(0, N):
    if i%2 == 0 and Ns[i] > 0:
      r = 0
    if i%2 == 1 and Ns[i] > 2:
      r = 0
    if i%2 == 1 and (Ns[i] == 1 or Ns[i] == 2):
      r = (r*2)%1000000007
print(r)

Submission status: Accepted

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

A.sort()

if N % 2 == 0:
  check = []
  for i in range(1, N + 1, 2):
    check.append(i)
    check.append(i)
  if A != check:
    print(0)
    exit(0)
else:
  check = [0]
  for i in range(2, N + 1, 2):
    check.append(i)
    check.append(i)
  if A != check:
    print(0)
    exit()

ans = 1
for _ in range(N // 2):
  ans *= 2
  ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

Submission status: Accepted

Solution code:
import collections

N = int(input())
lst = list(map(int, input().split()))
c = dict(collections.Counter(lst))
ans = 2 ** (N // 2)
if (N % 2 != 0):
  for i in range(0, N, 2):
    if (i not in c.keys()):
      ans = 0
      break
    else:
      if (i == 0):
        if (c[i] != 1):
          ans = 0
          break
      else:
        if (c[i] != 2):
          ans = 0
          break
else:
  for i in range(1, N, 2):
    if (i not in c.keys()):
      ans = 0
      break
    else:
      if (c[i] != 2):
        ans = 0
        break
      
print(ans % ((10 ** 9) + 7))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections


n = int(input())
A = input().split()
d = collections.defaultdict(int)
for a in A:
    d[a] += 1
if n == 1:
    print(1)
    exit()
if n % 2 != 0:
    if '0' not in d or d['0'] != 1:
        print(0)
        exit()
    for i in range(2, n, 2):
        if str(i) not in d or d[str(i)] != 2:
            print(0)
            exit()
else:
    if '0' in d:
        print(0)
        exit()
    for i in range(1, n, 2):
        if str(i) not in d or d[str(i)] != 2:
            print(0)
            exit()
print(2**(n//2) % (10**9+7))

Submission status: Accepted

Solution code:
from  collections import Counter

n =int(input())

a = list(input().rstrip().split())

count_num = Counter(a)

result = True

if len(a) == n:
    if n % 2 == 0:
        for i in range(n-1, -1, -2):
            if count_num[str(i)] ==2:
                continue
            else:
                result = False
                break

    else:
        if count_num['0'] == 1:
            for i in range(n-1, 1, -2):                
                if count_num[str(i)] ==2:continue
                else:
                    result = False
                    break
        else:result=False

if result: print(2**int(n/2) % (10**9+7))
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 == 1:
    check = [0]
    for i in range(2, N + 1, 2):
        check.append(i)
        check.append(i)
    if A != check:
        print(0)
        exit(0)
else:
    check = []
    for i in range(1, N + 1, 2):
        check.append(i)
        check.append(i)
    if A != check:
        print(0)
        exit(0)

ans = 1
for _ in range(N // 2):
    ans *= 2
    ans %= MOD

print(ans)

Submission status: Accepted

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

if N % 2 == 0:
    hasZero = False
    for a in A:
        if a % 2 == 0:
            print(0)
            exit(0)

if N % 2 == 1:
    hasZero = False
    for a in A:
        if a == 0:
            if hasZero:
                print(0)
                exit(0)
            hasZero = True
        elif a % 2 == 1:
            print(0)
            exit(0)
    if not hasZero:
        print(0)
        exit(0)

ans = 1
for _ in range(N // 2):
    ans *= 2
    ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
a = collections.Counter(a).most_common()
cnt = 1
for k, v in a:
    if k == 0 and v == 1 and n % 2 != 0:
        cnt *= 1
    elif k == 0 and v == 2 and n % 2 == 0:
        cnt *= 1
    elif k != 0 and v == 2:
        cnt *= 2
    else:
        print(0)
        exit()
    cnt %= (10 ** 9 + 7)
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
    if n > ((i+1)*2-1):
        b.append(n-((i+1)*2-1))
    else:
        b.append(((i+1)*2-1)-n)

a.sort()
b.sort()
if a==b:
    print((2**(n//2))%(10**9+7))
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num = int(input())
mem = list(map(int, input().split()))

dic = {}
mod = 10 ** 9 + 7
zeros = 0
flag = True
for i in range(num):
    temp = mem[i]
    if not temp == 0:
        dic.setdefault(str(temp), 0)
        dic[str(temp)] += 1
    else:
        zeros += 1
for key in dic:
    if not dic[key] == 2:
        flag = False
        break
        
if (zeros == 0 or zeros == 1) and flag:
    print(int((2 ** (len(mem) // 2) % mod)))
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
C = [0] * N
for a in A:
    C[a] += 1
if N % 2 == 1:
    if C[0] != 1:
        print(0)
        exit()
    for i in range(2, N, 2):
        if C[i] != 2:
            print(0)
            exit()
    print(2 ** ((N - 1) // 2) % 1000000007)
else:
    for i in range(1, N, 2):
        if C[i] != 2:
            print(0)
            exit()
    print(2 ** (N // 2) % 1000000007)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
aa=sorted(map(int,input().split()),reverse=True)
m=n-1
for i in range(n//2):
    if aa[2*i]!=m or aa[2*i+1]!=m:
        print(0)
        sys.exit()
    m-=2
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()
B = []

ans = 1

if len(A) % 2 == 0:
    for i in range(len(A)//2):
        ans *= 2
        ans %= MOD
        B.append(2 * i + 1)
        B.append(2 * i + 1)

else:
    B.append(0)
    for i in range(len(A)//2):
        ans *= 2
        ans %= MOD
        B.append(2 * i + 2)
        B.append(2 * i + 2)

if A == B:
    print(int(ans))
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())

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

bucket = [0 for _ in range(N)]

if N % 2 == 0:
	even = True
else:
	even = False

Not0 = True

for i in range(N):
	if even:
		if A[i] % 2 == 0:
			print(0)
			Not0 = False
			break
		else:
			if bucket[A[i]] == 2:
				print(0)
				Not0 = False
				break
			else:
				bucket[A[i]] += 1
	else:
		if A[i] % 2 == 1:
			print(0)
			Not0 = False
			break
		else:
			if bucket[A[i]] == 2:
				print(0)
				Not0 = False
				break
			else:
				bucket[A[i]] += 1

if Not0:
	if not even:
		if bucket[0] != 1:
			print(0)
			Not0 = False

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
lst = [int(i) for i in input().split()]
mod = 10**9 + 7
lst_c = Counter(lst)
lst_c = sorted(lst_c.items(),key = lambda x:x[0])

ideal = []

if n%2!=0:
    ideal.append((0,1))
    for i in range(1,n//2+1):
        ideal.append((2*i,2))
else:
    for i in range(n//2):
        ideal.append((2*i+1,2))

if lst_c != ideal:
    print(0)
else:
    l = len(ideal)
    if n%2!=0:
        l -= 1
    print(2**l % mod)

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
mod = 10**9 + 7
ans = (2 ** (n // 2)) % mod
b = []
for i in range(n):
  b += [abs(n+1-2*(i+1))]
b.sort()

if a == b :
  print(ans)
else:
  print(0)

Submission status: Accepted

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


def solve(N, A):
    counter = Counter(A)
    if N % 2 == 1:
        for a, n in counter.items():
            if a == 0 and n == 1:
                continue
            if a % 2 != 0 or n != 2:
                return 0
        return (2**(N//2)) % 1000000007
    else:
        for a, n in counter.items():
            if a % 2 != 1 or n != 2:
                return 0
        return (2**(N//2)) % 1000000007

print(solve(N, A))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections

MOD = 1000000007  # type: int

def mpow(n, base):
    res = 1
    for i in range(n):
        res = res * base % MOD
    return res

def solve(N: int, A: "List[int]"):
    A.sort()
    if N % 2 == 0:
        for i in range(0, N//2):
            if A[2*i] != 2*i+1 or A[2*i+1] != 2*i+1:
                print(0)
                return
        print(mpow(N//2, 2))
    else:
        for i in range(0, N//2):
            if i == 0:
                if A[0] != 0:
                    print(0)
                    return
                else:
                    continue
            if A[2*i] != 2*i or A[2*i-1] != 2*i:
                print(0)
                return
        print(mpow(N//2, 2))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
import math
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
half = math.floor(N/2)
ans = 2**(half)
if N%2 == 1 and A[-1] !=0:
  ans = 0
for i in range(half):
  if A[2*i] == N-2*i-1 and A[2*i+1] == N-2*i-1:
    continue
  else:
    ans = 0
    break
print(ans%(10**9+7))

Submission status: Accepted

Solution code:
N = int(input())
nums = list(map(int, input().split()))
n_dict = {}
idx = 0
mod = ((N%2)+1)%2
while True:
  if 2*idx + mod > N:
    break
  else:
    n_dict[2*idx+mod] = 0
  idx += 1
for num in nums:
  if num in n_dict:
    n_dict[num] += 1
  else:
    print(0)
    exit()
for key, value in n_dict.items():
  if value != 2 and key != 0:
    print(0)
    exit()
print((2**(N//2))%(10**9+7))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().rstrip().split()))
A.sort()
ANS = 2**(N//2)

if N%2 == 0:
    if A[0] and A[1] != 1:
        print(0)
        exit()
    elif N == 2:
        if A[0] != A[1]:
            print(0)
            exit()
    else:
        for i in range(2,N,2):
            if A[i] != A[i+1] or A[i] - A[i-2] != 2:
                print(0)
                exit()
else:
    if A[0] != 0:
        print(0)
        exit()
    elif N == 3:
        if A[1] != A[2]:
            print(0)
            exit()
    else:
        for i in range(3,N,2):
            if A[i] != A[i+1] or A[i] - A[i-2] != 2:
                print(0)
                exit()

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

Submission status: Accepted

Solution code:
n=int(input())

#データを並び替える
rowdata=[int(i) for i in input().split()]
rowdata.sort()

#nが偶数の時
if n%2==0:
    check=[]
    a=1
    for i in range(1,n,2):
        check.append(i)
        check.append(i)
    if check==rowdata:
        for i in range(int(n/2)):
            a*=2
            a=a%1000000007
        print(a)
    else:
        print(0)
        
#nが奇数の時
else:
    check=[]
    a=1
    if n==1:
        check=[0]
    else:
        for i in range(0,n,2):
            if i==0:
                check.append(i)
            else:
                check.append(i)
                check.append(i)
    if check==rowdata:
        for i in range(int((n-1)/2)):
            a*=2
            a=a%1000000007
        print(a)
    else:
        print(0)

Submission status: Accepted

Solution code:
import math
n = int(input())

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

if n == 1:
    if a[0] == 0:
        print(1)
    else:
        print(0)
    exit()



if n % 2 == 1:
    ans = 2 ** ((n-1) // 2)
else:
    ans = 2 ** (n//2)


if n % 2 == 1:
    for i in range(n):
        if i == 0:
            if a[i] == 0:
                continue
            else:
                print(0)
                exit()
        else:
            if a[i] == math.ceil(i/2)*2:
                continue
            else:
                print(0)
                exit()
else:
    for i in range(n):
        if a[i] == math.floor(i/2)*2+1:
            continue
        else:
            print(0)
            exit()

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

Submission status: Accepted

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

B = Counter(A)
c = (N+1)%2
#print(B, c)
ans = 1
for k, v in B.items():
    if k%2 != c or (k!=0 and v != 2):
        ans = 0
        break
    ans = ans * v % mod

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

sorted_l = sorted(l)

w = 0

if n % 2 == 0:
    k = 1
    for i in range(n):
        if k != sorted_l[i]:
            w += 1
        
        if i % 2 == 1:
            k += 2
            
else:
    if sorted_l[0] != 0:
        w += 1
    k = 2
    for i in range(1,n):
        if k != sorted_l[i]:
            w += 1
        
        if i % 2 == 0:
            k += 2
            
if w != 0:
    print(0)

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

Submission status: Accepted

Solution code:

from collections import Counter
import sys

def main():

    num = int(input())
    data = list(map(int, input().split()))
    count_data = Counter(data)
    mod = 10 ** 9 + 7

    if num % 2 == 1:
        if count_data[0] != 1:
            print(0)
            sys.exit()
        for i in range(1, (num // 2) + 1):
            if count_data[i * 2] != 2:
                print(0)
                sys.exit()

    else:
        for i in range(num // 2):
            if count_data[i * 2 + 1] != 2:
                print(0)
                sys.exit()

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




if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a = LS()
    if a[1][0] == "+":
        print(int("".join(a[0])) + int("".join(a[2])))
    else:
        print(int("".join(a[0])) - int("".join(a[2])))
    return

#B
def B():
    return

#C
def C():
    n = II()
    a = LI()
    d = defaultdict(int)
    ans = 1
    if n & 1:
        for i in a:
            if i & 1:
                print(0)
                return
            d[i] += 1
        for a, b in d.items():
            if a:
                if b == 2:
                    ans *= 2
                    ans %= mod
                    continue
                print(0)
                return
            if b == 1:
                continue
            print(0)
            return
    else:
        for i in a:
            if i & 1:
                d[i] += 1
                continue
            print(0)
            return
        for a, b in d.items():
            if b == 2:
                ans *= 2
                ans %= mod
                continue
            print(0)
            return
    print(ans)
            
        
    return

#D
def D():
    return


#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
flag = N % 2 == 0
if not flag:
	flag = A[0] == 0
if flag:
	index = N % 2
	while index < N:
		if A[index] != index + 1 or A[index] != A[index]:
			flag = False
			break
		index += 2
if flag:
	print((2**(N//2))%(10**9+7))
else:
	print(0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    count = [0] * N
    for a in A:
        if a % 2 == N % 2:
            print(0)
            return
        count[a] += 1
    if N % 2 == 1 and count[0] == 1:
        count = count[1:]
    for cnt in count:
        if cnt != 0 and cnt != 2:
            print(0)
            return
    ret = (2 ** (N // 2)) % MOD
    print(ret)
    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(raw_input())
A = map(int, raw_input().split())
A.sort(reverse=True)
success = True
el = n - 1
for i in range(0, len(A)-1, 2):
    if A[i] != el or A[i+1] != el:
        success = False
        break
    el -= 2
if n % 2 == 1:
    if A[-1] != 0:
        success = False
else:
    if A[-1] != 1 or A[-2] != 1:
        success = False
if success:
    print pow(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()
mod=10**9+7
f=True
if n==1:
    if a[0]==0:
        print(1)
    else:
        print(0)
    exit()
if n%2==1:
    if a[0]!=0 or a[1]==0:
        f=False
    for i in range(1,n-1,2):
        if not (a[i]==i+1 and a[i+1]==i+1):
            f=False
else:
    for i in range(0,n,2):
        if not (a[i]==i+1 and a[i+1]==i+1):
            f=False
if f:
    print((2**(n//2))%mod)
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7
import collections
import numpy as np
import sys
count = collections.Counter(A)
loops = np.arange(N-1,-1,-2)

for li in list(loops):
    if li == 0 :
        if count[li] != 1:break
    else:
        if count[li] != 2:break

else:
    b = N//2
    ans = 1
    for i in range(1,b+1):
        ans *= 2
        ans %= mod
    print(ans)   
    sys.exit()

print(0)