Problem:


Score : 300 points

Problem Statement

There are N people, conveniently numbered 1 through N.
They were standing in a row yesterday, but now they are unsure of the order in which they were standing.
However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person.
According to their reports, the difference above for person i is A_i.

Based on these reports, find the number of the possible orders in which they were standing.
Since it can be extremely large, print the answer modulo 10^9+7.
Note that the reports may be incorrect and thus there may be no consistent order.
In such a case, print 0.

Constraints

1≦N≦10^5

0≦A_i≦N-1

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the number of the possible orders in which they were standing, modulo 10^9+7.

Sample Input 1

5
2 4 4 0 2

Sample Output 1

4

There are four possible orders, as follows:

2,1,4,5,3

2,5,4,1,3

3,1,4,5,2

3,5,4,1,2

Sample Input 2

7
6 4 0 2 4 0 2

Sample Output 2

0

Any order would be inconsistent with the reports, thus the answer is 0.

Sample Input 3

8
7 5 1 1 7 3 5 3

Sample Output 3

16



Sample input:
5
2 4 4 0 2


Sample output:
4

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
a=sorted(a)
cnt=0
if len(a)%2==0:
  for i in range(1,len(a),2):
    if [i,i]==a[i-1:i+1]:
      cnt+=1
    else:
      cnt=-10**5-1
else:
  if a[0]==0:
    for i in range(2,len(a),2):
      if [i,i]==a[i-1:i+1]:
        cnt+=1
      else:
        cnt=-10**5-1
  else:
    cnt=-10**5-1
print((2**cnt)%(10**9+7) if cnt>=0 else 0)

Submission status: Accepted

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

from collections import Counter
MOD = 10**9 + 7
c = Counter(a)

ans = 0

if n % 2 == 1:
    for i in range(2, n, 2):
        if c[i] != 2:
            print(0)
            exit()
    if c[0] == 1:
        ans = pow(2, n // 2, MOD)
else:
    for i in range(1, n, 2):
        if c[i] != 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()))

from collections import Counter
MOD = 10**9 + 7
c = Counter(a)

ans = 0

if n % 2 == 1:
    for i in range(2, n, 2):
        if c[i] != 2:
            print(0)
            exit()
    if c[0] == 1:
        ans = pow(2, n // 2, MOD)
else:
    for i in range(1, n, 2):
        if c[i] != 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()
import sys, copy, math, heapq, bisect
from itertools import accumulate
from collections import deque, defaultdict, Counter
input = sys.stdin.readline # 文字列の入力のとき'/n'まで受け取るので注意!!!
sys.setrecursionlimit(500000)
mod = 10**9+7
D = Counter(A)
if N%2==0:
    ans = 1
    for i,k in enumerate(D.keys()):
        if D[k]==2:
            ans = ans*2%mod
        else:
            ans = 0
            break
    print(ans)


else:
    ans = 1
    for i,k in enumerate(D.keys()):
        if i==0 and D[k]==1:
            continue
        elif i==0:
            ans = 0
            break
        elif D[k]==2:
            ans = ans*2%mod
        else:
            ans = 0
            break
    print(ans)

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
from collections import Counter, deque
import itertools
#from scipy.misc import comb

MOD = 10**9+7

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

c = sorted(list(Counter(A).items()))

ans = 1
if N%2 == 1:
    for i in range(len(c)):
        if i==0:
            if c[i][0] == 0 and c[i][1] == 1:
                ans = 1
            else:
                ans = 0
        else:
            if c[i][0] == i*2 and c[i][1] == 2:
                ans *= 2
                ans %= MOD
            else:
                ans = 0
else:
    for i in range(len(c)):
        if c[i][0] == i*2+1 and c[i][1] == 2:
            ans *= 2
            ans %= MOD
        else:
            ans = 0

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[0] != 1:
      print(0); return
  for i in range(1 + (n & 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:
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:
      print(0); return
  for i in range(1 + (n & 1), n, 2):
    if c.get(i, 0) != 2:
      print(0); return 
  print(pow(2, n // 2, MOD))

if __name__ ==  '__main__':
  main()

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)
  ans = 0
  if n & 1:
    for i in range(2, n, 2):
      if c[i] != 2: break
    else:
      if c[0] == 1:
        ans = pow(2, n // 2, MOD)
  else:
    for i in range(1, n, 2):
      if c[i] != 2: break
    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()))

def calc():
    c = Counter(A)
    if N % 2 == 0:
        for i, v in c.items():
            if i % 2 == 0:
                return 0
            if v != 2:
                return 0
    else:
        for i, v in c.items():
            if i % 2 == 1:
                return 0
            if i == 0 and v == 1:
                continue
            if v != 2:
                return 0
    return pow(2, N//2, 10**9+7)

print(calc())

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
MOD = 10 ** 9 + 7
corrct = []
t = N - 1
for i in range(N):
    corrct.append(t)
    if i % 2 == 1:
        t -= 2

if all(corrct[i] == A[i] for i in range(N)):
    print(pow(2, N//2, MOD))
else:
    print(0)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
a = np.array(list(map(int,input().split())), dtype=np.int32)
a = np.sort(a)
b = np.diff(a)
c = np.array([2,0]*(N//2), dtype=np.int32)
if N%2==0:
    c = np.array([0] + [2,0]*((N-1)//2), dtype=np.int32)
# print(b,c)
if (b==c).all():
    res = (pow(2, (N-1)//2, 10**9+7) * ((N+1)%2+1)) % (10**9+7)
    print(res)
else:
    print(0)

Submission status: Accepted

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))

def main():
  n = int(input())
  A = readInts()
  A = sorted(A)
  ans = 0
  if n%2==1:#奇数ならば
    A.remove(0)
  if A[0::2]==A[1::2]:#偶数個数えた時と、奇数個数えた時
    ans = 2**(n//2)%(10**9+7)
  print(ans)
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys

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

#n=5
#a=[2,4,4,0,2]

#n=7
#a=[6,4,0,2,4,0,2]

#n=8
#a=[7,5,1,1,7,3,5,3]

acnt=[0]*n

for i in range(n):
    acnt[a[i]]=acnt[a[i]]+1
    
mod=10**9+7   
if n%2==0:
    for i in range(1,n,2):
        if acnt[i]!=2:
            print(0)
            sys.exit()
    print(pow(2,n//2,mod))
elif n%2==1:
    if acnt[0]!=1:
        print(0)
    else:
        for i in range(2,n,2):
            if acnt[i]!=2:
                print(0)
                sys.exit()
        print(pow(2,n//2,mod))

Submission status: Accepted

Solution code:
import sys
import math
in1 = sys.stdin.readlines()
"""
in1 = ['8','7 5 1 1 7 3 5 3']
in1 = ['7','6 4 0 2 4 0 2']
in1 = ['5','2 4 4 0 2']
"""
p = 10 ** 9 + 7
N = int(in1[0])
A_N = list(map(int, in1[1].split()))
A_N.sort()

ckA = []
if N % 2 == 1:
    ckA.append(0)
    oddFlag = 1
else:
    oddFlag = 0

for idx1 in range(1 + oddFlag, N, 2):
    ckA.append(idx1)
    ckA.append(idx1)

if ckA != A_N:
    print(0)
else:
    print((2 ** ((N - oddFlag) // 2)) % p)

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
l=[]
c=Counter(A)
flag=1
ans=1
values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys())	#先のvalue値に相当する要素のリスト(要素1,要素2,…)
p=10**9+7
for i in range(len(key)):
    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
l.sort(key=lambda x:x[0])
for i in range(len(key)):
    if N%2==0:
        if (l[i][0]%2==1)and(0<l[i][0]<N)and(l[i][1]==2):
            ans=(ans*2)%p
        else:
            flag=0
            break
    else:
        if (l[i][0]==0)and(l[i][1]==1):
            ans=ans
        elif (l[i][0]%2==0)and(0<l[i][0]<N)and(l[i][1]==2):
            ans=(ans*2)%p
        else:
            flag=0
            break
if flag==1:
    print(ans%p)
else:
    print("0")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**5)


def pow_mod(n,k,m):#nのk乗したものをmod 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())
A=list(map(int,input().split()))
MOD=10**9+7
A.sort()

#Nが奇数の場合
#Aをソートして、先頭に0、そのあとは2,2,4,4,となる。そうなっていない場合は間違い


if N&1:
    if A[0]!=0:
        print(0)
        exit()

    for i in range(1,N,2):
        if A[i]!=A[i+1] or A[i]!=i+1:
            print(0)
            exit()
    print(pow_mod(2,((N-1)//2),MOD))

else:
    for i in range(0,N,2):
        if A[i]!=A[i+1] or A[i]!=i+1:
            print(0)
            exit()
    print(pow_mod(2,N//2,MOD))

Submission status: Accepted

Solution code:
import sys
"""
奇数の場合は0が一つと偶数番号が2個ずつ存在している
偶数の場合は奇数番号が2個ずつ並んでいる
それらの条件を満たす場合に、並び替えることが可能で、
"""

N = int(input())
L = list(map(int, input().split()))
number_dict = {}

MOD = 10 ** 9 + 7

for l in L:
  if l in number_dict:
    number_dict[l] += 1
  else:
    number_dict[l] = 1

if N%2 ==1:
  if 0 in number_dict and number_dict[0] != 1:
    print(0)
    sys.exit()
  number_dict.pop(0)
  ran = range(2, N, 2)
else:
  ran = range(1, N, 2)

# チェック
for i in ran:
  if i not in number_dict:
    print(0)
    sys.exit()
  if number_dict[i] != 2:
    print(0)
    sys.exit()
  number_dict.pop(i)


if len(number_dict.keys()) == 0:
  print(2**int(N/2) % MOD )
else:
  print(0)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
from fractions import gcd
from math import ceil
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations
ans = 0
d = Counter(A)
if N%2==1:
    for i in range(0,N,2):
        # print(i)
        if i==0:
            if d[i]!=1:
                # print('A',A)
                break
        elif d[i]!=2:
            # print('B',i)
            break
    else:
        ans = pow(2,(N-1)//2,10**9+7)
else:
    for i in range(1,N,2):
        if d[i]!=2:
            # print(i)
            break
    else:
        ans = pow(2,N//2,10**9+7)
print(ans)

Submission status: Accepted

Solution code:
mod = 1000000007
    
n=int(input())

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

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

Submission status: Accepted

Solution code:
import sys
from collections import deque


mod = 10**9 + 7
n = int(input())
a = deque(sorted(list(map(int, (input().split())))))
if n % 2 == 0:
    for i in range(n//2):
        b = a.popleft()
        c = a.popleft()
        if b != i*2+1 or c != i*2+1:
            print(0)
            sys.exit()
    print(pow(2, n//2, mod))

if n % 2 == 1:
    if a.popleft() != 0:
        print(0)
        sys.exit()
    for i in range(n//2):
        b = a.popleft()
        c = a.popleft()
        if b != (i+1)*2 or c != (i+1)*2:
            print(0)
            sys.exit()
    print(pow(2, n//2, mod))

Submission status: Accepted

Solution code:
N = int(input())
A = map(int, input().split())
l = [abs(N - (n * 2 + 1)) for n in range(N)]

if sorted(A) == sorted(l):
    print(pow(2, N//2) % (pow(10,9) + 7))
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
A = map(int, input().split())
l = [abs(N - (n * 2 + 1)) for n in range(N)]

if sorted(A) == sorted(l):
    print(pow(2, int(N/2)) % (pow(10,9) + 7)) 
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

n=int(input())
a=list(map(int,input().split()))
lst=[0]*n
for i in range(n):
    lst[a[i]]+=1

for i in range(n):
    if n%2==0:
        if i%2==0 and lst[i]!=0:
            break
        elif i%2==1 and lst[i]!=2:
            break
    else:
        if i%2==1 and lst[i]!=0:
            break
        elif i%2==0:
            if i==0:
                if lst[i]!=1:
                    break
            elif lst[i]!=2:
                break
else:
    print(pow(2,n//2,mod))
    exit()
print(0)

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

for k, v in c.items():
    if v != 2:
        if N % 2 == 1 and k == 0:
            continue
        else:
            print("0")
            break
else:
    print(2 ** (N // 2) % MOD)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

    mod = 10 ** 9 + 7

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

    for i in range(N):
        count[A[i]] += 1

    M = N % 2

    res = 1

    if M == 1:
        if count[0] != 1:
            print(0)
            sys.exit()
        test = 0
        for i in range(1,N):
            if count[i] == test:
                res *= max(test,1)
                res %= mod
            else:
                res = 0
                break
            if test == 0:
                test = 2
            else:
                test = 0
    else:
        if count[0] != 0:
            print(0)
            sys.exit()
        test = 2
        for i in range(1,N):
            if count[i] == test:
                res *= max(test,1)
                res %= mod
            else:
                res = 0
                break
            if test == 0:
                test = 2
            else:
                test = 0

    print(res)



main()

Submission status: Accepted

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

from collections import Counter
c = Counter(A)

if N % 2 == 0:
    for i in range(1, N, 2):
        if c[i] != 2:
            break
    else:
        print(2**(N // 2) % mod)
        exit()
    print(0)
else:
    for i in range(0, N, 2):
        if i == 0:
            if c[i] != 1:
                break
        else:
            if c[i] != 2:
                break
    else:
        print(2**(N // 2) % mod)
        exit()
    print(0)

Submission status: Accepted

Solution code:
def check():
    if N %2 == 1:
        if A.pop(0) != 0:
            return 0
        pair = 2
    else:
        pair = 1
    
    for i in range(N//2):
        if A[2*i] == pair and A[2*i+1] == pair:
            pair += 2
        else:
            return 0
    return 1

N = int(input())
A = list(map(int, input().split()))
A.sort()
mod = int(1e9 +7)
if check() == 0:
    print(0)
else:
    print(pow(2, N//2, mod))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
comb = 0
c = Counter(a)
if n%2==0:
    i = 1 
else:
    if c[0]!=1:
        print(0)
        exit()
    c.pop(0)
    i = 2

for k in sorted(c):
    if i==k and c[k]==2:
        i+=2
        comb += 1
    else:
        print(0)
        exit()

print(2**comb%(10**9+7))

Submission status: Accepted

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

mod = 10**9 + 7

lis = [abs(n-2*i-1) for i in range(n)]

a.sort()
lis.sort()

print(pow(2, n//2, mod)) if a==lis else print(0)

Submission status: Accepted

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

mod = 10**9 + 7

lis = [0] * n

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

for i in range(1,n):
	if lis[i] % 2 == 1:
		print(0)
		exit()
		
print(pow(2, n//2, mod))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
s = 0
b = 0
d = [0]*n
if n % 2 == 0:
    for i in a:
        d[i] += 1 
    for i in range(1,n,2):
        if d[i] != 2:
            s = 1
            break
        else:
            b += 1
    ans = 2 ** b % (10**9 + 7)
else:
    for i in a:
        d[i] += 1 
    
    for i in range(0,n,2):
        if i == 0 and d[0] == 1:
            ans = 1
        elif d[i] != 2:
            s = 1
            break
        else:
            b += 1
    ans = 2 ** (b) % (10**9 + 7)

if s == 0:
    print(ans)
elif s == 1:
    print('0')

Submission status: Accepted

Solution code:
from math import ceil

N = int(input())
A = [int(i) for i in input().split()]
n = [0]*N
for a in A:
    n[a] += 1
# print(n)
if N&1:
    t = 0
    for a in range(len(n)):
        if a == 0:
            if n[a] != 1:
                print(0)
                break
        elif a&1:
            if n[a] != 0:
                print(0)
                break
        else:
            if n[a] != 2:
                print(0)
                break
            else:
                t += 1
    else:
        print(2**t%(10**9+7))
else:
    t = 0
    for a in range(len(n)):
        if a&1:
            if n[a] != 2:
                print(0)
                break
            else:
                t += 1
        else:
            if n[a] != 0:
                print(0)
                break
    else:
        print(2**t%(10**9+7))

Submission status: Accepted

Solution code:
from collections import Counter

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

if N % 2:
    if A == Counter((i + 1) // 2 * 2 for i in range(N)):
        print(pow(2, (N - 1) // 2, MOD))
    else:
        print(0)
else:
    if A == Counter(i // 2 * 2 + 1 for i in range(N)):
        print(pow(2, N // 2, MOD))
    else:
        print(0)

Submission status: Accepted

Solution code:
n=int(input())
l=sorted(map(int,input().split()))[::-1]
def f(x):
  t=n+1
  for i in l[x::2]:
    if t-2!=i: return 0
    t=i
  return 1
print(pow(2,n//2,10**9+7)*f(0)*f(1))

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(a)
r = 1 if n % 2 == 0 else 0
for k, v in c.items():
    if r == 0 and k == 0 and v == 1:
        continue
    if k != 0 and k % 2 == r and v == 2:
        continue
    print(0)
    break
else:
    print(2**(n//2) % (10**9+7))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    def ok(n,aa):
        if n&1:
            if aa[0]!=0:return False
            b=2
            first=True
            for a in aa[1:]:
                if a!=b:return False
                if first:first=False
                else:
                    b+=2
                    first=True
        else:
            b=1
            first=True
            for a in aa:
                if a!=b:return False
                if first:first=False
                else:
                    b+=2
                    first=True
        return True

    md=10**9+7
    n=II()
    aa=LI()
    aa.sort()
    if ok(n,aa):print(pow(2,n//2,md))
    else:print(0)

main()

Submission status: Accepted

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

mod = 10**9+7
ans = 1

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

for i in range(n//2):
    ans *= 2
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
import math
n=input()
mod = int(1e9) + 7
a=list(map(int,raw_input().split()))
if(len(a)%2==0 and a.count(0)>0):
    print(0)
elif(len(a)%2!=0 and a.count(0)>1):
    print(0)
else:    
    l=[0]*n
    b=set(a)
    for i in a:
        l[i] +=1
    for i in range(1,len(a)):
        if(l[i]%2==1):
            print(0)
            exit()
    if(a.count(0)):
        print(pow(2,len(b)-1,mod))
    else:
        print(pow(2,len(b),mod))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# C - Lining Up
# 標準入力の取得
N = int(input())
A_list = list(map(int, input().split()))
sorted_A_list = sorted(A_list)

# 期待されるA_listの算出
EXPECTED_LIST = []
is_N_even = (N % 2 == 0)
for n in range(N):
    is_n_even = (n % 2 == 0)
    if is_N_even:
        # Nが偶数の場合、[1, 1, 3, 3, ・・・, N-1, N-1]となる
        if is_n_even:
            EXPECTED_LIST.append(n+1)
        else:
            EXPECTED_LIST.append(n)
    else:
        # Nが奇数の場合、[0, 2, 2, 4, 4, ・・・, N-1, N-1]となる
        if is_n_even:
            EXPECTED_LIST.append(n)
        else:
            EXPECTED_LIST.append(n+1)

# 判定処理
if sorted_A_list == EXPECTED_LIST:
    # 報告が正しかった場合、並び方の総数を10^9+7で割った余りを出力
    print(2**(N//2) % (pow(10, 9)+7))
else:
    # 報告が誤りであった場合、0を出力して、処理を終了する
    print(0)

Submission status: Accepted

Solution code:
mod = int(1e9) + 7
n = int(input())
a = list(map(int, input().split()))
lis = [0] * n
for i in a:
    lis[i] += 1
for i in range(1,n):
    if lis[i] % 2 == 1:
        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()))
p=10**9+7

A_=Counter(A)
A_=A_.most_common()

flag=N%2

for a in A_:
    if a[0]%2==flag:
        print(0)
        exit()
    elif a[0]==0 and a[1]!=1:
        print(0)
        exit()
    elif a[0]!=0 and a[1]!=2:
        print(0)
        exit()

ans=1
for i in range(N//2):
    ans*=2
    ans%=p
print(ans%p)

Submission status: Accepted

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

Submission status: Accepted

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

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

    for k, v in dic.items():
        if v != 2:
            print(0)
            exit()
    print(2**(n//2)%mod)

else:
    for i in a:
        if i%2==1:
            print(0)
            exit()
        if i in dic:
            dic[i] += 1
        else:
            dic[i] = 1

    for k, v in dic.items():
        if v != 2 and k != 0:
            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
B=[0]*n
for i in range(n):
  B[A[i]]+=1
a=0
if B[0]==1:
  for i in range(1,n):
    if i%2==0:
      if B[i]!=2:
        a=1
    else:
      if B[i]!=0:
        a=1
  if a==0:
    print(pow(2,(n-1)//2,mod))
  else:
    print(0)
elif B[0]==0:
  for i in range(1,n):
    if i%2==0:
      if B[i]!=0:
        a=1
    else:
      if B[i]!=2:
        a=1
  if a==0:
    print(pow(2,n//2,mod))
  else:
    print(0)
else:
  print(0)

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
if n % 2 == 0:
    for i in a:
        if i % 2 == 0:
            print(0)
            exit()
    for i in c.values():
        if i != 2:
            print(0)
            exit()
    print(pow(2,n//2,mod))
if n % 2 == 1:
    for i in a:
        if i % 2 == 1:
            print(0)
            exit()
    if c[0]  == 1:
        c[0] = 2
    else:
        print(0)
        exit()
    for i in c.values():
        if i != 2:
            print(0)
            exit()
    print(pow(2,n//2,mod))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if n == 1 and l ==[0, 0]:
    print(1)
    exit()
else:
    a = []
    for i in range(1, n):
        if n % 2 == 1: # odd
            if i < n and i % 2 == 0:
                a += [i] * 2
        else:
            if i < n and i % 2 == 1:
                a += [i] * 2
    else:
        if n % 2 == 1:
            a.insert(0, 0)
    
if l != a:
    print(0)
else:
    print((2 ** (n // 2)) % (10**9 + 7))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
C = [0]*N
a=0
def line(A,N):
    for i in range(N):
        C[A[i]] += 1
    if C[0] == 1:
        if N % 2==1:
            return pow(2,(N-1)//2)
        else:
            return 0
    for i in range(N):
        if C[i] != 2 and C[i]>=1:
            return 0
        elif C[i]==0:
            continue
    if N % 2 ==0:
        return pow(2,N//2)
    else:
        return pow(2,(N-1)//2)
a=line(A,N)
print(a%(pow(10,9)+7))

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

from collections import Counter

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

ans = -1
A_ = Counter(A)
cnt = 0
if N % 2 == 1:
    if A_[0] != 1:
        ans = 0
    for i in range(2,N,2):
        if A_[i] != 2:
            ans = 0
            break
        cnt += 1
else:
    for i in range(1,N,2):
        if A_[i] != 2:
            ans = 0
            break
        cnt += 1

if ans == 0:
    print(ans)
else:
    print(2**cnt%mod)

Submission status: Accepted

Solution code:
import collections

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

m = collections.Counter(a)

# n: odd  ->  0, 2, ..., n-1
# n: even ->  1, 3, ..., n-1

if n % 2 == 0:
    mm = {2*i+1: 2 for i in range(0, n//2)}
else:
    mm = {2*i: 2 for i in range(0, n//2 + 1)}
    mm[0] = 1


for i in m:
    if i not in mm or m[i] != mm[i]:
        print(0)
        exit()

for i in mm:
    if i not in m or mm[i] != mm[i]:
        print(0)
        exit()

r = 10**9 + 7
ans = 1
for _ in range(n//2):
    ans = (ans * 2) % r

print(ans)