Problem:


Score : 300 points

Problem Statement

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

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

Constraints

1≦N≦10^5

0≦A_i≦N-1

Input

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

N
A_1 A_2 ... A_N

Output

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

Sample Input 1

5
2 4 4 0 2

Sample Output 1

4

There are four possible orders, as follows:

2,1,4,5,3

2,5,4,1,3

3,1,4,5,2

3,5,4,1,2

Sample Input 2

7
6 4 0 2 4 0 2

Sample Output 2

0

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

Sample Input 3

8
7 5 1 1 7 3 5 3

Sample Output 3

16



Sample input:
5
2 4 4 0 2


Sample output:
4

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
freq = Counter(a)
ordering = []
for i in range(n):
    right = n - i - 1
    left = i
    ordering.append(abs(right - left))
freq2 = Counter(ordering)
if freq != freq2:
    print(0)
else:
    result = 1
    for x in freq.values():
        result *= x
    print(result % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
n, *A = map(int, open(0).read().split())
if n % 2:
    d = {i:2 for i in range(0, n, 2)}
    d[0] -= 1
else:
    d = {i:2 for i in range(1, n, 2)}
for a in A:
    if a in d:
        d[a] -= 1
    else:
        print(0)
        exit()

if any(d.values()):
    print(0)
else:
    print(pow(2, n//2, 10**9 + 7))

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    n = int(input())
    A = list(map(int, input().split()))
    c = Counter(A)
    mod = 1000000007
    if n % 2 == 0:
        if any([a % 2 == 0 for a in A]) or any([v != 2 for v in c.values()]):
            print(0)
            exit()

    else:
        if any([a % 2 != 0 for a in A]) or any([v != 2 if k != 0 else v != 1 for k, v in c.items()]):
            print(0)
            exit()
    print(pow(2, n // 2, mod))    


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    MOD = 10 ** 9 + 7
    N = int(input())
    A = list(map(int, input().split(' ')))
    # 対称性から、左半分（中央含む）の各場所でのアサイン候補人数だけ考える。
    # 中央では1人、その他では2人（左右それぞれにアサイン）であればOK。
    # アサイン可能なのであれば答えは 2 ** (N // 2) 通り。
    count = [0 for _ in range(N // 2 + 1)]
    for a in A:
        if (N - 1 - a) % 2 > 0:
            print(0)
            return
        left = (N - 1 - a) // 2  # right = (N - 1 + a) // 2
        count[left] += 1
    for i in range(len(count)):
        c = count[i]

        if i == N // 2:
            if N % 2 > 0 and c != 1:
                print(0)
                return
        else:
            if c != 2:
                print(0)
                return
    # caclulate answer
    ans = 1
    for _ in range(N // 2):
        ans *= 2
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
n = int(input())
a = sorted(list(map(int, input().split())))
for i in range(n):
  if a[i] != (2 * ((i + 2 - n % 2) // 2) + n % 2 - 1):
    print(0)
    sys.exit()
print(pow(2, n // 2, 1000000007))

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
ac = collections.Counter(a)
ac = list(ac.items())
ac.sort()
# print(ac)

mod = int(1e9+7)
ans = 1
if n % 2 == 0:
    for i in range(1,n,2):
        if ac[i//2][0] != i or ac[i//2][1] != 2:
            print(0)
            exit()
        else:
            ans *= 2
            ans %= mod
else:
    for i in range(0, n, 2):
        if i == 0:
            if ac[i//2][0] != i or ac[i//2][1] != 1:
                print(0)
                exit()
        else:
            if ac[i//2][0] != i or ac[i//2][1] != 2:
                print(0)
                exit()
            else:
                ans *= 2
                ans %= mod
print(ans)

Submission status: Accepted

Solution code:
from sys import exit
N = int(input())
A = map(int,input().split())
B = [0]*N
for i in A:
  B[i] += 1
if N%2 == 1:
  if B[0] != 1:
    print(0)
    exit()
  for i in range(1,N):
    if i%2 == 1 and B[i] != 0:
      print(0)
      exit()
    elif i%2 == 0 and B[i] != 2:
      print(0)
      exit()
else:
  for i in range(N):
    if i%2 == 1 and B[i] != 2:
      print(0)
      exit()
    elif i%2 == 0 and B[i] != 0:
      print(0)
      exit()
print(pow(2,N//2,1000000007))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
c=Counter(lis)
if n%2==1:
    flag=True
    if c[0]!=1:
        flag=False
    for i in c.keys():
        if i!=0 and c[i]!=2:
            flag=False
    if flag==False:
        print(0)
    else:
        print(pow(2,(n-1)//2,mod))
else:
    flag=True
    for i in c.keys():
        if c[i]!=2:
            flag=False
    if flag==False:
        print(0)
    else:
        print(pow(2,n//2,mod))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
flag = True
c = Counter(a)
#print(c)
if n % 2 == 1:
    if c[0] != 1:
        flag = False
    for i in range(1, n//2+1):
        if c[i*2] != 2:
            flag = False
            break
    if flag:
        print(2**(n//2) % mod)
    else:
        print(0)
elif n % 2 == 0:
    for i in range(n//2):
        if c[i*2+1] != 2:
            flag = False
            break
    if flag:
        print(2**(n//2) % mod)
    else:
        print(0)

Submission status: Accepted

Solution code:
n = int(input())
nums = sorted(map(int, input().split()))
if n % 2 == 0:
    if nums[::2] != nums[1::2]:
        print(0)
    else:
        print(2 ** (n // 2) % 1000000007)
else:
    if nums[0] == 0 and nums[1::2] == nums[2::2]:
        print(2 ** (n // 2) % 1000000007)
    else:
        print(0)

Submission status: Accepted

Solution code:
from collections import Counter
import numpy as np

MOD = 10 ** 9 + 7

n = int(input())
a = list(map(int, input().split()))
count = Counter(a)
# 0の個数は、count[0]
num = len(a)
ans = 1


if (num % 2 == 0):
    # 偶数パターン
    temp = 1
    loop = int(num / 2)
    for i in range(loop):
        tar = count[temp]
        if (tar == 2):
            ans *= 2
            temp += 2
        else:
            print(0)
            exit()

else:

    tar0 = count[0]
    if (tar0 == 1):
        pass
    else:
        print(0)
        exit()

    temp = 2

    for i in range(num // 2):
        if (count[temp] == 2):
            ans *= 2
            temp += 2
        else:
            print(0)
            exit()

ans %= MOD
print(ans)

Submission status: Accepted

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

for i in range(N):
    a_comb.append(abs(i - (N - 1 - i)))

if sorted(a_comb) == sorted(a):
    print(2 ** (N // 2) % mod)
else:
    print(0)

Submission status: Accepted

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

from collections import Counter
c=Counter(a)

cnt_lst=[0]*n
for key in c:
    cnt_lst[key]+=c[key]

flag=True
if n%2==1:
    if cnt_lst[0]==1:
        cnt_lst.pop(0)
    else:
        flag=False
    for i in range(n-1):
        if (i%2==1 and cnt_lst[i]!=2) or (i%2==0 and cnt_lst[i]!=0):
            flag=False
else:
    for i in range(n):
        if (i%2==1 and cnt_lst[i]!=2) or (i%2==0 and cnt_lst[i]!=0):
            flag=False

print(2**(n//2)%mod if flag else 0)

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)

cnt_lst=[0]*n
for key in c:
    cnt_lst[key]+=c[key]

flag=True
if n%2==1:
    if cnt_lst[0]==1:
        cnt_lst.pop(0)
    else:
        flag=False
    for i in range(n-1):
        if (i%2==1 and cnt_lst[i]!=2) or (i%2==0 and cnt_lst[i]!=0):
            flag=False
else:
    for i in range(n):
        if (i%2==1 and cnt_lst[i]!=2) or (i%2==0 and cnt_lst[i]!=0):
            flag=False

print(pow(2,(n//2),mod) if flag else 0)

Submission status: Accepted

Solution code:
from collections import Counter

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

combi = []
for i in range(n):
    l = i
    r = n - i - 1
    combi.append(abs(l - r))

if sorted(combi) == sorted(a):
    c = Counter(combi)
    ans = 1
    for i in c.values():
        ans *= i
        ans %= mod
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 A.count(0)!=1 or len(set(A))!=(n+1)//2:
        flag=False
if flag:
    print(2**(n//2)%(10**9+7))
else:
    print(0)

Submission status: Accepted

Solution code:
import collections

n = int(input())
lst = [int(s) for s in input().split()]

is_success = True

if n % 2 == 1:
    is_success = lst.count(0) == 1

counters = collections.Counter(lst)

for i in range(n - 1, 0, -2):
    if counters[i] != 2:
        is_success = False
        break

if is_success:
    tmp = 1

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

    print(tmp)
else:
    print(0)

Submission status: Accepted

Solution code:
import collections

n = int(input())
lst = [int(s) for s in input().split()]

is_success = True

if n % 2 == 1:
    is_success = lst.count(0) == 1

counters = collections.Counter(lst)

for i in range(n - 1, 0, -2):
    if counters[i] != 2:
        is_success = False
        break

if is_success:
    tmp = 1

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

    print(tmp)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

result = 0
if N % 2 != 0:
  cor = [0]
  for i in range(1,int(N/2)+1):
    cor.append(i*2)
    cor.append(i*2)
  if sorted(a) == cor:
    result = 2**int((N-1)/2) % (10**9 + 7)
else:
  cor = []
  for i in range(1,int(N/2)+1):
    cor.append(i*2-1)
    cor.append(i*2-1)
  if sorted(a) == cor:
    result = 2**int(N/2) % (10**9 + 7)
    
print(result)

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
A = IL()

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


for a in A:
  correct[a] -= 1
  
if correct != [0 for i in range(N+1)]:
  print(0)
else:
  print(pow(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:

    memo = {key:0 for key in [i for i in range(2, N, 2)]}

    for a in A:
        try:
            memo[a] += 1
        except:
            memo[a] = 1

# print(memo)

    check_list = {}
    for i in range(2, N, 2):
        check_list[i] = False

    for check_num in check_list.keys():
        if check_num == 0:
            if memo[check_num] != 1:
                print(0)
                quit()
        if memo[check_num] != 2:
            print(0)
            quit()

else:
    memo = {key:0 for key in [i for i in range(1, N, 2)]}

    for a in A:
        try:
            memo[a] += 1
        except:
            memo[a] = 1

# print(memo)

    check_list = {}
    for i in range(1, N, 2):
        check_list[i] = False

    for check_num in check_list.keys():
        if memo[check_num] != 2:
            print(0)
            quit()

ans = pow(2, len(check_list))
ans %= mod
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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


if N % 2 == 0:
    for key, value in A.items():
        if key % 2 != 1:
            print(0)
            exit()
    for i in range(1, N, 2):
        if A[i] != 2:
            print(0)
            exit()
    print(pow(2, N//2, mod))
else:
    if A[0] != 1:
        print(0)
        exit()
    for key, value in A.items():
        if key % 2 != 0:
            print(0)
            exit()
    for i in range(2, N, 2):
        if A[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()))
mod = 10**9+7
cnt = [0] * N
flag = 1
for i in range(N):
  cnt[A[i]] += 1
if(N % 2 == 1):
  if(cnt[0] != 1):
    flag = 0
  for i in range(1, N):
    if(i%2 == 1 and cnt[i] != 0):
      flag = 0
    elif(i%2 == 0 and cnt[i] != 2):
      flag = 0
else:
  for i in range(N):
    if(i%2 == 1 and cnt[i] != 2):
      flag = 0
    elif(i%2 == 0 and cnt[i] != 0):
      flag = 0
print(flag*pow(2, N//2, mod))

Submission status: Accepted

Solution code:
t = int(input())
m = list(map(int,input().split()))
q={}
mod=10**9+7
z=False
cnt0=0
for i in range(t):
    d=m[i]
    a=(t-1-d)//2
    if d==0:
        cnt0+=1
    if (a,a+d) not in q:
        q[(a,a+d)]=0
    q[(a,a+d)]+=1
    if q[(a,a+d)]>2:
        z=True
        break
if z or cnt0>1:
    print(0)
elif cnt0==1 and t%2==0:
    print(0)

   
else:
    res=1
    for i in q:
        if i[0]==i[1]:
            res=res*1
        else:
            res=res*2
    print(res%mod)

Submission status: Accepted

Solution code:
n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
ans=[0]*(10**5+1)
flag=False
if n%2==0:
  for i in range(len(a)):
    if a[i]%2==0:
      flag=True
      break
    ans[a[i]]+=1
    if ans[a[i]]>2:
      flag=True
      break
else:
  for i in range(len(a)):
    if a[i]%2==1:
      flag=True
      break
    ans[a[i]]+=1
    if ans[0]>1:
      flag=True
      break
    if ans[a[i]]>2:
      flag=True
      break
if flag==True:
  print(0)
else:
  print(pow(2,(n//2),mod))

Submission status: Accepted

Solution code:
n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
ans=[0]*(10**5+1)
flag=False
if n%2==0:
  for i in range(len(a)):
    if a[i]%2==0:
      flag=True
      break
    ans[a[i]]+=1
    if ans[a[i]]>2:
      flag=True
      break
else:
  for i in range(len(a)):
    if a[i]%2==1:
      flag=True
      break
    ans[a[i]]+=1
    if ans[0]>1:
      flag=True
      break
    if ans[a[i]]>2:
      flag=True
      break
if flag==True:
  print(0)
else:
  print(pow(2,(n//2),mod))

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
ok = True
if n%2==1:
    a=sorted(A)
    for i in range(len(a)):
        if i%2==0:
            if a[i]!=i:
                ok = False
        else:
            if a[i]!=i+1:
                ok = False
else:
    a=sorted(A)
    for i in range(len(a)):
        if i%2==1:
            if a[i]!=i:
                ok = False
        else:
            if a[i]!=i+1:
                ok = False
if ok:
    print(2**(n//2)%1000000007)
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict

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

if N%2 == 0:
    a = defaultdict(int)
    for i,j in zip(c.keys(),c.values()):
        a[i] = j
    
    for i in range(N//2):
        if a[i*2+1] != 2:
            print(0)
            exit()
    
    print(pow(2,N//2,int(1e9+7)))

else:
    a = defaultdict(int)
    for i,j in zip(c.keys(),c.values()):
        a[i] = j

    for i in range(N//2+1):
        if i == 0:
            if a[i] != 1:
                print(0)
                exit()
        else:
            if a[2*i] != 2:
                print(0)
                exit()

    print(pow(2,N//2,int(1e9+7)))

Submission status: Accepted

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

ans = []
if N%2 == 0:
    for i in range(N):
        ans.append(2*(i//2)+1)
    if ans == a:
        print(pow(2,N//2,MOD))
    else:
        print(0)
else:
    for i in range(N):
        ans.append(2*((i+1)//2))
    if ans == a:
        print(pow(2,(N-1)//2,MOD))
    else:
        print(0)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = [0] + list(map(int, input().split()))
p = 10**9 + 7
l = Counter(A)

flag = True
for i in range(N%2 == 0,N,2):
  if l[i] != 2:
    flag = False
    break
if flag:
  print(pow(2,N//2,p))
else:
  print(0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())

    def check(L, n):
        # n 偶数 -> 1 1 3 3 5 5 ...
        if n % 2 == 0:
            for i in range(n):
                if (i % 2 == 0 and L[i] != i + 1) or (i % 2 == 1 and L[i] != i):
                    return False
        # n 奇数 -> 0 2 2 4 4 6..
        else:
            for i in range(n):
                if (i % 2 == 0 and L[i] != i) or (i % 2 == 1 and L[i] != i + 1):
                    return False
        return True

    
    n = ii()
    L = lmi()
    L.sort()
    if check(L, n):
        if n % 2 == 1:
            print(pow(2, (n - 1)//2, mod))
        else:
            print(pow(2, n//2, mod))
    else:
        print(0)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import collections
MOD = 10**9+7

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

A = sorted(collections.Counter(a).most_common())

flg = True
ans = 1

if n % 2 == 0:
    # EVEN
    if len(A) == n//2:
        for i in range(n//2):
            if A[i][0] == 1+i*2 and A[i][1] == 2:
                ans = ans * 2 % MOD
            else:
                flg = False
                break
    else:
        flg = False
else:
    # ODD
    if len(A) == n//2+1:
        for i in range(n//2+1):
            if i == 0:
                if A[i][0] == 0 and A[i][1] == 1:
                    pass
                else:
                    flg = False
                    break
            else:
                if A[i][0] == i*2 and A[i][1] == 2:
                    ans = ans * 2 % MOD
                else:
                    flg = False
                    break
    else:
        flg = False

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import Counter
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    A=list(map(int,input().split()))
    c=Counter(A)
    if N%2:
        if not (0 in c and c[0]==1):
            print(0)
            exit()
        for k in range(2,N,2):
            if not (k in c and c[k]==2):
                print(0)
                exit()
    else:
        for k in range(1,N,2):
            if not (k in c and c[k]==2):
                print(0)
                exit()
    print(pow(2,N//2,MOD))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

counters = Counter(A).items()

if N % 2 == 1:
    for k, v in counters:
        if k == 0:
            if v != 1:
                print(0)
                break
        else:
            if k % 2 != 0 or v != 2:
                print(0)
                break
    else:
        ans = pow(2, N // 2, mod)
        print(ans)
else:
    for k, v in counters:
        if k % 2 != 1 or v != 2:
            print(0)
            break
    else:
        ans = pow(2, N // 2, mod)
        print(ans)

Submission status: Accepted

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

adic=defaultdict(int)
for a in alist:
  adic[a]+=1
#print(adic)

answer=1
if N%2==1:  
  for a,v in adic.items():
    #print(a,v)
    if a==0:
      if v!=1:
        print(0)
        sys.exit(0)
    elif a%2==0:
      if v!=2:
        print(0)
        sys.exit(0)
      else:
        answer*=2
        answer%=MOD
    else:
      print(0)
      sys.exit(0)
  print(answer)
else:
  for a,v in adic.items():
    #print(a,v)
    if a%2==0:
      print(0)
      sys.exit(0)
    else:
      if v==2:
        answer*=2
        answer%=MOD
      else:
        print(0)
        sys.exit(0)
  print(answer)

Submission status: Accepted

Solution code:
import collections

N = int(input())
A = [int(i) for i in input().split()]
ans = 0
di = collections.Counter(A)
if N % 2 != 0:
    num_list = [int(i) for i in range(2, N, 2)]
    for num in num_list:
        if di[num] != 2:
            break
    else:
        if A.count(0) == 1:
            ans = (2 ** (N // 2)) % (10 ** 9 + 7)

else:
    num_list = [int(i) for i in range(1, N, 2)]
    for i in num_list:
        if di[i] != 2:
            break
    else:
        ans = (2 ** (N // 2)) % (10 ** 9 + 7)
print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
c = collections.Counter(a)
cl = ""
if n%2 == 1:
	cl = "odd"
else:
	cl = "even"
ans = 0
flg = True
if cl == "odd":
	for i in c:
		if i%2 == 1:
			flg = False
		if i == 0:
			if c[i] != 1:
				flg = False
		else:
			if c[i] != 2:
				flg = False
else:
	for i in c:
		if i%2 == 2:
			flg = False
		if c[i] != 2:
			flg = False
if not (flg):
	print (ans)
	exit()
ans = 2**(n//2)%mod
print (ans)