Problem:


Score : 300 points

Problem Statement

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

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

Constraints

1≦N≦10^5

0≦A_i≦N-1

Input

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

N
A_1 A_2 ... A_N

Output

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

Sample Input 1

5
2 4 4 0 2

Sample Output 1

4

There are four possible orders, as follows:

2,1,4,5,3

2,5,4,1,3

3,1,4,5,2

3,5,4,1,2

Sample Input 2

7
6 4 0 2 4 0 2

Sample Output 2

0

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

Sample Input 3

8
7 5 1 1 7 3 5 3

Sample Output 3

16



Sample input:
5
2 4 4 0 2


Sample output:
4

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
A = [i for i in input().split()]
c = Counter(A)
ans = 0

if len(A) % 2 == 0:
    if all(v == 2 for v in c.values()):
        ans = 2**(n//2)
        
else:
    if c['0'] == 1 :
        if len(A) == 1:
            ans = 1
        del c['0']
        if all(v == 2 for v in c.values()):
            ans = 2**((n-1)//2)

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

Submission status: Accepted

Solution code:
mod = 10**9+7
def main():
    n = int(input())
    a = list(map(int,input().split()))
    ret = [0]*n
    for i in a: ret[i] += 1
    #0,2,2,4,4
    if n%2==1:
        if ret[0] != 1:
            print(0)
            return 0
        for i in range(1,n):
            if i%2==0 and ret[i] != 2 or i%2==1 and ret[i] != 0:
                print(0)
                break
        else:
            print(pow(2,n//2,mod))
    else:
        for i in range(n):
            if i%2==0 and ret[i] != 0 or i%2==1 and ret[i] != 2:
                print(0)
                break
        else:
            print(pow(2,n//2,mod))

main()

Submission status: Accepted

Solution code:
def c_LiningUp(N, A):
    MOD = 10**9 + 7
    A = sorted(A)
    if N % 2 == 0:
        # Nが偶数なら、人数の差の絶対値はB=[N-1,N-3,...,3,1,1,3,...,N-3,N-1]
        # になっていないといけない。AとBをソートして一致しなければ解は0。
        B = [i for i in range(1, N, 2)]
        B = sorted(B + B)
    else:
        # Nが奇数なら、人数の差の絶対値はB=[N-1,N-3,...,2,0,2,...,N-3,N-1]
        # になっていないといけない。
        B = [i for i in range(2, N, 2)]
        B = sorted([0] + B + B)
    if A == B:
        return 2**(N // 2) % MOD  # 解説どおり
    else:
        return 0
    return None

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = sorted(list(map(int, input().split())))
div = 10 ** 9 + 7
if N % 2 == 0:
    B = [i for i in range(1, N, 2)]
    B.extend(B)
    B.sort()
    if A == B:
        print(2**(int(N/2)) % div)
    else:
        print(0)

else:
    B = [i for i in range(2, N, 2)]
    B.extend(B)
    B.append(0)
    B.sort()
    if A == B:
        print(2**(int(N/2)) % div)
    else:
        print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter


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

    ans = AC(N, A)
    print(ans)


def AC(N, A):
    """
    差分のとり方を用意しておく
    報告に問題があるか調べる
    差分のとり方＝組合せの要素になる
    """
    diff_dict = defaultdict(int)
    for i in range(1, N + 1):
        left, right = i - 1, N - i
        diff = abs(left - right)
        diff_dict[diff] += 1

    c = Counter(A)
    if diff_dict != c:
        return 0

    ans = 1
    for count in c.values():
        ans = (ans * count) % (10 ** 9 + 7)

    return ans

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=input()
a=map(int,raw_input().split())
#print N
#print a

b=[]
for i in range(1,N+1):
	b.append( abs((N-i)-(i-1)) )

#print b

a.sort()
b.sort()
if a != b:
	print 0
else:
	k=len(a)/2
	print 2**k%(10**9+7)

Submission status: Accepted

Solution code:
num =int(input())

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

_len = len(val)
sort_val = sorted(val)
res = False

if len(sort_val) %2 == 0:
    tmp = sort_val[1::2]
    tmp2 = sort_val[::2]
    if sorted(tmp) == sorted(tmp2):
        res = True
else:
    if sort_val.count(0) != 1:
        pass
    else:
        del sort_val[0]
        tmp = sort_val[::2]
        tmp2 = sort_val[1::2]
        if sorted(tmp) == sorted(tmp2):
            res = True

cnt = 1
if res:
    for i in range(0, _len//2):
        cnt = cnt*2 % 1000000007

print(0 if not res else cnt)

Submission status: Accepted

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

"""050-c"""

import sys
import pprint
import re

import itertools
pp = pprint.PrettyPrinter(indent=2)

mod = 1000000007

def main():
    """Main function."""
    N = int(input())
    as_ = sorted(list(map(int, input().split(' '))), reverse=True)

    checker = N - 1
    if N % 2 != 0:
        if as_[-1] != 0:
            print(0)
            sys.exit(0)
        else:
            N = N - 1

    for i in range(0, N, 2):
        if as_[i] != checker or as_[i + 1] != checker:
            print(0)
            sys.exit(0)
        checker = checker - 2

    print(pow(2, N // 2, mod))

if __name__ == '__main__':
    sys.exit(main())

Submission status: Accepted

Solution code:
import sys

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

end = lambda x: print(x) or sys.exit()
result = 1
n2 = n % 2
if n2 == a[0] % 2:
    end(0)
tmp = None
if n2:
    if a[0]:
        end(0)
else:
    if not a[0] == a[1] == 1:
        end(0)
for a1, a2 in zip(a[n2::2], a[n2 + 1::2]):
    if a1 - a2:
        end(0)
    if tmp:
        if a1 - tmp - 2:
            end(0)

    tmp = a1
    result *= 2
    if result >= M:
        result %= M
end(result)

Submission status: Accepted

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from collections import Counter


def solve():
    while 1:
        try:
            N = int(input())
            A = list(map(int, input().split(" ")))
            MOD = 10 ** 9 + 7
            counter = Counter(A)
            checker = [0 for _ in range(N)]
            for word, cnt in counter.most_common():
                if word > N - 1 or cnt > 2:
                    raise EndLoop
                else:
                    checker[word] = cnt

            if N % 2 == 0:
                for i in range(N):
                    if not i % 2 and checker[i] != 0:
                        raise EndLoop
                    elif i % 2 and checker[i] != 2:
                        raise EndLoop

                print((2 ** (N // 2)) % MOD)
                break
            else:
                for i in range(N):
                    if i == 0 and checker[i] != 1:
                        raise EndLoop
                    elif not i % 2 and i != 0and checker[i] != 2:
                        raise EndLoop
                    elif i % 2 and checker[i] != 0:
                        raise EndLoop

                print(((2 ** ((N - 1) // 2)) % MOD))
                break
        except:
            print(0)
            break


solve()

Submission status: Accepted

Solution code:
def end():
    print(0)
    exit()


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

b = [0] * ((n + 1) // 2)

if n % 2 == 0:
    for x in a:
        if x % 2 == 0:
            end()
        b[x // 2] += 1
    for y in b:
        if y != 2:
            end()
else:
    for x in a:
        if x % 2 != 0:
            end()
        b[x // 2] += 1
    for y in b[1:]:
        if y != 2:
            end()
        if b[0] != 1:
            end()

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

Submission status: Accepted

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

b = [0] * ((n + 1) // 2)

if n % 2 == 0:
    for x in a:
        if x % 2 == 0:
            print(0)
            exit()
        b[x // 2] += 1
    for y in b:
        if y != 2:
            print(0)
            exit()
else:
    for x in a:
        if x % 2 != 0:
            print(0)
            exit()
        b[x // 2] += 1
    for y in b[1:]:
        if y != 2:
            print(0)
            exit()
        if b[0] != 1:
            print(0)
            exit()

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

Submission status: Accepted

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


def solve(i, num):
    while i < len(A):
        if A[i] == num:
            if A[i + 1] == num:
                i += 2
                num += 2
            else:
                break
        else:
            break
    if i >= len(A):
        print(2 ** (N // 2) % mod)
    else:
        print(0)


if len(A) % 2 is 0:
    solve(0, 1)
else:
    if A[0] is 0:
        solve(1, 2)
    else:
        print(0)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
listA = input().split()

if N % 2 == 1:
    count = Counter(listA)
    i = 0
    flag = True
    while i < N:
        if i == 0 and count[str(i)] == 1:
            i = i + 2
            continue
        elif count[str(i)] == 2:
            i = i + 2
            continue
        else:
            flag = False
            break
    if flag:
        print((2 ** ((N-1)//2)) % (10**9 + 7))
    else:
        print("0")
else:
    count = Counter(listA)
    i = 1
    flag = True
    while i < N:
        if count[str(i)] == 2:
            i = i + 2
            continue
        else:
            flag = False
            break
    if flag:
        print(2 ** (N//2) % (10**9 + 7))
    else:
        print("0")

Submission status: Accepted

Solution code:
INF = 10**9+7

N = int(input())
A = sorted( list(map(int,input().split())) )
if N%2==1:
    tmp = [ 2*j for j in range(1,N//2+1)]
    TMP = sorted([0]+tmp+tmp)
else:
    tmp = [2*j+1 for j in range(N//2)]
    TMP = sorted(tmp+tmp)
if A==TMP:
    tmp=1
    for _ in range(N//2):
         tmp *=2
         tmp %=INF
    print(tmp)
else:
    print(0)

Submission status: Accepted

Solution code:
mod=10**9+7
n=int(input())
l=[int(x) for x in input().split()]
f=[0]*(10**5)
for ele in l:
    f[ele]+=1
if n%2==0 and f[0]:
    print(0)
elif f[0]>1:
    print(0)
else:
    cnt=0
    for i in range(1,n):
        if f[i]:
            cnt+=1
        if f[i]>2:
            print(0)
            break
    else:
        print(pow(2,cnt,mod))

Submission status: Accepted

Solution code:
import sys
from collections import Counter

M = 10 ** 9 + 7


# sys.stdin = open('c1.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def solve():
    n = read_int()
    a = read_int_list()

    c = Counter(a)
    expected = Counter()
    if n % 2 == 0:
        for i in range(1, n, 2):
            expected[i] = 2
    else:
        expected[0] = 1
        for i in range(2, n, 2):
            expected[i] = 2

    if c == expected:
        return 2 ** (n // 2) % M
        # return pow(2, n // 2, M)
    return 0


def main():
    res = solve()
    print(res)


main()

Submission status: Accepted

Solution code:
import sys
from collections import Counter

M = 10 ** 9 + 7

# sys.stdin = open('c1.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def solve():
    n = read_int()
    a = read_int_list()

    c = Counter(a)
    expected = Counter()
    if n % 2 == 0:
        for i in range(1, n, 2):
            expected[i] = 2
    else:
        expected[0] = 1
        for i in range(2, n, 2):
            expected[i] = 2

    if c == expected:
        return pow(2, n // 2, M)
    return 0


def main():
    res = solve()
    print(res)


main()

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import Counter

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

    if N % 2 == 0 and c[0] != 0:
        print(0)
        return
    if N % 2 != 0 and c[0] != 1:
        print(0)
        return
    for i in range(N - 1, 0, -2):
        if c[i] != 2:
            print(0)
            return

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

N = input()
A = map(int, raw_input().split())
hist = Counter(A)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

mod = 10**9+7
flg = [False]*n
      
for i in range(n):
    if(flg[a[i]]==False):
        flg[a[i]] = True
    elif(flg[a[i]-1]==False and a[i]-1>=0):
        flg[a[i]-1] = True
    
           
if(n%2==0):
    if(all(flg)):
        print(2**(n/2) % mod)
    else:
        print('0')
else:
    if(all(flg)):
        print(2**((n-1)/2) % mod)
    else:
        print('0')

Submission status: Accepted

Solution code:
from collections import Counter

n = int(raw_input())
ct = Counter(map(int, raw_input().split()))
correct = True
for i,j in zip(ct.keys(), ct.values()):
    if (n % 2) == (i % 2):
        correct = False
    elif i >= n:
        correct = False
    elif i == 0:
        if j != 1:
            correct = False
    else:
        if j != 2:
            correct = False
if correct:
    print (2**(n/2)) % (10**9+7)
else:
    print 0

Submission status: Accepted

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

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

Submission status: Accepted

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

    a = list(range(N))
    if N % 2 == 1:
        a2 = a[::2] * 2
        a2.sort(reverse=True)
        a2.pop()
    else:
        a2 = a[1::2] * 2
        a2.sort(reverse=True)
    A.sort(reverse=True)

    if tuple(a2) == tuple(A):
        comb = (2 ** (N // 2)) % 1000000007
        print(str(comb))
    else:
        print('0')

main()

Submission status: Accepted

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

    if N % 2 == 1:
        A.append(0)

    A.sort()
    ev = tuple(A[::2])
    od = tuple(A[1::2])

    if ev == od:
        comb = (2 ** (N // 2)) % 1000000007
        print(str(comb))
    else:
        print('0')

main()

Submission status: Accepted

Solution code:
num = int(raw_input())
array = map(int, raw_input().split(" "))

a = sorted(array)

if num % 2 == 0:
    for i in xrange(0, num, 2):
        if a[i] != a[i + 1]:
            print 0
            break
    else:
        div = pow(10, 9) + 7
        print pow(2, num / 2) % div
else:
    for i in xrange(1, num, 2):
        if a[i] != a[i + 1]:
            print 0
            break
    else:
        div = pow(10, 9) + 7
        print pow(2, num / 2) % div

Submission status: Accepted

Solution code:
N = int(input())

seq = [int(i) for i in input().split()]
seq_sort = sorted(seq)

if N % 2 == 0:
    seq_even = []
    for i in range(N // 2):
        seq_even += [2 * i + 1, 2 * i + 1]
    if seq_sort == seq_even:
        print((2 ** (N // 2)) % (10 ** 9 + 7))
    else:
        print(0)
else:
    seq_odd = [0]
    for i in range(N // 2):
        seq_odd += [2 * (i + 1), 2 * (i + 1)]
    if seq_sort == seq_odd:
        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()]

def is_satisfied(s):
    ln = len(s)
    check = sorted(list(range(ln - 1, 1, -2)) * 2)
    if ln % 2 == 0:
        check.insert(0, 1)
        check.insert(0, 1)
    else:
        check.insert(0, 0)

    return sorted(s) == check

    # for i in range(ln - 1, 1, -2):
    #     if not s.count(i) == 2:
    #         return False
    # if ln % 2 == 0:
    #     if not s.count(1) == 2:
    #         return False
    # else:
    #     if not s.count(0) == 1:
    #         return False

    # return True


ans = 2 ** (n // 2) % (10 ** 9 + 7)
print(ans if is_satisfied(a) else 0)

Submission status: Accepted

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

div=10**9+7

A.sort()

if N % 2 == 0:
    for i in range(int(N/2)):
        if A[2*i] != 2*i+1 or A[2*i+1] != 2*i+1:
            print (0)
            sys.exit() 
    print(2**int(N/2) % div)
if N % 2 == 1:
    if A[0]!=0:
        print(0)
        sys.exit()
    for i in range(int((N-1)/2)):
        if A[2*i+1] !=2*i+2  or A[2*i+2]!= 2*i+2:
            print(0)
            sys.exit()
    print(2**int((N-1)/2) % div)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
Nc = 0
e = 0
A.sort()
if N % 2 == 0:
    B = [2*i - 1 for i in range(1, N//2 + 1)]
    B = B + B
    B.sort()
    if A == B:
        Nc = 2**(N//2)
else:
    B = [2*i for i in range(1, (N-1)//2 + 1)]
    B = B + B + [0]
    B.sort()
    if A == B:
        Nc = 2**((N-1)//2)

print(Nc%1000000007)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
Nc = 1
e = 0
B = [0]*N
for i in A:
    if (N-i-1) < 0:
        e = 1
        Nc = 0
        break
if e ==0:
    if A.count(0) >= 2:
        Nc *= 0
    else:
        if A.count(0) == 1:
            A.remove(0)
        for i in A:
            B[i] = B[i] + 1
        for i in B:
            if i == 2:
                Nc *= 2
            elif i == 0:
                Nc *= 1
            else:
                Nc *= 0
                break
print(Nc%1000000007)

Submission status: Accepted

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

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

if sorted(A) == B:
    print((2 ** int(N/2)) % (10**9 + 7))
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(raw_input().strip())
a = map(int, raw_input().strip().split())
a.sort()


def validate(a, n):
	if n & 1 == 0:
		s = 0
		p = 1
	else:
		s = 1
		p = 2
		if a[0] != 0:
			return False
	for i in range(s, n, 2):
		if a[i] != a[i + 1]:
			return False
	return True


if not validate(a, n):
	print 0
else:
	print (1 << (n >> 1)) % int(1e9 + 7)

Submission status: Accepted

Solution code:
n = input()

a, b = map(int, raw_input().split()), [abs(x - (n - x - 1)) for x in xrange(n)]
a.sort()
b.sort()
if a != b:
	print '0'
	exit(0)

n >>= 1
s, e = 1, 2
MOD = 10 ** 9 + 7
while n > 0:
	if (n & 1) == 1:
		s = s * e % MOD
	e = e * e % MOD
	n >>= 1
print s

Submission status: Accepted

Solution code:
#ARC050C
import sys

n=int(raw_input())
a=map(int,raw_input().split())
b=sorted(a)
if n%2==0:
 for i in xrange(0,n,2):
  if b[i+1]!=b[i]:
   print 0
   sys.exit()
 else:
  print (2**(n/2))%(10**9+7)
else:
 for i in xrange(1,n,2):
  if b[i+1]!=b[i]:
   print 0
   sys.exit()
 else:
  print (2**(n/2))%(10**9+7)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
if n%2==1:
    b=b[1:]

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

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

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = [int(a) for a in input().split()]
 
check = {}
 
if N % 2 == 0:
    for i in range(1, N, 2):
        check[i] = 2
else:
    check[0] = 1
 
    for i in range(2, N, 2):
        check[i] = 2
 
if check == Counter(A):
    print((2 ** (N // 2)) % (10 ** 9 + 7))
else:
    print(0)

Submission status: Accepted

Solution code:

N = int(input())
A = [int(a) for a 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:
def solve(n, a_lst):
    dic = {}

    for i in range(1, n + 1, 2):
        j = n - i
        dic[j] = 1 if j == 0 else 2

    for i in a_lst:
        if i not in dic:
            return 0

        dic[i] -= 1

        if dic[i] < 0:
            return 0

    return pow(2, n // 2) % (pow(10, 9) + 7)


if __name__ == '__main__':
    n = int(input())
    a_lst = [int(x) for x in input().split()]
    print(solve(n, a_lst))

Submission status: Accepted

Solution code:
from collections import Counter

N = int(raw_input())
A = Counter(map(int, raw_input().split()))
cnt = 1
for k, v in A.items():
    if k == 0:
        continue
    if k % 2 == N % 2:
        print 0
        exit()
    if v != 2:
        print 0
        exit()
    cnt *= 2
    cnt %= 10 ** 9 + 7
print cnt

Submission status: Accepted

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

fail=False
count_list = [0]*(int((N-1)/2)+1)
for i in range(N):
	if A[i]%2==N%2:
		print(0)
		fail=True
		break
	count_list[int(A[i]/2)] = count_list[int(A[i]/2)]+1
if not fail:
	if N%2==0:
		for c in count_list:
			if c!=2:
				print(0)
				break
		else:
			result = 2
			for i in range(int(N/2)-1):
				result = result*2%(10**9+7)
			print(result)
	if N%2==1:
		if count_list[0]!=1:
			print(0)
		else:
			count_list.pop(0)
			for c in count_list:
				if c!=2:
					print(0)
					break
			else:
				if N==1:
					print(1)
				else:
					result = 2
					for i in range(int((N-1)/2)-1):
						result = result*2%(10**9+7)
					print(result)

Submission status: Accepted

Solution code:
class Lining:

    def line(self, N, A):

        if N == 1:
            print 1
            return

        if N == 2:
            print 2
            return

      
        if N % 2:

            m = [0 for i in range((N/2)+1)]
            for a in A:
                idx = a/2
                m[idx] += 1

            if m[0] != 1:
                print 0
                return

            ans = 1
            for i in range(1, (N/2)+1):
                ans *= 2

                if m[i] != 2:
                    print 0
                    return

            print ans % (pow(10, 9) + 7)

        else:

            m = [0 for i in range(N/2)]
            for a in A:
                idx = a/2
                m[idx] += 1

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

                if m[i] != 2:
                    print 0
                    return

            print ans % (pow(10, 9) + 7)

if __name__ == "__main__":

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

    abc = Lining()
    abc.line(N, A)

Submission status: Accepted

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

A.sort()
ansflag = True
if N % 2 == 0:
	for i in range(N):
		if A[i] != (i // 2) * 2 + 1:
			ansflag = False
			break
else:
	if A[0] != 0:
		ansflag = False
	for i in range(1, N):
		if A[i] != ((i+1) // 2) * 2:
			ansflag = False
			break

if ansflag:
	def repeatSquares(x, n):  # x^n
		res = 1
		while n != 0:
			if n % 2 == 1:
				res *= x
				res %= MOD  # MOD演算ないなら消していい
			x *= x
			n //= 2
			x %= MOD      # MOD演算ないなら消していい
		return res

	print(repeatSquares(2, N // 2))
else:
	print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
o, h = N%2, N//2
arr = [0]*h
for a in map(int, input().split()):
    if a > 0:
        arr[a//2 - o] += 1
if all(c == 2 for c in arr):
    print((1 << h) % (10**9 + 7))
else:
    print(0)

Submission status: Accepted

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

def check(n, a):
    count = Counter(a)
    if n % 2 == 1 and (0 not in count or count[0] != 1):
        return False
    for i in range(1 + (n % 2), n+1, 2):
        if i not in count or count[i] !=2:
            return False
    return True

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))

    m = N // 2
    if not check(N,A):
        print(0)
    else:
        print((2 ** m) % (10**9+7))

Submission status: Accepted

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

def check(n, a):
    count = Counter(a)
    if n % 2 == 1 and (0 not in count or count[0] != 1):
        return False
    for i in range(1 + (n % 2), n+1, 2):
        if i not in count or count[i] !=2:
            return False
    return True

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))

    if not check(N,A):
        print(0)
    else:
        if N > 1:
            c = 2
            for _ in range((N // 2) - 1):
                c = c * 2 % (int(1e9) + 7)
            print(c)
        else:
            print(1)

Submission status: Accepted

Solution code:
from collections import Counter


def check(n, a):
    aa = Counter(a)
    if n & 1 and (0 not in aa or aa[0] != 1):
        return False
    for i in range(1 + (n & 1), n + 1, 2):
        if i not in aa or aa[i] != 2:
            return False
    return True


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

    if not check(n, a):
        return 0

    exp = n // 2
    if exp < 30:
        return 2 ** exp
    c = 2 ** 29
    d = int(1e9) + 7
    exp -= 29
    for _ in range(exp):
        c = c * 2 % d
    return c


print(solve())

Submission status: Accepted

Solution code:
MOD = 10**9+7
n = int(input())
xs = list(map(int, input().split()))
cnt = [0 for _ in range(n)]
for x in xs:
    cnt[x] += 1

res = 1
if n % 2 == 0:
    s = 1
else:
    s = 2
    if cnt[0] != 1:
        res = 0
for i in range(s,n,2):
    if cnt[i] != 2:
        res = 0
    res *= 2
    res %= MOD
    
print(res)

Submission status: Accepted

Solution code:
def detect(n,c):
    if n%2 and c.pop(0) != 1:
        return False
    for i in range(1,n,2):
        if c[i] != 2:
            return False
    else:
        return True

N = int(input())

count = [0 for x in range(N)]
for x in map(int,input().split()):
    count[x] += 1

if detect(N,count):
    print((2**(N>>1)) % 1000000007)
else:
    print(0)

Submission status: Accepted

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
M = math.ceil(N / 2)
L = [0 for i in range(M)]

for a in A:
    if (N % 2 == 0 and a % 2 == 0) or (N % 2 != 0 and a % 2 != 0):
        print(0)
        exit()
    L[M - a // 2 - 1] += 1

if N % 2 == 0:
    for m in range(M):
        if L[m] != 2:
            print(0)
            exit()
else:
    for m in range(M):
        if m != M - 1:
            if L[m] != 2:
                print(0)
                exit()
        else:
            if L[m] != 1:
                print(0)
                exit()

ans = 1
MOD = int(1e9) + 7
for m in range(N // 2):
    ans *= 2
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
import sys
n=int(input())
array=list(map(int, input().split()))

if not (0<=min(array) and max(array)<n):
    print(0)
    sys.exit()

if n%2==0:
    if (n**2)/2 != sum(array):
        print(0)
        sys.exit()
else:
    if (n**2-1)/2 != sum(array):
        print(0)
        sys.exit()

sub_list=list(set(array))

if n%2==0:
    if int(n/2)==len(sub_list):
        print((2 ** int(n / 2))%(10**9 + 7))
    else:
        print(0)
else:
    if int(n/2)==len(sub_list)-1:
        print((2 ** int(n / 2)) % (10 ** 9 + 7))
    else:
        print(0)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def pow(base, nod):
  MOD = 10**9+7
  ans = 1
  tmp = base
  while nod>0:
    if nod%2==1: ans=ans*tmp%MOD
    tmp = tmp**2
    tmp %= MOD
    nod /= 2
  return ans

n=int(raw_input())
a=map(int,raw_input().split())
d={}
for i in xrange(n):
  if a[i] not in d: d[a[i]]=0
  d[a[i]]+=1
isValid=True
if n%2==0:
  for k,v in d.items():
    if k%2!=1 or v!=2:
      isValid=False
else:
  for k,v in d.items():
    if k%2!=0 or (k==0 and v!=1) or (k!=0 and v!=2):
      isValid=False
if isValid:
  print pow(2, n/2)
else:
  print 0

Submission status: Accepted

Solution code:
from collections import defaultdict
n=int(input())
arr=list(map(int,input().split()))
dd=defaultdict(int)
for a in arr:
    dd[a]+=1
if n%2==0:
    for i in range(1,n,2):
        if dd[i]!=2:
            print(0)
            exit(0)
    else:
        prod=1
        for i in range(n//2):
            prod*=2
            prod%=1000000007
        print(prod)
else:
    if dd[0]!=1:
        print(0)
        exit(0)
    for i in range(2,n,2):
        if dd[i]!=2:
            print(0)
            exit(0)
    else:
        prod=1
        for i in range((n-1)//2):
            prod*=2
            prod%=1000000007
        print(prod)

Submission status: Accepted

Solution code:

from collections import Counter

n = int(input())
a = list(map(int, input().split()))
m = n // 2
ca = Counter(a)

if n % 2 == 1 and ca[0] == 1 and all(ca[(i+1)*2] == 2 for i in range(m)):
    ans = (2 ** m) % (10 ** 9 + 7)
    print(ans)
elif n % 2 == 0 and all(ca[i*2 + 1] == 2 for i in range(m)):
    ans = (2 ** m) % (10 ** 9 + 7)
    print(ans)
else:
    print(0)