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: Runtime Error

Solution code:
n = int(input())
a = input().split()
d=int(n/2)
for i in range(len(a)):
  a[i]=int(a[i])
a.sort()
a.reverse()
j=1
count=2
while(a[j-1]==a[j]):
  j+=2
  count=count*2
  if(n-1==j):
    break
  elif(n-2==j):
    break

if(count==2**(d)):
  print(2**(d))
else:
  print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
a = input().split()
d=int(n/2)
for i in a:
  i=int(i)
a.reverse()
j=0
count=1
while(a[j]==a[j+1]):
  j+=2
  count=count*2
  if(n-1==j):
    break
  elif(n-2==j):
    break

if(count==2**(d)):
  print(2**(d))
else:
  print(0)

Submission status: Runtime Error

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 = 2**r % mod
    print(int(ans))
else:
    print(0)

Submission status: Runtime Error

Solution code:
from collections import Counter
from math import log2

N = int(input())
A = [int(i) for i in input().split()]
po = Counter(A)
ans = -1
mod = 10**9 + 7

if N % 2 == 0:
    if po[0] != 0:
        ans = 0
    else:
        for i in range(1,N,2):
            if po[i] != 2:
                ans = 0
        if ans != 0:
            while N/2 >= mod:
                N -= 2*(mod-1)
            ans = int(2**(N/2))
else:
    if po[0] != 1:
        ans = 0
    else:
        for i in range(2,N,2):
            if po[i] != 2:
                ans = 0
        if ans != 0:
            while (N-1)/2 >= mod:
                N -= (2*mod-1)
            ans = int(2**((N-1)/2))

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())
A = [int(i) for i in input().split()]
po = Counter(A)
ans = -1
mod = 10**9 + 7

if N % 2 == 0:
    if po[0] != 0:
        ans = 0
    else:
        for i in range(1,N,2):
            if po[i] != 2:
                ans = 0
        if ans != 0:
            ans = int(2**(N/2)) % mod
else:
    if po[0] != 1:
        ans = 0
    else:
        for i in range(2,N,2):
            if po[i] != 2:
                ans = 0
        if ans != 0:
            ans = int(2**((N-1)/2)) % mod 

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
f = lambda :[int(i) for i in input().split()]

N = int(input())
A = f()
po = Counter(A)
ans = -1

if N % 2 == 0:
    if po[0] != 0:
        ans = 0
    else:
        for i in range(1,N,2):
            if po[i] != 2:
                ans = 0
        if ans != 0:
            ans = int(2**(N/2))
else:
    if po[0] != 1:
        ans = 0
    else:
        for i in range(2,N,2):
            if po[i] != 2:
                ans = 0
        if ans != 0:
            ans = int(2**((N-1)/2))

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
div = 10**9 + 7
if N % 2 == 0:
    if A.count(0) != 0:
        print(0)
    else:
        A = dict(Counter(A))
        val = A.values()
        val = list(filter(lambda x: x == 2, val))
        if len(val) * 2 == N:
            print(int(2**(N/2) % div))
        else:
            print(0)

else:
    if A.count(0) != 1:
        print(0)
    else:
        A.remove(0)
        A = dict(Counter(A))
        val = A.values()
        val = list(filter(lambda x: x == 2, val))
        if len(val) * 2 == (N-1):
            print(int(2 ** ((N-1) / 2) % div))
        else:
            print(0)

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
div = 10**9+7

if N % 2 == 0:
    A = dict(Counter(A))
    val = A.values()
    val = list(filter(lambda x: x == 2, val))
    if len(val) * 2 == N:
        print(int(2**(N/2) % div))
    else:
        print(0)

else:
    if A.count(0) != 1:
        print(0)
    else:
        A.remove(0)
        A = dict(Counter(A))
        val = A.values()
        val = list(filter(lambda x: x == 2, val))
        if len(val) * 2 == (N-1):
            print(int(2 ** ((N-1) / 2) % div))
        else:
            print(0)

Submission status: Runtime Error

Solution code:
num =int(input())

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

_len = len(val)
sort_val = sorted(val)
set_val = set(sort_val)

res = True

if len(sort_val) %2 != 0 and sort_val[1] == 0:
    res = False
elif len(sort_val) %2 != 0 and sort_val[1] != 0:
    sort_val = sort_val[1:]
    set_val.remove(0)

if res:
    for i in set_val:
        if len(sort_val) == 2 and sort_val[0] == sort_val[1]:
            break
        if sort_val[2] == i:
            res = False
            break
        else:
            sort_val = sort_val[2:]


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

print(0 if not res else cnt)

Submission status: Runtime Error

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

ans = 1
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: Runtime Error

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
old, check = 0, 0
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 <= 1:
                check += 1
            elif old + 2 is A[i] and check <= 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 <= 1:
            check += 1
        elif old + 2 is A[i] and check <= 1:
            old = A[i]
            check = 0
        else:
            print(0)
            exit()
    print(2 ** (N // 2))

Submission status: Runtime Error

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)) % (1e9 + 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)) % (1e9 + 7))

Submission status: Runtime Error

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(int((2**((n - 1) // 2)) % (1e9 + 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(int((2**(n // 2)) % (1e9 + 7)))

Submission status: Runtime Error

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:
        for i in range(2, n, 2):
            if not(a[i - 1] == i and a[i] == i):
                print(0)
                flag = False
                break
    if flag:
        print(int((2**((n-1)//2))%(1e9+7)))

else:
    for i in range(1, n, 2):
        if not(a[i - 1] == i and a[i] == i):
            print(0)
            flag = False
            break
    if flag:
        print(int((2**(n//2))%(1e9+7)))

Submission status: Runtime Error

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

if N % 2 == 0:
	l = list(range(1, N, 2)) * 2
else:
	l = [0] + list(range(2, N, 2)) * 2

flag = True
if sorted(A) != sorted(l):
	flag = False

if flag == False:
	print(0)
else:
	if N % 2 == 0:
		print(int(2**(N/2)) % 1000000007)
	else:
		print(int(2**((N-1)/2)) % 1000000007)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

if N % 2 == 0:
	l = list(range(1, N, 2)) * 2
else:
	l = [0] + list(range(2, N, 2)) * 2

flag = True

cntA = Counter(A)
cntl = Counter(l)

if cntA != cntl:
	flag = False

if flag == False:
	print(0)
else:
	if N % 2 == 0:
		print(int(2**(N/2)) % 1000000007)
	else:
		print(int(2**((N-1)/2)) % 1000000007)

Submission status: Runtime Error

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

if N % 2 == 0:
	l = list(range(1, N, 2)) * 2
else:
	l = [0] + list(range(2, N, 2)) * 2

flag = True
for i in range(N):
	if sorted(T)[i] != sorted(A):
		flag = False
		break
	
if flag == False:
	print(0)
else:
	if N % 2 == 0:
		print(int(2**(N/2)) % 1000000007)
	else:
		print(int(2**((N-1)/2)) % 1000000007)

Submission status: Runtime Error

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

if N % 2 == 0:
	l = list(range(1, N, 2)) * 2
else:
	l = [0] + list(range(2, N, 2)) * 2

flag = True
for i in range(N):
	if sorted(T)[i] != sorted(A):
		flag = Flase
		break
	
if flag == False:
	print(0)
else:
	if N % 2 == 0:
		print(int(2**(N/2)) % 1000000007)
	else:
		print(int(2**((N-1)/2)) % 1000000007)

Submission status: Runtime Error

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

if N % 2 == 0:
	l = list(range(1, N, 2)) * 2
else:
	l = [0] + list(range(2, N, 2)) * 2

flag = True
if sum(A) != sum(l):
	flag = False
if A.count(0) > 1:
	flag = False
	
if flag == False:
	print(0)
else:
	if N % 2 == 0:
		print(int(2**(N/2)) % 1000000007)
	else:
		print(int(2**((N-1)/2)) % 1000000007)

Submission status: Runtime Error

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

print(Nc%1000000007)

Submission status: Runtime Error

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

print(Nc)

Submission status: Runtime Error

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:
			print(int(2**(N/2)%(10**9+7)))
	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:
				print(int(2**((N-1)/2)%(10**9+7)))

Submission status: Runtime Error

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

divider = pow(10,9)+7

def checkTrueReport(array):
    if len(array) != N:
        return False
    
    sorted_array = sorted(array)
    correct_array = list()
    if N % 2 == 0:
        for i in range(0,N):
            element = i
            if i %2==0:
                element +=1
            correct_array.append(element)
    else:
        for i in range(0,N):
            element = i
            if i %2!=0:
                element +=1
            correct_array.append(element)
    return correct_array == sorted_array
checkTrueReport(As)

if checkTrueReport(As):
    if N % 2 == 0:
        answer = pow(2,N/2)%divider
    else:
        answer = pow(2,(N-1)/2)%divider
    print(int(answer))
else:
    print(0)

Submission status: Runtime Error

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

list.sort()

if n%2==0:
    count=0
else: count=1
while count<n and list[count]==list[count+1]:
    count+=2
if count>=len(list):
    if n%2==0:
        print(int(2**(n/2)))
    else:
        print(int(2**((n-1)/2)))
else:
    print(0)

Submission status: Runtime Error

Solution code:
def pow(base, nod):
	MOD = 10**9+7
	ans = 1
	tmp = 2
	while base>0:
		if base%2==1: ans=ans*tmp%MOD
		tmp = tmp**2%MOD
		base /= 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:
		if k%2!=1 or v!=2:
		isValid=False
else:
	for k,v in d:
		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: Runtime Error

Solution code:
from collections import Counter

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

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

Submission status: Runtime Error

Solution code:
from collections import Counter

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

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

Submission status: Runtime Error

Solution code:
from collections import Counter

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

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

Submission status: Runtime Error

Solution code:
N = int(raw_input())
line = map(int,raw_input().split(' '))
if N%2 == 0:
    for i in range(1,N-1,2):
        if line.count(i) != 2:
            print 0
            exit(0)
        line.remove(i)
        line,remove(i)
    print 2**(N/2) %(10**9+7)
else:
    if line.count(0) != 1:
        print 0
        exit(0)
    line.remove(0)
    for i in range(2,N-1,2):
        if line.count(i) != 2:
            print 0
            exit(0)
        line.remove(i)
        line,remove(i)
    print 2**(N/2)%(10**9+7)

Submission status: Runtime Error

Solution code:
N = int(raw_input())
line = map(int,raw_input().split(' '))
if N%2 == 0:
    for i in range(1,N-1,2):
        if line.count(i) != 2:
            print 0
            exit(0)
    print 2**(N/2)
else:
    if line.count(0) != 1:
        print 0
        break
    for i in range(2,N-1,2):
        if line.count(i) != 2:
            print 0
            exit(0)
    print 2**(N/2)

Submission status: Runtime Error

Solution code:
N = int(input())
L = input().split()
if N % 2 == 0:
    sc = 0
    for i in range(0, N):
        n = L.count(str(i))
        if n  ¥= 2:
            sc += 1
            break
        else:
            pass
    if sc ==0:
        ss = 2 * (N / 2)
        print(ss)
else:
    n = L.count("0")
    if n % 2 ¥= 0:
        print(0)
    else:
        for i in range(0, N):
        n = L.count(str(i))
        if n  ¥= 2:
            sc += 1
            break
        else:
            pass
    if sc ==0:
        ss = 2 * (N / 2)
        print(ss)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)

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

if N%2 == 1:
      if A.count(0) != 1:
            print(0)
      elif sum(A) != (N+1)*(N-1)/2:
            print(0)
      else:
            print(int((2**((N-1)/2))%(10**9+7)))
      
else:
      if A.count(0) != 0:
            print(0)
      elif sum(A) != N**2/2:
            print(0)
      else:
            print(int((2**(N/2))%(10**9+7)))

Submission status: Runtime Error

Solution code:
import numpy as np
import math

N = int(input())
A = list(map(int, input().split()))
if N % 2 == 1 and A.count(0) == 1 and np.all(A.count(i*2+2)==2 for i in range(N//2)):
    print(int(math.fmod(math.pow(2, N//2), (math.pow(10, 9) + 7))))
elif N % 2 == 0 and np.all(A.count(i*2+1)==2 for i in range(N//2)):
    print(int(math.fmod(math.pow(2, N//2), (math.pow(10, 9) + 7))))
else:
    print(0)

Submission status: Runtime Error

Solution code:
import numpy as np
import math

N = int(input())
A = list(map(int, input().split()))
if N % 2 == 1 and A.count(0) == 1 and np.all(A.count(i*2+2)==2 for i in range(N//2)):
    print(np.int64(np.remainder(math.pow(2, N//2), (math.pow(10, 9) + 7))))
elif N % 2 == 0 and np.all(A.count(i*2+1)==2 for i in range(N//2)):
    print(np.int64(np.remainder(math.pow(2, N//2), (math.pow(10, 9) + 7))))
else:
    print(0)

Submission status: Runtime Error

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

if N%2 == 1:
      if A.count(0) != 1:
            print(0)
      elif sum(A) != (N+1)*(N-1)/2:
            print(0)
      else:
            print(int((2**((N-1)/2))%(10**9+7)))
      
else:
      if A.count(0) != 0:
            print(0)
      elif sum(A) != N**2/2:
            print(0)
      else:
            print(int((2**(N/2))%(10**9+7)))

Submission status: Runtime Error

Solution code:
N = int(raw_input())
A=map(int, raw_input().split(' '))
A.sort()
flug = 0
if N % 2 == 0:
    for i in range(N):
        if not A[i] == 2*(i/2)+1:
          N = int(raw_input())
A=map(int, raw_input().split(' '))
A.sort()
flug = 0
if N % 2 == 0:
    for i in range(N):
        if not A[i] == 2*(i/2)+1:
            print 0
            flug = 1
            break
 
else:
    for i in range(N):
        if i % 2 == 0:
            if not A[i] == i:
                print 0
                flug =1
                break
        else:
            if not A[i] == i+1:
                print 0
                flug = 1
                break
if flug == 0:
    print(pow(2, N/2))
            flug = 1
            break
 
else:
    for i in range(N):
        if i % 2 == 0:
            if not A[i] == i:
           
                flug =1
                break
        else:
            if not A[i] == i+1:
                
                flug = 1
                break
if flug == 0:
    print(pow(2, N/2))
else:
    print 0

Submission status: Runtime Error

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

dic = dict()
for a in A:
    a = int(a)
    dic[a] = dic.get(a, 0) + 1

keys = list(dic.keys())
values = list(dic.values())

if N % 2 == 0:
    if keys == [2*i+1 for i in range(N//2)] and values == [2 for i in range(N//2)]:
        print(2**(N//2) % (10**9 + 7))
    else:
        print(0)
else:
    if keys == [2*i for i in range(N//2)] and values == [1] + [2 for i in range(N//2 - 1)]:
        print(2**(N//2) % (10**9 + 7))
    else:
        print(0)

Submission status: Runtime Error

Solution code:
import sys

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

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:
    dic[i] -= 1

    if dic[i] < 0:
        print(0)
        sys.exit()

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(n)]
res = 1

for i in a:
    b[i] += 1

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