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:
def powmod(b,e,m):
    r=1
    while e>0:
        if e%2==1:
            r=(r*b)%m
        e>>=1
        b=(b*b)%m
    return r

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

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

for a in A:
    if a in d:
        d[a]+=1
    else:
        d[a]=1

if check(N,d):
    ans=powmod(2,N//2,10**9+7)
else:
    ans=0
print(ans)

Submission status: Accepted

Solution code:
import sys


def test(a):
    if len(a) % 2:
        if a[0]:
            return False

        del a[0]

    for i in range(0, len(a) - 2, 2):
        if a[i] != a[i + 1] or a[i + 2] - a[i] != 2:
            return False

    return True


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

if a[:2] == [0, 0]:
    print(0)
    sys.exit(0)

elif a == [0]:
    print(1)
    sys.exit(0)

elif a == [0, 1, 1] or a == [1, 1]:
    print(2)
    sys.exit(0)

print((2 ** round(len(a) / 2)) % (10 ** 9 + 7) if test(a) else 0)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
M = N//2
c = Counter(A)
if N % 2 == 1 and A.count(0) == 1 and all(c[i*2+2] == 2 for i in range(M)):
    print((2 ** M) % (10**9+7))
elif N % 2 == 0 and all(c[i*2+1]==2 for i in range(M)):
    print((2 ** M) % (10**9+7))
else:
    print(0)

Submission status: Accepted

Solution code:
def error_check(n,l):
	total = 0
	if n % 2 == 0:
		i = 1
		for k in range(n//2):
			total += (i+i)
			i += 2
		if total == sum(l):
			return True
		else:
			return False
	else:
		i = 2
		for k in range(n//2):
			total += (i+i)
			i += 2
		if total == sum(l):
			return True
		else:
			return False

n = int(input())
a = list(map(int,input().split()))
m = n // 2
if error_check(n,a):
	print((2 ** m) % (10**9+7))
else:
	print(0)

Submission status: Accepted

Solution code:
N = int(input())
line = list(map(int, input().split()))
n = N - 1
ans = 1
line.sort()
s = len(line)
index = s - 1
while(index > 1):
    if line[index] == n and line[index-1] == n:
        ans *= 2
        n = n - 2
        index = index - 2
    else:
        print(0)
        break

if index == 1:
    if line[index] == n and line[index-1] == n:
        ans *= 2
        print(ans % (10**9+7))
    else:
        print(0)

elif index == 0:
    if line[0] == 0:
        print(ans % (10**9+7))
    else:
        print(0)

Submission status: Accepted

Solution code:
from sys import stdin
mod=10**9+7
def expo(n):
    if n<=0:
        return 1
    if n%2==0:
        return expo(n//2)*expo(n//2)%mod
    else:
        return 2*expo(n//2)*expo(n//2)%mod

n=int(input())
differences=list(map(int,stdin.readline().split()))
repetition=0
nbDiff=[0]*n
places=[0]*n
possible=True
moitie=n//2
for i in range(n):
    difference=differences[i]
    moitieDiff=difference//2
    if nbDiff[difference]==1:
        repetition+=1
    nbDiff[difference]+=1    
    
    if n%2==1:
        places[moitie+moitieDiff]+=1
        places[moitie-moitieDiff]+=1
    else:
        places[moitie+moitieDiff]+=1
        places[moitie-moitieDiff-1]+=1

for i in range(n):
    if places[i]!=2:
        possible=False

if possible:
    print(expo(repetition))
else:
    print(0)

Submission status: Accepted

Solution code:
import collections
N=int(input())
B=[]
g=10**9+7
A=[int(i) for i in input().split()]
for i in A:
 B.append(((N-1+i)/2,(N-1-i)/2))
c= collections.Counter(B)
d=1
for i,j in c.items():
 d*=j
 if j==1 and i[0]!=i[1]:
   d=0
   break
 if d>g:
   d=d%g
print(d%g)

Submission status: Accepted

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:
            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))%(pow(10,9)+7)
else:
    print 0

Submission status: Accepted

Solution code:
import collections
N=int(raw_input())
A=map(int, raw_input().split())
count_A=collections.Counter(A).most_common(1)
cnt = 0
if N == 1:
    if A[0] == 0:
        print 1
    else:
        print 0
elif N%2 == 0:
    if A.count(0) != 0:
        print 0
        cnt = 1
    elif count_A[0][1] != 2:
        print 0
        cnt = 1
    if cnt == 0:
        print (2**(N/2)) % (10**9+7)
else:
    if A.count(0) != 1:
        print 0
        cnt = 1
    elif count_A[0][1] != 2:
        print 0
        cnt = 1
    if cnt == 0:
        print (2**(N/2)) % (10**9+7)

Submission status: Accepted

Solution code:
#!/usr/bin/python

import sys

def main(argv):
    n = sys.stdin.readline().rstrip()

    while n:
        result = -1
        n = int(n)
        count = [0 for i in range(0, int(n / 2))]
        if n % 2 != 0:
            count.append(0)
        a = [int(i) for i in raw_input().split()]
        for a_i in a:
            index, reminder = divmod(a_i, 2)
            if reminder == n % 2 or index >= len(count):
                result = 0
                break
            else:
                count[index] += 1

        if result < 0:
            if n % 2 != 0:
                if count[0] != 1:
                    result = 0
                else:
                    for c in count[1:]:
                        if c != 2:
                            result = 0
                            break
                    if result != 0:
                        result = 2 ** (len(count) - 1)
            else:
                for c in count:
                    if c != 2:
                        result = 0
                        break
                if result != 0:
                    result = 2 ** len(count)
        print result % ((10 ** 9) + 7)

        n = sys.stdin.readline().rstrip()

if __name__ == "__main__":
    main(sys.argv)

Submission status: Accepted

Solution code:
import collections

num = int(input().rstrip())
line = input().rstrip().split()
line = [int(x) for x in line]

count_dict = collections.Counter(line)

last = 10**9 + 7

num_list = []

ans = 1

if num % 2 == 0:
    for k, v in count_dict.items():
        if v != 2:
            ans = 0

else:
    for k, v in count_dict.items():
        if v != 2 and k != 0:
            ans = 0

if ans == 0:
    print(0)
else:
    print(2**(num // 2) % last)

Submission status: Accepted

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:
    if i not in dic:
        print(0)
        sys.exit()

    dic[i] -= 1

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

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

Submission status: Accepted

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(0)
    else:
        for i in range(2, n, 2):
            if b[i] != 2:
                print(0)
                exit(0)
            #print(res)
            res = res * 2 % (10**9 + 7)
else:
    for i in range(1, n, 2):
        if b[i] != 2:
            print(0)
            exit(0)
        res = res * 2 % (10 ** 9 + 7)
print(res)

Submission status: Accepted

Solution code:
def main():
	n = input()
	p = map(int, raw_input().split())
	p.sort()

	lia = []
	lib = []
	if(n % 2 == 0):
		for i in range(0,n,2):
			if(p[i] != p[i+1]):
				print 0
				return
			if(p[i] != i+1):
				print 0
				return
			lia.append(p[i])
			lib.append(p[i+1])
	else:
		for i in range(1, n, 2):
			if(p[i] != p[i+1]):
				print 0
				return
			if(p[i] != i+1):
				print 0
				return
			lia.append(p[i])
			lib.append(p[i+1])

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

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
f=True
if n%2==0:
    for i in range(n):
        if a[i]!=i//2*2+1:
            f=False
            break
else:
    for i in range(n):
        if a[i]!=(i+1)//2*2:
            f=False
            break
print(2**(n//2)%(10**9+7) if f else 0)

Submission status: Accepted

Solution code:

N = int(input())
st = input().split()
d = 10**9 + 7
A = []
m = N%2
fl = {}
exflag = False
for i in range(N):
    a = int(st[i])
    A.append(a)
    if (a + m) % 2 == 0:
        print(0)
        exflag = True
        break
    if a == 0:
        if 0 in fl.keys():
            print(0)
            exflag = True
            break
        fl[0] = 1
    else:
        if a in fl.keys():
            if fl[a] > 1:
                print(0)
                exflag = True
                break
            else:
                fl[a] = 2
        else:
            fl[a] = 1

        
if exflag == False:    
    ret = 2**(N//2) %d
    print(ret)

Submission status: Accepted

Solution code:

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

A_ = sorted(A)

if len(A_) == 1:
    if A_[0] == 0:
        print(1)
    else:
        print(0)

elif A_[0] == A_[1] == 0:
    print(0)

else:
    ans_ = 2 ** (N // 2)
    ans = ans_ % (10**9 + 7)


    if len(A_) % 2 == 0:
        for i in range(len(A_) // 2):
            if A_[2*i] != A_[2*i+1]:
                print(0)
                exit()

    else:
        if A_[0] != 0:
            print(0)
            exit()

        for i in range(len(A_) // 2):
            if A_[2*i+1] != A_[2*i+2]:
                print(0)
                exit()


    print(ans)

Submission status: Accepted

Solution code:
n = input()
a = map(int, raw_input().split())
a.sort()
ok = 0
# print a

if n % 2 == 1:
	for i in range(len(a)):
		if (i % 2 == 0 and a[i] != i) or (i % 2 == 1 and a[i] != i + 1):
			print 0
			ok = 1
			break

if n % 2 == 0:
	for i in range(len(a)):
		if (i % 2 == 1 and a[i] != i) or (i % 2 == 0 and a[i] != i + 1):
			print 0
			ok = 1
			break

if ok == 0:
	# print pow(2, n / 2)
	print pow((2 % 1000000007), ((n / 2) % 1000000006)) % 1000000007

Submission status: Accepted

Solution code:
#coding:utf-8
import math
import string
import time
import fractions


#制約
#1≦N≦105
#0≦Ai≦N−1

#N
#A1 A2 … AN

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

a.sort()
ret = -1
if n % 2 == 0:
	for i in range(n):
		tmp = i
		if i % 2 == 0:
			tmp += 1
		if tmp != a[i]:
			ret = 0
			break
	if ret == -1:
		ret = (2 ** (n / 2)) % (10 ** 9 + 7)
else:
	for i in range(n):
		tmp = i
		if i % 2 == 1:
			tmp += 1
		if tmp != a[i]:
			ret = 0
			break
	if ret == -1:
		ret = (2 ** (n / 2)) % (10 ** 9 + 7)

print ret

Submission status: Accepted

Solution code:
n = int(raw_input())
a = [int(x) for x in raw_input().split()]

c = {}

for v in a:
    if v not in c:
        c[v] = 0
    c[v] += 1

d = {i: 1 if i == 0 else 2 for i in xrange(1 - n % 2, n, 2)}

MOD = 10**9 + 7

if c == d:
    print pow(2, n // 2, MOD)
else:
    print 0

Submission status: Runtime Error

Solution code:
n=int(input())
*A=sorted(map(int,input().split()))

a=True
if n%2==0:
  for i in range(1,n,2):
    if A[i-1]!=i or A[i]!=i:
      a=False
      break
else:
  if A[0]!=0:a=False
  else:
    for i in range(2,n,2):
      if A[i-1]!=i or A[i]!=i:
        a=False
        break
print(2**(n//2)%(10**9+7) if a else 0)

Submission status: Runtime Error

Solution code:
import math
def main():
    n = int(input())
    As = list(map(int, input().split(' ')))
    ind_lis = {}
    idx = n - 1
    while idx >= 0:
        ind_lis[idx] = 0
        idx -= 2
    for a in As:
        ind_lis[a] += 1
        if a == 0 and ind_lis[a] > 1:
            print(0)
            exit()
        elif ind_lis[a] > 2:
            print(0)
            exit()
    print(2**(n//2)%(10**9 + 7))



if __name__ == '__main__':
    main()

Submission status: Runtime Error

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


c = dict(Counter(A))
MOD = 10**9 + 7
if N % 2 == 0:
    is_ok = 1
    cnt = 0
    for num in range(1, N, 2):
        cnt += 1
        if c[num] != 2:
            is_ok=0
            break
    if not is_ok:
        print(0)
        exit()
    print(pow(2, cnt, MOD))
else:
    is_ok = 1
    cnt = 0
    if c[0] != 1:
        is_ok = 0
    for num in range(2, N, 2):
        cnt += 1
        if c[num] != 2:
            is_ok = 0
            break
    if not is_ok:
        print(0)
        exit()
    print(pow(2, cnt, MOD))

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
from collections import defaultdict as dd
Dict = dd(lambda:0)
for a in A:
    Dict[a] += 1
    
if N & 1: Dict[0] += 1
f = (lambda:(lambda x:0 if x&1 else 2) if N&1 else (lambda x:2 if x&1 else 0))()
Possible = {i:f(i) for i in range(N)}
for key,value in Dict.items:
    if value != Possible[key]:
        print(0)
        exit()
else:
    print(2**(N//2)%1000000007)

Submission status: Runtime Error

Solution code:
n = int(input())
# n, m = list(map(int, input().split()))
# Ch, Cw = list(map(int, input().split()))
# Dh, Dw = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(4)]
# n = int(input())
a = list(map(int, input().split()))
# r = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
# data = [list(map(int, input().split())) for i in range(n)]
a.sort()
if n == 1:
    if a[0] == 0:
        print(1)
    else:
        print(0)

if n % 2 == 1:
    if a[0] == 0 and a[1] == 0:
        print(0)
        exit()
    ans = 1
    for i in range(1, n, 2):
        if not(a[i] == a[i+1] and a[i] == i+1):
            print(0)
            exit()
        else:
            ans *= 2
    print(ans)
else:
    ans = 1
    for i in range(0, n, 2):
        if not(a[i] == a[i+1] and a[i] == i+1):
            print(0)
            exit()
        else:
            ans *= 2
    print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
if a[0] == 0 and a[1] == 0:
    print(0)
    exit()
count = 1
ans = 1
for i in range(n-1):
    if a[i] == a[i+1]:
        count += 1
    else:
        ans *= count
        count = 1

    if count > 3:
        print(0)
        exit()
ans *= count
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
mod=10**9+7
if n%2==0:
    d={i:2 for i in range(1,n,2)}
else:
    d={i:2 for i in range(0,n,2)}
    d[0]=1
print('def:',d)
for a in l:
    if a in d:
        d[a]-=1
    else:
        print(0)
        exit()
    print(a,d)
for i in d.values():
    if i!=0:
        print(0)
        exit()
print((2**(n//2))%mod)

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
mod=10**9+7
if n%2==0:
    d={i:2 for i in range(1,n,2)}
else:
    d={i:2 for i in range(0,n,2)}
    d[0]=1
print('def:',d)
for a in l:
    if a in d:
        d[a]-=1
    else:
        print(0)
        exit()
    print(a,d)
for i in d.values():
    if i!=0:
        print(0)
        exit()
print(2**(n//2)%mod)

Submission status: Runtime Error

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

if n%2 == 0:
  for i in range(0,n-2,2):
    if a[i] != a[i+1] or a[i] == a[i+2]:
      print(0)
      exit()
  if a[-2] != a[-1]:
    print(0)
    exit()
else:
  if a[0] != 0 or a[1] == 0:
    print(0)
    exit()
  for i in range(1,n-2,2):
    if a[i] != a[i+1] or a[i] == a[i+2]:
      print(0)
      exit()
  if a[-2] != a[-1]:
    print(0)
    exit()

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

Submission status: Runtime Error

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

check=[0]*N

for idx in range(N%2,N,2):
    check[idx]=idx+1
    check[idx+1]=idx+1

ans=0

if check == A:
    if N % 2 == 0:
        ans=(2**(N//2))%(10**9+7)
    elif N % 2 != 0:
        ans=(2**((N-1)//2))%(10**9+7)
    
print(ans)

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
p=10**9+7

def main(n,a):
  h=n//2
  g=n%2
  a.sort()
  c=[2*(x//2)+g+1 for x in range(n-g)]
  if g==1:
    c.insert(0,0)
  if a!=c:
      return 0
  return 2**(h%(p-1))

if __name__='__main__':
  n=int(input())
  a=list(map(int,sys.stdin.readline().strip().split()))
  print(main(n,a))

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
p=10**9+7

def main(n,a):
  h=n//2
  g=n%2
  if g==1:
    if a.count(0)!=1:
      del a[a.index(0)]
  b=[0]*(n-g)
  d=deque(a)
  while d:
    x=d.pop()
    b[x-1-g]=x
    b[x-g]=x
  c=[2*(x//2)+g+1 for x in range(n-g)]
  if g==1:
    c.insert(0,0)
  if b!=c:
      return 0
  return 2**(h%(p-1))
n=int(input())
a=list(map(int,sys.stdin.readline().strip().split()))

print(main(n,a))

Submission status: Runtime Error

Solution code:
import sys
p=10**9+7

def main(n,a):
  h=n//2
  g=n%2
  tp=2**h
  if g==1:
    if a.count(0)!=1:
      return 0
    else:
      del a[a.index(0)]
  c=sum([2**((x-1)//2) % tp for x in a])
  if c ^ 2*(tp-1):
      return 0
  return 2**(h%(p-1))
n=int(input())
a=list(map(int,sys.stdin.readline().strip().split()))

print(main(n,a))

Submission status: Runtime Error

Solution code:
import math

N = 5
ARR = [2, 4, 4, 0, 2]

N = 7
ARR = [6, 4, 0, 2, 4, 0, 2]

N = 8
ARR = [7, 5, 1, 1, 7, 3, 5, 3]

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


def calculate(n, arr):
    if n % 2 == 0:
        n = n // 2
        start = 1
        finalResult = pow(2, n, 1000000000 + 7)
    else:
        n = n // 2 + 1
        start = 0
        finalResult = pow(2, (n - 1), 1000000000 + 7)

    result = {}
    for i in range(n):
        index = start + 2 * i
        if index == 0:
            result.__setitem__(0, 1)
        else:
            result.__setitem__(index, 2)

    isOk = True
    for i in range(len(arr)):
        aa = result.get(arr[i])
        aa = aa - 1
        if aa < 0:
            isOk = False
            break
        result.__setitem__(arr[i], aa)

    if sum(result.values()) != 0:
        isOk = False

    if isOk:
        print(finalResult)
    else:
        print(0)


calculate(N, ARR)

Submission status: Runtime Error

Solution code:
N = 5
ARR = [2, 4, 4, 0, 2]

N = 7
ARR = [6, 4, 0, 2, 4, 0, 2]

N = 8
ARR = [7, 5, 1, 1, 7, 3, 5, 3]

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

def calculate(n, arr):
    if n % 2 == 0:
        n = n // 2
        start = 1
        finalResult = 2 ** n
    else:
        n = n // 2 + 1
        start = 0
        finalResult = 2 ** (n - 1)

    result = {}
    for i in range(n):
        index = start + 2 * i
        if index == 0:
            result.__setitem__(0, 1)
        else:
            result.__setitem__(index, 2)

    isOk = True
    for i in range(len(arr)):
        aa = result.get(arr[i])
        aa = aa - 1
        if aa < 0:
            isOk = False
            break
        result.__setitem__(arr[i], aa)


    if sum(result.values()) != 0:
        isOk = False

    if isOk:
        print(finalResult)
    else:
        print(0)

calculate(N, ARR)

Submission status: Runtime Error

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

ans = 0
A_test = sorted(list(set(A)))

if N % 2 == 1:
    judge = [i for i in range(0,N,2)]
    if A_test == judge:
        ans = 2**(N//2)
else:
    judge = [i for i in range(1,N,2)]
    if A_test == judge:
        ans = 2**(N//2)]

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

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n = I()
	a_list = LI()
	a_dict = list(Counter(a_list).items())
	a_dict.sort()
	if n % 2 == 0:
		for i in range(len(a_dict)):
			diff, number = a_dict[i]
			if diff % 2 == 0:
				ans = 0
				break
			if diff != 2*i+1 or number != 2:
				ans = 0
				break
		else:
			ans = 2**(n/2)%MOD
	else:
		for i in range(len(a_dict)):
			diff, number = a_dict[i]
			if diff % 2 == 1 or (diff == 0 and number !=1):
				ans = 0
				break
			if diff != 2*i or (diff > 0 and number != 2):
				ans = 0
				break
		else:
			ans = 2**((n-1)/2)%MOD
	print(int(ans))


	


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
if len(a)%2==1:
    tmp = [0]
    for i in range((len(a)-1)//2):
        tmp.append((i+1)*2)
        tmp.append((i+1)*2)
    if a == tmp:
        ans = (2**((len(a)-1)//2))%(10**9+7)
    else:
        ans = 0
else:
    tmp = []
    for i in range(len(a)//2):
        tmp.append(2*i+1)
        tmp.append(2*i+1)
    if a == tmp:
        ans = (2**(len(a)//2))%(10**9+7)
    else:
        ans = 0
print(ans)

Submission status: Runtime Error

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    counter = collections.Counter(A)
    keys = [False]*(N+1)
    keys[(N - 1) % 2] = True
    for n in range(1, N//2+1):
        keys[((N - 1) % 2)+2*n] = True
    if N % 2 != 0 and counter[0] != 1:
        print(0)
        exit()

    cnt = 0
    for k, v in counter.items():
        if k == 0: continue
        if not keys[k] or v != 2:
            print(0)
            exit()
        cnt += 1

    print((N // 2) * cnt)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    counter = collections.Counter(A)
    keys = [False]*N
    keys[(N - 1) % 2] = True
    for n in range(1, N//2+1):
        keys[((N - 1) % 2)+2*n] = True
    if N % 2 != 0 and counter[0] != 1:
        print(0)
        exit()

    cnt = 0
    for k, v in counter.items():
        if k == 0: continue
        if not keys[k] or v != 2:
            print(0)
            exit()
        cnt += 1

    print((N // 2) * cnt)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
import math
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(): return list(imap())
def farr(): return list(fmap())
def sarr(): return sinput().split()

n = int(input())
A = iarr()
s = set(A)
if sum(A)==2*sum(s): print(pow(2, l//2, int(1e9+7)))
else: print(0)

Submission status: Runtime Error

Solution code:
n, *A = map(int, open(0).read().split())
if n % 2:
    d = {i:2 for i in range(0, n, 2)}
    d[0] -= 1
else:
    d = {i:2 for i in range(1, n, 2)}
for a in A:
    d[a] -= 1

if any(d.values()):
    print(0)
else:
    print(pow(2, n//2, 10**9 + 7))

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
b = [0]*(n//2)
c = [0]
d = [0]*(n//2)
e = []
lot = 10**9 + 7
ans = 2**(n//2)%lot
for i in range(n):
    b[i] = n-(2*i+1)
    if b[i] == 1 or b[i] == 2:
        break
for i in range(n):
    d[i] = n-(2*i+1)
    if d[i] == 1 or b[i] == 2:
        break
if n%2 == 0:
    e = b + d
else:
    e = b + c + d

count1 = collections.Counter(a)
count2 = collections.Counter(e)

if count1 == count2:
    print(ans)
else:
    print(0)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
b = [0]*(n//2)
c = [0]
d = [0]*(n//2)
e = []
for i in range(n):
    b[i] = n-(2*i+1)
    if b[i] == 1 or b[i] == 2:
        break
for i in range(n):
    d[i] = n-(2*i+1)
    if d[i] == 1 or b[i] == 2:
        break
if n%2 == 0:
    e = b + d
else:
    e = b + c + d

count1 = collections.Counter(a)
count2 = collections.Counter(e)

if count1 == count2:
    print(2**(n//2))
else:
    print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
MOD = 10**9+7
a = list(map(int,input().split()))
a.sort()
if n % 2 == 0:
    if a[0] != 1 or a[1] != 1 or a[2] == 1:
        print(0)
        exit()
    j = 3
    for i in range(2,n,2):
        if a[i] != j:
            print(0)
            exit()
        j += 2
    j = 3
    for i in range(3,n,2):
        if a[i] != j:
            print(0)
            exit()
        j+=2
if n % 2 != 0:
    if a[0] != 0 or a[1] == 0:
        print(0)
        exit()
    j = 2
    for i in range(1,n,2):
        if a[i] != j:
            print(0)
            exit()
        j += 2
    j = 2
    for i in range(2,n,2):
        if a[i] != j:
            print(0)
            exit()
        j+=2
print(pow(2,(n//2),MOD))

Submission status: Runtime Error

Solution code:
from collections import Counter
import numpy as np

MOD = 10 ** 9 + 7

n = int(input())
a = list(map(int, input().split()))
count = Counter(a)
# 0の個数は、count[0]
num = len(a)
ans = 1


if (num % 2 == 0):
    # 偶数パターン
    temp = 1
    loop = int(num / 2)
    for i in range(loop):
        tar = count[temp]
        if (tar == 2):
            ans *= 2
            temp += 2
        else:
            print(0)
            exit()

else:

    tar0 = count[0]
    if (tar0 == 1):
        pass
    else:
        print(0)
        exit()

    temp = 2

    for i in range(num // 2):
        if (count[temp] == 2):
            ans *= 2
            temp += 2
        else:
            print(0)
            exit()

ans % = MOD
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int,input().split()))
ok = True
if n%2==1:
    a=sorted(A)
    for i in range(len(a)):
        if i%2==0:
            if a[i]!=i:
                ok = False
        else:
            if a[i]!=i+1:
                ok = False
else:
    a=sorted(A)
    for i in range(len(a)):
        if i%2==1:
            if a[i]!=i:
                ok = False
        else:
            if a[i]!=i+1:
                ok = False
if ok:
    print(2**(n//2))%1000000007
else:
    print(0)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=int(input())
alls=sum(a)
for _ in range(m):
    p,x=map(int,input().split())
    print(alls + x - a[p-1])

Submission status: Runtime Error

Solution code:
def main():
    from collections import Counter
    n, *a = map(int, open(0).read().split())
    c = Counter(a)
    f = True
    if n % 2 == 0:
        f = all(x == 2 for x in c.values())
    else:
        g = c.pop("0") == 1
        f = all(x == 2 for x in c.values()) and g
    ans = 2 ** (n // 2) % 1000000007 if f is True else 0
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    import collections
    n, *a = map(int, open(0).read().split())
    c = collections.Counter(a)
    if n % 2 == 0:
        f = all(x == 2 for x in c.values())
    else:
        g = c.pop("0") == 1
        f = all(x == 2 for x in c.values()) and g
    ans = 2 ** (n // 2) % 1000000007 if f is True else 0
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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