Problem:


Score : 300 points

Problem Statement

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

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

Constraints

1≦N≦10^5

0≦A_i≦N-1

Input

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

N
A_1 A_2 ... A_N

Output

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

Sample Input 1

5
2 4 4 0 2

Sample Output 1

4

There are four possible orders, as follows:

2,1,4,5,3

2,5,4,1,3

3,1,4,5,2

3,5,4,1,2

Sample Input 2

7
6 4 0 2 4 0 2

Sample Output 2

0

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

Sample Input 3

8
7 5 1 1 7 3 5 3

Sample Output 3

16



Sample input:
5
2 4 4 0 2


Sample output:
4

Submission status: Accepted

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

    flag = True
    for i in range(n):
        if rec[i] > 2:
            flag = False

    if rec[0] == 0 and flag:
        print((2 ** (n // 2)) % mod)
    else:
        print(0)
else:
    for i in range(n):
       rec[a[i]] += 1

    flag = True
    for i in range(n):
        if rec[i] > 2:
            flag = False

    if rec[0] == 1 and flag:
        print((2 ** (n // 2)) % mod)
    else:
        print(0)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
a = list(map(int,input().split()))
g = itertools.groupby(sorted(a))
for i,(k,v) in enumerate(g):
    if n%2==1:
        f1 = i==0 and k==0 and len(list(v))==1
        f2 = i!=0 and k==i*2 and len(list(v))==2
        if not (f1 or f2):
            print(0)
            exit()
    else:
        if k!=2*i+1 or len(list(v))!=2:
            print(0)
            exit()
print((2**(n//2))%(10**9+7))

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-
from collections import Counter

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    counter = Counter(a_list)
    ans = 1

    if n % 2 == 0:
        if all(counter[i] == 2 for i in range(1, n, 2)):
            ans = 2 ** (n // 2)
        else:
            ans = 0
    else:
        if all(counter[i] == 2 for i in range(2, n, 2)) and counter[0] == 1:
            ans = 2 ** (n // 2)
        else:
            ans = 0
    print(ans % (10 ** 9 + 7))
        
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-
from collections import Counter

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    counter = Counter(a_list)

    ans = 1
    if n % 2 != 0:
        for i in range(0, n, 2):
            c = counter[i]
            if (i == 0 and c != 1) or c == 0:
                print(0)
                exit()
            else:
                ans *= c
    else:
        for i in range(1, n, 2):
            c = counter[i]
            if c == 0:
                print(0)
                exit()
            else:
                ans *= c
    print(ans % (10 ** 9 + 7))
        
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
a = tuple(map(int, input().split(" ")))
# n = 10000
# a = tuple(sum([[i, i] for i in range(1, n+1, 2)], [])[:n])

a_counter = Counter(a)
a_counter[int(n%2==0)] = 2

if set(a_counter.values()) == {2}:
    print((2 ** (n//2)) % (10**9+7))
else:
    print(0)

Submission status: Accepted

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

cnt = [0 for i in range(N)]
ans = 1

if N % 2 == 0:
    for i in range(N):
        if A[i] % 2 == 0:
            print(0)
            exit()
        cnt[A[i]] += 1
        if cnt[A[i]] > 2:
            print(0)
            exit()
        if cnt[A[i]] == 1:
            ans = (ans * 2) % (10 ** 9 + 7)
    print(ans)
else:
    for i in range(N):
        if A[i] % 2 == 1:
            print(0)
            exit()
        if A[i] > 0:
            cnt[A[i]] += 1
            if cnt[A[i]] > 2:
                print(0)
                exit()
            if cnt[A[i]] == 1:
                ans = (ans * 2) % (10 ** 9 + 7)
        if A[i] == 0:
            cnt[0] += 1
            if cnt[0] > 1:
                print(0)
                exit()
    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = Counter(map(int, input().split()))
f = True
if N == 1 and A[0] == 1:
    print(1)
    exit()

if N % 2 == 1:
    if A[0] != 1:
        f = False
    else:
        del A[0]
    if set(A) != set(range(2, N, 2)) or set(A.values()) != {2}:
        f = False
else:
    if set(A) != set(range(1, N, 2)) or set(A.values()) != {2}:
        f = False
if not f:
    print(0)
else:
    print(2 ** len(A) % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
from collections import Counter

MOD = 10**9+7

def judge(N: int, A: list) -> int:
    # 報告数カウンタ
    cnt = Counter(A)
    
    # 奇数
    if N%2 == 1:
        #矛盾チェック
        for k,v in cnt.items():
            if k==0:
                if v != 1:
                    return 0
            else:
                if v != 2:
                    return 0
        
        # 矛盾がなければ2**(N//2)
        ans = 1
        for i in range(N//2):
            ans = (ans*2) %MOD
        
        return ans
    
    else:
        #矛盾チェック
        for k,v in cnt.items():
            if v != 2:
                return 0
            
        # 矛盾がなければ2**(N//2)
        ans = 1
        for i in range(N//2):
            ans = (ans*2) %MOD
        
        return ans
                
N = int(input())
A = list(map(int, input().split()))

print(judge(N,A))

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
l=Counter(map(int,input().split()))
o=int(1e9+7)
if n%2:
  if not (0 in l and l[0]==1):
    print(0)
  elif n//2!=list(l.values()).count(2):
    print(0)
  else:
    print(2**(n//2)%o)
else:
  if n//2!=list(l.values()).count(2):
    print(0)
  else:
    print(2**(n//2)%o)

Submission status: Accepted

Solution code:
import collections
N = int(input())
a = list(map(int,input().split()))
mod = (10**9+7)
if N%2 !=0:
    if sum(a)%2!=0 or max(a)>N or a.count(0)!=1 or len(set(a))!=N//2+1:
        print(0)
    else:
        print(2**(len(set(a))-1)%mod)
elif N%2 ==0:
    if sum(a)%2!=0 or max(a)>N or len(set(a))!=N//2:
        print(0)
    else:
        print(2**len(set(a))%mod)

Submission status: Accepted

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

exp = []
if n % 2 == 0:
    for i in range(0, n // 2):
        exp.append(2 * i + 1)
        exp.append(2 * i + 1)
else:
    exp.append(0)
    for i in range(1, n // 2 + 1):
        exp.append(2 * i)
        exp.append(2 * i)

a_sorted = sorted(a)

if a_sorted == exp:
    ans = 1
    for i in range(0, n // 2):
        ans *= 2
        if ans > 1000000007:
            ans -= 1000000007
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
def inpl(): return input().split()

n = int(input())
a = sorted(list(map(int, inpl())))
p = 10 ** 9 + 7

if a[0] == 0:
    st = 1
    next_value = 2
else:
    st = 0
    next_value = 1

ans = 1
found = False
for i in range(st, n):    
    if (next_value == a[i]):
        if found:
            next_value += 2
            found = False
            ans *= 2
            if ans > p:
                ans %= p
        else:
            found = True
    else:
        ans = 0
        break
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())
A = [int(i) for i in input().split()]
p = 10 ** 9 + 7

m = n % 2 == 0
cnt = defaultdict(int)

for a in A:
    if (a % 2 == 0) == m:
        print(0)
        exit()
    cnt[a] += 1

if cnt[0] > 1:
    print(0)
    exit(0)

del cnt[0]

for c in cnt.values():
    if c != 2:
        print(0)
        exit(0)

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

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())
A = [int(i) for i in input().split()]
p = 10 ** 9 + 7

m = n % 2 == 0
cnt = defaultdict(int)

for a in A:
    if (a % 2 == 0) == m:
        print(0)
        exit()
    cnt[a] += 1
    if cnt[a] > 2 or cnt[0] > 1:
        print(0)
        exit()

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

Submission status: Accepted

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

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

BN = [0] * (N//2+1)

# 偶奇で分けて集計
for i in range(N):
    if N % 2 != 0:
        BN[N//2 - AN[i]//2] += 1
    else:
        BN[N//2 - (AN[i]//2+1)] += 1

# 偶数の場合は真ん中を考慮
ans = 0
for i in range(len(BN)):
    if BN[i] > 2 or N % 2 != 0 and BN[-1] > 1:
        print(0)
        exit()

# 結果出力
print(2 ** (N//2) % (10 ** 9 +7))

Submission status: Accepted

Solution code:
mod=1000000007

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

t.sort()

f=1

if n%2==1:
    for i in range(n):
        if not t[i]//2==(i+1)//2 or t[i]%2==1:
            f=-1
else:
    for i in range(n):
        if not t[i]//2==i//2 or t[i]%2==0:
            f=-1

if f<0:
    print(0)
else:
    ans=1
    for i in range(n//2):
        ans=(ans*2)%mod
    print(ans)

Submission status: Accepted

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

if n%2 == 0:
    valid = True
    for i in range(n):
        if i%2 == 0: v = i+1
        else: v = i
        if a[i] != v:
            valid = False
            print(0)
            break
    if valid:
        print(2**(n//2)%MOD)

else:
    valid = True
    for i in range(n):
        if i%2 != 0: v = i+1
        else: v = i
        if a[i] != v:
            valid = False
            print(0)
            break
    if valid:
        print(2**(n//2)%MOD)

Submission status: Accepted

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

a_dict = {}
for v in a:
    if v in a_dict:
        a_dict[v] += 1
    else:
        a_dict[v] = 1

can = True
if n % 2 == 0:
    possible_list = {i: True for i in range(1, n, 2)}
    for k, v in a_dict.items():
        if v != 2 or k not in possible_list:
            can = False
            break
else:
    possible_list = {i: True for i in range(0, n, 2)}
    if 0 not in a_dict:
        can = False
    elif a_dict[0] != 1:
        can = False
    else:
        a_dict[0] = 2
        for k, v in a_dict.items():
            if v != 2 or k not in possible_list:
                can = False
                break

if can:
    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()]

candidates = []

for i in range(N // 2) :
    d = N - 1 - 2*i
    candidates.append(d)
    candidates.append(d)
    
if N % 2 != 0: 
    candidates.append(0)
    
if sorted(candidates) != sorted(a) :
    print(0)
else :
    c_dict = {}
    for c in candidates :
        if c in c_dict.keys() :
            c_dict[c] += 1
        else: 
            c_dict[c] = 1
            
    prod = 1
    for v in c_dict.values() :
        prod *= v
        
    print(prod % (10**9 + 7))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
cnt = {i : 0 for i in range(N)}
for a in A:
    cnt[a] += 1
exist_ans = True
if N % 2:
    if cnt[0] != 1:
        exiet_ans = False
    for i in range(2, N, 2):
        if cnt[i] != 2:
            exist_ans = False
else:
    for i in range(1, N, 2):
        if cnt[1] != 2:
            exist_ans = False
if exist_ans:
    print(2**(N//2) % (10**9 +7))
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=list(map(int, input().split()))
b=Counter(a)
ans=0
if n%2==1:
    for i in b:
        if i==0:
            if b[i]!=1:ans=1
        elif b[i]!=2 or i%2==1 or i>n:ans=1
else:
    for i in b:
        if b[i]!=2 or i%2==0 or i>n:ans=1
if ans==1:print(0)
else: print((2**(len(a)//2))%(10**9+7))

Submission status: Accepted

Solution code:
n = int(input())

arr = map(int,raw_input().split())

sums = [0 for i in range(n)]

for i in range(n):
	sums[arr[i]] += 1


isprinted = False
mod = 1000000007
if n%2 == 1:
	if sums[0] == 1:
		for i in range(2,n,2):
			if sums[i] != 2:
				print 0
				isprinted = True
				break

		if not isprinted :
			print 2**((n-1)/2)%mod
	else :
		print 0

else :
	for i in range(1,n,2):
		if sums[i] != 2:
			print 0
			isprinted = True
			break

	if not isprinted:
		print 2**(n/2)%mod

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = map(int, input().split())
c = Counter(a)
q,r = divmod(n, 2)
if r:
    b = [c[0] == 1]
    for i in range(1,q+1):
        b.append(c[i*2] == 2)
    if all(b):
        print(2**q%(10**9+7))
    else:
        print(0)
else:
    b = []
    for i in range(q):
        b.append(c[i*2+1] == 2)
    if all(b):
        print(2**q%(10**9+7))
    else:
        print(0)

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

def m():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    if a[0] == 0:
        tmp = 2
        for i in range(1, n, 2):
            for k in range(2):
                if a[i+k] != tmp:
                    return 0
            tmp += 2
        tmp -=2
        return (2 ** (tmp//2))%MOD

    if a[0] == 1:
        tmp = 1
        for i in range(0, n, 2):
            for k in range(2):
                if a[i+k] != tmp:
                    return 0
            tmp += 2
        tmp -= 1
        return (2 ** (tmp//2))%MOD
    return 0


print(m())

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
MOD = 10**9+7
ctr = Counter(A)
if N%2:
    if ctr[0] != 1:
        print(0)
        exit()
    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()
print(2**(N//2) % MOD)

Submission status: Accepted

Solution code:
N = int(input())
evenFlg = False
flg = False
lastIndex = int((N - (N % 2))/2)
if N % 2 == 0: evenFlg = True
ary = [2 for i in range(lastIndex)]
l = list(map(int, input().split()))
# for i in range(lastIndex):
#   ary.append(2)

if not evenFlg: ary.insert(0, 1)

for r in range(N):
    if evenFlg:
        l[r] = (l[r] - 1) / 2
    else:
        l[r] /= 2
    l[r] = int(l[r])
    ary[l[r]] -= 1
for k in range(lastIndex):
    if ary[k] != 0:
        flg = True
        break
ans = 0 if flg else (2**lastIndex) % (10**9 + 7)

print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    if N%2 == 1:
        if A[0] != 0:
            return 0
        for i in range(1,N,2):
            if (A[i]==i+1 and A[i+1]==i+1)==False:
                return 0
        return (2**(N//2))%(10**9+7)
    else:
        for i in range(0,N,2):
            if (A[i]==i+1 and A[i+1]==i+1)==False:
                return 0
        return (2**(N//2))%(10**9+7)

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

Submission status: Accepted

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

def is_valid(ctr):
    if N%2:
        if ctr[0] != 1:
            return False
        for i in range(2,N,2):
            if ctr[i] != 2:
                return False
    else:
        for i in range(1,N,2):
            if ctr[i] != 2:
                return False
    return True

if is_valid(ctr):
    MOD = 10**9+7
    print(2**(N//2) % MOD)
else:
    print(0)

Submission status: Accepted

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

flag = 1
if n % 2 == 1 :
    for i in range(0,n):
        if i == 0 :
            co = 0
            if x[i] == 0:
                x[i] = -1

        elif i != 0 and i <= n-2 and (i) % 2 ==1 :
            if x[i] == i+1 and x[i+1] == i+ 1 and (i+1) % 2 == 0:
                x[i] = -1
                x[i+1] = -1
        else:
            continue
else:
    for i in range(0,n):  
        if x[i] == i+1 and x[i+1] == i+ 1 and (i+1) % 2 == 1 and i <= n-2:
            x[i] = -1
            x[i+1] = -1
        else:
            continue
            
if list(set(x)) == [-1]:
    ans = 1
    if n >=2:
        for i in range(n // 2 ):
            ans = (ans * 2) % (10 ** 9 + 7)
        
    print(ans)
else:
    print(0)

Submission status: Accepted

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

    pos = True
    num_dict = {}
    if n % 2 == 0:
        for i in range(n):
            if a[i] % 2 == 0:
                pos = False
                break

            num_dict[a[i]] = num_dict.get(a[i], 0) + 1

    else:
        cnt0 = 0
        for i in range(n):
            if a[i] % 2 == 1:
                pos = False
                break
            elif a[i] == 0:
                cnt0 += 1
            else:
                num_dict[a[i]] = num_dict.get(a[i], 0) + 1

        if cnt0 != 1:
            pos = False

    for i in num_dict:
        if num_dict[i] != 2:
            pos = False

    if pos:
        com = 1
        for i in range(len(num_dict)):
            com *= 2
            if com >= 10 ** 9 + 7:
                com %= 10 ** 9 + 7

        print(com)
    else:
        print(0)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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:
  print(2**(n//2)%mod)
elif not n % 2 == 0 and l.count(0) == 1:
  print(2**((n-1)//2)%mod)
else:
  print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted([int(i) for i in input().split()],reverse=True)
x = n+1

for i in range(len(a)):
  if i%2 ==0:
    x-=2
  if a[i] != x:
    print(0)
    break
else:
  print((2**(n//2))%(10**9 +7))

Submission status: Accepted

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

if a == able:
    r = n//2
    ans = 1
    for i in range(0,r):
        ans = ans * 2 % mod
    print(int(ans))
else:
    print(0)

Submission status: Accepted

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

if N%2==0:
    for k in B:
        if k%2==0 or B[k]!=2:
            print(0)
            exit(0)
else:
    if B[0] != 1:
        print(0)
        exit(0)
    B[0] = 2
    for k in B:
        if k%2==1 or B[k]!=2:
            print(0)
            exit(0)

ans = 1
for k in range(N//2):
    ans *= 2
    ans %= 10**9+7
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))
q = {}
flag = 0
for i in range(N):
    if A[i] in q:
        q[A[i]] += 1
    else:
        q[A[i]] = 1
if N % 2 == 0:
    even = [2*i+1 for i in range(N // 2)]
    for i in even:
        if i not in q.keys():
            flag = 1
            break
        elif q[i] != 2:
            flag = 1
            break
    if flag == 1:
        print(0)
    else:
        print(pow(2, len(q.keys())) % 1000000007)
else:
    odd = [2*i for i in range((N+1) // 2)]
    for i in odd:
        if i not in q.keys():
            flag = 1
            break
        elif i == 0 and q[i] != 1:
            flag = 1
            break
        elif i != 0 and q[i] != 2:
            flag = 1
            break
    if flag == 1:
        print(0)
    else:
        print(pow(2, (len(q.keys()) - 1)) % 1000000007)

Submission status: Accepted

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

def beki(n):
    ans = 1
    for _ in range(int(n)):
        ans = (ans * 2) % (10 ** 9 + 7)
    return int(ans)

if n % 2 == 0:
    hikaku = []
    for i in range(1, n, 2):
        hikaku += [i, i]
    if sorted(a) == hikaku:
        print(beki(n / 2))
    else:
        print(0)

elif n == 1:
    if a == [0]:
        print(1)
    else:
        print(0)
else:
    hikaku = [0]
    for i in range(2, n, 2):
        hikaku += [i, i]
    if sorted(a) == hikaku:
        print(beki((n - 1) / 2))
    else:
        print(0)

Submission status: Accepted

Solution code:
N=int(input())
s=list(map(int,input().split()))
if N%2==1:
    s.remove(0)
s=list(sorted(s))
if s[0::2]==s[1::2]:
    print((2**((len(s))//2))%(10**9+7))
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
data=Counter(a)
if n%2==1:
    if 0 not in a:
        print(0)
        exit()
    else:
        a.remove(0)
        data=Counter(a)
        for i in data.values():
            if i!=2:
                print(0)
                exit()
    print((2**(n//2))%mod)
else:
    for i in data.values():
        if i!=2:
            print(0)
            exit()
    print((2**(n//2))%mod)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
from collections import Counter
data=Counter(a)
if n%2==0:
    if 0  in a:
        print(0)
        exit()
    else:
        for i in data.values():
            if i!=2:
                print(0)
                exit()
    print((2**(n//2))%mod)
else:
    if a.count(0)!=1:
        print(0)
        exit()
    else:
        a.remove(0)
        data=Counter(a)
        for i in data.values():
            if i!=2:
                print(0)
                exit()
    print((2**(n//2))%mod)

Submission status: Accepted

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

C = Counter(A).most_common()
p = 0
for k,v in C:
    if v==1 and k==0 and N%2==1:
        continue
    elif v==2:
        p += 1
        continue
    else:
        p = 0
        break
if N==1 and A==[0]:
    print(1)
else:
    print(p if p==0 else (2**p)%(10**9+7))

Submission status: Accepted

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

C = Counter(A).most_common()
p = 0
for k,v in C:
    if v==1 and k==0 and N%2==1:
        continue
    elif v==2:
        p += 1
        continue
    else:
        p = 0
        break
if N==1:
    print(1)
else:
    print(p if p==0 else (2**p)%(10**9+7))

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
src = list(map(int,input().split()))
ctr = Counter(src)

def valid():
    if N%2:
        if ctr[0] != 1: return False
        i = 2
        while i <= N:
            if ctr[i] != 2: return False
            i += 2
    else:
        i = 1
        while i <= N:
            if ctr[i] != 2: return False
            i += 2
    return True

MOD = 10**9+7
print(2**(N//2) % MOD if valid() else 0)

Submission status: Accepted

Solution code:
def calc(n):
	ans = 1
	for i in range(0, n):
		ans = ans * 2
		if ans >= 1000000007:
			ans = ans - 1000000007
	return ans

def judge(n, lst):
	start = 0
	if n%2 == 1:
		if lst[0] != 0: return False
		else: start = 1
	for i in range(0, n/2):
		if lst[2*i+start] != lst[2*i+start+1]:
			return False
		elif lst[2*i+start] != 2*i+1+start:
			return False
	return True

n = int(raw_input())
inpt = map(int, raw_input().split())
inpt.sort()

if judge(n, inpt):
	print calc(n/2)
else:
	print 0

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
di = defaultdict(int)
right = True
for i in range(n):
    if n < a[i]:
        right = False
    if (n%2==0 and a[i]%2==1):
        di[a[i]] += 1
    elif (n%2==1 and a[i]%2==0):
        di[a[i]] += 1
    if 2 < di[a[i]]:
        right = False
    if a[i]==0 and di[a[i]]>1:
        right = False
    if n%2==0 and a[i]%2==0:
        right = False
    elif n%2==1 and a[i]%2 ==1:
        right = False

print((2**(n//2)%(10**9+7)) if right else 0)

Submission status: Accepted

Solution code:
N=int(input())
A=sorted([int(i) for i in input().split()],reverse=True)
#6,6,4,4,2,2,0
#7,7,5,5,3,3,1,1
B=[]
for i in range(N//2):
    for p in [0,1]:
        B.append(N-1-2*i)
if N%2==1:
    B.append(0)
for i in range(N):
    if A[i]!=B[i]:
        print(0)
        exit()
M=1
P=10**9+7
for i in range(N//2):
	M=(2*M)%P
print(M)

Submission status: Accepted

Solution code:
characteristic=10**9+7
def plus(input1,input2):
    return (input1+input1)%characteristic
def minus(input1,input2):
    return (input1-input2)%characteristic
def times(input1,input2):
    return (input1*input2)%characteristic
def exponen(input1,input2):
    binaryl=list(str(bin(input2))[2:])
    binarysize=len(binaryl)
    binarylist=[int(binaryl[binarysize-1-i]) for i in range(binarysize)]
    modlist=[0 for i in range(binarysize)]
    modlist[0]=input1
    for i in range(1,binarysize):
        modlist[i]=times(modlist[i-1],modlist[i-1])
    answer=1
    for i in range(binarysize):
        if binarylist[i]==1:
            answer=times(answer,modlist[i])
    return answer
def divide(input1,input2):
    return times(input1,exponen(input2,characteristic-2))
N=int(input())
A=sorted([int(i) for i in input().split()],reverse=True)
#6,6,4,4,2,2,0
#7,7,5,5,3,3,1,1
B=[]
for i in range(N//2):
    for p in [0,1]:
        B.append(N-1-2*i)
if N%2==1:
    B.append(0)
for i in range(N):
    if A[i]!=B[i]:
        print(0)
        exit()
print(exponen(2,N//2))

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
mod = 10**9 + 7
def f():
  memo = {}

  for i in l:
    if i in memo:
      memo[i] += 1
    else:
      memo[i] = 1
  
  for k, v in memo.items():
    if k == 0 and not v == 1:
      return 0
    elif not k == 0 and not v == 2:
      return 0
  
  return 2**(n//2) % mod

print(f())

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    from collections import Counter

    person_count = int(input())
    relative_positions = Counter(map(int, input().split()))

    if person_count % 2 == 0:
        for key, value in relative_positions.items():
            if (key % 2 == 0) or (value != 2):
                print(0)
                exit()
    else:
        for key, value in relative_positions.items():
            if (key % 2 == 1) or (key == 0 and value != 1) or (key != 0 and value != 2):
                print(0)
                exit()

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

Submission status: Accepted

Solution code:
N = int(input())
inline = list(map(int,input().split()))
di = {}
key = 0
if N%2 ==1:
    cen = 0
else:
    cen = -1

for l in inline:
    if l in di:
        if l != cen:
            if di[l] >= 2:
                key += 1
                break
            else:
                di[l] += 1
        else:
            if di[l] >= 1:
                key += 1
                break
    else:
        di[l] = 1

if key >= 1:
    print(0)
else:
    print((2**int(N/2)%(10**9+7)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = [int(i) for i in input().split()]
c = collections.Counter(a)
if n%2==0:
	if all(c[i]==2 for i in range(1,n+1,2)):
		answer = (2**(n//2))%(10**9+7)
	else: answer = 0
else:
	if all(c[i]==2 for i in range(2,n+1,2)) and c[0]==1:
		answer = (2**((n-1)//2))%(10**9+7)
	else: answer = 0
print(answer)

Submission status: Accepted

Solution code:
from collections import Counter

def orders(count, n):
    c = 1
    for k, v in count.items():
        if k == 0:
            if (n % 2 == 0 or v != 1):
                return 0
        elif (n - 1 - k) % 2 == 1 or v != 2:
            return 0
        else:
            c *= v
    return(c % (10 ** 9 + 7))


if __name__ == '__main__':
    n = int(input())
    count = Counter(map(int, input().split()))
    print(orders(count, n))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
d = {}
for x in a:
	d[x] = d.get(x, 0) + 1
ok = True
for i in range(1 + n % 2, n, 2):
	if i not in d or d[i] != 2:
		ok = False
		break
if ok: print(pow(2, n//2, 10**9+7))
else: print(0)

Submission status: Accepted

Solution code:
n =int(input())
num = [0]*n
tmp = input().split()
L = pow(10,9)+7
for x in range(n):
  num[x] = int(tmp[x])
num.sort()
judge = 1
flg = True
if n%2 == 1:
  judge = 0
  if num[0] != 0:
    flg = False
  else:
    num.pop(0)
prev = -1
count = 0
for i in range(len(num)):
  if prev < 0:
    prev = num[i]
    count += 1
  else:
    if prev == num[i]:
      count += 1
      if count > 2:
        flg = False
        break
    else:
      if count < 2:
        flg = False
        break
      else:
        prev = num[i]
        count = 1
if flg:
  if n%2:
  	print(pow(2,(n-1)//2)%L)
  else:
    print(pow(2,n//2)%L)
else:
  print(0)

Submission status: Accepted

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

A.sort(reverse=True)
l = len(A)

if l % 2 == 1:
	if A[-1] != 0:
		print(0)
	else:
		num = (N-1)
		for i in range(0,N-1,2):
			if not (A[i] == A[i+1] == num):
				print(0)
				exit(0)
			num -= 2

		print((2 ** ((N-1)//2)) % ((10 ** 9)+7))
else:
	num = (N-1)
	for i in range(0,N,2):
		if not (A[i] == A[i+1] == num):
			print(0)
			exit(0)
		num -= 2

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

Submission status: Accepted

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