using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("4");
WillReturn.Add("0 1 1 2");
//6
}
else if (InputPattern == "Input2") {
WillReturn.Add("4");
WillReturn.Add("0 1 2 0");
//0
}
else if (InputPattern == "Input3") {
WillReturn.Add("3");
WillReturn.Add("1 1 2");
//0
}
else if (InputPattern == "Input4") {
WillReturn.Add("17");
WillReturn.Add("0 1 1 2 2 4 3 2 4 5 3 3 2 1 5 4 2");
//855391686
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
const long Hou = 1000000007;
static void Main()
{
List<string> InputList = GetInputList();
long[] AArr = InputList[1].Split(' ').Select(pX => long.Parse(pX)).ToArray();
// 度数分布表
var CntDict = new SortedDictionary<long, long>();
foreach (long EachA in AArr) {
if (CntDict.ContainsKey(EachA) == false) {
CntDict[EachA] = 0;
}
CntDict[EachA]++;
}
if (AArr[0] != 0 || CntDict[0] > 1) {
Console.WriteLine(0);
return;
}
if (AArr[0] == 0 && AArr.Length == 1) {
Console.WriteLine(1);
return;
}
// 歯抜けがあったらNG
long MaxKey = CntDict.Keys.Max();
for (long I = 1; I <= MaxKey; I++) {
if (CntDict.ContainsKey(I) == false) {
Console.WriteLine(0);
return;
}
}
long Answer = 1;
// 同じ距離のノードでの辺の数
foreach (var EachPair in CntDict) {
if (EachPair.Value > 1) {
long EdgeCnt = DeriveTousaSuuretuSum(1, 1, EachPair.Value - 1);
long Beki2 = DeriveBekijyou(2, EdgeCnt, Hou);
Answer *= Beki2;
Answer %= Hou;
}
}
// 距離が1小さいノードとの辺
foreach (var EachPair in CntDict) {
if (EachPair.Key > 0) {
long ParentCnt = CntDict[EachPair.Key - 1];
if (ParentCnt > 1) {
long ChoosePatternCnt = DeriveBekijyou(2, ParentCnt, Hou) - 1;
if (ChoosePatternCnt < 0) ChoosePatternCnt += Hou;
for (long I = 1; I <= EachPair.Value; I++) {
Answer *= ChoosePatternCnt;
Answer %= Hou;
}
}
}
}
if (Answer < 0) Answer += Hou;
Console.WriteLine(Answer);
}
// 初項と公差と項数を引数として、等差数列の和を返す
static long DeriveTousaSuuretuSum(long pSyokou, long pKousa, long pKouCnt)
{
long Makkou = pSyokou + pKousa * (pKouCnt - 1);
long wkSum = pSyokou + Makkou;
long Result = wkSum * pKouCnt;
Result /= 2;
return Result;
}
// 繰り返し2乗法で、(NのP乗) Mod Mを求める
static long DeriveBekijyou(long pN, long pP, long pM)
{
long CurrJyousuu = pN % pM;
long CurrShisuu = 1;
long WillReturn = 1;
while (true) {
// 対象ビットが立っている場合
if ((pP & CurrShisuu) > 0) {
WillReturn = (WillReturn * CurrJyousuu) % pM;
}
CurrShisuu *= 2;
if (CurrShisuu > pP) return WillReturn;
CurrJyousuu = (CurrJyousuu * CurrJyousuu) % pM;
}
}
}