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 = list(map(int, input().split(' ')))

false_flag = 0
'''
if N % 2 == 0:
    count_ = 1
else:
    if A.count(0) != 1:
        false_flag = 1
    count_ = 2
while count_ < N and false_flag == 0:
    if A.count(count_) != 2:
        false_flag = 1
    count_ += 2
'''

count_list = [0 for i in range(N)]
for index in A:
    count_list[index] += 1

if N % 2 == 0:
    count_ = 1
    diff = -1
else:
    if count_list[0] != 1 or count_list[1] != 0:
        false_flag = 1
    count_ = 2
    diff = 1
while count_ < N and false_flag == 0:
    if count_list[count_] != 2 or count_list[count_ + diff] != 0:
        false_flag = 1
    count_ += 2

if false_flag == 0:
    print(2 ** (N // 2))
else:
    print(0)

Submission status: Runtime Error

Solution code:
n=int(input())
A=list(map(int,input().split()))
  
cnt=[0]*n
for a in A:
  cnt[a]+=1
for i in range(len(cnt)):
  if i==0 and cnt[i]>1:
    print(0)
    exit()
  elif cnt[i]>3:
    print(0)
    exit()
print(int((2**(n/2))%(10**9+7)))

Submission status: Runtime Error

Solution code:
def index(n:int, a: int):
    if a % 2 == 0:
        i = n // 2 - a // 2
        j = (i + 1) * -1
        return (i, j) if i != n // 2 else (i,)
    else:
        i = (n // 2 - 1) - (a - 1) // 2
        j = (i + 1) * -1
        return (i, j)
 
n = int(input())
line = [0 for _ in range(n)]
for a in map(int, input().split()):
    for i in index(n, a):
        line[i] += 1
else:
    if n % 2 == 0 and set(line) == {2}:
        print(2 ** (n // 2) % (10 ** 9 + 7))
    elif n % 2 == 1 and set(line) == {1, 2} and line[n//2] == 1:
        print(2 ** ((n - 1) // 2) % (10 ** 9 + 7))
    else:
        print(0)
def index(n:int, a: int):
    if a % 2 == 0:
        i = n // 2 - a // 2
        j = (i + 1) * -1
        return (i, j) if i != n // 2 else (i,)
    else:
        i = (n // 2 - 1) - (a - 1) // 2
        j = (i + 1) * -1
        return (i, j)

n = int(input())
line = [0 for _ in range(n)]
for a in map(int, input().split()):
    for i in index(n, a):
        line[i] += 1
else:
    if n % 2 == 0 and set(line) == {2}:
        print(2 ** (n // 2) % (10 ** 9 + 7))
    elif n % 2 == 1 and set(line) == {1, 2} and line[n//2] == 1:
        print(2 ** ((n - 1) // 2) % (10 ** 9 + 7))
    elif n == 1 and line == [1]:
        print(1)
    else:
        print(0)

Submission status: Runtime Error

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
if N % 2 == 0:
    for i in range(1, N//2+1):
        if A[(i-1)*2] == A[1+(i-1)*2] == 2*i-1:
            continue
        else:
            print(0)
            exit()
    print(2**(N//2))
else:
    if A[0] == 0 and A[1] != 0:
        for i in range(1, N//2+1):
            if A[2*i-1] == A[2*i] == 2*i:
                continue
            else:
                print(0)
                exit()
        print(2**(N//2))
    else:
        print(0)
        exit()

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
N=int(input())
A=list(map(int,input().split()))
A.sort()
Devide_N=10**9+7
Rem_2_32_DN=(2**32)%Devide_N

if N%2==1:
  if A[0]!=0 or A[1]==0:
    print(0)

  else:
    del A[0]
    for ch_n in range(1,(N-1)//2+1):
      if A[0]!=ch_n*2 or A[1]!=ch_n*2:
        break
      else:
        del A[0:2]
    else:
      #exp=(N-1)//2
      
      #exp_quotient_32=exp//32
      #exp_rem_32=exp%32
      #Rem_ans_Devide_N=1
      #for _ in range(exp_quotient_32):
      #  Rem_ans_Devide_N=(Rem_ans_Devide_N*Rem_2_32_DN)%Devide_N
        
      #print((Rem_ans_Devide_N*2**(exp_rem_32))%Devide_N)
      sys.exit()
    print(0)

else:
  for ch_n in range(1,N//2+1):
    if A[0]!=ch_n*2-1 or A[1]!=ch_n*2-1:
      break
    else:
      del A[0:2]
  else:
    #exp=N//2
    
    #exp_quotient_32=exp//32
    #exp_rem_32=exp%32
    #Rem_ans_Devide_N=1
    #for _ in range(exp_quotient_32):
    #  Rem_ans_Devide_N=(Rem_ans_Devide_N*Rem_2_32_DN)%Devide_N
      
    #print((Rem_ans_Devide_N*2**(exp_rem_32))%Devide_N)
    sys.exit()
  print(0)

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
N=int(input())
A=list(map(int,input().split()))
A.sort()
Devide_N=10**9+7
Rem_2_32_DN=(2**32)%Devide_N

if N%2==1:
  if A[0]!=0 or A[1]==0:
    print(0)

  else:
    del A[0]
    for ch_n in range(1,(N-1)//2+1):
      if A[0]!=ch_n*2 or A[1]!=ch_n*2:
        break
      else:
        del A[0:2]
    else:
      exp=(N-1)//2
      
      exp_quotient_32=exp//32
      exp_rem_32=exp%32
      Rem_ans_Devide_N=1
      for _ in range(exp_quotient_32):
        Rem_ans_Devide_N=(Rem_ans_Devide_N*Rem_2_32_DN)%Devide_N
        
      print((Rem_ans_Devide_N*2**(exp_rem_32))%Devide_N)
      sys.exit()
    print(0)
else:
  for ch_n in range(1,N//2+1):
    if A[0]!=ch_n*2-1 or A[1]!=ch_n*2-1:
      break
    else:
      del A[0:2]
  else:
    exp=N//2
    
    exp_quotient_32=exp//32
    exp_rem_32=exp%32
    Rem_ans_Devide_N=1
    for _ in range(exp_quotient_32):
      Rem_ans_Devide_N=(Rem_ans_Devide_N*Rem_2_32_DN)%Devide_N
      
    print((Rem_ans_Devide_N*2**(exp_rem_32))%Devide_N)
    sys.exit()
  print(0)

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
N=int(input())
A=list(map(int,input().split()))

Devide_N=10**9+7
Rem_2_32_DN=(2**32)%Devide_N

if N%2==1:
  if A.count(0)!=1:
    print(0)
  else:
    for ch_n in range(1,(N-1)//2+1):
      if A.count(ch_n*2)!=2:
        break
      else:
        A.remove(ch_n*2)
        A.remove(ch_n*2)
    else:
      #exp=(N-1)//2
      
      #exp_quotient_32=exp//32
      #exp_rem_32=exp%32
      #Rem_ans_Devide_N=1
      #for _ in range(exp_quotient_32):
      #  Rem_ans_Devide_N=(Rem_ans_Devide_N*Rem_2_32_DN)%Devide_N
        
      #print((Rem_ans_Devide_N*2**(exp_rem_32))%Devide_N)
      sys.exit()
    print(0)
else:
  for ch_n in range(1,N//2+1):
    if A.count(ch_n*2-1)!=2:
      break
    else:
      A.remove(ch_n*2-1)
      A.remove(ch_n*2-1)
  else:
    #exp=N//2
    
    #exp_quotient_32=exp//32
    #exp_rem_32=exp%32
    #Rem_ans_Devide_N=1
    #for _ in range(exp_quotient_32):
    #  Rem_ans_Devide_N=(Rem_ans_Devide_N*Rem_2_32_DN)%Devide_N
      
    #print((Rem_ans_Devide_N*2**(exp_rem_32))%Devide_N)
    #sys.exit()
  print(0)

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
A = list(map(int,input().split(' ')))
C = collections.Counter(A)
L = C.most_common()

if N % 2 == 0:
  for i, j in L:
    if j == 2:
      pass
    else:
      print(0)
      exit()
else:
   for i, j in L:
    if j == 2:
      pass
    else:
      if i == 0:
        pass
      else:
        print(0)
        exit()
print(int(2**(N//2 / (10**9+7)))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    base = []
    base_flg = []
    
    if N % 2 == 1:
        for i in range(0,N,2):
            base.append(i)
            base_flg.append(False)
    else:
        for i in range(1,N,2):
            base.append(i)
            base_flg.append(False)
            
    dic = {}
    for i in A:
        if i in dic:
            dic[i] += 1
        else:
            dic[i] = 1
            
    for k, v in dic.items():
        if k in base:
            if v == 2 ans k != 0:
                ind = base.index(k)
                if base_flg[ind] == False:
                    base_flg[ind] = True
                else:
                    print(0)
                    sys.exit()
            else:
                if k == 0 and v == 1:
                    ind = base.index(k)
                    if base_flg[ind] == False:
                        base_flg[ind] = True
                    else:
                        print(0)
                        sys.exit()
                else:
                    print(0)
                    sys.exit()
        else:
            print(0)
            sys.exit()
            
    for i in base_flg:
        if i == False:
            print(0)
            sys.exit()
            
    tmp = N // 2    
    print(2**tmp)
    
if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    base = []
    '''
    if N % 2 == 1:
        for i in range(0,N,2):
            base.append(i)
    else:
        for i in range(1,N,2):
            base.append(i)
            '''
            
    dic = {}
    for i in A:
        if i in dic:
            dic[i] += 1
        else:
            dic[i] = 1
            
    for k, v in dic.items():
        if v == 2 and K != 0:
            pass
        elif v == 1:
            if k == 0 and N % 2 == 1:
                pass
            else:
                print(0)
                sys.exit()
        else:
            print(0)
            sys.exit()
            
    tmp = 0
    if N % 2 == 1:
        tmp = N // 2
    else:
        tmp = N // 2
        
    print(2**tmp)
    
if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
a = list(map(int,input().split()))
MOD = 10 ** 9 + 7
ans = 1

l = collections.Counter(a)

if (len(l) % 2 == 1 and l[0] > 1) or (len % 2 == 0 and l[0] > 0):
    ans = 0
else:
    for vals in l.values():
        ans *= vals
    
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
sum = 0
ans = 0
zeroflg = 0

for i in range(len(A)-2):
    if N%2 == 0 and A[0] == 1 and A[N-1] == N-1:
        if N == 2:
            if A[0] == A[1]:
                sum = 2**(N/2)
            else:
                zeroflg = 1
        elif N > 2:
            if A[0] == A[1]:
                if  i%2 == 0 and A[i + 2] - A[i] == 2 and A[i + 1] - A[i] == 0:
                    sum = 2**(N/2)
                elif i%2 == 1 and A[i + 2] - A[i] == 2 and A[i + 1] - A[i] == 2:
                    sum = 2**(N/2)
                else:
                    zeroflg = 1
            else:
                zeroflg = 1
    elif N%2 == 1 and A[0] == 0 and A[N-1] == N-1:
        if N == 1:
            sum = 2**(N//2)
        elif N > 1: 
            if i%2 == 0 and A[i + 2] - A[i] == 2 and A[i + 1] - A[i] == 2:
                sum = 2**(N//2)
            elif i%2 == 1 and A[i + 2] - A[i] == 2 and A[i + 1] - A[i] == 0:
                sum = 2**(N//2)
            else:
                zeroflg = 1

if zeroflg == 1:
    print(ans)
else:
    ans = int(sum)
    ans%(10**9+7)
    print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
A.sort()
B = []

if len(A) % 2 == 0:
    ans = 2 ** (len(A)/2)
    for i in range(len(A)//2):
        B.append(2 * i + 1)
        B.append(2 * i + 1)

else:
    ans = 2 ** (len(A)//2)
    B.append(0)
    for i in range(len(A)//2):
        B.append(2 * i + 2)
        B.append(2 * i + 2)

if A == B:
    print(int(ans/MOD))
else:
    print(0)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
A.sort()
B = []

if len(A) % 2 == 0:
    ans = 2 ** (len(A)/2)
    for i in range(len(A)//2):
        B.append(2 * i + 1)
        B.append(2 * i + 1)

else:
    ans = 2 ** (len(A)//2)
    B.append(0)
    for i in range(len(A)//2):
        B.append(2 * i + 2)
        B.append(2 * i + 2)

if A == B:
    print(int(ans))
else:
    print(0)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
lst = [int(i) for i in input().split()]
mod = 10**9 + 7
lst_c = Counter(lst)
lst_c = sorted(lst_c.items(),key = lambda x:x[0])

ideal = []

if n%2!=0:
    ideal.append((0,1))
    for i in range(1,n//2+1):
        ideal.append((2*i,2))
else:
    for i in range(n//2):
        ideal.append((2*i+1,2))

if lst_c != ideal:
    print(0)
else:
    l = len(ideal)
    if n%2!=0:
        l -= 1
    print(2**l　% mod)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
half = math.floor(N/2)
ans = 2**(half)
if N%2 == 1 and A[-1] !=0:
  ans = 0
for i in range(half):
  if A[2*i] == N-2*i-1 and A[2*i+1] == N-2*i-1:
    continue
  else:
    ans = 0
    break
print(ans/(10**9+7))

Submission status: Runtime Error

Solution code:
N = int(input())
nums = list(map(int, input().split()))
n_dict = {}
idx = 0
mod = !(N%2)
while True:
  if 2*idx + mod > N:
    break
  else:
    n_dict[2*idx+mod] = 0
for num in nums:
  if num in n_dict:
    n_dict[num] += 1
  else:
    print(0)
    exit()
for key, value in n_dict.items():
  if value != 2:
    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()
if n%2 == 1:
  if a[0]!=0:
    print(0)
    exit()
  for i,j,k in zip(a[1::2],a[2::2],range(,n,2)):
    if not i==j==k:
      print(0)
      exit()
  print(2**(n//2))
  exit()
for i,j,k in zip(a[::2],a[1::2],range(,n,2)):
  if not i==j==k:
    print(0)
    exit()
print(2**(n//2))

Submission status: Runtime Error

Solution code:
#データを並び替える
rowdata=[int(i) for i in input().split()]
rowdata.sort()

#nが偶数の時
if n%2==0:
    check=[]
    a=1
    for i in range(1,n,2):
        check.append(i)
        check.append(i)
    if check==rowdata:
        for i in range(int(n/2)):
            a*=2
            a=a%1000000007
        print(a)
    else:
        print(0)
        
#nが奇数の時
else:
    check=[]
    a=1
    if n==1:
        check=[0]
    else:
        for i in range(0,n,2):
            if i==0:
                check.append(i)
            else:
                check.append(i)
                check.append(i)
    if check==rowdata:
        print(int(2**((n-1)/2))%1000000007)
        for i in range(int((n-1)/2)):
            a*=2
            a=a%1000000007
        print(a)
    else:
        print(0)

Submission status: Runtime Error

Solution code:
n=int(input())

#データを並び替える
rowdata=[int(i) for i in input().split()]
rowdata.sort()

#nが偶数の時
if n%2==0:
    check=[]
    a=1
    for i in range(1,n,2):
        check.append(i)
        check.append(i)
    if check==rowdata:
        for i in range(int(n/2)):
            a*=2
            a=a%1000000007
            print(a)
    else:
        print(0)
        
#nが奇数の時
else:
    check=[]
    a=1
    if n==1:
        check=[0]
    else:
        for i in range(0,n,2):
            if i==0:
                check.append(i)
            else:
                check.append(i)
                check.append(i)
    if check==rowdata:
        print(int(2**((n-1)/2))%1000000007)
        for i in range(int((n-1)/2)):
            a*=2
            a=a%1000000007
            print(a)
    else:
        print(0)

Submission status: Runtime Error

Solution code:
n=int(input())

#データを並び替える
rowdata=[int(i) for i in input().split()]
rowdata.sort()

#nが偶数の時
if n%2==0:
    check=[]
    for i in range(1,n,2):
        check.append(i)
        check.append(i)
    if check==rowdata:
        print(int(2**(n/2))%1000000007)
    else:
        print(0)
        
#nが奇数の時
else:
    check=[]
    if n==1:
        check=[0]
    else:
        for i in range(0,n,2):
            if i==0:
                check.append(i)
            else:
                check.append(i)
                check.append(i)
    if check==rowdata:
        print(int(2**((n-1)/2))%1000000007)
    else:
        print(0)

Submission status: Runtime Error

Solution code:

n=int(input())
rowdata=[int(i) for i in input().split()]
rowdata.sort()

if n%2==0:
    check=[]
    for i in range(1,n,2):
        check.append(i)
        check.append(i)
    if check==rowdata:
        print(int(2**(n/2)))
    else:
        print(0)
else:
    check=[]
    if n==1:
        check=[0]
    else:
        for i in range(0,n,2):
            if i==0:
                check.append(i)
            else:
                check.append(i)
                check.append(i)
    if check==rowdata:
        print(int(2**((n-1)/2)))
    else:
        print(0)

Submission status: Runtime Error

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

#nが偶数の時
if n%2==0:
    check=[]
    for i in range(1,n,2):
        check.append(i)
        check.append(i)
    if check==rowdata:
        print(int(2**(n/2)))
    else:
        print(0)
else:
    check=[]
    if n==1:
        check=[0]
    else:
        for i in range(0,n,2):
            if i==0:
                check.append(i)
            else:
                check.append(i)
                check.append(i)
    if check==rowdata:
        print(int(2**((n-1)/2)))
    else:
        print(0)

Submission status: Runtime Error

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

#nが偶数の時
if n%2==0:
    check=[]
    for i in range(1,n,2):
        check.append(i)
        check.append(i)
    if check==rowdata:
        print(int(2**(n/2)))
    else:
        print(0)
else:
    check=[]
    for i in range(0,n,2):
        if i==0:
            check.append(i)
        else:
            check.append(i)
            check.append(i)
    if check==rowdata:
        print(int(2**((n-1)/2)))
    else:
        print(0)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7
import collections
import numpy as np
import sys
count = collections.Counter(A)
loops = np.arange(N-1,-1,-2)

for li in list(loops):
    if li == 0 :
        if count[li] != 1:break
    else:
        if count[li] != 2:break

else:
    b = N//2
    ans = 1
    for i in range(1,b+1):
        ans *= 2
        ans %= mod
    print(ans)   
    sys.exit(1)

print(0)

Submission status: Runtime Error

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

A.sort()
i = 0
res = 0
if N % 2 == 1:
  res = 1
  i = 1
  if A[0] == A[1]:
    print(0)
    exit(0)
  if A[0] == 1:
    print(0)
    exit(0)
else:
  res = 2
  i = 2
  if A[0] != A[1]:
    print(0)
    exit(0)
  if A[0] == 0:
    print(0)
    exit(0)
while i < N - 1:
  if A[i] == A[i + 1]:
    if N % 2 == 0:
      if A[i] != 2 * (i / 2 + 1) - 1:
        res = 0
        break
    else:
      if A[i] != 2 * (i // 2 + 1):
        res = 0
        break
    res *= 2
    i += 2
  else:
    res = 0
    break
print(res)

Submission status: Runtime Error

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

A.sort()
i = 0
if N % 2 == 1:
  i = 1
  if A[0] == A[1]:
    print(0)
    exit(0)
  if A[0] == 1:
    print(0)
    exit(0)
else:
  i = 2
  if A[0] != A[1]:
    print(0)
    exit(0)
  if A[0] == 0:
    print(0)
    exit(0)
res = 1
while i < N - 1:
  if A[i] == A[i + 1]:
    if N % 2 == 0:
      if A[i] != 2 * (i / 2 + 1) - 1:
        res = 0
        break
    else:
      if A[i] != 2 * (i // 2 + 1):
        res = 0
        break
    res *= 2
    i += 2
  else:
    res = 0
    break
print(res)

Submission status: Runtime Error

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

A.sort()
i = 0
if N % 2 == 1:
  i = 1
  if A[0] == A[1]:
    print(0)
    exit(0)
  if A[0] == 1:
    print(0)
    exit(0)
else:
  i = 2
  if A[0] != A[1]:
    print(0)
    exit(0)
  if A[0] == 0:
    print(0)
    exit(0)
res = 1
while i < N - 1:
  print("a", i)
  if A[i] == A[i + 1]:
    if N % 2 == 0:
      if A[i] != 2 * (i / 2 + 1) - 1:
        res = 0
        break
    else:
      if A[i] != 2 * (i // 2 + 1):
        res = 0
        break
    res *= 2
    i += 2
  else:
    res = 0
    break
print(res)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
#ABC50 C

from collections import Counter
from operator import itemgetter

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

c = Counter(a)
c = list(c.items())
cc = sorted(c,key = itemgetter(1))
ccc = sorted(c,key = itemgetter(0))
if n % 2 == 1:
    if cc[1][1] != 2:
        print(0)
        quit()
    if cc[0][0] != 0:
        print(0)
        quit()
if n % 2 == 0:
    k = 0
    for i,j in ccc:
        if j == 2 and i % 2 == 1 and i == 2*k+1:
            k += 1
            continue
        else:
            print(0)
            quit()
print(2**(n//2))

Submission status: Runtime Error

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

A.sort(reverse = True)
if N % 2 == 1:
  if A.count(A[-1]) == 0:
    print(0)
    exit(0)
else:
  if A.count(A[-1]) == 1:
    print(0)
    exit(0)
res = 1
i = 0
while i <= N - 1:
  if A[i] == A[i + 1]:
    res *= 2
    i += 2
  else:
    res = 0
    break
print(res)

Submission status: Runtime Error

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

l = {}
ll = {}

if n % 2 == 0:
  for i in m:
    l[2*(i//2)+1] = 2
    if i in ll:
      ll[i] += 1
    else:
      ll[i] = 1
else:
  for i in m:
    if 2*(i//2) == 0:
      l[2*(i//2)] = 1
    else:
      l[2*(i//2)] = 2
    if i in ll:
      ll[i] += 1
    else:
      ll[i] = 1

if l != ll:
  print(0)
  exit()

print(1 << (n // 2) / (10**9+7))

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))
mod = 10**9+7
if n % 2 == 0 and len(set(l)) == n/2:
  print(int(2**(n/2)%mod))
elif not n % 2 == 0 and l.count(0) == 1:
  print(int(2**((n-1)/2)%mod))
else:
  print(0)

Submission status: Runtime Error

Solution code:
# そもそも人数分布は一意。
import numpy as np
MOD = 10**9 + 7
N = int(input())
A = np.array([int(x) for x in input().split()])

left = np.arange(N)
right = N-1-left
cnt_1 = np.bincount(np.abs(left-right))
cnt_2 = np.bincount(A)

if (cnt_1 != cnt_2).any():
  answer = 0
else:
  answer = pow(2, N//2, MOD)
  
print(answer)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
if n % 2 == 0:
    a_ = [[a[i],a[i+1]] for i in range(0,n,2)]
    for i,j in enumerate(a_):
        j_ = j[0]
        k_ = j[1]
        if  (i*2+1) != j_ or (i*2+1) != k_:
            print(0)
            break
    else:
        r = (2 ** (n/2))%((10**9)+7)
        print(int(r))
else:
    if a[0] == 0:
        a_ = [[a[i],a[i+1]] for i in range(1,n,2)]
        for i,j in enumerate(a_,start=1):
            j_ = j[0]
            k_ = j[1]
            if i*2 != j_ or i*2 != k_:
                print(0)
                break
        else:
            r = (2**((n-1)/2))%((10**9)+7)
            print(int(r))
    else:
        print(0)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)[::-1]
memo = [0 for i in range(N)]
memo[0] = N-1
memo[1] = N-1
if N % 2 == 0:
    for i in range(2, N):
        memo[i] = memo[i-2]-2
        if memo[i] != A[i]:
            print(0)
            exit()
else:
    for i in range(2, N-1):
        memo[i] = memo[i-2]-2
        if memo[i] != A[i]:
            print(0)
            exit()


# 最初(N//2)**2にしていた、それぞれの場合の数ではなくなってしまう
print((2**(N // 2))%(10**9+7))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)[::-1]
memo = [0 for i in range(N)]
memo[0] = N-1
memo[1] = N-1
if N % 2 == 0:
    for i in range(2, N):
        memo[i] = memo[i-2]-2
        if memo[i] != A[i]:
            print(0)
            exit()
else:
    for i in range(2, N-1):
        memo[i] = memo[i-2]-2
        if memo[i] != A[i]:
            print(0)
            exit()



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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)[::-1]
memo = [0 for i in range(N)]
memo[0] = N-1
memo[1] = N-1
if N % 2 == 0:
    for i in range(2, N):
        memo[i] = memo[i-2]-2
        if memo[i] != A[i]:
            print(0)
            exit()
else:
    for i in range(2, N-1):
        memo[i] = memo[i-2]-2
        if memo[i] != A[i]:
            print(0)
            exit()



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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
# print(A)
if A.count(0) > 1:
    print(0)
    exit()

A = sorted(A)[::-1]
memo = [0 for i in range(N)]
memo[0] = N-1
memo[1] = N-1
if N % 2 == 0:
    for i in range(2, N):
        memo[i] = memo[i-2]-2
        if memo[i] != A[i]:
            print(0)
            exit()
else:
    for i in range(2, N-1):
        memo[i] = memo[i-2]-2
        if memo[i] != A[i]:
            print(0)
            exit()



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

Submission status: Runtime Error

Solution code:
N = int(input())

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10 ** 5 + 1)

def dfs(i, n, a, L):
    # x + y = n - 1
    # x - y = a
    # x = (n - 1 + a) / 2
    # y = (n - 1 - a) / 2
    if i == n:
        return 1
    if a [i] == 0:
        x = [(n - 1 + a[i]) // 2]
    else:
        x = [(n - 1 + a[i]) // 2, (n - 1 - a[i]) // 2]
    t = 0
    MOD = 10 ** 9 + 7
    for xi in x:
        if L[xi] == 0:
            L[xi] = i + 1
            t += dfs(i + 1, n, a, L)
            L[xi] = 0
    return t % MOD

n = int(input())
a = list(map(int, input().split()))
L = [0 for _ in range(n)]
ans = dfs(0, n, a, L)
print(ans)

Submission status: Runtime Error

Solution code:
def dfs(i, n, a, L):
    # x + y = n - 1
    # x - y = a
    # x = (n - 1 + a) / 2
    # y = (n - 1 - a) / 2
    if i == n:
        return 1
    if a [i] == 0:
        x = [(n - 1 + a[i]) // 2]
    else:
        x = [(n - 1 + a[i]) // 2, (n - 1 - a[i]) // 2]
    t = 0
    MOD = 10 ** 9 + 7
    for xi in x:
        if L[xi] == 0:
            L[xi] = i + 1
            t += dfs(i + 1, n, a, L)
            L[xi] = 0
    return t % MOD

n = int(input())
a = list(map(int, input().split()))
L = [0 for _ in range(n)]
ans = dfs(0, n, a, L)
print(ans)

Submission status: Runtime Error

Solution code:
import copy

def dfs(i, n, a, L):
    # x + y = n - 1
    # x - y = a
    # x = (n - 1 + a) / 2
    # y = (n - 1 - a) / 2
    if i == n:
        return 1
    if a [i] == 0:
        x = [(n - 1 + a[i]) // 2]
    else:
        x = [(n - 1 + a[i]) // 2, (n - 1 - a[i]) // 2]
    t = 0
    MOD = 10 ** 9 + 7
    for xi in x:
        if L[xi] == 0:
            Li = copy.copy(L)
            Li[xi] = i + 1
            t += dfs(i + 1, n, a, Li)
    return t % MOD

n = int(input())
a = list(map(int, input().split()))
L = [0 for _ in range(n)]
ans = dfs(0, n, a, L)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(input().split())
count = 0
import collections
c = dict(collections.Counter(A))



if N % 2 == 0:
    for i in c.values():
        if i != 2:
            break
        count = (N / 2)
else:
    if int(c["0"]) != 1:
        pass
    else:
        for i in c.values():
            if i != 2:
                break
            count = (N-1) / 2


if count == 0:
    print(0)
else:
    print(2 ** count % (10 ** 9 + 7))

Submission status: Runtime Error

Solution code:

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

if n%2==0:
    if sorted(a) != [(k//2)*2+1 for k in range(n)]:
        print(0)
    else:
        print(int(2**(n//2) % (10e9+7)))
else:
    if sorted(a)!= [0]+[(k//2+1)*2 for k in range(n-1)]:
        print(0)
    else:
        print(int(2**(n//2) % (10e9+7)))

Submission status: Runtime Error

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

# validation
if A.count(0) > 1:
    print(0)
    exit()

start = 2 if N % 2 == 1 else 1
for n in range(start, N - 1, 2):
    if A.count(n) != 2:
        print(0)
        exit()

if N % 2 != 0:
    N -= 1

ans = 2 << (int(N / 2) - 1)

if ans > 1000000007:
    ans %= 1000000007

print(ans)