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: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
flag = 0
if n % 2 == 1:
  if a.count(0) != 1: flag = 1
  else:
    for i in range(n):
      if a[i] != 0 and a.count(a[i]) != 2:
        flag = 1
else:
  if a.count(0) != 0: flag = 1
  else:
    for i in range(n):
      if a.count(a[i]) != 2:
        flag = 1

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    

    N = int(input().rstrip())
    # A = list(int(_) for _ in input().split())
    A = list(input().split())
    s_num = N -1
    ans = 2**(N//2)
    while s_num > 0:
        count = A.count(str(s_num))
        if(s_num != 0 and count != 2):
            ans = 0 
            break
        elif(s_num == 0 and count !=1):
            ans = 0 
            break
        s_num -= 2
    
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    

    N = int(input().rstrip())
    A = list(int(_) for _ in input().split())
    s_num = N -1
    ans = 2**(N//2)
    while s_num > 0:
        count = A.count(s_num)
        if(s_num != 0 and count != 2):
            ans = 0 
            break
        elif(s_num == 0 and count !=1):
            ans = 0 
            break
        s_num -= 2
    
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(input())
alist = list(map(int,input().split()))
flg = True
if N == 1:
    if alist[0] == 0:
        print(1)
    else:
        print(0)
    sys.exit()
inf = 10 ** 9 + 7
if N % 2 == 0:
    for i in range(N)[1::2]:
        if alist.count(i) != 2:
            flg = False
else:
    for i in range(N)[2::2]:
        if alist.count(i) != 2:
            flg = False
if flg:
    print((2 ** (N // 2)) %  inf)
else:
    print(0)

Submission status: Time Limit Exceeded

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

if N%2:
  A = A+ [0]

# 0,0,2,2,4,4  5   (i//2)*2 + 1- N%2 0,2,4
# 1,1,3,3,5,5  6

if all([A.count(i)==2 for i in range(1-N%2, N, 2)]):
  print(2**(N//2))
else:
  print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input()) 
a = list(map(int,input().split())) 
if n%2==0:
    k = 0
else:
    k = 1
if k==0:
    for i in range(1,n,2):
        if a.count(i)!=2:
            print(0)
    else:
        print((2**(n//2))%(10**9+7))
else:
    if a.count(0)!=1:
        print(0)
    else:
        for i in range(2,n,2):
            if a.count(i)!=2:
                print(0)
        else:
            print((2**(n//2))%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
c = 0
if n % 2 == 0:
    for i in range(1,n+1,2):
        if a.count(i) != 2:
            c = 1
            break
    if c == 0:
        print(int(2 ** (n / 2)))
    else:
        print(0)
else:
    for i in range(0, n + 1, 2):
        if i == 0:
            if a.count(0) != 1:
                c = 1
                break
        elif a.count(i) != 2:
            c = 1
            break
    if c == 0:
        print(int(2 ** ((n - 1) / 2)))
    else:
        print(0)

Submission status: Time Limit Exceeded

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

    if N%2==1:
        for i in range(0,N,2):
            if i == 0 :
                if A.count(i) != 1:
                    print(0)
                    return
            elif A.count(i)!=2:
                print(0)
                return
        ans = (2**((N-1)//2))%(10**9 + 7)
    else:
        for i in range(1,N,2):
            if A.count(i)!=2:
                print(0)
                return
        ans = (2**(N//2))%(10**9 + 7)
    
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

    if N%2==1:
        for i in range(0,N,2):
            if i == 0 :
                if A.count(i) != 1:
                    print(0)
                    return
            elif A.count(i)!=2:
                print(0)
                return
        ans = 2**((N-1)//2)
    else:
        for i in range(1,N,2):
            if A.count(i)!=2:
                print(0)
                return
        ans = 2**(N//2)
    
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
flag = True

if n % 2 == 1:
    if 0 not in A:
        flag = False
    for i in range(n//2):
        if A.count(2*(i+1)) != 2:
            flag = False
else:
    for i in range(n//2):
        if A.count(2*i + 1) != 2:
            flag = False

if flag == True:
    ans = 2**(n//2) % (10**9 + 7)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
t = [a.count(i) for i in range(n)]
for i in range(n//2):
  if t[i*2+n%2] != 0 or t[i*2+1+n%2] != 2 or t[0] > 1:
    print(0)
    exit()
print(2**(n//2))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
if n%2==0:
    ans=0
    for i in range(n//2):
        if a.count(2*i+1)!=2:
            ans=1
            break
    if ans==1:print(0)
    elif ans==0:
        res=1
        for j in range(n//2):
            res=(res*2)%(10**9+7)
        print(res)
elif n%2==1:
    ans=0
    if a.count(0)!=1:ans=1
    for i in range(n//2):
        if ans==1:break
        if a.count(2*i+2)!=2:ans=1
    if ans==1:print(0)
    elif ans==0:
        res=1
        for j in range(n//2):
            res=(res*2)%(10**9+7)
        print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(set(A))
if N % 2 == 0 :
    for b in B :
        if b % 2 != 1 :
            ans = 0
            break
        elif A.count(b) != 2 :
            ans = 0
            break
    else :
        ans = 2**len(B)
else :
    for b in B :
        if b == 0 :
            if A.count(b) != 1 :
                ans = 0
                break
        elif b % 2 != 0 :
            ans = 0
            break
        elif A.count(b) != 2 :
            ans = 0
            break
    else :
        ans = 2**(len(B)-1)

print(ans)

Submission status: Time Limit Exceeded

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

if N % 2 == 1:
    if A.count(0) != 1:
        print(0)
        exit()
else:
    if A.count(0) != 0:
        print(0)
        exit()

m = set(A)
for n in m:
    if n == 0:
        continue
    if A.count(n) != 2:
        print(0)
        exit()


ans = 0
if 0 in A:
    ans = 2**((N-1)/2) % (10**9+7)
else:
    ans = 2**(N/2) % (10**9+7)
print(int(ans))

Submission status: Time Limit Exceeded

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

dic = {}

for a in A:
    if a in dic.keys():
        dic[a] += 1
    else: dic[a] = 1

flag = True
ini = N
if N % 2 == 1:
    if 0 in A:
        if dic[0] == 1:
            ini = 2
        else:
            flag = False
    else:
        flag = False
else:
    ini = 1

for i in range(ini,N,2):
    if not flag: break
    if i in A:
        if dic[i] != 2:
            flag = False
    else: flag = False

if flag:
    print(2**(N//2)%(10**9+7))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
miss=0
if N%2==0:
    for i in range(int(N/2)):
        if A.count((2*i+1))!=2:
            miss=1
    if miss==1:
        print(0)
    else:
        print(int((2**int(N/2))%(10e9+7)))
if N%2==1:
    if not 0 in A:
        miss=1
    for i in range(int((N-1)/2)):
        if A.count((2*i+2))!=2:
            miss=1
    if miss==1:
        print(0)
    else:
        print(int((2**int((N-1)/2))%(10e9+7)))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
miss=0
if N%2==0:
    for i in range(int(N/2)):
        if A.count((2*i+1))!=2:
            miss=1
    if miss==1:
        print(0)
    else:
        print(2**int(N/2))
if N%2==1:
    if not 0 in A:
        miss=1
    for i in range(int((N-1)/2)):
        if A.count((2*i+2))!=2:
            miss=1
    if miss==1:
        print(0)
    else:
        print(2**int((N-1)/2))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
 
a_dict = {}
for v in a:
    if v in a_dict:
        a_dict[v] += 1
    else:
        a_dict[v] = 1
 
 
if n % 2 == 0:
    possible_list = [i for i in range(1, n, 2)]
    for k, v in a_dict.items():
        if v != 2 or k not in possible_list:
            print(0)
            exit()
else:
    possible_list = [i for i in range(0, n, 2)]
    if a_dict[0] != 1:
        print(0)
        exit()
    else:
        a_dict[0] = 2
        for k, v in a_dict.items():
            if v != 2 or k not in possible_list:
                print(0)
                exit()
 
print(2 ** (n // 2) % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

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

for i in range(1, n, 2):
    if a_list.count(n - i) != 2:
        print(0)
        exit()

if n % 2 != 0:
    if a_list.count(0) != 1:
        print(0)
        exit()
    else:
        print((2 ** -(-(len(a_list) - 1) // 2)) % (1000000000 + 7))
else:
    print((2 ** (len(a_list) // 2)) % (1000000000 + 7))

Submission status: Time Limit Exceeded

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

for i in range(1, n, 2):
    if a_list.count(n - i) != 2:
        print(0)
        exit()

if n % 2 != 0:
    if a_list.count(0) != 1:
        print(0)
        exit()
    else:
        print(2 ** -(-(len(a_list) - 1) // 2))
else:
    print(2 ** (len(a_list) // 2))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
correct_list = []

for i in range(1, n, 2):
    correct_list.append(n - i)

for i in correct_list:
    if a_list.count(i) != 2:
        print(0)
        exit()

if n % 2 != 0:
    if a_list.count(0) != 1:
        print(0)
        exit()

print(2 ** len(correct_list))

Submission status: Time Limit Exceeded

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

if n%2 == 0:
    for i in range(1,n,2):
        if not A.count(i) == 2:
            print(0)
            break
    else:
        print(2**(n//2)%(10**9+7))
else:
    if not A.count(0) == 1:
        print(0)
    else:
        for i in range(2,n,2):
            if not A.count(i) == 2:
                print(0)
                break
        else:
            print(2**((n-1)//2)%(10**9+7))

Submission status: Time Limit Exceeded

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

if n == 1:
    print(1)
    exit()

if n % 2 != 0:
    if a_list.count(0) != 1:
        print(0)
        exit()
    else:
        for i in range(2, n, 2):
            if a_list.count(i) != 2:
                print(0)
                exit()
            else:
                continue
    print(int(pow(2, (n - 1) / 2) % (pow(10, 9) + 7)))
else:
    for i in range(1, n, 2):
        if a_list.count(i) != 2:
            print(0)
            exit()
        else:
            continue
    print(int(pow(2, n / 2) % (pow(10, 9) + 7)))

Submission status: Time Limit Exceeded

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

if n % 2:
    if a.count(0) != 1:
        print(0)
        exit()
    for i in range(1, n//2+1):
        if a.count(2*i) != 2:
            print(0)
            exit()

else:
    for i in range(1, n//2+1):
        if a.count(2*i-1) != 2:
            print(0)
            exit()

print(2**(n//2))

Submission status: Time Limit Exceeded

Solution code:
M = 10 ** 9 + 7

def main():
    n = int(input())
    a = [int(s) for s in input().split()]
    print(solve(a, n))

def solve(a, n):
    if n % 2 == 0:
        for i in range(1, n, 2):
            if a.count(i) != 2:
                return 0
    else:
        if a.count(0) != 1:
            return 0
        for i in range(2, n, 2):
            if a.count(i) != 2:
                return 0

    return modpow(2, n // 2, M)

def modpow(a, b, m):
    r = 1

    while b != 0:
        if b & 0x01:
            r = (r * a) % m
        a = (a * a) % m
        b >>= 1

    return r

main()

Submission status: Time Limit Exceeded

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


if N % 2 == 1:
  if A.count(0) != 1:
    print(0)
  else:
    if not all([A.count(i) == 2 for i in range(2, N, 2)]):
      print(0)
    else:
      print(2 ** ((N - 1) // 2) % (10**9 + 7))
else:
  if not all([A.count(i) == 2 for i in range(1, N, 2)]):
    print(0)
  else:
    print(2 ** ((N // 2) % (10**9 + 7)))

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
ans = 1
count = 0
if N == 1:
    if A[0] == 0:
        ans = 1
    else:
        print(0)

if N % 2 == 0:
    for i in range(1, int(N/2)+1):
        if A.count(i*2-1) == 2:
            count += 1
        else:
            ans = 0
else:
    if A.count(0) == 1:
        for i in range(1, int(N/2)+1):
            if A.count(i*2) == 2:
                count += 1

            else:
                ans = 0
    else:
        ans = 0
for i in range(count):
    ans *= 2
    ans %= 1000000007
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
ans = 1
if N == 1:
    if A[0] == 0:
        ans = 1
    else:
        print(0)

if N % 2 == 0:
    for i in range(1, int(N/2)+1):
        if A.count(i*2-1) == 2:
            ans *= 2
            ans %= 1000000007
        else:
            ans *= 0
else:
    if A.count(0) == 1:
        for i in range(1, int(N/2)+1):
            if A.count(i*2) == 2:
                ans *= 2
                ans %= 1000000007
            else:
                ans *=0
    else:
        ans *= 0
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 入力
N = int(input())
A = input().split()
OE = N % 2
if OE == 1 and '0' not in A:
    print(0)
    exit()
if OE == 1 and '0' in A:
    A.remove('0')

for i in range(1 ,int((N-OE)/2)+OE):
    count = 0
    length = len(A)
    j = 0
    while(j < len(A)):
        if A[j] == str(i * 2 + 1 - OE):
            #print(str(i * 2 + 1 - OE))
            #A.remove(str(i * 2 + 1 - OE))
            A.pop(j)
            j = j - 1
            count = count + 1
            if count == 2:
                break
        j = j + 1
    if count < 2:
        print(0)
        exit()

print(int(pow(2, (N-OE)/2) % (pow(10, 9) + 7)))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 入力
N = int(input())
A = input().split()
OE = N % 2
if OE == 1 and '0' not in A:
    print(0)
    exit()
if OE == 1 and '0' in A:
    A.remove('0')
for i in range(1 ,int((N-OE)/2)+OE):
    if A.count(str(i * 2 + 1 - OE)) == 2:
        A.remove(str(i * 2 + 1 - OE))
        A.remove(str(i * 2 + 1 - OE))
        continue
    else:
        print(0)
        exit()
print(int(pow(2, (N-OE)/2) % (pow(10, 9) + 7)))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 入力
N = int(input())
A = input().split()
OE = N % 2
flag = 0
for i in range(1 ,int((N-OE)/2)+OE):
    if A.count(str(i * 2 + 1 - OE)) == 2:
        A.remove(str(i * 2 + 1 - OE))
        continue
    else:
        print(0)
        flag = 1
if flag == 0:
    print(int(pow(2, (N-OE)/2) % (pow(10, 9) + 7)))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 入力
N = int(input())
A = input().split()
OE = N % 2
flag = 0
for i in range(1 ,int((N-OE)/2)+OE):
    if A.count(str(i * 2 + 1 - OE)) == 2:
        continue
    else:
        print(0)
        flag = 1
if flag == 0:
    print(int(pow(2, (N-OE)/2) % (pow(10, 9) + 7)))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 入力
N = int(input())
A = input().split()
OE = N % 2
flag = 0
for i in range(1 ,int((N-OE)/2)+OE):
    if A.count(str(i * 2 + 1 - OE)) == 2:
        continue
    else:
        print(0)
        flag = 1
if flag == 0:
    print(int(pow(2, (N-OE)/2)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 1
if N % 2 == 0:
    
    for i in list(range(1, N, 2)):
        if A.count(i) != 2:
            ans = 0
            break
            
else:
    if A.count(0) == 1:
        for i in list(range(2, N, 2)):
            if A.count(i) != 2:
                ans = 0
                break
    else:
        ans = 0

if ans == 0:
    print(0)
else:
    print((2**(N//2))%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
if N % 2 == 0:
    
    for i in list(range(1, N, 2)):
        if A.count(i) == 2:
            ans += 1
        else:
            break
else:
    if A.count(0) == 1:
        
        for i in list(range(0, N, 2)):
            if 1 <= A.count(i) <=2:
                ans +=1
            else:
                break
    else:
        ans = 0

if ans != 0:
    if N%2 == 0:
        print((2**ans)%(10**9+7))
    else:
        print((2**(ans-1))%(10**9+7))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 1
if N % 2 == 0:
    
    for i in list(range(1, N, 2)):
        if 1 <= A.count(i) <= 2:
            ans = (ans*A.count(i))%(10**9+7)
        else:
            ans = 0
            break
else:
    if A.count(0) == 1:
        
        for i in list(range(0, N, 2)):
            if 1 <= A.count(i) <=2:
                ans = (ans*A.count(i))%(10**9+7)
            else:
                ans = 0
                break
    else:
        ans = 0

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 1
if N % 2 == 0:
    
    for i in list(range(1, N, 2)):
        if 1 <= A.count(i) <= 2:
            ans = ans*A.count(i)
        else:
            ans = 0
            break
else:
    if A.count(0) == 1:
        
        for i in list(range(0, N, 2)):
            if 1 <= A.count(i) <=2:
                ans = ans*A.count(i)
            else:
                ans = 0
                break
    else:
        ans = 0

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = int((N + 1) / 2)
flag = True
for i in range(M):
    count = 0
    for j in range(N):
        if A[j] == N - 2 * i - 1:
            count = count + 1
    if N % 2 == 1:
        if N - 2 * i - 1 == 0:
            if count != 1:
                flag = False
        else:
            if count != 2:
                flag = False
    else:
        if count != 2:
            flag = False
if flag:
    if N % 2 == 0:
        print((2 ** M) % (10 ** 9 + 7))
    else:
        print((2 ** (M - 1)) % (10 ** 9 + 7))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = tuple(map(int, input().split(" ")))
# n = 10000
# a = tuple(sum([[i, i] for i in range(1, n+1, 2)], [])[:n])

nums_sample = sum([[i, i] for i in range(n-1, 0-1, -2)], [])[:n]

if sorted(a, reverse=True) == nums_sample:
    print(2**(n//2) % (10**9+7))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
a = list(map(int,input().split()))
a = np.array(a)
mod = (1e9 + 7)


if len(a)%2 == 1:
    temp = int((len(a) - 1)/2)
    ans = 1
    for k in range(temp):
        ans = int((ans * 2)%mod)
              
    if sum(a == 0) != 1:
        ans = 0
    else:
        a = a[a!=0]
else:
    temp = int((len(a))/2)
    ans = 1
    for k in range(temp):
        ans = int((ans * 2)%mod)
    a = a+1

cands = [2*k for k in range(1,int(len(a)/2) + 1)] * 2

for c in cands:
    if sum(a == c) != 2:
        ans = 0
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def inpl(): return input().split()

n = int(input())
a = sorted(list(map(int, inpl())))

p = 10 ** 9 + 7

ans = 1
i = (n - 1) % 2
j = 0
while (i + j) < n:
    cnt = a.count(i + j)
    if (j % 2 == 0):
        if cnt != 2:
            if not((cnt == 1) and (((i + j) == 0) or ((i + j) == (n - 1)))):
                ans = 0
                break
        else:
            if ((i + j) == 0):
                ans = 0
                break
            else:
                ans *= cnt
                if ans > p:
                    ans %= p
    else:
        if cnt != 0:
            ans = 0
            break
    j += 1
print(ans)

Submission status: Time Limit Exceeded

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

a_dict = {}
for v in a:
    if v in a_dict:
        a_dict[v] += 1
    else:
        a_dict[v] = 1

can = True
if n % 2 == 0:
    possible_list = [i for i in range(1, n, 2)]
    for k, v in a_dict.items():
        if v != 2 or k not in possible_list:
            can = False
            break
else:
    possible_list = [i for i in range(0, n, 2)]
    if 0 not in a_dict:
        can = False
    elif a_dict[0] != 1:
        can = False
    else:
        a_dict[0] = 2
        for k, v in a_dict.items():
            if v != 2 or k not in possible_list:
                can = False
                break

if can:
    print(2 ** (n // 2) % (10 ** 9 + 7))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
number = input().split(" ")
if N%2 == 0:
    count = 0
    for i in range(int(N/2)):
        if number.count(str(2*i +1)) == 2:
            count += 0
        else:
            count += 1
    if count != 0:
        print(0)
    else:
        print(2**(int(N/2))%(10**9+7))
else:
    count = 0
    if "0" not in number:
        print(0)
    else:
        for i in range(int((N-1)/2)):
            if number.count(str(2*i+2)) == 2:
                count += 0
            else:
                count += 1
        if count != 0:
            print(0)
        else:
            print((2**(N//2)) % (10**9+7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
number = input().split(" ")
if N%2 == 0:
    count = 0
    for i in range(int(N/2)):
        if number.count(str(2*i +1)) == 2:
            count += 0
        else:
            count += 1
    if count != 0:
        print(0)
    else:
        print(2**(int(N/2))%(10**9+7))
else:
    count = 0
    if "0" not in number:
        print(0)
    else:
        for i in range(int((N-1)/2)):
            if number.count(str(2*i+2)) == 2:
                count += 0
            else:
                count += 1
        if count != 0:
            print(0)
        else:
            print(2**(int((N-1)/2))%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
number = input().split(" ")
if N%2 == 0:
    count = 0
    for i in range(int(N/2)):
        if number.count(str(2*i +1)) == 2:
            count += 0
        else:
            count += 1
    if count != 0:
        print(0)
    else:
        print(2**(int(N/2))%(2**10-7))
else:
    count = 0
    if "0" not in number:
        print(0)
    else:
        for i in range(int((N-1)/2)):
            if number.count(str(2*i+2)) == 2:
                count += 0
            else:
                count += 1
        if count != 0:
            print(0)
        else:
            print(2**(int((N-1)/2))%(2**10-7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
number = input().split(" ")
if N%2 == 0:
    count = 0
    for i in range(int(N/2)):
        if number.count(str(2*i +1)) == 2:
            count += 0
        else:
            count += 1
    if count != 0:
        print(0)
    else:
        print(2**(int(N/2)))
else:
    count = 0
    if "0" not in number:
        print(0)
    else:
        for i in range(int((N-1)/2)):
            if number.count(str(2*i+2)) == 2:
                count += 0
            else:
                count += 1
        if count != 0:
            print(0)
        else:
            print(2**(int((N-1)/2)))

Submission status: Time Limit Exceeded

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

flag = 1
if n % 2 == 1 :
    for i in range(0,n,2):
        if i == 0 :
            if x.count(i) !=1:
                flag = 0
                break
        elif x.count(i) == 2:
            x.remove(i)
            x.remove(i)
            continue
        else:
            flag = 0
            break
else:
    for i in range(1,n,2):  
        if x.count(i) == 2:
            x.remove(i)
            x.remove(i)
            continue
        else:
            flag = 0
            break
            
if flag == 1:
    ans = 1
    if n >=2:
        for i in range(n // 2 ):
            ans = (ans * 2) % (10 ** 9 + 7)
        
    print(2 ** ((n) // 2 ))
else:
    print(0)

Submission status: Time Limit Exceeded

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

flag = 1
if n % 2 == 1 :
    for i in range(0,n,2):
        if i == 0 :
            if x.count(i) !=1:
                flag = 0
                break
        elif x.count(i) != 2:
            flag = 0
            break
else:
    for i in range(1,n,2):
        if x.count(i) != 2:
            flag = 0
            break
            
if flag == 1:
    ans = 1
    if n >=2:
        for i in range(n // 2 ):
            ans = (ans * 2) % (10 ** 9 + 7)
        
    print(2 ** ((n) // 2 ))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

def beki(n):
    ans = 1
    for _ in range(int(n)):
        ans = (ans * 2) % (10 ** 9 + 7)
    return int(ans)

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

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

Submission status: Time Limit Exceeded

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    from collections import Counter

    person_count = int(input())
    relative_positions = Counter(map(int, input().split()))

    if person_count % 2 == 0:
        odd = [2 * i + 1 for i in range(person_count // 2)]

        for key, value in relative_positions.items():
            if (key % 2 == 0) or (key not in odd) or (value != 2):
                print(0)
                exit()
    else:
        even = [2 * i for i in range((person_count + 1) // 2)]

        for key, value in relative_positions.items():
            if (key % 2 == 1) or (key not in even) or (key == 0 and value != 1) or (key != 0 and value != 2):
                print(0)
                exit()

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

Submission status: Time Limit Exceeded

Solution code:
import sys
n=int(input())
a=list(map(int,input().split()))
a.sort()
if(n%2==0):
  if(0 in a):
    print(0)
    sys.exit()
  else:
    num=0
    for i in range(1,n,2):
      if(a.count(i)==2):
        num+=1
        a.remove(i)
        a.remove(i)
      else:
        print(0)
        sys.exit()
    if(len(a)>0):
      print(0)
      sys.exit()
else:
  if(a.count(0)!=1):
    print(0)
    sys.exit()
  else:
    a.remove(0)
    num=0
    for i in range(2,n,2):
      if(a.count(i)==2):
        num+=1
        a.remove(i)
        a.remove(i)
      else:
        print(0)
        sys.exit()
print(int(2**num)%(10**9+7))