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:
import math
n = int(input())
lis = list(map(str,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()
print(2 ** (math.floor(n/2)))

Submission status: Runtime Error

Solution code:
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(1<<((n-1)//2)%mod)
    else:
        print(0)
else:
    if all([a[i] == i+(i+1)%2 for i in range(n)]):
        print(1<<(n//2)%mod)
    else:
        print(0)

Submission status: Runtime Error

Solution code:
import sys
def coun(n):
  if n == 0:
    return 1
  else:
    return (2*coun(n-1))%(10**9+7)
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: Runtime Error

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(filter(lambda c: c == 2, cnt.values())) != 0:
        print(0)
    else:
        print(2 ** (N // 2))
else:
    if cnt[0] != 1:
        print(0)
    cnt.pop(0)
    if len(filter(lambda c: c == 2, cnt.values())) != 0:
        print(0)
    else:
        print(2 ** (N // 2))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())

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

M = len(set(report_list))


def how_many_num_in_list(list, num):
    count = 0
    for element in list:
        if element == num:
            count += 1
    return count


# 同じ数字が２個ずつあるか
# def is_ready_for_solve(list):
#     if N % 2 == 0:
#         c = 0
#         for n in set(report_list):
#             if how_many_num_in_list(report_list, n) == 2:
#                 c += 1
#         if c == N / 2:
#             return True
#         else:
#             return False
#
#     else:
#         c = 0
#         for n in set(report_list):
#             if n == 0:
#                 continue
#             elif how_many_num_in_list(report_list, n) == 2:
#                 c += 1
#         if c == (N - 1) / 2:
#             return True
#         else:
#             return False


if N % 2 == 0:
    if how_many_num_in_list(report_list, 0) == 0:
        # if is_ready_for_solve(report_list):
        if N == M * 2:
            print(int((2 ** (N / 2)) % (10 ** 9 + 7)))
        else:
            print(0)
    else:
        print(0)
else:
    if how_many_num_in_list(report_list, 0) == 1:
        # if is_ready_for_solve(report_list):
        if N - 1 == (M - 1) * 2:
            print(int((2 ** ((N - 1) / 2)) % (10 ** 9 + 7)))
        else:
            print(0)
    else:
        print(0)

Submission status: Runtime Error

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

lst = sorted(lst)

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

Submission status: Runtime Error

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

lst = sorted(lst)

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:
        print((2 ** (((n - 1) / 2) / 5) % 1000000007) ** 5 % 1000000007)
    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:
        print(int(2 ** ((n / 2) / 5) % 1000000007) ** 5 % 1000000007)
    else:
        print(0)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = input()
a = [int(x) for x in raw_input().split()]
a.sort()
c = 0
if n&1:
    if a[0] == 0:
        del a[0]
        d = Counter(a)
        for i in d.keys():
            if i == 0:
                print 0
                exit(1)
            if i&1:
                print 0
                exit(1)
            if not(i&1):
                if d[i] == 2:
                    c += 1
                if d[i] != 2:
                    print 0
                    exit(1)
    if c == (n-1)//2:
        print (1 << c)%(10**9+7)
if not(n&1):
    d = Counter(a)
    for i in d.keys():
        if i&1:
            if d[i] == 2:
                c +=1
            if d[i] != 2:
                print 0
                exit(1)
        if not(i&1):
            print 0
            exit(1)
    if c == n//2:
        print (1 << c)%(10**9+7)

Submission status: Runtime Error

Solution code:
import sys

cin = sys.stdin
cin = open("in.txt", "r")

MODULO = int(10**9+7)
N = int(cin.readline())
A = list(map(int, cin.readline().split()))
pos = [0]*(N)
if (N%2==1):
    pos[N//2+1]=1
for ai in A:
    if (ai+N)%2==0:
        print(0)
        exit()
    pos[ai]+=1
    if pos[ai]>2:
        print(0)
        exit()
cnt = 1
for i in range(N//2):
    cnt = cnt * 2 % MODULO
print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
MOD = 10**9 + 7
def calc(a):
	if 0 in a:
		if a.count(0) != 1:
			return 0
		for i in [x*2 for x in range(1,int(N/2) + 1)]:
			if a.count(i) != 2:
				return 0
	else:
		for i in [x*2 - 1 for x in range(1,int(N/2) + 1)]:
			if a.count(i) != 2:
				return 0
	return 2 ** int(N/2)
if N % 2 is 0:
	if len(filter(lambda n:n%2==0, A)) > 0:
		print(0)
	else:
		print(calc(A) % MOD)
else:
	if len(filter(lambda n:n%2==1, A)) > 0:
		print(0)
	else:
		print(calc(A) % MOD)

Submission status: Runtime Error

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

def maybe_check(n,A):
    try:
        if n <= 0 or n >= 10000:
            raise

        if len(A) <= 0 or len(A) > n:
            raise

        div = 10 ** 9 + 7
        maybe_list = []
        for i in range(1, n+1):
            left = abs(i - n)
            right = (n -1 )- left
            maybe_list.append(abs(left - right))

        pattern =  len(set([x for x in maybe_list if maybe_list.count(x) != 1]))

        for i in A:
            if i in maybe_list:
                maybe_list.remove(i)
            else:
                raise

        return (2 ** pattern) % div

    except:
        return 0


args = sys.argv
_n = int(args[1])
_A = map(int,args[2:])

print maybe_check(_n,_A)

Submission status: Runtime Error

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

def maybe_check(n,A):
    if n <= 0 or n >= 10000:
        return False

    if len(A) <= 0 or len(A) > n:
        print len(A),n-1
        return False

    div = 10 ** 9 + 7
    maybe_list = []
    for i in range(1, n+1):
        left = abs(i - n)
        right = (n -1 )- left
        maybe_list.append(abs(left - right))

    pattern =  len(set([x for x in maybe_list if maybe_list.count(x) != 1]))

    for i in A:
        if i in maybe_list:
            maybe_list.remove(i)
        else:
            return 0

    return (2 ** pattern) % div



args = sys.argv
_n = int(args[1])
_A = map(int,args[2:])

print maybe_check(_n,_A)

Submission status: Runtime Error

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

def maybe_check(n,A):
    if n <= 0 or n >= 10000:
        return False

    if len(A) <= 0 or len(A) > n:
        print len(A),n-1
        return False

    maybe_list = []
    for i in range(1, n+1):
        left = abs(i - n)
        right = (n -1 )- left
        maybe_list.append(abs(left - right))

    pattern =  len(set([x for x in maybe_list if maybe_list.count(x) != 1]))

    for i in A:
        if i in maybe_list:
            maybe_list.remove(i)
        else:
            return 0

    return (2 ** pattern) % div



args = sys.argv
n = int(args[1])
A = map(int,args[2:])

div = 10 ** 9 + 7
print maybe_check(n,A)

Submission status: Runtime Error

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

def maybe_check(A,n):
    maybe_list = []
    for i in range(1, n+1):
        left = abs(i - n)
        right = (n -1 )- left
        maybe_list.append(abs(left - right))

    pattern =  len(set([x for x in maybe_list if maybe_list.count(x) != 1]))

    for i in A:
        if i in maybe_list:
            maybe_list.remove(i)
        else:
            return 0

    return (2 ** pattern) % div


args = sys.argv
n = int(args[1])
A = map(int,args[2:])
div = 10 ** 9 + 7
print maybe_check(A, n)

Submission status: Runtime Error

Solution code:
import sys

def maybe_check(A,n):
    maybe_list = []
    for i in range(1, n+1):
        left = abs(i - n)
        right = (n -1 )- left
        maybe_list.append(abs(left - right))

    pattern =  len(set([x for x in maybe_list if maybe_list.count(x) != 1]))

    for i in A:
        if i in maybe_list:
            maybe_list.remove(i)
        else:
            return 0

    return (2 ** pattern) % div


args = sys.argv
n = int(args[1])
A = map(int,args[2:])
div = 10 ** 9 + 7
print maybe_check(A, n)