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:
import collections
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
c = collections.Counter(a)
cl = ""
if n%2 == 1:
	cl = "odd"
else:
	cl = "even"
ans = 0
if cl == "odd":
	for i in c:
		if i%2 == 1:
			print (ans)
			exit()
		if i == 0:
			if c[i] != 1:
				print (ans)
				exit()
		else:
			if c[i] != 2:
				print (ans)
				exit()
	ans = 2**(n//2)%mod
else:
	for i in c:
		if i%2 == 2:
			print (ans)
			exit()
		if c[i] != 2:
			print (ans)
			exit()
	ans = 2**(n//2)%mod
print (ans)

Submission status: Accepted

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

Submission status: Accepted

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

from collections import Counter

class Mint:
    
    MOD = 10**9+7
    
    def __init__(self, x=0):
        self.x = (x%self.MOD + self.MOD) % self.MOD
    
    def __iadd__(self, other):
        self.x += other.x
        if self.x >= self.MOD:
            self.x -= self.MOD
        return self
    
    def __isub__(self, other):
        self.x += self.MOD - other.x
        if (self.x >= self.MOD):
            self.x -= self.MOD
        return self
    
    def __imul__(self, other):
        self.x *= other.x
        self.x %= self.MOD;
        return self;
    
    def __add__(self, other):
        ans = Mint(self.x)
        ans += other
        return ans
        
    def __sub__(self, other):
        ans = Mint(self.x)
        ans -= other
        return ans
    
    def __mul__(self, other):
        ans = Mint(self.x)
        ans *= other
        return ans
    
    def __pow__(self, n):
        if n == 0:
            return Mint(1)
        a = self.__pow__(n >> 1)
        a *= a
        if n&1:
            a *= self
        return a
    
    def inv(self):
        return self**(self.MOD-2)
    
    def __ifloordiv__(self, other):
        self *= other.inv()
        return self
    
    def __floordiv__(self, other):
        ans = Mint(self.x)
        ans //= other
        return ans
        
    

def Main(N, A):
    counter = Counter(A)
    if len(A)%2 == 0:
        v = counter.values()
        s = set(v)
        if len(s) > 1:
            return 0
        else:
            k = list(counter.keys())
            k.sort()
            for i, e in enumerate(k):
                if e != 2*i+1:
                    return 0
            return (Mint(2)**(len(A)//2)).x
    else:
        if 0 not in counter:
            return 0
        if 0 in counter and counter[0] != 1:
            return 0
        del counter[0]
        v = counter.values()
        s = set(v)
        if len(s) > 1:
            return 0
        else:
            k = list(counter.keys())
            k.sort()
            for i, e in enumerate(k):
                if e != 2*(i+1):
                    return 0
            return (Mint(2)**(len(A)//2)).x           
                    
                

res = Main(N, A)
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

if sum(l) == 2 * sum(s):
  flg = True
else:
  flg = False
#print(c)
print(2**(n//2)%(10**9+7) if flg else 0)

Submission status: Accepted

Solution code:
def main():
    from collections import Counter
    n, *a = map(int, open(0).read().split())
    c = Counter(a)
    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
    ans = 2 ** (n // 2) % 1000000007 if f is True else 0
    print(ans)


if __name__ == '__main__':
    main()

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:
def pow_mod(n, k, m):
    if k == 0:
        return 1
    if k & 1:
        return (pow_mod(n, k - 1, m) * n % m) % m
    else:
        return (pow_mod(n, k // 2, m) ** 2) % m

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

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(map(int, input().split()))
print(pow(2, N >> 1, 10 ** 9 + 7) if (N & 1 and sorted(list(range(0, N, 2)) + list(range(2, N, 2))) == A) or (not N & 1 and sorted(list(range(1, N, 2)) + list(range(1, N, 2))) == A) else 0)

Submission status: Accepted

Solution code:
n = int(input())
cnts = [0]*n
alist = list(map(int,input().split()))
mod = 10**9+7

for i in range(n):
    cnts[alist[i]] += 1

p = n%2
if p == 1:
    cnts[0] += 1

for i in range(n):
    if p != (i%2):
        if cnts[i] != 2:
            print(0)
            exit()
    else:
        if cnts[i] != 0:
            print(0)
            exit()
print(pow(2,(n//2))%mod)

Submission status: Accepted

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

if N%2 == 0:
  B = list(range(N-1,0,-2))+list(range(1,N,2))
else:
  B = list(range(N-1,0,-2))+list(range(0,N,2))

if Counter(A) != Counter(B):
  print(0)
else:
  mod = 10**9+7
  print(2**(N//2)%mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7
n = int(input())
a = list(map(int,input().split()))

if n%2 == 0:
    c = collections.Counter(a)
    item = []
    for key,value in c.items():
        item.append([key,value])
    item.sort()
    ans = 1
    for i in range(len(item)):
        if 2*i + 1 == item[i][0]:
            if item[i][1] == 2:
                ans *= 2
                ans %=MOD
            else:
                print(0)
                sys.exit()
        else:
            print(0)
            sys.exit()
    print(ans%MOD)
else:
    c = collections.Counter(a)
    ans = 1
    item = []
    for key,value in c.items():
        item.append([key,value])
    item.sort()
    for i in range(1,len(item)):
        if 2*i == item[i][0]:
            if item[i][1] == 2:
                ans *= 2
                ans %=MOD
            else:
                print(0)
                sys.exit()
        else:
            print(0)
            sys.exit()
    if item[0][0] == 0 and item[0][1] == 1:
        print(ans%MOD)
    else:
        print(0)

Submission status: Accepted

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

Submission status: Accepted

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

if N%2==0:
    if all(A[i]==A[i+1] and A[0]==1 and A[1]==1 and A[i]-2==A[i-2] for i in range(2,N,2)):
        print((2**(N//2))%mod)
    else:
        print(0)
else:
    if all(A[0]==0 and A[i]==A[i-1] and A[i]-2==A[i-2] and A[-1]==N-1 for i in range(2,N,2)):
        print((2**(N//2))%mod)
    else:
        print(0)

Submission status: Accepted

Solution code:
def main():
  n=int(input())
  a=sorted(list(map(int,input().split())))
  mod=pow(10,9)+7
  if n%2==0:
    b=[2*(i//2)+1 for i in range(n)]
    if  not all(a[i]==b[i] for i in range(n)):
      ans=0
    else:
      ans=pow(2,n//2,mod)
  else:
    b=[0]+[2*(i//2) for i in range(2,n+1)]
    if not all(a[i]==b[i] for i in range(n)):
      ans=0
    else:
      ans=pow(2,n//2,mod)
  print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7
c = Counter(A)
flg = True
for k,v in c.items():
    if k==0:
        if v!=1:
            flg = False
    else:
        if v!=2:
            flg = False
if flg is False:
    print(0)
else:
    print(pow(2, n//2, mod))

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

# print('c', c)
if N % 2 == 0:
    for key, value in c.items():
        if key % 2 != 1:
            print(0)
            exit()
        if value != 2:
            print(0)
            exit()
else:
    if c.get(0) is None:
        print(0)
        exit()
    for key, value in c.items():
        if key == 0:
            continue
        if key % 2 != 0:
            print(0)
            exit()
        if value != 2:
            print(0)
            exit()
ans = pow(2, N // 2, MOD)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

li=[]

for i in range(n-1,-(n),-2):
    li.append(abs(i))

li.sort()

if a==li:
    print((2**(n//2))%mod)
else:
    print(0)

Submission status: Accepted

Solution code:
import collections
def solve(n, a_list):

    count = collections.Counter()
    for a in a_list:
        count[a] += 1

    count[0] += 1
    c = [False] * n
    for k, v in count.items():
        c[k] = (v == 2)

    if n % 2 == 1:
        tmp = all([v for i, v in enumerate(c) if i % 2 == 0])
    else:
        tmp = all([v for i, v in enumerate(c) if i % 2 == 1])

    if tmp:
        return (2 ** (n//2) ) % (10**9+7)
    else:
        return 0

if __name__ == "__main__":
    n = int(input())
    a_list = [int(i) for i in input().split()]
    print(solve(n, a_list))

Submission status: Accepted

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

flg = True
if N%2 == 0:
  for i in range(0, N//2): flg &= A[2*i] == A[2*i+1] == 2*i+1
else:
  flg &= A[0] == 0
  for i in range(1, (N+1)//2): flg &= A[2*i-1] == A[2*i] == 2*i

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

print(modpow(2, N//2, 10**9+7) if flg else 0)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
lst = [int(x) for x in input().split()]
counter = Counter(lst)

if N % 2 == 0:
    if len(counter) * 2 != N:
        print(0)
        exit()
    for x in range(1, N, 2):
        if counter[x] != 2:
            print(0)
            exit()

else:
    if len(counter) * 2 - 1 != N:
        print(0)
        exit()
    if counter[0] != 1:
        print(0)
        exit()
    for x in range(2, N + 1, 2):
        if counter[x] != 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(map(int,input().split()))
c = Counter(a)
m = c.most_common()
judge = 0
ans = 1
if n%2 == 0:
    for i in range(len(m)):
        if m[i][0]%2==0 or m[i][1]!=2 or m[i][0]>n-1:
            judge = 1
    num=n//2
else:
    for i in range(len(m)):
        if (m[i][0]==0 and m[i][1]!=1) or m[i][0]%2==1 or (m[i][1]!=2 and m[i][0]!=0)or m[i][0]>n-1:
            judge = 1
    num=(n-1)//2
if judge ==1:
    print('0')
else:
    for i in range(num):
        ans=ans*2%1000000007
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

alist.sort()

# print(alist)

mod = (10**9 + 7)

if N % 2 == 1:
    alist.pop(0)
    for i in range(N//2):
        # print('it', alist[i*2], 2*(i + 1), alist[i*2 + 1], 2*(i + 1))
        if alist[i*2] != 2*(i + 1) or alist[i*2 + 1] != 2*(i + 1):
            print(0)
            exit(0)
    print(2**(N//2)%mod)
else:
    for i in range(N//2):
        # print('it', alist[i*2], 2*(i + 1), alist[i*2 + 1], 2*(i + 1))
        if alist[i*2] != 2*i + 1 or alist[i*2 + 1] != 2*i + 1:
            print(0)
            exit(0)
    print(2**(N//2)%mod)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
a = [0] * ((N + 1) // 2)
for i in A:
	if N % 2:
		if i % 2:
			print(0)
			exit()
	else:
		if i % 2 == 0:
			print(0)
			exit()
	a[i // 2] += 1
if N % 2:
	if any(i != 2 for i in a[1:]) or a[0] != 1:
		print(0)
		exit()
else:
	if any(i != 2 for i in a):
		print(0)
		exit()
print(2 ** (N // 2) % 1000000007)

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(int, input().split()))
s_set = set(s)
count = 2 ** ((n) // 2)
if (sum(s) == 2 * sum(s_set)):
    print(count % (10 ** 9 + 7))
else:
    print(0)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    # A = list(input().replace(" ", "")) -> WA
    A = input().split() # -> AC
    import collections
    counter = collections.Counter(A)
    if N % 2 == 1:
        if counter["0"] != 1:
            print("0")
            return
        for k, v in counter.items():
            if k == "0":
                continue
            if int(k) % 2 == 1:
                print("0")
                return
            if v != 2:
                print("0")
                return
    else:
        for k, v in counter.items():
            if int(k) % 2 == 0:
                print("0")
                return
            if v != 2:
                print("0")
                return
    
    print( (2**(N//2)) % (10**9+7) )




if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

def resolve():
    N = int(input())
    # A = input().replace(" ", "")
    # A = readline().rstrip().split()
    A = input().split()
    import collections
    counter = collections.Counter(A)
    if N % 2 == 1:
        if counter["0"] != 1:
            print("0")
            return
        for k, v in counter.items():
            if k == "0":
                continue
            if int(k) % 2 == 1:
                print("0")
                return
            if v != 2:
                print("0")
                return
    else:
        for k, v in counter.items():
            if int(k) % 2 == 0:
                print("0")
                return
            if v != 2:
                print("0")
                return
    
    print( (2**(N//2)) % (10**9+7) )




if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

def resolve():
    N = int(input())
    # A = input().replace(" ", "")
    A = readline().rstrip().split()
    import collections
    counter = collections.Counter(A)
    if N % 2 == 1:
        if counter["0"] != 1:
            print("0")
            return
        for k, v in counter.items():
            if k == "0":
                continue
            if int(k) % 2 == 1:
                print("0")
                return
            if v != 2:
                print("0")
                return
    else:
        for k, v in counter.items():
            if int(k) % 2 == 0:
                print("0")
                return
            if v != 2:
                print("0")
                return
    
    print( (2**(N//2)) % (10**9+7) )




if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

if A != B:
  print(0)
else:
  if N % 2 == 0:
    print(pow(2, N//2, mod))
  else:
    print(pow(2, (N-1)//2, mod))

Submission status: Accepted

Solution code:
n = int(input())
q = [int(x) for x in input().split(' ')]
q_set = set(q)

if (n%2 == 1):
    count = 2**((n-1)//2)
else:
    count = 2**(n//2)
    
    
if (sum(q) == 2*sum(q_set)):
    print(count%(10**9+7))
else:
    print(0)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
from collections import Counter
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    c = Counter(A)
    if N % 2 == 1:
        if c[0] != 1:
            print(0)
            return
        for i in range(2, N, 2):
            if c[i] != 2:
                print(0)
                return

    else:
        for i in range(1, N, 2):
            if c[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(c) for c in input().split()]
ans = 1
MOD = 10**9+7
Cnt = Counter(A)
if N%2==1:
  for k,v in Cnt.items():
    if (k%2==0 and v==2) or (k==0 and v==1):
      ans *= v
      ans %= MOD
    else:
      print(0)
      break
  else:
    print(ans)
else:
  for k,v in Cnt.items():
    if k%2==1 and v==2:
      ans *= v
      ans %= MOD
    else:
      print(0)
      break
  else:
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a_ls = list(map(int, input().split()))
mod = 1000000007
isOK = True
if n % 2 == 0:
    count_ls = [0] * n
    for a in a_ls:  
        count_ls[a] += 1
    suppose = [0,2] * (n//2)
    if not count_ls == [0,2] * (n//2):
        isOK = False
else:
    count_ls = [0] * n
    for a in a_ls:  
        count_ls[a] += 1
    suppose = [1] + [0,2] * (n//2)
    if not count_ls == suppose:
        isOK = False
if isOK:
    ans = (2 ** (n // 2)) % mod
else:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(l)
ans = 0
flag = True
if N%2==0:
    for i in range(1,N+1,2):
        if c[i] != 2:
            flag = False
else:
    for i in range(0,N+1,2):
        if i == 0 and c[i] != 1:
            flag = False 
        if i != 0 and c[i] != 2: 
            flag = False

if flag:
    ans = 2**int(N/2)
print(ans % (10**9+7))

Submission status: Accepted

Solution code:
from collections import Counter

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

count = Counter(Alist)
res = 1
if N % 2 ==0:
    for i in range(1,N,2):
        if count[i] != 2:
            print(0)
            exit()
else:
    if count[0] != 1:
        print(0)
        exit()
    else:
        for i in range(2,N,2):
            if count[i] != 2:
                print(0)
                exit()
print(2**(N//2) % (10**9+7))

Submission status: Accepted

Solution code:
from collections import defaultdict

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

for i in range(n):
    cnt[a[i]] += 1
flag = True

if 0 in cnt.keys():
    del cnt[0]

for i in range(n - 1, 0, -2):
    if cnt[i] != 2:
        flag = False
        break 
print((2 ** (n // 2)) % (10 ** 9 + 7) if flag else 0)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=Counter(a)
c=len(([i[0] for i in b.items() if i[1] == 2]))
if n%2==0:
    if n//2==c:
        print(2**(len(set(a)))%1000000007)
    else:
        print(0)
else:
    if (n-1)//2==c and a.count(0)==1:
        print(2**(len(set(a))-1)%1000000007)
    else:
        print(0)

Submission status: Accepted

Solution code:
# python3.4.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')

N = iin()
A = iln()

counter = dict()

possible = True
for a in A:
    if a in counter:
        counter[a] += 1
        if a == 0 and counter[a] > 1:
            possible = False
        elif a != 0 and counter[a] > 2:
            possible = False
    else:
        counter[a] = 1
if possible:
    print(2**(N//2)%MOD)
else:
    print(0)

Submission status: Accepted

Solution code:
def abc050_c():
  n = int(input())
  A = list(map(int, input().split()))
  div = 10**9 + 7

  from collections import Counter
  cntr = Counter(A)

  if n % 2 == 0:
    # 偶数個の場合：1,3,5..が2個ずつ
    for i in range(1, n, 2):
      if cntr[i] != 2:
        print(0)
        return
  else:
    # 奇数個の場合：0が1個、2,4,6..が2個ずつ
    if cntr[0] != 1:
      print(0)
      return
    for i in range(2, n, 2):
      if cntr[i] != 2:
        print(0)
        return

  # 半分決まれば残り半分は自動的に決まる
  # nを2で切り捨てた個数 (奇数個のど真ん中は含まない)
  ans = pow(2, n//2, div)
  print(ans)

abc050_c()

Submission status: Accepted

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

mod = 10**9+7
c = collections.Counter(a)
c =c.most_common()
c.sort()

if n%2==0:
    for i in range(len(c)):
        if c[i][0]==i*2+1 and c[i][1]==2:
            continue
        else:
            print(0)
            exit()
    ans=pow(2,n//2,mod)
    print(ans)

else:
    for i in range(len(c)):
        if i==0:
            if c[i][0]==0 and c[i][1]==1:
                continue
            else:
                print(0)
                exit()
        else:
            if c[i][0] == i * 2 and c[i][1] == 2:
                continue
            else:
                print(0)
                exit()
    ans=pow(2,n//2,mod)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
def main():
  N = int(input())
  A = [int(_) for _ in input().split()]
  MOD = 10 ** 9 + 7
  B = Counter(A)
  
  if N%2 == 0:
    for i in range(N):
      if (i%2 == 0 and B[i] == 0) or (i%2 == 1 and B[i] == 2):
        pass
      else:
        print(0)
        break
    else:
      print(pow(2, N//2, MOD))
  else:
    for i in range(N):
      if (i == 0 and B[i] == 1) or (i%2 == 0 and B[i] == 2) or (i%2 == 1 and B[i] == 0):
        pass
      else:
        print(0)
        break
    else:
      print(pow(2, N//2, MOD))
      
  return

if __name__ == '__main__':
  main()

Submission status: Accepted

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

icnt=[0]*n
for i in range(n):
    icnt[a[i]]+=1

yn=""
if n%2==0:
    for i in range(n):
        if i%2==0:
            if icnt[i]!=0:
                yn="NO"
                break
        else:
            if icnt[i]!=2:
                yn="NO"
                break
else:
    for i in range(n):
        if i==0:
            if icnt[i]!=1:
                yn="NO"
                break
        elif i%2==0:
            if icnt[i]!=2:
                yn="NO"
                break
        else:
            if icnt[i]!=0:
                yn="NO"
                break
if yn=="NO":
    print(0)
else:
    n2=n//2
    p=10**9+7
    print(pow(2,n2,p))

Submission status: Accepted

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

list_Counter = list(Counter(list_A).items())
ans = 1
list_Counter.sort(key=lambda x:x[0])

if n % 2 == 0:
    for i in range(n//2):
        l = list_Counter[i]
        if l[0] != 2*i + 1 or l[1] != 2:
            ans = -1

    if ans == -1:
        print(0)
    else:
        print((2**(n//2))%mod)
else:
    if list_Counter[0][0] == 0 and list_Counter[0][1] == 1:
        for i in range(1, n//2+1):
            l = list_Counter[i]
            if l[0] != 2*i or l[1] != 2:
                ans = -1
    else:
        ans = -1

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

Submission status: Accepted

Solution code:
from collections import Counter


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

C = Counter(A)

isAble = True
k = N - 1
while k >= 0:
    if k == 0:
        if C[k] != 1:
            isAble = False
    else:
        if C[k] != 2:
            isAble = False
    k -= 2

if isAble:
    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()))
if n%2==0:
  b=sorted([2*i+1 for i in range((n+1)//2)]*2)
else:
  b=sorted([2*i for i in range(1,(n+1)//2)]*2+[0])

if sorted(a)!=b:
  ans=0
else:
  ans=2**(n//2)
print(ans%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import Counter


def main():

    N = int(input())
    A = list(map(int, input().split()))
    arr = [abs(i - (N - i - 1)) for i in range(N)]
    result = 0
    mod = 10**9 + 7

    if Counter(A) == Counter(arr):
        result = (2**(N // 2)) % mod

    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import io

data = int(input())
array = list(map(int,input().split()))
array.sort()
modulus = 10**9 + 7
result = (2 ** (data // 2)) % modulus
array2 = []
for i in range(data):
  array2 += [abs(data+1-2*(i+1))]
array2.sort()
if array == array2 :
  print(result)
else:
  print(0)

Submission status: Accepted

Solution code:
N = int(input())
nums = [int(e) for e in input().split()]
nums.sort()
t=1
ans = 1
t = 10**9
t+=7
i=1
k=0
if(N%2)==1:
    if(nums.count(0) == 1):
        while(i<N):
            if nums[i] == nums[i+1]:
                i+=2
                ans = (ans *2)%t
                continue
            else:
                print('0')
                break
        else:
            print(ans)
    else:
        print('0')
else:
    while(k<N):
        if nums[k] == nums[k+1]:
            k += 2
            ans = (ans * 2)%t
            continue
        else:
            print('0')
            break
    else:
        print(ans)

Submission status: Accepted

Solution code:
N = int(input())
o, h = N%2, N//2
arr = [0]*h
for a in map(int, input().split()):
    if a > 0:
        arr[a//2 - o] += 1
if all(c == 2 for c in arr):
    print((1 << h) % (10**9 + 7))
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
d = {}
for i in a:
  if ((i+n)%2 == 0) and (i != 0):
    print(0)
    exit()
  if i in d:
    d[i] += 1
    if (d[i] == 3) or (i == 0):
      print(0)
      exit()
  else:
    d[i] = 1
ans = 1
for i in list(d.values()):
  ans *= i
print(ans%1000000007)

Submission status: Accepted

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