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: Wrong Answer

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

if n % 2 == 0:
    i = 0
    while True:
        if i == n // 2:
            print(2 ** (n//2))
            break
        if a.count(2 * i + 1) == 2:
            i += 1
            continue
        else:
            print(0)
            break

elif a.count(0) != 1:
    print(0)

else:
    i = 1
    while True:
        if i == (n - 1) // 2:
            print(2 ** ((n-1)//2))
            break
        if a.count(2 * i) == 2:
            i += 1
            continue
        else:
            print(0)
            break

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

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))

Submission status: Wrong Answer

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:ans=1
else:
    for i in b:
        if b[i]!=2 or i%2==0:
            ans=1
if ans==1:print(0)
else: print(2**(len(a)//2))

Submission status: Wrong Answer

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
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)
	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)

Submission status: Wrong Answer

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)
    else:
        print(0)
else:
    b = []
    for i in range(q):
        b.append(c[i*2+1] == 2)
    if all(b):
        print(2**q)
    else:
        print(0)

Submission status: Wrong Answer

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 -= 2
        return (2 ** (tmp//2))%MOD
    return 0


print(m())

Submission status: Wrong Answer

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(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: Wrong Answer

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))
else:
    print(0)

Submission status: Wrong Answer

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(2 ** ((n) // 2 ))
else:
    print(0)

Submission status: Wrong Answer

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:
            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(2 ** ((n) // 2 ))
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if n % 2 == 0 and len(set(l)) == n//2:
  print(2**(n//2))
elif not n % 2 == 0 and l.count(0) == 1:
  print(2**((n-1)//2))
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
counts = {}
flag = True
for i in l:
  if i in counts:
    if counts[i] >= 2:
      print(0)
      flag = False
      break
    else:
      counts[i] += 1
  else:
    counts[i] = 1

if flag:
  if n % 2 == 0:
    print(2**len(counts))
  else:
    if not counts[0] == 1:
      print(0)
    else:
      print(2**(len(counts)-1))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted([int(i) for i in input().split()])
mod = 10e9+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: Wrong Answer

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 = []
    for i in range(n-1, 2):
        hikaku += []
    hikaku += [n-1]
    if sorted(a) == hikaku:
        print(beki((n - 1) / 2))
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
import sys

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

if n % 2 == 0:
    i = 1
    while True:
        if i in a:
            a.remove(i)
        else:
            print(0)
            sys.exit()
        if i in a:
            a.remove(i)
        else:
            print(0)
            sys.exit()
        i += 2
        if a == []:
            break       
    print((2 ** (n / 2)) % (10 ** 9 + 7))

elif n == 1:
    if a == [0]:
        print("1")
    else:
        print("0")
else:
    i = 2
    while True:
        if i in a:
            a.remove(i)
        else:
            print(0)
            sys.exit()
        if i in a:
            a.remove(i)
        else:
            print(0)
            sys.exit()
        i += 2
        if a == [0]:
            break
    print((2 ** ((n - 1) / 2)) % (10 ** 9 + 7))

Submission status: Wrong Answer

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((((len(s))//2)**2)%(10**9+7))
else:
    print(0)

Submission status: Wrong Answer

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(((len(s))//2)**2)
else:
    print(0)

Submission status: Wrong Answer

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))
else:
    for i in data.values():
        if i!=2:
            print(0)
            exit()
    print(2**(n//2))

Submission status: Wrong Answer

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()
    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()
    for i in data.values():
        if i!=2:
            print(0)
            exit()
    print((2**(n//2))%mod)

Submission status: Wrong Answer

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()
    print((2**(n//2))%mod)
else:
    if a.count(0)!=1:
        print(0)
        exit()
    print((2**(n//2))%mod)

Submission status: Wrong Answer

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:
        if N==1:
            p = 1
        else:
            continue
    elif v==2:
        p += 1
        continue
    else:
        p = 0
        break 
print(p if p==0 else (2**p)%(10**9+7))

Submission status: Wrong Answer

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 
print(p if p==0 else (2**p)%(10**9+7))

Submission status: Wrong Answer

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 
print(p if p==0 else 2**p)

Submission status: Wrong Answer

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:
    n -= 1
    for i in range(1, n, 2):
        if P[i] != P[i+1]:
            flag = False
            break
if flag:
    ans = 2 ** n % (10 ** 9 + 7)
else:
    ans = 0
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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) if right else 0)

Submission status: Wrong Answer

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
  
  if len(memo) % 2 == 0:
    return len(memo)**2 % mod
  else:
    return (len(memo)-1)**2 % mod

  return memo
  
print(f())

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
mod = 10**9 + 7
def f():
  memo = {}
  count = 0
  zero = False
  for i in l:
    if i in memo:
      if memo[i] >= 2:
        return 0
      elif i == 0 and memo[i] >= 1:
        return 0
      else:
        memo[i] += 1
    else:
      memo[i] = 1
  
  for k, v in memo.items():
    if not k == 0 and v == 2:
      count += 1
    elif k == 0 and v == 1:
      zero = True
    else:
      return 0

  if zero:
    if count == len(memo)-1:
      return count**2 % mod
    else:
      return 0
  else:
    if count == len(memo):
      return count**2 % mod
    else:
      return 0

print(f())

Submission status: Wrong Answer

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%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) if right else 0)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
mod = 10**9 + 7
def f():
  memo = {}
  count = 0
  zero = False
  for i in l:
    if i in memo:
      if memo[i] >= 2:
        return 0
      elif i == 0 and memo[i] >= 1:
        return 0
      else:
        memo[i] += 1
    else:
      memo[i] = 1
  
  for k, v in memo.items():
    if not k == 0 and v == 2:
      count += 1
    elif k == 0 and v == 1:
      zero = True

  if zero:
    if count == len(memo)-1:
      return count**2 % mod
    else:
      return 0
  else:
    if count == len(memo):
      return count**2 % mod
    else:
      return 0

print(f())

Submission status: Wrong Answer

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

def f():
  memo = {}
  count = 0
  zero = False
  for i in l:
    if i in memo:
      if memo[i] >= 2:
        return 0
      elif i == 0 and memo[i] >= 1:
        return 0
      else:
        memo[i] += 1
    else:
      memo[i] = 1
  
  for k, v in memo.items():
    if not k == 0 and v == 2:
      count += 1
    elif k == 0 and v == 1:
      zero = True

  if zero:
    if count == len(memo)-1:
      return count**2
    else:
      return 0
  else:
    if count == len(memo):
      return count**2
    else:
      return 0

print(f())

Submission status: Wrong Answer

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:
        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: Wrong Answer

Solution code:
N = int(input())
inline = list(map(int,input().split()))
di = {}
key = 0
if N%2 ==1:
    cen = int(N/2)+1
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: Wrong Answer

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)


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

Submission status: Wrong Answer

Solution code:
n =int(input())
num = [0]*n
tmp = input().split()
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))
  else:
    print(pow(2,n//2))
else:
  print(0)

Submission status: Wrong Answer

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))
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: Wrong Answer

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))
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))

Submission status: Wrong Answer

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 = (n//2)**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 = ((n-1)//2)**2

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

Submission status: Wrong Answer

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 = (n//2)**2
        
else:
    if c['0'] == 1 :
        del c['0']
        if all(v == 2 for v in c.values()):
            ans = ((n-1)//2)**2

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

Submission status: Wrong Answer

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 % 2 == 0:
    for i in range(n):
        check_ans += 2 * x - 1
        check_in += a[i]
        if check_ans != check_in:
            flag = 1
            print(-1)
            break
        if i % 2 == 1:
            x += 1
    if flag == 0:
        print(2**int(n/2))
else:
    for i in range(1, n):
        check_ans += 2 * x
        check_in += a[i]
        if check_ans != check_in:
            flag = 1
            print(-1)
            break
        if i % 2 == 0:
            x += 1
    if flag == 0:
        print(2**int((n-1)/2))

Submission status: Wrong Answer

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

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)))
    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)))
    else:
        print(0)

Submission status: Wrong Answer

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(((N // 2) ** 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((((N - 1) // 2) ** 2) % MOD)
                break
        except:
            print(0)
            break


solve()

Submission status: Wrong Answer

Solution code:
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(((N // 2) ** 2) % MOD)
                break
            else:
                for i in range(N):
                    if i == 0 and checker[i] != 1:
                        raise EndLoop
                    elif not i % 2 and checker[i] != 2:
                        raise EndLoop
                    elif i % 2 and i != 0 and checker[i] != 0:
                        raise EndLoop

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


solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
old, check = 0, 1
if len(A) is 1:
    if A[0] == 0:
        print(1)
        exit()
    else:
        print(0)
        exit()
if len(A) % 2 is 1:
    if A[0] is not 0 or A[1] is not 2:
        print(0)
        exit()
    else:
        for i in range(1, N):
            if old is A[i] and check is 0:
                check += 1
            elif old + 2 is A[i] and check is 1:
                old = A[i]
                check = 0
            else:
                print(0)
                exit()

        print((2 ** ((N - 1) // 2)) % (10 ** 9 + 7))
else:
    old = -1
    for i in range(N):
        if old is A[i] and check is 0:
            check += 1
        elif old + 2 is A[i] and check is 1:
            old = A[i]
            check = 0
        else:
            print(0)
            exit()
    print((2 ** (N // 2) % (10 ** 9 + 7)))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
old, check = 0, 1
if len(A) is 1:
    if A[0] == 0:
        print(1)
        exit()
    else:
        print(0)
        exit()
if len(A) % 2 is 1:
    if A[0] is not 0 or A[1] is not 2:
        print(0)
        exit()
    else:
        for i in range(1, N):
            if old is A[i] and check is 0:
                check += 1
            elif old + 2 is A[i] and check is 1:
                old = A[i]
                check = 0
            else:
                print(0)
                exit()

        print(2 ** ((N - 1) // 2))
else:
    old = -1
    for i in range(N):
        if old is A[i] and check is 0:
            check += 1
        elif old + 2 is A[i] and check is 1:
            old = A[i]
            check = 0
        else:
            print(0)
            exit()
    print(2 ** (N // 2))

Submission status: Wrong Answer

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))
    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))
    else:
        print("0")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
from collections import Counter
c=Counter(a)
def pattern(n):
    r=1
    if n%2==1:
        r=2
        if c[0]!=1:
            return 0
    for i in range(n//2):
        if c[2*i+r]!=2:
            return 0
    return 2**(n//2)
print(pattern(n))

Submission status: Wrong Answer

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
else :
  print 0