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,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
cnt = Counter(a)
if n%2 == 0:
    for key in cnt.keys():
        if key%2 and key < n and cnt[key] == 2:
            continue
        else:
            print(0)
            quit()
    print((2**(n//2)) % mod)
else:
    for key in cnt.keys():
        if key % 2 == 0 and key < n and cnt[key] == 2:
            continue
        elif key == 0 and cnt[key] == 1:
            continue
        else:
            print(0)
            quit()
    print((2**(n//2)) % mod)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce



sys.setrecursionlimit(2147483647)
INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
L = sorted(LI())
l = 0
r = n - 1
A = []
while r >= 0:
    A += [abs(r - l)]
    l += 1
    r -= 1


if sorted(A) != L:
    print(0)
else:
    s  = len(set(L))
    if n % 2:
        s -= 1
    print(pow(2, s, mod))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def __is_even(num):
    return num % 2 == 0


DIVISOR = 10 ** 9 + 7
ITR_NUM = 1000

N = int(input())
reported_num_count = {}
power_num = 0
if __is_even(N):  # Nが偶数の場合
    # 報告が正しい場合、値は全て奇数であり、1 ~ N-1 (1つ飛ばし) が2回ずつ出現する
    for i in range(1, N, 2):
        reported_num_count[i] = 0
    for i in list(map(int, input().split())):
        if (1 <= i <= N - 1) and not __is_even(i) and reported_num_count[i] < 2:
            reported_num_count[i] += 1
        else:
            print(0)
            exit()
    power_num = int(N / 2)
else:  # N が奇数の場合
    # 報告が正しい場合、値は全て偶数であり、0 が 1回、 2 ~ N-1（1つ飛ばし）が2回ずつ出現する
    for i in range(0, N, 2):
        reported_num_count[i] = 0
    for i in list(map(int, input().split())):
        if (i == 0) and reported_num_count[0] < 1:
            reported_num_count[0] += 1
        elif (2 <= i <= N - 1) and __is_even(i) and reported_num_count[i] < 2:
            reported_num_count[i] += 1
        else:
            print(0)
            exit()
    power_num = int((N - 1) / 2)

result = 1
while power_num > ITR_NUM:
    result *= 2 ** ITR_NUM % DIVISOR
    result %= DIVISOR
    power_num -= ITR_NUM
result *= 2 ** power_num % DIVISOR
print(result % DIVISOR)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int,input().split()))
    mod = 10**9+7
    
    from collections import defaultdict
    D = defaultdict(int)
    for i in A:
        D[i] += 1
    flag = 0
    for i in D:
        if i==0 and D[i] != 1:
            flag = 1
            break
        if i!=0 and D[i] != 2:
            flag = 1
            break
    if flag == 1:
        print(0)
    else:
        print(pow(2,N//2,mod))
    
    
main()

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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

"""
Nが奇数個の場合、
    Aiに奇数の数字があったらNG
    0の数は1つだけ
    2^(N//2)通り

偶数個の場合
    Aiに偶数の数字があったらNG
    0は0個
    2^((N-1)/2)通り→2^(N//2)でOK

同じ数字は2個ある
"""

from collections import Counter
c = Counter(A)

def ng():
    print(0)
    exit()

# 奇数
if N%2 == 1:
    for k, v in c.items():
        if k % 2 == 1:
            ng()

        if k != 0:
            if v != 2:
                ng()

    if c[0] != 1:
            ng()

else:
    for k, v in c.items():
        if k % 2 == 0:
            ng()

        if k != 0:
            if v != 2:
                ng()

    if c[0] != 0:
            ng()

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

Submission status: Accepted

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

N = int(input().split()[0])
a_list = list(map(int, input().split()))

excepted_dict = {}

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

counter = collections.Counter(a_list)

mod = 10 ** 9 + 7

if dict(counter) == expected_dict:
    c = 1
    for v in counter.values():
        c = ((c % mod) * (v % mod)) % mod
    ans = c
else:
    ans = 0

print(ans)

Submission status: Accepted

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

if n%2==0:
    evenlists=[]
    for i in range(1,n,2):
        evenlists.append(i)
        evenlists.append(i)
    special=sorted(evenlists)
    
    if special==sorted(lists):
        ans=1
        for i in range(int(n/2)):
            ans=ans*2
            ans=ans%(10**9+7)
        print(ans)
    else:
        print(0)
else:
    oddlists=[]
    for j in range(2,n,2):
        oddlists.append(j)
        oddlists.append(j)
    oddlists.append(0)
    special=sorted(oddlists)
    
    if special==sorted(lists):
        ans=1
        for j in range(int((n-1)/2)):
            ans=ans*2
            ans=ans%(10**9+7)
        print(ans)  
    else:
        print(0)

Submission status: Accepted

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

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    from collections import Counter
    c = Counter(A)

    for k,v in c.items():
        if(v == 2 or (k == 0 and v == 1)):
            pass
        else:
            print(0)
            exit()
        
    print((2 ** (N//2))%MOD)


    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    A = map(int, input().split())
    count = [0] * N
    ex = [i*2 if N%2!=i%2 else 0 for i in range(N)]
    for a in A:
        count[a] += a
    
    if count == ex:
        return 2**(N//2) % (10**9+7)
    else:
        return 0
    
if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
# N=5
# A=[2,4,4,0,2]
mod=10**9+7
# N=8
# A=[7,7,5,5,3,3,1,1]
Asorted = sorted(A,reverse=True)
# print(Asorted)
for i in range(0,len(A)-1,2):

    if Asorted[i]==Asorted[i+1]==N-i-1:
        # print("ok:",N-i-1)
        pass
    else:
        print("0")
        exit(0)


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

Submission status: Accepted

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

false_flag = 0
'''
if N % 2 == 0:
    count_ = 1
else:
    if A.count(0) != 1:
        false_flag = 1
    count_ = 2
while count_ < N and false_flag == 0:
    if A.count(count_) != 2:
        false_flag = 1
    count_ += 2
'''

count_list = [0 for i in range(N)]
for index in A:
    count_list[index] += 1

if N % 2 == 0:
    count_ = 1
    diff = -1
else:
    if count_list[0] != 1:
        false_flag = 1
    count_ = 2
    diff = -1
while count_ < N and false_flag == 0:
    #print(count_)
    if count_list[count_] != 2 or count_list[count_ + diff] != 0:
        false_flag = 1
    count_ += 2

if false_flag == 0:
    print((2 ** (N // 2) ) % 1000000007)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

ans_0 = False
N = int(input())
l = list(map(int, input().split()))
l_Counter = Counter(l)
if N % 2 == 1:
    if l_Counter[0] != 1:
        ans_0 = True
    else:
        l_Counter[0] = 2
        for i in l_Counter.items():
            # print(i)
            if i[1] != 2 or i[0] % 2 == 1:
                ans_0 = True
                break
else:
    for i in l_Counter.items():
        # print(i)
        if i[1] != 2 or i[0] == 0 or i[0] % 2 == 0:
            ans_0 = True
            break
#     print(An)
# print(end_0)
if ans_0:
    print(0)
else:
    print((2 ** (N // 2)) % 1000000007)

Submission status: Accepted

Solution code:
mod = 1000000007

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

data = [0]*N
for i in a:
  data[i] += 1

cnt = 0
for i in range(1,len(data)):
  if data[i] == 2:
    cnt += 1
  elif data[i] == 0:
    continue
  else:
      print(0)
      exit()
print(pow(2, cnt) %mod)

Submission status: Accepted

Solution code:
n = int(input())
A = [int(num) for num in input().split()]
import collections as cl
dic = cl.Counter(A)

cont = False
if n % 2 == 1:
  if dic[0] != 1:
    cont = True
  else:
    dic[0] = 2
    for num in dic.values():
      if num != 2:
        cont = True
        break
else:
  for num in dic.values():
    if num != 2:
      cont = True
      break

if cont == True:
  print(0)
else:
  print(2**(n//2) % (10**9 + 7))

Submission status: Accepted

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

D = [0] * n

for i in range(n):
    D[A[i]] += 1

ok = 1
if n % 2 == 0:
    for i in range(1, n, 2):
        if D[i] != 2:
            ok = 0
            break
else:
    if D[0] != 1:
        ok = 0
    for i in range(2, n//2+1, 2):
        if D[i] != 2:
            ok = 0
            break

ans = 0
if ok == 1:
    ans = 1
    for i in range(n//2):
        ans = (ans * 2) % mod

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int,input().split()))
a = set(b)
flag = 0
if n % 2 == 1:
    if all(i % 2 == 0 for i in a) and len(a) == (n-1)//2 +1 and b.count(0) == 1:
        flag = 1
else:
    if all(i % 2 == 1 for i in a) and len(a) == (n-1)//2 + 1:
        flag = 1
print(2**(n//2)%(10**9+7) if flag==1 else 0)

Submission status: Accepted

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

Submission status: Accepted

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

if N % 2:
  for i in range(N):
    if A[i] != (i+1) // 2 * 2:
      f = False
      
else:
  for i in range(N):
    if A[i] != i // 2 * 2 + 1:
      f = False

if f:
  print(2 ** (N//2) % mod)
else:
  print(0)

Submission status: Accepted

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

def main():
    N = int(input())
    a = sorted(list(map(int, input().split())), reverse=True)

    MOD = int(1e9) + 7

    tmp = N - 1
    ans = 1
    for i in range(N//2):
        # print(a[2*i], a[2*i+1], tmp)
        if a[2*i] == tmp and a[2*i+1] == tmp:
            # print("ok")
            ans *= 2
            ans %= MOD
        else:
            print(0)
            return
        tmp -= 2
    
    if N&1:
        if a[N-1] != 0:
            print(0)
            return
    
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
line = [abs(i - (n - i - 1)) for i in range(n)]
if sorted(a) == sorted(line):
    print((2 ** (n // 2)) % (10 ** 9 + 7))
else:
    print(0)

Submission status: Accepted

Solution code:
def index(n:int, a: int):
    if a % 2 == 0:
        i = n // 2 - a // 2
        j = (i + 1) * -1
        return (i, j) if i != n // 2 else (i,)
    else:
        i = (n // 2 - 1) - (a - 1) // 2
        j = (i + 1) * -1
        return (i, j)

n = int(input())
line = [0 for _ in range(n)]
for a in map(int, input().split()):
    for i in index(n, a):
        line[i] += 1
else:
    if n == 1 and line == [1]:
        print(1)
    elif n % 2 == 0 and set(line) == {2}:
        print(2 ** (n // 2) % (10 ** 9 + 7))
    elif n % 2 == 1 and set(line) == {1, 2} and line[n//2] == 1:
        print(2 ** ((n - 1) // 2) % (10 ** 9 + 7))
    else:
        print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
line = [abs(i - (n - i- 1)) for i in range(n)]
if sorted(a) == sorted(line):
    print((2 ** (n // 2)) % (10 ** 9 + 7))
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
line = [abs(i - (n - i- 1)) for i in range(n)]
if sorted(a) == sorted(line):
    print((2 ** (n // 2)) %  (10 ** 9 + 7))
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import*
N=int(input())
if N%2:
 if Counter(map(int,input().split()))==Counter(i//2*2for i in range(1,N+1)):print(2**(N//2)%(10**9+7))
 else:print(0)
else:
 if Counter(map(int,input().split()))==Counter(i//2*2+1for i in range(N)):print(2**(N//2)%(10**9+7))
 else:print(0)

Submission status: Accepted

Solution code:
# 人数分布は一意
import numpy as np

N = int(input())
A = np.array([int(x) for x in input().split()])
MOD = 10 ** 9 + 7

left = np.arange(N)
right = N-1-left
cnt_1 = np.bincount(np.abs(left-right))
cnt_2 = np.bincount(A)
#print(cnt_1)
if cnt_1.shape != cnt_2.shape or (cnt_1 != cnt_2).any():
    answer = 0
else:
    answer = pow(2, N//2, MOD)
print(answer)

Submission status: Accepted

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

def chk(c, n):
    if n % 2:
        if 0 not in c or c[0] != 1:
            return False
        for i in range(2, (n//2)*2+1, 2):
            if i not in c or c[i] != 2:
                return False
    else:
        for i in range(1, n, 2):
            if i not in c or c[i] != 2:
                return False
    return True

if chk(c, N):
    ans = 2 ** (N//2) % MOD
else:
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
# 人数分布は一意
import numpy as np
MOD = 10**9 + 7
N = int(input())
A = np.array([int(x) for x in input().split()])

left = np.arange(N)
right = N-1-left
cnt_1 = np.bincount(np.abs(left-right))
cnt_2 = np.bincount(A)

if cnt_1.shape != cnt_2.shape or (cnt_1 != cnt_2).any():
    answer = 0
else:
    answer = pow(2, N//2, MOD)

print(answer)

Submission status: Accepted

Solution code:
def pow2( n ):
    ans = 1 
    for i in range(n):
        ans = 2*ans % 1000000007
    return ans

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

if N % 2 == 0:
    flag = True
    for n in range(0,N-1,2):
        if AList[n] == n+1 and AList[n+1] == n+1:
            pass
        else:
            flag = False
            break

    if flag == False:
        print(0)
    else:
        a = N//2
        print(pow2(a))
else:
    flag = True
    if AList[0] != 0:
        flag = False
    else:
        for n in range(1,N-1,2):
            if AList[n] == n+1 and AList[n+1] == n+1:
                pass
            else:
                flag = False
                break
    if flag == False:
        print(0)
    else:
        a = N//2
        print(pow2(a))

Submission status: Accepted

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

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

if A==B:
  print(pow(2,N//2,10**9+7))
else:
  print(0)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
flag=0
B=[0]*100000
mod=1000000007
if N%2==1:
    for i in range(N):
        B[A[i]]+=1
    for i in range(N):
        if i==0:
            if B[i]!=1:
                flag=1
        elif i%2==0:
            if B[i]!=2:
                flag=1

if N%2==0:
    for i in range(N):
        B[A[i]]+=1
    for i in range(N):
        if i%2==1:
            if B[i]!=2:
                flag=1


if flag==1:
    print(0)
else:
    print(2**(N//2)%mod)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = []
flag = 0

for i in range(N//2):
    B.append((N-1) - (i*2))
    B.append((N-1) - (i*2))
if N % 2 == 1:
    B.append(0)
        
A.sort()
B.sort()
if A == B:
    print((2**(N//2)) % (1000000007))
else:
    print(0)

Submission status: Accepted

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

if N % 2 == 0:
    for i in range(1, N, 2):
        B.append(i)
        B.append(i)
else:
    B.append(0)
    for i in range(2, N, 2):
        B.append(i)
        B.append(i)

if A != B:
    ans = 0
else:
    ans = 2 ** (N // 2) % mod

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=[int(i) for i in input().split()]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

mod = 10 ** 9 + 7

n = ni()
aaa = na()
c = Counter(aaa)
ct = 0
ans = 0
if n % 2 == 0:
    for k, v in c.items():
        if k % 2 != 1:
            ct = 0
            break
        if v == 2:
            ct += 1
        else:
            ct = 0
            break
else:
    for k, v in c.items():
        if k % 2 != 0:
            ct = 0
            break
        if k == 0:
            if v != 1:
                ct = 0
                break
        elif v == 2:
            ct += 1
        else:
            ct = 0
            break
if n == 1 and aaa[0] == 0:
    print(1)
elif ct == 0:
    print(0)
else:
    ans = 2 ** ct
    print(ans % mod)

Submission status: Accepted

Solution code:
def resolve():
    n=int(input())
    A=sorted(list(map(int,input().split())))
    if n%2:
        A.insert(0,0)
        flag=all(A[2*i]==2*i and A[2*i+1]==2*i for i in range(len(A)//2))
    else:
        flag=all(A[2*i]==2*i+1 and A[2*i+1]==2*i+1 for i in range(len(A)//2))
    print(2**(n//2)%(10**9+7) if flag else 0)
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

dic= {}
for i in A:
    if i in dic:
        dic[i]+= 1
    else:
        dic[i] = 1

flag = 1

if N%2 == 1:
    for m, n in dic.items():
        if m == 0:
            if n != 1:
                flag = 0
                break
        elif m%2 == 1 or n != 2:
            flag = 0
            break
else:
    for m, n in dic.items():
        if m%2==0 or n != 2:
            flag = 0
            break
if flag:
    if N%2 == 0:
        print(2**(N//2)%1000000007)
    else:
        print(2**((N-1)//2)%1000000007)
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())

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

a.sort(reverse=True)
mod = 10**9+7
ans = 1

for i in range(n):
    #print(i,i%2)
    if a[i] != n - 1 - 2*int(i*0.5):
        print(0)
        exit()
    elif i % 2 == 1:
        #print(ans)
        ans = ans * 2 % mod
        
        
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
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//2+1:
    flag = False
if flag:
  print(2**(n//2) % mod)
else:
  print(0)

Submission status: Accepted

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

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

if n % 2 == 0:
    ans = 1
    for i in range(n//2):
        j = 2*i + 1
        ans *= 2 if d[j] == 2 else 0
        ans %= MOD
else:
    ans = 1 if d[0] == 1 else 0
    for i in range(n//2):
        j = 2 * (i+1)
        ans *= 2 if d[j] == 2 else 0
        ans %= MOD

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
m = [2 * ((i - 1 + N % 2) // 2) + 1 - N % 2 for i in range(1, N + 1)]
for i, a in enumerate(sorted([int(a) for a in input().split()])):
  if m[i] != a:
    ret = 0
    break
else:
  ret = 2 ** (N // 2)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

A = sorted([int(_) for _ in input().split()])
if N % 2 == 1:
    if A[0] != 0:
        print(0)
        exit()
    A.pop(0)
    s = 2
else:
    s = 1

ans = 1
MOD = 10 ** 9 + 7
for i in range(0, N // 2):
    v = s + 2 * i
    j = 2 * i
    # print(v, A[j],A[j+1])
    if A[j] != v or A[j + 1] != v:
        print(0)
        exit()
    ans *= 2
    ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
mod=10**9+7
n=int(input())
A=tuple(map(int,input().split()))

def solve(n,A):
    D=defaultdict(int)
    for a in A:
        D[a]+=1
    if n%2:
        if D[0]!=1:
            return 0
        for i in range(2,n,2):
            if D[i]!=2:
                return 0
    else:
        for i in range(1,n,2):
            if D[i]!=2:
                return 0
    return pow(2,n//2,mod)

print(solve(n,A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
N=int(input())
A=list(map(int,input().split()))
A.sort()
Devide_N=10**9+7
Rem_2_32_DN=(2**32)%Devide_N

if N%2==1:
  if (A[0]!=0 or A[1]==0 if N>2 else A[0]!=0):
    print(0)

  else:
    del A[0]
    for ch_n in range(1,(N-1)//2+1):
      if A[0]!=ch_n*2 or A[1]!=ch_n*2:
        break
      else:
        del A[0:2]
    else:
      exp=(N-1)//2
      
      exp_quotient_32=exp//32
      exp_rem_32=exp%32
      Rem_ans_Devide_N=1
      for _ in range(exp_quotient_32):
        Rem_ans_Devide_N=(Rem_ans_Devide_N*Rem_2_32_DN)%Devide_N
        
      print((Rem_ans_Devide_N*2**(exp_rem_32))%Devide_N)
      sys.exit()
    print(0)

else:
  for ch_n in range(1,N//2+1):
    if A[0]!=ch_n*2-1 or A[1]!=ch_n*2-1:
      break
    else:
      del A[0:2]
  else:
    exp=N//2
    
    exp_quotient_32=exp//32
    exp_rem_32=exp%32
    Rem_ans_Devide_N=1
    for _ in range(exp_quotient_32):
      Rem_ans_Devide_N=(Rem_ans_Devide_N*Rem_2_32_DN)%Devide_N
      
    print((Rem_ans_Devide_N*2**(exp_rem_32))%Devide_N)
    sys.exit()
  print(0)

Submission status: Accepted

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

Submission status: Accepted

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

l = len(a)
s = sorted(set(a))
if l % 2 == 0:
    if s == list(range(1, max(s)+1, 2)) and a.count(0) == 0:
        print(2 ** len(s) % (10 ** 9 + 7))
    else:
        print(0)
else:
    s = sorted(set(a))
    if s == list(range(0, max(s)+1, 2)) and a.count(0) == 1:
        print(2 ** (len(s)-1) % (10 ** 9 + 7))
    else:
        print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
A = list(set(a))
flag = True
if n%2==0:
  if a.count(0)>0 or len(A)!=len(a)//2:
    flag=False
else:
  if a.count(0)!=1 or len(A)!=len(a)//2+1:
    flag=False
if flag==True:
    print((2**(n//2))%(10**9+7))
else:
  print(0)

Submission status: Accepted

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

ans = 1
for key, value in c.items():
    if key == 0:
        if n % 2 == 1 and value != 1:
            print(0)
            exit()
        else:
            continue
    elif value == 2:
        ans *= 2
        ans %= MOD
    else:
        print(0)
        exit()
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
alist = list(map(int, input().split()))
len_alist = len(alist)

mod = 10**9 + 7

if len_alist % 2 == 0:
  nums = [2 for _ in range(n//2)]
  for a in alist:
    nums[(a-1)//2] -= 1
    if nums[(a-1)//2] < 0:
      break
  if all(num == 0 for num in nums):
    print(2**(n//2)%mod)
  else:
    print(0)
else:
  nums = [1] + [2 for _ in range((n-1)//2)]
  for a in alist:
    nums[(a)//2] -= 1
    if nums[(a)//2] < 0:
      break
  if all(num == 0 for num in nums):
    print(2**((n-1)//2)%mod)
  else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
arr = [abs(i - (n-i-1)) for i in range(n)]
ans = (2**(n//2)) % (10**9 + 7) if Counter(a) == Counter(arr) else 0
print(ans)

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]!=i+1 or a[i+1]!=i+1:
        print(0)
        exit()
else:
  if a[0]!=0:
    print(0)
    exit()
  for i in range(2,n,2):
    if a[i-1]!=i or a[i]!=i:
      print(0)
      exit()
      
print((2**(n//2))%(10**9+7))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    div = pow(10, 9) + 7
    d = dict()
    if N % 2 == 0:
        for i in range(1, N, 2):
            d[i] = 0
    else:
        for i in range(0, N, 2):
            d[i] = 0
    # print(d)
    # print(A)
    for a in A:
        if a not in d: return 0
        else: d[a] += 1
    # print(d)

    if N % 2 == 0:
        if all(d[a] == 2 for a in d):
            return pow(2, len(d.keys())) % div
        else:
            return 0
    else:
        if d[0] != 1: return 0
        else:
            del d[0]
            if all(d[a] == 2 for a in d):
                return pow(2, len(d.keys())) % div
            else:
                return 0

if __name__ == '__main__':
    print(main())