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:
import collections

n = int(input())
a = list(map(int, input().split()))
ac = collections.Counter(a)
if n % 2:
    if ac[0] != 1:
        print(0)
        exit()
    for i in ac:
        if i == 0:
            continue
        if ac[i] != 2:
            print(0)
            exit()
else:
    if ac[1] != 2:
        print(0)
        exit()
    for i in ac:
        if i == 1:
            continue
        if ac[i] != 2:
            print(0)
            exit()
mod = 10 ** 9 + 7
print((2 ** (n // 2)) % mod)

Submission status: Accepted

Solution code:
def inpl():
    return list(map(int, input().split()))


N = int(input())

A = inpl()
A.sort()

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

ans = 1
for j, i in enumerate(range(a, N, 2)):
    if A[i] == A[i + 1] == 2 * (j + 1) - (a + 1) % 2:
        ans *= 2
    else:
        print(0)
        exit()
print(ans % (10**9 + 7))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Feb  9 09:53:28 2019

@author: shinjisu
"""


# ARC 066 C lining up
def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def db(x):
    global debug
    if debug:
        print(x)


def solve():
    A.sort()
    db(A)
    if A[0] == 0:
        n = 1
    else:
        n = 0
    for i in range(n, len(A), 2):
        db(i)
        if A[i] != A[i+1]:
            return 0
    return 2**(len(A)//2) % (10**9+7)


debug = False
N = getInt()
A = getIntList()
db((N, A))
print(solve())

Submission status: Accepted

Solution code:
from math import factorial, floor
n = int(input())
a_list = list(map(int, input().split()))

co = a_list.copy()
if 0 in co:
    co.remove(0)
co.sort()


if not len(co) % 2 == 0:
    print(0)
    quit()

for index in range(len(a_list))[:-1:2]:
    if not co[index] == co[index + 1]:
        print(0)
        quit()


print(int(pow(2, floor(n / 2))) % (pow(10,9) + 7))

Submission status: Accepted

Solution code:
N=int(input())

ans=None
tmp=0
z=1
if(N%2==0):
    tmp=int(N/2)
    ans=[2 for i in range(tmp)]
    A=map(int,input().split())
    for i in A:
        if(int(i/2)<=int(N/2)):
            ans[int(i/2)-1]-=1
        else:
            print(0)
            exit() 
else:
    tmp=int(N/2)
    ans=[2 for i in range(tmp)]
    z=0
    A=map(int,input().split())
    for i in A:
        if(i==0):
            z=1
            continue
        if(int(i/2)<=int(N/2)):
            ans[int(i/2)-1]-=1
        else:
            print(0)
            exit()
output=2**(tmp)%(10**9+7)
for i in ans:
    if(i!=0):
        output=0

print(output*z)

Submission status: Accepted

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

if N % 2 == 1:
    l.append(0)
    N -= 1
else:
    l = list(map(lambda x: x-1, l))

l = sorted(l)
i = 0
for f, s in zip(l[0::2], l[1::2]):
    if f == 2*i and s == 2*i:
        i += 1
    else:
        print(0)
        exit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(int(i) for i in input().split())
if n%2==0 and sum(a)==n*n//2 or n%2==1 and sum(a) == (n+1)*(n//2):
    print(2**(n//2)%(10**9+7))
else:
    print(0)

Submission status: Accepted

Solution code:
# coding: utf-8

II = lambda: int(input())
MI = lambda: map(int, input().split())


def check(N, A):
    if N % 2 == 0:
        for i in range(N):
            if A[i] != (i // 2) * 2 + 1: return False
    else:
        for i in range(N):
            if A[i] != ((i + 1) // 2) * 2: return False
    return True

def main():
    N = II()
    A = sorted(list(MI()))
    if not check(N, A):
        return 0
    ans = 1
    MOD = int(1e9 + 7)
    for i in range(N//2):
        ans = ans * 2 % MOD
    return ans


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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
judge = "YES"
if N % 2 == 1:
	if A[0] != 0:
		judge = "NO"
	for i in range(int(N // 2)):
		if A[2 * i + 1] != 2 * i + 2 or A[2 * i + 2] != 2 * i + 2:
			judge = "NO"
			break

else:
	for i in range(int(N // 2)):
		if A[2 * i] != 2 * i + 1 or A[2 * i + 1] != 2 * i + 1:
			judge = "NO"
			break

if judge == "NO":
	print(0)
else:
	c = 1
	for i in range(int(N // 2)):
		c = (2 * c) % 1000000007
	print(c)

Submission status: Accepted

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

N = int(input())
A = input().split(' ')
flag = False
c = collections.Counter(A)


if c.most_common()[0][1] > 2:
    flag = True
if N % 2 == 1:
    if not c.most_common()[-1][0] == '0':
        flag = True
if flag:
    print(0)
    exit()

if N % 2 == 0:
    ans = pow(2, N//2, MOD)
else:
    ans = pow(2, (N-1)//2, MOD)
print(ans)

Submission status: Accepted

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))
if N%2==1:
    if 0 not in A:
        print(0)
    else:
        A.remove(0)
        Bc=dict(collections.Counter(A))
        for i in Bc.keys():
            if Bc[i]!=2:
                print(0)
                break
        else:
            print((2**(len(A)//2))%(10**9+7))
else:
    Bc=dict(collections.Counter(A))
    for i in Bc.keys():
        if Bc[i]!=2:
            print(0)
            break
    else:
        print((2**(len(A)//2))%(10**9+7))

Submission status: Accepted

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

A.sort()

if N % 2 == 0:
    middle = N // 2
    able = True
    for i in range(0,N,2):
        if A[i] != A[i+1]:
            able = False
            break
    if able:
        ans = 2**middle
    else:
        ans = 0
else:
    middle = N // 2
    able = True
    if A[0] == 0:
        for i in range(1,N,2):
            if A[i] != A[i+1]:
                able = False
                break
        if able:
            ans = 2**middle
        else:
            ans = 0
    else:
        ans = 0
        
print(ans%(10**9 + 7))

Submission status: Accepted

Solution code:
def inpl(): return [int(i) for i in input().split()]
import sys
from collections import defaultdict
H = defaultdict(lambda: 0)
N = int(input())
A = inpl()
mod = 10**9+7
if N%2:
    H[0] = -1
    for i in range(1, 1+N//2):
        H[2*i] = -2
else:
    for i in range(1, 1+N//2):
        H[2*i-1] = -2
for i in A:
    H[i] += 1
H = list(H.values())
if any(H):
    print(0)
    sys.exit()
print(2**(N//2)%mod)

Submission status: Accepted

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

check = [0]*(n//2 + n%2)
flag = True
for i in a:
    check[i//2] += 1
    if i%2 == n%2:
        flag = False
        break
    if (i//2 == 0 and n%2 == 1 and check[0] > 1) or check[i//2] > 2:
        flag = False
        break
if flag:
    print(2**(n//2) % (10**9 + 7))
else:
    print(0)

Submission status: Accepted

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

a.sort()
ra = a.copy()
a = a[0::2]
ra = ra[1::2]
ra.reverse()
a = ra + a
for i in range(n):
    if a[i] != abs(n - 1 - i * 2):
        print(0)
        sys.exit(0)
print(2 ** (n // 2) % 1000000007)

Submission status: Accepted

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


a.sort()
fl=True

fl=True
if N%2==0:
    for i in range(0,N,2):
        if a[i]!=i+1 or a[i+1]!=i+1:
            fl=False
            break
else:
    if a[0]!=0:
        fl=False
    for i in range(1,N,2):
        if a[i]!=i+1 or a[i+1]!=i+1:
            fl=False
            break

if fl:
    print((2**(N//2))%inf)
else:
    print(0)

Submission status: Accepted

Solution code:
MOD = 1000000007
N = int(input())
A = [int(a) for a in input().split()]
cnt = [0] * N
for a in A:
  cnt[a] += 1

if N % 2 == 1:
  if cnt[0] != 1:
    print(0)
  else:
    for i in range(2,N,2):
      if cnt[i] != 2:
        print(0)
        break
    else:
      print(2**(N//2)%MOD)
else:
  for i in range(1,N,2):
    if cnt[i] != 2:
      print(0)
      break
  else:
    print(2**(N//2)%MOD)

Submission status: Accepted

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

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

d = 10**9 + 7

cnt = Counter(A)

sA = sorted(A)

if N % 2 == 0:
    i = 0
    for i in range(0, N - 1, 2):
        if sA[i] == sA[i + 1] and sA[i] == i + 1:
            pass
        else:
            print(0)
            sys.exit(0)
else:
    if sA[0] != 0:
        print(0)
        sys.exit(0)
    for i in range(1, N - 1, 2):
        if sA[i] == sA[i + 1] and sA[i] == i + 1:
            pass
        else:
            print(0)
            sys.exit(0)

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

sys.exit(0)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
center = 0
M = N//2
parity = N%2
capacity = [0 for _ in range(M)]
failed = False
for i in range(N):
    if a[i]%2 == parity:
        failed = True
        break
    if a[i] < 0 or a[i] > N-1:
        failed = True
        break
    if a[i] == 0:
        center += 1
    else:
        j = (N-a[i])//2
        capacity[j] += 1
if parity == 1 and center != 1:
    failed = True
answer = 1
MOD = 10**9+7
for c in capacity:
    if c!=2:
        failed = True
        break
    else:
        answer *= 2
        answer %= MOD

if failed:
    print(0)
else:
    print(answer)

Submission status: Accepted

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

Submission status: Accepted

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


def solve():
    cnt = {i + (1 - N % 2): 0 for i in range(0, 2 * N // 2, 2)}
    for a in A:
        if a not in cnt:
            return 0

        if N % 2 == 1:
            if a % 2 == 1:
                return 0
            cnt[a] += 1
        else:
            if a % 2 == 0:
                return 0
            cnt[a] += 1

    for key, value in cnt.items():
        if key == 0:
            if value != 1:
                return 0
        else:
            if value != 2:
                return 0

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


print(solve())

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
N=int(input())
A=[int(i) for i in input().split()]
mod=10**9+7
L=[0]*N
for i in range(N):
    L[A[i]]+=1
if N%2==0:
    for i in range(1,N,2):
        if L[i]!=2:
            print(0)
            sys.exit()
    print(pow(2,N//2,mod))
else:
    if L[0]!=1:
        print(0)
        sys.exit()
    for i in range(2,N,2):
        if L[i]!=2:
            print(0)
            sys.exit()
    print(pow(2,N//2,mod))

Submission status: Accepted

Solution code:
import sys

MOD = 10 ** 9 + 7

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

As.sort()

if N % 2: # 奇数
    for i in range(N):
        if As[i] != (i + 1) // 2 * 2:
            print(0)
            sys.exit(0)
else: # 偶数
    for i in range(N):
        if As[i] != i // 2 * 2 + 1:
            print(0)
            sys.exit(0)

ans = 1
for _ in range(N // 2):
    ans = (ans * 2) % MOD
print(ans)

Submission status: Accepted

Solution code:

N = int(raw_input())
A = map(int,raw_input().split())

flag=True
if N%2==0:
    l = [0 for i in range(N/2)]
    for i in range(N):
        if A[i]%2!=1 or A[i]>=N or A[i]<=0:
            print 0
            flag=False
            break
        l[(A[i]-1)/2]+=1
        if l[(A[i]-1)/2]>=3:
            print 0
            flag=False
            break
    if flag:
        print (2**(N/2))%(10**9+7)
else:
    l = [0 for i in range((N+1)/2)]
    for i in range(N):
        if A[i]%2!=0 or A[i]>=N or A[i]<0:
            print 0
            flag=False
            break
        if A[i]==0:
            l[0]+=1
            if l[0]>=2:
                print 0
                flag=False
                break
        else:
            l[A[i]/2]+=1
            if l[A[i]/2]>=3:
                print 0
                flag=False
                break        
    if flag:
        print (2**((N-1)/2))%(10**9+7)

Submission status: Accepted

Solution code:
i = int(input())
list_a = list(map(int, input().split()))
dict_ans = {}
for number in list_a:
    try:
        dict_ans[number] += 1
    except KeyError:
        dict_ans[number] = 1
if i % 2 == 0:
    dict_prop = {key:2 for key in [j for j in range(i) if j % 2 == 1]}
    if dict_prop == dict_ans:
        ans = 2 ** (i//2)
    else:
        ans = 0
else:
    dict_prop = {key:2 for key in [j for j in range(i) if j % 2 == 0]}
    dict_prop.update({0:1})
    if dict_prop == dict_ans:
        ans = 2 ** (i // 2)
    else:
        ans = 0
print(ans % (10 **9 + 7))

Submission status: Accepted

Solution code:
import collections

n = int(input())
a = list(map(int, input().split()))
ac = collections.Counter(a)
if n % 2 == 1:
    for i in ac:
        if i == 0:
            if ac[i] != 1:
                print(0)
                exit()
        else:
            if ac[i] != 2:
                print(0)
                exit()
    print((2 ** (n // 2)) % (10 ** 9 + 7))
else:
    for i in ac:
        if i == 0:
            if ac[i] != 0:
                print(0)
                exit()
        else:
            if ac[i] != 2:
                print(0)
                exit()
    print((2 ** (n // 2)) % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
from collections import defaultdict

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

counter = defaultdict(int)
for a in A:
    counter[a] += 1

if N % 2 == 0:
    check = {i: 2 for i in range(1, N, 2)}
else:
    check = {i: 2 for i in range(2, N, 2)}
    check[0] = 1

unsatisfied = False
for key, val in counter.items():
    temp = check.get(key, None)
    if temp == None or temp < val:
        unsatisfied = True
        break

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

Submission status: Accepted

Solution code:
from collections import Counter

MOD = 10 ** 9 + 7

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

Submission status: Accepted

Solution code:
import math
n = int(input())
lis = list(map(int,input().split()))
li = [0 for _ in range(math.ceil(n / 2))]

for i in range(n):
  li[math.floor(lis[i] / 2)] += 1
for i in range(len(li)):
  if n % 2 == 1 and i == 0:
    if li[i] != 1:
      print("0")
      exit()
  else:
    if li[i] != 2:
      print("0")
      exit()
cou = 1
for i in range(math.floor(n/2)):
  cou *= 2
  cou %= (10 ** 9 + 7)
print(cou)

Submission status: Accepted

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

n = int(input())
a = sorted(f())
if n&1:
    if all([a[i] == i+i%2 for i in range(n)]):
        print(2**(n//2)%mod)
    else:
        print(0)
else:
    if all([a[i] == i+(i+1)%2 for i in range(n)]):
        print(2**(n//2)%mod)
    else:
        print(0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
d = {}
for x in input().split(" "):
    x = int(x)
    if x not in d:
        d[x] = 0
    d[x] += 1
# print(d)

if n%2==0 and 0 in d:
    print(0)
    exit()
if n%2==1 and d[0]!=1:
    print(0)
    exit()

for k,v in d.items():
    if k==0:
        continue
    if v!=2:
        print(0)
        exit()

if 0 in d:
    del d[0]
m = len(d)
MOD = 10**9 + 7

ret = 1
for _ in range(m):
    ret = (ret*2)%MOD
print(ret)

Submission status: Accepted

Solution code:
n=int(input());print(pow(2,n//2,10**9+7)*(sorted(list(map(int,input().split())))==sorted(abs(n-1-i-i)for i in range(n))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
cnt = [0] * n
for i in input().split():
    cnt[int(i)] += 1
for i in range(1 + n % 2, n, 2):
    if cnt[i] != 2:
        print(0)
        exit(0)
print(pow(2, n // 2, int(1e9 + 7)))

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def coun(n):
  i = 0
  ans = 1
  while i < n:
    ans = (ans*2)%(10**9+7)
    i += 1
  return ans
N = int(input())
A = list(map(int, input().split()))
A.sort()
if len(A)%2 == 1:
  if A[0]!=0:
    print(0)
    sys.exit()
  i = 1
  while i <= len(A)//2:
    if A[2*i-1]==2*i and A[2*i]==2*i:
      i += 1
    else:
      print(0)
      sys.exit()
  print(coun(N//2))

if len(A)%2 == 0:
  i = 0
  while i < N//2:
    if A[2*i] == 2*i+1 and A[2*i+1] == 2*i+1:
      i += 1
    else:
      print(0)
      sys.exit()
  print(coun(N//2))

Submission status: Accepted

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

L = [ abs((N-1) - 2*i) for i in range(N)]

L.sort(); A.sort()

print pow(2, (N-N%2)/2, 10**9+7) if L == A else 0

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())

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

mod = 1000000007

isok=True
for a in A:
    if a%2==0:
        if a==0:
            if A[a]!=1:
                isok=False
                break
        elif (N-1)%2!=0 or A[a]!=2:
                isok=False
                break
    else:
        if (N-1)%2!=1 or A[a]!=2:
            isok=False
            break

if isok:
    ans = 1
    for i in range(N//2):
        ans = (ans*2)%mod
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
a.sort()
try:
    for i, a_i in enumerate(a):
        if n % 2 == 1:
            assert a_i == (i + 1) // 2 * 2
        else:
            assert a_i == i // 2 * 2 + 1
    answer = pow(2, n // 2, 10 ** 9 + 7)
except AssertionError:
    answer = 0
print(answer)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
is_even=True if n%2==0 else False
dic={}
for i in range(n):
    if a[i] in dic:
        dic[a[i]]+=1
    else:
        dic[a[i]]=1
if is_even:
    for m in dic.values():
        if m!=2:
            print(0)
            exit()
    else:
        print((2**(n//2))%1000000007)
else:
    if a.count(0)!=1:
        print(0)
        exit()
    else:
        dic[0]=2
        for m in dic.values():
            if m!=2:
                print(0)
                exit()
        else:
            print(2**(n//2)%1000000007)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
flag = 0
check_ans = 0
check_in = 0
x = 1

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
from collections import Counter
N = int(input())
As = list(map(int, input().split()))
M = 10**9 + 7
cnt = Counter(As)
ans = 1
if N%2 == 0:
    for i in range(0,N//2):
        if cnt[i*2+1] != 2:
            print(0)
            exit()

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

p = N//2
for i in range(p):
    ans = (ans*2) % M

print(ans)

Submission status: Accepted

Solution code:
import collections


def func1(N):
    if N == 0:
        print(0)
    else:
        print((pow(2, int(N / 2)) % (pow(10, 9) + 7)))


def func2(G, N):
    G_list = list(G.values())

    if G_list.count(2) == len(G_list):
        N = N
    else:
        N = 0

    return N


def main():
    N = int(input())
    A = list(map(int, input().split()))
    G = dict(collections.Counter(A))

    if N % 2 == 1:
        if G[0] == 1:
            del G[0]
        else:
            N = 0

    N = func2(G, N)

    func1(N)


main()

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = map(int, input().split())
# N = 5
# A = [2, 4, 4, 0, 2]
mod = 10 ** 9 + 7

cnt = Counter(A)
if N % 2 == 0:
    if len(list(filter(lambda c: c != 2, cnt.values()))) != 0:
        print(0)
    else:
        print((2 ** (N // 2)) % mod)
else:
    if cnt[0] != 1:
        print(0)
    else:
        cnt.pop(0)
        if len(list(filter(lambda c: c != 2, cnt.values()))) != 0:
            print(0)
        else:
            print((2 ** (N // 2)) % mod)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import Counter
mo = 1000000007
r = range

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

c = Counter(a.tolist())

if n % 2 == 1 and (0 not in c or c[0] != 1): print(0); exit();

for i in r(n//2):
    x = i * 2 + (1 if n % 2 == 0 else 2)
    if x not in c or c[x] != 2: print(0); exit();

print(2 ** (n//2) % mo)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np
import functools
from collections import Counter
mo = 1000000007
r = range

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

c = Counter(a.tolist())

if n % 2 == 1 and (0 not in c or c[0] != 1):
    print(0)
    exit()

for i in r(n//2):
    x = i * 2 + (1 if n % 2 == 0 else 2)
    if x not in c or c[x] != 2:
        print(0)
        exit()

print(2 ** (n//2) % mo)

Submission status: Accepted

Solution code:
from collections import *
n=input()
a=Counter(map(int,raw_input().split()))
s=1
if n&1:
    if 0 not in a or a[0]>1:
        print 0
        exit(0)
    s+=1
while s<n:
    if s not in a or a[s]!=2:
        print 0
        exit(0)
    s+=2
print pow(2,n/2,10**9+7)

Submission status: Accepted

Solution code:
MOD = 1000000007
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

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

dp = [0]*(n+1)
flag1 = True
for e in A:
  dp[e] += 1
if n % 2 == 0:
  for i in range(1, n):
    if i % 2 == 1:
      if dp[i] != 2:
        flag1 = False

  if flag1:
    ans = repeatSquares(2, n//2)
    print(ans)
  else:
    print(0)
else:
  for i in range(2, n):
    if i % 2 == 0:
      if dp[i] != 2:
        flag1 = False

  if flag1:
    ans = repeatSquares(2, n//2)
    print(ans)
  else:
    print(0)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=[]#偶数だけ
C=[]#奇数だけ

if N%2==0:
  for i in range(0,int(N/2)):
    B+=[2*i,2*i]
    C+=[2*i+1,2*i+1]
  if A==B or A==C:
    n=int(N/2)
    ans=2**n
    print(ans%(10**9+7))
  else:
    print(0)
else:
  B+=[0]
  C+=[1]
  for i in range(0,int(N/2)):
    B+=[2*i+2,2*i+2]
    C+=[2*i+3,2*i+3]
  if A==B or A==C:
    n=int((N-1)/2)
    ans=2**n
#    ans=2**((N-1)/2)
    print(ans%(10**9+7))
  else: 
    print(0)

Submission status: Accepted

Solution code:
mod = 10**9 + 7

N = int(raw_input())
A = map(int, raw_input().split())
A.sort(reverse = True)

ans = 1
for i in xrange(N/2):
    if A[2*i] == A[2*i + 1] == abs((N - 1 - i) - i):
        pass
    else:
        ans = 0
if ans:
    ans = pow(2, N/2, mod)
print ans

Submission status: Accepted

Solution code:
## 2 * 100000 % 1000000007 の高速計算法がわからずOUT

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

lst = sorted(lst)
result = 1

valid_list = []
if n % 2 == 1:
    # 奇数
    valid_list.append(0)
    for i in range(1, int((n + 1) / 2)):
        valid_list.append(i * 2)
        valid_list.append(i * 2)
    if lst == valid_list:
        for i in range(int((n - 1) / 2)):
            result = (result * 2) % 1000000007
        print(int(result))
    else:
        print(0)
else:
    for i in range(1, int((n / 2) + 1)):
        valid_list.append((i * 2) - 1)
        valid_list.append((i * 2) - 1)
    if lst == valid_list:
        for i in range(int(n / 2)):
            result = (result * 2) % 1000000007
        print(int(result))
    else:
        print(0)

Submission status: Accepted

Solution code:
# coding: utf-8
num_N = int(input())
l_num = list(map(int, input().split()))
l_num.sort()

num_div = num_N // 2

if num_N % 2 == 1:
    l_cor = [0]
    for i in range(1, num_div + 1):
        l_cor.append(i * 2)
        l_cor.append(i * 2)

else:
    l_cor = []
    for i in range(1, num_div + 1):
        l_cor.append(2 * i - 1)
        l_cor.append(2 * i - 1)

if l_num == l_cor:
    print((2 ** num_div) % (10 ** 9 + 7))

else:
    print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict
length = int(input())
num_list = defaultdict(int)
target = [int(n) for n in input().split(" ")]

for t in target:
    num_list[t] += 1
if length == 1 and target[0] == 0:
    print(1)
elif length % 2 == 1:
    for k,v in num_list.items():
        if k % 2 != 0 or (k != 0 and v != 2) or (k == 0 and v != 1):
            print(0)
            break
    else:
        print((2**(length//2)) % (10**9 + 7))
else:
    for k,v in num_list.items():
        if k % 2 != 1 or (k != 0 and v != 2) or (k == 0 and v != 1):
            print(0)
            break
    else:
        print((2**(length//2)) % (10**9 + 7))

Submission status: Accepted

Solution code:
n=input()
a=map(int, raw_input().split())
a.sort()
cur = 1
if n % 2 == 1:
    if a[0] != 0:
        print 0
        exit(0)
    n -= 1
    a = a[1:]
    cur += 1
    
for i in xrange(n / 2):
    if a[i * 2] != cur or a[i * 2 + 1] != cur:
        print 0
        exit(0)
    cur += 2
print pow(2, n / 2, 1000000007)

Submission status: Accepted

Solution code:
n=int(input())
a=list(sorted(map(int,input().split())))
def valid():
    cur=(n+1)&1
    for i in range(n):
        if n&1==0 and i&1==0 and i>0:
            cur+=2
        if n&1==1 and i&1==1:
            cur+=2
        if a[i] != cur: return False
    return True
print(2**(n//2)%(10**9+7) if valid() else 0)

Submission status: Accepted

Solution code:
n=int(input())
a=map(int,input().split())
def valid():
    b = list(range((n+1)&1, n+1, 2))
    for i in range(len(b)-1, -1, -1):
        b.insert(i, b[i])
    if b[0] == 0:
        b = b[1:]
    return list(sorted(a)) == b
ans,mod = 1,10**9+7
for i in range(n//2):
    ans = (ans * 2) % mod
print(ans if valid() else 0)