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:
def even_case(input_list) -> int:
    input_list.sort()

    if input_list[0] == 0: return 0


    for i in range(1, len(input_list), 2):
        if input_list[i] % 2 == 0 or input_list[i] != input_list[i-1]:
            return 0

    ans = 2 ** (n//2)

    return ans


def odd_case(input_list) -> int:
    input_list.sort()

    if input_list[0] != 0: return 0

    if len(input_list) == 1: return 1

    if input_list[1] == 0: return 0

    for i in range(2, len(input_list), 2):
        if input_list[i] % 2 == 1 or input_list[i] != input_list[i-1]:
            return 0

    ans = 2 ** ((n-1) // 2)

    return ans

n = int(input())
input_list = list(map(int, input().split()))
math = 10 ** 9 + 7

if n % 2 == 0:
    result = even_case(input_list)
else:
    result = odd_case(input_list)

print(result % math)

Submission status: Accepted

Solution code:
n=int(input())
numbb=input().split(' ')
numb=[]
for i in numbb:
    numb.append(int(i))
numb=sorted(numb)
#print(numb)
if(n==len(numb)):
    if(n%2!=0):
        temp=[]
        temp.append(0)
        strt=2
        for i in range(0,int(n/2)):
            temp.append(strt)
            temp.append(strt)
            strt+=2
        if(temp==numb):
            #print(temp,numb)
            print(pow(2,len(set(numb))-1)%(1000000007))
        else:
            print(0)
    if(n%2==0):
        temp=[]
        strt=1
        for i in range(0,int(n/2)):
            temp.append(strt)
            temp.append(strt)
            strt+=2
        if(temp==numb):
            #print(temp,numb)
            #print(pow(2,len(set(numb))))
            print((pow(2,len(set(numb)))%(1000000007)))
        else:
            print(0)

Submission status: Accepted

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

if N % 2: # 奇数の場合
    for i in range(0, N - 2, 2):
        if A[i] != i:
            isOK = False
            break
        if A[i + 1] != i + 2:
            isOK = False
            break
    if A[N - 1] != N - 1:
        isOK = False
    num = (N - 1) // 2
else: # 偶数の場合
    for i in range(0, N, 2):
        if A[i] != i + 1:
            isOK = False
            break
        if A[i + 1] != i + 1:
            isOK = False
            break
    num = N // 2

if isOK:
    ans = 1
    for _ in range(num):
        ans *= 2
        ans %= BIG_PRIME
    print(str(ans))
else:
    print("0")

Submission status: Accepted

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

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

from collections import Counter

for key,count in sorted(Counter(A).items(), key=lambda x:x[0]):
    if key == 0 and N % 2 == 1:
        continue
    if count == 2 and key % 2 != N % 2:
        continue
    print(0)
    exit()

if N % 2 == 1:
    N -= 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
L = list(map(int,input().split()))
L.sort()
mod = 10**9+7
if len(L)%2 == 0 and len(set(L))*2 == len(L):
    print(2**len(set(L))%mod)
elif len(L)%2 == 0 and len(set(L))*2 != len(L):
    print(0)
elif len(L)%2 == 1: 
    if L.count(0) == 1:
        L.pop(0)
        if len(set(L))*2 == len(L):
            print(2**(len(set(L)))%mod)
    else:
        print(0)

Submission status: Accepted

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

A.sort()
if N % 2 == 0:
    # print(A[0:N:2])
    # print(A[1:N+1:2])
    if A[0:N:2] != A[1:N+1:2]:
        print(0)
        exit(0)
else:
    if A[0] != 0:
        print(0)
        exit()
    if A[1:N-1:2] != A[2:N:2]:
        print(0)
        exit()

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1
mod=10**9+7
n=int(input())
A=list(map(int,input().split()))
C=collections.Counter(A)
if n%2==1:
    if C[0]!=1:
        print(0)
        exit()
    else:
        a=2
else:
    if C[1]!=2:
        print(0)
        exit()
    else:
        a=3
for i in range(a,n,2):
    if C[i]!=2:
        print(0)
        exit()
print(pow(2,n//2,mod))

Submission status: Accepted

Solution code:
import collections

N = int(input())

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

mod = 10**9+7

# 各数字の出現回数を調べる
c = collections.Counter(A)

# 可否判定
# 偶数ならすべての数字の出現回数が2である
# 奇数なら1つを除き、すべての数字の出現回数が2であり、1つの数字の出現回数が1である

if len(A) ==1 and A[0]==0:
    print(1)

elif len(A)%2==0:
    if list(c.values()).count(2) == (len(A) // 2 ):
        print(2**(len(c.values()))%mod)
    else:
        print(0)
else:
    if list(c.values()).count(2) == (len(A) // 2 ) and c[0] == 1:
        print((2**(len(c.values())-1))%mod)
    else:
        print(0)
    



# 数字のペア数の2乗が組み合わせ数

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter

MOD = 10 ** 9 + 7

n, *a = map(int, sys.stdin.read().split())

def main():
    c = Counter(a)
    if n & 1:
        if c.get(0, 0) != 1:
            return 0
    for i in range(1 + (n & 1), n, 2):
        if c.get(i, 0) != 2:
            return 0

    return pow(2, n // 2, MOD)
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

MOD = 10 ** 9 + 7

n, *a = map(int, sys.stdin.read().split())

def main():
    c = Counter(a)
    if n & 1:
        if c.get(0, 0) != 1:
            return 0
        for i in range(2, n, 2):
            if c.get(i, 0) != 2:
                return 0
    else:
        for i in range(1, n, 2):
            if c.get(i, 0) != 2:
                return 0

    return pow(2, n // 2, MOD)
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if n%2 == 0:
  l_ = [0]*(n//2)
  for i in range(n):
    l_[(n-(l[i])-1)//2] += 1
  for j in range(len(l_)):
    if l_[j] != 2:
      print(0)
      exit()
  else:
    print((2**(n//2))%(10**9+7))

else:
  l_ = [0]*(n//2+1)
  for i in range(n):
    l_[(n-(l[i])-1)//2] += 1
  for j in range(len(l_)):
    if j != len(l_)-1: 
      if l_[j] != 2:
        print(0)
        exit()
    else:
      if l_[j] != 1:
        print(0)
        exit()
  else:
    print((2**(n//2))%(10**9+7))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import math

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]
MOD = 10**9+7

N = INT()
A = MAP()

A.sort()
#print(A)

s = 0 if N%2 else 1
e = N if N%2 else N+1

for i in range(s, e):
	t = math.ceil(i/2)*2
	if not N%2: t -= 1
	if t != A[i-s]:
		print(0)
		break
else:
	print(2**(N//2)%MOD)

Submission status: Accepted

Solution code:
import math
import sys
import collections

n = int(input())
a = list(map(int, input().split()))
ans = 0
counts = collections.Counter(a)
mod = 10**9+7


if n % 2 == 1:
    # if counts[0] is None or counts[0] != 1:
    if counts[0] != 1:
        print(0)
        sys.exit()
    for i in range(2, n-1, 2):
        if counts[i] != 2:
            print(0)
            sys.exit()
else:
    for i in range(1, n-1, 2):
        if counts[i] != 2:
            print(0)
            sys.exit()

ans = 2**(n//2)

print(ans%mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

c=Counter(aa)

ans = 0
z_flag = False

if n%2 == 1:  
  if c[0] != 1:  
    z_flag = True    
else:
  if c[0] != 0:  
    z_flag = True    
    
ans = 1      
for k,v in c.items():
  if k==0:
    pass
  else:
    if v//2 != 1:
      z_flag = True
      break
    else:
      ans *= v      

if z_flag:
  ans = 0
  
print(ans % (10**9+7))

Submission status: Accepted

Solution code:
n=int(input())
import numpy as np
a=np.sort(np.array(input().split(),dtype=int))
DIV=10**9+7
if n%2==1:
  if a[0]!=0:
    print(0)
    exit(0)
  a=a[1:]
  a-=1    
for i in range(len(a)):
  if a[i]!=i+(i%2==0):
    print(0)
    exit(0)
print((2**(len(a)//2))%DIV)

Submission status: Accepted

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

DIV=10**9+7

if n%2==1:
  if a[0]!=0:
    print(0)
    exit(0)
  a=a[1:]
  for i in range(len(a)):
    a[i]=a[i]-1
    
for i in range(len(a)):
  if a[i]!=i+(i%2==0):
    print(0)
    exit(0)
    
print((2**(len(a)//2))%DIV)

Submission status: Accepted

Solution code:
from collections import defaultdict
INF = 10 ** 9 + 7
N = int(input())
a = list(map(int, input().split()))

d = defaultdict(int)
for key in a:
    d[key] += 1

sd = sorted(d.items(), key=lambda x: x[0])

if N % 2 == 0:
    if sd[0][1] == 1:
        print(0)
        exit()
else:
    if sd[0][1] != 1:
        print(0)
        exit()
ans = 1
for i in range(N // 2):
    ans *= 2
    ans %= INF

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import math
N = int(input())
A = list(map(int,input().split()))
A_count = Counter(A)
count_item = list(A_count.items())
count_item.sort()
start = 1 - (N % 2)
for i in range(math.ceil(N / 2)):
    if i == 0 and N % 2 == 1:
        if count_item[i][0] == 0 and count_item[i][1] != 1:
            print("0")
            exit()
    else:
        if count_item[i][0] != i * 2 + (1 - (N % 2)) or count_item[i][1] != 2:
            print("0")
            exit()
print(2 ** (N // 2) % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
import sys
from collections import Counter
n = int(input())
MOD = 10**9 + 7
a_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter(a_ls)
_sum = 0
res = 1
flg = (n + 1) % 2
if flg == 0:
    res = 0 if ct.get(0) != 1 else 1
for i in range(1, max(a_ls) + 1):
    if flg == i % 2:
        if ct.get(i) == 2:
            res = res * 2 % MOD
        else:
            res = 0
            break
    else:
        if ct.get(i) is None:
            continue
        else:
            res = 0
            break
    if res == 0:
        break
print(res)

Submission status: Accepted

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

for i in range(N):
  if A[i] != i + (i % 2 == N % 2):
    print(0)
    exit()

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
 
memo = {}
ans = 0
 
for a in A:
  v = str(a)
  if v in memo:
    memo[v] += 1
  else:
    memo[v] = 1

result = False
for key in memo.keys():
  if key == '0':
    if N%2 == 0:
      result=True
      break
    if memo[key] != 1:
      result=True
      break
  elif memo[key] != 2:
    result=True
    break
    
if not result:
  x = len(memo.keys())
  if N%2 != 0:
    x-=1
  ans = 2**x
  
div = 10**9 + 7
print(ans%div)

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect
import itertools


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    A = string_to_int(inputs[0])
    A.sort()
    apper = collections.Counter()

    for a in A:
        apper[a] += 1

    start = 1 if len(A) % 2 == 0 else 0
    for i in range(start, len(A), 2):
        if i not in apper:
            return 0
        if i == 0 and apper[0] != 1:
            return 0
        if i != 0 and apper[i] != 2:
            return 0
    if 0 in apper:
        apper.pop(0)

    return (2 ** len(apper)) % 1000000007


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

def possible():
    if N%2==0:
        for cnt in cnt_dict.values():
            if cnt != 2:
                return False
        return True
    else:
        for i, cnt in enumerate(cnt_dict.values()):
            if i==0:
                if cnt != 1:
                    return False
            else:
                if cnt != 2:
                    return False
        return True

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

cnt_dict = defaultdict(list)

if N%2==0:
    for i in range(1, N, 2):
        cnt_dict[i] = 0
else:
    for i in range(0, N, 2):
        cnt_dict[i] = 0
for a in A:
    if not(a in cnt_dict.keys()):
        flag=False
    else:
        cnt_dict[a]+=1
        flag=True

if __name__ == "__main__":    

    if possible() and flag:
        mod = 10**9+7
        res = 1
        for i in range(1, num+1):
            res = res*2%mod
        print(res)
    else:
        print(0)

Submission status: Accepted

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

a.sort()
if n % 2 == 0:
    for i in range(0, n, 2):
        if a[i] % 2 == 0:
            print(0)
            exit()
        elif a[i] != a[i+1]:
            print(0)
            exit()

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

num = n // 2
ans = (2 ** num) % 1000000007
print(ans)

Submission status: Accepted

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

    C = [0] * N
    for ai in A:
        C[ai] += 1
    # print(C)
    flag = True
    if N % 2 == 1:
        for i, n in enumerate(C):
            if i == 0:
                if n != 1:
                    flag = False
            elif i % 2 == 0:
                if n != 2:
                    flag = False
            else:  # 奇数の時
                if n != 0:
                    flag = False
        if not flag:
            ans = 0
        else:
            ans = 2 ** ((N - 1)//2)
    else:
        for i, n in enumerate(C):
            if i % 2 == 1:
                if n != 2:
                    flag = False
            else:
                if n != 0:
                    flag = False
        if not flag:
            ans = 0
        else:
            ans = 2 ** (N // 2)

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




if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
import math
from itertools import groupby

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li.sort()

if len(li) == 1:
    if li[0] != 0:
        print(0)
        exit()
    else:
        print(1)
        exit()

if li[0] == 0 and li[1] == 0:
    print(0)
    exit()
    
lin = []
for key, value in groupby(li):
    lin.append(len(list(value)))

point = 1

for i in lin:
    if i >= 3:
        print(0)
        exit()
    point *= math.factorial(i)
    point %= 10**9+7

print(point)

Submission status: Accepted

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

flag = False
ans = 0
b = [0] * n

# 報告があっているか
if n % 2 == 0:
    for i in range(0, n, 2):
        b[i] = i + 1
        b[i + 1] = i + 1
else:
    for i in range(1, n, 2):
        b[i] = i + 1
        b[i + 1] = i + 1

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
judge=True
if n%2!=0:#奇数のとき
	if a[0]==0:
		for i in range(1,n//2+1):
			if a[i*2-1]!=i*2 or a[i*2]!=i*2:
				judge=False
				break
	else:
		judge=False
	if judge:
		ans=2**(n//2)
	else:
		ans=0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC050 C - Lining Up
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
a.sort()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
a = Counter([int(i) for i in input().split()])

res = 2 ** (n // 2)
res %= 10**9 + 7

if n % 2 == 1:
    if 0 not in a:
        res = 0
    elif a[0] != 1:
        res = 0
    for i in range(2, n, 2):
        if a[i] != 2:
            res = 0
else:
    for i in range(1, n, 2):
        if a[i] != 2:
            res = 0

print(res)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
#まずaの条件がありうるかを判定する。

def kaijo(n):
  temp=1
  for i in range(n):
    temp*=2
    temp%=mod
  return temp

#nが奇数の場合…
if n%2:
  ki=[0]*((n+1)//2)
  for i in a:
    if i==0: #0の場合は2個なので2を足す
      ki[0]+=2
    elif i%2==0: #ちゃんと偶数かを判定
      ki[i//2]+=1
  if len(set(ki))==1:
    print(kaijo((n-1)//2))
  else:
    print(0)
else:
  ki=[0]*(n//2)
  for i in a:
    if i%2: #ちゃんと奇数かを判定
      ki[i//2]+=1
  if len(set(ki))==1:
    print(kaijo((n//2)))
  else:
    print(0)

Submission status: Accepted

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

#列を組める条件は、
#N=奇数: 0が1人、2,4,..len(N)-1 が2人ずつ
#N=偶数: 1,3,..len(N)-1 が2人ずつ
#想定される数列と同様のものを作成して、イコールかどうかを確認する

#それぞれの番号持ちは場所を入れ替えることができるので、(0より大きい数の個数**2)%(10**9 + 7)が答え

def check(L):
    if len(L) % 2 == 1:
        C = [x for x in range(2,len(L), 2)]*2 + [0]
        C = sorted(C)
        if L == C:
            return True
        else:
            return False
    elif len(L) % 2 == 0:
        C = [x for x in range(1,len(L), 2)]*2
        C = sorted(C)
        if L == C:
            return True
        else:
            return False

if check(A) == True:
    ans = (2 ** (len(A)//2)) % (10**9 + 7)
else:
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a_sorted = sorted(a)
b_sorted = sorted([abs(i) for i in range(-(n - 1), n, 2)])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    Ai = tuple(map(int, input().split()))
    P = 10**9 + 7

    # print(N)
    # print(Ai)

    lis = []
    if N % 2 == 0:
        for i in range(1, N, 2):
            lis.append(i)
            lis.append(i)
        # print(lis)
    else:
        lis.append(0)
        for i in range(2, N, 2):
            lis.append(i)
            lis.append(i)
        # print(lis)

    if not (len(Ai) == len(lis) and sorted(Ai) == sorted(lis)):
        return 0

    if N % 2 == 0:
        return pow(2, len(lis) // 2, P)
    else:
        return pow(2, (len(lis) - 1) // 2, P)


if __name__ == '__main__':
    res = solve()
    print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#C
import math
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
A.sort()
if N%2 == 0:
    n = N//2
    flag = 0
    for i in range(N):
        I = i//2 * 2 + 1
        if A[i] != I:
            flag = 1
            break
    if flag == 1:
        print(0)
    else:
        print(2**n%mod)
    
else:
    n = N//2
    flag = 0
    for i in range(N):
        if i == 0:
            if A[0] != 0:
                flag = 1
                break
        else:
            I = (i+1)//2 * 2
            if A[i] != I:
                flag = 1
                break
    if flag == 1:
        print(0)
    else:
        print(2**n%mod)

Submission status: Accepted

Solution code:
import collections
n=int(input())
a=[int(i) for i in input().split()]
def is_even(n):
    if(n%2==0):
        even=True
    else:
        even=False
    return even

c = collections.Counter(a)
ans=1
if(is_even(n)==True):
    for num,count in c.items():
        if(is_even(num)==True):
            print(0)
            exit()
        if(count>=3):
            print(0)
            exit()
        ans*=2
else:
    for num,count in c.items():
        if(is_even(num)==False):
            print(0)
            exit()
        if(count>=3):
            print(0)
            exit()
        if(count>=2 and num==0):
            print(0)
            exit()
        if(num!=0):
            ans*=2
print(ans%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

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

def two_n (n):
    mod = 10**9 + 7
    ret = 1
    for _ in range(n):
        ret *= 2
        ret %= mod
    return ret

bl = [0 for _ in range(n)]
for aa in a:
    bl[aa] += 1

report = True

if n % 2 == 0:
    for i in range(n):
        if i % 2 == 1 and bl[i] != 2:
            report = False
            break
        elif i % 2 == 0 and bl[i] != 0:
            report = False
            break
    
elif n % 2 == 1:
    for i in range(n):
        if i % 2 == 1 and bl[i] != 0:
            report = False
            break
        elif i % 2 == 0 and i > 0 and bl[i] != 2:
            report = False
            break
        elif i == 0 and bl[i] != 1:
            report = False

if report:
    print(two_n(n//2))
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
mod = 10**9 + 7
from collections import Counter

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

c = Counter(A)
ans = 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()
        ans *= 2
        ans %= mod
else:
    for i in range(1, N, 2):
        if c[i] != 2:
            print(0)
            exit()
        ans *= 2
        ans %= mod

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!python3.4.3

n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
# a_list.sort()

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

Submission status: Accepted

Solution code:
import collections

N = int(input())
A = list(map(int, input().split()))
counter = collections.Counter(A)
flag = True

if N % 2 != 0:
    for i in range(0, max(A) + 1):
        if i == 0:
            if counter[i] != 1:
                flag = False
                break
        elif (i % 2 == 0 and counter[i] != 2) or (i % 2 != 0 and counter[i] != 0):
            flag = False
            break                
    ans = 2 ** (max(A) // 2) % (10**9 + 7)

else:
    for i in range(0, max(A) + 1):
        if (i % 2 == 0 and counter[i] != 0) or (i % 2 != 0 and counter[i] != 2):
            flag = False
            break
    ans = 2 ** (max(A) // 2 + 1) % (10**9 + 7)

if flag:
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
d = {}
if N % 2 == 0:
    for i in range(N//2):
        d[2*i+1] = 0
else:
    for i in range(N//2+1):
        d[2*i] = 0
A = list(map(int,input().split()))
x = 1
for i in range(N):
    if A[i] in d:
        if d[A[i]] >= 2:
            x = 0
            break
        else:
            d[A[i]] += 1
    else:
        x = 0
        break
y = 1
if N % 2 == 1:
    if d[0] != 1:
        y = 0
e = 10**9 + 7
ans = (2**(N//2))*x*y%e
print(ans)