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 sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
# 20:16
N = INT()
A = LIST()
 
flag = True
# A.sort()
 
# dic = {}
dic = defaultdict(int)
for i in range(N):
    if not A[i] in dic:
        dic[A[i]] = 1
    else:
        dic[A[i]] += 1
s = sum(A)
 
 
if N % 2 == 1:
    for i in range(N):
        if i == 0:
            if dic[i] != 1:
                flag = False
        elif i % 2 == 0:
            if dic[i] != 2:
                flag = False
        else:
            if dic[i] != 0:
                flag = False
        # elif dic[i * 2] != 2:
        #     flag = False
    if flag == False:
        print(0)
    else:
        if N == 1:
            print(1)
        else:
            print(2 ** ((N) // 2) % mod)
 
else:
    for i in range(N):
        if (i - 1) % 2 == 0:
            if dic[i] != 2:
                flag = False
        else:
            if dic[i] != 0:
                flag = False
    if flag == False:
        print(0)
    else:
        print(2 ** (N//2) % mod)
 
 
 
 
 
 
        
 
 
    # c = Counter(A)
    # c = sorted(c.items(), key=lambda x: x[0], reverse = False)
    # if c[0][1] != 1:
        # print(0)
    # for i in c[1:]:
        # if c[0]

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# 20:16
N = INT()
A = LIST()

dic = {}
for i in range(N):
    if not A[i] in dic:
        dic[A[i]] = 1
    else:
        dic[A[i]] += 1

if N % 2 == 0:
    # even
    # N = 8
    for i in range(N//2):
        #4 (0, 1, 2, 3)
        if N - 1 - 2 * i not in dic:
            # 7, 5, 3, 1
            # なければでる
            print(0)
            # exit()
            break
        elif dic[N-1-2*i] != 2:
            print(0)
            break
        else:
            pass
    else:
        print(2 ** (N // 2) % mod)
else:
    if A.count(0) != 1:
        print(0)
        # exit()
    else:
        # N = 5
        for i in range(N//2):
            # 2, (0, 1)
            if N - 1 - 2 * i not in dic:
                print(0)
                break
            elif dic[N-1-2*i] != 2:
                print(0)
                break
            else:
                pass
        else:
            print(2 ** (N // 2) % mod)



exit()


flag = True
if N % 2 == 1:
    for i in range((N+1) // 2):
        if i == 0:
            if A.count(i) != 1:
                flag = False
        elif A.count(i * 2) != 2:
            flag = False
    if flag == False:
        print(0)
        exit()
    else:
        print(2 ** ((N-1) // 2))
else:
    for i in range(N // 2):
        if A.count(2 * i + 1) != 2:
            flag = False
    if flag == False:
        print(0)
    else:
        print(2 ** (N//2))

Submission status: Accepted

Solution code:
n = int(input())
MOD = 10 ** 9 + 7

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

if n % 2 == 1:
    for i in range(n):
        if i % 2 == 1 and a[i] - 1 == i: continue
        elif i % 2 == 0 and a[i] == i: continue
        else: 
            print(0)
            exit()
else:
    for i in range(n):
        if i % 2 == 1 and a[i] == i: continue
        elif i % 2 == 0 and a[i] - 1 == i: continue
        else: 
            print(0)
            exit()

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

Submission status: Accepted

Solution code:
n = int(input())
MOD = 10 ** 9 + 7

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

if n % 2 == 1:
    l = (n + 1) * (n - 1)
else:
    l = n ** 2

if sum(a) == l // 2:
    print(2 ** (n//2) % MOD)
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
if n % 2 == 0:
    l = n ** 2
else:
    l = (n - 1) * (n + 1)
if sum(A) == l // 2:
    print(2 ** (n // 2) % (10 ** 9 + 7))
else:
    print(0)

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    MOD = 10**9+7
    S = list(map(int, input().split()))

    if n % 2 == 0:
        sn = (1 + (n-1)) * (n // 2)
    else:
        sn = (2 + (n-1)) * (n//2)

    ss = sum(S)

    print((2**(n//2))%MOD if ss == sn else 0)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    ans=1
    A.sort()
    L=[]
    if N%2==1:
        L.append(0)
        for i in range(N//2):
            for _ in range(2):
                L.append(2*(i+1))
                
    else:
        for i in range(N//2):
            for _ in range(2):
                L.append(2*i+1)
                
    if L==A:
        ans=pow(2,N//2,mod)
    else:
        ans=0
        
    print(ans)
        

main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    S = list(map(int, input().split()))
    if n % 2 == 0:
        sum_a = (1 + max(S)) * (n // 2)
    else:
        sum_a = (2 + max(S)) * (n // 2)
    if sum(S) == sum_a:
        ans = pow(2, n // 2, (10 ** 9 + 7))
    else:
        ans = 0

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
mod = 10**9+7
N = int(input())
A = [int(i) for i in input().split()]
if N % 2 == 1:
    import collections
    c = collections.Counter(A)
    for i in range(N):
        if i % 2 == 1:
            continue
        if i == 0:
            if c[i] != 1:
                print(0)
                exit()
        else:
            if c[i] != 2:
                print(0)
                exit()
if N % 2 == 0:
    import collections
    c = collections.Counter(A)
    for i in range(1,N):
        if i % 2 == 0:
            continue
        if c[i] != 2:
            print(0)
            exit()
def pow_k(a,n,mod):
    if n == 0:
        return 1
    if n % 2 ==0:
        return pow_k(a*a % mod,n//2,mod)
    else:
        return a * pow_k(a,n-1,mod) % mod
if N % 2 == 1:
    N -=1
print(pow_k(2,N//2,mod))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC050

n = int(input())
a = sorted(list(map(int,input().split())))
p = 10 ** 9 + 7
l_odd = sorted([2*i-1 for i in range(1,n//2+1)]*2)
l_even = [0]+sorted([2*i for i in range(1,n//2+1)]*2)
#print(l_odd) if n % 2 == 0 else print(l_even)

if (n % 2 != 0 and a == l_even) or (n % 2 == 0 and a == l_odd):
    print(2**(n//2)%p)
else:
    print(0)

Submission status: Accepted

Solution code:
import numpy as np

div = 10**9 + 7

def Mod_Pow(a,n,mod):
    res = 1
    while (n > 0):
        if (n & 1):
            res = (res * a )% mod
        a = (a * a)% mod
        n >>= 1
    
    return res

def CountFrequency(my_list): 
  
    # Creating an empty dictionary  
    freq = {} 
    count_0 = 0
    for item in my_list: 
        if (item in freq): 
            freq[item] += 1
        else:             
            if item ==0:
                count_0+=1
            else:
                freq[item] = 1
    if N%2==0:
        return freq
    else:
        return freq, count_0

N = int(input())

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

if N%2 == 0:
    if all([ i ==2 for i in CountFrequency(A).values()]):
        ans = Mod_Pow(2,int(N/2),div)
    else:
        ans =0
    
            
else:
    count_0 = CountFrequency(A)[1]
    
    count_1 = list(CountFrequency(A)[0].values())
    if all([ i ==2 for i in count_1]) & (count_0 ==1):
        ans = Mod_Pow(2,int(N/2),div)
    else:
        ans =0
    
    
            
print(ans)

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 a in A if a==0])!=1 or len(set(A))!=N//2+1:flag=False
if flag:print(2**(N//2)%(10**9+7))
else:print(0)

Submission status: Accepted

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

def po2(x) :
    ans = 1
    for i in range(x) :
        ans = (ans*2)%mod
    return ans

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

A.sort()
B.sort()

if A != B :
    print(0)
else :
    print(po2(N//2))

Submission status: Accepted

Solution code:
def get_pow(x, n):
    if n == 0:
        return 1
    ans = get_pow(x * x % 1000000007, int(n / 2))
    if n % 2 == 1:
        ans *= x
        ans %= 1000000007
    return ans

n = int(input())
a = list(map(int, input().split()))
c = [2] * ((n + 1) // 2)
if n % 2 == 1:
    c[0] = 1
for i in a:
    c[i // 2] -= 1
if c == [0] * len(c):
    print(get_pow(2, n // 2))
else:
    print(0)

Submission status: Accepted

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

N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
#-----

A_list.sort()

# Check Reports(Ai) that is correct or not.
if N%2 == 0:
    i=0
    for x in range(int(N/2)):
        if A_list[i] == A_list[i+1] == 2*x + 1:
            i += 2
            continue
        else:
            #NG
            print("0")
            sys.exit()

elif N%2 == 1:
    i=0
    for x in range( int((N-1)/2) ):
        if i == 0 and A_list[i] == 0:
            i += 1
            continue
        elif A_list[i] == A_list[i+1] == 2*x:
            i += 2
            continue
        else:
            #NG
            print("0")
            sys.exit()

# Calculate Order
order = 1
for i in range(N//2):
    order = order * 2 % (10**9 + 7)

print(order)

Submission status: Accepted

Solution code:
mod = 10 ** 9 + 7
n = int(input())
a_i = list(map(int, input().split()))
a_i.sort()
ans = 1
if max(a_i) >= n: ans = 0
else:
    for x in range(n //2):
        if n % 2 == 0:
            if a_i[2 * x] != 2 * x + 1 or a_i[2 * x + 1] != 2 * x + 1: ans = 0
            else: 
                ans *= 2
                ans = ans % mod
        elif a_i[0] == 0 and n % 2 != 0:
            if a_i[2 * (x + 1) - 1] != 2 * (x + 1) or a_i[2 * (x + 1)] != 2 * (x + 1): ans = 0
            else: 
                ans *= 2
                ans = ans % mod
        else: ans = 0
print(ans % mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    n=int(readline())
    ai=list(map(int, readline().split()))

    x=[0]*(10**5+1)
    for a in ai:
        x[a]+=1
    
    k=n-1
    x2=0
    while k>=0:
        if k==0 and x[k]==1:
            x2+=0
        elif x[k]==2:
            x2+=1
        else:
            print(0)
            return
        k-=2
    
    print(pow(2,x2,10**9+7))
resolve()

Submission status: Accepted

Solution code:
import math
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 a in A if a==0])!=1 or len(set(A))!=N//2+1:flag=False
if flag:print(2**(N//2)%(10**9+7))
else:print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
numlist=list(map(int,input().split()))
num=[]
for i in range(n):
  num.append(0)
count=0
for i in numlist:
  num[i]+=1
  if num[i]==3:
    count=-1
    break
  elif i==0 and num[0]==2:
    count=-1
    break
  else:
    pass
if count==-1:
  print(0)
else:
  count=2**(n//2)
  count=count%(10**9+7)
  print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc050/tasks/arc066_a
# 並び方がありうるかの判別は簡単で、Nが偶数なら、Aがすべて奇数かつすべての数が2回ずつ出現する
# 奇数なら、Aが全て偶数で、0だけ1回出現しほかは2回ずつ出現する。

# ありえるならば、N&1→ 2**(N//2)が答え
# N&1 =0→ 2**(N//2)が答え
# どちらも同じ式でOK
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


N = read_a_int()
A = read_ints()

from collections import Counter
A_cnt = Counter(A)


def end():
    print(0)
    exit()


if N & 1:
    if A_cnt[0] != 1:
        end()
    for i in range(2, N, 2):
        if A_cnt[i] != 2:
            end()
else:
    for i in range(1, N, 2):
        if A_cnt[i] != 2:
            end()

print(pow(2, N // 2, 10**9 + 7))

Submission status: Accepted

Solution code:
def main():
    people_num = int(input())
    information = sorted(list(map(int, input().split())))
    unique = len(set(information))
    answer = 0
    if unique * 2 == people_num + people_num % 2:
        if people_num > 1 and information[1] > 0:
            answer = 2 ** (unique - people_num % 2)
        elif people_num == 1 and information[0] == 0:
            answer = 1
    print(answer % (10 ** 9 + 7))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import collections
N = int(input())
A = list(map(int,input().split()))
A.sort()
mod = 10 ** 9 + 7
Flg = True
if N % 2 == 1:
    a = A.pop(0)
    if a != 0:
        Flg = False

k = (N % 2) + 1
for i in range(N //2):
    if A[i *2] != k or A[i * 2 + 1] != k:
        Flg = False
    k += 2
    
if Flg:
    ans = (2 ** (N // 2)) % mod
else:
    ans = 0
    
print(ans)

Submission status: Accepted

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

MOD=10**9+7
flg=True
k=1

if N%2==1:
    k=2
    a=A.pop(0)
    if a!=0:
        flg=False
        
for i in range(N//2):
    if A[i*2]!=k or A[i*2+1]!=k:
        flg=False
    k+=2
    
if flg:
    ans=1
    for i in range(N//2):
        ans*=2
        ans=ans%MOD
else:
    ans=0

print(ans)

Submission status: Accepted

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

if n % 2 == 0:
    for k,v in a.items():
        if v != 2:
            print(0)
            sys.exit()

else:
    for k,v in a.items():
        if k == 0:
            if v != 1:
                print(0)
                sys.exit(0)
        else:
            if v != 2:
                print(0)
                sys.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()))
mod = 10**9 + 7
cnt = defaultdict(int)

for i in a:
    cnt[i] += 1

ans = 1
if n % 2 == 0:
    for _ in range(n // 2):
        ans *= 2
        ans %= mod
    if cnt[0] == 0:
        check = [2 * i + 1 for i in range(n // 2)]
        for i in check:
            if cnt[i] != 2:
                ans = 0
                break
    else:
        ans = 0

else:
    for _ in range((n-1)//2):
        ans *= 2
        ans %= mod
    if cnt[0] == 1:
        check = [2 * i + 2 for i in range((n-1)//2)]
        for i in check:
            if cnt[i] != 2:
                ans = 0
                break

    else:
        ans = 0

print(ans)

Submission status: Accepted

Solution code:
MOD=1000000007
def modpow(a,n,mod):
    res=1
    a=a%mod
    while(n>0):
        if(n&1):
            res=res*a%mod
        a=a*a%mod
        n>>=1
    return res

N=int(input())
A=list(map(int,input().split()))
cnt=[0]*100001
for i in range(N):
    cnt[A[i]]+=1
if(N%2==1):
    if(cnt[0]!=1):
        print(0)
        exit()
    for i in range(2,N,2):
        if(cnt[i]!=2):
            print(0)
            exit()
elif(N%2==0):
    for i in range(1,N,2):
        if(cnt[i]!=2):
            print(0)
            exit()
print(modpow(2,N//2,MOD))

Submission status: Accepted

Solution code:

def mod_(b, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * b % mod
        b = b * b % mod
        n >>= 1
    return int(res)

def main():

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

    n = ((N+1) >> 1)
    li = [0]*n



    for a in A:
        li[a >> 1] += 1

    if N & 1:
        if li[0] != 1:
            print(0)
        elif li.count(2) != n-1:
            print(0)
        else:
            c = n-1
            print(2 ** c % (10**9+7))
    else:
        if li.count(2) != n:
            print(0)
        else:
            c = n
            print(2 ** c % (10**9+7))

main()

Submission status: Accepted

Solution code:
import numpy as np

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

if len(A)%2 == 0:
    result = (2**(len(A)//2))%(10**9+7)
    a = np.arange(1, len(A), 2).tolist()
    a = sorted(a+a)
    if a == A:
        pass
    else:
        result = 0
else:
    result = 2**(len(A)//2)%(10**9+7)
    a = np.arange(2, len(A), 2).tolist()
    a = sorted([0]+a+a)
    if a == A:
        pass
    else:
        result = 0
print(result)

Submission status: Accepted

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

f = 1

if n%2 == 0:
    ans = [2]*(n//2)
    #print(ans)
    for i in range(n):
        if a[i]%2 == 0:
            f = 0
            break
        x = a[i]//2
        ans[x] -= 1

else:
    ans = [2]*((n+1)//2)
    ans[0] -= 1
    for i in range(n):
        if a[i]%2 != 0:
            f = 0
            break
        x = a[i]//2
        ans[x] -= 1

for i in range(len(ans)):
    if ans[i] != 0:
        f = 0
        break

if f == 0:
    print(f)
else:
    print((2**(n//2))%1000000007)

Submission status: Accepted

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

    if n%2==1:
        if 0 not in a:
            print(0)
            exit()
        else:
            if a[0]!=1:
                print(0)
                exit()
            else:
                a[0]=2
    
    for k,v in a.items():
        if v!=2 or (n-k-1)%2==1:
            print(0)
            exit()
            
    print(2**(n//2)%mod)  
if __name__=='__main__':
    main()

Submission status: Accepted

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

    numlist = dict()

    if n % 2 == 1:
        for i in range(0, n+1, 2):
            numlist[i] = []
    else:
        for i in range(1, n+1, 2):
            numlist[i] = []

    for aa in a:
        if aa not in numlist.keys():
            print('0')
            exit()
        numlist[aa].append(aa)

    for num in numlist:
        if num == 0 and len(numlist[num]) != 1:
            print('0')
            exit()
        elif num == 0 and len(numlist[num]) == 1:
            continue
        elif len(numlist[num]) != 2:
            print('0')
            exit()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if n%2 == 1:
    m = (n+1)//2
    l =[0]*m
    for i in range(n):
        if (n-A[i]-1)%2 != 0:
            print(0)
            exit()
        else:
            id = (n-A[i]-1)//2
            l[id] += 1
    #print(l)
    ans = 1
    for i in range(m):
        #print(i, ans)
        if i != m -1:
            if l[i] != 2:
                print(0)
                exit()
            else:
                ans *= l[i]
                ans %= mod
        else:
            if l[i] != 1:
                print(0)
                exit()
            else:
                ans *= l[i]
                ans %= mod
    print(ans)

else:
    m = n//2
    l =[0]*m
    for i in range(n):
        if (n-A[i]-1)%2 != 0:
            print(0)
            exit()
        else:
            id = (n-A[i]-1)//2
            l[id] += 1
    #print(l)
    ans = 1
    for i in range(m):
        #print(i, ans)
        if l[i] != 2:
            print(0)
            exit()
        else:
            ans *= l[i]
            ans %= mod
    print(ans)

Submission status: Accepted

Solution code:
import math
import sys

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

li = [0] * N
count = 0

if N % 2 == 0:
  t = 1
else:
  t = 0

for a in A:
  if a == 0:
    li[math.floor((N-1)/2)] += 1
    count += 1
    
    if count == 2:
      print(0)
      sys.exit()

    continue

  li[math.floor((N-1)/2)-math.floor(a/2)] += 1
  li[math.floor((N-1)/2)+math.floor(a/2)+t] += 1

ans = 1

for i in range(0, math.floor(N/2)):
  ans *= li[i]

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

Submission status: Accepted

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

from collections import Counter
C = Counter(A)
if len(A)%2 == 0:
  for k, v in C.items():
    if v != 2:
      print(0)
      exit()
else:
  for k, v in C.items():
    if k == 0:
      if v != 1:
        print(0)
        exit()
    else:
      if v!=2:
        print(0)
        exit()

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

Submission status: Accepted

Solution code:
from collections import defaultdict
count=defaultdict(lambda:0)
N=int(input())
A=list(input().split(" "))
k=-1
for i in range(N):
    count[A[i]]+=1
if N%2==1:
    if count["0"]!=1:
        k=0
    for i in range(1,N//2+1):
        if count[str(2*i)]!=2:
            k=0
else:
    for i in range(1,N//2+1):
        if count[str(2*i-1)]!=2:
            k=0
if k!=0:
    if N%2==0:
        print(2**(len(count.keys()))%(10**9+7))
    else:
        print(2**(len(count.keys())-1)%(10**9+7))
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
r = n%2

d = [0]*n
for a in A:
    if a%2 == r:
        print(0)
        break
    d[a] += 1
    if (d[a] > 2) or (a == 0 and d[0] > 1):
        print(0)
        break
else:
    print(2**(n//2) % (10**9+7))

Submission status: Accepted

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

MOD=10**9+7

if N%2:
    arr=sorted([0]+list(range(2,N))[::2]*2)
else:
    arr=sorted(list(range(1,N))[::2]*2)

print(2**(N//2)%MOD if A == arr else 0)

Submission status: Accepted

Solution code:
from itertools import groupby


def main():
    n = int(input())
    xs = sorted(list(map(int, input().split())))

    if n == 1:
        if xs[0] == 0:
            print(1)
        else:
            print(0)
        return

    xxs = [list(it) for k, it in groupby(xs)]

    if len([xs for xs in xxs if len(xs) != 2 and xs[0] != 0]) > 0:
        print(0)
        return

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


main()

Submission status: Accepted

Solution code:
import collections
n = int(input())
dat = list(map(int, input().split()))
dat.sort()
f = True
if n % 2 == 0: # 偶数
    for i in range(n):
        if dat[i] != 2 * (i // 2) + 1:
            f = False
    if f:
        print(2 ** (n // 2) % (1000000000+7) )
else: # 奇数
    if dat[0] != 0:
        f = False
    for i in range(n - 1):
        if dat[i + 1] != 2 * (i//2 + 1):
            f = False
    if f:
        print(2** (n //2 ) % (1000000000+7) )
if f is False:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
judge = 1
while 0 in A:
    A.remove(0)

A_ = list(set(A))
A_.sort()
for i in range(len(A_) - 1):
    if A_[i+1] == A_[i]+2:
        judge = 1
    else:
        judge = 0

if len(set(A)) == len(A)/2 and judge:
    print((2 ** (len(A) // 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 == 0:
    a_l = a[0::2]
    a_r = a[1::2]
    flag = True
    key = 1
    for i,j in zip(a_l,a_r):
        if i!=key or j!=key:
            flag = False
            break
        key += 2
    if flag:
        print(2**(n//2)%(10**9+7))
    else:
        print(0)
else:
    a_l = a[1::2]   #0を一つとばす
    a_r = a[2::2]
    flag = True
    key = 2
    for i,j in zip(a_l,a_r):
        if i!=key or j!=key:
            flag = False
            break
        key += 2
    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()))
B=[]
if N%2 ==0:
    for a in range(1, N, 2):
        B.append(a)
    B+=B
    if sorted(A) == sorted(B):
        print(2**len(set(A))%(10**9+7))
    else:
        print(0)
else:
    for a in range(2, N, 2):
        B.append(a)
    B=B+B+[0]
    if sorted(A) == sorted(B):
        print(2**(len(set(A))-1)%(10**9+7))
    else:
        print(0)