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:
from subprocess import*
with open('Main.java','w')as f:f.write(r"""
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = Integer.parseInt(sc.next());
		Arrays.sort(a);
		boolean able = true;
		if (n % 2 > 0) {
			for (int i = 0; i < n; i++) {
				if (i % 2 == 0 && a[i] == i) continue;
				if (i % 2 > 0 && a[i] == i + 1) continue;
				able = false;
			}
		}
		else {
			for (int i = 0; i < n; i++) {
				if (i % 2 == 0 && a[i] == i + 1) continue;
				if (i % 2 > 0 && a[i] == i) continue;
				able = false;
			}
		}
		if (able) {
			long ans = 1;
			for (int i = 1; i <= n / 2; i++)
				ans = ans * 2 % 1000000007;
			System.out.println(ans);
		}
		else
			System.out.println("0");
	}
}
""")
call(('javac','Main.java'))
call(('java','Main'))

Submission status: Accepted

Solution code:
from math import ceil

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

A.sort()

if N % 2 == 1:
    num = (N - 1) // 2
    if A[0] != 0:
        print(0)
        exit()
    for i in range(1, N):
        if A[i] == ceil(i / 2) * 2:
            continue
        else:
            print(0)
            exit()
else:
    num = N // 2
    for i in range(N - 1):
        if A[i] == (i // 2) * 2 + 1:
            continue
        else:
            print(0)
            exit()

print((2**num) % (10**9 + 7))

Submission status: Accepted

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

A.sort()

if N % 2 == 1:
    num = (N - 1) // 2
    if A[0] != 0:
        print(0)
        exit()
    for i in range(1, N):
        if A[i] == ceil(i / 2) * 2:
            continue
        else:
            print(0)
            exit()
else:
    num = N // 2
    for i in range(N - 1):
        if A[i] == (i // 2) * 2 + 1:
            continue
        else:
            print(0)
            exit()

print((2**num) % (10**9 + 7))

Submission status: Accepted

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

A.sort()

if N % 2 == 1:
    num = (N - 1) // 2
    if A[0] != 0:
        print(0)
        exit()
    for i in range(1, N):
        if A[i] == ceil(i / 2) * 2:
            continue
        else:
            print(0)
            exit()
else:
    num = N // 2
    for i in range(N - 1):
        if A[i] == (i // 2) * 2 + 1:
            continue
        else:
            print(0)
            exit()
ans = 1
for i in range(num):
    ans *= 2
    ans %= (10**9 + 7)

print(ans)

Submission status: Accepted

Solution code:
c = int(input())
n = list(map(int,input().split()))
flag =True
n.sort()
if(len(n)%2==0):
	count=1
else:
	count=2
	if(n.pop(0)!=0):
		flag = False
		print('not 0 false')
while flag:
	if(len(n)==0): break
	if(not count==n.pop(0)==n.pop(0)):
		flag=False
	count += 2

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

Submission status: Accepted

Solution code:
import itertools
N = input()
l = list(map(int,input().split(" ")))
l.sort()
N = int(N)
flag = True
NUM = 10** 9 + 7
num = 2
if N %2 != 0:
    if l[0] != 0:
        flag =False
    num = 2
    start = 1
else:
    num = 1
    start = 0
for i in range(start,N,2):
    if l[i] != l[i + 1]   or l[i] != num:
        flag = False
    else:
        num += 2
if flag:
    temp = (N - start)//2
    print(2 ** temp %NUM )
else:
    print(0)

Submission status: Accepted

Solution code:

N = int(input())

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

dic = {}


for i in A:

    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

#print(dic)

if N % 2 == 0:

    flag = True
    now = 1

    for i in range(N // 2):

        if now not in dic or dic[now] != 2:
            flag = False
            break

        now += 2

    if len(dic) != N // 2:
        flag = False

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

    else:
        print (0)

else:

    flag = True
    now = 2

    if 0 not in dic or dic[0] != 1:
        flag = False

    for i in range(N // 2):

        if now not in dic or dic[now] != 2:
            flag = False
            break
        now += 2

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

    else:
        print (0)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
MOD = 10 ** 9 + 7

def judge() :
    p = N % 2
    c = [0] * ((N + 1) // 2)

    for a in A :
        if a % 2 == p or a < 0 or N <= a :
            return 0
            
        c[a//2] += 1
 
    if p == 1 and c[0] == 1 and c[1:].count(2) == (N - 1) // 2 :
        return pow(2, (N - 1) // 2, MOD)
    
    elif p == 0 and c.count(2) == N // 2 :
        return pow(2, N // 2, MOD)
        
    return 0
    
print(judge())

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(map(int,input().split()))
B = []

if N%2:
	B = [0]
	for i in range(N//2):
		B += [(i + 1)*2]*2
else:
	for i in range(N//2):
		B += [i*2 + 1]*2	
#print(A, B)
#print(B)
if A==B:
	print(2**(N//2)%((10**9) + 7))
else:
	print(0)

Submission status: Accepted

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

A.sort()
mod = 10 ** 9 + 7
i = 0
res = 0
if N == 1:
  if A[0] == 0:
    print(1)
  else:
    print(0)
  exit(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 % mod)

Submission status: Accepted

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())
ccc = sorted(c,key = itemgetter(0))
if n % 2 == 1:
    k = 0
    for i,j in ccc:
        if j == 2 and i == 2*k:
            k += 1
            continue
        if j == 1 and i == 0:
            k += 1
            continue
        else:
            print(0)
            quit()
if n % 2 == 0:
    k = 0
    for i,j in ccc:
        if j == 2 and i == 2*k+1:
            k += 1
            continue
        else:
            print(0)
            quit()
print(2**(n//2) % mod)

Submission status: Accepted

Solution code:
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
"""
#decomment when needed
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
"""
n = ip()
a = iprow()
b = sorted(a)
if n%2:
    s = 2
else:
    s = 1
    b.insert(0,0)
if n%2 != 0 and b[0] != 0:
    print(0)
    exit(0)
for i in range(1,n):
    if b[i]!=s:
        print(0)
        exit(0)
    if i%2 == 0:
        s+=2
print(pow(2,n//2,rem))

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    mod = 10**9+7
    n = int(input())
    a = list(map(int,input().split(' ')))
    c = Counter(a)
    ans = (2**(n//2))%mod
    if n%2 != 0:
        for key,i in c.items():
            if key%2 != 0 or (key==0 and i != 1) or (key != 0 and i != 2):
                ans = 0
                break
    else:
        for key,i in c.items():
            if key%2 ==0 or i !=2:
                ans = 0
                break

    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    mod = 10**9+7
    n = int(input())
    a = list(map(int,input().split(' ')))
    c = Counter(a)
    ans = 1
    if n%2 != 0:
        for key,i in c.items():
            if key%2 != 0 or (key==0 and i != 1) or (key != 0 and i != 2):
                ans = 0
                break
            elif i ==2:
                ans *=2
                ans %= mod
    else:
        for key,i in c.items():
            if key%2 ==0 or i !=2:
                ans = 0
                break
            elif i ==2:
                ans *=2
                ans %= mod
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict

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

D = defaultdict(lambda: 0)
for a in A:
    D[a] += 1

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

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

Submission status: Accepted

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: Accepted

Solution code:
N = int(input())
Al = list(map(int,input().split()))
Al.sort()
Bl = []

if N % 2 == 0:
  for i in range(1,N+1,2):
    Bl.append(i)
    Bl.append(i)

else:
  Bl.append(0)
  for i in range(2,N+1,2):
    Bl.append(i)
    Bl.append(i)

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

Submission status: Accepted

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

waru=10**9+7

kakunin=[0]*n
kigu=n%2
for i in range(n):
    if kigu==a[i]%2:
        print(0)
        quit()
    kakunin[a[i]]+=1

for i in range(n):
    # if i==0 and kakunin[0]==1 and kigu==1:
    #     continue
    # if kigu!=i%2 and kakunin[i]!=2:
    #     print(0)
    #     quit()
    if kigu==0 and i%2==1:
        if kakunin[i]!=2:
            print(0)
            quit()
    if kigu==1 and i%2==0:
        if i==0 and kakunin[i]!=1:
            print(0)
            quit()
        elif i!=0 and kakunin[i]!=2:
            print(0)
            quit()

print((2**(n//2))%waru)

Submission status: Accepted

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

waru=10**9+7

kakunin=[0]*n
kigu=n%2
for i in range(n):
    kakunin[a[i]]+=1
    
# print(kakunin)
for i in range(n):
    if kigu==0:
        if i%2==1 and kakunin[i]!=2:
            print(0)
            quit()
        elif i%2==0 and kakunin[i]!=0:
            print(0)
            quit()

    if kigu==1:
        if i==0:
            if kakunin[i]!=1:
                print(0)
                quit()
        elif i%2==0 and kakunin[i]!=2:
            print(0)
            quit()
        elif i%2==1 and kakunin[i]!=0:
            print(0)
            quit()

print((2**(n//2))%waru)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def power_func(a,n,p):
  bi=str(format(n,"b"))
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":res=(res*a) %p
  return res

N = int(input())
a = list(map(int,input().split()))
b = set()
for c in a:
    if c in b:b.remove(c)
    else:b.add(c)

if N%2==1:
    if b == {0}:print(power_func(2,N//2,10**9+7))
    else:print(0)
else:
    if len(b) == 0:print(power_func(2,N//2,10**9+7))
    else:print(0)

Submission status: Accepted

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(2**(n//2)%mod)
elif not n % 2 == 0 and l.count(0) == 1:
  print(2**((n-1)//2)%mod)
else:
  print(0)

Submission status: Accepted

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

for i in range(N):
    if A.count(i) == 2 and i != 0:
        c += 1
    elif A.count(i) == 1 and i == 0:
        continue
    elif A.count(i) == 0:
        continue
    else:
        break
'''
c = N // 2
if N % 2 == 0:
    K = N
else:
    K = N + 1 
if sum(A) == c * K:
    ans = 2 ** c % (10**9 + 7)
else:
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
NUM = 10 ** 9 + 7

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

A.sort(reverse=True)

length = len(A)
if not length % 2 == 0:
    length -= 1

for i in range(0, length, 2):
    if not A[i] == A[i + 1]:
        print(0)
        exit()

print((2 ** (length // 2)) % NUM)

Submission status: Accepted

Solution code:
# 前の回答が気に食わなかったのでもう一回

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

for i, a in enumerate(A):
    if N % 2 == 0:
        if a != i // 2 * 2 + 1:
            print(0)
            exit()
    else:
        if a != (i + 1) // 2 * 2:
            print(0)
            exit()

print(pow(2, N // 2, 10 ** 9 + 7))

Submission status: Accepted

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

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

# 全探索でやると間に合わなかったので正しい場合の和の値を求めてそれを配列の和と比較する

K = N if N % 2 == 0 else N + 1
S = N // 2
if sum(A) == K * S:
    ans = 2 ** S % (10 ** 9 + 7)
else:
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
diff=[int(s) for s in input().split()]
diff.sort()
MOD=10**9+7

# 奇数の場合は先頭のみ0
start=0
if n&1==1:
    start=1
    if diff[0]!=0:
        print(0)
        exit()

ans=1
for i in range(start,n,2):
    # 中央以外の0は矛盾
    if diff[i]==0:
        print(0)
        exit()
    
    # 必ず左右対称である必要がある
    if diff[i]!=diff[i+1]:
        print(0)
        exit()

    ans=ans*2%MOD

print(ans)

Submission status: Accepted

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

A = list(sorted(A))#ソート
flag = 0#判定のフラグ
for i in range(N//2-1):
    if N % 2 == 1:#奇数
        if A[2*i+1]==A[2*i+2] and A[2*i+1] == 2*i+2 and A[0] == 0:
            pass;
        else:
            flag = -1
            break;
    if N % 2 == 0:
        if A[2*i]==A[2*i] and A[2*i+1] == 2*i+1:
            pass;
        else:
            flag = -1
            break;
if flag == 0:
    ans = 2**(N//2)%(10**9+7)
    print (ans)
else:
    print(0)

Submission status: Accepted

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

A = list(sorted(A))
flag = 0
for i in range(N//2-1):
    if N % 2 == 1:
        if A[2*i+1]==A[2*i+2] and A[2*i+1] == 2*i+2:
            pass;
        else:
            flag = -1
            break;
    if N % 2 == 0:
        if A[2*i]==A[2*i] and A[2*i+1] == 2*i+1:
            pass;
        else:
            flag = -1
            break;
if flag == 0:
    ans = 2**(N//2)%(10**9+7)
    print (ans)
else:
    print(0)

Submission status: Accepted

Solution code:
# ARC066C - Lining Up (ABC050C)
from collections import Counter


def main():
    n = int(input())
    a = tuple(map(int, input().rstrip().split()))
    MOD = 10 ** 9 + 7
    s = (n // 2) * 2
    l = (n + 1) // 2
    if sum(a) == s * l:
        print(2 ** (n // 2) % MOD)
    else:
        print(0)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ARC066C - Lining Up (ABC050C)
from collections import Counter


def main():
    n = int(input())
    a = tuple(map(int, input().rstrip().split()))
    MOD = 10 ** 9 + 7
    s = (n // 2) * 2
    l = (n + 1) // 2
    p = l if n % 2 == 0 else l - 1
    if sum(a) == s * l:
        print(2 ** p % MOD)
    else:
        print(0)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ARC066C - Lining Up (ABC050C)
from collections import Counter


def main():
    n = int(input())
    a = sorted(Counter(map(int, input().rstrip().split())).items())
    MOD = 10 ** 9 + 7
    if n % 2 == 1 and a[0][1] != 1:
        print(0)
    elif not all(i[1] == 2 for i in a[1:]):
        print(0)
    else:
        if n % 2 == 0:
            print(2 ** len(a) % MOD)
        else:
            print(2 ** (len(a) - 1) % MOD)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

N = int(input())
L = [int(v) for v in input().split()]
m = [set() for _ in range(N)]

t = N - 1
for i in range(N):
    v = L[i]
    e = (t + v) // 2
    s = t - e
    
    m[s].add(i)
    m[e].add(i)
    
l = set()
for v in m:
    if len(v) == 0:
        print("0")
        exit()
    elif len(v) == 1:
        v = list(v)
        if v[0] in l:
            print("0")
            exit()
        
        l.add(v[0])
        
c = (N - len(l)) // 2
print(2 ** c % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
import os
import sys

import numpy as np

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

sys.setrecursionlimit(2147483647)
INF = float("inf")

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

A = np.array(A)
c = np.bincount(A)
e = np.bincount(abs(np.arange(N - 1, -N, -2)))
if c.shape == e.shape and all(c == e):
    print(pow(2, N // 2, 10 ** 9 + 7))
else:
    print(0)

Submission status: Accepted

Solution code:
import sys

mod = 10**9 + 7

n = int(input())
li = list(map(int,input().split()))
li.sort()
cnt = 0

if n % 2 == 1:
    for i,s in enumerate(li):
        if i == 0 :
            if s != 0:
                print(0)
                sys.exit()
        else:
            if i % 2 == 1:
                if i + 1 != s:
                    print(0)
                    sys.exit()
            else:
                if i != s:
                    print(0)
                    sys.exit()
    res = (n-1)//2
    print((2**res)%mod)
    
else:
    for i,s in enumerate(li):
        if i % 2 == 1:
            if i != s:
                print(0)
                sys.exit()
        else:
            if i + 1 != s:
                print(0)
                sys.exit()

    res = n//2
    print((2**res)%mod)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
*A, = map(int, input().split())
MOD = 10**9 + 7
cnt = Counter(A)
if N % 2 == 0:
    for i in range(1, N+1, 2):
        if cnt[i] != 2:
            print(0)
            break
    else:
        print(pow(2, N//2, MOD))
else:
    if cnt[0] != 1:
        print(0)
    else:
        for i in range(2, N+1, 2):
            if cnt[i] != 2:
                print(0)
                break
        else:
            print(pow(2, N//2, MOD))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
# print (A)
flag = True
if N%2 == 0:
    for i in range(N//2):
        if A[2 * i] == 2 * i+1 and A[2 * i+1] == 2 * i+1:
            pass
        else:
            flag = False
else:
    if A[0] == 0:
        pass
    else:
        flag = False
    for i in range((N)//2):
        # print (i)
        if A[2 * i+1] == 2 * (i+1) and A[2 * i+2] == 2 * (i+1):
            pass
            # print ('A')
        else:
            # print ('B')
            flag = False

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

Submission status: Accepted

Solution code:
import sys
import math
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
mod = 10 ** 9 + 7


A.sort()

# check
check = 0
if N % 2 == 1:
    for i in range(1,N + 1):
        if A[i-1] != math.floor(i/2) * 2:
            check = 1
            break
if N %2 == 0:
    for i in range(N):
        if A[i] != math.floor(i/2) * 2 + 1:
            check = 1
            break

if check == 1:
    ans = 0
    print(ans)
    sys.exit()

if N % 2 == 1:
    jou = (N-1)/2
else:
    jou = N/2

ans = 1
for i in range(int(jou)):
    ans = (ans * 2) % mod

print(ans)

Submission status: Accepted

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.shape != cnt_2.shape or (cnt_1 != cnt_2).any():
  answer = 0
else:
  answer = pow(2, N//2, MOD)
  
print(answer)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
l=[0 for i in range(n)]
for x in a:
    l[x] += 1
p = [(0 if i % 2 == 0 else 2) for i in range(n // 2 * 2)]
if n % 2 == 1: p = [1] + p
if l != p:
    print(0)
    import sys
    sys.exit()


def mod_power(x, a, p):
    if a == 0:
        return 1
    t = mod_power(x, a // 2, p)
    if a % 2 == 0:
        return t * t % p
    else:
        return x * t * t % p

ans = 1
# for i in range(n // 2):
#     ans *= 2
#     ans %= 10 ** 9 + 7
# print(ans)
print(mod_power(2,n//2,10**9+7))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
l=[0 for i in range(n)]
for x in a:
    l[x] += 1
p = [(0 if i % 2 == 0 else 2) for i in range(n // 2 * 2)]
if n % 2 == 1: p = [1] + p
if l != p:
    print(0)
    import sys
    sys.exit()


def mod_power(x, a, p):
    if a == 0:
        return 1
    t = mod_power(x, a // 2, p)
    if a % 2 == 0:
        return t * t
    else:
        return x * t % p * t

ans = 1
for i in range(n // 2):
    ans *= 2
    ans %= 10 ** 9 + 7
print(ans)
# print(mod_power(2,n//2,10**9+7))

Submission status: Accepted

Solution code:

N = int(input())

can_flg = True

lst_A = input().split()

for i in range(len(lst_A)):
    lst_A[i] = int(lst_A[i])

lst_A.sort()

while 1:
    if len(lst_A) % 2 == 1:
        if lst_A[0] != 0:
            can_flg = False
            break
        for i in range(1, len(lst_A), 2):
            if not((lst_A[i] == (i + 1)) and (lst_A[i + 1] == (i + 1))):
                can_flg = False
                break
    else:
        for i in range(0, len(lst_A), 2):
            if not ((lst_A[i] == (i + 1)) and (lst_A[i + 1] == (i + 1))):
                can_flg = False
                break
    break

if can_flg == True:
    ans = 2 ** (len(lst_A) // 2)
    ans = ans % (10 ** 9 + 7)
else:
    ans = 0

print(ans)

Submission status: Accepted

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

if n % 2 == 0:
    kakeru = n
else:
    kakeru = n + 1

if sum(int_a) == kakeru * (n // 2):
    syou = n // 2
    answer = 2 ** syou
    print(answer % ((10 ** 9) + 7))
else:
    print("0")

Submission status: Accepted

Solution code:
n = int(input())
a = input().split()
int_a =[]
for i in range(len(a)):
    int_a.append(int(a[i]))
if n % 2 == 0:
    kakeru = n
else:
    kakeru = n + 1

if sum(int_a) == kakeru * (n // 2):
    syou = n // 2
    answer = 2 ** syou
    print(answer % ((10 ** 9) + 7))
else:
    print("0")

Submission status: Accepted

Solution code:
n=int(input())
l=sorted(map(int,input().split()))
mod=10**9+7
if n%2==1:
	for i in range(n):
		if l[i]!=i+i%2:
			print(0)
			break
	else:
		print(pow(2,n//2,mod))
else:
	for i in range(n):
		if l[i]!=i+(i+1)%2:
			print(0)
			break
	else:
		print(pow(2,n//2,mod))

Submission status: Accepted

Solution code:
def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

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

A.sort()
mod = int(1e9+7)

if N % 2 == 1:
  for i in range(N):
    if not ((i+1) // 2) *2 == A[i]:
      print(0)
      exit()
  else:
    ans = power_func(2, (N-1)//2, mod)
    print(ans)
else:
  for i in range(N):
    if not (i // 2) *2 + 1 == A[i]:
      print(0)
      exit()
  else:
    ans = power_func(2, N//2, mod)
    print(ans)

Submission status: Accepted

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: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l.sort()

  if n%2==0:
    for i in range(n//2):
      if l[i]!=i//2*2+1:
        return 0
  else:
    if l[0]!=0:
      return 0
    for i in range(1,n):
      if -(-i//2)*2!=l[i]:
        return 0
  return pow(2,n//2)%mod

print(main())

Submission status: Accepted

Solution code:
from itertools import accumulate
from bisect import bisect, bisect_left
from functools import reduce
from itertools import accumulate, product
from operator import itemgetter, xor
from math import sqrt
from random import randint, random
from heapq import heappop, heappush

from fractions import gcd
from collections import Counter, deque, defaultdict

import sys
#input = sys.stdin.readline
from sys import setrecursionlimit
setrecursionlimit(10**9)

def inpl(): return list(map(int, input().split()))
MOD = 10**9 + 7
N = int(input())
A = inpl()
C = Counter(A)
OK = True

if (N%2) and (C[0] != 1):
    OK = False
for i in range(N//2):
    if C[2*(i+1) -1 + N%2] != 2:
        OK = False

print(pow(2, N//2, MOD)*OK)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
"""考え方
・Nが奇数の時、
0が一個と、
2, 4, 6, ..., K (< N)が2個ずつ

・Nが偶数の時、
1, 3, ... K (< N)が2個ずつ

"""
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10**9+7

    dic = {}
    for a in A:
        if not a in dic:
            dic[a] = 0
        dic[a] += 1
    
    if N%2 == 0:
        # Nが偶数のとき
        for i in range(N):
            num = i*2+1
            if num > N:
                break

            if not num in dic:
                print(0)
                return

            if dic[num] == 2:
                continue
            else:
                print(0)
                return
        print((2**i)%MOD)
        return
    else:
        # Nが奇数のとき
        i = -1
        while True:
            i += 1
            num = i*2
            if num > N:
                break
            
            if not num in dic:
                print(0)
                return
            
            if num == 0 and dic[num] == 1:
                continue
            elif num != 0 and dic[num] == 2:
                continue
            else:
                print(0)
                return
        print((2**(i-1))%MOD)
        return
        

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N=int(input());print(2**(N//2)%(10**9+7)if sorted(list(map(int,input().split())))==[i+(i+N+1)%2for i in range(N)]else 0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int,input().split()))
#nが奇数の場合,0,2,2,4,4,...
#nが偶数の場合,1,1,3,3,...
a.sort()
flag = True
if n %2==1:
    for n,v in enumerate(a):
        if n==0:
            if v != 0:
                flag=False
                break
        else:
            if v!=((n+1)//2)*2:
                flag=False
                break
else:
    for n,v in enumerate(a):
        if v!=(n//2)*2+1:
            flag=False
            break
if flag:
    print(2**(len(a)//2)%(10**9+7))
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
response_list = [ int(v) for v in input().split() ]

ans = 0

mod = 10**9+7


if n % 2 == 0:
	right_list = [ 2*(i//2+1)-1 for i in range(n) ]
else:
	right_list = [ 2*((i+1)//2) for i in range(n) ]

if sorted(response_list) == right_list:

	if n % 2 == 0:
		ans = pow(2,n//2,mod)
	else:
		ans = pow(2,(n-1)//2,mod)

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

K = Counter(A).most_common()
flag = True

for i in range(len(K)):
    if K[i][1] != 2:
        if K[i][0] == 0 and K[i][1] == 1:
            continue
        else:
            flag = False

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l.sort()

  if n%2==0:
    for i in range(n):
      if (i//2)*2+1!=l[i]:
        return 0
    return pow(2,n//2)%mod

  else:
    if l[0]!=0:
      return 0
    l=l[1:]
    for i in range(n-1):
      if (i//2)*2+2!=l[i]:
        return 0
    return pow(2,n//2)%mod

print(main())