Problem:


Score : 300 points

Problem Statement

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

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

Constraints

1≦N≦10^5

0≦A_i≦N-1

Input

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

N
A_1 A_2 ... A_N

Output

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

Sample Input 1

5
2 4 4 0 2

Sample Output 1

4

There are four possible orders, as follows:

2,1,4,5,3

2,5,4,1,3

3,1,4,5,2

3,5,4,1,2

Sample Input 2

7
6 4 0 2 4 0 2

Sample Output 2

0

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

Sample Input 3

8
7 5 1 1 7 3 5 3

Sample Output 3

16



Sample input:
5
2 4 4 0 2


Sample output:
4

Submission status: Accepted

Solution code:
def pow2(x):
    if x == 0:
        return 1
    elif x % 2 == 0:
        return (pow2(x/2) ** 2) % (10**9 + 7)
    else:
        return 2 * pow2(x-1)

N = int(input())
a_arr = list(map(int, input().split()))
flag = 0

count_arr = []
for _ in range((N+1)//2):
    count_arr.append(0)

if N%2 == 0: # a = N-1, N-3, ... , 1, 3, ...
    for a in a_arr:
        if a%2 == 0:
            flag = 1
            break
        else:
            count_arr[(a-1)//2] += 1
            if count_arr[(a-1)//2] > 2:
                break
else:
    for a in a_arr: # N-1, N-3, ... 0, 2, ..., N-1
        if a%2 == 1:
            flag = 1
            break
        elif a == 0:
            if count_arr[0] > 0:
                flag = 1
                break
            else:
                count_arr[0] += 1
        else:
            if count_arr[a//2] > 1:
                flag = 1
                break
            else:
                count_arr[a//2] += 1
if flag == 1:
    print(0)
else:
    print(pow2(N//2))

Submission status: Accepted

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

if N % 2 == 0:
  for i in range(0, N, 2):
    if A[i] != A[i+1]:
      print(0)
      break
  else:
    print(2**(N // 2) % 1000000007)
else:
  if A[0] != 0:
    print(0)
  else:
    for i in range(1, N, 2):
      if A[i] != A[i+1]:
        print(0)
        break
    else:
      print(2**((N-1)//2) % 1000000007)

Submission status: Accepted

Solution code:
def c_lining_up(N, A):
    # Nが偶数なら、人数の差の絶対値のリストは[N-1,N-3,...,3,1,1,3,...,N-3,N-1]
    # Nが奇数なら、人数の差の絶対値のリストは[N-1,N-3,...,2,0,2,...,N-3,N-1]
    # でなければならない。このリストとAを共にソートして一致しなければ解は0。

    # 人数の差の絶対値のリストを昇順ソートしたリストを(わざと技巧的に)作る
    b = ([] if N % 2 == 0 else [0]) + [k for k in range(1 if N % 2 == 0 else 2, N, 2) for _ in range(2)]

    ans = 2**(N // 2) % (10**9 + 7) if sorted(A) == b else 0
    return ans

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

Submission status: Accepted

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

A.sort()

ans = 0
for i, Ai in enumerate(A):
    # 0
    if i == 0:
        if Ai == 0: mode = 0
        elif Ai == 1: mode = 1
        else: break
        continue
    # > 1
    if mode == 0 and Ai != ((i + 1) // 2) * 2: break
    elif mode == 1 and Ai != 1 + (i // 2) * 2: break
    else: continue
else:
    ans = (2 ** (N // 2)) % (10 ** 9 + 7)

print(ans)

Submission status: Accepted

Solution code:
import sys
import collections
import itertools
import math
import re
from collections import deque

MOD = 10 ** 9 + 7

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

B = []
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:
    print(2 ** (N // 2) % MOD)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
b=[0,]*N
err=0
cnt=0
ans=1
for i in range(N):
    b[a[i]]+=1
if N%2 == 0:
    for i in range(1,N,2):
        if b[i]!=2:
            err=1
        cnt+=1
    for i in range(0,N,2):
        if b[i]!=0:
            err=1
else:
    if b[0]!=1:
        err=1
    for i in range(2,N,2):
        if b[i]!=2:
            err=1
        cnt+=1
    for i in range(1,N,2):
        if b[i]!=0:
            err=1
if err == 1:
    print("0")
else:
    for i in range(cnt):
        ans=(ans*2)%(10**9+7)
    print(str(ans))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]
mod = 10**9+7
is_odd = N % 2
table = [0]*N
for a in A:
    table[a] += 1
for i in range(N):
    if is_odd and i == 0 and table[i] == 1:
        continue
    if is_odd and i % 2 == 0 and table[i] == 2:
        continue
    if is_odd and i % 2 == 1 and table[i] == 0:
        continue
    if not is_odd and i % 2 == 0 and table[i] == 0:
        continue
    if not is_odd and i % 2 == 1 and table[i] == 2:
        continue
    print(0)
    exit()
print(2**(N//2) % mod)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
# aで嘘がある場合は出力0
# aは,nが奇数なら[0, 2, 2, 4, 4, 6, 6, ...]
# aは,nが偶数なら[1, 1, 3, 3, 5, 5, 7, ...]
valid = [i + (i+n+1) % 2 for i in range(n)]
a = sorted(a)
if a != valid:
    print(0)
else:
    # aが正しいなら答えはaに関係なくnのみで決まる
    # n==5->2**2, n==6->2**3, n==7->2**3, n==8->2**4
    # つまり答えは2**(int(n/2))
    out = 1
    for i in range(int(n/2)):
        out *= 2
        out %= 10**9+7
    print(out)

Submission status: Accepted

Solution code:
import collections

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

cou = collections.Counter(A)

if N % 2 == 0:
    for i in cou.keys():
        if i % 2 == 0 or cou[i] % 2 != 0:
            print(0)
            break
    else:
        print((2**(N//2)) % (10**9+7))

else:
    for i in cou.keys():
        if i % 2 != 0 or cou[i] % 2 != 0:
            if i == 0 and cou[i] == 1:
                aa = 1
            else:
                print(0)
                break
    else:
        print((2**((N-1)//2)) % (10**9+7))

Submission status: Accepted

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

if n % 2 == 0:
  if len(set(nums)) == n // 2:
    print(2**(n//2) % mod)
  else:
    print(0)
else:
  if len(set(nums))== n // 2 + 1 and nums.count(0) == 1:
    print(2**(n//2) % mod)
  else:
    print(0)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
nOdd=len(l)%2==1
if nOdd:
    num=[x for x in range(n) if n%2==0]
else:
    num=[x for x in range(n) if n%2!=0]
dic={}
for i in num:
    dic[i]=0
for i in l:
    dic.setdefault(i,0)
    dic[i]+=1
for i,c in dic.items():
    if i==0 and nOdd:
        if c!=1:
            print(0)
            exit()
    elif i==0 and not(nOdd):
        print(0)
        exit()
    elif c!=2:
        print(0)
        exit()
    


print(pow(2,n//2) % 1000000007)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
nOdd=len(l)%2==1
if nOdd:
    num=[x for x in range(len(l)) if n%2==0]
else:
    num=[x for x in range(len(l)) if n%2!=0]
dic={}
for i in num:
    dic[i]=0
for i in l:
    dic.setdefault(i,0)
    dic[i]+=1
for i,c in dic.items():
    if i==0 and nOdd:
        if c!=1:
            print(0)
            exit()

    elif c!=2:
        print(0)
        exit()
    

        
       

print(pow(2, len(l)//2) % 1000000007)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
nOdd=len(l)%2==1
if nOdd:
    num=[x for x in range(len(l)) if n%2==0]
else:
    num=[x for x in range(len(l)) if n%2!=0]
dic={}
for i in num:
    dic[i]=0
for i in l:
    dic.setdefault(i,0)
    dic[i]+=1
for i,c in dic.items():
    if i==0 and nOdd:
        if c!=1:
            print(0)
            exit()
    elif i==0 and not(nOdd):
        print(0)
        exit()
    elif c!=2:
        print(0)
        exit()
    

        
       

print(pow(2, len(l)//2) % 1000000007)

Submission status: Accepted

Solution code:
N=int(input())
l=list(map(int,input().split()))
a=1
if N%2==0:
    if len(l)!=len(set(l))*2:
        a=0
else:
    if l.count(0) == 1:
        l.remove(0)
        if len(l) != 2*len(set(l)):
            a = 0
    else:
        a=0
if a:
      print((2**(N//2))%(10**9+7))
else:
      print(0)

Submission status: Accepted

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

len_A = len(A)
isOdd = len_A % 2 == 1
m = {}

nums = []
if isOdd:
    nums = [i for i in range(len_A) if i % 2 == 0]
    nums.append(0)
else:
    nums = [i for i in range(len_A) if i % 2 != 0]

for n in nums:
    m[n] = 0

for a in A:
    m.setdefault(a, 0)
    m[a] += 1

# check
for k, v in m.items():
    if k == 0:
        if isOdd:
            if v != 1:
                print(0)
                exit()
            else:
                continue
        else:
            print(0)
            exit()
    elif v == 0 or v > 2:
        print(0)
        exit()

print(pow(2, len_A//2) % 1000000007)

Submission status: Accepted

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

Submission status: Accepted

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

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

if sorted(a)!=sorted(arr):
    print(0)
    exit()

print(pow(2,n//2,MOD))

Submission status: Accepted

Solution code:
N=int(input())
if N%2==0:
    L=[]
    for i in range(int(N/2)):
        L.append(i*2+1)
        L.append(i*2+1)
        
else:
    L=[0]
    for i in range(1,int((N-1)/2)+1):
        L.append(i*2)
        L.append(i*2)

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

if A==L:
    if N%2==0:
        ans=1
        for j in range(int(N/2)):
            ans*=2
            ans%=(10**9+7)
        print(ans)
    else:
        ans=1
        for j in range(int((N-1)/2)):
            ans*=2
            ans%=(10**9+7)
        print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter
N = int( input())
A = Counter(list( map( int, input().split())))
Q = 10**9 + 7
ans = 1
for i in range(N-1, 0, -2):
    if A[i] == 1:
        ans = 0
        break
if N%2 == 1:
    if A[0] != 1:
        ans = 0
print(ans*pow(2,N//2,Q))

Submission status: Accepted

Solution code:
from collections import Counter
N = int( input())
A = Counter(list( map( int, input().split())))
Q = 10**9 + 7
ans = 1
for i in range(N-1, 0, -2):
    if A[i] == 2:
        ans *= 2
        ans %= Q
    else:
        ans = 0
        break
if N%2 == 1:
    if A[0] != 1:
        ans = 0
print(ans)

Submission status: Accepted

Solution code:
import collections

n=int(input())
l=list(map(int,input().split()))
s=collections.Counter(l)
s=s.most_common()
#print(s)
a=1
if n%2==0:
    for i in s:
        if i[1]!=2:
            print(0)
            exit()
        elif i[0]%2!=1 or i[1]//2>n//2:
            print(0)
            exit()
    else:
        for j in range(n//2):
            a=(2*a)%1000000007
    print(a)
elif n%2==1:
    if (0,1) not in s:
        print(0)
        exit()
    else:
        del s[-1]
        #print(s)
        for i in s:
            if i[1]!=2 or i[0]%2!=0 or i[0]//2>n//2:
                print(0)
                exit()
        else:
            for j in range(n//2):
                a=(2*a)%1000000007
    print(a)

Submission status: Accepted

Solution code:
from collections import Counter

M = 10 ** 9 + 7

def main():
    n = int(input())
    a = [int(s) for s in input().split()]
    print(solve(a, n))

def solve(a, n):
    counter = Counter(a)

    if n % 2 == 0:
        for i in range(1, n, 2):
            if counter.get(i, None) != 2:
                return 0
    else:
        if counter.get(0, None) != 1:
            return 0
        for i in range(2, n, 2):
            if counter.get(i, None) != 2:
                return 0

    return modpow(2, n // 2, M)

def modpow(a, b, m):
    r = 1

    while b != 0:
        if b & 0x01:
            r = (r * a) % m
        a = (a * a) % m
        b >>= 1

    return r

main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
An = list(map(int, input().split()))
DIV = 10**9 + 7

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

abs_cnt = {}
for Ai in An:
    if Ai in abs_cnt:
        abs_cnt[Ai] += 1
    else:
        abs_cnt[Ai] = 1

# print(abs_cnt)

jijo = 0
if N%2 == 0:
    for k,v in abs_cnt.items():
        if k % 2 == 1 and v == 2:
            jijo += 1
        else:
            print(0)
            exit()
else:
    for k, v in abs_cnt.items():
        if k % 2 == 0 and v == 2:
            jijo += 1
        elif k == 0 and v == 1:
            pass
        else:
            print(0)
            exit()

print(2**jijo%DIV)

Submission status: Accepted

Solution code:
from collections import Counter


def solve(N, As):
    c = Counter(As)
    n = 10 ** 9 + 7
    if c['0'] == N % 2 and \
            all([v == 2 and int(i) % 2 == (N + 1) % 2 for i, v in c.items() if i != '0']):
        return pow(2, N // 2, n)

    return 0


if __name__ == "__main__":
    N = int(input())
    As = input().split(" ")
    print(solve(N, As))

Submission status: Accepted

Solution code:
n = int(input())
nums = {0:0}

for i in list(map(int, input().split())):
    if i in nums:
        nums[i] += 1
        if nums[i] > 2:
            ans = 0
            break
    else:
        nums[i] = 1
        
if n % 2 == 0:
    if 1 in nums.values():
        ans = 0
    else:
        ans = 2**(n//2)
        
else:
    if nums[0] == 1:
        del nums[0]
        if 1 in nums.values():
            ans = 0
        else:
            ans = 2**((n-1)//2)
    else:
        ans = 0
        
print(ans % (10**9+7))

Submission status: Accepted

Solution code:
iN = int(input())
aA = [int(_) for _ in input().split()]
aA.sort()
iD = 10**9 + 7



iRet = 0
if iN % 2 == 0:
    aR = [x if x % 2 == 1 else x + 1 for x in range(iN)]
else:
    aR = [x if x % 2 == 0 else x + 1 for x in range(iN)]
if aA == aR:
    print(pow(2,iN//2,iD))
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
flag = True
if n%2 == 1:
  for i in range(n):
    if a[i] != i+i%2:
      flag = False
else:
  for i in range(n):
    if a[i] != i+1-i%2:
      flag = False
if not flag:
  print(0)
else:
  s = 1
  for _ in range(n//2):
    s = s*2%1000000007
  print(s)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1
count = 0
if N == 1:
    if A[0] == 1:
        ans = 1
    else:
        ans = 0

elif N % 2 == 0:
    for i in range(1, int(N/2)+1):
        if A[i*2-1] == 2:
            count += 1
        else:
            ans = 0
else:
    if A[0] == 1:
        for i in range(1, int(N/2)+1):
            if A[i*2] == 2:
                count += 1

            else:
                ans = 0
    else:
        ans = 0
for i in range(count):
    ans *= 2
    ans %= 1000000007
print(ans)

Submission status: Accepted

Solution code:
def mod_pow(a,p,mod):# a^p を求めるアルゴリズム

    if p == 0:
        return 1
    elif p%2 == 1:
        return a * mod_pow(a,p-1,mod)
    else:
        half = mod_pow(a,p//2,mod) %mod
    return half * half % mod

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

B = [0 for i in range(N)]
max_b = 0
mod =10**9 + 7

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

if N%2 == 1:
    for i,b in enumerate(B):
        if i == 0:
            if b != 1:
                print(0)
                exit()

        elif b != 2 and b != 0:
            print(0)
            exit()
    p = (N - 1)//2

else:
    for i,b in enumerate(B):
        if b != 2 and b != 0:
            print(0)
            exit()
    p = (N)//2

ans = mod_pow(2,p,mod)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
s=sorted([i for i in range((N+1)%2, N, 2)]*2)
if N%2 == 1:
    s.pop(0)
print((2**(N//2))%1000000007 if sorted([int(i) for i in input().split()])==s else 0)

Submission status: Accepted

Solution code:
import sys
N = int(input())
A = list(map(int, input().split()))
A.sort()
MOD = int(1e9) + 7


if N % 2 == 0:
    ans = 1
    for i in range(N//2):
        if A[2*i] == A[2*i+1] == 2*i+1:
            ans *= 2
            ans %= MOD
        else:
            print(0)
            sys.exit()
            
else:
    if A[0] == 0:
        ans = 1
    else:
        print(0)
        sys.exit()

    for i in range(N//2):
        if A[2*i+1] == A[2*i+2] == 2*(i+1):
            ans *= 2
            ans %= MOD
        else:
            print(0)
            sys.exit()
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
mod = int(1e9+7)
A = sorted(list(map(int, input().split())))


N_mod = N%2
if N == 1:
    if A[0] == 0:
        print(1)
        exit()
    else:
        print(0)
        exit()
    
if N_mod == 1 and A[0] == 0:
    A = A[1:]
    num = 2
else:
    num = 1
ans = 1
for i in range(0, N-N_mod, 2):
    if A[i] == A[i+1] and A[i] == num:
        ans = int(ans * 2)
        ans = int(ans % mod)
        num += 2
    else:
        ans = 0
        break
print(ans)

Submission status: Accepted

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

s=list(sorted(s))
if n%2==1:
    s.remove(0)
    for i in range(n-1):
        s[i] -= 1

a = []
for i in range(n//2):
    a.append(2*i+1)

if s[0::2]==s[1::2] and s[0::2] ==a :
    print((2**((len(s))//2))%(10**9+7))
else:
    print(0)

Submission status: Accepted

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

if N % 2 == 0: #報告値はすべて奇数かつ1~N-1まで2回ずつ出る必要がある
    i = 0
    while i < N:
        if A[i] != i+1 or A[i+1] != i+1:
            Appropriate = False
            break
        else:
            ans *= 2
            ans %= mod
            i+=2
else: #報告値はすべて偶数で0が1回、2~N-1が2回ずつ出る必要がある
    i = 1
    if A[0] != 0 or A.count(0) > 2:
        Appropriate = False
    else:
        while i < N:
            if A[i] != i+1 or A[i+1] != i+1:
                Appropriate = False
                break
            else:
                ans *= 2
                ans %= mod
                i += 2

print(ans if Appropriate else 0)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
b = [0] * n

for ai in a:
    if n % 2 == ai % 2:
        break
    left = (n - ai) // 2
    right = (n + ai) // 2
    if b[left] == 0:
        b[left] = 1
    elif b[right] == 0:
        b[right] = 1
    else:
        break

if 0 in b:
    ans = 0
elif n % 2 == 0:
    ans = pow(2, len(set(a)), mod)
else:
    ans = pow(2, len(set(a)) - 1, mod)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    C = Counter(list(map(int, input().split())))
    MOD = 10 ** 9 + 7

    ans = 1
    num_zero = 0
    for k, v in C.items():
        if k == 0:
            num_zero += 1
        elif v == 2:
            ans *= 2
            ans %= MOD
        else:
            print(0)
            return
    
    if N % 2 != num_zero:
        print(0)
        return

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
il = lambda: list(map(int, input().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]
mod = int(1e9+7)

n = int(input())
a = il()
dic = dict()
for i in a:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
flag = 1
for i, j in dic.items():
    if i == 0:
        if j != 1:
            flag = 0
    else:
        if j != 2:
            flag = 0
if flag:
    print(pow(2, n//2)%mod)
else:
    print(0)

Submission status: Accepted

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

A.sort()

i = 0

if N%2 == 1:
  if A[0] != 0:
    print(0)
    exit(0)
  i = 1

cnt = 0

while i < N:
  if i+1 == A[i] and i+1 == A[i+1]:
    cnt += 1
    i = i + 2
    continue
  else:
    print(0)
    exit(0)
    
ans = 1
for j in range(cnt):
  ans = ans * 2 % int(1e9 +7)
  
print(ans)

Submission status: Accepted

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

def f():
    As = sorted(A)
    if N % 2:
        if As[0] != 0: return 0
        if any((i // 2 + 1)*2 != a for i,a in enumerate(As[1:])): return 0
    else:
        if any((i // 2)*2 + 1 != a for i,a in enumerate(As)): return 0
    return pow(2, N//2, 10**9 + 7)

print(f())

Submission status: Accepted

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

from collections import Counter
def f():
    cnt = Counter(A)
    m = N - 1
    for k, v in cnt.items():
        if k == 0:
            if v == 1:
                continue
            else:
                return 0
        else:
            if v != 2 or k > m:
                return 0
    return pow(2, N//2, 10**9 + 7)

print(f())

Submission status: Accepted

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

from collections import Counter

def f():
    cnt = Counter(A)
    m = N - 1
    for k, v in cnt.items():
        if k == 0 and v == 1: continue
        if v != 2 or k > m:
            return 0
    return pow(2, N//2, 10**9 + 7)

print(f())

Submission status: Accepted

Solution code:
from collections import defaultdict

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

mod = 10 ** 9 + 7
c = defaultdict(int)
for a in A:
    if a != 0:
        x = (N - 1 + a) // 2
        y = (N - 1 - a) // 2
        c[(x, y)] += 1

ans = 1
for v in c.values():
    if v == 2:
        ans *= 2
    else:
        ans = 0
        break
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
A = [int(x) for x in input().split()]
p = 10 ** 9 + 7
C = defaultdict(int)
mod = 1 - N % 2
for a in A:
  if a % 2 != mod:
    print(0)
    break
  elif a >= N:
    print(0)
    break
  else:
    C[a] += 1
    if a and C[a] > 2:
      print(0)
      break
    elif a == 0 and C[a] > 1:
      print(0)
      break
else:
  print(2 ** (N // 2) % p)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
def main():
    if A[0] == N % 2:
        print(0)
        return 0
    if len(A) == 1 and A[0] == 0:
        print(1)
        return 0
    elif len(A) == 1:
        print(0)
        return 0
    if A[0] == 0:
        del A[0]
    if A[0] == 0:
        print(0)
        return 0
    i = 1
    while True:
        if i >= len(A):
            break
        if len(A) % 2 != 0:
            print(0)
            return 0
        if A[i] != A[i - 1]:
            print(0)
            return 0
        i += 2
    i = 2
    while True:
        if i >= len(A):
            break
        if A[i] == A[i - 1]:
            print(0)
            return 0
        i += 2
    print(pow(2, len(A) // 2) % 1000000007)
main()

Submission status: Accepted

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

dic = {}
ans = 1

for Ai in A:
    if Ai not in dic:
        dic[Ai] = 1
    else:
        dic[Ai] += 1

for t in dic.items():
    ans *= N % 2 != t[0] % 2

    if t[0] == 0:
        ans *= t[1] == 1
    else:
        ans = (ans * 2 * (t[1] == 2)) % (10 ** 9 + 7)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 1
if N % 2 == 0:
    if len(A) != 2*len(set(A)):
        ans = 0
else:
    if A.count(0) == 1:
        A.remove(0)
        if len(A) != 2*len(set(A)):
            ans = 0
    else:
        ans = 0
if ans == 0:
    print(0)
else:
    print((2**(N//2))%(10**9+7))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int, input().split()))
import math
x=[0 for _ in range(n)]
if n%2!=0:
    x[0]+=1
for i in range(n):
    x[a[i]]+=1

j=True
for t in x:
    if t%2!=0:
        j=False
print(2**(n//2)%(10**9+7) if j else 0)

Submission status: Accepted

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

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

Submission status: Accepted

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

ctr = Counter(A)
if N%2 and ctr[0] != 1:
    print(0)
    exit()

if N%2:
    for i in range(2,N,2):
        if ctr[i] != 2:
            print(0)
            exit()
else:
    for i in range(1,N,2):
        if ctr[i] != 2:
            print(0)
            exit()

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

Submission status: Accepted

Solution code:
def c_lining_up(N, A):
    # Nが偶数なら、人数の差の絶対値のリストは[N-1,N-3,...,3,1,1,3,...,N-3,N-1]
    # Nが奇数なら、人数の差の絶対値のリストは[N-1,N-3,...,2,0,2,...,N-3,N-1]
    # でなければならない。このリストとAを共にソートして一致しなければ解は0。

    # 人数の差の絶対値のリストを昇順ソートしたものに等しいリストを得る
    if N % 2 == 0:
        B = [i for i in range(1, N, 2) for _ in range(2)]
    else:
        B = [0] + [i for i in range(2, N, 2) for _ in range(2)]

    ans = 2**(N // 2) % (10**9 + 7) if sorted(A) == B else 0
    return ans

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

Submission status: Accepted

Solution code:
N = int(input())
input_list = sorted([int(i) for i in input().split()])

mod = 10 ** 9 + 7

if N % 2 == 1:
    if input_list[0] != 0:
        print(0)
    else:
        if N == 1:
            print(1)
        flag = 2
        limit = (N - 1) // 2
        for i in range(1, limit, 2):
            if input_list[i] == flag and input_list[i+1] == flag:
                flag += 2
                if i == limit-1:
                    print((2**limit) % mod)
            else:
                print(0)
                break
elif N % 2 == 0:
    flag = 1
    limit = N
    for i in range(0, limit, 2):
        if input_list[i] == flag and input_list[i+1] == flag:
            flag += 2
            if i == limit-2:
                print((2**(N//2)) % mod)
                break
        else:
            print(0)
            break

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=[0]*(N//2+N%2)
IndexCount=0
IndexRe=0
Divider=pow(10,9)+7
ans=1
if N%2==0:
    for i in range(N):
        if A[i]%2==1 and (A[i]+1)/2<=N/2:
            B[(A[i]-1)//2]+=1
        else:
            print(0)
            exit()
    for i in range((N//2+N%2)):
        if B[i]!=2:
            print(0)
            exit()
    IndexCount=int((N/2)//1000)
    IndexRe=int((N/2)%1000)
    for i in range(IndexCount):
        ans=(ans*(pow(2,1000)%Divider))%Divider
    ans=(ans*(pow(2,IndexRe)%Divider))%Divider
    print(ans)
elif N%2==1:
    for i in range(N):
        if A[i]%2==0 and A[i]/2<=(N-1)/2:
            B[A[i]//2]+=1
        else:
            print(0)
            exit()
    if B[0]!=1:
        print(0)
        exit()
    for i in range((N//2+N%2)-1):
        if B[i+1]!=2:
            print(0)
            exit()
    IndexCount=int(((N-1)/2)//1000)
    IndexRe=int(((N-1)/2)%1000)
    for i in range(IndexCount):
        ans=(ans*(pow(2,1000)%Divider))%Divider
    ans=(ans*(pow(2,IndexRe)%Divider))%Divider
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 23 22:15:42 2018
ABC050C
@author: maezawa
"""

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

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